(error, inspected)
| 396 | } |
| 397 | |
| 398 | const inputPreviewCallback = (error, inspected) => { |
| 399 | if (inspected == null) { |
| 400 | return; |
| 401 | } |
| 402 | |
| 403 | wrapped = false; |
| 404 | |
| 405 | // Ignore the output if the value is identical to the current line. |
| 406 | if (line === inspected) { |
| 407 | return; |
| 408 | } |
| 409 | |
| 410 | if (error) { |
| 411 | debug('Error while generating preview', error); |
| 412 | return; |
| 413 | } |
| 414 | // Do not preview `undefined` if colors are deactivated or explicitly |
| 415 | // requested. |
| 416 | if (inspected === 'undefined' && |
| 417 | (!repl.useColors || repl.ignoreUndefined)) { |
| 418 | return; |
| 419 | } |
| 420 | |
| 421 | inputPreview = inspected; |
| 422 | |
| 423 | // Limit the output to maximum 250 characters. Otherwise it becomes a) |
| 424 | // difficult to read and b) non terminal REPLs would visualize the whole |
| 425 | // output. |
| 426 | let maxColumns = MathMin(repl.columns, 250); |
| 427 | |
| 428 | // Support unicode characters of width other than one by checking the |
| 429 | // actual width. |
| 430 | if (inspected.length * 2 >= maxColumns && |
| 431 | getStringWidth(inspected) > maxColumns) { |
| 432 | maxColumns -= 4 + (repl.useColors ? 0 : 3); |
| 433 | let res = ''; |
| 434 | for (const char of new SafeStringIterator(inspected)) { |
| 435 | maxColumns -= getStringWidth(char); |
| 436 | if (maxColumns < 0) |
| 437 | break; |
| 438 | res += char; |
| 439 | } |
| 440 | inspected = `${res}...`; |
| 441 | } |
| 442 | |
| 443 | // Line breaks are very rare and probably only occur in case of error |
| 444 | // messages with line breaks. |
| 445 | const lineBreakMatch = RegExpPrototypeExec(/[\r\n\v]/, inspected); |
| 446 | if (lineBreakMatch !== null) { |
| 447 | inspected = `${StringPrototypeSlice(inspected, 0, lineBreakMatch.index)}`; |
| 448 | } |
| 449 | |
| 450 | const result = repl.useColors ? |
| 451 | `\u001b[90m${inspected}\u001b[39m` : |
| 452 | `// ${inspected}`; |
| 453 | |
| 454 | const { cursorPos, displayPos } = getPreviewPos(); |
| 455 | const rows = displayPos.rows - cursorPos.rows; |
nothing calls this directly
no test coverage detected
searching dependent graphs…