Skip to content

Commit

Permalink
Bracketed paste sequences
Browse files Browse the repository at this point in the history
  • Loading branch information
knz authored and muesli committed Aug 19, 2022
1 parent 504165e commit d980a37
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 18 deletions.
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)
}

0 comments on commit d980a37

Please sign in to comment.