Codebase list golang-github-muesli-termenv / 62f13c9
Import upstream version 0.13.0+git20221101.1.6fd0ee9 Debian Janitor 1 year, 6 months ago
18 changed file(s) with 120 addition(s) and 186 deletion(s). Raw diff Collapse all Expand all
+0
-1
.github/FUNDING.yml less more
0 github: muesli
+0
-14
.github/dependabot.yml less more
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
-29
.github/workflows/build.yml less more
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
-28
.github/workflows/coverage.yml less more
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
-23
.github/workflows/lint-soft.yml less more
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
-23
.github/workflows/lint.yml less more
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
-15
.gitignore less more
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/
247247
248248 // Show the cursor
249249 output.ShowCursor()
250
251 // Copy to clipboard
252 output.Copy(message)
253
254 // Trigger notification
255 output.Notify(title, body)
250256 ```
251257
252258 ## Mouse
293299 termenv.DisableBracketedPaste()
294300 ```
295301
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 | ✅ | ✅ | ❌ |
317366
318367 [^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.
320368 [^urxvt]: Workaround for urxvt not supporting OSC52. See [this](https://unix.stackexchange.com/a/629485) for more information.
321369 [^konsole]: OSC52 is not supported, for more info see [bug#372116](https://bugs.kde.org/show_bug.cgi?id=372116).
322370 [^apple]: OSC52 works with a [workaround](https://github.com/roy2220/osc52pty).
324372 [^screen]: OSC8 is not supported, for more info see [bug#50952](https://savannah.gnu.org/bugs/index.php?50952).
325373 [^alacritty]: OSC8 is not supported, for more info see [issue#922](https://github.com/alacritty/alacritty/issues/922).
326374
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>
334376
335377 ## Platform Support
336378
5454 ```bash
5555 echo -ne "\033[?2004h" && sleep 10
5656 ```
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 ```
116116 }
117117
118118 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)
125125 default:
126126 return RGBColor(""), ErrInvalidColor
127127 }
5252 fmt.Printf("\t%q copied to clipboard\n", hw)
5353 fmt.Println()
5454
55 termenv.Notify("Termenv", hw)
56 fmt.Print("\tTriggered a notification")
57 fmt.Println()
58
5559 fmt.Printf("\t%s", termenv.Hyperlink("http://example.com", "This is a link"))
5660 fmt.Println()
5761 }
22 go 1.13
33
44 require (
5 github.com/aymanbagabas/go-osc52 v1.0.3
5 github.com/aymanbagabas/go-osc52 v1.2.1
66 github.com/lucasb-eyer/go-colorful v1.2.0
77 github.com/mattn/go-isatty v0.0.16
88 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=
22 github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
33 github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
44 github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
00 package termenv
1
2 import (
3 "fmt"
4 )
51
62 // Hyperlink creates a hyperlink using OSC8.
73 func Hyperlink(link, name string) string {
106
117 // Hyperlink creates a hyperlink using OSC8.
128 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
1410 }
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 }
5656 EndBracketedPasteSeq = "201~"
5757
5858 // 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)
6363 ShowCursorSeq = "?25h"
6464 HideCursorSeq = "?25l"
6565 )
1111 )
1212
1313 const (
14 // Escape character
15 ESC = '\x1b'
16 // Bell
17 BEL = '\a'
1418 // Control Sequence Introducer
15 CSI = "\x1b["
19 CSI = string(ESC) + "["
1620 // Operating System Command
17 OSC = "\x1b]"
21 OSC = string(ESC) + "]"
22 // String Terminator
23 ST = string(ESC) + `\`
1824 )
1925
2026 func (o *Output) isTTY() bool {
159159 }
160160
161161 // first byte must be ESC
162 for start != '\033' {
162 for start != ESC {
163163 start, err = readNextByte(fd)
164164 if err != nil {
165165 return "", false, err
196196
197197 if oscResponse {
198198 // 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)) {
200200 return response, true, nil
201201 }
202202 } else {
248248 }
249249
250250 // 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)
252252
253253 // then, query cursor position, should be supported by all terminals
254 fmt.Fprintf(tty, "\033[6n")
254 fmt.Fprintf(tty, CSI+"6n")
255255
256256 // read the next response
257257 res, isOSC, err := readNextResponse(tty)