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

Implement bracketed paste insert #655

Merged
merged 1 commit into from
May 8, 2024
Merged

Conversation

tompng
Copy link
Member

@tompng tompng commented Mar 19, 2024

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
Copy link
Member

@ima1zumi ima1zumi left a comment

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!

@@ -66,6 +67,12 @@ def self.set_default_key_bindings(config, allow_terminfo: true)
end
end

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
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
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
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
Development

Successfully merging this pull request may close these issues.

Continue implement bracketed paste mode
2 participants