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

Support bracketed-paste terminal mode #53

Open
rhysd opened this issue Nov 18, 2023 · 0 comments
Open

Support bracketed-paste terminal mode #53

rhysd opened this issue Nov 18, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@rhysd
Copy link
Owner

rhysd commented Nov 18, 2023

Both crossterm and termwiz are supporting bracketed-paste:

  • crossterm opts in bracketed-paste when EnableBracketedPaste is executed. Pasted text is sent via Event::Paste.
  • termwiz automatically enables bracketed-paste if the terminal supports it. And there is no way to disable it. Pasted text is sent via InputEvent::Paste.

However tui-textarea doesn't support bracketed-paste yet. When pasting some text through terminal, the pasted text from terminal is simply ignored.

It's possible to handle the paste event in user side. However it has the following downsides:

  • Those who are not familiar with terminals usually don't know bracketed-paste.
  • Users need to know the details of backend-specific input events. Users should be able to use Input::from without knowing the details of backend-specific input event.
  • Multiple lines are joined with \r. Users need to replace \r with \n before setting the pasted text via TextArea::set_yank_text.

TextArea::input should handle the bracketed-paste events. This feature will require restructuring Input struct into enum because they are not key inputs. Currently tui-textarea assumes all inputs are by keyboard (though mouse virtual keys are already not fitting to this assumption well). The assumption is no longer applicable.

Before:

struct Input {
    key: Key,
    ctrl: bool,
    // ... 
}

After:

struct KeyInput {
    key: Key,
    ctrl: bool,
    // ...
}

struct MouseInput {
    mouse: Mouse,
    ctrl: bool,
    // ...
}

enum Input {
    Key(KeyInput),
    Mouse(MouseInput),
    Paste(String),
}

This means that the input structure is made more complicated. Input can no longer derive Copy.

@rhysd rhysd added the enhancement New feature or request label Nov 18, 2023
@rhysd rhysd changed the title Support bracked-paste terminal mode Support bracketed-paste terminal mode Nov 18, 2023
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

No branches or pull requests

1 participant