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 paste bracket mode #45213

Closed
jcubic opened this issue Oct 27, 2022 · 10 comments · Fixed by #47150
Closed

Readline paste bracket mode #45213

jcubic opened this issue Oct 27, 2022 · 10 comments · Fixed by #47150
Labels
feature request Issues that request new features to be added to Node.js.

Comments

@jcubic
Copy link
Contributor

jcubic commented Oct 27, 2022

What is the problem this feature will solve?

Found recently about paste bracket mode that would help solve the issue with auto-indentation in NodeJS-based REPLs.

I've asked on StackOveflow but no one answered because I think no one uses such a feature, because no one knows that this exists.

How to use terminal bracket paste mode in Nodejs REPL?

You can read about paste bracket mode on Wikipedia.

What is the feature you are proposing to solve the problem?

Add paste bracket mode to NodeJS readline.

What alternatives have you considered?

The alternatives are flaky hacks.

@jcubic jcubic added the feature request Issues that request new features to be added to Node.js. label Oct 27, 2022
@jcubic
Copy link
Contributor Author

jcubic commented Mar 15, 2023

Aditional notes

A quick intro to how paste brackets work:

You print this escape sequence:

process.stdout.write('\x1b[?2004h');

and terminal will include \x1b[200~ and \x1b[201~ at the end and the beginning of the pasting text. This allows for the addition of proper indentation to the code if you have language REPL.

If your REPL is a programming language and you auto-indent the user input when copy-paste long code you can skip the auto-indentation if the input text is in paste brackets.

I have an application when I was testing this but the line event removes the escape sequence \x1b[200 and \x1b[201 and only ~ is left which is of no use since the user may add this to the text.

There is a need for some kind of API (like a flag) to turn on paste brackets and send it with a line event so it can be processed. It can even be always sent since to turn this on you need to write the \x1b[?2004h escape sequence.

Without this, you need to use hacks to fix the auto-indentation, but I was not able to create a proper hack for my REPL.

@bnoordhuis
Copy link
Member

@jcubic seems like a reasonable thing to support. PR welcome.

@jcubic
Copy link
Contributor Author

jcubic commented Mar 16, 2023

I was looking at the code for readline and I have no idea where ANSI escapes codes are removed.

@bnoordhuis
Copy link
Member

Probably emitKeys() in lib/internal/readline/utils.js.

@jcubic
Copy link
Contributor Author

jcubic commented Mar 17, 2023

@bnoordhuis I will try to see what I can do.

One question can you build Node and run it without installation, I don't want to mess up NVM and my local Node installation (I use Fedora GNU/Linux).

Edit:
I'm building right now

@bnoordhuis
Copy link
Member

@jcubic yes, the binary ends up in out/Release and you can run it from there.

jcubic added a commit to jcubic/node that referenced this issue Mar 18, 2023
The paste bracket mode allow REPL to have auto-indentation
that is handled differently when user copy paste the code
from the clipboard and the code already have indantation.
@jcubic
Copy link
Contributor Author

jcubic commented Mar 18, 2023

I've created a PR, it was testing it with my REPL, and it works much better. I can have a proper auto-indentation without any effort.

I can also update documentation for Node 20 if the feature will be included with that version.

jcubic added a commit to jcubic/node that referenced this issue Mar 18, 2023
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.
jcubic added a commit to jcubic/node that referenced this issue Mar 19, 2023
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.
@jcubic
Copy link
Contributor Author

jcubic commented Apr 8, 2023

@bnoordhuis how long it takes for CI/CD to run? I'm waiting 3 weeks for triggering the GitHub action.

@bnoordhuis
Copy link
Member

@jcubic can you link me to the pull request?

@jcubic
Copy link
Contributor Author

jcubic commented Apr 14, 2023

Yes, sorry it seems that only commit is linked: #47150

aduh95 pushed a commit to jcubic/node that referenced this issue Aug 12, 2023
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 <[email protected]>
Reviewed-By: Kohei Ueno <[email protected]>
@aduh95 aduh95 closed this as completed in 87af913 Aug 12, 2023
Ceres6 pushed a commit to Ceres6/node that referenced this issue Aug 14, 2023
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 <[email protected]>
Reviewed-By: Kohei Ueno <[email protected]>
Ceres6 pushed a commit to Ceres6/node that referenced this issue Aug 14, 2023
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 <[email protected]>
Reviewed-By: Kohei Ueno <[email protected]>
RafaelGSS pushed a commit that referenced this issue Aug 15, 2023
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 <[email protected]>
Reviewed-By: Kohei Ueno <[email protected]>
RafaelGSS pushed a commit to RafaelGSS/node that referenced this issue Aug 15, 2023
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 <[email protected]>
Reviewed-By: Kohei Ueno <[email protected]>
rluvaton pushed a commit to rluvaton/node that referenced this issue Aug 15, 2023
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 <[email protected]>
Reviewed-By: Kohei Ueno <[email protected]>
RafaelGSS pushed a commit that referenced this issue Aug 16, 2023
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 <[email protected]>
Reviewed-By: Kohei Ueno <[email protected]>
RafaelGSS pushed a commit that referenced this issue Aug 17, 2023
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 <[email protected]>
Reviewed-By: Kohei Ueno <[email protected]>
targos pushed a commit that referenced this issue Nov 27, 2023
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 <[email protected]>
Reviewed-By: Kohei Ueno <[email protected]>
sercher added a commit to sercher/graaljs that referenced this issue Apr 25, 2024
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 <[email protected]>
Reviewed-By: Kohei Ueno <[email protected]>
sercher added a commit to sercher/graaljs that referenced this issue Apr 25, 2024
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 <[email protected]>
Reviewed-By: Kohei Ueno <[email protected]>
@RedYetiDev RedYetiDev moved this from Awaiting Triage to Done in Node.js feature requests Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants