Import upstream version 0.13.0+git20221101.1.6fd0ee9
Debian Janitor
1 year, 6 months ago
0 | version: 2 | |
1 | updates: | |
2 | - package-ecosystem: "gomod" | |
3 | directory: "/" | |
4 | schedule: | |
5 | interval: "daily" | |
6 | labels: | |
7 | - "dependencies" | |
8 | - package-ecosystem: "github-actions" | |
9 | directory: "/" | |
10 | schedule: | |
11 | interval: "daily" | |
12 | labels: | |
13 | - "dependencies" |
0 | name: build | |
1 | on: [push, pull_request] | |
2 | jobs: | |
3 | build: | |
4 | strategy: | |
5 | matrix: | |
6 | go-version: [~1.13, ^1] | |
7 | os: [ubuntu-latest, macos-latest, windows-latest] | |
8 | runs-on: ${{ matrix.os }} | |
9 | env: | |
10 | GO111MODULE: "on" | |
11 | steps: | |
12 | - name: Install Go | |
13 | uses: actions/setup-go@v3 | |
14 | with: | |
15 | go-version: ${{ matrix.go-version }} | |
16 | ||
17 | - name: Checkout code | |
18 | uses: actions/checkout@v3 | |
19 | ||
20 | - name: Download Go modules | |
21 | run: go mod download | |
22 | ||
23 | - name: Build | |
24 | run: go build -v ./... | |
25 | ||
26 | - name: Test | |
27 | run: go test ./... | |
28 | if: matrix.platform != 'windows-latest' |
0 | name: coverage | |
1 | on: [push, pull_request] | |
2 | ||
3 | jobs: | |
4 | coverage: | |
5 | strategy: | |
6 | matrix: | |
7 | go-version: [^1] | |
8 | os: [ubuntu-latest] | |
9 | runs-on: ${{ matrix.os }} | |
10 | env: | |
11 | GO111MODULE: "on" | |
12 | steps: | |
13 | - name: Install Go | |
14 | uses: actions/setup-go@v3 | |
15 | with: | |
16 | go-version: ${{ matrix.go-version }} | |
17 | ||
18 | - name: Checkout code | |
19 | uses: actions/checkout@v3 | |
20 | ||
21 | - name: Coverage | |
22 | env: | |
23 | COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
24 | run: | | |
25 | go test -race -covermode atomic -coverprofile=profile.cov ./... | |
26 | GO111MODULE=off go get github.com/mattn/goveralls | |
27 | $(go env GOPATH)/bin/goveralls -coverprofile=profile.cov -service=github |
0 | name: lint-soft | |
1 | on: | |
2 | push: | |
3 | pull_request: | |
4 | ||
5 | permissions: | |
6 | contents: read | |
7 | # Optional: allow read access to pull request. Use with `only-new-issues` option. | |
8 | pull-requests: read | |
9 | ||
10 | jobs: | |
11 | golangci: | |
12 | name: lint-soft | |
13 | runs-on: ubuntu-latest | |
14 | steps: | |
15 | - uses: actions/checkout@v3 | |
16 | - name: golangci-lint | |
17 | uses: golangci/golangci-lint-action@v3 | |
18 | with: | |
19 | # Optional: golangci-lint command line arguments. | |
20 | args: --config .golangci-soft.yml --issues-exit-code=0 | |
21 | # Optional: show only new issues if it's a pull request. The default value is `false`. | |
22 | only-new-issues: true |
0 | name: lint | |
1 | on: | |
2 | push: | |
3 | pull_request: | |
4 | ||
5 | permissions: | |
6 | contents: read | |
7 | # Optional: allow read access to pull request. Use with `only-new-issues` option. | |
8 | pull-requests: read | |
9 | ||
10 | jobs: | |
11 | golangci: | |
12 | name: lint | |
13 | runs-on: ubuntu-latest | |
14 | steps: | |
15 | - uses: actions/checkout@v3 | |
16 | - name: golangci-lint | |
17 | uses: golangci/golangci-lint-action@v3 | |
18 | with: | |
19 | # Optional: golangci-lint command line arguments. | |
20 | #args: | |
21 | # Optional: show only new issues if it's a pull request. The default value is `false`. | |
22 | only-new-issues: true |
0 | # Binaries for programs and plugins | |
1 | *.exe | |
2 | *.exe~ | |
3 | *.dll | |
4 | *.so | |
5 | *.dylib | |
6 | ||
7 | # Test binary, built with `go test -c` | |
8 | *.test | |
9 | ||
10 | # Output of the go coverage tool, specifically when used with LiteIDE | |
11 | *.out | |
12 | ||
13 | # Dependency directories (remove the comment below to include it) | |
14 | # vendor/ |
247 | 247 | |
248 | 248 | // Show the cursor |
249 | 249 | output.ShowCursor() |
250 | ||
251 | // Copy to clipboard | |
252 | output.Copy(message) | |
253 | ||
254 | // Trigger notification | |
255 | output.Notify(title, body) | |
250 | 256 | ``` |
251 | 257 | |
252 | 258 | ## Mouse |
293 | 299 | termenv.DisableBracketedPaste() |
294 | 300 | ``` |
295 | 301 | |
296 | ## Optional Feature Support | |
297 | ||
298 | | Terminal | Alt Screen | Query Color Scheme | Query Cursor Position | Set Window Title | Change Cursor Color | Change Default Foreground Setting | Change Default Background Setting | Copy (OSC52) | Hyperlinks (OSC8) | Bracketed Paste | | |
299 | | ---------------- | :--------: | :----------------: | :-------------------: | :--------------: | :-----------------: | :-------------------------------: | :-------------------------------: | :----------: | :---------------: | :-------------: | | |
300 | | alacritty | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌[^alacritty] | ✅ | | |
301 | | foot | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | |
302 | | kitty | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | |
303 | | Konsole | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | ❌[^konsole] | ✅ | ✅ | | |
304 | | rxvt | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ✅ | | |
305 | | urxvt | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅[^urxvt] | ❌ | ✅ | | |
306 | | screen | ✅ | ⛔[^mux] | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ | ❌[^screen] | ❌ | | |
307 | | st | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | | |
308 | | tmux | ✅ | ⛔[^mux] | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌[^tmux] | ✅ | | |
309 | | vte-based[^vte] | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌[^vte] | ✅ | ✅ | | |
310 | | wezterm | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | |
311 | | xterm | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ | ❌ | ✅ | | |
312 | | Linux Console | ✅ | ❌ | ✅ | ⛔ | ❌ | ❌ | ❌ | ⛔ | ⛔ | ❌ | | |
313 | | Apple Terminal | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅[^apple] | ❌ | ✅ | | |
314 | | iTerm | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | | |
315 | | Windows cmd | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | | |
316 | | Windows Terminal | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | |
302 | ## Terminal Feature Support | |
303 | ||
304 | ### Color Support | |
305 | ||
306 | - 24-bit (RGB): alacritty, foot, iTerm, kitty, Konsole, st, tmux, vte-based, wezterm, Windows Terminal | |
307 | - 8-bit (256): rxvt, screen, xterm, Apple Terminal | |
308 | - 4-bit (16): Linux Console | |
309 | ||
310 | ### Control Sequences | |
311 | ||
312 | <details> | |
313 | <summary>Click to show feature matrix</summary> | |
314 | ||
315 | | Terminal | Query Color Scheme | Query Cursor Position | Set Window Title | Change Cursor Color | Change Default Foreground Setting | Change Default Background Setting | Bracketed Paste | | |
316 | | ---------------- | :----------------: | :-------------------: | :--------------: | :-----------------: | :-------------------------------: | :-------------------------------: | :-------------: | | |
317 | | alacritty | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | |
318 | | foot | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | |
319 | | kitty | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | |
320 | | Konsole | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | | |
321 | | rxvt | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | |
322 | | urxvt | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | |
323 | | screen | ⛔[^mux] | ✅ | ✅ | ❌ | ❌ | ✅ | ❌ | | |
324 | | st | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | |
325 | | tmux | ⛔[^mux] | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | |
326 | | vte-based[^vte] | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | | |
327 | | wezterm | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | |
328 | | xterm | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ | | |
329 | | Linux Console | ❌ | ✅ | ⛔ | ❌ | ❌ | ❌ | ❌ | | |
330 | | Apple Terminal | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | | |
331 | | iTerm | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ | | |
332 | | Windows cmd | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | | |
333 | | Windows Terminal | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | |
334 | ||
335 | [^vte]: This covers all vte-based terminals, including Gnome Terminal, guake, Pantheon Terminal, Terminator, Tilix, XFCE Terminal. | |
336 | [^mux]: Unavailable as multiplexers (like tmux or screen) can be connected to multiple terminals (with different color settings) at the same time. | |
337 | ||
338 | You can help improve this list! Check out [how to](ansi_compat.md) and open an issue or pull request. | |
339 | ||
340 | </details> | |
341 | ||
342 | ### System Commands | |
343 | ||
344 | <details> | |
345 | <summary>Click to show feature matrix</summary> | |
346 | ||
347 | | Terminal | Copy to Clipboard (OSC52) | Hyperlinks (OSC8) | Notifications (OSC777) | | |
348 | | ---------------- | :-----------------------: | :---------------: | :--------------------: | | |
349 | | alacritty | ✅ | ❌[^alacritty] | ❌ | | |
350 | | foot | ✅ | ✅ | ✅ | | |
351 | | kitty | ✅ | ✅ | ✅ | | |
352 | | Konsole | ❌[^konsole] | ✅ | ❌ | | |
353 | | rxvt | ❌ | ❌ | ❌ | | |
354 | | urxvt | ✅[^urxvt] | ❌ | ✅ | | |
355 | | screen | ✅ | ❌[^screen] | ❌ | | |
356 | | st | ✅ | ❌ | ❌ | | |
357 | | tmux | ✅ | ❌[^tmux] | ❌ | | |
358 | | vte-based[^vte] | ❌[^vte] | ✅ | ❌ | | |
359 | | wezterm | ✅ | ✅ | ❌ | | |
360 | | xterm | ✅ | ❌ | ❌ | | |
361 | | Linux Console | ⛔ | ⛔ | ❌ | | |
362 | | Apple Terminal | ✅[^apple] | ❌ | ❌ | | |
363 | | iTerm | ✅ | ✅ | ❌ | | |
364 | | Windows cmd | ❌ | ❌ | ❌ | | |
365 | | Windows Terminal | ✅ | ✅ | ❌ | | |
317 | 366 | |
318 | 367 | [^vte]: This covers all vte-based terminals, including Gnome Terminal, guake, Pantheon Terminal, Terminator, Tilix, XFCE Terminal. OSC52 is not supported, see [issue#2495](https://gitlab.gnome.org/GNOME/vte/-/issues/2495). |
319 | [^mux]: Unavailable as multiplexers (like tmux or screen) can be connected to multiple terminals (with different color settings) at the same time. | |
320 | 368 | [^urxvt]: Workaround for urxvt not supporting OSC52. See [this](https://unix.stackexchange.com/a/629485) for more information. |
321 | 369 | [^konsole]: OSC52 is not supported, for more info see [bug#372116](https://bugs.kde.org/show_bug.cgi?id=372116). |
322 | 370 | [^apple]: OSC52 works with a [workaround](https://github.com/roy2220/osc52pty). |
324 | 372 | [^screen]: OSC8 is not supported, for more info see [bug#50952](https://savannah.gnu.org/bugs/index.php?50952). |
325 | 373 | [^alacritty]: OSC8 is not supported, for more info see [issue#922](https://github.com/alacritty/alacritty/issues/922). |
326 | 374 | |
327 | You can help improve this list! Check out [how to](ansi_compat.md) and open an issue or pull request. | |
328 | ||
329 | ### Color Support | |
330 | ||
331 | - 24-bit (RGB): alacritty, foot, iTerm, kitty, Konsole, st, tmux, vte-based, wezterm, Windows Terminal | |
332 | - 8-bit (256): rxvt, screen, xterm, Apple Terminal | |
333 | - 4-bit (16): Linux Console | |
375 | </details> | |
334 | 376 | |
335 | 377 | ## Platform Support |
336 | 378 |
54 | 54 | ```bash |
55 | 55 | echo -ne "\033[?2004h" && sleep 10 |
56 | 56 | ``` |
57 | ||
58 | ## Trigger Notification | |
59 | ||
60 | This command should trigger a notification: | |
61 | ||
62 | ```bash | |
63 | echo -ne "\033]777;notify;Title;Body\033\\" | |
64 | ``` |
116 | 116 | } |
117 | 117 | |
118 | 118 | switch { |
119 | case strings.HasSuffix(s, "\a"): | |
120 | s = strings.TrimSuffix(s, "\a") | |
121 | case strings.HasSuffix(s, "\033"): | |
122 | s = strings.TrimSuffix(s, "\033") | |
123 | case strings.HasSuffix(s, "\033\\"): | |
124 | s = strings.TrimSuffix(s, "\033\\") | |
119 | case strings.HasSuffix(s, string(BEL)): | |
120 | s = strings.TrimSuffix(s, string(BEL)) | |
121 | case strings.HasSuffix(s, string(ESC)): | |
122 | s = strings.TrimSuffix(s, string(ESC)) | |
123 | case strings.HasSuffix(s, ST): | |
124 | s = strings.TrimSuffix(s, ST) | |
125 | 125 | default: |
126 | 126 | return RGBColor(""), ErrInvalidColor |
127 | 127 | } |
52 | 52 | fmt.Printf("\t%q copied to clipboard\n", hw) |
53 | 53 | fmt.Println() |
54 | 54 | |
55 | termenv.Notify("Termenv", hw) | |
56 | fmt.Print("\tTriggered a notification") | |
57 | fmt.Println() | |
58 | ||
55 | 59 | fmt.Printf("\t%s", termenv.Hyperlink("http://example.com", "This is a link")) |
56 | 60 | fmt.Println() |
57 | 61 | } |
2 | 2 | go 1.13 |
3 | 3 | |
4 | 4 | require ( |
5 | github.com/aymanbagabas/go-osc52 v1.0.3 | |
5 | github.com/aymanbagabas/go-osc52 v1.2.1 | |
6 | 6 | github.com/lucasb-eyer/go-colorful v1.2.0 |
7 | 7 | github.com/mattn/go-isatty v0.0.16 |
8 | 8 | github.com/mattn/go-runewidth v0.0.14 |
0 | github.com/aymanbagabas/go-osc52 v1.0.3 h1:DTwqENW7X9arYimJrPeGZcV0ln14sGMt3pHZspWD+Mg= | |
1 | github.com/aymanbagabas/go-osc52 v1.0.3/go.mod h1:zT8H+Rk4VSabYN90pWyugflM3ZhpTZNC7cASDfUCdT4= | |
0 | github.com/aymanbagabas/go-osc52 v1.2.1 h1:q2sWUyDcozPLcLabEMd+a+7Ea2DitxZVN9hTxab9L4E= | |
1 | github.com/aymanbagabas/go-osc52 v1.2.1/go.mod h1:zT8H+Rk4VSabYN90pWyugflM3ZhpTZNC7cASDfUCdT4= | |
2 | 2 | github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= |
3 | 3 | github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= |
4 | 4 | github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ= |
0 | 0 | package termenv |
1 | ||
2 | import ( | |
3 | "fmt" | |
4 | ) | |
5 | 1 | |
6 | 2 | // Hyperlink creates a hyperlink using OSC8. |
7 | 3 | func Hyperlink(link, name string) string { |
10 | 6 | |
11 | 7 | // Hyperlink creates a hyperlink using OSC8. |
12 | 8 | func (o *Output) Hyperlink(link, name string) string { |
13 | return fmt.Sprintf("\x1b]8;;%s\x1b\\%s\x1b]8;;\x1b\\", link, name) | |
9 | return OSC + "8;;" + link + ST + name + OSC + "8;;" + ST | |
14 | 10 | } |
0 | package termenv | |
1 | ||
2 | // Notify triggers a notification using OSC777. | |
3 | func Notify(title, body string) { | |
4 | output.Notify(title, body) | |
5 | } | |
6 | ||
7 | // Notify triggers a notification using OSC777. | |
8 | func (o *Output) Notify(title, body string) { | |
9 | _, _ = o.WriteString(OSC + "777;notify;" + title + ";" + body + ST) | |
10 | } |
56 | 56 | EndBracketedPasteSeq = "201~" |
57 | 57 | |
58 | 58 | // Session. |
59 | SetWindowTitleSeq = "2;%s\007" | |
60 | SetForegroundColorSeq = "10;%s\007" | |
61 | SetBackgroundColorSeq = "11;%s\007" | |
62 | SetCursorColorSeq = "12;%s\007" | |
59 | SetWindowTitleSeq = "2;%s" + string(BEL) | |
60 | SetForegroundColorSeq = "10;%s" + string(BEL) | |
61 | SetBackgroundColorSeq = "11;%s" + string(BEL) | |
62 | SetCursorColorSeq = "12;%s" + string(BEL) | |
63 | 63 | ShowCursorSeq = "?25h" |
64 | 64 | HideCursorSeq = "?25l" |
65 | 65 | ) |
11 | 11 | ) |
12 | 12 | |
13 | 13 | const ( |
14 | // Escape character | |
15 | ESC = '\x1b' | |
16 | // Bell | |
17 | BEL = '\a' | |
14 | 18 | // Control Sequence Introducer |
15 | CSI = "\x1b[" | |
19 | CSI = string(ESC) + "[" | |
16 | 20 | // Operating System Command |
17 | OSC = "\x1b]" | |
21 | OSC = string(ESC) + "]" | |
22 | // String Terminator | |
23 | ST = string(ESC) + `\` | |
18 | 24 | ) |
19 | 25 | |
20 | 26 | func (o *Output) isTTY() bool { |
159 | 159 | } |
160 | 160 | |
161 | 161 | // first byte must be ESC |
162 | for start != '\033' { | |
162 | for start != ESC { | |
163 | 163 | start, err = readNextByte(fd) |
164 | 164 | if err != nil { |
165 | 165 | return "", false, err |
196 | 196 | |
197 | 197 | if oscResponse { |
198 | 198 | // OSC can be terminated by BEL (\a) or ST (ESC) |
199 | if b == '\a' || strings.HasSuffix(response, "\033") { | |
199 | if b == BEL || strings.HasSuffix(response, string(ESC)) { | |
200 | 200 | return response, true, nil |
201 | 201 | } |
202 | 202 | } else { |
248 | 248 | } |
249 | 249 | |
250 | 250 | // first, send OSC query, which is ignored by terminal which do not support it |
251 | fmt.Fprintf(tty, "\033]%d;?\033\\", sequence) | |
251 | fmt.Fprintf(tty, OSC+"%d;?"+ST, sequence) | |
252 | 252 | |
253 | 253 | // then, query cursor position, should be supported by all terminals |
254 | fmt.Fprintf(tty, "\033[6n") | |
254 | fmt.Fprintf(tty, CSI+"6n") | |
255 | 255 | |
256 | 256 | // read the next response |
257 | 257 | res, isOSC, err := readNextResponse(tty) |