-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
Conversation
I was testing this code with something like this, this is a basic test: const readline = require('readline');
let cmd = '';
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
// add the paste bracket markers to output code
process.stdin.on('keypress', (c, k) => {
if (k?.name?.match(/^paste-/)) {
cmd += k.sequence;
}
});
// enable paste bracket mode
process.stdout.write('\x1b[?2004h');
rl.on('line', function(line) {
cmd += line;
// we clear old paste brackets that we don't need anymore
if (cmd.match(/\x1b\[201~$/)) {
cmd = cmd.replace(/\x1b\[(200|201)~/g, '');
}
cmd += '\n';
// get rid of the opening paste bracket
const code = cmd.replace(/\x1b\[200~/g, '');
// first you check if this is multiline if the code ends
// my case is lisp code it's easy to check
// if there are balanced parentheses
if (/* multi-line */) {
if (cmd.match(/\x1b\[200~/)) {
// do indentation when copy-pasting the code
// you can check if the code is indented or not
} else {
// user pressed enter so you can use normal auto-indent
}
} else {
// evaluate the code
}
}); in the base case when you want to indent the next line you check if cmd has paste brackets code and you evaluate the code variable. |
What's now? When this will be merged? It's been two months since this issue was approved. |
@bnoordhuis what is the status? |
@nodejs/repl - review requested |
Will check the test when I get back home. Any clue why tests failed on Linux? |
The paste bracket mode allows REPL to have auto-indentation that is handled differently when the user copy-pastes the code from the clipboard and the code already has an indentation. PR-URL: nodejs#47150 Fixes: nodejs#45213 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Kohei Ueno <kohei.ueno119@gmail.com>
The paste bracket mode allows REPL to have auto-indentation that is handled differently when the user copy-pastes the code from the clipboard and the code already has an indentation. PR-URL: nodejs#47150 Fixes: nodejs#45213 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Kohei Ueno <kohei.ueno119@gmail.com>
Landed in 87af913 |
The paste bracket mode allows REPL to have auto-indentation that is handled differently when the user copy-pastes the code from the clipboard and the code already has an indentation. PR-URL: nodejs#47150 Fixes: nodejs#45213 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Kohei Ueno <kohei.ueno119@gmail.com>
The paste bracket mode allows REPL to have auto-indentation that is handled differently when the user copy-pastes the code from the clipboard and the code already has an indentation. PR-URL: nodejs#47150 Fixes: nodejs#45213 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Kohei Ueno <kohei.ueno119@gmail.com>
The paste bracket mode allows REPL to have auto-indentation that is handled differently when the user copy-pastes the code from the clipboard and the code already has an indentation. PR-URL: #47150 Fixes: #45213 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Kohei Ueno <kohei.ueno119@gmail.com>
The paste bracket mode allows REPL to have auto-indentation that is handled differently when the user copy-pastes the code from the clipboard and the code already has an indentation. PR-URL: nodejs#47150 Fixes: nodejs#45213 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Kohei Ueno <kohei.ueno119@gmail.com>
The paste bracket mode allows REPL to have auto-indentation that is handled differently when the user copy-pastes the code from the clipboard and the code already has an indentation. PR-URL: nodejs#47150 Fixes: nodejs#45213 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Kohei Ueno <kohei.ueno119@gmail.com>
The paste bracket mode allows REPL to have auto-indentation that is handled differently when the user copy-pastes the code from the clipboard and the code already has an indentation. PR-URL: #47150 Fixes: #45213 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Kohei Ueno <kohei.ueno119@gmail.com>
The paste bracket mode allows REPL to have auto-indentation that is handled differently when the user copy-pastes the code from the clipboard and the code already has an indentation. PR-URL: #47150 Fixes: #45213 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Kohei Ueno <kohei.ueno119@gmail.com>
The paste bracket mode allows REPL to have auto-indentation that is handled differently when the user copy-pastes the code from the clipboard and the code already has an indentation. PR-URL: #47150 Fixes: #45213 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Kohei Ueno <kohei.ueno119@gmail.com>
The paste bracket mode allows REPL to have auto-indentation that is handled differently when the user copy-pastes the code from the clipboard and the code already has an indentation. PR-URL: nodejs/node#47150 Fixes: nodejs/node#45213 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Kohei Ueno <kohei.ueno119@gmail.com>
The paste bracket mode allows REPL to have auto-indentation that is handled differently when the user copy-pastes the code from the clipboard and the code already has an indentation. PR-URL: nodejs/node#47150 Fixes: nodejs/node#45213 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Kohei Ueno <kohei.ueno119@gmail.com>
The paste bracket mode allows REPL to have auto-indentation that is handled differently when the user copy-pastes the code from the clipboard and the code already has an indentation.
There are no unit tests because there is no way to test copy-pate. You will need to have the equivalent of Cypress or Playwright for Terminal to test (but I'm also not sure if you can easily test copy-paste in those front-end frameworks).
Fixes: #45213