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

Conversation

jcubic
Copy link
Contributor

@jcubic jcubic commented 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.

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

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. readline Issues and PRs related to the built-in readline module. labels Mar 18, 2023
@jcubic
Copy link
Contributor Author

jcubic commented Mar 18, 2023

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.

@jcubic jcubic changed the title add paste bracket mode - fixes #45213 readline: add paste bracket mode - fixes #45213 Mar 18, 2023
@jcubic
Copy link
Contributor Author

jcubic commented Jun 16, 2023

What's now? When this will be merged? It's been two months since this issue was approved.

@jcubic
Copy link
Contributor Author

jcubic commented Jul 6, 2023

@bnoordhuis what is the status?

@bnoordhuis
Copy link
Member

@nodejs/repl - review requested

@aduh95 aduh95 added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels Jul 16, 2023
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 16, 2023
@nodejs-github-bot
Copy link
Collaborator

@jcubic
Copy link
Contributor Author

jcubic commented Jul 16, 2023

Will check the test when I get back home. Any clue why tests failed on Linux?

@nodejs-github-bot
Copy link
Collaborator

@aduh95 aduh95 added the request-ci Add this label to start a Jenkins CI on a PR. label Aug 10, 2023
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Aug 10, 2023
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

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>
aduh95 pushed a commit to jcubic/node that referenced this pull request 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 <info@bnoordhuis.nl>
Reviewed-By: Kohei Ueno <kohei.ueno119@gmail.com>
@aduh95
Copy link
Contributor

aduh95 commented Aug 12, 2023

Landed in 87af913

@aduh95 aduh95 merged commit 87af913 into nodejs:main Aug 12, 2023
37 checks passed
Ceres6 pushed a commit to Ceres6/node that referenced this pull request 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 <info@bnoordhuis.nl>
Reviewed-By: Kohei Ueno <kohei.ueno119@gmail.com>
Ceres6 pushed a commit to Ceres6/node that referenced this pull request 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 <info@bnoordhuis.nl>
Reviewed-By: Kohei Ueno <kohei.ueno119@gmail.com>
RafaelGSS pushed a commit that referenced this pull request 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 <info@bnoordhuis.nl>
Reviewed-By: Kohei Ueno <kohei.ueno119@gmail.com>
@UlisesGascon UlisesGascon mentioned this pull request Aug 15, 2023
RafaelGSS pushed a commit to RafaelGSS/node that referenced this pull request 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 <info@bnoordhuis.nl>
Reviewed-By: Kohei Ueno <kohei.ueno119@gmail.com>
rluvaton pushed a commit to rluvaton/node that referenced this pull request 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 <info@bnoordhuis.nl>
Reviewed-By: Kohei Ueno <kohei.ueno119@gmail.com>
RafaelGSS pushed a commit that referenced this pull request 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 <info@bnoordhuis.nl>
Reviewed-By: Kohei Ueno <kohei.ueno119@gmail.com>
RafaelGSS pushed a commit that referenced this pull request 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 <info@bnoordhuis.nl>
Reviewed-By: Kohei Ueno <kohei.ueno119@gmail.com>
targos pushed a commit that referenced this pull request 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 <info@bnoordhuis.nl>
Reviewed-By: Kohei Ueno <kohei.ueno119@gmail.com>
sercher added a commit to sercher/graaljs that referenced this pull request 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 <info@bnoordhuis.nl>
Reviewed-By: Kohei Ueno <kohei.ueno119@gmail.com>
sercher added a commit to sercher/graaljs that referenced this pull request 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 <info@bnoordhuis.nl>
Reviewed-By: Kohei Ueno <kohei.ueno119@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. needs-ci PRs that need a full CI run. readline Issues and PRs related to the built-in readline module.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Readline paste bracket mode
5 participants