GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — readline: add paste bracket mode - fixes #45213 by jcubic · Pull Request #47150 · nodejs/node

Conversation

@jcubic

@jcubic jcubic commented Mar 18, 2023 •
edited by aduh95
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bricss reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@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

jcubic commented Mar 18, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jcubic
jcubic force-pushed the paste-bracket branch from 5fadb17 to c17d42b Compare March 18, 2023 18:40
@jcubic jcubic changed the title add paste bracket mode - fixes #45213 readline: add paste bracket mode - fixes #45213 Mar 18, 2023
@jcubic
jcubic force-pushed the paste-bracket branch from a32e9f6 to 8e338e3 Compare March 19, 2023 09:53
@jcubic jcubic mentioned this pull request Apr 14, 2023
Readline paste bracket mode #45213
Closed
bnoordhuis
bnoordhuis approved these changes Apr 14, 2023
View reviewed changes
@jcubic

jcubic commented Jun 16, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jcubic

jcubic commented Jul 6, 2023

Copy link
Copy Markdown
Contributor Author

@bnoordhuis what is the status?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bnoordhuis

bnoordhuis commented Jul 7, 2023

Copy link
Copy Markdown
Member

@nodejs/repl - review requested

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

cola119
cola119 approved these changes Jul 12, 2023
View reviewed changes
@aduh95 aduh95 added author ready PRs with CI started, the required approvals, and no outstanding review comments. request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. labels Jul 16, 2023
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Jul 16, 2023
@nodejs-github-bot

nodejs-github-bot commented Jul 16, 2023

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/52793/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jcubic

jcubic commented Jul 16, 2023

Copy link
Copy Markdown
Contributor Author

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Jul 17, 2023
CI Reliability 2023-07-17 nodejs/reliability#615
Open
CI Reliability 2023-07-18 nodejs/reliability#616
Open
CI Reliability 2023-07-19 nodejs/reliability#617
Open
CI Reliability 2023-07-20 nodejs/reliability#618
Open
CI Reliability 2023-07-21 nodejs/reliability#619
Open
@nodejs-github-bot

nodejs-github-bot commented Jul 30, 2023

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/52987/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Aug 1, 2023
CI Reliability 2023-08-01 nodejs/reliability#630
Open
CI Reliability 2023-08-02 nodejs/reliability#631
Open
CI Reliability 2023-08-03 nodejs/reliability#632
Open
CI Reliability 2023-08-04 nodejs/reliability#633
Open
@aduh95 aduh95 added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Aug 10, 2023
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Aug 10, 2023
@nodejs-github-bot

nodejs-github-bot commented Aug 10, 2023

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/53140/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot

nodejs-github-bot commented Aug 10, 2023

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/53149/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot mentioned this pull request Aug 11, 2023
CI Reliability 2023-08-11 nodejs/reliability#634
Open
1 of 29 tasks
@nodejs-github-bot

nodejs-github-bot commented Aug 11, 2023

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/53199/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot

nodejs-github-bot commented Aug 12, 2023

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/53227/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@aduh95
aduh95 force-pushed the paste-bracket branch from 8e338e3 to b730b80 Compare August 12, 2023 11:39
@jcubic @aduh95
readline: add paste bracket mode
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 <[email protected]>
Reviewed-By: Kohei Ueno <[email protected]>
@aduh95
aduh95 force-pushed the paste-bracket branch from b730b80 to 87af913 Compare August 12, 2023 11:39
@aduh95

aduh95 commented Aug 12, 2023

Copy link
Copy Markdown
Contributor

Landed in 87af913

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@aduh95
aduh95 merged commit 87af913 into nodejs:main Aug 12, 2023
This was referenced Aug 13, 2023
CI Reliability 2023-08-13 nodejs/reliability#635
Open
CI Reliability 2023-08-14 nodejs/reliability#636
Open
Ceres6 pushed a commit to Ceres6/node that referenced this pull request Aug 14, 2023
@jcubic @Ceres6
readline: add paste bracket mode
240cf4a
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 pull request Aug 14, 2023
@jcubic @Ceres6
readline: add paste bracket mode
a8123e9
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 pull request Aug 15, 2023
@jcubic @RafaelGSS
readline: add paste bracket mode
71e383e
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]>
@UlisesGascon UlisesGascon mentioned this pull request Aug 15, 2023
v20.6.0 proposal #49185
Merged
RafaelGSS pushed a commit to RafaelGSS/node that referenced this pull request Aug 15, 2023
@jcubic @RafaelGSS
readline: add paste bracket mode
56ad64b
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 pull request Aug 16, 2023
@jcubic @RafaelGSS
readline: add paste bracket mode
85d1289
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 pull request Aug 17, 2023
@jcubic @RafaelGSS
readline: add paste bracket mode
8380800
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 pull request Nov 27, 2023
@jcubic @targos
readline: add paste bracket mode
a625f22
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 targos mentioned this pull request Nov 28, 2023
v18.19.0 release proposal #50953
Merged
sercher added a commit to sercher/graaljs that referenced this pull request Apr 25, 2024
@sercher
readline: add paste bracket mode
b37c3a8
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 pull request Apr 25, 2024
@sercher
readline: add paste bracket mode
7ea61e1
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]>
@addaleax addaleax mentioned this pull request Jan 23, 2025
feat(cli-repl): add support for bracketed paste in REPL MONGOSH-1909 mongodb-js/mongosh#2328
Merged
@addaleax addaleax mentioned this pull request May 2, 2025
deps: update libuv to 1.51.0 #58124
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@bnoordhuis bnoordhuis bnoordhuis approved these changes
@cola119 cola119 cola119 approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. needs-ci PRs that need a full CI run. readline Issues and PRs related to the built-in readline module.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Readline paste bracket mode

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@jcubic @bnoordhuis @nodejs-github-bot @aduh95 @cola119
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.