Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repl: fix preview cursor position #31293

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/internal/repl/utils.js
Expand Up @@ -384,9 +384,9 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) {
const { cursorPos, displayPos } = getPreviewPos();
const rows = displayPos.rows - cursorPos.rows;
moveCursor(repl.output, 0, rows);
const { cols: resultCols } = repl._getDisplayPos(result);
repl.output.write(`\n${result}`);
moveCursor(repl.output, cursorPos.cols - resultCols, -rows - 1);
cursorTo(repl.output, cursorPos.cols);
moveCursor(repl.output, 0, -rows - 1);
});
};

Expand Down
20 changes: 10 additions & 10 deletions test/parallel/test-repl-history-navigation.js
Expand Up @@ -254,7 +254,7 @@ const tests = [
// 360 % 250 + 2 === 112 (+1)
`${prompt}${'veryLongName'.repeat(30)}`, '\x1B[113G',
// "// 'I should be previewed'".length + 86 === 112 (+1)
"\n// 'I should be previewed'", '\x1B[86C\x1B[1A',
"\n// 'I should be previewed'", '\x1B[113G', '\x1B[1A',
// Preview cleanup
'\x1B[1B', '\x1B[2K', '\x1B[1A',
// 4. WORD LEFT
Expand All @@ -263,51 +263,51 @@ const tests = [
'\x1B[1A',
'\x1B[1G', '\x1B[0J',
`${prompt}${'veryLongName'.repeat(30)}`, '\x1B[3G', '\x1B[1A',
'\x1B[1B', "\n// 'I should be previewed'", '\x1B[24D\x1B[2A',
'\x1B[1B', "\n// 'I should be previewed'", '\x1B[3G', '\x1B[2A',
// Preview cleanup
'\x1B[2B', '\x1B[2K', '\x1B[2A',
// 5. UP
'\x1B[1G', '\x1B[0J',
`${prompt}e`, '\x1B[4G',
// '// RangeError: visible'.length - 19 === 3 (+1)
'\n// RangeError: visible', '\x1B[19D\x1B[1A',
'\n// RangeError: visible', '\x1B[4G', '\x1B[1A',
// Preview cleanup
'\x1B[1B', '\x1B[2K', '\x1B[1A',
// 6. Backspace
'\x1B[1G', '\x1B[0J',
'> ', '\x1B[3G', 'x', '1',
`\n// '${'あ'.repeat(124)}'`,
'\x1B[1C\x1B[1A',
'\x1B[5G', '\x1B[1A',
'\x1B[1B', '\x1B[2K', '\x1B[1A',
'\x1B[1G', '\x1B[0J',
'> x', '\x1B[4G', '2',
`\n// '${'🐕'.repeat(124)}'`,
'\x1B[1C\x1B[1A',
'\x1B[5G', '\x1B[1A',
'\x1B[1B', '\x1B[2K', '\x1B[1A',
'\x1B[1G', '\x1B[0J',
'> x', '\x1B[4G', '3',
`\n// '${'𐐷'.repeat(248)}'`,
'\x1B[1C\x1B[1A',
'\x1B[5G', '\x1B[1A',
'\x1B[1B', '\x1B[2K', '\x1B[1A',
'\x1B[1G', '\x1B[0J',
'> x', '\x1B[4G', '4',
`\n// 'a${'\u0301'.repeat(1000)}'`,
'\x1B[2D\x1B[1A',
'\x1B[5G', '\x1B[1A',
'\x1B[1B', '\x1B[2K', '\x1B[1A',
'\x1B[1G', '\x1B[0J',
'> ', '\x1B[3G', 'y', '1',
`\n// '${'あ'.repeat(121)}...`,
'\x1B[245D\x1B[1A',
'\x1B[5G', '\x1B[1A',
'\x1B[1B', '\x1B[2K', '\x1B[1A',
'\x1B[1G', '\x1B[0J',
'> y', '\x1B[4G', '2',
`\n// '${'🐕'.repeat(121)}...`,
'\x1B[245D\x1B[1A',
'\x1B[5G', '\x1B[1A',
'\x1B[1B', '\x1B[2K', '\x1B[1A',
'\x1B[1G', '\x1B[0J',
'> y', '\x1B[4G', '3',
`\n// '${'𐐷'.repeat(242)}...`,
'\x1B[245D\x1B[1A',
'\x1B[5G', '\x1B[1A',
'\x1B[1B', '\x1B[2K', '\x1B[1A',
'\r\n',
'\x1B[1G', '\x1B[0J',
Expand Down
14 changes: 7 additions & 7 deletions test/parallel/test-repl-preview.js
Expand Up @@ -68,12 +68,12 @@ async function tests(options) {
const testCases = [
['foo', [2, 4], '[Function: foo]',
'foo',
'\x1B[90m[Function: foo]\x1B[39m\x1B[5D\x1B[1A\x1B[1B\x1B[2K\x1B[1A\r',
'\x1B[90m[Function: foo]\x1B[39m\x1B[11G\x1B[1A\x1B[1B\x1B[2K\x1B[1A\r',
'\x1B[36m[Function: foo]\x1B[39m',
'\x1B[1G\x1B[0Jrepl > \x1B[8G'],
['koo', [2, 4], '[Function: koo]',
'k\x1B[90moo\x1B[39m\x1B[9G\x1B[0Ko\x1B[90mo\x1B[39m\x1B[10G\x1B[0Ko',
'\x1B[90m[Function: koo]\x1B[39m\x1B[5D\x1B[1A\x1B[1B\x1B[2K\x1B[1A\r',
'\x1B[90m[Function: koo]\x1B[39m\x1B[11G\x1B[1A\x1B[1B\x1B[2K\x1B[1A\r',
'\x1B[36m[Function: koo]\x1B[39m',
'\x1B[1G\x1B[0Jrepl > \x1B[8G'],
['a', [1, 2], undefined],
Expand All @@ -83,19 +83,19 @@ async function tests(options) {
'\x1B[1G\x1B[0Jrepl > \x1B[8G'],
['1n + 2n', [2, 5], '\x1B[33m3n\x1B[39m',
'1n + 2',
'\x1B[90mType[39m\x1B[57D\x1B[1A\x1B[1B\x1B[2K\x1B[1An',
'\x1B[90m3n\x1B[39m\x1B[12C\x1B[1A\x1B[1B\x1B[2K\x1B[1A\r',
'\x1B[90mType[39m\x1B[14G\x1B[1A\x1B[1B\x1B[2K\x1B[1An',
'\x1B[90m3n\x1B[39m\x1B[15G\x1B[1A\x1B[1B\x1B[2K\x1B[1A\r',
'\x1B[33m3n\x1B[39m',
'\x1B[1G\x1B[0Jrepl > \x1B[8G'],
['{ a: true };', [2, 4], '\x1B[33mtrue\x1B[39m',
'{ a: tru\x1B[90me\x1B[39m\x1B[16G\x1B[0Ke };',
'\x1B[90mtrue\x1B[39m\x1B[15C\x1B[1A\x1B[1B\x1B[2K\x1B[1A\r',
'\x1B[90mtrue\x1B[39m\x1B[20G\x1B[1A\x1B[1B\x1B[2K\x1B[1A\r',
'\x1B[33mtrue\x1B[39m',
'\x1B[1G\x1B[0Jrepl > \x1B[8G'],
[' \t { a: true};', [2, 5], '\x1B[33mtrue\x1B[39m',
' \t { a: tru\x1B[90me\x1B[39m\x1B[26G\x1B[0Ke}',
'\x1B[90m{ a: true }\x1B[39m\x1B[16C\x1B[1A\x1B[1B\x1B[2K\x1B[1A;',
'\x1B[90mtrue\x1B[39m\x1B[24C\x1B[1A\x1B[1B\x1B[2K\x1B[1A\r',
'\x1B[90m{ a: true }\x1B[39m\x1B[28G\x1B[1A\x1B[1B\x1B[2K\x1B[1A;',
'\x1B[90mtrue\x1B[39m\x1B[29G\x1B[1A\x1B[1B\x1B[2K\x1B[1A\r',
'\x1B[33mtrue\x1B[39m',
'\x1B[1G\x1B[0Jrepl > \x1B[8G']
];
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-repl-reverse-search.js
Expand Up @@ -223,7 +223,7 @@ const tests = [
'\r\n',
'\x1B[1G', '\x1B[0J',
prompt, '\x1B[3G',
'1', '+', '1', '\n// 2', '\x1B[1C\x1B[1A',
'1', '+', '1', '\n// 2', '\x1B[6G', '\x1B[1A',
'\x1B[1B', '\x1B[2K', '\x1B[1A',
'\r\n',
'2\n',
Expand All @@ -239,7 +239,7 @@ const tests = [
'2\n',
'\x1B[1G', '\x1B[0J',
prompt, '\x1B[3G',
'2', '\n// 2', '\x1B[1D\x1B[1A',
'2', '\n// 2', '\x1B[4G', '\x1B[1A',
'\x1B[1B', '\x1B[2K', '\x1B[1A',
'\nbck-i-search: _', '\x1B[1A', '\x1B[4G',
'\x1B[3G', '\x1B[0J',
Expand All @@ -252,7 +252,7 @@ const tests = [
`${prompt}ab = "aaaa"`, '\x1B[14G',
'\x1B[1G', '\x1B[0J',
`${prompt}repl.repl.historyIndex`, '\x1B[25G', '\n// 8',
'\x1B[20C\x1B[1A',
'\x1B[25G', '\x1B[1A',
'\x1B[1B', '\x1B[2K', '\x1B[1A',
'\nfwd-i-search: _', '\x1B[1A', '\x1B[25G',
'\x1B[3G', '\x1B[0J',
Expand Down