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

feat: bracketed paste #397

Merged
merged 3 commits into from Feb 5, 2024
Merged

feat: bracketed paste #397

merged 3 commits into from Feb 5, 2024

Conversation

knz
Copy link
Contributor

@knz knz commented Aug 14, 2022

First 3 commits from #568, #569 and #570.
Partial fix to #404

This introduces support for input via bracketed paste, where escape
characters in the pasted input are not interpreted.
Pasted input are marked as a special field in the KeyMsg.
This is because pasted input may need sanitation in individual widgets.

cc @maaslalani @muesli

@knz
Copy link
Contributor Author

knz commented Aug 19, 2022

As discussed with @muesli I changed the PR to always enable bracked paste, unless the option WithoutBracketedPaste is specified on the program.

key.go Outdated
//
// The rune array is modified in-place. The returned slice
// is the original slice shortened after the control characters have been removed.
func SanitizeRunes(runes []rune, replaceNewLine rune) []rune {
Copy link
Member

Choose a reason for hiding this comment

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

Is there any particular reason this function needs to be exported?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it's for use here: charmbracelet/bubbles#214

I'm expecting any widget that wants to handle multi-rune input to need this (regardless of bracketed paste), so it deserves to be a common utility function.

@knz

This comment was marked as outdated.

@muesli
Copy link
Member

muesli commented Oct 13, 2022

Rebasing.

@muesli muesli force-pushed the bracketed-paste branch 3 times, most recently from 1eacdc1 to 23fe7a1 Compare October 13, 2022 04:29
@knz

This comment was marked as outdated.

@knz knz force-pushed the bracketed-paste branch 5 times, most recently from 71d1d7d to a38be3c Compare January 7, 2023 20:28
@knz knz changed the title Support bracketed paste feat: bracketed paste Jan 7, 2023
@knz
Copy link
Contributor Author

knz commented Jan 7, 2023

@muesli this is ready again.

@knz
Copy link
Contributor Author

knz commented Apr 22, 2023

@muesli in case you haven't found it already, this patch has a shortcoming: certain terminal emulators feed the pasted datas as non-continuous writes to the terminal buffer, so the bubbletea code can sometimes read less than len(buf) before the paste end marker is encountered.

I will iterate and submit a better version.

@knz
Copy link
Contributor Author

knz commented Apr 22, 2023

I have added a commit on top of the original branch. @muesli you can look at just the diff for the latest commit to see what you need to change on your branch.

@xprnio
Copy link

xprnio commented Dec 15, 2023

Bumping. I have a use-case similar to #800 and would love to be able to detect ctrl+enter, but AFAIK this PR is what would solve that.

@nadimkobeissi
Copy link

Please merge this!

@muesli muesli force-pushed the bracketed-paste branch 2 times, most recently from c0359b4 to 0af1b45 Compare January 31, 2024 12:54
knz and others added 3 commits January 31, 2024 14:02
This introduces support for input via bracketed paste, where escape
characters in the pasted input are not interpreted.

Pasted input are marked as a special field in the KeyMsg. This is
useful because pasted input may need sanitation in individual widgets.
Some terminal emulators feed the bracketed paste data in multiple
chunks, which may not be aligned on a 256 byte boundary. So it's
possible for `input.Read` to return less than 256 bytes read
but while there's still more data to be read to complete a bracketed
paste input.
@muesli muesli merged commit 2b46020 into charmbracelet:master Feb 5, 2024
9 checks passed
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.

None yet

5 participants