From c255e086f652762b1a9a0541e9cbe118c246c749 Mon Sep 17 00:00:00 2001 From: Raphael 'kena' Poss Date: Sun, 14 Aug 2022 18:21:09 +0200 Subject: [PATCH] Bracketed paste sequences --- README.md | 46 ++++++++++++++++++++++++++++------------------ ansi_compat.md | 9 +++++++++ screen.go | 17 +++++++++++++++++ 3 files changed, 54 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index aeece33..28e9c38 100644 --- a/README.md +++ b/README.md @@ -277,26 +277,36 @@ termenv.EnableMouseAllMotion() termenv.DisableMouseAllMotion() ``` +## Bracketed Paste + +```go +// Enables bracketed paste mode +termenv.EnableBracketedPaste() + +// Disables bracketed paste mode +termenv.DisableBracketedPaste() +``` + ## Optional Feature Support -| Terminal | Alt Screen | Query Color Scheme | Query Cursor Position | Set Window Title | Change Cursor Color | Change Default Foreground Setting | Change Default Background Setting | -| ---------------- | :--------: | :----------------: | :-------------------: | :--------------: | :-----------------: | :-------------------------------: | :-------------------------------: | -| alacritty | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| foot | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| kitty | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| Konsole | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | -| rxvt | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | -| screen | ✅ | ⛔[^mux] | ✅ | ✅ | ❌ | ❌ | ✅ | -| st | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| tmux | ✅ | ⛔[^mux] | ✅ | ✅ | ✅ | ✅ | ✅ | -| vte-based[^vte] | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | -| wezterm | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| xterm | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | -| Linux Console | ✅ | ❌ | ✅ | ⛔ | ❌ | ❌ | ❌ | -| Apple Terminal | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | -| iTerm | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | -| Windows cmd | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | -| Windows Terminal | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Terminal | Alt Screen | Query Color Scheme | Query Cursor Position | Set Window Title | Change Cursor Color | Change Default Foreground Setting | Change Default Background Setting | Bracketed Paste | +| ---------------- | :--------: | :----------------: | :-------------------: | :--------------: | :-----------------: | :-------------------------------: | :-------------------------------: | :-------------: | +| alacritty | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| foot | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| kitty | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Konsole | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | +| rxvt | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| screen | ✅ | ⛔[^mux] | ✅ | ✅ | ❌ | ❌ | ✅ | ❌ | +| st | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| tmux | ✅ | ⛔[^mux] | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| vte-based[^vte] | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | +| wezterm | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| xterm | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ | +| Linux Console | ✅ | ❌ | ✅ | ⛔ | ❌ | ❌ | ❌ | ❌ | +| Apple Terminal | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | +| iTerm | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ | +| Windows cmd | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | +| Windows Terminal | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | [^vte]: This covers all vte-based terminals, including Gnome Terminal, guake, Pantheon Terminal, Terminator, Tilix, XFCE Terminal. [^mux]: Unavailable as multiplexers (like tmux or screen) can be connected to multiple terminals (with different color settings) at the same time. diff --git a/ansi_compat.md b/ansi_compat.md index 67ef4e4..b403d74 100644 --- a/ansi_compat.md +++ b/ansi_compat.md @@ -46,3 +46,12 @@ This command should set the window title to "Test": ```bash echo -ne "\033]2;Test\007" && sleep 10 ``` + +## Bracketed paste + +Enter this command, then paste a word from the clipboard. The text +displayed on the terminal should contain the codes `200~` and `201~`: + +```bash +echo -ne "\033[?2004h" && sleep 10 +``` diff --git a/screen.go b/screen.go index 897bebc..ada21e6 100644 --- a/screen.go +++ b/screen.go @@ -49,6 +49,13 @@ const ( AltScreenSeq = "?1049h" ExitAltScreenSeq = "?1049l" + // Bracketed paste. + // https://en.wikipedia.org/wiki/Bracketed-paste + EnableBracketedPasteSeq = "?2004h" + DisableBracketedPasteSeq = "?2004l" + StartBracketedPasteSeq = "200~" + EndBracketedPasteSeq = "201~" + // Session. SetWindowTitleSeq = "2;%s\007" SetForegroundColorSeq = "10;%s\007" @@ -256,3 +263,13 @@ func DisableMouseAllMotion() { func SetWindowTitle(title string) { fmt.Printf(OSC+SetWindowTitleSeq, title) } + +// EnableBracketedPaste enables bracketed paste. +func EnableBracketedPaste() { + fmt.Print(CSI + EnableBracketedPasteSeq) +} + +// DisableBracketedPaste disables bracketed paste. +func DisableBracketedPaste() { + fmt.Print(CSI + DisableBracketedPasteSeq) +}