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: add paste bracket mode - fixes #45213 #47150

Merged
merged 1 commit into from
Aug 12, 2023
Merged
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
22 changes: 18 additions & 4 deletions lib/internal/readline/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,10 @@ function* emitKeys(stream) {
*
* - `;5` part is optional, e.g. it could be `\x1b[24~`
* - first part can contain one or two digits
* - there is also special case when there can be 3 digits
* but without modifier. They are the case of paste bracket mode
*
* So the generic regexp is like /^\d\d?(;\d)?[~^$]$/
* So the generic regexp is like /^(?:\d\d?(;\d)?[~^$]|\d{3}~)$/
*
*
* 2. `\x1b[1;5H` should be parsed as { code: '[H', modifier: 5 }
Expand All @@ -170,6 +172,10 @@ function* emitKeys(stream) {

if (ch >= '0' && ch <= '9') {
s += (ch = yield);

if (ch >= '0' && ch <= '9') {
s += (ch = yield);
}
}
}

Expand All @@ -189,9 +195,13 @@ function* emitKeys(stream) {
const cmd = StringPrototypeSlice(s, cmdStart);
let match;

if ((match = RegExpPrototypeExec(/^(\d\d?)(;(\d))?([~^$])$/, cmd))) {
code += match[1] + match[4];
modifier = (match[3] || 1) - 1;
if ((match = RegExpPrototypeExec(/^(?:(\d\d?)(?:;(\d))?([~^$])|(\d{3}~))$/, cmd))) {
if (match[4]) {
code += match[4];
} else {
code += match[1] + match[3];
modifier = (match[2] || 1) - 1;
}
} else if (
(match = RegExpPrototypeExec(/^((\d;)?(\d))?([A-Za-z])$/, cmd))
) {
Expand Down Expand Up @@ -228,6 +238,10 @@ function* emitKeys(stream) {
case '[13~': key.name = 'f3'; break;
case '[14~': key.name = 'f4'; break;

/* paste bracket mode */
case '[200~': key.name = 'paste-start'; break;
case '[201~': key.name = 'paste-end'; break;

/* from Cygwin and used in libuv */
case '[[A': key.name = 'f1'; break;
case '[[B': key.name = 'f2'; break;
Expand Down