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

Bracketed paste sequences #84

Merged
merged 1 commit into from Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 28 additions & 18 deletions README.md
Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions ansi_compat.md
Expand Up @@ -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
```
17 changes: 17 additions & 0 deletions screen.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}