Skip to content

Implement bracketed paste insert - #655

Merged
ima1zumi merged 1 commit into
ruby:masterfrom
tompng:bracketed_paste
May 8, 2024
Merged

ima1zumi merged 1 commit into
ruby:masterfrom
tompng:bracketed_paste

Conversation

@tompng

@tompng tompng commented Mar 19, 2024 •

Copy link
Copy Markdown
Member

Closes #631

Description

Implemented bracketed paste. Directly inserts pasted text.

This will speedup paste (1100 lines in 8sec → 2600 lines in 8sec)
Stops tab-complete while pasting code that includes tab
Code using tab indentation can be pasted to reline

Bracketed paste implementation

Reline had a code for bracketed paste but it seems not working.
(Escape sequence for bracketed paste start and end was also wrong)

irb(main):001> puts "\e[?2004h";gets
(paste text `text` here and press enter)
^[[200~text^[[201~
=> "\e[200~text\e[201~\n" # this is the correct start and end sequence

Readline compatibility

Readline(>= 8.1) enables bracketed paste by default. set enable-bracketed-paste off will disable it.
Readline accepts bracketed paste input "\e[200~text\e[201~" even if it's disabled in inputrc.

inputrc read

Changed inputrc read timing. Reline should read inputrc before io_gate.prep

@tompng
tompng force-pushed the bracketed_paste branch 2 times, most recently from cb57eae to c9262ea Compare April 17, 2024 17:37
@tompng
tompng marked this pull request as ready for review April 17, 2024 17:47
@ima1zumi ima1zumi added the enhancement New feature or request label Apr 29, 2024
@tompng
tompng force-pushed the bracketed_paste branch from f486059 to bc16e62 Compare May 2, 2024 16:45

@ima1zumi ima1zumi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Paste is now very fast! Thanks!

Comment thread lib/reline/ansi.rb

def self.set_bracketed_paste_key_bindings(config)
[:emacs, :vi_insert, :vi_command].each do |keymap|
config.add_default_key_binding_by_keymap(keymap, START_BRACKETED_PASTE.bytes, :bracketed_paste_start)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

q: Bracketed paste doesn't seem like a keybinding since it's sent from the terminal, not the user. Why is it set here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bracketed paste start sequence \e[200~ is very similar to some keys: kf9=\E[20~, knp=\E[6~, kpp=\E[5~.
We can't distinguish them until we read the 5th or 6th bytes. So treating them as same as keybinding is one of the simple way to implement it.
We can think key bindings (processed in class KeyStroke) as a transformation layer of byte stream (includes many kind of escape sequences) to meaningful symbols.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. It's similar to the terminal capabilities. Your explanation that it deals with byte streams made sense. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Continue implement bracketed paste mode

2 participants