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

readline: fix position computation #28272

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/readline.js
Original file line number Diff line number Diff line change
Expand Up @@ -732,8 +732,9 @@ Interface.prototype._getDisplayPos = function(str) {
i++;
}
if (code === 0x0a) { // new line \n
// row must be incremented by 1 even if offset = 0 or col = +Infinity
row += Math.ceil(offset / col) || 1;
offset = 0;
row += 1;
continue;
}
const width = getStringWidth(code);
Expand Down
19 changes: 18 additions & 1 deletion test/parallel/test-readline-interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ function isWarned(emitter) {
rli.close();
}

// multi-line cursor position
// Multi-line input cursor position
{
const fi = new FakeInput();
const rli = new readline.Interface({
Expand All @@ -1079,6 +1079,23 @@ function isWarned(emitter) {
rli.close();
}

// Multi-line prompt cursor position
{
const fi = new FakeInput();
const rli = new readline.Interface({
input: fi,
output: fi,
prompt: '\nfilledline\nwraping text\n> ',
terminal: terminal
});
fi.columns = 10;
fi.emit('data', 't');
const cursorPos = rli._getCursorPos();
assert.strictEqual(cursorPos.rows, 4);
assert.strictEqual(cursorPos.cols, 3);
rli.close();
}

// Clear the whole screen
{
const fi = new FakeInput();
Expand Down