rhysd/tui-textarea

Support bracketed-paste terminal mode

rhysd opened this issue · 0 comments

rhysd commented

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.