mirror of
https://github.com/nodejs/node.git
synced 2026-11-25 23:01:06 -05:00
repl: fix preview cursor position
The cusor position was off in case the preview was exactly as long as the current terminal was wide. PR-URL: https://github.com/nodejs/node/pull/31293 Fixes: https://github.com/nodejs/node/issues/31291 Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com> Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
1 parent
f588301f2d
commit
3867f2095e
4 files changed
+22
-22
No files matched your search
@@ -382,9 +382,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);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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',
|
||||
|
||||
@@ -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],
|
||||
@@ -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']
|
||||
];
|
||||
|
||||
@@ -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',
|
||||
@@ -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',
|
||||
@@ -252,7 +252,7 @@ const tests = [
|
||||
`${prompt}ab = "aaaa"`, '\x1B[14G',
|
||||
'\x1B[1G', '\x1B[0J',
|
||||
`${prompt}repl.repl.historyIndex`, '\x1B[25G', '\n// -1',
|
||||
'\x1B[19C\x1B[1A',
|
||||
'\x1B[25G', '\x1B[1A',
|
||||
'\x1B[1B', '\x1B[2K', '\x1B[1A',
|
||||
'\nfwd-i-search: _', '\x1B[1A', '\x1B[25G',
|
||||
'\x1B[3G', '\x1B[0J',
|
||||
|
||||
Reference in new issue
Block a user