├── .appveyor.yml ├── .github ├── FUNDING.yml ├── dependabot.yml └── workflows │ ├── coverage.yml │ ├── linux.yml │ └── windows.yml ├── .gitignore ├── .travis.yml ├── AUTHORS ├── CHANGESv2.md ├── LICENSE ├── README-wasm.md ├── README.md ├── SECURITY.md ├── TUTORIAL.md ├── UKRAINE.md ├── _demos ├── beep.go ├── boxes.go ├── clipboard.go ├── colors.go ├── cursors.go ├── hello_world.go ├── hyperlink.go ├── mouse.go ├── setsize.go ├── sixel.go ├── stress.go ├── style.go └── unicode.go ├── attr.go ├── cell.go ├── charset_stub.go ├── charset_unix.go ├── charset_windows.go ├── color.go ├── color_test.go ├── colorfit.go ├── console_stub.go ├── console_win.go ├── doc.go ├── encoding.go ├── encoding ├── all.go └── encoding_init_test.go ├── encoding_test.go ├── errors.go ├── event.go ├── event_test.go ├── focus.go ├── go.mod ├── go.sum ├── interrupt.go ├── key.go ├── logos ├── patreon.png ├── staysail.png ├── tcell.png └── tidelift.png ├── mouse.go ├── nonblock_bsd.go ├── nonblock_unix.go ├── paste.go ├── resize.go ├── runes.go ├── runes_test.go ├── screen.go ├── sim_test.go ├── simulation.go ├── stdin_unix.go ├── style.go ├── style_test.go ├── termbox └── compat.go ├── terminfo ├── .gitignore ├── README.md ├── TERMINALS.md ├── a │ ├── aixterm │ │ └── term.go │ ├── alacritty │ │ ├── direct.go │ │ └── term.go │ └── ansi │ │ └── term.go ├── b │ └── beterm │ │ └── term.go ├── base │ └── base.go ├── c │ └── cygwin │ │ └── term.go ├── d │ └── dtterm │ │ └── term.go ├── dynamic │ └── dynamic.go ├── e │ └── emacs │ │ └── term.go ├── extended │ └── extended.go ├── f │ └── foot │ │ └── foot.go ├── g │ └── gnome │ │ └── term.go ├── gen.sh ├── h │ └── hpterm │ │ └── term.go ├── k │ ├── konsole │ │ └── term.go │ └── kterm │ │ └── term.go ├── l │ └── linux │ │ └── term.go ├── mkinfo.go ├── models.txt ├── p │ └── pcansi │ │ └── term.go ├── r │ └── rxvt │ │ └── term.go ├── s │ ├── screen │ │ └── term.go │ ├── simpleterm │ │ └── term.go │ └── sun │ │ └── term.go ├── t │ └── tmux │ │ └── term.go ├── terminfo.go ├── terminfo_test.go ├── v │ ├── vt100 │ │ └── term.go │ ├── vt102 │ │ └── term.go │ ├── vt220 │ │ └── term.go │ ├── vt320 │ │ └── term.go │ ├── vt400 │ │ └── term.go │ ├── vt420 │ │ └── term.go │ └── vt52 │ │ └── term.go ├── w │ ├── wy50 │ │ └── term.go │ ├── wy60 │ │ └── term.go │ └── wy99_ansi │ │ └── term.go └── x │ ├── xfce │ └── term.go │ ├── xterm │ ├── direct.go │ └── term.go │ ├── xterm_ghostty │ └── term.go │ └── xterm_kitty │ └── term.go ├── terms_default.go ├── terms_dynamic.go ├── terms_static.go ├── tscreen.go ├── tscreen_stub.go ├── tscreen_unix.go ├── tty.go ├── tty_unix.go ├── views ├── README.md ├── _demos │ ├── cellview.go │ ├── hbox.go │ └── vbox.go ├── app.go ├── boxlayout.go ├── cellarea.go ├── constants.go ├── panel.go ├── spacer.go ├── sstext.go ├── sstextbar.go ├── text.go ├── text_test.go ├── textarea.go ├── textarea_test.go ├── textbar.go ├── view.go └── widget.go ├── webfiles ├── beep.wav ├── tcell.html ├── tcell.js └── termstyle.css └── wscreen.go /.appveyor.yml: -------------------------------------------------------------------------------- 1 | version: 1.0.{build} 2 | clone_folder: c:\gopath\src\github.com\gdamore\tcell 3 | environment: 4 | GOPATH: c:\gopath 5 | build_script: 6 | - go version 7 | - go env 8 | - SET PATH=%LOCALAPPDATA%\atom\bin;%GOPATH%\bin;%PATH% 9 | - go get -t ./... 10 | - go build 11 | - go install ./... 12 | test_script: 13 | - go test ./... 14 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | patreon: gedamore 2 | github: gdamore 3 | tidelift: go/github.com/gdamore/tcell 4 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: gomod 4 | directory: / 5 | schedule: 6 | interval: weekly 7 | - package-ecosystem: github-actions 8 | directory: / 9 | schedule: 10 | interval: weekly 11 | -------------------------------------------------------------------------------- /.github/workflows/coverage.yml: -------------------------------------------------------------------------------- 1 | name: coverage 2 | on: [push] 3 | jobs: 4 | 5 | build: 6 | name: build 7 | runs-on: ${{ matrix.os }} 8 | strategy: 9 | matrix: 10 | os: [ubuntu-latest, windows-latest] 11 | steps: 12 | 13 | - name: Check out code into the Go module directory 14 | uses: actions/checkout@v4 15 | 16 | - name: Set up Go 17 | uses: actions/setup-go@v5 18 | with: 19 | go-version: 1.18 20 | id: go 21 | 22 | - name: Get dependencies 23 | run: go get -v -t -d ./... 24 | 25 | - name: Build 26 | run: go build -v . 27 | 28 | - name: Test 29 | run: go test -coverpkg="github.com/gdamore/tcell/v2/..." -covermode=count -coverprofile="coverage.txt" ./... 30 | 31 | - name: Upload coverage to Codecov 32 | uses: codecov/codecov-action@v5.1.2 33 | with: 34 | token: ${{ secrets.CODECOV_TOKEN }} 35 | file: ./coverage.txt 36 | flags: unittests 37 | name: codecov-umbrella 38 | yml: ./codecov.yml 39 | -------------------------------------------------------------------------------- /.github/workflows/linux.yml: -------------------------------------------------------------------------------- 1 | name: linux 2 | on: [push] 3 | jobs: 4 | 5 | build: 6 | name: build 7 | runs-on: [ ubuntu-latest ] 8 | steps: 9 | 10 | - name: Check out code into the Go module directory 11 | uses: actions/checkout@v4 12 | 13 | - name: Set up Go 14 | uses: actions/setup-go@v5 15 | with: 16 | go-version: 1.18 17 | id: go 18 | 19 | - name: Go version 20 | run: go version 21 | 22 | - name: Get dependencies 23 | run: go get -v -t -d ./... 24 | 25 | - name: Build 26 | run: go build -v . 27 | 28 | - name: Test 29 | run: go test ./... 30 | -------------------------------------------------------------------------------- /.github/workflows/windows.yml: -------------------------------------------------------------------------------- 1 | name: windows 2 | on: [push] 3 | jobs: 4 | 5 | build: 6 | name: build 7 | runs-on: [ windows-latest ] 8 | steps: 9 | 10 | - name: Check out code into the Go module directory 11 | uses: actions/checkout@v4 12 | 13 | - name: Set up Go 14 | uses: actions/setup-go@v5 15 | with: 16 | go-version: 1.18 17 | id: go 18 | 19 | - name: Get dependencies 20 | run: go get -v -t -d ./... 21 | 22 | - name: Build 23 | run: go build -v . 24 | 25 | - name: Test 26 | run: go test ./... 27 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | coverage.txt 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - 1.15.x 5 | - master 6 | 7 | arch: 8 | - amd64 9 | - ppc64le 10 | 11 | before_install: 12 | - go get -t -v ./... 13 | 14 | script: 15 | - go test -race -coverprofile=coverage.txt -covermode=atomic 16 | 17 | after_success: 18 | - bash <(curl -s https://codecov.io/bash) 19 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Garrett D'Amore 2 | Zachary Yedidia 3 | Junegunn Choi 4 | Staysail Systems, Inc. 5 | -------------------------------------------------------------------------------- /CHANGESv2.md: -------------------------------------------------------------------------------- 1 | ## Breaking Changes in _Tcell_ v2 2 | 3 | A number of changes were made to _Tcell_ for version two, and some of these are breaking. 4 | 5 | ### Import Path 6 | 7 | The import path for tcell has changed to `github.com/gdamore/tcell/v2` to reflect a new major version. 8 | 9 | ### Style Is Not Numeric 10 | 11 | The type `Style` has changed to a structure, to allow us to add additional data such as flags for color setting, 12 | more attribute bits, and so forth. 13 | Applications that relied on this being a number will need to be updated to use the accessor methods. 14 | 15 | ### Mouse Event Changes 16 | 17 | The middle mouse button was reported as button 2 on Linux, but as button 3 on Windows, 18 | and the right mouse button was reported the reverse way. 19 | _Tcell_ now always reports the right mouse button as button 2, and the middle button as button 3. 20 | To help make this clearer, new symbols `ButtonPrimary`, `ButtonSecondary`, and 21 | `ButtonMiddle` are provided. 22 | (Note that which button is right vs. left may be impacted by user preferences. 23 | Usually the left button will be considered the Primary, and the right will be the Secondary.) 24 | Applications may need to adjust their handling of mouse buttons 2 and 3 accordingly. 25 | 26 | ### Terminals Removed 27 | 28 | A number of terminals have been removed. 29 | These are mostly ancient definitions unlikely to be used by anyone, such as `adm3a`. 30 | 31 | ### High Number Function Keys 32 | 33 | Historically terminfo reported function keys with modifiers set as a different 34 | function key altogether. For example, Shift-F1 was reported as F13 on XTerm. 35 | _Tcell_ now prefers to report these using the base key (such as F1) with modifiers added. 36 | This works on XTerm and VTE based emulators, but some emulators may not support this. 37 | The new behavior more closely aligns with behavior on Windows platforms. 38 | 39 | ## New Features in _Tcell_ v2 40 | 41 | These features are not breaking, but are introduced in version 2. 42 | 43 | ### Improved Modifier Support 44 | 45 | For terminals that appear to behave like the venerable XTerm, _tcell_ 46 | automatically adds modifier reporting for ALT, CTRL, SHIFT, and META keys 47 | when the terminal reports them. 48 | 49 | ### Better Support for Palettes (Themes) 50 | 51 | When using a color by its name or palette entry, _Tcell_ now tries to 52 | use that palette entry as is; this should avoid some inconsistency and respect 53 | terminal themes correctly. 54 | 55 | When true fidelity to RGB values is needed, the new `TrueColor()` API can be used 56 | to create a direct color, which bypasses the palette altogether. 57 | 58 | ### Automatic TrueColor Detection 59 | 60 | For some terminals, if the `Tc` or `RGB` properties are present in terminfo, 61 | _Tcell_ will automatically assume the terminal supports 24-bit color. 62 | 63 | ### ColorReset 64 | 65 | A new color value, `ColorReset` can be used on the foreground or background 66 | to reset the color the default used by the terminal. 67 | 68 | ### tmux Support 69 | 70 | _Tcell_ now has improved support for tmux, when the `$TERM` variable is set to "tmux". 71 | 72 | ### Strikethrough Support 73 | 74 | _Tcell_ has support for strikethrough when the terminal supports it, using the new `StrikeThrough()` API. 75 | 76 | ### Bracketed Paste Support 77 | 78 | _Tcell_ provides the long requested capability to discriminate paste event by using the 79 | bracketed-paste capability present in some terminals. This is automatically available on 80 | terminals that support XTerm style mouse handling, but applications must opt-in to this 81 | by using the new `EnablePaste()` function. A new `EventPaste` type of event will be 82 | delivered when starting and finishing a paste operation. -------------------------------------------------------------------------------- /README-wasm.md: -------------------------------------------------------------------------------- 1 | # WASM for _Tcell_ 2 | 3 | You can build _Tcell_ project into a webpage by compiling it slightly differently. This will result in a _Tcell_ project you can embed into another html page, or use as a standalone page. 4 | 5 | ## Building your project 6 | 7 | WASM needs special build flags in order to work. You can build it by executing 8 | ```sh 9 | GOOS=js GOARCH=wasm go build -o yourfile.wasm 10 | ``` 11 | 12 | ## Additional files 13 | 14 | You also need 5 other files in the same directory as the wasm. Four (`tcell.html`, `tcell.js`, `termstyle.css`, and `beep.wav`) are provided in the `webfiles` directory. The last one, `wasm_exec.js`, can be copied from GOROOT into the current directory by executing 15 | ```sh 16 | cp "$(go env GOROOT)/misc/wasm/wasm_exec.js" ./ 17 | ``` 18 | 19 | In `tcell.js`, you also need to change the constant 20 | ```js 21 | const wasmFilePath = "yourfile.wasm" 22 | ``` 23 | to the file you outputted to when building. 24 | 25 | ## Displaying your project 26 | 27 | ### Standalone 28 | 29 | You can see the project (with an white background around the terminal) by serving the directory. You can do this using any framework, including another golang project: 30 | 31 | ```golang 32 | // server.go 33 | 34 | package main 35 | 36 | import ( 37 | "log" 38 | "net/http" 39 | ) 40 | 41 | func main() { 42 | log.Fatal(http.ListenAndServe(":8080", 43 | http.FileServer(http.Dir("/path/to/dir/to/serve")), 44 | )) 45 | } 46 | 47 | ``` 48 | 49 | To see the webpage with this example, you can type in `localhost:8080/tcell.html` into your browser while `server.go` is running. 50 | 51 | ### Embedding 52 | It is recommended to use an iframe if you want to embed the app into a webpage: 53 | ```html 54 | 55 | ``` 56 | 57 | ## Other considerations 58 | 59 | ### Accessing files 60 | 61 | `io.Open(filename)` and other related functions for reading file systems do not work; use `http.Get(filename)` instead. -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # SECURITY 2 | 3 | It's somewhat unlikely that tcell is in a security sensitive path, 4 | but we do take security seriously. 5 | 6 | ## Vulnerabilityu Response 7 | 8 | If you report a vulnerability, we will respond within 2 business days. 9 | 10 | ## Report a Vulnerability 11 | 12 | If you wish to report a vulnerability found in tcell, simply send a message 13 | to garrett@damore.org. You may also reach us on our discord channel - 14 | https://discord.gg/urTTxDN - a private message to `gdamore` on that channel 15 | may be submitted instead of mail. 16 | -------------------------------------------------------------------------------- /_demos/beep.go: -------------------------------------------------------------------------------- 1 | //go:build ignore 2 | // +build ignore 3 | 4 | // Copyright 2019 The TCell Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use file except in compliance with the License. 8 | // You may obtain a copy of the license at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | // beep makes a beep every second until you press ESC 19 | package main 20 | 21 | import ( 22 | "fmt" 23 | "os" 24 | "time" 25 | 26 | "github.com/gdamore/tcell/v2" 27 | ) 28 | 29 | func main() { 30 | tcell.SetEncodingFallback(tcell.EncodingFallbackASCII) 31 | s, e := tcell.NewScreen() 32 | if e != nil { 33 | fmt.Fprintf(os.Stderr, "%v\n", e) 34 | os.Exit(1) 35 | } 36 | if e = s.Init(); e != nil { 37 | fmt.Fprintf(os.Stderr, "%v\n", e) 38 | os.Exit(1) 39 | } 40 | 41 | s.SetStyle(tcell.StyleDefault) 42 | s.Clear() 43 | 44 | quit := make(chan struct{}) 45 | go func() { 46 | for { 47 | ev := s.PollEvent() 48 | switch ev := ev.(type) { 49 | case *tcell.EventKey: 50 | switch ev.Key() { 51 | case tcell.KeyEscape, tcell.KeyEnter, tcell.KeyCtrlC: 52 | close(quit) 53 | return 54 | case tcell.KeyCtrlL: 55 | s.Sync() 56 | } 57 | case *tcell.EventResize: 58 | s.Sync() 59 | } 60 | } 61 | }() 62 | beep(s, quit) 63 | s.Fini() 64 | } 65 | 66 | func beep(s tcell.Screen, quit <-chan struct{}) { 67 | t := time.NewTicker(time.Second) 68 | for { 69 | select { 70 | case <-quit: 71 | return 72 | case <-t.C: 73 | s.Beep() 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /_demos/boxes.go: -------------------------------------------------------------------------------- 1 | //go:build ignore 2 | // +build ignore 3 | 4 | // Copyright 2015 The TCell Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use file except in compliance with the License. 8 | // You may obtain a copy of the license at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | // boxes just displays random colored boxes on your terminal screen. 19 | // Press ESC to exit the program. 20 | package main 21 | 22 | import ( 23 | "fmt" 24 | "math/rand" 25 | "os" 26 | "time" 27 | 28 | "github.com/gdamore/tcell/v2" 29 | ) 30 | 31 | func makebox(s tcell.Screen) { 32 | w, h := s.Size() 33 | 34 | if w == 0 || h == 0 { 35 | return 36 | } 37 | 38 | glyphs := []rune{'@', '#', '&', '*', '=', '%', 'Z', 'A'} 39 | 40 | lx := rand.Int() % w 41 | ly := rand.Int() % h 42 | lw := rand.Int() % (w - lx) 43 | lh := rand.Int() % (h - ly) 44 | st := tcell.StyleDefault 45 | gl := ' ' 46 | if s.Colors() > 256 { 47 | rgb := tcell.NewHexColor(int32(rand.Int() & 0xffffff)) 48 | st = st.Background(rgb) 49 | } else if s.Colors() > 1 { 50 | st = st.Background(tcell.Color(rand.Int()%s.Colors()) | tcell.ColorValid) 51 | } else { 52 | st = st.Reverse(rand.Int()%2 == 0) 53 | gl = glyphs[rand.Int()%len(glyphs)] 54 | } 55 | 56 | for row := 0; row < lh; row++ { 57 | for col := 0; col < lw; col++ { 58 | s.SetCell(lx+col, ly+row, st, gl) 59 | } 60 | } 61 | s.Show() 62 | } 63 | 64 | func main() { 65 | 66 | tcell.SetEncodingFallback(tcell.EncodingFallbackASCII) 67 | s, e := tcell.NewScreen() 68 | if e != nil { 69 | fmt.Fprintf(os.Stderr, "%v\n", e) 70 | os.Exit(1) 71 | } 72 | if e = s.Init(); e != nil { 73 | fmt.Fprintf(os.Stderr, "%v\n", e) 74 | os.Exit(1) 75 | } 76 | 77 | s.SetStyle(tcell.StyleDefault. 78 | Foreground(tcell.ColorBlack). 79 | Background(tcell.ColorWhite)) 80 | s.Clear() 81 | 82 | quit := make(chan struct{}) 83 | go func() { 84 | for { 85 | ev := s.PollEvent() 86 | switch ev := ev.(type) { 87 | case *tcell.EventKey: 88 | switch ev.Key() { 89 | case tcell.KeyEscape, tcell.KeyEnter: 90 | close(quit) 91 | return 92 | case tcell.KeyCtrlL: 93 | s.Sync() 94 | } 95 | case *tcell.EventResize: 96 | s.Sync() 97 | } 98 | } 99 | }() 100 | 101 | cnt := 0 102 | dur := time.Duration(0) 103 | loop: 104 | for { 105 | select { 106 | case <-quit: 107 | break loop 108 | case <-time.After(time.Millisecond * 50): 109 | } 110 | start := time.Now() 111 | makebox(s) 112 | cnt++ 113 | dur += time.Now().Sub(start) 114 | } 115 | 116 | s.Fini() 117 | fmt.Printf("Finished %d boxes in %s\n", cnt, dur) 118 | fmt.Printf("Average is %0.3f ms / box\n", (float64(dur)/float64(cnt))/1000000.0) 119 | } 120 | -------------------------------------------------------------------------------- /_demos/clipboard.go: -------------------------------------------------------------------------------- 1 | //go:build ignore 2 | // +build ignore 3 | 4 | // Copyright 2024 The TCell Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use file except in compliance with the License. 8 | // You may obtain a copy of the license at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | package main 19 | 20 | import ( 21 | "fmt" 22 | "os" 23 | "unicode/utf8" 24 | 25 | "github.com/gdamore/tcell/v2" 26 | "github.com/gdamore/tcell/v2/encoding" 27 | 28 | "github.com/mattn/go-runewidth" 29 | ) 30 | 31 | func emitStr(s tcell.Screen, x, y int, style tcell.Style, str string) { 32 | for _, c := range str { 33 | var comb []rune 34 | w := runewidth.RuneWidth(c) 35 | if w == 0 { 36 | comb = []rune{c} 37 | c = ' ' 38 | w = 1 39 | } 40 | s.SetContent(x, y, c, comb, style) 41 | x += w 42 | } 43 | } 44 | 45 | var clipboard []byte 46 | 47 | func displayHelloWorld(s tcell.Screen) { 48 | w, h := s.Size() 49 | s.Clear() 50 | style := tcell.StyleDefault.Foreground(tcell.ColorCadetBlue.TrueColor()).Background(tcell.ColorWhite) 51 | emitStr(s, w/2-14, h/2, style, "Press 1 to set clipboard") 52 | emitStr(s, w/2-14, h/2+1, style, "Press 2 to get clipboard") 53 | 54 | msg := "" 55 | if utf8.Valid(clipboard) { 56 | cp := string(clipboard) 57 | if len(cp) >= w-25 { 58 | cp = cp[:21] + " ..." 59 | } 60 | msg = fmt.Sprintf("Clipboard (%d bytes): %s", len(clipboard), cp) 61 | } else if clipboard != nil { 62 | msg = fmt.Sprintf("Clipboard (%d bytes) Not Valid UTF-8", len(clipboard)) 63 | } else { 64 | msg = "No clipboard data" 65 | } 66 | emitStr(s, (w-len(msg))/2, h/2+3, tcell.StyleDefault, msg) 67 | emitStr(s, w/2-9, h/2+5, tcell.StyleDefault, "Press ESC to exit.") 68 | s.Show() 69 | } 70 | 71 | // This program just prints "Hello, World!". Press ESC to exit. 72 | func main() { 73 | encoding.Register() 74 | 75 | s, e := tcell.NewScreen() 76 | if e != nil { 77 | fmt.Fprintf(os.Stderr, "%v\n", e) 78 | os.Exit(1) 79 | } 80 | if e := s.Init(); e != nil { 81 | fmt.Fprintf(os.Stderr, "%v\n", e) 82 | os.Exit(1) 83 | } 84 | 85 | defStyle := tcell.StyleDefault. 86 | Background(tcell.ColorBlack). 87 | Foreground(tcell.ColorWhite) 88 | s.SetStyle(defStyle) 89 | 90 | displayHelloWorld(s) 91 | 92 | for { 93 | switch ev := s.PollEvent().(type) { 94 | case *tcell.EventResize: 95 | s.Sync() 96 | displayHelloWorld(s) 97 | case *tcell.EventKey: 98 | switch ev.Key() { 99 | case tcell.KeyRune: 100 | switch ev.Rune() { 101 | case '1': 102 | s.SetClipboard([]byte("Enjoy your new clipboard content!")) 103 | case '2': 104 | s.GetClipboard() 105 | } 106 | case tcell.KeyEscape: 107 | s.Fini() 108 | os.Exit(0) 109 | } 110 | case *tcell.EventClipboard: 111 | clipboard = ev.Data() 112 | displayHelloWorld(s) 113 | } 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /_demos/colors.go: -------------------------------------------------------------------------------- 1 | //go:build ignore 2 | // +build ignore 3 | 4 | // Copyright 2019 The TCell Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use file except in compliance with the License. 8 | // You may obtain a copy of the license at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | // colors just displays a single centered rectangle that should pulse 19 | // through available colors. It uses the RGB color cube, bumping at 20 | // predefined larger intervals (values of about 8) in order that the 21 | // changes happen quickly enough to be appreciable. 22 | // 23 | // Press ESC to exit the program. 24 | package main 25 | 26 | import ( 27 | "fmt" 28 | "math/rand" 29 | "os" 30 | "time" 31 | 32 | "github.com/gdamore/tcell/v2" 33 | ) 34 | 35 | var red = int32(rand.Int() % 256) 36 | var grn = int32(rand.Int() % 256) 37 | var blu = int32(rand.Int() % 256) 38 | var inc = int32(8) // rate of color change 39 | var redi = int32(inc) 40 | var grni = int32(inc) 41 | var blui = int32(inc) 42 | 43 | func makebox(s tcell.Screen) { 44 | w, h := s.Size() 45 | 46 | if w == 0 || h == 0 { 47 | return 48 | } 49 | 50 | glyphs := []rune{'@', '#', '&', '*', '=', '%', 'Z', 'A'} 51 | 52 | lh := h / 2 53 | lw := w / 2 54 | lx := w / 4 55 | ly := h / 4 56 | st := tcell.StyleDefault 57 | gl := ' ' 58 | 59 | if s.Colors() == 0 { 60 | st = st.Reverse(rand.Int()%2 == 0) 61 | gl = glyphs[rand.Int()%len(glyphs)] 62 | } else { 63 | 64 | red += redi 65 | if (red >= 256) || (red < 0) { 66 | redi = -redi 67 | red += redi 68 | } 69 | grn += grni 70 | if (grn >= 256) || (grn < 0) { 71 | grni = -grni 72 | grn += grni 73 | } 74 | blu += blui 75 | if (blu >= 256) || (blu < 0) { 76 | blui = -blui 77 | blu += blui 78 | 79 | } 80 | st = st.Background(tcell.NewRGBColor(red, grn, blu)) 81 | } 82 | for row := 0; row < lh; row++ { 83 | for col := 0; col < lw; col++ { 84 | s.SetCell(lx+col, ly+row, st, gl) 85 | } 86 | } 87 | s.Show() 88 | } 89 | 90 | func flipcoin() bool { 91 | if rand.Int()&1 == 0 { 92 | return false 93 | } 94 | return true 95 | } 96 | 97 | func main() { 98 | 99 | rand.Seed(time.Now().UnixNano()) 100 | tcell.SetEncodingFallback(tcell.EncodingFallbackASCII) 101 | s, e := tcell.NewScreen() 102 | if e != nil { 103 | fmt.Fprintf(os.Stderr, "%v\n", e) 104 | os.Exit(1) 105 | } 106 | if e = s.Init(); e != nil { 107 | fmt.Fprintf(os.Stderr, "%v\n", e) 108 | os.Exit(1) 109 | } 110 | 111 | s.SetStyle(tcell.StyleDefault. 112 | Foreground(tcell.ColorBlack). 113 | Background(tcell.ColorWhite)) 114 | s.Clear() 115 | 116 | quit := make(chan struct{}) 117 | go func() { 118 | for { 119 | ev := s.PollEvent() 120 | switch ev := ev.(type) { 121 | case *tcell.EventKey: 122 | switch ev.Key() { 123 | case tcell.KeyEscape, tcell.KeyEnter: 124 | close(quit) 125 | return 126 | case tcell.KeyCtrlL: 127 | s.Sync() 128 | } 129 | case *tcell.EventResize: 130 | s.Sync() 131 | } 132 | } 133 | }() 134 | 135 | cnt := 0 136 | dur := time.Duration(0) 137 | loop: 138 | for { 139 | select { 140 | case <-quit: 141 | break loop 142 | case <-time.After(time.Millisecond * 50): 143 | } 144 | start := time.Now() 145 | makebox(s) 146 | dur += time.Now().Sub(start) 147 | cnt++ 148 | if cnt%(256/int(inc)) == 0 { 149 | if flipcoin() { 150 | redi = -redi 151 | } 152 | if flipcoin() { 153 | grni = -grni 154 | } 155 | if flipcoin() { 156 | blui = -blui 157 | } 158 | } 159 | } 160 | 161 | s.Fini() 162 | fmt.Printf("Finished %d boxes in %s\n", cnt, dur) 163 | fmt.Printf("Average is %0.3f ms / box\n", (float64(dur)/float64(cnt))/1000000.0) 164 | } 165 | -------------------------------------------------------------------------------- /_demos/cursors.go: -------------------------------------------------------------------------------- 1 | //go:build ignore 2 | // +build ignore 3 | 4 | // Copyright 2022 The TCell Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use file except in compliance with the License. 8 | // You may obtain a copy of the license at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | package main 19 | 20 | import ( 21 | "fmt" 22 | "github.com/gdamore/tcell/v2" 23 | "os" 24 | ) 25 | 26 | func main() { 27 | tcell.SetEncodingFallback(tcell.EncodingFallbackASCII) 28 | s, e := tcell.NewScreen() 29 | if e != nil { 30 | fmt.Fprintf(os.Stderr, "%v\n", e) 31 | os.Exit(1) 32 | } 33 | if e = s.Init(); e != nil { 34 | fmt.Fprintf(os.Stderr, "%v\n", e) 35 | os.Exit(1) 36 | } 37 | 38 | s.SetStyle(tcell.StyleDefault) 39 | s.Clear() 40 | 41 | text := "This demonstrates cursor styles. Press 0 through 6 to change the style." 42 | x := 1 43 | for _, r := range text { 44 | s.SetCell(x, 1, tcell.StyleDefault, r) 45 | x++ 46 | } 47 | s.SetCell(2, 2, tcell.StyleDefault, '0') 48 | s.SetCursorStyle(tcell.CursorStyleDefault) 49 | s.ShowCursor(3, 2) 50 | quit := make(chan struct{}) 51 | style := tcell.StyleDefault 52 | go func() { 53 | for { 54 | s.Show() 55 | ev := s.PollEvent() 56 | switch ev := ev.(type) { 57 | case *tcell.EventKey: 58 | switch ev.Key() { 59 | case tcell.KeyRune: 60 | switch ev.Rune() { 61 | case '0': 62 | s.SetContent(2, 2, '0', nil, style) 63 | s.SetCursorStyle(tcell.CursorStyleDefault, tcell.ColorReset) 64 | case '1': 65 | s.SetContent(2, 2, '1', nil, style) 66 | s.SetCursorStyle(tcell.CursorStyleBlinkingBlock, tcell.ColorGreen) 67 | case '2': 68 | s.SetCell(2, 2, tcell.StyleDefault, '2') 69 | s.SetCursorStyle(tcell.CursorStyleSteadyBlock, tcell.ColorBlue) 70 | case '3': 71 | s.SetCell(2, 2, tcell.StyleDefault, '3') 72 | s.SetCursorStyle(tcell.CursorStyleBlinkingUnderline, tcell.ColorRed) 73 | case '4': 74 | s.SetCell(2, 2, tcell.StyleDefault, '4') 75 | s.SetCursorStyle(tcell.CursorStyleSteadyUnderline, tcell.ColorOrange) 76 | case '5': 77 | s.SetCell(2, 2, tcell.StyleDefault, '5') 78 | s.SetCursorStyle(tcell.CursorStyleBlinkingBar, tcell.ColorYellow) 79 | case '6': 80 | s.SetCell(2, 2, tcell.StyleDefault, '6') 81 | s.SetCursorStyle(tcell.CursorStyleSteadyBar, tcell.ColorPink) 82 | } 83 | 84 | case tcell.KeyEscape, tcell.KeyEnter, tcell.KeyCtrlC: 85 | close(quit) 86 | return 87 | case tcell.KeyCtrlL: 88 | s.Sync() 89 | } 90 | case *tcell.EventResize: 91 | s.Sync() 92 | } 93 | } 94 | }() 95 | <-quit 96 | s.Fini() 97 | } 98 | -------------------------------------------------------------------------------- /_demos/hello_world.go: -------------------------------------------------------------------------------- 1 | //go:build ignore 2 | // +build ignore 3 | 4 | // Copyright 2020 The TCell Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use file except in compliance with the License. 8 | // You may obtain a copy of the license at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | package main 19 | 20 | import ( 21 | "fmt" 22 | "os" 23 | 24 | "github.com/gdamore/tcell/v2" 25 | "github.com/gdamore/tcell/v2/encoding" 26 | 27 | "github.com/mattn/go-runewidth" 28 | ) 29 | 30 | func emitStr(s tcell.Screen, x, y int, style tcell.Style, str string) { 31 | for _, c := range str { 32 | var comb []rune 33 | w := runewidth.RuneWidth(c) 34 | if w == 0 { 35 | comb = []rune{c} 36 | c = ' ' 37 | w = 1 38 | } 39 | s.SetContent(x, y, c, comb, style) 40 | x += w 41 | } 42 | } 43 | 44 | func displayHelloWorld(s tcell.Screen) { 45 | w, h := s.Size() 46 | s.Clear() 47 | style := tcell.StyleDefault.Foreground(tcell.ColorCadetBlue.TrueColor()).Background(tcell.ColorWhite) 48 | emitStr(s, w/2-7, h/2, style, "Hello, World!") 49 | emitStr(s, w/2-9, h/2+1, tcell.StyleDefault, "Press ESC to exit.") 50 | s.Show() 51 | } 52 | 53 | // This program just prints "Hello, World!". Press ESC to exit. 54 | func main() { 55 | encoding.Register() 56 | 57 | s, e := tcell.NewScreen() 58 | if e != nil { 59 | fmt.Fprintf(os.Stderr, "%v\n", e) 60 | os.Exit(1) 61 | } 62 | if e := s.Init(); e != nil { 63 | fmt.Fprintf(os.Stderr, "%v\n", e) 64 | os.Exit(1) 65 | } 66 | 67 | defStyle := tcell.StyleDefault. 68 | Background(tcell.ColorBlack). 69 | Foreground(tcell.ColorWhite) 70 | s.SetStyle(defStyle) 71 | 72 | displayHelloWorld(s) 73 | 74 | for { 75 | switch ev := s.PollEvent().(type) { 76 | case *tcell.EventResize: 77 | s.Sync() 78 | displayHelloWorld(s) 79 | case *tcell.EventKey: 80 | if ev.Key() == tcell.KeyEscape { 81 | s.Fini() 82 | os.Exit(0) 83 | } 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /_demos/hyperlink.go: -------------------------------------------------------------------------------- 1 | //go:build ignore 2 | // +build ignore 3 | 4 | // Copyright 2022 The TCell Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use file except in compliance with the License. 8 | // You may obtain a copy of the license at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | package main 19 | 20 | import ( 21 | "fmt" 22 | "os" 23 | 24 | "github.com/gdamore/tcell/v2" 25 | "github.com/gdamore/tcell/v2/encoding" 26 | 27 | "github.com/mattn/go-runewidth" 28 | ) 29 | 30 | func emitStr(s tcell.Screen, x, y int, style tcell.Style, str string) int { 31 | for _, c := range str { 32 | var comb []rune 33 | w := runewidth.RuneWidth(c) 34 | if w == 0 { 35 | comb = []rune{c} 36 | c = ' ' 37 | w = 1 38 | } 39 | s.SetContent(x, y, c, comb, style) 40 | x += w 41 | } 42 | return x 43 | } 44 | 45 | func displayDemo(s tcell.Screen) { 46 | w, h := s.Size() 47 | s.Clear() 48 | style := tcell.StyleDefault 49 | x := (w - 55) / 2 50 | x = emitStr(s, x, h/2, style, "Please visit the ") 51 | x = emitStr(s, x, h/2, style.Url("https://github.com/gdamore/tcell"), "GitHub Repository") 52 | emitStr(s, x, h/2, style, " for the source code.") 53 | style = tcell.StyleDefault.Foreground(tcell.ColorCadetBlue.TrueColor()).Background(tcell.ColorWhite) 54 | emitStr(s, (w-18)/2, h/2+2, style, "Press ESC to exit.") 55 | s.Show() 56 | } 57 | 58 | // This program just prints "Hello, World!". Press ESC to exit. 59 | func main() { 60 | encoding.Register() 61 | 62 | s, e := tcell.NewScreen() 63 | if e != nil { 64 | fmt.Fprintf(os.Stderr, "%v\n", e) 65 | os.Exit(1) 66 | } 67 | if e := s.Init(); e != nil { 68 | fmt.Fprintf(os.Stderr, "%v\n", e) 69 | os.Exit(1) 70 | } 71 | 72 | defStyle := tcell.StyleDefault. 73 | Background(tcell.ColorBlack). 74 | Foreground(tcell.ColorWhite) 75 | s.SetStyle(defStyle) 76 | 77 | displayDemo(s) 78 | 79 | for { 80 | switch ev := s.PollEvent().(type) { 81 | case *tcell.EventResize: 82 | s.Sync() 83 | displayDemo(s) 84 | case *tcell.EventKey: 85 | if ev.Key() == tcell.KeyEscape { 86 | s.Fini() 87 | os.Exit(0) 88 | } 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /_demos/setsize.go: -------------------------------------------------------------------------------- 1 | //go:build ignore 2 | // +build ignore 3 | 4 | // Copyright 2022 The TCell Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use file except in compliance with the License. 8 | // You may obtain a copy of the license at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | package main 19 | 20 | import ( 21 | "fmt" 22 | "os" 23 | 24 | "github.com/gdamore/tcell/v2" 25 | "github.com/gdamore/tcell/v2/encoding" 26 | 27 | "github.com/mattn/go-runewidth" 28 | ) 29 | 30 | func emitStr(s tcell.Screen, x, y int, style tcell.Style, str string) { 31 | for _, c := range str { 32 | var comb []rune 33 | w := runewidth.RuneWidth(c) 34 | if w == 0 { 35 | comb = []rune{c} 36 | c = ' ' 37 | w = 1 38 | } 39 | s.SetContent(x, y, c, comb, style) 40 | x += w 41 | } 42 | } 43 | 44 | func displayDemo(s tcell.Screen) { 45 | w, h := s.Size() 46 | s.Clear() 47 | style := tcell.StyleDefault.Foreground(tcell.ColorCadetBlue.TrueColor()).Background(tcell.ColorWhite) 48 | sizeStr := fmt.Sprintf("%d x %d", w, h) 49 | helpStr := "Use cursors to resize, ESC to exit." 50 | emitStr(s, (w-len(sizeStr))/2, h/2, style, sizeStr) 51 | emitStr(s, (w-len(helpStr))/2, h/2+1, tcell.StyleDefault, helpStr) 52 | s.Show() 53 | } 54 | 55 | // This program just prints "Hello, World!". Press ESC to exit. 56 | func main() { 57 | encoding.Register() 58 | 59 | s, e := tcell.NewScreen() 60 | if e != nil { 61 | fmt.Fprintf(os.Stderr, "%v\n", e) 62 | os.Exit(1) 63 | } 64 | if e := s.Init(); e != nil { 65 | fmt.Fprintf(os.Stderr, "%v\n", e) 66 | os.Exit(1) 67 | } 68 | 69 | defStyle := tcell.StyleDefault. 70 | Background(tcell.ColorBlack). 71 | Foreground(tcell.ColorWhite) 72 | s.SetStyle(defStyle) 73 | 74 | displayDemo(s) 75 | 76 | for { 77 | switch ev := s.PollEvent().(type) { 78 | case *tcell.EventResize: 79 | s.Sync() 80 | displayDemo(s) 81 | case *tcell.EventKey: 82 | switch ev.Key() { 83 | case tcell.KeyEscape: 84 | s.Fini() 85 | os.Exit(0) 86 | case tcell.KeyRight: 87 | w, h := s.Size() 88 | s.SetSize(w+1, h) 89 | case tcell.KeyLeft: 90 | w, h := s.Size() 91 | s.SetSize(w-1, h) 92 | case tcell.KeyUp: 93 | w, h := s.Size() 94 | s.SetSize(w, h-1) 95 | case tcell.KeyDown: 96 | w, h := s.Size() 97 | s.SetSize(w, h+1) 98 | } 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /_demos/stress.go: -------------------------------------------------------------------------------- 1 | //go:build ignore 2 | // +build ignore 3 | 4 | // Copyright 2022 The TCell Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use file except in compliance with the License. 8 | // You may obtain a copy of the license at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | // stress will fill the whole screen with random characters, colors and 19 | // formatting. The frames are pre-generated to draw as fast as possible. 20 | // ESC and Ctrl-C will end the program. Note that resizing isn't supported. 21 | package main 22 | 23 | import ( 24 | "fmt" 25 | "math/rand" 26 | "time" 27 | 28 | "github.com/gdamore/tcell/v2" 29 | ) 30 | 31 | func main() { 32 | screen, err := tcell.NewScreen() 33 | if err != nil { 34 | panic(err) 35 | } 36 | if err := screen.Init(); err != nil { 37 | panic(err) 38 | } 39 | 40 | var frames int 41 | 42 | type cell struct { 43 | c rune 44 | style tcell.Style 45 | } 46 | 47 | width, height := screen.Size() 48 | glyphs := []rune{'@', '#', '&', '*', '=', '%', 'Z', 'A'} 49 | attrs := []tcell.AttrMask{tcell.AttrBold, tcell.AttrReverse, tcell.AttrItalic, tcell.AttrNone} 50 | 51 | // Pre-Generate 100 different frame patterns, so we stress the terminal as 52 | // much as possible :D 53 | var patterns [][][]*cell 54 | for i := 0; i < 100; i++ { 55 | pattern := make([][]*cell, height) 56 | for h := 0; h < height; h++ { 57 | row := make([]*cell, width) 58 | for w := 0; w < width; w++ { 59 | rF := int32(rand.Int() % 256) 60 | gF := int32(rand.Int() % 256) 61 | bF := int32(rand.Int() % 256) 62 | rB := int32(rand.Int() % 256) 63 | gB := int32(rand.Int() % 256) 64 | bB := int32(rand.Int() % 256) 65 | 66 | row[w] = &cell{ 67 | c: glyphs[rand.Int()%len(glyphs)], 68 | style: tcell.StyleDefault. 69 | Attributes(attrs[rand.Int()%len(attrs)]). 70 | Background(tcell.NewRGBColor(rB, gB, bB)). 71 | Foreground(tcell.NewRGBColor(rF, gF, bF)), 72 | } 73 | } 74 | pattern[h] = row 75 | } 76 | patterns = append(patterns, pattern) 77 | } 78 | 79 | evCh := make(chan tcell.Event) 80 | quitCh := make(chan struct{}) 81 | 82 | go screen.ChannelEvents(evCh, quitCh) 83 | startTime := time.Now() 84 | loop: 85 | for { 86 | select { 87 | case event := <-evCh: 88 | if event, ok := event.(*tcell.EventKey); ok { 89 | if event.Key() == tcell.KeyCtrlC || event.Key() == tcell.KeyESC { 90 | close(quitCh) 91 | break loop 92 | } 93 | } 94 | break 95 | default: 96 | } 97 | pattern := patterns[frames%len(patterns)] 98 | for h := 0; h < height; h++ { 99 | for w := 0; w < width; w++ { 100 | c := pattern[h][w] 101 | screen.SetContent(w, h, c.c, nil, c.style) 102 | } 103 | } 104 | screen.Show() 105 | frames++ 106 | } 107 | duration := time.Since(startTime) 108 | screen.Fini() 109 | fps := int(float64(frames) / duration.Seconds()) 110 | fmt.Println("FPS:", fps) 111 | } 112 | -------------------------------------------------------------------------------- /attr.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 The TCell Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use file except in compliance with the License. 5 | // You may obtain a copy of the license at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package tcell 16 | 17 | // AttrMask represents a mask of text attributes, apart from color. 18 | // Note that support for attributes may vary widely across terminals. 19 | type AttrMask uint 20 | 21 | // Attributes are not colors, but affect the display of text. They can 22 | // be combined, in some cases, but not others. (E.g. you can have Dim Italic, 23 | // but only CurlyUnderline cannot be mixed with DottedUnderline.) 24 | const ( 25 | AttrBold AttrMask = 1 << iota 26 | AttrBlink 27 | AttrReverse 28 | AttrUnderline // Deprecated: Use UnderlineStyle 29 | AttrDim 30 | AttrItalic 31 | AttrStrikeThrough 32 | AttrInvalid AttrMask = 1 << 31 // Mark the style or attributes invalid 33 | AttrNone AttrMask = 0 // Just normal text. 34 | ) 35 | -------------------------------------------------------------------------------- /charset_stub.go: -------------------------------------------------------------------------------- 1 | //go:build plan9 || nacl 2 | // +build plan9 nacl 3 | 4 | // Copyright 2015 The TCell Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use file except in compliance with the License. 8 | // You may obtain a copy of the license at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | package tcell 19 | 20 | func getCharset() string { 21 | return "" 22 | } 23 | -------------------------------------------------------------------------------- /charset_unix.go: -------------------------------------------------------------------------------- 1 | //go:build !windows && !nacl && !plan9 2 | // +build !windows,!nacl,!plan9 3 | 4 | // Copyright 2016 The TCell Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use file except in compliance with the License. 8 | // You may obtain a copy of the license at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | package tcell 19 | 20 | import ( 21 | "os" 22 | "strings" 23 | ) 24 | 25 | func getCharset() string { 26 | // Determine the character set. This can help us later. 27 | // Per POSIX, we search for LC_ALL first, then LC_CTYPE, and 28 | // finally LANG. First one set wins. 29 | locale := "" 30 | if locale = os.Getenv("LC_ALL"); locale == "" { 31 | if locale = os.Getenv("LC_CTYPE"); locale == "" { 32 | locale = os.Getenv("LANG") 33 | } 34 | } 35 | if locale == "POSIX" || locale == "C" { 36 | return "US-ASCII" 37 | } 38 | if i := strings.IndexRune(locale, '@'); i >= 0 { 39 | locale = locale[:i] 40 | } 41 | if i := strings.IndexRune(locale, '.'); i >= 0 { 42 | locale = locale[i+1:] 43 | } else { 44 | // Default assumption, and on Linux we can see LC_ALL 45 | // without a character set, which we assume implies UTF-8. 46 | return "UTF-8" 47 | } 48 | // XXX: add support for aliases 49 | return locale 50 | } 51 | -------------------------------------------------------------------------------- /charset_windows.go: -------------------------------------------------------------------------------- 1 | //go:build windows 2 | // +build windows 3 | 4 | // Copyright 2015 The TCell Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use file except in compliance with the License. 8 | // You may obtain a copy of the license at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | package tcell 19 | 20 | func getCharset() string { 21 | return "UTF-16" 22 | } 23 | -------------------------------------------------------------------------------- /colorfit.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The TCell Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use file except in compliance with the License. 5 | // You may obtain a copy of the license at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package tcell 16 | 17 | import ( 18 | "math" 19 | 20 | "github.com/lucasb-eyer/go-colorful" 21 | ) 22 | 23 | // FindColor attempts to find a given color, or the best match possible for it, 24 | // from the palette given. This is an expensive operation, so results should 25 | // be cached by the caller. 26 | func FindColor(c Color, palette []Color) Color { 27 | match := ColorDefault 28 | dist := float64(0) 29 | r, g, b := c.RGB() 30 | c1 := colorful.Color{ 31 | R: float64(r) / 255.0, 32 | G: float64(g) / 255.0, 33 | B: float64(b) / 255.0, 34 | } 35 | for _, d := range palette { 36 | r, g, b = d.RGB() 37 | c2 := colorful.Color{ 38 | R: float64(r) / 255.0, 39 | G: float64(g) / 255.0, 40 | B: float64(b) / 255.0, 41 | } 42 | // CIE94 is more accurate, but really really expensive. 43 | nd := c1.DistanceCIE76(c2) 44 | if math.IsNaN(nd) { 45 | nd = math.Inf(1) 46 | } 47 | if match == ColorDefault || nd < dist { 48 | match = d 49 | dist = nd 50 | } 51 | } 52 | return match 53 | } 54 | -------------------------------------------------------------------------------- /console_stub.go: -------------------------------------------------------------------------------- 1 | //go:build !windows 2 | // +build !windows 3 | 4 | // Copyright 2015 The TCell Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use file except in compliance with the License. 8 | // You may obtain a copy of the license at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | package tcell 19 | 20 | // NewConsoleScreen returns a console based screen. This platform 21 | // doesn't have support for any, so it returns nil and a suitable error. 22 | func NewConsoleScreen() (Screen, error) { 23 | return nil, ErrNoScreen 24 | } 25 | -------------------------------------------------------------------------------- /doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The TCell Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use file except in compliance with the License. 5 | // You may obtain a copy of the license at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package tcell provides a lower-level, portable API for building 16 | // programs that interact with terminals or consoles. It works with 17 | // both common (and many uncommon!) terminals or terminal emulators, 18 | // and Windows console implementations. 19 | // 20 | // It provides support for up to 256 colors, text attributes, and box drawing 21 | // elements. A database of terminals built from a real terminfo database 22 | // is provided, along with code to generate new database entries. 23 | // 24 | // Tcell offers very rich support for mice, dependent upon the terminal 25 | // of course. (Windows, XTerm, and iTerm 2 are known to work very well.) 26 | // 27 | // If the environment is not Unicode by default, such as an ISO8859 based 28 | // locale or GB18030, Tcell can convert input and output, so that your 29 | // terminal can operate in whatever locale is most convenient, while the 30 | // application program can just assume "everything is UTF-8". Reasonable 31 | // defaults are used for updating characters to something suitable for 32 | // display. Unicode box drawing characters will be converted to use the 33 | // alternate character set of your terminal, if native conversions are 34 | // not available. If no ACS is available, then some ASCII fallbacks will 35 | // be used. 36 | // 37 | // Note that support for non-UTF-8 locales (other than C) must be enabled 38 | // by the application using RegisterEncoding() -- we don't have them all 39 | // enabled by default to avoid bloating the application unnecessarily. 40 | // (These days UTF-8 is good enough for almost everyone, and nobody should 41 | // be using legacy locales anymore.) Also, actual glyphs for various code 42 | // point will only be displayed if your terminal or emulator (or the font 43 | // the emulator is using) supports them. 44 | // 45 | // A rich set of key codes is supported, with support for up to 65 function 46 | // keys, and various other special keys. 47 | package tcell 48 | -------------------------------------------------------------------------------- /encoding/all.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The TCell Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use file except in compliance with the License. 5 | // You may obtain a copy of the license at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package encoding is used to provide a fairly complete set of encodings 16 | // for tcell applications. Importing this package will automatically 17 | // register encodings. Note that this package will add several MB to the 18 | // generated binaries, as the encodings themselves can be somewhat large, 19 | // particularly for the East Asian locales. 20 | package encoding 21 | 22 | import ( 23 | "github.com/gdamore/encoding" 24 | "github.com/gdamore/tcell/v2" 25 | 26 | "golang.org/x/text/encoding/charmap" 27 | "golang.org/x/text/encoding/japanese" 28 | "golang.org/x/text/encoding/korean" 29 | "golang.org/x/text/encoding/simplifiedchinese" 30 | "golang.org/x/text/encoding/traditionalchinese" 31 | ) 32 | 33 | // Register registers all known encodings. This is a short-cut to 34 | // add full character set support to your program. Note that this can 35 | // add several megabytes to your program's size, because some of the encodings 36 | // are rather large (particularly those from East Asia.) 37 | // 38 | // Deprecated: This is no longer needed, importing the package is sufficient. 39 | func Register() { 40 | registerAll() 41 | } 42 | 43 | func registerAll() { 44 | // We supply latin1 and latin5, because Go doesn't 45 | tcell.RegisterEncoding("ISO8859-1", encoding.ISO8859_1) 46 | tcell.RegisterEncoding("ISO8859-9", encoding.ISO8859_9) 47 | 48 | tcell.RegisterEncoding("ISO8859-10", charmap.ISO8859_10) 49 | tcell.RegisterEncoding("ISO8859-13", charmap.ISO8859_13) 50 | tcell.RegisterEncoding("ISO8859-14", charmap.ISO8859_14) 51 | tcell.RegisterEncoding("ISO8859-15", charmap.ISO8859_15) 52 | tcell.RegisterEncoding("ISO8859-16", charmap.ISO8859_16) 53 | tcell.RegisterEncoding("ISO8859-2", charmap.ISO8859_2) 54 | tcell.RegisterEncoding("ISO8859-3", charmap.ISO8859_3) 55 | tcell.RegisterEncoding("ISO8859-4", charmap.ISO8859_4) 56 | tcell.RegisterEncoding("ISO8859-5", charmap.ISO8859_5) 57 | tcell.RegisterEncoding("ISO8859-6", charmap.ISO8859_6) 58 | tcell.RegisterEncoding("ISO8859-7", charmap.ISO8859_7) 59 | tcell.RegisterEncoding("ISO8859-8", charmap.ISO8859_8) 60 | tcell.RegisterEncoding("KOI8-R", charmap.KOI8R) 61 | tcell.RegisterEncoding("KOI8-U", charmap.KOI8U) 62 | 63 | // Asian stuff 64 | tcell.RegisterEncoding("EUC-JP", japanese.EUCJP) 65 | tcell.RegisterEncoding("SHIFT_JIS", japanese.ShiftJIS) 66 | tcell.RegisterEncoding("ISO2022JP", japanese.ISO2022JP) 67 | 68 | tcell.RegisterEncoding("EUC-KR", korean.EUCKR) 69 | 70 | tcell.RegisterEncoding("GB18030", simplifiedchinese.GB18030) 71 | tcell.RegisterEncoding("GB2312", simplifiedchinese.HZGB2312) 72 | tcell.RegisterEncoding("GBK", simplifiedchinese.GBK) 73 | 74 | tcell.RegisterEncoding("Big5", traditionalchinese.Big5) 75 | 76 | // Common aliases 77 | aliases := map[string]string{ 78 | "8859-1": "ISO8859-1", 79 | "ISO-8859-1": "ISO8859-1", 80 | "8859-13": "ISO8859-13", 81 | "ISO-8859-13": "ISO8859-13", 82 | "8859-14": "ISO8859-14", 83 | "ISO-8859-14": "ISO8859-14", 84 | "8859-15": "ISO8859-15", 85 | "ISO-8859-15": "ISO8859-15", 86 | "8859-16": "ISO8859-16", 87 | "ISO-8859-16": "ISO8859-16", 88 | "8859-2": "ISO8859-2", 89 | "ISO-8859-2": "ISO8859-2", 90 | "8859-3": "ISO8859-3", 91 | "ISO-8859-3": "ISO8859-3", 92 | "8859-4": "ISO8859-4", 93 | "ISO-8859-4": "ISO8859-4", 94 | "8859-5": "ISO8859-5", 95 | "ISO-8859-5": "ISO8859-5", 96 | "8859-6": "ISO8859-6", 97 | "ISO-8859-6": "ISO8859-6", 98 | "8859-7": "ISO8859-7", 99 | "ISO-8859-7": "ISO8859-7", 100 | "8859-8": "ISO8859-8", 101 | "ISO-8859-8": "ISO8859-8", 102 | "8859-9": "ISO8859-9", 103 | "ISO-8859-9": "ISO8859-9", 104 | 105 | "SJIS": "Shift_JIS", 106 | "EUCJP": "EUC-JP", 107 | "2022-JP": "ISO2022JP", 108 | "ISO-2022-JP": "ISO2022JP", 109 | 110 | "EUCKR": "EUC-KR", 111 | 112 | // ISO646 isn't quite exactly ASCII, but the 1991 IRV 113 | // (international reference version) is so. This helps 114 | // some older systems that may use "646" for POSIX locales. 115 | "646": "US-ASCII", 116 | "ISO646": "US-ASCII", 117 | 118 | // Other names for UTF-8 119 | "UTF8": "UTF-8", 120 | } 121 | for n, v := range aliases { 122 | if enc := tcell.GetEncoding(v); enc != nil { 123 | tcell.RegisterEncoding(n, enc) 124 | } 125 | } 126 | } 127 | 128 | func init() { 129 | registerAll() 130 | } 131 | -------------------------------------------------------------------------------- /encoding/encoding_init_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The TCell Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use file except in compliance with the License. 5 | // You may obtain a copy of the license at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | package encoding 15 | 16 | import ( 17 | "testing" 18 | 19 | "github.com/gdamore/tcell/v2" 20 | ) 21 | 22 | func TestGBK(t *testing.T) { 23 | enc := tcell.GetEncoding("GBK") 24 | if enc == nil { 25 | t.Fatal("NULL encoding for GBK") 26 | } 27 | glyph, _ := enc.NewDecoder().Bytes([]byte{0x82, 0x74}) 28 | if string(glyph) != "倀" { 29 | t.Errorf("failed to match: %s != 倀", string(glyph)) 30 | } 31 | } 32 | 33 | func TestAscii(t *testing.T) { 34 | encodings := []string{ 35 | "ASCII", 36 | "ISO-8859-1", 37 | "KOI8-R", 38 | "KOI8-U", 39 | "SJIS", 40 | "Big5", 41 | "GB2312", 42 | "GB18030", 43 | "EUC-JP", 44 | "EUCKR", 45 | } 46 | 47 | for _, name := range encodings { 48 | t.Run(name, func(t *testing.T) { 49 | enc := tcell.GetEncoding(name) 50 | if enc == nil { 51 | t.Errorf("Failed getting encoding for %s", name) 52 | return 53 | } 54 | encoder := enc.NewEncoder() 55 | decoder := enc.NewDecoder() 56 | // Ensure that all US-ASCII (lower 7 bit values) encode and decode identically 57 | for i := byte(0); i < 126; i++ { // well, KOI8-R has some problem with "~" 58 | s := string([]byte{i}) 59 | if x, err := encoder.String(s); err != nil || x != s { 60 | t.Errorf("failed encoding for character: %d, err %v expect %s got %s", i, err, s, x) 61 | } 62 | if x, err := decoder.String(s); err != nil || x != s { 63 | t.Errorf("failed decoding for character: %d, err %v expect %s got %s", i, err, s, x) 64 | } 65 | } 66 | }) 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /encoding_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The TCell Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use file except in compliance with the License. 5 | // You may obtain a copy of the license at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | package tcell 15 | 16 | import ( 17 | "fmt" 18 | 19 | "golang.org/x/text/encoding/simplifiedchinese" 20 | ) 21 | 22 | func ExampleRegisterEncoding() { 23 | RegisterEncoding("GBK", simplifiedchinese.GBK) 24 | enc := GetEncoding("GBK") 25 | glyph, _ := enc.NewDecoder().Bytes([]byte{0x82, 0x74}) 26 | fmt.Println(string(glyph)) 27 | // Output: 倀 28 | } 29 | -------------------------------------------------------------------------------- /errors.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The TCell Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use file except in compliance with the License. 5 | // You may obtain a copy of the license at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package tcell 16 | 17 | import ( 18 | "errors" 19 | "time" 20 | 21 | "github.com/gdamore/tcell/v2/terminfo" 22 | ) 23 | 24 | var ( 25 | // ErrTermNotFound indicates that a suitable terminal entry could 26 | // not be found. This can result from either not having TERM set, 27 | // or from the TERM failing to support certain minimal functionality, 28 | // in particular absolute cursor addressability (the cup capability) 29 | // is required. For example, legacy "adm3" lacks this capability, 30 | // whereas the slightly newer "adm3a" supports it. This failure 31 | // occurs most often with "dumb". 32 | ErrTermNotFound = terminfo.ErrTermNotFound 33 | 34 | // ErrNoScreen indicates that no suitable screen could be found. 35 | // This may result from attempting to run on a platform where there 36 | // is no support for either termios or console I/O (such as nacl), 37 | // or from running in an environment where there is no access to 38 | // a suitable console/terminal device. (For example, running on 39 | // without a controlling TTY or with no /dev/tty on POSIX platforms.) 40 | ErrNoScreen = errors.New("no suitable screen available") 41 | 42 | // ErrNoCharset indicates that the locale environment the 43 | // program is not supported by the program, because no suitable 44 | // encoding was found for it. This problem never occurs if 45 | // the environment is UTF-8 or UTF-16. 46 | ErrNoCharset = errors.New("character set not supported") 47 | 48 | // ErrEventQFull indicates that the event queue is full, and 49 | // cannot accept more events. 50 | ErrEventQFull = errors.New("event queue full") 51 | ) 52 | 53 | // An EventError is an event representing some sort of error, and carries 54 | // an error payload. 55 | type EventError struct { 56 | t time.Time 57 | err error 58 | } 59 | 60 | // When returns the time when the event was created. 61 | func (ev *EventError) When() time.Time { 62 | return ev.t 63 | } 64 | 65 | // Error implements the error. 66 | func (ev *EventError) Error() string { 67 | return ev.err.Error() 68 | } 69 | 70 | // NewEventError creates an ErrorEvent with the given error payload. 71 | func NewEventError(err error) *EventError { 72 | return &EventError{t: time.Now(), err: err} 73 | } 74 | -------------------------------------------------------------------------------- /event.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The TCell Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use file except in compliance with the License. 5 | // You may obtain a copy of the license at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package tcell 16 | 17 | import ( 18 | "time" 19 | ) 20 | 21 | // Event is a generic interface used for passing around Events. 22 | // Concrete types follow. 23 | type Event interface { 24 | // When reports the time when the event was generated. 25 | When() time.Time 26 | } 27 | 28 | // EventTime is a simple base event class, suitable for easy reuse. 29 | // It can be used to deliver actual timer events as well. 30 | type EventTime struct { 31 | when time.Time 32 | } 33 | 34 | // When returns the time stamp when the event occurred. 35 | func (e *EventTime) When() time.Time { 36 | return e.when 37 | } 38 | 39 | // SetEventTime sets the time of occurrence for the event. 40 | func (e *EventTime) SetEventTime(t time.Time) { 41 | e.when = t 42 | } 43 | 44 | // SetEventNow sets the time of occurrence for the event to the current time. 45 | func (e *EventTime) SetEventNow() { 46 | e.SetEventTime(time.Now()) 47 | } 48 | 49 | // EventHandler is anything that handles events. If the handler has 50 | // consumed the event, it should return true. False otherwise. 51 | type EventHandler interface { 52 | HandleEvent(Event) bool 53 | } 54 | -------------------------------------------------------------------------------- /event_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The TCell Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use file except in compliance with the License. 5 | // You may obtain a copy of the license at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package tcell 16 | 17 | import ( 18 | "testing" 19 | "time" 20 | ) 21 | 22 | func eventLoop(s Screen, evch chan Event) { 23 | for { 24 | ev := s.PollEvent() 25 | if ev == nil { 26 | close(evch) 27 | return 28 | } 29 | select { 30 | case evch <- ev: 31 | case <-time.After(time.Second): 32 | } 33 | } 34 | } 35 | 36 | func TestMouseEvents(t *testing.T) { 37 | 38 | s := mkTestScreen(t, "") 39 | defer s.Fini() 40 | 41 | s.EnableMouse() 42 | s.InjectMouse(4, 9, Button1, ModCtrl) 43 | evch := make(chan Event) 44 | em := &EventMouse{} 45 | done := false 46 | go eventLoop(s, evch) 47 | 48 | for !done { 49 | select { 50 | case ev := <-evch: 51 | if evm, ok := ev.(*EventMouse); ok { 52 | em = evm 53 | done = true 54 | } 55 | continue 56 | case <-time.After(time.Second): 57 | done = true 58 | } 59 | } 60 | 61 | if x, y := em.Position(); x != 4 || y != 9 { 62 | t.Errorf("Mouse position wrong (%v, %v)", x, y) 63 | } 64 | if em.Buttons() != Button1 { 65 | t.Errorf("Should be Button1") 66 | } 67 | if em.Modifiers() != ModCtrl { 68 | t.Errorf("Modifiers should be control") 69 | } 70 | } 71 | 72 | func TestChannelMouseEvents(t *testing.T) { 73 | 74 | s := mkTestScreen(t, "") 75 | defer s.Fini() 76 | 77 | s.EnableMouse() 78 | s.InjectMouse(4, 9, Button1, ModCtrl) 79 | evch := make(chan Event) 80 | quit := make(chan struct{}) 81 | em := new(EventMouse) 82 | go s.ChannelEvents(evch, quit) 83 | 84 | loop: 85 | for { 86 | select { 87 | case ev := <-evch: 88 | if evm, ok := ev.(*EventMouse); ok { 89 | em = evm 90 | close(quit) 91 | break loop 92 | } 93 | continue 94 | case <-time.After(time.Second): 95 | close(quit) 96 | break loop 97 | } 98 | } 99 | 100 | if x, y := em.Position(); x != 4 || y != 9 { 101 | t.Errorf("Mouse position wrong (%v, %v)", x, y) 102 | } 103 | if em.Buttons() != Button1 { 104 | t.Errorf("Should be Button1") 105 | } 106 | if em.Modifiers() != ModCtrl { 107 | t.Errorf("Modifiers should be control") 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /focus.go: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The TCell Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use file except in compliance with the License. 5 | // You may obtain a copy of the license at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package tcell 16 | 17 | // EventFocus is a focus event. It is sent when the terminal window (or tab) 18 | // gets or loses focus. 19 | type EventFocus struct { 20 | *EventTime 21 | 22 | // True if the window received focus, false if it lost focus 23 | Focused bool 24 | } 25 | 26 | func NewEventFocus(focused bool) *EventFocus { 27 | return &EventFocus{Focused: focused} 28 | } 29 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/gdamore/tcell/v2 2 | 3 | go 1.12 4 | 5 | require ( 6 | github.com/gdamore/encoding v1.0.1 7 | github.com/lucasb-eyer/go-colorful v1.2.0 8 | github.com/mattn/go-runewidth v0.0.16 9 | github.com/rivo/uniseg v0.4.3 // indirect 10 | golang.org/x/sys v0.29.0 11 | golang.org/x/term v0.28.0 12 | golang.org/x/text v0.21.0 13 | ) 14 | -------------------------------------------------------------------------------- /interrupt.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The TCell Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use file except in compliance with the License. 5 | // You may obtain a copy of the license at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package tcell 16 | 17 | import ( 18 | "time" 19 | ) 20 | 21 | // EventInterrupt is a generic wakeup event. Its can be used to 22 | // to request a redraw. It can carry an arbitrary payload, as well. 23 | type EventInterrupt struct { 24 | t time.Time 25 | v interface{} 26 | } 27 | 28 | // When returns the time when this event was created. 29 | func (ev *EventInterrupt) When() time.Time { 30 | return ev.t 31 | } 32 | 33 | // Data is used to obtain the opaque event payload. 34 | func (ev *EventInterrupt) Data() interface{} { 35 | return ev.v 36 | } 37 | 38 | // NewEventInterrupt creates an EventInterrupt with the given payload. 39 | func NewEventInterrupt(data interface{}) *EventInterrupt { 40 | return &EventInterrupt{t: time.Now(), v: data} 41 | } 42 | -------------------------------------------------------------------------------- /logos/patreon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gdamore/tcell/781586687ddb57c9d44727dc9320340c4d049b11/logos/patreon.png -------------------------------------------------------------------------------- /logos/staysail.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gdamore/tcell/781586687ddb57c9d44727dc9320340c4d049b11/logos/staysail.png -------------------------------------------------------------------------------- /logos/tcell.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gdamore/tcell/781586687ddb57c9d44727dc9320340c4d049b11/logos/tcell.png -------------------------------------------------------------------------------- /logos/tidelift.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gdamore/tcell/781586687ddb57c9d44727dc9320340c4d049b11/logos/tidelift.png -------------------------------------------------------------------------------- /mouse.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The TCell Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use file except in compliance with the License. 5 | // You may obtain a copy of the license at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package tcell 16 | 17 | import ( 18 | "time" 19 | ) 20 | 21 | // EventMouse is a mouse event. It is sent on either mouse up or mouse down 22 | // events. It is also sent on mouse motion events - if the terminal supports 23 | // it. We make every effort to ensure that mouse release events are delivered. 24 | // Hence, click drag can be identified by a motion event with the mouse down, 25 | // without any intervening button release. On some terminals only the initiating 26 | // press and terminating release event will be delivered. 27 | // 28 | // Mouse wheel events, when reported, may appear on their own as individual 29 | // impulses; that is, there will normally not be a release event delivered 30 | // for mouse wheel movements. 31 | // 32 | // Most terminals cannot report the state of more than one button at a time -- 33 | // and some cannot report motion events unless a button is pressed. 34 | // 35 | // Applications can inspect the time between events to resolve double or 36 | // triple clicks. 37 | type EventMouse struct { 38 | t time.Time 39 | btn ButtonMask 40 | mod ModMask 41 | x int 42 | y int 43 | } 44 | 45 | // When returns the time when this EventMouse was created. 46 | func (ev *EventMouse) When() time.Time { 47 | return ev.t 48 | } 49 | 50 | // Buttons returns the list of buttons that were pressed or wheel motions. 51 | func (ev *EventMouse) Buttons() ButtonMask { 52 | return ev.btn 53 | } 54 | 55 | // Modifiers returns a list of keyboard modifiers that were pressed 56 | // with the mouse button(s). 57 | func (ev *EventMouse) Modifiers() ModMask { 58 | return ev.mod 59 | } 60 | 61 | // Position returns the mouse position in character cells. The origin 62 | // 0, 0 is at the upper left corner. 63 | func (ev *EventMouse) Position() (int, int) { 64 | return ev.x, ev.y 65 | } 66 | 67 | // NewEventMouse is used to create a new mouse event. Applications 68 | // shouldn't need to use this; its mostly for screen implementors. 69 | func NewEventMouse(x, y int, btn ButtonMask, mod ModMask) *EventMouse { 70 | return &EventMouse{t: time.Now(), x: x, y: y, btn: btn, mod: mod} 71 | } 72 | 73 | // ButtonMask is a mask of mouse buttons and wheel events. Mouse button presses 74 | // are normally delivered as both press and release events. Mouse wheel events 75 | // are normally just single impulse events. Windows supports up to eight 76 | // separate buttons plus all four wheel directions, but XTerm can only support 77 | // mouse buttons 1-3 and wheel up/down. Its not unheard of for terminals 78 | // to support only one or two buttons (think Macs). Old terminals, and true 79 | // emulations (such as vt100) won't support mice at all, of course. 80 | type ButtonMask int16 81 | 82 | // These are the actual button values. Note that tcell version 1.x reversed buttons 83 | // two and three on *nix based terminals. We use button 1 as the primary, and 84 | // button 2 as the secondary, and button 3 (which is often missing) as the middle. 85 | const ( 86 | Button1 ButtonMask = 1 << iota // Usually the left (primary) mouse button. 87 | Button2 // Usually the right (secondary) mouse button. 88 | Button3 // Usually the middle mouse button. 89 | Button4 // Often a side button (thumb/next). 90 | Button5 // Often a side button (thumb/prev). 91 | Button6 92 | Button7 93 | Button8 94 | WheelUp // Wheel motion up/away from user. 95 | WheelDown // Wheel motion down/towards user. 96 | WheelLeft // Wheel motion to left. 97 | WheelRight // Wheel motion to right. 98 | ButtonNone ButtonMask = 0 // No button or wheel events. 99 | 100 | ButtonPrimary = Button1 101 | ButtonSecondary = Button2 102 | ButtonMiddle = Button3 103 | ) 104 | -------------------------------------------------------------------------------- /nonblock_bsd.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The TCell Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use file except in compliance with the License. 5 | // You may obtain a copy of the license at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //go:build darwin || dragonfly || freebsd || netbsd || openbsd 16 | // +build darwin dragonfly freebsd netbsd openbsd 17 | 18 | package tcell 19 | 20 | import ( 21 | "syscall" 22 | 23 | "golang.org/x/sys/unix" 24 | ) 25 | 26 | // BSD systems use TIOC style ioctls. 27 | 28 | // tcSetBufParams is used by the tty driver on UNIX systems to configure the 29 | // buffering parameters (minimum character count and minimum wait time in msec.) 30 | // This also waits for output to drain first. 31 | func tcSetBufParams(fd int, vMin uint8, vTime uint8) error { 32 | _ = syscall.SetNonblock(fd, true) 33 | tio, err := unix.IoctlGetTermios(fd, unix.TIOCGETA) 34 | if err != nil { 35 | return err 36 | } 37 | tio.Cc[unix.VMIN] = vMin 38 | tio.Cc[unix.VTIME] = vTime 39 | if err = unix.IoctlSetTermios(fd, unix.TIOCSETAW, tio); err != nil { 40 | return err 41 | } 42 | return nil 43 | } 44 | -------------------------------------------------------------------------------- /nonblock_unix.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The TCell Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use file except in compliance with the License. 5 | // You may obtain a copy of the license at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //go:build linux || aix || zos || solaris 16 | // +build linux aix zos solaris 17 | 18 | package tcell 19 | 20 | import ( 21 | "syscall" 22 | 23 | "golang.org/x/sys/unix" 24 | ) 25 | 26 | // tcSetBufParams is used by the tty driver on UNIX systems to configure the 27 | // buffering parameters (minimum character count and minimum wait time in msec.) 28 | // This also waits for output to drain first. 29 | func tcSetBufParams(fd int, vMin uint8, vTime uint8) error { 30 | _ = syscall.SetNonblock(fd, true) 31 | tio, err := unix.IoctlGetTermios(fd, unix.TCGETS) 32 | if err != nil { 33 | return err 34 | } 35 | tio.Cc[unix.VMIN] = vMin 36 | tio.Cc[unix.VTIME] = vTime 37 | if err = unix.IoctlSetTermios(fd, unix.TCSETSW, tio); err != nil { 38 | return err 39 | } 40 | return nil 41 | } 42 | -------------------------------------------------------------------------------- /paste.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 The TCell Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use file except in compliance with the License. 5 | // You may obtain a copy of the license at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package tcell 16 | 17 | import ( 18 | "time" 19 | ) 20 | 21 | // EventPaste is used to mark the start and end of a bracketed paste. 22 | // 23 | // An event with .Start() true will be sent to mark the start of a bracketed paste, 24 | // followed by a number of keys (string data) for the content, ending with the 25 | // an event with .End() true. 26 | type EventPaste struct { 27 | start bool 28 | t time.Time 29 | data []byte 30 | } 31 | 32 | // When returns the time when this EventPaste was created. 33 | func (ev *EventPaste) When() time.Time { 34 | return ev.t 35 | } 36 | 37 | // Start returns true if this is the start of a paste. 38 | func (ev *EventPaste) Start() bool { 39 | return ev.start 40 | } 41 | 42 | // End returns true if this is the end of a paste. 43 | func (ev *EventPaste) End() bool { 44 | return !ev.start 45 | } 46 | 47 | // NewEventPaste returns a new EventPaste. 48 | func NewEventPaste(start bool) *EventPaste { 49 | return &EventPaste{t: time.Now(), start: start} 50 | } 51 | 52 | // NewEventClipboard returns a new NewEventClipboard with a data payload 53 | func NewEventClipboard(data []byte) *EventClipboard { 54 | return &EventClipboard{t: time.Now(), data: data} 55 | } 56 | 57 | // EventClipboard represents data from the clipboard, 58 | // in response to a GetClipboard request. 59 | type EventClipboard struct { 60 | t time.Time 61 | data []byte 62 | } 63 | 64 | // Data returns the attached binary data. 65 | func (ev *EventClipboard) Data() []byte { 66 | return ev.data 67 | } 68 | 69 | // When returns the time when this event was created. 70 | func (ev *EventClipboard) When() time.Time { 71 | return ev.t 72 | } 73 | -------------------------------------------------------------------------------- /resize.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The TCell Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use file except in compliance with the License. 5 | // You may obtain a copy of the license at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package tcell 16 | 17 | import ( 18 | "time" 19 | ) 20 | 21 | // EventResize is sent when the window size changes. 22 | type EventResize struct { 23 | t time.Time 24 | ws WindowSize 25 | } 26 | 27 | // NewEventResize creates an EventResize with the new updated window size, 28 | // which is given in character cells. 29 | func NewEventResize(width, height int) *EventResize { 30 | ws := WindowSize{ 31 | Width: width, 32 | Height: height, 33 | } 34 | return &EventResize{t: time.Now(), ws: ws} 35 | } 36 | 37 | // When returns the time when the Event was created. 38 | func (ev *EventResize) When() time.Time { 39 | return ev.t 40 | } 41 | 42 | // Size returns the new window size as width, height in character cells. 43 | func (ev *EventResize) Size() (int, int) { 44 | return ev.ws.Width, ev.ws.Height 45 | } 46 | 47 | // PixelSize returns the new window size as width, height in pixels. The size 48 | // will be 0,0 if the screen doesn't support this feature 49 | func (ev *EventResize) PixelSize() (int, int) { 50 | return ev.ws.PixelWidth, ev.ws.PixelHeight 51 | } 52 | 53 | type WindowSize struct { 54 | Width int 55 | Height int 56 | PixelWidth int 57 | PixelHeight int 58 | } 59 | 60 | // CellDimensions returns the dimensions of a single cell, in pixels 61 | func (ws WindowSize) CellDimensions() (int, int) { 62 | if ws.PixelWidth == 0 || ws.PixelHeight == 0 { 63 | return 0, 0 64 | } 65 | return (ws.PixelWidth / ws.Width), (ws.PixelHeight / ws.Height) 66 | } 67 | -------------------------------------------------------------------------------- /runes.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The TCell Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use file except in compliance with the License. 5 | // You may obtain a copy of the license at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package tcell 16 | 17 | // The names of these constants are chosen to match Terminfo names, 18 | // modulo case, and changing the prefix from ACS_ to Rune. These are 19 | // the runes we provide extra special handling for, with ASCII fallbacks 20 | // for terminals that lack them. 21 | const ( 22 | RuneSterling = '£' 23 | RuneDArrow = '↓' 24 | RuneLArrow = '←' 25 | RuneRArrow = '→' 26 | RuneUArrow = '↑' 27 | RuneBullet = '·' 28 | RuneBoard = '░' 29 | RuneCkBoard = '▒' 30 | RuneDegree = '°' 31 | RuneDiamond = '◆' 32 | RuneGEqual = '≥' 33 | RunePi = 'π' 34 | RuneHLine = '─' 35 | RuneLantern = '§' 36 | RunePlus = '┼' 37 | RuneLEqual = '≤' 38 | RuneLLCorner = '└' 39 | RuneLRCorner = '┘' 40 | RuneNEqual = '≠' 41 | RunePlMinus = '±' 42 | RuneS1 = '⎺' 43 | RuneS3 = '⎻' 44 | RuneS7 = '⎼' 45 | RuneS9 = '⎽' 46 | RuneBlock = '█' 47 | RuneTTee = '┬' 48 | RuneRTee = '┤' 49 | RuneLTee = '├' 50 | RuneBTee = '┴' 51 | RuneULCorner = '┌' 52 | RuneURCorner = '┐' 53 | RuneVLine = '│' 54 | ) 55 | 56 | // RuneFallbacks is the default map of fallback strings that will be 57 | // used to replace a rune when no other more appropriate transformation 58 | // is available, and the rune cannot be displayed directly. 59 | // 60 | // New entries may be added to this map over time, as it becomes clear 61 | // that such is desirable. Characters that represent either letters or 62 | // numbers should not be added to this list unless it is certain that 63 | // the meaning will still convey unambiguously. 64 | // 65 | // As an example, it would be appropriate to add an ASCII mapping for 66 | // the full width form of the letter 'A', but it would not be appropriate 67 | // to do so a glyph representing the country China. 68 | // 69 | // Programs that desire richer fallbacks may register additional ones, 70 | // or change or even remove these mappings with Screen.RegisterRuneFallback 71 | // Screen.UnregisterRuneFallback methods. 72 | // 73 | // Note that Unicode is presumed to be able to display all glyphs. 74 | // This is a pretty poor assumption, but there is no easy way to 75 | // figure out which glyphs are supported in a given font. Hence, 76 | // some care in selecting the characters you support in your application 77 | // is still appropriate. 78 | var RuneFallbacks = map[rune]string{ 79 | RuneSterling: "f", 80 | RuneDArrow: "v", 81 | RuneLArrow: "<", 82 | RuneRArrow: ">", 83 | RuneUArrow: "^", 84 | RuneBullet: "o", 85 | RuneBoard: "#", 86 | RuneCkBoard: ":", 87 | RuneDegree: "\\", 88 | RuneDiamond: "+", 89 | RuneGEqual: ">", 90 | RunePi: "*", 91 | RuneHLine: "-", 92 | RuneLantern: "#", 93 | RunePlus: "+", 94 | RuneLEqual: "<", 95 | RuneLLCorner: "+", 96 | RuneLRCorner: "+", 97 | RuneNEqual: "!", 98 | RunePlMinus: "#", 99 | RuneS1: "~", 100 | RuneS3: "-", 101 | RuneS7: "-", 102 | RuneS9: "_", 103 | RuneBlock: "#", 104 | RuneTTee: "+", 105 | RuneRTee: "+", 106 | RuneLTee: "+", 107 | RuneBTee: "+", 108 | RuneULCorner: "+", 109 | RuneURCorner: "+", 110 | RuneVLine: "|", 111 | } 112 | -------------------------------------------------------------------------------- /runes_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The TCell Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use file except in compliance with the License. 5 | // You may obtain a copy of the license at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package tcell 16 | 17 | import ( 18 | "testing" 19 | ) 20 | 21 | func TestCanDisplayUTF8(t *testing.T) { 22 | s := mkTestScreen(t, "UTF-8") 23 | defer s.Fini() 24 | 25 | if s.CharacterSet() != "UTF-8" { 26 | t.Errorf("Bad charset: %v", s.CharacterSet()) 27 | } 28 | if !s.CanDisplay('a', true) { 29 | t.Errorf("Should be able to display 'a'") 30 | } 31 | if !s.CanDisplay(RuneHLine, true) { 32 | t.Errorf("Should be able to display hline (with fallback)") 33 | } 34 | if !s.CanDisplay(RuneHLine, false) { 35 | t.Errorf("Should be able to display hline (no fallback)") 36 | } 37 | if !s.CanDisplay('⌀', false) { 38 | t.Errorf("Should be able to display null") 39 | } 40 | } 41 | func TestCanDisplayASCII(t *testing.T) { 42 | s := mkTestScreen(t, "US-ASCII") 43 | defer s.Fini() 44 | 45 | if s.CharacterSet() != "US-ASCII" { 46 | t.Errorf("Wrong character set: %v", s.CharacterSet()) 47 | } 48 | if !s.CanDisplay('a', true) { 49 | t.Errorf("Should be able to display 'a'") 50 | } 51 | if !s.CanDisplay(RuneHLine, true) { 52 | t.Errorf("Should be able to display hline (with fallback)") 53 | } 54 | if s.CanDisplay(RunePi, false) { 55 | t.Errorf("Should not be able to display Pi (no fallback)") 56 | } 57 | if s.CanDisplay('⌀', false) { 58 | t.Errorf("Should not be able to display null") 59 | } 60 | } 61 | 62 | func TestRuneFallbacks(t *testing.T) { 63 | s := mkTestScreen(t, "US-ASCII") 64 | defer s.Fini() 65 | if s.CharacterSet() != "US-ASCII" { 66 | t.Errorf("Wrong character set: %v", s.CharacterSet()) 67 | } 68 | 69 | // Test registering a fallback 70 | s.RegisterRuneFallback('⌀', "o") 71 | if s.CanDisplay('⌀', false) { 72 | t.Errorf("Should not be able to display null (no fallback)") 73 | } 74 | if !s.CanDisplay('⌀', true) { 75 | t.Errorf("Should be able to display null (with fallback)") 76 | } 77 | 78 | // Test unregistering custom fallback 79 | s.UnregisterRuneFallback('⌀') 80 | if s.CanDisplay('⌀', false) { 81 | t.Errorf("Should not be able to display null (no fallback)") 82 | } 83 | if s.CanDisplay('⌀', true) { 84 | t.Errorf("Should not be able to display null (with fallback)") 85 | } 86 | 87 | // Test unregistering builtin fallback 88 | if !s.CanDisplay(RuneHLine, true) { 89 | t.Errorf("Should be able to display hline") 90 | } 91 | s.UnregisterRuneFallback(RuneHLine) 92 | if s.CanDisplay(RuneHLine, true) { 93 | t.Errorf("Should not be able to display hline") 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /sim_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The TCell Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use file except in compliance with the License. 5 | // You may obtain a copy of the license at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package tcell 16 | 17 | import ( 18 | "testing" 19 | ) 20 | 21 | func mkTestScreen(t *testing.T, charset string) SimulationScreen { 22 | s := NewSimulationScreen(charset) 23 | if s == nil { 24 | t.Fatalf("Failed to get simulation screen") 25 | } 26 | if e := s.Init(); e != nil { 27 | t.Fatalf("Failed to initialize screen: %v", e) 28 | } 29 | return s 30 | } 31 | 32 | func TestInitScreen(t *testing.T) { 33 | 34 | s := mkTestScreen(t, "") 35 | defer s.Fini() 36 | 37 | if x, y := s.Size(); x != 80 || y != 25 { 38 | t.Fatalf("Size should be 80, 25, was %v, %v", x, y) 39 | } 40 | if s.CharacterSet() != "UTF-8" { 41 | t.Fatalf("Character Set (%v) not UTF-8", s.CharacterSet()) 42 | } 43 | if b, x, y := s.GetContents(); len(b) != x*y || x != 80 || y != 25 { 44 | t.Fatalf("Contents (%v, %v, %v) wrong", len(b), x, y) 45 | } 46 | } 47 | 48 | func TestClearScreen(t *testing.T) { 49 | s := mkTestScreen(t, "") 50 | defer s.Fini() 51 | s.Clear() 52 | b, x, y := s.GetContents() 53 | if len(b) != x*y || x != 80 || y != 25 { 54 | t.Fatalf("Contents (%v, %v, %v) wrong", len(b), x, y) 55 | } 56 | for i := 0; i < x*y; i++ { 57 | if len(b[i].Runes) == 1 && b[i].Runes[0] != ' ' { 58 | t.Errorf("Incorrect contents at %v: %v", i, b[i].Runes) 59 | } 60 | if b[i].Style != StyleDefault { 61 | t.Errorf("Incorrect style at %v: %v", i, b[i].Style) 62 | } 63 | } 64 | } 65 | 66 | func TestSetCell(t *testing.T) { 67 | st := StyleDefault.Background(ColorRed).Blink(true) 68 | s := mkTestScreen(t, "") 69 | defer s.Fini() 70 | s.SetCell(2, 5, st, '@') 71 | b, _, _ := s.GetContents() 72 | s.Show() 73 | if len(b) != 80*25 { 74 | t.Fatalf("Wrong content size") 75 | } 76 | cell := &b[5*80+2] 77 | if len(cell.Runes) != 1 || len(cell.Bytes) != 1 || 78 | cell.Runes[0] != '@' || cell.Bytes[0] != '@' || 79 | cell.Style != st { 80 | t.Errorf("Incorrect cell content: %v", cell) 81 | } 82 | } 83 | 84 | func TestResize(t *testing.T) { 85 | st := StyleDefault.Background(ColorYellow).Underline(true) 86 | s := mkTestScreen(t, "") 87 | defer s.Fini() 88 | s.SetCell(2, 5, st, '&') 89 | b, x, y := s.GetContents() 90 | s.Show() 91 | 92 | cell := &b[5*80+2] 93 | if len(cell.Runes) != 1 || len(cell.Bytes) != 1 || 94 | cell.Runes[0] != '&' || cell.Bytes[0] != '&' || 95 | cell.Style != st { 96 | t.Errorf("Incorrect cell content: %v", cell) 97 | } 98 | s.SetSize(30, 10) 99 | s.Show() 100 | b2, x2, y2 := s.GetContents() 101 | if len(b2) == len(b) || x2 == x || y2 == y { 102 | t.Errorf("Screen parameters should not match") 103 | } 104 | 105 | cell2 := &b[5*80+2] 106 | if len(cell2.Runes) != 1 || len(cell2.Bytes) != 1 || 107 | cell2.Runes[0] != '&' || cell2.Bytes[0] != '&' || 108 | cell2.Style != st { 109 | t.Errorf("Incorrect cell content after resize: %v", cell2) 110 | } 111 | } 112 | 113 | func TestBeep(t *testing.T) { 114 | s := mkTestScreen(t, "") 115 | defer s.Fini() 116 | 117 | b0, x0, y0 := s.GetContents() 118 | 119 | if err := s.Beep(); err != nil { 120 | t.Errorf("could not beep: %v", err) 121 | } 122 | s.Show() 123 | 124 | b1, x1, y1 := s.GetContents() 125 | if x0 != x1 { 126 | t.Fatalf("screen width changed unexpectedly from %d to %d", x0, x1) 127 | } 128 | if y0 != y1 { 129 | t.Fatalf("screen height changed unexpectedly from %d to %d", y0, y1) 130 | } 131 | if len(b0) != len(b1) { 132 | t.Fatalf("screen size changed unexpectedly (had %d cells, has %d cells)", 133 | len(b0), len(b1)) 134 | } 135 | for i := 0; i < len(b0); i++ { 136 | cell0 := b0[i] 137 | cell1 := b1[i] 138 | if len(cell0.Runes) != len(cell1.Runes) { 139 | t.Errorf("incorrect cell content: had %d runes, has %d runes", 140 | len(cell0.Runes), len(cell1.Runes)) 141 | continue 142 | } 143 | for j := 0; j < len(cell0.Runes); j++ { 144 | r0 := cell0.Runes[j] 145 | r1 := cell1.Runes[j] 146 | if r0 != r1 { 147 | t.Errorf("incorrect content: cell %d rune %d changed from %v to %v", 148 | i, j, r0, r1) 149 | } 150 | } 151 | } 152 | } 153 | 154 | func TestTitle(t *testing.T) { 155 | s := mkTestScreen(t, "") 156 | defer s.Fini() 157 | s.SetTitle("My Title") 158 | s.Show() 159 | if s.GetTitle() != "My Title" { 160 | t.Errorf("Title mismatched") 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /style_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 The TCell Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use file except in compliance with the License. 5 | // You may obtain a copy of the license at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package tcell 16 | 17 | import ( 18 | "testing" 19 | ) 20 | 21 | func TestStyle(t *testing.T) { 22 | s := mkTestScreen(t, "") 23 | defer s.Fini() 24 | 25 | style := StyleDefault 26 | fg, bg, attr := style.fg, style.bg, style.attrs 27 | 28 | if fg != ColorDefault || bg != ColorDefault || attr != AttrNone { 29 | t.Errorf("Bad default style (%v, %v, %v)", fg, bg, attr) 30 | } 31 | 32 | s2 := style. 33 | Background(ColorRed). 34 | Foreground(ColorBlue). 35 | Blink(true) 36 | 37 | fg, bg, attr = s2.fg, s2.bg, s2.attrs 38 | if fg != ColorBlue || bg != ColorRed || attr != AttrBlink { 39 | t.Errorf("Bad custom style (%v, %v, %v)", fg, bg, attr) 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /terminfo/.gitignore: -------------------------------------------------------------------------------- 1 | mkinfo 2 | -------------------------------------------------------------------------------- /terminfo/README.md: -------------------------------------------------------------------------------- 1 | This package represents the parent for all terminals. 2 | 3 | In older versions of tcell we had (a couple of) different 4 | external file formats for the terminal database. Those are 5 | now removed. All terminal definitions are supplied by 6 | one of two methods: 7 | 8 | 1. Compiled Go code 9 | 10 | 2. For systems with terminfo and infocmp, dynamically 11 | generated at runtime. 12 | 13 | The Go code can be generated using the mkinfo utility in 14 | this directory. The database entry should be generated 15 | into a package in a directory named as the first character 16 | of the package name. (This permits us to group them all 17 | without having a huge directory of little packages.) 18 | 19 | It may be desirable to add new packages to the extended 20 | package, or -- rarely -- the base package. 21 | 22 | Applications which want to have the large set of terminal 23 | descriptions built into the binary can simply import the 24 | extended package. Otherwise a smaller reasonable default 25 | set (the base package) will be included instead. 26 | -------------------------------------------------------------------------------- /terminfo/TERMINALS.md: -------------------------------------------------------------------------------- 1 | TERMINALS 2 | ========= 3 | 4 | The best way to populate terminals on Debian is to install ncurses, 5 | ncurses-term, screen, tmux, rxvt-unicode, and dvtm. This populates the 6 | the terminfo database so that we can have a reasonable set of starting 7 | terminals. 8 | -------------------------------------------------------------------------------- /terminfo/a/aixterm/term.go: -------------------------------------------------------------------------------- 1 | // Generated automatically. DO NOT HAND-EDIT. 2 | 3 | package aixterm 4 | 5 | import "github.com/gdamore/tcell/v2/terminfo" 6 | 7 | func init() { 8 | 9 | // IBM Aixterm Terminal Emulator 10 | terminfo.AddTerminfo(&terminfo.Terminfo{ 11 | Name: "aixterm", 12 | Columns: 80, 13 | Lines: 25, 14 | Colors: 8, 15 | Bell: "\a", 16 | Clear: "\x1b[H\x1b[J", 17 | AttrOff: "\x1b[0;10m\x1b(B", 18 | Underline: "\x1b[4m", 19 | Bold: "\x1b[1m", 20 | Reverse: "\x1b[7m", 21 | SetFg: "\x1b[3%p1%dm", 22 | SetBg: "\x1b[4%p1%dm", 23 | SetFgBg: "\x1b[3%p1%d;4%p2%dm", 24 | ResetFgBg: "\x1b[32m\x1b[40m", 25 | PadChar: "\x00", 26 | AltChars: "jjkkllmmnnqqttuuvvwwxx", 27 | EnterAcs: "\x1b(0", 28 | ExitAcs: "\x1b(B", 29 | SetCursor: "\x1b[%i%p1%d;%p2%dH", 30 | CursorBack1: "\b", 31 | CursorUp1: "\x1b[A", 32 | KeyUp: "\x1b[A", 33 | KeyDown: "\x1b[B", 34 | KeyRight: "\x1b[C", 35 | KeyLeft: "\x1b[D", 36 | KeyInsert: "\x1b[139q", 37 | KeyDelete: "\x1b[P", 38 | KeyBackspace: "\b", 39 | KeyHome: "\x1b[H", 40 | KeyEnd: "\x1b[146q", 41 | KeyPgUp: "\x1b[150q", 42 | KeyPgDn: "\x1b[154q", 43 | KeyF1: "\x1b[001q", 44 | KeyF2: "\x1b[002q", 45 | KeyF3: "\x1b[003q", 46 | KeyF4: "\x1b[004q", 47 | KeyF5: "\x1b[005q", 48 | KeyF6: "\x1b[006q", 49 | KeyF7: "\x1b[007q", 50 | KeyF8: "\x1b[008q", 51 | KeyF9: "\x1b[009q", 52 | KeyF10: "\x1b[010q", 53 | KeyF11: "\x1b[011q", 54 | KeyF12: "\x1b[012q", 55 | KeyF13: "\x1b[013q", 56 | KeyF14: "\x1b[014q", 57 | KeyF15: "\x1b[015q", 58 | KeyF16: "\x1b[016q", 59 | KeyF17: "\x1b[017q", 60 | KeyF18: "\x1b[018q", 61 | KeyF19: "\x1b[019q", 62 | KeyF20: "\x1b[020q", 63 | KeyF21: "\x1b[021q", 64 | KeyF22: "\x1b[022q", 65 | KeyF23: "\x1b[023q", 66 | KeyF24: "\x1b[024q", 67 | KeyF25: "\x1b[025q", 68 | KeyF26: "\x1b[026q", 69 | KeyF27: "\x1b[027q", 70 | KeyF28: "\x1b[028q", 71 | KeyF29: "\x1b[029q", 72 | KeyF30: "\x1b[030q", 73 | KeyF31: "\x1b[031q", 74 | KeyF32: "\x1b[032q", 75 | KeyF33: "\x1b[033q", 76 | KeyF34: "\x1b[034q", 77 | KeyF35: "\x1b[035q", 78 | KeyF36: "\x1b[036q", 79 | KeyClear: "\x1b[144q", 80 | KeyBacktab: "\x1b[Z", 81 | AutoMargin: true, 82 | }) 83 | } 84 | -------------------------------------------------------------------------------- /terminfo/a/alacritty/direct.go: -------------------------------------------------------------------------------- 1 | // Generated automatically. DO NOT HAND-EDIT. 2 | 3 | package alacritty 4 | 5 | import "github.com/gdamore/tcell/v2/terminfo" 6 | 7 | func init() { 8 | 9 | // alacritty with direct color indexing 10 | terminfo.AddTerminfo(&terminfo.Terminfo{ 11 | Name: "alacritty-direct", 12 | Columns: 80, 13 | Lines: 24, 14 | Colors: 16777216, 15 | Bell: "\a", 16 | Clear: "\x1b[H\x1b[2J", 17 | EnterCA: "\x1b[?1049h\x1b[22;0;0t", 18 | ExitCA: "\x1b[?1049l\x1b[23;0;0t", 19 | ShowCursor: "\x1b[?12l\x1b[?25h", 20 | HideCursor: "\x1b[?25l", 21 | AttrOff: "\x1b(B\x1b[m", 22 | Underline: "\x1b[4m", 23 | Bold: "\x1b[1m", 24 | Dim: "\x1b[2m", 25 | Italic: "\x1b[3m", 26 | Reverse: "\x1b[7m", 27 | EnterKeypad: "\x1b[?1h\x1b=", 28 | ExitKeypad: "\x1b[?1l\x1b>", 29 | SetFg: "\x1b[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;m", 30 | SetBg: "\x1b[%?%p1%{8}%<%t4%p1%d%e%p1%{16}%<%t10%p1%{8}%-%d%e48;5;%p1%d%;m", 31 | SetFgBg: "\x1b[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;;%?%p2%{8}%<%t4%p2%d%e%p2%{16}%<%t10%p2%{8}%-%d%e48;5;%p2%d%;m", 32 | ResetFgBg: "\x1b[39;49m", 33 | AltChars: "``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~", 34 | EnterAcs: "\x1b(0", 35 | ExitAcs: "\x1b(B", 36 | StrikeThrough: "\x1b[9m", 37 | Mouse: "\x1b[M", 38 | SetCursor: "\x1b[%i%p1%d;%p2%dH", 39 | CursorBack1: "\b", 40 | CursorUp1: "\x1b[A", 41 | KeyUp: "\x1bOA", 42 | KeyDown: "\x1bOB", 43 | KeyRight: "\x1bOC", 44 | KeyLeft: "\x1bOD", 45 | KeyInsert: "\x1b[2~", 46 | KeyDelete: "\x1b[3~", 47 | KeyBackspace: "\x7f", 48 | KeyHome: "\x1bOH", 49 | KeyEnd: "\x1bOF", 50 | KeyPgUp: "\x1b[5~", 51 | KeyPgDn: "\x1b[6~", 52 | KeyF1: "\x1bOP", 53 | KeyF2: "\x1bOQ", 54 | KeyF3: "\x1bOR", 55 | KeyF4: "\x1bOS", 56 | KeyF5: "\x1b[15~", 57 | KeyF6: "\x1b[17~", 58 | KeyF7: "\x1b[18~", 59 | KeyF8: "\x1b[19~", 60 | KeyF9: "\x1b[20~", 61 | KeyF10: "\x1b[21~", 62 | KeyF11: "\x1b[23~", 63 | KeyF12: "\x1b[24~", 64 | KeyBacktab: "\x1b[Z", 65 | Modifiers: 1, 66 | TrueColor: true, 67 | AutoMargin: true, 68 | }) 69 | } 70 | -------------------------------------------------------------------------------- /terminfo/a/alacritty/term.go: -------------------------------------------------------------------------------- 1 | // Generated automatically. DO NOT HAND-EDIT. 2 | 3 | package alacritty 4 | 5 | import "github.com/gdamore/tcell/v2/terminfo" 6 | 7 | func init() { 8 | 9 | // alacritty terminal emulator 10 | terminfo.AddTerminfo(&terminfo.Terminfo{ 11 | Name: "alacritty", 12 | Columns: 80, 13 | Lines: 24, 14 | Colors: 256, 15 | Bell: "\a", 16 | Clear: "\x1b[H\x1b[2J", 17 | EnterCA: "\x1b[?1049h\x1b[22;0;0t", 18 | ExitCA: "\x1b[?1049l\x1b[23;0;0t", 19 | ShowCursor: "\x1b[?12l\x1b[?25h", 20 | HideCursor: "\x1b[?25l", 21 | AttrOff: "\x1b(B\x1b[m", 22 | Underline: "\x1b[4m", 23 | Bold: "\x1b[1m", 24 | Dim: "\x1b[2m", 25 | Italic: "\x1b[3m", 26 | Blink: "\x1b[5m", 27 | Reverse: "\x1b[7m", 28 | EnterKeypad: "\x1b[?1h\x1b=", 29 | ExitKeypad: "\x1b[?1l\x1b>", 30 | SetFg: "\x1b[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;m", 31 | SetBg: "\x1b[%?%p1%{8}%<%t4%p1%d%e%p1%{16}%<%t10%p1%{8}%-%d%e48;5;%p1%d%;m", 32 | SetFgBg: "\x1b[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;;%?%p2%{8}%<%t4%p2%d%e%p2%{16}%<%t10%p2%{8}%-%d%e48;5;%p2%d%;m", 33 | ResetFgBg: "\x1b[39;49m", 34 | AltChars: "``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~", 35 | EnterAcs: "\x1b(0", 36 | ExitAcs: "\x1b(B", 37 | EnableAutoMargin: "\x1b[?7h", 38 | DisableAutoMargin: "\x1b[?7l", 39 | StrikeThrough: "\x1b[9m", 40 | Mouse: "\x1b[<", 41 | SetCursor: "\x1b[%i%p1%d;%p2%dH", 42 | CursorBack1: "\b", 43 | CursorUp1: "\x1b[A", 44 | KeyUp: "\x1bOA", 45 | KeyDown: "\x1bOB", 46 | KeyRight: "\x1bOC", 47 | KeyLeft: "\x1bOD", 48 | KeyInsert: "\x1b[2~", 49 | KeyDelete: "\x1b[3~", 50 | KeyBackspace: "\x7f", 51 | KeyHome: "\x1bOH", 52 | KeyEnd: "\x1bOF", 53 | KeyPgUp: "\x1b[5~", 54 | KeyPgDn: "\x1b[6~", 55 | KeyF1: "\x1bOP", 56 | KeyF2: "\x1bOQ", 57 | KeyF3: "\x1bOR", 58 | KeyF4: "\x1bOS", 59 | KeyF5: "\x1b[15~", 60 | KeyF6: "\x1b[17~", 61 | KeyF7: "\x1b[18~", 62 | KeyF8: "\x1b[19~", 63 | KeyF9: "\x1b[20~", 64 | KeyF10: "\x1b[21~", 65 | KeyF11: "\x1b[23~", 66 | KeyF12: "\x1b[24~", 67 | KeyBacktab: "\x1b[Z", 68 | Modifiers: 1, 69 | AutoMargin: true, 70 | DoubleUnderline: "\x1b[4:2m", 71 | CurlyUnderline: "\x1b[4:3m", 72 | DottedUnderline: "\x1b[4:4m", 73 | DashedUnderline: "\x1b[4:5m", 74 | XTermLike: true, 75 | }) 76 | } 77 | -------------------------------------------------------------------------------- /terminfo/a/ansi/term.go: -------------------------------------------------------------------------------- 1 | // Generated automatically. DO NOT HAND-EDIT. 2 | 3 | package ansi 4 | 5 | import "github.com/gdamore/tcell/v2/terminfo" 6 | 7 | func init() { 8 | 9 | // ansi/pc-term compatible with color 10 | terminfo.AddTerminfo(&terminfo.Terminfo{ 11 | Name: "ansi", 12 | Columns: 80, 13 | Lines: 24, 14 | Colors: 8, 15 | Bell: "\a", 16 | Clear: "\x1b[H\x1b[J", 17 | AttrOff: "\x1b[0;10m", 18 | Underline: "\x1b[4m", 19 | Bold: "\x1b[1m", 20 | Blink: "\x1b[5m", 21 | Reverse: "\x1b[7m", 22 | SetFg: "\x1b[3%p1%dm", 23 | SetBg: "\x1b[4%p1%dm", 24 | SetFgBg: "\x1b[3%p1%d;4%p2%dm", 25 | ResetFgBg: "\x1b[39;49m", 26 | PadChar: "\x00", 27 | AltChars: "+\x10,\x11-\x18.\x190\xdb`\x04a\xb1f\xf8g\xf1h\xb0j\xd9k\xbfl\xdam\xc0n\xc5o~p\xc4q\xc4r\xc4s_t\xc3u\xb4v\xc1w\xc2x\xb3y\xf3z\xf2{\xe3|\xd8}\x9c~\xfe", 28 | EnterAcs: "\x1b[11m", 29 | ExitAcs: "\x1b[10m", 30 | SetCursor: "\x1b[%i%p1%d;%p2%dH", 31 | CursorBack1: "\x1b[D", 32 | CursorUp1: "\x1b[A", 33 | KeyUp: "\x1b[A", 34 | KeyDown: "\x1b[B", 35 | KeyRight: "\x1b[C", 36 | KeyLeft: "\x1b[D", 37 | KeyInsert: "\x1b[L", 38 | KeyBackspace: "\b", 39 | KeyHome: "\x1b[H", 40 | KeyBacktab: "\x1b[Z", 41 | AutoMargin: true, 42 | }) 43 | } 44 | -------------------------------------------------------------------------------- /terminfo/b/beterm/term.go: -------------------------------------------------------------------------------- 1 | // Generated automatically. DO NOT HAND-EDIT. 2 | 3 | package beterm 4 | 5 | import "github.com/gdamore/tcell/v2/terminfo" 6 | 7 | func init() { 8 | 9 | // BeOS Terminal 10 | terminfo.AddTerminfo(&terminfo.Terminfo{ 11 | Name: "beterm", 12 | Columns: 80, 13 | Lines: 25, 14 | Colors: 8, 15 | Bell: "\a", 16 | Clear: "\x1b[H\x1b[J", 17 | AttrOff: "\x1b[0;10m", 18 | Underline: "\x1b[4m", 19 | Bold: "\x1b[1m", 20 | Reverse: "\x1b[7m", 21 | EnterKeypad: "\x1b[?4h", 22 | ExitKeypad: "\x1b[?4l", 23 | SetFg: "\x1b[3%p1%dm", 24 | SetBg: "\x1b[4%p1%dm", 25 | SetFgBg: "\x1b[3%p1%d;4%p2%dm", 26 | ResetFgBg: "\x1b[m", 27 | PadChar: "\x00", 28 | SetCursor: "\x1b[%i%p1%d;%p2%dH", 29 | CursorBack1: "\b", 30 | CursorUp1: "\x1b[A", 31 | KeyUp: "\x1b[A", 32 | KeyDown: "\x1b[B", 33 | KeyRight: "\x1b[C", 34 | KeyLeft: "\x1b[D", 35 | KeyInsert: "\x1b[2~", 36 | KeyDelete: "\x1b[3~", 37 | KeyBackspace: "\b", 38 | KeyHome: "\x1b[1~", 39 | KeyEnd: "\x1b[4~", 40 | KeyPgUp: "\x1b[5~", 41 | KeyPgDn: "\x1b[6~", 42 | KeyF1: "\x1b[11~", 43 | KeyF2: "\x1b[12~", 44 | KeyF3: "\x1b[13~", 45 | KeyF4: "\x1b[14~", 46 | KeyF5: "\x1b[15~", 47 | KeyF6: "\x1b[16~", 48 | KeyF7: "\x1b[17~", 49 | KeyF8: "\x1b[18~", 50 | KeyF9: "\x1b[19~", 51 | KeyF10: "\x1b[20~", 52 | KeyF11: "\x1b[21~", 53 | KeyF12: "\x1b[22~", 54 | AutoMargin: true, 55 | InsertChar: "\x1b[@", 56 | }) 57 | } 58 | -------------------------------------------------------------------------------- /terminfo/base/base.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The TCell Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use file except in compliance with the License. 5 | // You may obtain a copy of the license at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // This is just a "minimalist" set of the base terminal descriptions. 16 | // It should be sufficient for most applications. 17 | 18 | // Package base contains the base terminal descriptions that are likely 19 | // to be needed by any stock application. It is imported by default in the 20 | // terminfo package, so terminal types listed here will be available to any 21 | // tcell application. 22 | package base 23 | 24 | import ( 25 | // The following imports just register themselves -- 26 | // these are the terminal types we aggregate in this package. 27 | _ "github.com/gdamore/tcell/v2/terminfo/a/ansi" 28 | _ "github.com/gdamore/tcell/v2/terminfo/v/vt100" 29 | _ "github.com/gdamore/tcell/v2/terminfo/v/vt102" 30 | _ "github.com/gdamore/tcell/v2/terminfo/v/vt220" 31 | _ "github.com/gdamore/tcell/v2/terminfo/x/xterm" 32 | ) 33 | -------------------------------------------------------------------------------- /terminfo/c/cygwin/term.go: -------------------------------------------------------------------------------- 1 | // Generated automatically. DO NOT HAND-EDIT. 2 | 3 | package cygwin 4 | 5 | import "github.com/gdamore/tcell/v2/terminfo" 6 | 7 | func init() { 8 | 9 | // ANSI emulation for Cygwin 10 | terminfo.AddTerminfo(&terminfo.Terminfo{ 11 | Name: "cygwin", 12 | Colors: 8, 13 | Bell: "\a", 14 | Clear: "\x1b[H\x1b[J", 15 | EnterCA: "\x1b7\x1b[?47h", 16 | ExitCA: "\x1b[2J\x1b[?47l\x1b8", 17 | AttrOff: "\x1b[0;10m", 18 | Underline: "\x1b[4m", 19 | Bold: "\x1b[1m", 20 | Reverse: "\x1b[7m", 21 | SetFg: "\x1b[3%p1%dm", 22 | SetBg: "\x1b[4%p1%dm", 23 | SetFgBg: "\x1b[3%p1%d;4%p2%dm", 24 | ResetFgBg: "\x1b[39;49m", 25 | PadChar: "\x00", 26 | AltChars: "+\x10,\x11-\x18.\x190\xdb`\x04a\xb1f\xf8g\xf1h\xb0j\xd9k\xbfl\xdam\xc0n\xc5o~p\xc4q\xc4r\xc4s_t\xc3u\xb4v\xc1w\xc2x\xb3y\xf3z\xf2{\xe3|\xd8}\x9c~\xfe", 27 | EnterAcs: "\x1b[11m", 28 | ExitAcs: "\x1b[10m", 29 | SetCursor: "\x1b[%i%p1%d;%p2%dH", 30 | CursorBack1: "\b", 31 | CursorUp1: "\x1b[A", 32 | KeyUp: "\x1b[A", 33 | KeyDown: "\x1b[B", 34 | KeyRight: "\x1b[C", 35 | KeyLeft: "\x1b[D", 36 | KeyInsert: "\x1b[2~", 37 | KeyDelete: "\x1b[3~", 38 | KeyBackspace: "\b", 39 | KeyHome: "\x1b[1~", 40 | KeyEnd: "\x1b[4~", 41 | KeyPgUp: "\x1b[5~", 42 | KeyPgDn: "\x1b[6~", 43 | KeyF1: "\x1b[[A", 44 | KeyF2: "\x1b[[B", 45 | KeyF3: "\x1b[[C", 46 | KeyF4: "\x1b[[D", 47 | KeyF5: "\x1b[[E", 48 | KeyF6: "\x1b[17~", 49 | KeyF7: "\x1b[18~", 50 | KeyF8: "\x1b[19~", 51 | KeyF9: "\x1b[20~", 52 | KeyF10: "\x1b[21~", 53 | KeyF11: "\x1b[23~", 54 | KeyF12: "\x1b[24~", 55 | KeyF13: "\x1b[25~", 56 | KeyF14: "\x1b[26~", 57 | KeyF15: "\x1b[28~", 58 | KeyF16: "\x1b[29~", 59 | KeyF17: "\x1b[31~", 60 | KeyF18: "\x1b[32~", 61 | KeyF19: "\x1b[33~", 62 | KeyF20: "\x1b[34~", 63 | AutoMargin: true, 64 | InsertChar: "\x1b[@", 65 | }) 66 | } 67 | -------------------------------------------------------------------------------- /terminfo/d/dtterm/term.go: -------------------------------------------------------------------------------- 1 | // Generated automatically. DO NOT HAND-EDIT. 2 | 3 | package dtterm 4 | 5 | import "github.com/gdamore/tcell/v2/terminfo" 6 | 7 | func init() { 8 | 9 | // CDE desktop terminal 10 | terminfo.AddTerminfo(&terminfo.Terminfo{ 11 | Name: "dtterm", 12 | Columns: 80, 13 | Lines: 24, 14 | Colors: 8, 15 | Bell: "\a", 16 | Clear: "\x1b[H\x1b[J", 17 | ShowCursor: "\x1b[?25h", 18 | HideCursor: "\x1b[?25l", 19 | AttrOff: "\x1b[m\x0f", 20 | Underline: "\x1b[4m", 21 | Bold: "\x1b[1m", 22 | Dim: "\x1b[2m", 23 | Blink: "\x1b[5m", 24 | Reverse: "\x1b[7m", 25 | SetFg: "\x1b[3%p1%dm", 26 | SetBg: "\x1b[4%p1%dm", 27 | SetFgBg: "\x1b[3%p1%d;4%p2%dm", 28 | ResetFgBg: "\x1b[39;49m", 29 | PadChar: "\x00", 30 | AltChars: "``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~", 31 | EnterAcs: "\x0e", 32 | ExitAcs: "\x0f", 33 | EnableAcs: "\x1b(B\x1b)0", 34 | EnableAutoMargin: "\x1b[?7h", 35 | DisableAutoMargin: "\x1b[?7l", 36 | SetCursor: "\x1b[%i%p1%d;%p2%dH", 37 | CursorBack1: "\b", 38 | CursorUp1: "\x1b[A", 39 | KeyUp: "\x1b[A", 40 | KeyDown: "\x1b[B", 41 | KeyRight: "\x1b[C", 42 | KeyLeft: "\x1b[D", 43 | KeyInsert: "\x1b[2~", 44 | KeyDelete: "\x1b[3~", 45 | KeyBackspace: "\b", 46 | KeyPgUp: "\x1b[5~", 47 | KeyPgDn: "\x1b[6~", 48 | KeyF1: "\x1b[11~", 49 | KeyF2: "\x1b[12~", 50 | KeyF3: "\x1b[13~", 51 | KeyF4: "\x1b[14~", 52 | KeyF5: "\x1b[15~", 53 | KeyF6: "\x1b[17~", 54 | KeyF7: "\x1b[18~", 55 | KeyF8: "\x1b[19~", 56 | KeyF9: "\x1b[20~", 57 | KeyF10: "\x1b[21~", 58 | KeyF11: "\x1b[23~", 59 | KeyF12: "\x1b[24~", 60 | KeyF13: "\x1b[25~", 61 | KeyF14: "\x1b[26~", 62 | KeyF15: "\x1b[28~", 63 | KeyF16: "\x1b[29~", 64 | KeyF17: "\x1b[31~", 65 | KeyF18: "\x1b[32~", 66 | KeyF19: "\x1b[33~", 67 | KeyF20: "\x1b[34~", 68 | KeyHelp: "\x1b[28~", 69 | AutoMargin: true, 70 | }) 71 | } 72 | -------------------------------------------------------------------------------- /terminfo/e/emacs/term.go: -------------------------------------------------------------------------------- 1 | // Generated automatically. DO NOT HAND-EDIT. 2 | 3 | package emacs 4 | 5 | import "github.com/gdamore/tcell/v2/terminfo" 6 | 7 | func init() { 8 | 9 | // GNU Emacs term.el terminal emulation 10 | terminfo.AddTerminfo(&terminfo.Terminfo{ 11 | Name: "eterm", 12 | Columns: 80, 13 | Lines: 24, 14 | Bell: "\a", 15 | Clear: "\x1b[H\x1b[J", 16 | EnterCA: "\x1b7\x1b[?47h", 17 | ExitCA: "\x1b[2J\x1b[?47l\x1b8", 18 | AttrOff: "\x1b[m", 19 | Underline: "\x1b[4m", 20 | Bold: "\x1b[1m", 21 | Reverse: "\x1b[7m", 22 | PadChar: "\x00", 23 | SetCursor: "\x1b[%i%p1%d;%p2%dH", 24 | CursorBack1: "\b", 25 | CursorUp1: "\x1b[A", 26 | AutoMargin: true, 27 | }) 28 | 29 | // Emacs term.el terminal emulator term-protocol-version 0.96 30 | terminfo.AddTerminfo(&terminfo.Terminfo{ 31 | Name: "eterm-color", 32 | Columns: 80, 33 | Lines: 24, 34 | Colors: 8, 35 | Bell: "\a", 36 | Clear: "\x1b[H\x1b[J", 37 | EnterCA: "\x1b7\x1b[?47h", 38 | ExitCA: "\x1b[2J\x1b[?47l\x1b8", 39 | AttrOff: "\x1b[m", 40 | Underline: "\x1b[4m", 41 | Bold: "\x1b[1m", 42 | Blink: "\x1b[5m", 43 | Reverse: "\x1b[7m", 44 | SetFg: "\x1b[%p1%{30}%+%dm", 45 | SetBg: "\x1b[%p1%'('%+%dm", 46 | SetFgBg: "\x1b[%p1%{30}%+%d;%p2%'('%+%dm", 47 | ResetFgBg: "\x1b[39;49m", 48 | PadChar: "\x00", 49 | SetCursor: "\x1b[%i%p1%d;%p2%dH", 50 | CursorBack1: "\b", 51 | CursorUp1: "\x1b[A", 52 | KeyUp: "\x1bOA", 53 | KeyDown: "\x1bOB", 54 | KeyRight: "\x1bOC", 55 | KeyLeft: "\x1bOD", 56 | KeyInsert: "\x1b[2~", 57 | KeyDelete: "\x1b[3~", 58 | KeyBackspace: "\x7f", 59 | KeyHome: "\x1b[1~", 60 | KeyEnd: "\x1b[4~", 61 | KeyPgUp: "\x1b[5~", 62 | KeyPgDn: "\x1b[6~", 63 | AutoMargin: true, 64 | }) 65 | } 66 | -------------------------------------------------------------------------------- /terminfo/extended/extended.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 The TCell Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use file except in compliance with the License. 5 | // You may obtain a copy of the license at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package extended contains an extended set of terminal descriptions. 16 | // Applications desiring to have a better chance of Just Working by 17 | // default should include this package. This will significantly increase 18 | // the size of the program. 19 | package extended 20 | 21 | import ( 22 | // The following imports just register themselves -- 23 | // these are the terminal types we aggregate in this package. 24 | _ "github.com/gdamore/tcell/v2/terminfo/a/aixterm" 25 | _ "github.com/gdamore/tcell/v2/terminfo/a/alacritty" 26 | _ "github.com/gdamore/tcell/v2/terminfo/a/ansi" 27 | _ "github.com/gdamore/tcell/v2/terminfo/b/beterm" 28 | _ "github.com/gdamore/tcell/v2/terminfo/c/cygwin" 29 | _ "github.com/gdamore/tcell/v2/terminfo/d/dtterm" 30 | _ "github.com/gdamore/tcell/v2/terminfo/e/emacs" 31 | _ "github.com/gdamore/tcell/v2/terminfo/f/foot" 32 | _ "github.com/gdamore/tcell/v2/terminfo/g/gnome" 33 | _ "github.com/gdamore/tcell/v2/terminfo/h/hpterm" 34 | _ "github.com/gdamore/tcell/v2/terminfo/k/konsole" 35 | _ "github.com/gdamore/tcell/v2/terminfo/k/kterm" 36 | _ "github.com/gdamore/tcell/v2/terminfo/l/linux" 37 | _ "github.com/gdamore/tcell/v2/terminfo/p/pcansi" 38 | _ "github.com/gdamore/tcell/v2/terminfo/r/rxvt" 39 | _ "github.com/gdamore/tcell/v2/terminfo/s/screen" 40 | _ "github.com/gdamore/tcell/v2/terminfo/s/simpleterm" 41 | _ "github.com/gdamore/tcell/v2/terminfo/s/sun" 42 | _ "github.com/gdamore/tcell/v2/terminfo/t/tmux" 43 | _ "github.com/gdamore/tcell/v2/terminfo/v/vt100" 44 | _ "github.com/gdamore/tcell/v2/terminfo/v/vt102" 45 | _ "github.com/gdamore/tcell/v2/terminfo/v/vt220" 46 | _ "github.com/gdamore/tcell/v2/terminfo/v/vt320" 47 | _ "github.com/gdamore/tcell/v2/terminfo/v/vt400" 48 | _ "github.com/gdamore/tcell/v2/terminfo/v/vt420" 49 | _ "github.com/gdamore/tcell/v2/terminfo/v/vt52" 50 | _ "github.com/gdamore/tcell/v2/terminfo/w/wy50" 51 | _ "github.com/gdamore/tcell/v2/terminfo/w/wy60" 52 | _ "github.com/gdamore/tcell/v2/terminfo/w/wy99_ansi" 53 | _ "github.com/gdamore/tcell/v2/terminfo/x/xfce" 54 | _ "github.com/gdamore/tcell/v2/terminfo/x/xterm" 55 | _ "github.com/gdamore/tcell/v2/terminfo/x/xterm_ghostty" 56 | _ "github.com/gdamore/tcell/v2/terminfo/x/xterm_kitty" 57 | ) 58 | -------------------------------------------------------------------------------- /terminfo/f/foot/foot.go: -------------------------------------------------------------------------------- 1 | // Generated automatically. DO NOT HAND-EDIT. 2 | 3 | package foot 4 | 5 | import "github.com/gdamore/tcell/v2/terminfo" 6 | 7 | func init() { 8 | 9 | // foot terminal emulator 10 | terminfo.AddTerminfo(&terminfo.Terminfo{ 11 | Name: "foot", 12 | Aliases: []string{"foot-extra"}, 13 | Columns: 80, 14 | Lines: 24, 15 | Colors: 256, 16 | Bell: "\a", 17 | Clear: "\x1b[H\x1b[2J", 18 | EnterCA: "\x1b[?1049h\x1b[22;0;0t", 19 | ExitCA: "\x1b[?1049l\x1b[23;0;0t", 20 | ShowCursor: "\x1b[?12l\x1b[?25h", 21 | HideCursor: "\x1b[?25l", 22 | AttrOff: "\x1b(B\x1b[m", 23 | Underline: "\x1b[4m", 24 | Bold: "\x1b[1m", 25 | Dim: "\x1b[2m", 26 | Italic: "\x1b[3m", 27 | Blink: "\x1b[5m", 28 | Reverse: "\x1b[7m", 29 | EnterKeypad: "\x1b[?1h\x1b=", 30 | ExitKeypad: "\x1b[?1l\x1b>", 31 | SetFg: "\x1b[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38:5:%p1%d%;m", 32 | SetBg: "\x1b[%?%p1%{8}%<%t4%p1%d%e%p1%{16}%<%t10%p1%{8}%-%d%e48:5:%p1%d%;m", 33 | SetFgBg: "\x1b[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38:5:%p1%d%;;%?%p2%{8}%<%t4%p2%d%e%p2%{16}%<%t10%p2%{8}%-%d%e48:5:%p2%d%;m", 34 | ResetFgBg: "\x1b[39;49m", 35 | AltChars: "``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~", 36 | EnterAcs: "\x1b(0", 37 | ExitAcs: "\x1b(B", 38 | StrikeThrough: "\x1b[9m", 39 | Mouse: "\x1b[M", 40 | SetCursor: "\x1b[%i%p1%d;%p2%dH", 41 | CursorBack1: "\b", 42 | CursorUp1: "\x1b[A", 43 | KeyUp: "\x1bOA", 44 | KeyDown: "\x1bOB", 45 | KeyRight: "\x1bOC", 46 | KeyLeft: "\x1bOD", 47 | KeyInsert: "\x1b[2~", 48 | KeyDelete: "\x1b[3~", 49 | KeyBackspace: "\u007f", 50 | KeyHome: "\x1bOH", 51 | KeyEnd: "\x1bOF", 52 | KeyPgUp: "\x1b[5~", 53 | KeyPgDn: "\x1b[6~", 54 | KeyF1: "\x1bOP", 55 | KeyF2: "\x1bOQ", 56 | KeyF3: "\x1bOR", 57 | KeyF4: "\x1bOS", 58 | KeyF5: "\x1b[15~", 59 | KeyF6: "\x1b[17~", 60 | KeyF7: "\x1b[18~", 61 | KeyF8: "\x1b[19~", 62 | KeyF9: "\x1b[20~", 63 | KeyF10: "\x1b[21~", 64 | KeyF11: "\x1b[23~", 65 | KeyF12: "\x1b[24~", 66 | KeyBacktab: "\x1b[Z", 67 | Modifiers: 1, 68 | AutoMargin: true, 69 | }) 70 | } 71 | -------------------------------------------------------------------------------- /terminfo/g/gnome/term.go: -------------------------------------------------------------------------------- 1 | // Generated automatically. DO NOT HAND-EDIT. 2 | 3 | package gnome 4 | 5 | import "github.com/gdamore/tcell/v2/terminfo" 6 | 7 | func init() { 8 | 9 | // GNOME Terminal 10 | terminfo.AddTerminfo(&terminfo.Terminfo{ 11 | Name: "gnome", 12 | Columns: 80, 13 | Lines: 24, 14 | Colors: 8, 15 | Bell: "\a", 16 | Clear: "\x1b[H\x1b[2J", 17 | EnterCA: "\x1b7\x1b[?47h", 18 | ExitCA: "\x1b[2J\x1b[?47l\x1b8", 19 | ShowCursor: "\x1b[?25h", 20 | HideCursor: "\x1b[?25l", 21 | AttrOff: "\x1b[0m\x0f", 22 | Underline: "\x1b[4m", 23 | Bold: "\x1b[1m", 24 | Dim: "\x1b[2m", 25 | Italic: "\x1b[3m", 26 | Reverse: "\x1b[7m", 27 | EnterKeypad: "\x1b[?1h\x1b=", 28 | ExitKeypad: "\x1b[?1l\x1b>", 29 | SetFg: "\x1b[3%p1%dm", 30 | SetBg: "\x1b[4%p1%dm", 31 | SetFgBg: "\x1b[3%p1%d;4%p2%dm", 32 | ResetFgBg: "\x1b[39;49m", 33 | PadChar: "\x00", 34 | AltChars: "``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~", 35 | EnterAcs: "\x0e", 36 | ExitAcs: "\x0f", 37 | EnableAcs: "\x1b)0", 38 | EnableAutoMargin: "\x1b[?7h", 39 | DisableAutoMargin: "\x1b[?7l", 40 | Mouse: "\x1b[M", 41 | SetCursor: "\x1b[%i%p1%d;%p2%dH", 42 | CursorBack1: "\b", 43 | CursorUp1: "\x1b[A", 44 | KeyUp: "\x1bOA", 45 | KeyDown: "\x1bOB", 46 | KeyRight: "\x1bOC", 47 | KeyLeft: "\x1bOD", 48 | KeyInsert: "\x1b[2~", 49 | KeyDelete: "\x1b[3~", 50 | KeyBackspace: "\x7f", 51 | KeyHome: "\x1bOH", 52 | KeyEnd: "\x1bOF", 53 | KeyPgUp: "\x1b[5~", 54 | KeyPgDn: "\x1b[6~", 55 | KeyF1: "\x1bOP", 56 | KeyF2: "\x1bOQ", 57 | KeyF3: "\x1bOR", 58 | KeyF4: "\x1bOS", 59 | KeyF5: "\x1b[15~", 60 | KeyF6: "\x1b[17~", 61 | KeyF7: "\x1b[18~", 62 | KeyF8: "\x1b[19~", 63 | KeyF9: "\x1b[20~", 64 | KeyF10: "\x1b[21~", 65 | KeyF11: "\x1b[23~", 66 | KeyF12: "\x1b[24~", 67 | KeyBacktab: "\x1b[Z", 68 | Modifiers: 1, 69 | AutoMargin: true, 70 | XTermLike: true, 71 | }) 72 | 73 | // GNOME Terminal with xterm 256-colors 74 | terminfo.AddTerminfo(&terminfo.Terminfo{ 75 | Name: "gnome-256color", 76 | Columns: 80, 77 | Lines: 24, 78 | Colors: 256, 79 | Bell: "\a", 80 | Clear: "\x1b[H\x1b[2J", 81 | EnterCA: "\x1b7\x1b[?47h", 82 | ExitCA: "\x1b[2J\x1b[?47l\x1b8", 83 | ShowCursor: "\x1b[?25h", 84 | HideCursor: "\x1b[?25l", 85 | AttrOff: "\x1b[0m\x0f", 86 | Underline: "\x1b[4m", 87 | Bold: "\x1b[1m", 88 | Dim: "\x1b[2m", 89 | Italic: "\x1b[3m", 90 | Reverse: "\x1b[7m", 91 | EnterKeypad: "\x1b[?1h\x1b=", 92 | ExitKeypad: "\x1b[?1l\x1b>", 93 | SetFg: "\x1b[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;m", 94 | SetBg: "\x1b[%?%p1%{8}%<%t4%p1%d%e%p1%{16}%<%t10%p1%{8}%-%d%e48;5;%p1%d%;m", 95 | SetFgBg: "\x1b[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;;%?%p2%{8}%<%t4%p2%d%e%p2%{16}%<%t10%p2%{8}%-%d%e48;5;%p2%d%;m", 96 | ResetFgBg: "\x1b[39;49m", 97 | PadChar: "\x00", 98 | AltChars: "``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~", 99 | EnterAcs: "\x0e", 100 | ExitAcs: "\x0f", 101 | EnableAcs: "\x1b)0", 102 | EnableAutoMargin: "\x1b[?7h", 103 | DisableAutoMargin: "\x1b[?7l", 104 | Mouse: "\x1b[M", 105 | SetCursor: "\x1b[%i%p1%d;%p2%dH", 106 | CursorBack1: "\b", 107 | CursorUp1: "\x1b[A", 108 | KeyUp: "\x1bOA", 109 | KeyDown: "\x1bOB", 110 | KeyRight: "\x1bOC", 111 | KeyLeft: "\x1bOD", 112 | KeyInsert: "\x1b[2~", 113 | KeyDelete: "\x1b[3~", 114 | KeyBackspace: "\x7f", 115 | KeyHome: "\x1bOH", 116 | KeyEnd: "\x1bOF", 117 | KeyPgUp: "\x1b[5~", 118 | KeyPgDn: "\x1b[6~", 119 | KeyF1: "\x1bOP", 120 | KeyF2: "\x1bOQ", 121 | KeyF3: "\x1bOR", 122 | KeyF4: "\x1bOS", 123 | KeyF5: "\x1b[15~", 124 | KeyF6: "\x1b[17~", 125 | KeyF7: "\x1b[18~", 126 | KeyF8: "\x1b[19~", 127 | KeyF9: "\x1b[20~", 128 | KeyF10: "\x1b[21~", 129 | KeyF11: "\x1b[23~", 130 | KeyF12: "\x1b[24~", 131 | KeyBacktab: "\x1b[Z", 132 | Modifiers: 1, 133 | AutoMargin: true, 134 | XTermLike: true, 135 | }) 136 | } 137 | -------------------------------------------------------------------------------- /terminfo/gen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | while read line 3 | do 4 | case "$line" in 5 | *'|'*) 6 | alias=${line#*|} 7 | line=${line%|*} 8 | ;; 9 | *) 10 | alias=${line%%,*} 11 | ;; 12 | esac 13 | 14 | alias=${alias//-/_} 15 | direc=${alias:0:1} 16 | 17 | mkdir -p ${direc}/${alias} 18 | go run mkinfo.go -P ${alias} -go ${direc}/${alias}/term.go ${line//,/ } 19 | done < models.txt 20 | -------------------------------------------------------------------------------- /terminfo/h/hpterm/term.go: -------------------------------------------------------------------------------- 1 | // Generated automatically. DO NOT HAND-EDIT. 2 | 3 | package hpterm 4 | 5 | import "github.com/gdamore/tcell/v2/terminfo" 6 | 7 | func init() { 8 | 9 | // HP X11 terminal emulator (old) 10 | terminfo.AddTerminfo(&terminfo.Terminfo{ 11 | Name: "hpterm", 12 | Aliases: []string{"X-hpterm"}, 13 | Columns: 80, 14 | Lines: 24, 15 | Bell: "\a", 16 | Clear: "\x1b&a0y0C\x1bJ", 17 | AttrOff: "\x1b&d@\x0f", 18 | Underline: "\x1b&dD", 19 | Bold: "\x1b&dB", 20 | Dim: "\x1b&dH", 21 | Reverse: "\x1b&dB", 22 | EnterKeypad: "\x1b&s1A", 23 | ExitKeypad: "\x1b&s0A", 24 | PadChar: "\x00", 25 | EnterAcs: "\x0e", 26 | ExitAcs: "\x0f", 27 | SetCursor: "\x1b&a%p1%dy%p2%dC", 28 | CursorBack1: "\b", 29 | CursorUp1: "\x1bA", 30 | KeyUp: "\x1bA", 31 | KeyDown: "\x1bB", 32 | KeyRight: "\x1bC", 33 | KeyLeft: "\x1bD", 34 | KeyInsert: "\x1bQ", 35 | KeyDelete: "\x1bP", 36 | KeyBackspace: "\b", 37 | KeyHome: "\x1bh", 38 | KeyPgUp: "\x1bV", 39 | KeyPgDn: "\x1bU", 40 | KeyF1: "\x1bp", 41 | KeyF2: "\x1bq", 42 | KeyF3: "\x1br", 43 | KeyF4: "\x1bs", 44 | KeyF5: "\x1bt", 45 | KeyF6: "\x1bu", 46 | KeyF7: "\x1bv", 47 | KeyF8: "\x1bw", 48 | KeyClear: "\x1bJ", 49 | AutoMargin: true, 50 | }) 51 | } 52 | -------------------------------------------------------------------------------- /terminfo/k/kterm/term.go: -------------------------------------------------------------------------------- 1 | // Generated automatically. DO NOT HAND-EDIT. 2 | 3 | package kterm 4 | 5 | import "github.com/gdamore/tcell/v2/terminfo" 6 | 7 | func init() { 8 | 9 | // kterm kanji terminal emulator (X window system) 10 | terminfo.AddTerminfo(&terminfo.Terminfo{ 11 | Name: "kterm", 12 | Columns: 80, 13 | Lines: 24, 14 | Colors: 8, 15 | Bell: "\a", 16 | Clear: "\x1b[H\x1b[2J", 17 | EnterCA: "\x1b7\x1b[?47h", 18 | ExitCA: "\x1b[2J\x1b[?47l\x1b8", 19 | AttrOff: "\x1b[m\x1b(B", 20 | Underline: "\x1b[4m", 21 | Bold: "\x1b[1m", 22 | Reverse: "\x1b[7m", 23 | EnterKeypad: "\x1b[?1h\x1b=", 24 | ExitKeypad: "\x1b[?1l\x1b>", 25 | SetFg: "\x1b[3%p1%dm", 26 | SetBg: "\x1b[4%p1%dm", 27 | SetFgBg: "\x1b[3%p1%d;4%p2%dm", 28 | ResetFgBg: "\x1b[39;49m", 29 | PadChar: "\x00", 30 | AltChars: "``aajjkkllmmnnooppqqrrssttuuvvwwxx~~", 31 | EnterAcs: "\x1b(0", 32 | ExitAcs: "\x1b(B", 33 | EnableAutoMargin: "\x1b[?7h", 34 | DisableAutoMargin: "\x1b[?7l", 35 | Mouse: "\x1b[M", 36 | SetCursor: "\x1b[%i%p1%d;%p2%dH", 37 | CursorBack1: "\b", 38 | CursorUp1: "\x1b[A", 39 | KeyUp: "\x1bOA", 40 | KeyDown: "\x1bOB", 41 | KeyRight: "\x1bOC", 42 | KeyLeft: "\x1bOD", 43 | KeyInsert: "\x1b[2~", 44 | KeyDelete: "\x1b[3~", 45 | KeyBackspace: "\x7f", 46 | KeyPgUp: "\x1b[5~", 47 | KeyPgDn: "\x1b[6~", 48 | KeyF1: "\x1b[11~", 49 | KeyF2: "\x1b[12~", 50 | KeyF3: "\x1b[13~", 51 | KeyF4: "\x1b[14~", 52 | KeyF5: "\x1b[15~", 53 | KeyF6: "\x1b[17~", 54 | KeyF7: "\x1b[18~", 55 | KeyF8: "\x1b[19~", 56 | KeyF9: "\x1b[20~", 57 | KeyF10: "\x1b[21~", 58 | KeyF11: "\x1b[23~", 59 | KeyF12: "\x1b[24~", 60 | KeyF13: "\x1b[25~", 61 | KeyF14: "\x1b[26~", 62 | KeyF15: "\x1b[28~", 63 | KeyF16: "\x1b[29~", 64 | KeyF17: "\x1b[31~", 65 | KeyF18: "\x1b[32~", 66 | KeyF19: "\x1b[33~", 67 | KeyF20: "\x1b[34~", 68 | AutoMargin: true, 69 | XTermLike: true, 70 | }) 71 | } 72 | -------------------------------------------------------------------------------- /terminfo/l/linux/term.go: -------------------------------------------------------------------------------- 1 | // Generated automatically. DO NOT HAND-EDIT. 2 | 3 | package linux 4 | 5 | import "github.com/gdamore/tcell/v2/terminfo" 6 | 7 | func init() { 8 | 9 | // Linux console 10 | terminfo.AddTerminfo(&terminfo.Terminfo{ 11 | Name: "linux", 12 | Colors: 8, 13 | Bell: "\a", 14 | Clear: "\x1b[H\x1b[J", 15 | ShowCursor: "\x1b[?25h\x1b[?0c", 16 | HideCursor: "\x1b[?25l\x1b[?1c", 17 | AttrOff: "\x1b[m\x0f", 18 | Underline: "\x1b[4m", 19 | Bold: "\x1b[1m", 20 | Dim: "\x1b[2m", 21 | Blink: "\x1b[5m", 22 | Reverse: "\x1b[7m", 23 | SetFg: "\x1b[3%p1%dm", 24 | SetBg: "\x1b[4%p1%dm", 25 | SetFgBg: "\x1b[3%p1%d;4%p2%dm", 26 | ResetFgBg: "\x1b[39;49m", 27 | PadChar: "\x00", 28 | AltChars: "++,,--..00``aaffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~", 29 | EnterAcs: "\x0e", 30 | ExitAcs: "\x0f", 31 | EnableAcs: "\x1b)0", 32 | EnableAutoMargin: "\x1b[?7h", 33 | DisableAutoMargin: "\x1b[?7l", 34 | Mouse: "\x1b[M", 35 | SetCursor: "\x1b[%i%p1%d;%p2%dH", 36 | CursorBack1: "\b", 37 | CursorUp1: "\x1b[A", 38 | KeyUp: "\x1b[A", 39 | KeyDown: "\x1b[B", 40 | KeyRight: "\x1b[C", 41 | KeyLeft: "\x1b[D", 42 | KeyInsert: "\x1b[2~", 43 | KeyDelete: "\x1b[3~", 44 | KeyBackspace: "\x7f", 45 | KeyHome: "\x1b[1~", 46 | KeyEnd: "\x1b[4~", 47 | KeyPgUp: "\x1b[5~", 48 | KeyPgDn: "\x1b[6~", 49 | KeyF1: "\x1b[[A", 50 | KeyF2: "\x1b[[B", 51 | KeyF3: "\x1b[[C", 52 | KeyF4: "\x1b[[D", 53 | KeyF5: "\x1b[[E", 54 | KeyF6: "\x1b[17~", 55 | KeyF7: "\x1b[18~", 56 | KeyF8: "\x1b[19~", 57 | KeyF9: "\x1b[20~", 58 | KeyF10: "\x1b[21~", 59 | KeyF11: "\x1b[23~", 60 | KeyF12: "\x1b[24~", 61 | KeyF13: "\x1b[25~", 62 | KeyF14: "\x1b[26~", 63 | KeyF15: "\x1b[28~", 64 | KeyF16: "\x1b[29~", 65 | KeyF17: "\x1b[31~", 66 | KeyF18: "\x1b[32~", 67 | KeyF19: "\x1b[33~", 68 | KeyF20: "\x1b[34~", 69 | KeyBacktab: "\x1b\t", 70 | AutoMargin: true, 71 | InsertChar: "\x1b[@", 72 | }) 73 | } 74 | -------------------------------------------------------------------------------- /terminfo/models.txt: -------------------------------------------------------------------------------- 1 | aixterm 2 | alacritty 3 | ansi 4 | beterm 5 | cygwin 6 | dtterm 7 | eterm,eterm-color|emacs 8 | gnome,gnome-256color 9 | hpterm 10 | konsole,konsole-256color 11 | kterm 12 | linux 13 | pcansi 14 | rxvt,rxvt-256color,rxvt-88color,rxvt-unicode,rxvt-unicode-256color 15 | screen,screen-256color 16 | st,st-256color|simpleterm 17 | tmux,tmux-256color 18 | vt52 19 | vt100 20 | vt102 21 | vt220 22 | vt320 23 | vt400 24 | vt420 25 | wy50 26 | wy60 27 | wy99-ansi,wy99a-ansi 28 | xfce 29 | xterm,xterm-88color,xterm-256color 30 | xterm-ghostty 31 | xterm-kitty 32 | -------------------------------------------------------------------------------- /terminfo/p/pcansi/term.go: -------------------------------------------------------------------------------- 1 | // Generated automatically. DO NOT HAND-EDIT. 2 | 3 | package pcansi 4 | 5 | import "github.com/gdamore/tcell/v2/terminfo" 6 | 7 | func init() { 8 | 9 | // ibm-pc terminal programs claiming to be ANSI 10 | terminfo.AddTerminfo(&terminfo.Terminfo{ 11 | Name: "pcansi", 12 | Columns: 80, 13 | Lines: 24, 14 | Colors: 8, 15 | Bell: "\a", 16 | Clear: "\x1b[H\x1b[J", 17 | AttrOff: "\x1b[0;10m", 18 | Underline: "\x1b[4m", 19 | Bold: "\x1b[1m", 20 | Blink: "\x1b[5m", 21 | Reverse: "\x1b[7m", 22 | SetFg: "\x1b[3%p1%dm", 23 | SetBg: "\x1b[4%p1%dm", 24 | SetFgBg: "\x1b[3%p1%d;4%p2%dm", 25 | ResetFgBg: "\x1b[37;40m", 26 | PadChar: "\x00", 27 | AltChars: "+\x10,\x11-\x18.\x190\xdb`\x04a\xb1f\xf8g\xf1h\xb0j\xd9k\xbfl\xdam\xc0n\xc5o~p\xc4q\xc4r\xc4s_t\xc3u\xb4v\xc1w\xc2x\xb3y\xf3z\xf2{\xe3|\xd8}\x9c~\xfe", 28 | EnterAcs: "\x1b[12m", 29 | ExitAcs: "\x1b[10m", 30 | SetCursor: "\x1b[%i%p1%d;%p2%dH", 31 | CursorBack1: "\x1b[D", 32 | CursorUp1: "\x1b[A", 33 | KeyUp: "\x1b[A", 34 | KeyDown: "\x1b[B", 35 | KeyRight: "\x1b[C", 36 | KeyLeft: "\x1b[D", 37 | KeyBackspace: "\b", 38 | KeyHome: "\x1b[H", 39 | AutoMargin: true, 40 | }) 41 | } 42 | -------------------------------------------------------------------------------- /terminfo/s/screen/term.go: -------------------------------------------------------------------------------- 1 | // Generated automatically. DO NOT HAND-EDIT. 2 | 3 | package screen 4 | 5 | import "github.com/gdamore/tcell/v2/terminfo" 6 | 7 | func init() { 8 | 9 | // VT 100/ANSI X3.64 virtual terminal 10 | terminfo.AddTerminfo(&terminfo.Terminfo{ 11 | Name: "screen", 12 | Columns: 80, 13 | Lines: 24, 14 | Colors: 8, 15 | Bell: "\a", 16 | Clear: "\x1b[H\x1b[J", 17 | EnterCA: "\x1b[?1049h", 18 | ExitCA: "\x1b[?1049l", 19 | ShowCursor: "\x1b[34h\x1b[?25h", 20 | HideCursor: "\x1b[?25l", 21 | AttrOff: "\x1b[m\x0f", 22 | Underline: "\x1b[4m", 23 | Bold: "\x1b[1m", 24 | Dim: "\x1b[2m", 25 | Blink: "\x1b[5m", 26 | Reverse: "\x1b[7m", 27 | EnterKeypad: "\x1b[?1h\x1b=", 28 | ExitKeypad: "\x1b[?1l\x1b>", 29 | SetFg: "\x1b[3%p1%dm", 30 | SetBg: "\x1b[4%p1%dm", 31 | SetFgBg: "\x1b[3%p1%d;4%p2%dm", 32 | ResetFgBg: "\x1b[39;49m", 33 | PadChar: "\x00", 34 | AltChars: "++,,--..00``aaffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~", 35 | EnterAcs: "\x0e", 36 | ExitAcs: "\x0f", 37 | EnableAcs: "\x1b(B\x1b)0", 38 | Mouse: "\x1b[M", 39 | SetCursor: "\x1b[%i%p1%d;%p2%dH", 40 | CursorBack1: "\b", 41 | CursorUp1: "\x1bM", 42 | KeyUp: "\x1bOA", 43 | KeyDown: "\x1bOB", 44 | KeyRight: "\x1bOC", 45 | KeyLeft: "\x1bOD", 46 | KeyInsert: "\x1b[2~", 47 | KeyDelete: "\x1b[3~", 48 | KeyBackspace: "\x7f", 49 | KeyHome: "\x1b[1~", 50 | KeyEnd: "\x1b[4~", 51 | KeyPgUp: "\x1b[5~", 52 | KeyPgDn: "\x1b[6~", 53 | KeyF1: "\x1bOP", 54 | KeyF2: "\x1bOQ", 55 | KeyF3: "\x1bOR", 56 | KeyF4: "\x1bOS", 57 | KeyF5: "\x1b[15~", 58 | KeyF6: "\x1b[17~", 59 | KeyF7: "\x1b[18~", 60 | KeyF8: "\x1b[19~", 61 | KeyF9: "\x1b[20~", 62 | KeyF10: "\x1b[21~", 63 | KeyF11: "\x1b[23~", 64 | KeyF12: "\x1b[24~", 65 | KeyBacktab: "\x1b[Z", 66 | AutoMargin: true, 67 | }) 68 | 69 | // GNU Screen with 256 colors 70 | terminfo.AddTerminfo(&terminfo.Terminfo{ 71 | Name: "screen-256color", 72 | Columns: 80, 73 | Lines: 24, 74 | Colors: 256, 75 | Bell: "\a", 76 | Clear: "\x1b[H\x1b[J", 77 | EnterCA: "\x1b[?1049h", 78 | ExitCA: "\x1b[?1049l", 79 | ShowCursor: "\x1b[34h\x1b[?25h", 80 | HideCursor: "\x1b[?25l", 81 | AttrOff: "\x1b[m\x0f", 82 | Underline: "\x1b[4m", 83 | Bold: "\x1b[1m", 84 | Dim: "\x1b[2m", 85 | Blink: "\x1b[5m", 86 | Reverse: "\x1b[7m", 87 | EnterKeypad: "\x1b[?1h\x1b=", 88 | ExitKeypad: "\x1b[?1l\x1b>", 89 | SetFg: "\x1b[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;m", 90 | SetBg: "\x1b[%?%p1%{8}%<%t4%p1%d%e%p1%{16}%<%t10%p1%{8}%-%d%e48;5;%p1%d%;m", 91 | SetFgBg: "\x1b[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;;%?%p2%{8}%<%t4%p2%d%e%p2%{16}%<%t10%p2%{8}%-%d%e48;5;%p2%d%;m", 92 | ResetFgBg: "\x1b[39;49m", 93 | PadChar: "\x00", 94 | AltChars: "++,,--..00``aaffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~", 95 | EnterAcs: "\x0e", 96 | ExitAcs: "\x0f", 97 | EnableAcs: "\x1b(B\x1b)0", 98 | Mouse: "\x1b[M", 99 | SetCursor: "\x1b[%i%p1%d;%p2%dH", 100 | CursorBack1: "\b", 101 | CursorUp1: "\x1bM", 102 | KeyUp: "\x1bOA", 103 | KeyDown: "\x1bOB", 104 | KeyRight: "\x1bOC", 105 | KeyLeft: "\x1bOD", 106 | KeyInsert: "\x1b[2~", 107 | KeyDelete: "\x1b[3~", 108 | KeyBackspace: "\x7f", 109 | KeyHome: "\x1b[1~", 110 | KeyEnd: "\x1b[4~", 111 | KeyPgUp: "\x1b[5~", 112 | KeyPgDn: "\x1b[6~", 113 | KeyF1: "\x1bOP", 114 | KeyF2: "\x1bOQ", 115 | KeyF3: "\x1bOR", 116 | KeyF4: "\x1bOS", 117 | KeyF5: "\x1b[15~", 118 | KeyF6: "\x1b[17~", 119 | KeyF7: "\x1b[18~", 120 | KeyF8: "\x1b[19~", 121 | KeyF9: "\x1b[20~", 122 | KeyF10: "\x1b[21~", 123 | KeyF11: "\x1b[23~", 124 | KeyF12: "\x1b[24~", 125 | KeyBacktab: "\x1b[Z", 126 | AutoMargin: true, 127 | }) 128 | } 129 | -------------------------------------------------------------------------------- /terminfo/s/simpleterm/term.go: -------------------------------------------------------------------------------- 1 | // Generated automatically. DO NOT HAND-EDIT. 2 | 3 | package simpleterm 4 | 5 | import "github.com/gdamore/tcell/v2/terminfo" 6 | 7 | func init() { 8 | 9 | // aka simpleterm 10 | terminfo.AddTerminfo(&terminfo.Terminfo{ 11 | Name: "st", 12 | Aliases: []string{"stterm"}, 13 | Columns: 80, 14 | Lines: 24, 15 | Colors: 8, 16 | Bell: "\a", 17 | Clear: "\x1b[H\x1b[2J", 18 | EnterCA: "\x1b[?1049h", 19 | ExitCA: "\x1b[?1049l", 20 | ShowCursor: "\x1b[?25h", 21 | HideCursor: "\x1b[?25l", 22 | AttrOff: "\x1b[0m", 23 | Underline: "\x1b[4m", 24 | Bold: "\x1b[1m", 25 | Dim: "\x1b[2m", 26 | Italic: "\x1b[3m", 27 | Blink: "\x1b[5m", 28 | Reverse: "\x1b[7m", 29 | EnterKeypad: "\x1b[?1h\x1b=", 30 | ExitKeypad: "\x1b[?1l\x1b>", 31 | SetFg: "\x1b[3%p1%dm", 32 | SetBg: "\x1b[4%p1%dm", 33 | SetFgBg: "\x1b[3%p1%d;4%p2%dm", 34 | ResetFgBg: "\x1b[39;49m", 35 | AltChars: "+C,D-A.B0E``aaffgghFiGjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~", 36 | EnterAcs: "\x1b(0", 37 | ExitAcs: "\x1b(B", 38 | EnableAcs: "\x1b)0", 39 | StrikeThrough: "\x1b[9m", 40 | Mouse: "\x1b[M", 41 | SetCursor: "\x1b[%i%p1%d;%p2%dH", 42 | CursorBack1: "\b", 43 | CursorUp1: "\x1b[A", 44 | KeyUp: "\x1bOA", 45 | KeyDown: "\x1bOB", 46 | KeyRight: "\x1bOC", 47 | KeyLeft: "\x1bOD", 48 | KeyInsert: "\x1b[2~", 49 | KeyDelete: "\x1b[3~", 50 | KeyBackspace: "\x7f", 51 | KeyHome: "\x1b[1~", 52 | KeyEnd: "\x1b[4~", 53 | KeyPgUp: "\x1b[5~", 54 | KeyPgDn: "\x1b[6~", 55 | KeyF1: "\x1bOP", 56 | KeyF2: "\x1bOQ", 57 | KeyF3: "\x1bOR", 58 | KeyF4: "\x1bOS", 59 | KeyF5: "\x1b[15~", 60 | KeyF6: "\x1b[17~", 61 | KeyF7: "\x1b[18~", 62 | KeyF8: "\x1b[19~", 63 | KeyF9: "\x1b[20~", 64 | KeyF10: "\x1b[21~", 65 | KeyF11: "\x1b[23~", 66 | KeyF12: "\x1b[24~", 67 | KeyClear: "\x1b[3;5~", 68 | Modifiers: 1, 69 | AutoMargin: true, 70 | XTermLike: true, 71 | }) 72 | 73 | // simpleterm with 256 colors 74 | terminfo.AddTerminfo(&terminfo.Terminfo{ 75 | Name: "st-256color", 76 | Aliases: []string{"stterm-256color"}, 77 | Columns: 80, 78 | Lines: 24, 79 | Colors: 256, 80 | Bell: "\a", 81 | Clear: "\x1b[H\x1b[2J", 82 | EnterCA: "\x1b[?1049h", 83 | ExitCA: "\x1b[?1049l", 84 | ShowCursor: "\x1b[?25h", 85 | HideCursor: "\x1b[?25l", 86 | AttrOff: "\x1b[0m", 87 | Underline: "\x1b[4m", 88 | Bold: "\x1b[1m", 89 | Dim: "\x1b[2m", 90 | Italic: "\x1b[3m", 91 | Blink: "\x1b[5m", 92 | Reverse: "\x1b[7m", 93 | EnterKeypad: "\x1b[?1h\x1b=", 94 | ExitKeypad: "\x1b[?1l\x1b>", 95 | SetFg: "\x1b[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;m", 96 | SetBg: "\x1b[%?%p1%{8}%<%t4%p1%d%e%p1%{16}%<%t10%p1%{8}%-%d%e48;5;%p1%d%;m", 97 | SetFgBg: "\x1b[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;;%?%p2%{8}%<%t4%p2%d%e%p2%{16}%<%t10%p2%{8}%-%d%e48;5;%p2%d%;m", 98 | ResetFgBg: "\x1b[39;49m", 99 | AltChars: "+C,D-A.B0E``aaffgghFiGjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~", 100 | EnterAcs: "\x1b(0", 101 | ExitAcs: "\x1b(B", 102 | EnableAcs: "\x1b)0", 103 | StrikeThrough: "\x1b[9m", 104 | Mouse: "\x1b[M", 105 | SetCursor: "\x1b[%i%p1%d;%p2%dH", 106 | CursorBack1: "\b", 107 | CursorUp1: "\x1b[A", 108 | KeyUp: "\x1bOA", 109 | KeyDown: "\x1bOB", 110 | KeyRight: "\x1bOC", 111 | KeyLeft: "\x1bOD", 112 | KeyInsert: "\x1b[2~", 113 | KeyDelete: "\x1b[3~", 114 | KeyBackspace: "\x7f", 115 | KeyHome: "\x1b[1~", 116 | KeyEnd: "\x1b[4~", 117 | KeyPgUp: "\x1b[5~", 118 | KeyPgDn: "\x1b[6~", 119 | KeyF1: "\x1bOP", 120 | KeyF2: "\x1bOQ", 121 | KeyF3: "\x1bOR", 122 | KeyF4: "\x1bOS", 123 | KeyF5: "\x1b[15~", 124 | KeyF6: "\x1b[17~", 125 | KeyF7: "\x1b[18~", 126 | KeyF8: "\x1b[19~", 127 | KeyF9: "\x1b[20~", 128 | KeyF10: "\x1b[21~", 129 | KeyF11: "\x1b[23~", 130 | KeyF12: "\x1b[24~", 131 | KeyClear: "\x1b[3;5~", 132 | Modifiers: 1, 133 | AutoMargin: true, 134 | XTermLike: true, 135 | }) 136 | } 137 | -------------------------------------------------------------------------------- /terminfo/s/sun/term.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The TCell Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use file except in compliance with the License. 5 | // You may obtain a copy of the license at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // This terminal definition is hand-coded, as the default terminfo for 16 | // this terminal is busted with respect to color. Unlike pretty much every 17 | // other ANSI compliant terminal, this terminal cannot combine foreground and 18 | // background escapes. The default terminfo also only provides escapes for 19 | // 16-bit color. 20 | 21 | package sun 22 | 23 | import "github.com/gdamore/tcell/v2/terminfo" 24 | 25 | func init() { 26 | 27 | // Sun Microsystems Inc. workstation console 28 | terminfo.AddTerminfo(&terminfo.Terminfo{ 29 | Name: "sun", 30 | Aliases: []string{"sun1", "sun2"}, 31 | Columns: 80, 32 | Lines: 34, 33 | Bell: "\a", 34 | Clear: "\f", 35 | AttrOff: "\x1b[m", 36 | Reverse: "\x1b[7m", 37 | PadChar: "\x00", 38 | SetCursor: "\x1b[%i%p1%d;%p2%dH", 39 | CursorBack1: "\b", 40 | CursorUp1: "\x1b[A", 41 | KeyUp: "\x1b[A", 42 | KeyDown: "\x1b[B", 43 | KeyRight: "\x1b[C", 44 | KeyLeft: "\x1b[D", 45 | KeyInsert: "\x1b[247z", 46 | KeyDelete: "\u007f", 47 | KeyBackspace: "\b", 48 | KeyHome: "\x1b[214z", 49 | KeyEnd: "\x1b[220z", 50 | KeyPgUp: "\x1b[216z", 51 | KeyPgDn: "\x1b[222z", 52 | KeyF1: "\x1b[224z", 53 | KeyF2: "\x1b[225z", 54 | KeyF3: "\x1b[226z", 55 | KeyF4: "\x1b[227z", 56 | KeyF5: "\x1b[228z", 57 | KeyF6: "\x1b[229z", 58 | KeyF7: "\x1b[230z", 59 | KeyF8: "\x1b[231z", 60 | KeyF9: "\x1b[232z", 61 | KeyF10: "\x1b[233z", 62 | KeyF11: "\x1b[234z", 63 | KeyF12: "\x1b[235z", 64 | AutoMargin: true, 65 | InsertChar: "\x1b[@", 66 | }) 67 | 68 | // Sun Microsystems Workstation console with color support (IA systems) 69 | terminfo.AddTerminfo(&terminfo.Terminfo{ 70 | Name: "sun-color", 71 | Columns: 80, 72 | Lines: 34, 73 | Colors: 256, 74 | Bell: "\a", 75 | Clear: "\f", 76 | AttrOff: "\x1b[m", 77 | Bold: "\x1b[1m", 78 | Reverse: "\x1b[7m", 79 | SetFg: "\x1b[38;5;%p1%dm", 80 | SetBg: "\x1b[48;5;%p1%dm", 81 | ResetFgBg: "\x1b[0m", 82 | PadChar: "\x00", 83 | SetCursor: "\x1b[%i%p1%d;%p2%dH", 84 | CursorBack1: "\b", 85 | CursorUp1: "\x1b[A", 86 | KeyUp: "\x1b[A", 87 | KeyDown: "\x1b[B", 88 | KeyRight: "\x1b[C", 89 | KeyLeft: "\x1b[D", 90 | KeyInsert: "\x1b[247z", 91 | KeyDelete: "\u007f", 92 | KeyBackspace: "\b", 93 | KeyHome: "\x1b[214z", 94 | KeyEnd: "\x1b[220z", 95 | KeyPgUp: "\x1b[216z", 96 | KeyPgDn: "\x1b[222z", 97 | KeyF1: "\x1b[224z", 98 | KeyF2: "\x1b[225z", 99 | KeyF3: "\x1b[226z", 100 | KeyF4: "\x1b[227z", 101 | KeyF5: "\x1b[228z", 102 | KeyF6: "\x1b[229z", 103 | KeyF7: "\x1b[230z", 104 | KeyF8: "\x1b[231z", 105 | KeyF9: "\x1b[232z", 106 | KeyF10: "\x1b[233z", 107 | KeyF11: "\x1b[234z", 108 | KeyF12: "\x1b[235z", 109 | AutoMargin: true, 110 | InsertChar: "\x1b[@", 111 | }) 112 | } 113 | -------------------------------------------------------------------------------- /terminfo/t/tmux/term.go: -------------------------------------------------------------------------------- 1 | // Generated automatically. DO NOT HAND-EDIT. 2 | 3 | package tmux 4 | 5 | import "github.com/gdamore/tcell/v2/terminfo" 6 | 7 | func init() { 8 | 9 | // tmux terminal multiplexer 10 | terminfo.AddTerminfo(&terminfo.Terminfo{ 11 | Name: "tmux", 12 | Columns: 80, 13 | Lines: 24, 14 | Colors: 8, 15 | Bell: "\a", 16 | Clear: "\x1b[H\x1b[J", 17 | EnterCA: "\x1b[?1049h", 18 | ExitCA: "\x1b[?1049l", 19 | ShowCursor: "\x1b[34h\x1b[?25h", 20 | HideCursor: "\x1b[?25l", 21 | AttrOff: "\x1b[m\x0f", 22 | Underline: "\x1b[4m", 23 | Bold: "\x1b[1m", 24 | Dim: "\x1b[2m", 25 | Italic: "\x1b[3m", 26 | Blink: "\x1b[5m", 27 | Reverse: "\x1b[7m", 28 | EnterKeypad: "\x1b[?1h\x1b=", 29 | ExitKeypad: "\x1b[?1l\x1b>", 30 | SetFg: "\x1b[3%p1%dm", 31 | SetBg: "\x1b[4%p1%dm", 32 | SetFgBg: "\x1b[3%p1%d;4%p2%dm", 33 | ResetFgBg: "\x1b[39;49m", 34 | PadChar: "\x00", 35 | AltChars: "++,,--..00``aaffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~", 36 | EnterAcs: "\x0e", 37 | ExitAcs: "\x0f", 38 | EnableAcs: "\x1b(B\x1b)0", 39 | StrikeThrough: "\x1b[9m", 40 | Mouse: "\x1b[M", 41 | SetCursor: "\x1b[%i%p1%d;%p2%dH", 42 | CursorBack1: "\b", 43 | CursorUp1: "\x1bM", 44 | KeyUp: "\x1bOA", 45 | KeyDown: "\x1bOB", 46 | KeyRight: "\x1bOC", 47 | KeyLeft: "\x1bOD", 48 | KeyInsert: "\x1b[2~", 49 | KeyDelete: "\x1b[3~", 50 | KeyBackspace: "\x7f", 51 | KeyHome: "\x1b[1~", 52 | KeyEnd: "\x1b[4~", 53 | KeyPgUp: "\x1b[5~", 54 | KeyPgDn: "\x1b[6~", 55 | KeyF1: "\x1bOP", 56 | KeyF2: "\x1bOQ", 57 | KeyF3: "\x1bOR", 58 | KeyF4: "\x1bOS", 59 | KeyF5: "\x1b[15~", 60 | KeyF6: "\x1b[17~", 61 | KeyF7: "\x1b[18~", 62 | KeyF8: "\x1b[19~", 63 | KeyF9: "\x1b[20~", 64 | KeyF10: "\x1b[21~", 65 | KeyF11: "\x1b[23~", 66 | KeyF12: "\x1b[24~", 67 | KeyBacktab: "\x1b[Z", 68 | Modifiers: 1, 69 | AutoMargin: true, 70 | DoubleUnderline: "\x1b[4:2m", 71 | CurlyUnderline: "\x1b[4:3m", 72 | DottedUnderline: "\x1b[4:4m", 73 | DashedUnderline: "\x1b[4:5m", 74 | }) 75 | 76 | // tmux with 256 colors 77 | terminfo.AddTerminfo(&terminfo.Terminfo{ 78 | Name: "tmux-256color", 79 | Columns: 80, 80 | Lines: 24, 81 | Colors: 256, 82 | Bell: "\a", 83 | Clear: "\x1b[H\x1b[J", 84 | EnterCA: "\x1b[?1049h", 85 | ExitCA: "\x1b[?1049l", 86 | ShowCursor: "\x1b[34h\x1b[?25h", 87 | HideCursor: "\x1b[?25l", 88 | AttrOff: "\x1b[m\x0f", 89 | Underline: "\x1b[4m", 90 | Bold: "\x1b[1m", 91 | Dim: "\x1b[2m", 92 | Italic: "\x1b[3m", 93 | Blink: "\x1b[5m", 94 | Reverse: "\x1b[7m", 95 | EnterKeypad: "\x1b[?1h\x1b=", 96 | ExitKeypad: "\x1b[?1l\x1b>", 97 | SetFg: "\x1b[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;m", 98 | SetBg: "\x1b[%?%p1%{8}%<%t4%p1%d%e%p1%{16}%<%t10%p1%{8}%-%d%e48;5;%p1%d%;m", 99 | SetFgBg: "\x1b[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;;%?%p2%{8}%<%t4%p2%d%e%p2%{16}%<%t10%p2%{8}%-%d%e48;5;%p2%d%;m", 100 | ResetFgBg: "\x1b[39;49m", 101 | PadChar: "\x00", 102 | AltChars: "++,,--..00``aaffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~", 103 | EnterAcs: "\x0e", 104 | ExitAcs: "\x0f", 105 | EnableAcs: "\x1b(B\x1b)0", 106 | StrikeThrough: "\x1b[9m", 107 | Mouse: "\x1b[M", 108 | SetCursor: "\x1b[%i%p1%d;%p2%dH", 109 | CursorBack1: "\b", 110 | CursorUp1: "\x1bM", 111 | KeyUp: "\x1bOA", 112 | KeyDown: "\x1bOB", 113 | KeyRight: "\x1bOC", 114 | KeyLeft: "\x1bOD", 115 | KeyInsert: "\x1b[2~", 116 | KeyDelete: "\x1b[3~", 117 | KeyBackspace: "\x7f", 118 | KeyHome: "\x1b[1~", 119 | KeyEnd: "\x1b[4~", 120 | KeyPgUp: "\x1b[5~", 121 | KeyPgDn: "\x1b[6~", 122 | KeyF1: "\x1bOP", 123 | KeyF2: "\x1bOQ", 124 | KeyF3: "\x1bOR", 125 | KeyF4: "\x1bOS", 126 | KeyF5: "\x1b[15~", 127 | KeyF6: "\x1b[17~", 128 | KeyF7: "\x1b[18~", 129 | KeyF8: "\x1b[19~", 130 | KeyF9: "\x1b[20~", 131 | KeyF10: "\x1b[21~", 132 | KeyF11: "\x1b[23~", 133 | KeyF12: "\x1b[24~", 134 | KeyBacktab: "\x1b[Z", 135 | Modifiers: 1, 136 | AutoMargin: true, 137 | DoubleUnderline: "\x1b[4:2m", 138 | CurlyUnderline: "\x1b[4:3m", 139 | DottedUnderline: "\x1b[4:4m", 140 | DashedUnderline: "\x1b[4:5m", 141 | }) 142 | } 143 | -------------------------------------------------------------------------------- /terminfo/v/vt100/term.go: -------------------------------------------------------------------------------- 1 | // Generated automatically. DO NOT HAND-EDIT. 2 | 3 | package vt100 4 | 5 | import "github.com/gdamore/tcell/v2/terminfo" 6 | 7 | func init() { 8 | 9 | // DEC VT100 (w/advanced video) 10 | terminfo.AddTerminfo(&terminfo.Terminfo{ 11 | Name: "vt100", 12 | Aliases: []string{"vt100-am"}, 13 | Columns: 80, 14 | Lines: 24, 15 | Bell: "\a", 16 | Clear: "\x1b[H\x1b[J$<50>", 17 | AttrOff: "\x1b[m\x0f$<2>", 18 | Underline: "\x1b[4m$<2>", 19 | Bold: "\x1b[1m$<2>", 20 | Blink: "\x1b[5m$<2>", 21 | Reverse: "\x1b[7m$<2>", 22 | EnterKeypad: "\x1b[?1h\x1b=", 23 | ExitKeypad: "\x1b[?1l\x1b>", 24 | PadChar: "\x00", 25 | AltChars: "``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~", 26 | EnterAcs: "\x0e", 27 | ExitAcs: "\x0f", 28 | EnableAcs: "\x1b(B\x1b)0", 29 | EnableAutoMargin: "\x1b[?7h", 30 | DisableAutoMargin: "\x1b[?7l", 31 | SetCursor: "\x1b[%i%p1%d;%p2%dH$<5>", 32 | CursorBack1: "\b", 33 | CursorUp1: "\x1b[A$<2>", 34 | KeyUp: "\x1bOA", 35 | KeyDown: "\x1bOB", 36 | KeyRight: "\x1bOC", 37 | KeyLeft: "\x1bOD", 38 | KeyBackspace: "\b", 39 | KeyF1: "\x1bOP", 40 | KeyF2: "\x1bOQ", 41 | KeyF3: "\x1bOR", 42 | KeyF4: "\x1bOS", 43 | KeyF5: "\x1bOt", 44 | KeyF6: "\x1bOu", 45 | KeyF7: "\x1bOv", 46 | KeyF8: "\x1bOl", 47 | KeyF9: "\x1bOw", 48 | KeyF10: "\x1bOx", 49 | AutoMargin: true, 50 | }) 51 | } 52 | -------------------------------------------------------------------------------- /terminfo/v/vt102/term.go: -------------------------------------------------------------------------------- 1 | // Generated automatically. DO NOT HAND-EDIT. 2 | 3 | package vt102 4 | 5 | import "github.com/gdamore/tcell/v2/terminfo" 6 | 7 | func init() { 8 | 9 | // DEC VT102 10 | terminfo.AddTerminfo(&terminfo.Terminfo{ 11 | Name: "vt102", 12 | Columns: 80, 13 | Lines: 24, 14 | Bell: "\a", 15 | Clear: "\x1b[H\x1b[J$<50>", 16 | AttrOff: "\x1b[m\x0f$<2>", 17 | Underline: "\x1b[4m$<2>", 18 | Bold: "\x1b[1m$<2>", 19 | Blink: "\x1b[5m$<2>", 20 | Reverse: "\x1b[7m$<2>", 21 | EnterKeypad: "\x1b[?1h\x1b=", 22 | ExitKeypad: "\x1b[?1l\x1b>", 23 | PadChar: "\x00", 24 | AltChars: "``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~", 25 | EnterAcs: "\x0e", 26 | ExitAcs: "\x0f", 27 | EnableAcs: "\x1b(B\x1b)0", 28 | EnableAutoMargin: "\x1b[?7h", 29 | DisableAutoMargin: "\x1b[?7l", 30 | SetCursor: "\x1b[%i%p1%d;%p2%dH$<5>", 31 | CursorBack1: "\b", 32 | CursorUp1: "\x1b[A$<2>", 33 | KeyUp: "\x1bOA", 34 | KeyDown: "\x1bOB", 35 | KeyRight: "\x1bOC", 36 | KeyLeft: "\x1bOD", 37 | KeyBackspace: "\b", 38 | KeyF1: "\x1bOP", 39 | KeyF2: "\x1bOQ", 40 | KeyF3: "\x1bOR", 41 | KeyF4: "\x1bOS", 42 | KeyF5: "\x1bOt", 43 | KeyF6: "\x1bOu", 44 | KeyF7: "\x1bOv", 45 | KeyF8: "\x1bOl", 46 | KeyF9: "\x1bOw", 47 | KeyF10: "\x1bOx", 48 | AutoMargin: true, 49 | }) 50 | } 51 | -------------------------------------------------------------------------------- /terminfo/v/vt220/term.go: -------------------------------------------------------------------------------- 1 | // Generated automatically. DO NOT HAND-EDIT. 2 | 3 | package vt220 4 | 5 | import "github.com/gdamore/tcell/v2/terminfo" 6 | 7 | func init() { 8 | 9 | // DEC VT220 10 | terminfo.AddTerminfo(&terminfo.Terminfo{ 11 | Name: "vt220", 12 | Aliases: []string{"vt200"}, 13 | Columns: 80, 14 | Lines: 24, 15 | Bell: "\a", 16 | Clear: "\x1b[H\x1b[J", 17 | ShowCursor: "\x1b[?25h", 18 | HideCursor: "\x1b[?25l", 19 | AttrOff: "\x1b[m\x1b(B", 20 | Underline: "\x1b[4m", 21 | Bold: "\x1b[1m", 22 | Blink: "\x1b[5m", 23 | Reverse: "\x1b[7m", 24 | PadChar: "\x00", 25 | AltChars: "``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~", 26 | EnterAcs: "\x1b(0$<2>", 27 | ExitAcs: "\x1b(B$<4>", 28 | EnableAcs: "\x1b)0", 29 | EnableAutoMargin: "\x1b[?7h", 30 | DisableAutoMargin: "\x1b[?7l", 31 | SetCursor: "\x1b[%i%p1%d;%p2%dH", 32 | CursorBack1: "\b", 33 | CursorUp1: "\x1b[A", 34 | KeyUp: "\x1b[A", 35 | KeyDown: "\x1b[B", 36 | KeyRight: "\x1b[C", 37 | KeyLeft: "\x1b[D", 38 | KeyInsert: "\x1b[2~", 39 | KeyDelete: "\x1b[3~", 40 | KeyBackspace: "\b", 41 | KeyPgUp: "\x1b[5~", 42 | KeyPgDn: "\x1b[6~", 43 | KeyF1: "\x1bOP", 44 | KeyF2: "\x1bOQ", 45 | KeyF3: "\x1bOR", 46 | KeyF4: "\x1bOS", 47 | KeyF6: "\x1b[17~", 48 | KeyF7: "\x1b[18~", 49 | KeyF8: "\x1b[19~", 50 | KeyF9: "\x1b[20~", 51 | KeyF10: "\x1b[21~", 52 | KeyF11: "\x1b[23~", 53 | KeyF12: "\x1b[24~", 54 | KeyF13: "\x1b[25~", 55 | KeyF14: "\x1b[26~", 56 | KeyF17: "\x1b[31~", 57 | KeyF18: "\x1b[32~", 58 | KeyF19: "\x1b[33~", 59 | KeyF20: "\x1b[34~", 60 | KeyHelp: "\x1b[28~", 61 | AutoMargin: true, 62 | }) 63 | } 64 | -------------------------------------------------------------------------------- /terminfo/v/vt320/term.go: -------------------------------------------------------------------------------- 1 | // Generated automatically. DO NOT HAND-EDIT. 2 | 3 | package vt320 4 | 5 | import "github.com/gdamore/tcell/v2/terminfo" 6 | 7 | func init() { 8 | 9 | // DEC VT320 7 bit terminal 10 | terminfo.AddTerminfo(&terminfo.Terminfo{ 11 | Name: "vt320", 12 | Aliases: []string{"vt300"}, 13 | Columns: 80, 14 | Lines: 24, 15 | Bell: "\a", 16 | Clear: "\x1b[H\x1b[2J", 17 | ShowCursor: "\x1b[?25h", 18 | HideCursor: "\x1b[?25l", 19 | AttrOff: "\x1b[m\x1b(B", 20 | Underline: "\x1b[4m", 21 | Bold: "\x1b[1m", 22 | Blink: "\x1b[5m", 23 | Reverse: "\x1b[7m", 24 | EnterKeypad: "\x1b[?1h\x1b=", 25 | ExitKeypad: "\x1b[?1l\x1b>", 26 | PadChar: "\x00", 27 | AltChars: "``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~", 28 | EnterAcs: "\x1b(0", 29 | ExitAcs: "\x1b(B", 30 | EnableAutoMargin: "\x1b[?7h", 31 | DisableAutoMargin: "\x1b[?7l", 32 | SetCursor: "\x1b[%i%p1%d;%p2%dH", 33 | CursorBack1: "\b", 34 | CursorUp1: "\x1b[A", 35 | KeyUp: "\x1bOA", 36 | KeyDown: "\x1bOB", 37 | KeyRight: "\x1bOC", 38 | KeyLeft: "\x1bOD", 39 | KeyInsert: "\x1b[2~", 40 | KeyDelete: "\x1b[3~", 41 | KeyBackspace: "\x7f", 42 | KeyHome: "\x1b[1~", 43 | KeyPgUp: "\x1b[5~", 44 | KeyPgDn: "\x1b[6~", 45 | KeyF1: "\x1bOP", 46 | KeyF2: "\x1bOQ", 47 | KeyF3: "\x1bOR", 48 | KeyF4: "\x1bOS", 49 | KeyF6: "\x1b[17~", 50 | KeyF7: "\x1b[18~", 51 | KeyF8: "\x1b[19~", 52 | KeyF9: "\x1b[20~", 53 | KeyF10: "\x1b[21~", 54 | KeyF11: "\x1b[23~", 55 | KeyF12: "\x1b[24~", 56 | KeyF13: "\x1b[25~", 57 | KeyF14: "\x1b[26~", 58 | KeyF15: "\x1b[28~", 59 | KeyF16: "\x1b[29~", 60 | KeyF17: "\x1b[31~", 61 | KeyF18: "\x1b[32~", 62 | KeyF19: "\x1b[33~", 63 | KeyF20: "\x1b[34~", 64 | AutoMargin: true, 65 | }) 66 | } 67 | -------------------------------------------------------------------------------- /terminfo/v/vt400/term.go: -------------------------------------------------------------------------------- 1 | // Generated automatically. DO NOT HAND-EDIT. 2 | 3 | package vt400 4 | 5 | import "github.com/gdamore/tcell/v2/terminfo" 6 | 7 | func init() { 8 | 9 | // DEC VT400 24x80 column autowrap 10 | terminfo.AddTerminfo(&terminfo.Terminfo{ 11 | Name: "vt400", 12 | Aliases: []string{"vt400-24", "dec-vt400"}, 13 | Columns: 80, 14 | Lines: 24, 15 | Clear: "\x1b[H\x1b[J$<10/>", 16 | ShowCursor: "\x1b[?25h", 17 | HideCursor: "\x1b[?25l", 18 | AttrOff: "\x1b[m\x1b(B", 19 | Underline: "\x1b[4m", 20 | Bold: "\x1b[1m", 21 | Blink: "\x1b[5m", 22 | Reverse: "\x1b[7m", 23 | EnterKeypad: "\x1b[?1h\x1b=", 24 | ExitKeypad: "\x1b[?1l\x1b>", 25 | PadChar: "\x00", 26 | AltChars: "``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~", 27 | EnterAcs: "\x1b(0", 28 | ExitAcs: "\x1b(B", 29 | EnableAutoMargin: "\x1b[?7h", 30 | DisableAutoMargin: "\x1b[?7l", 31 | SetCursor: "\x1b[%i%p1%d;%p2%dH", 32 | CursorBack1: "\b", 33 | CursorUp1: "\x1b[A", 34 | KeyUp: "\x1bOA", 35 | KeyDown: "\x1bOB", 36 | KeyRight: "\x1bOC", 37 | KeyLeft: "\x1bOD", 38 | KeyBackspace: "\b", 39 | KeyF1: "\x1bOP", 40 | KeyF2: "\x1bOQ", 41 | KeyF3: "\x1bOR", 42 | KeyF4: "\x1bOS", 43 | KeyF6: "\x1b[17~", 44 | KeyF7: "\x1b[18~", 45 | KeyF8: "\x1b[19~", 46 | KeyF9: "\x1b[20~", 47 | AutoMargin: true, 48 | InsertChar: "\x1b[@", 49 | }) 50 | } 51 | -------------------------------------------------------------------------------- /terminfo/v/vt420/term.go: -------------------------------------------------------------------------------- 1 | // Generated automatically. DO NOT HAND-EDIT. 2 | 3 | package vt420 4 | 5 | import "github.com/gdamore/tcell/v2/terminfo" 6 | 7 | func init() { 8 | 9 | // DEC VT420 10 | terminfo.AddTerminfo(&terminfo.Terminfo{ 11 | Name: "vt420", 12 | Columns: 80, 13 | Lines: 24, 14 | Bell: "\a", 15 | Clear: "\x1b[H\x1b[2J$<50>", 16 | ShowCursor: "\x1b[?25h", 17 | HideCursor: "\x1b[?25l", 18 | AttrOff: "\x1b[m\x1b(B$<2>", 19 | Underline: "\x1b[4m", 20 | Bold: "\x1b[1m$<2>", 21 | Blink: "\x1b[5m$<2>", 22 | Reverse: "\x1b[7m$<2>", 23 | EnterKeypad: "\x1b=", 24 | ExitKeypad: "\x1b>", 25 | PadChar: "\x00", 26 | AltChars: "``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~", 27 | EnterAcs: "\x1b(0$<2>", 28 | ExitAcs: "\x1b(B$<4>", 29 | EnableAcs: "\x1b)0", 30 | EnableAutoMargin: "\x1b[?7h", 31 | DisableAutoMargin: "\x1b[?7l", 32 | SetCursor: "\x1b[%i%p1%d;%p2%dH$<10>", 33 | CursorBack1: "\b", 34 | CursorUp1: "\x1b[A", 35 | KeyUp: "\x1b[A", 36 | KeyDown: "\x1b[B", 37 | KeyRight: "\x1b[C", 38 | KeyLeft: "\x1b[D", 39 | KeyInsert: "\x1b[2~", 40 | KeyDelete: "\x1b[3~", 41 | KeyBackspace: "\b", 42 | KeyPgUp: "\x1b[5~", 43 | KeyPgDn: "\x1b[6~", 44 | KeyF1: "\x1bOP", 45 | KeyF2: "\x1bOQ", 46 | KeyF3: "\x1bOR", 47 | KeyF4: "\x1bOS", 48 | KeyF5: "\x1b[17~", 49 | KeyF6: "\x1b[18~", 50 | KeyF7: "\x1b[19~", 51 | KeyF8: "\x1b[20~", 52 | KeyF9: "\x1b[21~", 53 | KeyF10: "\x1b[29~", 54 | AutoMargin: true, 55 | }) 56 | } 57 | -------------------------------------------------------------------------------- /terminfo/v/vt52/term.go: -------------------------------------------------------------------------------- 1 | // Generated automatically. DO NOT HAND-EDIT. 2 | 3 | package vt52 4 | 5 | import "github.com/gdamore/tcell/v2/terminfo" 6 | 7 | func init() { 8 | 9 | // DEC VT52 10 | terminfo.AddTerminfo(&terminfo.Terminfo{ 11 | Name: "vt52", 12 | Columns: 80, 13 | Lines: 24, 14 | Bell: "\a", 15 | Clear: "\x1bH\x1bJ", 16 | EnterKeypad: "\x1b=", 17 | ExitKeypad: "\x1b>", 18 | PadChar: "\x00", 19 | AltChars: "+h.k0affggolpnqprrss", 20 | EnterAcs: "\x1bF", 21 | ExitAcs: "\x1bG", 22 | SetCursor: "\x1bY%p1%' '%+%c%p2%' '%+%c", 23 | CursorBack1: "\x1bD", 24 | CursorUp1: "\x1bA", 25 | KeyUp: "\x1bA", 26 | KeyDown: "\x1bB", 27 | KeyRight: "\x1bC", 28 | KeyLeft: "\x1bD", 29 | KeyBackspace: "\b", 30 | KeyF1: "\x1bP", 31 | KeyF2: "\x1bQ", 32 | KeyF3: "\x1bR", 33 | KeyF5: "\x1b?t", 34 | KeyF6: "\x1b?u", 35 | KeyF7: "\x1b?v", 36 | KeyF8: "\x1b?w", 37 | KeyF9: "\x1b?x", 38 | }) 39 | } 40 | -------------------------------------------------------------------------------- /terminfo/w/wy50/term.go: -------------------------------------------------------------------------------- 1 | // Generated automatically. DO NOT HAND-EDIT. 2 | 3 | package wy50 4 | 5 | import "github.com/gdamore/tcell/v2/terminfo" 6 | 7 | func init() { 8 | 9 | // Wyse 50 10 | terminfo.AddTerminfo(&terminfo.Terminfo{ 11 | Name: "wy50", 12 | Aliases: []string{"wyse50"}, 13 | Columns: 80, 14 | Lines: 24, 15 | Bell: "\a", 16 | Clear: "\x1b+$<20>", 17 | ShowCursor: "\x1b`1", 18 | HideCursor: "\x1b`0", 19 | AttrOff: "\x1b(\x1bH\x03", 20 | Dim: "\x1b`7\x1b)", 21 | Reverse: "\x1b`6\x1b)", 22 | PadChar: "\x00", 23 | AltChars: "a;j5k3l2m1n8q:t4u9v=w0x6", 24 | EnterAcs: "\x1bH\x02", 25 | ExitAcs: "\x1bH\x03", 26 | SetCursor: "\x1b=%p1%' '%+%c%p2%' '%+%c", 27 | CursorBack1: "\b", 28 | CursorUp1: "\v", 29 | KeyUp: "\v", 30 | KeyDown: "\n", 31 | KeyRight: "\f", 32 | KeyLeft: "\b", 33 | KeyInsert: "\x1bQ", 34 | KeyDelete: "\x1bW", 35 | KeyBackspace: "\b", 36 | KeyHome: "\x1e", 37 | KeyPgUp: "\x1bJ", 38 | KeyPgDn: "\x1bK", 39 | KeyF1: "\x01@\r", 40 | KeyF2: "\x01A\r", 41 | KeyF3: "\x01B\r", 42 | KeyF4: "\x01C\r", 43 | KeyF5: "\x01D\r", 44 | KeyF6: "\x01E\r", 45 | KeyF7: "\x01F\r", 46 | KeyF8: "\x01G\r", 47 | KeyF9: "\x01H\r", 48 | KeyF10: "\x01I\r", 49 | KeyF11: "\x01J\r", 50 | KeyF12: "\x01K\r", 51 | KeyF13: "\x01L\r", 52 | KeyF14: "\x01M\r", 53 | KeyF15: "\x01N\r", 54 | KeyF16: "\x01O\r", 55 | KeyPrint: "\x1bP", 56 | KeyBacktab: "\x1bI", 57 | KeyShfHome: "\x1b{", 58 | AutoMargin: true, 59 | }) 60 | } 61 | -------------------------------------------------------------------------------- /terminfo/w/wy60/term.go: -------------------------------------------------------------------------------- 1 | // Generated automatically. DO NOT HAND-EDIT. 2 | 3 | package wy60 4 | 5 | import "github.com/gdamore/tcell/v2/terminfo" 6 | 7 | func init() { 8 | 9 | // Wyse 60 10 | terminfo.AddTerminfo(&terminfo.Terminfo{ 11 | Name: "wy60", 12 | Aliases: []string{"wyse60"}, 13 | Columns: 80, 14 | Lines: 24, 15 | Bell: "\a", 16 | Clear: "\x1b+$<100>", 17 | EnterCA: "\x1bw0", 18 | ExitCA: "\x1bw1", 19 | ShowCursor: "\x1b`1", 20 | HideCursor: "\x1b`0", 21 | AttrOff: "\x1b(\x1bH\x03\x1bG0\x1bcD", 22 | Underline: "\x1bG8", 23 | Dim: "\x1bGp", 24 | Blink: "\x1bG2", 25 | Reverse: "\x1bG4", 26 | PadChar: "\x00", 27 | AltChars: "+/,.0[a2fxgqh1ihjYk?lZm@nEqDtCu4vAwBx3yszr{c~~", 28 | EnterAcs: "\x1bcE", 29 | ExitAcs: "\x1bcD", 30 | EnableAutoMargin: "\x1bd/", 31 | DisableAutoMargin: "\x1bd.", 32 | SetCursor: "\x1b=%p1%' '%+%c%p2%' '%+%c", 33 | CursorBack1: "\b", 34 | CursorUp1: "\v", 35 | KeyUp: "\v", 36 | KeyDown: "\n", 37 | KeyRight: "\f", 38 | KeyLeft: "\b", 39 | KeyInsert: "\x1bQ", 40 | KeyDelete: "\x1bW", 41 | KeyBackspace: "\b", 42 | KeyHome: "\x1e", 43 | KeyPgUp: "\x1bJ", 44 | KeyPgDn: "\x1bK", 45 | KeyF1: "\x01@\r", 46 | KeyF2: "\x01A\r", 47 | KeyF3: "\x01B\r", 48 | KeyF4: "\x01C\r", 49 | KeyF5: "\x01D\r", 50 | KeyF6: "\x01E\r", 51 | KeyF7: "\x01F\r", 52 | KeyF8: "\x01G\r", 53 | KeyF9: "\x01H\r", 54 | KeyF10: "\x01I\r", 55 | KeyF11: "\x01J\r", 56 | KeyF12: "\x01K\r", 57 | KeyF13: "\x01L\r", 58 | KeyF14: "\x01M\r", 59 | KeyF15: "\x01N\r", 60 | KeyF16: "\x01O\r", 61 | KeyPrint: "\x1bP", 62 | KeyBacktab: "\x1bI", 63 | KeyShfHome: "\x1b{", 64 | AutoMargin: true, 65 | }) 66 | } 67 | -------------------------------------------------------------------------------- /terminfo/w/wy99_ansi/term.go: -------------------------------------------------------------------------------- 1 | // Generated automatically. DO NOT HAND-EDIT. 2 | 3 | package wy99_ansi 4 | 5 | import "github.com/gdamore/tcell/v2/terminfo" 6 | 7 | func init() { 8 | 9 | // Wyse WY-99GT in ANSI mode (int'l PC keyboard) 10 | terminfo.AddTerminfo(&terminfo.Terminfo{ 11 | Name: "wy99-ansi", 12 | Columns: 80, 13 | Lines: 25, 14 | Bell: "\a", 15 | Clear: "\x1b[H\x1b[J$<200>", 16 | ShowCursor: "\x1b[34h\x1b[?25h", 17 | HideCursor: "\x1b[?25l", 18 | AttrOff: "\x1b[m\x0f\x1b[\"q", 19 | Underline: "\x1b[4m", 20 | Bold: "\x1b[1m", 21 | Dim: "\x1b[2m", 22 | Blink: "\x1b[5m", 23 | Reverse: "\x1b[7m", 24 | EnterKeypad: "\x1b[?1h", 25 | ExitKeypad: "\x1b[?1l", 26 | PadChar: "\x00", 27 | AltChars: "``aaffggjjkkllmmnnooqqssttuuvvwwxx{{||}}~~", 28 | EnterAcs: "\x0e", 29 | ExitAcs: "\x0f", 30 | EnableAcs: "\x1b)0", 31 | EnableAutoMargin: "\x1b[?7h", 32 | DisableAutoMargin: "\x1b[?7l", 33 | SetCursor: "\x1b[%i%p1%d;%p2%dH", 34 | CursorBack1: "\b$<1>", 35 | CursorUp1: "\x1bM", 36 | KeyUp: "\x1bOA", 37 | KeyDown: "\x1bOB", 38 | KeyRight: "\x1bOC", 39 | KeyLeft: "\x1bOD", 40 | KeyBackspace: "\b", 41 | KeyF1: "\x1bOP", 42 | KeyF2: "\x1bOQ", 43 | KeyF3: "\x1bOR", 44 | KeyF4: "\x1bOS", 45 | KeyF5: "\x1b[M", 46 | KeyF6: "\x1b[17~", 47 | KeyF7: "\x1b[18~", 48 | KeyF8: "\x1b[19~", 49 | KeyF9: "\x1b[20~", 50 | KeyF10: "\x1b[21~", 51 | KeyF11: "\x1b[23~", 52 | KeyF12: "\x1b[24~", 53 | KeyF17: "\x1b[K", 54 | KeyF18: "\x1b[31~", 55 | KeyF19: "\x1b[32~", 56 | KeyF20: "\x1b[33~", 57 | KeyF21: "\x1b[34~", 58 | KeyF22: "\x1b[35~", 59 | KeyF23: "\x1b[1~", 60 | KeyF24: "\x1b[2~", 61 | KeyBacktab: "\x1b[z", 62 | AutoMargin: true, 63 | }) 64 | 65 | // Wyse WY-99GT in ANSI mode (US PC keyboard) 66 | terminfo.AddTerminfo(&terminfo.Terminfo{ 67 | Name: "wy99a-ansi", 68 | Columns: 80, 69 | Lines: 25, 70 | Bell: "\a", 71 | Clear: "\x1b[H\x1b[J$<200>", 72 | ShowCursor: "\x1b[34h\x1b[?25h", 73 | HideCursor: "\x1b[?25l", 74 | AttrOff: "\x1b[m\x0f\x1b[\"q", 75 | Underline: "\x1b[4m", 76 | Bold: "\x1b[1m", 77 | Dim: "\x1b[2m", 78 | Blink: "\x1b[5m", 79 | Reverse: "\x1b[7m", 80 | EnterKeypad: "\x1b[?1h", 81 | ExitKeypad: "\x1b[?1l", 82 | PadChar: "\x00", 83 | AltChars: "``aaffggjjkkllmmnnooqqssttuuvvwwxx{{||}}~~", 84 | EnterAcs: "\x0e", 85 | ExitAcs: "\x0f", 86 | EnableAcs: "\x1b)0", 87 | EnableAutoMargin: "\x1b[?7h", 88 | DisableAutoMargin: "\x1b[?7l", 89 | SetCursor: "\x1b[%i%p1%d;%p2%dH", 90 | CursorBack1: "\b$<1>", 91 | CursorUp1: "\x1bM", 92 | KeyUp: "\x1bOA", 93 | KeyDown: "\x1bOB", 94 | KeyRight: "\x1bOC", 95 | KeyLeft: "\x1bOD", 96 | KeyBackspace: "\b", 97 | KeyF1: "\x1bOP", 98 | KeyF2: "\x1bOQ", 99 | KeyF3: "\x1bOR", 100 | KeyF4: "\x1bOS", 101 | KeyF5: "\x1b[M", 102 | KeyF6: "\x1b[17~", 103 | KeyF7: "\x1b[18~", 104 | KeyF8: "\x1b[19~", 105 | KeyF9: "\x1b[20~", 106 | KeyF10: "\x1b[21~", 107 | KeyF11: "\x1b[23~", 108 | KeyF12: "\x1b[24~", 109 | KeyF17: "\x1b[K", 110 | KeyF18: "\x1b[31~", 111 | KeyF19: "\x1b[32~", 112 | KeyF20: "\x1b[33~", 113 | KeyF21: "\x1b[34~", 114 | KeyF22: "\x1b[35~", 115 | KeyF23: "\x1b[1~", 116 | KeyF24: "\x1b[2~", 117 | KeyBacktab: "\x1b[z", 118 | AutoMargin: true, 119 | }) 120 | } 121 | -------------------------------------------------------------------------------- /terminfo/x/xfce/term.go: -------------------------------------------------------------------------------- 1 | // Generated automatically. DO NOT HAND-EDIT. 2 | 3 | package xfce 4 | 5 | import "github.com/gdamore/tcell/v2/terminfo" 6 | 7 | func init() { 8 | 9 | // Xfce Terminal 10 | terminfo.AddTerminfo(&terminfo.Terminfo{ 11 | Name: "xfce", 12 | Columns: 80, 13 | Lines: 24, 14 | Colors: 8, 15 | Bell: "\a", 16 | Clear: "\x1b[H\x1b[2J", 17 | EnterCA: "\x1b7\x1b[?47h", 18 | ExitCA: "\x1b[2J\x1b[?47l\x1b8", 19 | ShowCursor: "\x1b[?25h", 20 | HideCursor: "\x1b[?25l", 21 | AttrOff: "\x1b[0m\x0f", 22 | Underline: "\x1b[4m", 23 | Bold: "\x1b[1m", 24 | Reverse: "\x1b[7m", 25 | EnterKeypad: "\x1b[?1h\x1b=", 26 | ExitKeypad: "\x1b[?1l\x1b>", 27 | SetFg: "\x1b[3%p1%dm", 28 | SetBg: "\x1b[4%p1%dm", 29 | SetFgBg: "\x1b[3%p1%d;4%p2%dm", 30 | ResetFgBg: "\x1b[39;49m", 31 | PadChar: "\x00", 32 | AltChars: "``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~", 33 | EnterAcs: "\x0e", 34 | ExitAcs: "\x0f", 35 | EnableAcs: "\x1b)0", 36 | EnableAutoMargin: "\x1b[?7h", 37 | DisableAutoMargin: "\x1b[?7l", 38 | Mouse: "\x1b[M", 39 | SetCursor: "\x1b[%i%p1%d;%p2%dH", 40 | CursorBack1: "\b", 41 | CursorUp1: "\x1b[A", 42 | KeyUp: "\x1bOA", 43 | KeyDown: "\x1bOB", 44 | KeyRight: "\x1bOC", 45 | KeyLeft: "\x1bOD", 46 | KeyInsert: "\x1b[2~", 47 | KeyDelete: "\x1b[3~", 48 | KeyBackspace: "\x7f", 49 | KeyHome: "\x1bOH", 50 | KeyEnd: "\x1bOF", 51 | KeyPgUp: "\x1b[5~", 52 | KeyPgDn: "\x1b[6~", 53 | KeyF1: "\x1bOP", 54 | KeyF2: "\x1bOQ", 55 | KeyF3: "\x1bOR", 56 | KeyF4: "\x1bOS", 57 | KeyF5: "\x1b[15~", 58 | KeyF6: "\x1b[17~", 59 | KeyF7: "\x1b[18~", 60 | KeyF8: "\x1b[19~", 61 | KeyF9: "\x1b[20~", 62 | KeyF10: "\x1b[21~", 63 | KeyF11: "\x1b[23~", 64 | KeyF12: "\x1b[24~", 65 | KeyBacktab: "\x1b[Z", 66 | Modifiers: 1, 67 | AutoMargin: true, 68 | XTermLike: true, 69 | }) 70 | } 71 | -------------------------------------------------------------------------------- /terminfo/x/xterm/direct.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The TCell Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use file except in compliance with the License. 5 | // You may obtain a copy of the license at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // This terminal definition is derived from the xterm-256color definition, but 16 | // makes use of the RGB property these terminals have to support direct color. 17 | // The terminfo entry for this uses a new format for the color handling introduced 18 | // by ncurses 6.1 (and used by nobody else), so this override ensures we get 19 | // good handling even in the face of this. 20 | 21 | package xterm 22 | 23 | import "github.com/gdamore/tcell/v2/terminfo" 24 | 25 | func init() { 26 | 27 | // derived from xterm-256color, but adds full RGB support 28 | terminfo.AddTerminfo(&terminfo.Terminfo{ 29 | Name: "xterm-direct", 30 | Aliases: []string{"xterm-truecolor"}, 31 | Columns: 80, 32 | Lines: 24, 33 | Colors: 256, 34 | Bell: "\a", 35 | Clear: "\x1b[H\x1b[2J", 36 | EnterCA: "\x1b[?1049h\x1b[22;0;0t", 37 | ExitCA: "\x1b[?1049l\x1b[23;0;0t", 38 | ShowCursor: "\x1b[?12l\x1b[?25h", 39 | HideCursor: "\x1b[?25l", 40 | AttrOff: "\x1b(B\x1b[m", 41 | Underline: "\x1b[4m", 42 | Bold: "\x1b[1m", 43 | Dim: "\x1b[2m", 44 | Italic: "\x1b[3m", 45 | Blink: "\x1b[5m", 46 | Reverse: "\x1b[7m", 47 | EnterKeypad: "\x1b[?1h\x1b=", 48 | ExitKeypad: "\x1b[?1l\x1b>", 49 | SetFg: "\x1b[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;m", 50 | SetBg: "\x1b[%?%p1%{8}%<%t4%p1%d%e%p1%{16}%<%t10%p1%{8}%-%d%e48;5;%p1%d%;m", 51 | SetFgBg: "\x1b[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;;%?%p2%{8}%<%t4%p2%d%e%p2%{16}%<%t10%p2%{8}%-%d%e48;5;%p2%d%;m", 52 | SetFgRGB: "\x1b[38;2;%p1%d;%p2%d;%p3%dm", 53 | SetBgRGB: "\x1b[48;2;%p1%d;%p2%d;%p3%dm", 54 | SetFgBgRGB: "\x1b[38;2;%p1%d;%p2%d;%p3%d;48;2;%p4%d;%p5%d;%p6%dm", 55 | ResetFgBg: "\x1b[39;49m", 56 | AltChars: "``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~", 57 | EnterAcs: "\x1b(0", 58 | ExitAcs: "\x1b(B", 59 | StrikeThrough: "\x1b[9m", 60 | Mouse: "\x1b[M", 61 | SetCursor: "\x1b[%i%p1%d;%p2%dH", 62 | CursorBack1: "\b", 63 | CursorUp1: "\x1b[A", 64 | KeyUp: "\x1bOA", 65 | KeyDown: "\x1bOB", 66 | KeyRight: "\x1bOC", 67 | KeyLeft: "\x1bOD", 68 | KeyInsert: "\x1b[2~", 69 | KeyDelete: "\x1b[3~", 70 | KeyBackspace: "\u007f", 71 | KeyHome: "\x1bOH", 72 | KeyEnd: "\x1bOF", 73 | KeyPgUp: "\x1b[5~", 74 | KeyPgDn: "\x1b[6~", 75 | KeyF1: "\x1bOP", 76 | KeyF2: "\x1bOQ", 77 | KeyF3: "\x1bOR", 78 | KeyF4: "\x1bOS", 79 | KeyF5: "\x1b[15~", 80 | KeyF6: "\x1b[17~", 81 | KeyF7: "\x1b[18~", 82 | KeyF8: "\x1b[19~", 83 | KeyF9: "\x1b[20~", 84 | KeyF10: "\x1b[21~", 85 | KeyF11: "\x1b[23~", 86 | KeyF12: "\x1b[24~", 87 | KeyBacktab: "\x1b[Z", 88 | Modifiers: 1, 89 | AutoMargin: true, 90 | TrueColor: true, 91 | }) 92 | } 93 | -------------------------------------------------------------------------------- /terminfo/x/xterm_ghostty/term.go: -------------------------------------------------------------------------------- 1 | // Generated automatically. DO NOT HAND-EDIT. 2 | 3 | package xterm_ghostty 4 | 5 | import "github.com/gdamore/tcell/v2/terminfo" 6 | 7 | func init() { 8 | 9 | // Ghostty 10 | terminfo.AddTerminfo(&terminfo.Terminfo{ 11 | Name: "xterm-ghostty", 12 | Aliases: []string{"ghostty"}, 13 | Columns: 80, 14 | Lines: 24, 15 | Colors: 256, 16 | Bell: "\a", 17 | Clear: "\x1b[H\x1b[2J", 18 | EnterCA: "\x1b[?1049h", 19 | ExitCA: "\x1b[?1049l", 20 | ShowCursor: "\x1b[?12l\x1b[?25h", 21 | HideCursor: "\x1b[?25l", 22 | AttrOff: "\x1b(B\x1b[m", 23 | Underline: "\x1b[4m", 24 | Bold: "\x1b[1m", 25 | Dim: "\x1b[2m", 26 | Italic: "\x1b[3m", 27 | Blink: "\x1b[5m", 28 | Reverse: "\x1b[7m", 29 | EnterKeypad: "\x1b[?1h\x1b=", 30 | ExitKeypad: "\x1b[?1l\x1b>", 31 | SetFg: "\x1b[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;m", 32 | SetBg: "\x1b[%?%p1%{8}%<%t4%p1%d%e%p1%{16}%<%t10%p1%{8}%-%d%e48;5;%p1%d%;m", 33 | SetFgBg: "\x1b[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;;%?%p2%{8}%<%t4%p2%d%e%p2%{16}%<%t10%p2%{8}%-%d%e48;5;%p2%d%;m", 34 | ResetFgBg: "\x1b[39;49m", 35 | AltChars: "++,,--..00``aaffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~", 36 | EnterAcs: "\x1b(0", 37 | ExitAcs: "\x1b(B", 38 | EnableAutoMargin: "\x1b[?7h", 39 | DisableAutoMargin: "\x1b[?7l", 40 | StrikeThrough: "\x1b[9m", 41 | Mouse: "\x1b[<", 42 | SetCursor: "\x1b[%i%p1%d;%p2%dH", 43 | CursorBack1: "\b", 44 | CursorUp1: "\x1b[A", 45 | KeyUp: "\x1bOA", 46 | KeyDown: "\x1bOB", 47 | KeyRight: "\x1bOC", 48 | KeyLeft: "\x1bOD", 49 | KeyInsert: "\x1b[2~", 50 | KeyDelete: "\x1b[3~", 51 | KeyBackspace: "\x7f", 52 | KeyHome: "\x1bOH", 53 | KeyEnd: "\x1bOF", 54 | KeyPgUp: "\x1b[5~", 55 | KeyPgDn: "\x1b[6~", 56 | KeyF1: "\x1bOP", 57 | KeyF2: "\x1bOQ", 58 | KeyF3: "\x1bOR", 59 | KeyF4: "\x1bOS", 60 | KeyF5: "\x1b[15~", 61 | KeyF6: "\x1b[17~", 62 | KeyF7: "\x1b[18~", 63 | KeyF8: "\x1b[19~", 64 | KeyF9: "\x1b[20~", 65 | KeyF10: "\x1b[21~", 66 | KeyF11: "\x1b[23~", 67 | KeyF12: "\x1b[24~", 68 | KeyBacktab: "\x1b[Z", 69 | Modifiers: 1, 70 | TrueColor: true, 71 | AutoMargin: true, 72 | InsertChar: "\x1b[@", 73 | DoubleUnderline: "\x1b[4:2m", 74 | CurlyUnderline: "\x1b[4:3m", 75 | DottedUnderline: "\x1b[4:4m", 76 | DashedUnderline: "\x1b[4:5m", 77 | XTermLike: true, 78 | }) 79 | } 80 | -------------------------------------------------------------------------------- /terminfo/x/xterm_kitty/term.go: -------------------------------------------------------------------------------- 1 | // Generated automatically. DO NOT HAND-EDIT. 2 | 3 | package xterm_kitty 4 | 5 | import "github.com/gdamore/tcell/v2/terminfo" 6 | 7 | func init() { 8 | 9 | // KovIdTTY 10 | terminfo.AddTerminfo(&terminfo.Terminfo{ 11 | Name: "xterm-kitty", 12 | Columns: 80, 13 | Lines: 24, 14 | Colors: 256, 15 | Bell: "\a", 16 | Clear: "\x1b[H\x1b[2J", 17 | EnterCA: "\x1b[?1049h", 18 | ExitCA: "\x1b[?1049l", 19 | ShowCursor: "\x1b[?12h\x1b[?25h", 20 | HideCursor: "\x1b[?25l", 21 | AttrOff: "\x1b(B\x1b[m", 22 | Underline: "\x1b[4m", 23 | Bold: "\x1b[1m", 24 | Dim: "\x1b[2m", 25 | Italic: "\x1b[3m", 26 | Reverse: "\x1b[7m", 27 | EnterKeypad: "\x1b[?1h", 28 | ExitKeypad: "\x1b[?1l", 29 | SetFg: "\x1b[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;m", 30 | SetBg: "\x1b[%?%p1%{8}%<%t4%p1%d%e%p1%{16}%<%t10%p1%{8}%-%d%e48;5;%p1%d%;m", 31 | SetFgBg: "\x1b[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;;%?%p2%{8}%<%t4%p2%d%e%p2%{16}%<%t10%p2%{8}%-%d%e48;5;%p2%d%;m", 32 | ResetFgBg: "\x1b[39;49m", 33 | AltChars: "++,,--..00``aaffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~", 34 | EnterAcs: "\x1b(0", 35 | ExitAcs: "\x1b(B", 36 | EnableAutoMargin: "\x1b[?7h", 37 | DisableAutoMargin: "\x1b[?7l", 38 | StrikeThrough: "\x1b[9m", 39 | Mouse: "\x1b[M", 40 | SetCursor: "\x1b[%i%p1%d;%p2%dH", 41 | CursorBack1: "\b", 42 | CursorUp1: "\x1b[A", 43 | KeyUp: "\x1bOA", 44 | KeyDown: "\x1bOB", 45 | KeyRight: "\x1bOC", 46 | KeyLeft: "\x1bOD", 47 | KeyInsert: "\x1b[2~", 48 | KeyDelete: "\x1b[3~", 49 | KeyBackspace: "\x7f", 50 | KeyHome: "\x1bOH", 51 | KeyEnd: "\x1bOF", 52 | KeyPgUp: "\x1b[5~", 53 | KeyPgDn: "\x1b[6~", 54 | KeyF1: "\x1bOP", 55 | KeyF2: "\x1bOQ", 56 | KeyF3: "\x1bOR", 57 | KeyF4: "\x1bOS", 58 | KeyF5: "\x1b[15~", 59 | KeyF6: "\x1b[17~", 60 | KeyF7: "\x1b[18~", 61 | KeyF8: "\x1b[19~", 62 | KeyF9: "\x1b[20~", 63 | KeyF10: "\x1b[21~", 64 | KeyF11: "\x1b[23~", 65 | KeyF12: "\x1b[24~", 66 | KeyBacktab: "\x1b[Z", 67 | Modifiers: 1, 68 | TrueColor: true, 69 | AutoMargin: true, 70 | DoubleUnderline: "\x1b[4:2m", 71 | CurlyUnderline: "\x1b[4:3m", 72 | DottedUnderline: "\x1b[4:4m", 73 | DashedUnderline: "\x1b[4:5m", 74 | }) 75 | } 76 | -------------------------------------------------------------------------------- /terms_default.go: -------------------------------------------------------------------------------- 1 | //go:build !tcell_minimal 2 | // +build !tcell_minimal 3 | 4 | // Copyright 2019 The TCell Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use file except in compliance with the License. 8 | // You may obtain a copy of the license at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | package tcell 19 | 20 | import ( 21 | // This imports the default terminal entries. To disable, use the 22 | // tcell_minimal build tag. 23 | _ "github.com/gdamore/tcell/v2/terminfo/extended" 24 | ) 25 | -------------------------------------------------------------------------------- /terms_dynamic.go: -------------------------------------------------------------------------------- 1 | //go:build !tcell_minimal && !nacl && !js && !zos && !plan9 && !windows && !android 2 | // +build !tcell_minimal,!nacl,!js,!zos,!plan9,!windows,!android 3 | 4 | // Copyright 2019 The TCell Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use file except in compliance with the License. 8 | // You may obtain a copy of the license at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | package tcell 19 | 20 | import ( 21 | // This imports a dynamic version of the terminal database, which 22 | // is built using infocmp. This relies on a working installation 23 | // of infocmp (typically supplied with ncurses). We only do this 24 | // for systems likely to have that -- i.e. UNIX based hosts. We 25 | // also don't support Android here, because you really don't want 26 | // to run external programs there. Generally the android terminals 27 | // will be automatically included anyway. 28 | "github.com/gdamore/tcell/v2/terminfo" 29 | "github.com/gdamore/tcell/v2/terminfo/dynamic" 30 | 31 | "fmt" 32 | ) 33 | 34 | func loadDynamicTerminfo(term string) (*terminfo.Terminfo, error) { 35 | if term == "" { 36 | return nil, fmt.Errorf("%w: term not set", ErrTermNotFound) 37 | } 38 | ti, _, e := dynamic.LoadTerminfo(term) 39 | if e != nil { 40 | return nil, e 41 | } 42 | return ti, nil 43 | } 44 | -------------------------------------------------------------------------------- /terms_static.go: -------------------------------------------------------------------------------- 1 | //go:build tcell_minimal || nacl || zos || plan9 || windows || android || js 2 | // +build tcell_minimal nacl zos plan9 windows android js 3 | 4 | // Copyright 2019 The TCell Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use file except in compliance with the License. 8 | // You may obtain a copy of the license at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | package tcell 19 | 20 | import ( 21 | "errors" 22 | 23 | "github.com/gdamore/tcell/v2/terminfo" 24 | ) 25 | 26 | func loadDynamicTerminfo(_ string) (*terminfo.Terminfo, error) { 27 | return nil, errors.New("terminal type unsupported") 28 | } 29 | -------------------------------------------------------------------------------- /tscreen_stub.go: -------------------------------------------------------------------------------- 1 | //go:build plan9 || windows 2 | // +build plan9 windows 3 | 4 | // Copyright 2022 The TCell Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use file except in compliance with the License. 8 | // You may obtain a copy of the license at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | package tcell 19 | 20 | // NB: We might someday wish to move Windows to this model. However, 21 | // that would probably mean sacrificing some of the richer key reporting 22 | // that we can obtain with the console API present on Windows. 23 | 24 | func (t *tScreen) initialize() error { 25 | if t.tty == nil { 26 | return ErrNoScreen 27 | } 28 | // If a tty was supplied (custom), it should work. 29 | // Custom screen implementations will need to provide a TTY 30 | // implementation that we can use. 31 | return nil 32 | } 33 | -------------------------------------------------------------------------------- /tscreen_unix.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 The TCell Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use file except in compliance with the License. 5 | // You may obtain a copy of the license at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris || zos 16 | // +build aix darwin dragonfly freebsd linux netbsd openbsd solaris zos 17 | 18 | package tcell 19 | 20 | import ( 21 | // import the stock terminals 22 | _ "github.com/gdamore/tcell/v2/terminfo/base" 23 | ) 24 | 25 | // initialize is used at application startup, and sets up the initial values 26 | // including file descriptors used for terminals and saving the initial state 27 | // so that it can be restored when the application terminates. 28 | func (t *tScreen) initialize() error { 29 | var err error 30 | if t.tty == nil { 31 | t.tty, err = NewDevTty() 32 | if err != nil { 33 | return err 34 | } 35 | } 36 | return nil 37 | } 38 | -------------------------------------------------------------------------------- /tty.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The TCell Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use file except in compliance with the License. 5 | // You may obtain a copy of the license at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package tcell 16 | 17 | import "io" 18 | 19 | // Tty is an abstraction of a tty (traditionally "teletype"). This allows applications to 20 | // provide for alternate backends, as there are situations where the traditional /dev/tty 21 | // does not work, or where more flexible handling is required. This interface is for use 22 | // with the terminfo-style based API. It extends the io.ReadWriter API. It is reasonable 23 | // that the implementation might choose to use different underlying files for the Reader 24 | // and Writer sides of this API, as part of it's internal implementation. 25 | type Tty interface { 26 | // Start is used to activate the Tty for use. Upon return the terminal should be 27 | // in raw mode, non-blocking, etc. The implementation should take care of saving 28 | // any state that is required so that it may be restored when Stop is called. 29 | Start() error 30 | 31 | // Stop is used to stop using this Tty instance. This may be a suspend, so that other 32 | // terminal based applications can run in the foreground. Implementations should 33 | // restore any state collected at Start(), and return to ordinary blocking mode, etc. 34 | // Drain is called first to drain the input. Once this is called, no more Read 35 | // or Write calls will be made until Start is called again. 36 | Stop() error 37 | 38 | // Drain is called before Stop, and ensures that the reader will wake up appropriately 39 | // if it was blocked. This workaround is required for /dev/tty on certain UNIX systems 40 | // to ensure that Read() does not block forever. This typically arranges for the tty driver 41 | // to send data immediately (e.g. VMIN and VTIME both set zero) and sets a deadline on input. 42 | // Implementations may reasonably make this a no-op. There will still be control sequences 43 | // emitted between the time this is called, and when Stop is called. 44 | Drain() error 45 | 46 | // NotifyResize is used register a callback when the tty thinks the dimensions have 47 | // changed. The standard UNIX implementation links this to a handler for SIGWINCH. 48 | // If the supplied callback is nil, then any handler should be unregistered. 49 | NotifyResize(cb func()) 50 | 51 | // WindowSize is called to determine the terminal dimensions. This might be determined 52 | // by an ioctl or other means. 53 | WindowSize() (WindowSize, error) 54 | 55 | io.ReadWriteCloser 56 | } 57 | -------------------------------------------------------------------------------- /views/README.md: -------------------------------------------------------------------------------- 1 | ## tcell views 2 | 3 | This package provides some enhanced functionality on top of base tcell. 4 | In particular, support for logical views, and a few different kinds of 5 | widgets like title bars, and scrollable areas, are provided. 6 | 7 | These make up a higher level interface than tcell itself. 8 | -------------------------------------------------------------------------------- /views/_demos/hbox.go: -------------------------------------------------------------------------------- 1 | //go:build ignore 2 | // +build ignore 3 | 4 | // Copyright 2015 The Tops'l Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use file except in compliance with the License. 8 | // You may obtain a copy of the license at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | package main 19 | 20 | import ( 21 | "fmt" 22 | "os" 23 | 24 | "github.com/gdamore/tcell/v2" 25 | "github.com/gdamore/tcell/v2/views" 26 | ) 27 | 28 | type boxL struct { 29 | views.BoxLayout 30 | } 31 | 32 | var app = &views.Application{} 33 | var box = &boxL{} 34 | 35 | func (m *boxL) HandleEvent(ev tcell.Event) bool { 36 | switch ev := ev.(type) { 37 | case *tcell.EventKey: 38 | if ev.Key() == tcell.KeyEscape { 39 | app.Quit() 40 | return true 41 | } 42 | } 43 | return m.BoxLayout.HandleEvent(ev) 44 | } 45 | 46 | func main() { 47 | 48 | title := &views.TextBar{} 49 | title.SetStyle(tcell.StyleDefault. 50 | Background(tcell.ColorYellow). 51 | Foreground(tcell.ColorBlack)) 52 | title.SetCenter("Horizontal Boxes", tcell.StyleDefault) 53 | title.SetLeft("ESC to exit", tcell.StyleDefault. 54 | Background(tcell.ColorBlue). 55 | Foreground(tcell.ColorWhite)) 56 | title.SetRight("==>X", tcell.StyleDefault) 57 | 58 | inner := views.NewBoxLayout(views.Horizontal) 59 | 60 | l := views.NewText() 61 | m := views.NewText() 62 | r := views.NewText() 63 | 64 | l.SetText("Left (0.0)") 65 | m.SetText("Middle (0.7)") 66 | r.SetText("Right (0.3)") 67 | l.SetStyle(tcell.StyleDefault.Foreground(tcell.ColorWhite). 68 | Background(tcell.ColorRed)) 69 | m.SetStyle(tcell.StyleDefault.Foreground(tcell.ColorWhite). 70 | Background(tcell.ColorLime)) 71 | r.SetStyle(tcell.StyleDefault.Foreground(tcell.ColorWhite). 72 | Background(tcell.ColorBlue)) 73 | l.SetAlignment(views.AlignBegin) 74 | m.SetAlignment(views.AlignMiddle) 75 | r.SetAlignment(views.AlignEnd) 76 | 77 | inner.AddWidget(l, 0) 78 | inner.AddWidget(m, 0.7) 79 | inner.AddWidget(r, 0.3) 80 | 81 | box.SetOrientation(views.Vertical) 82 | box.AddWidget(title, 0) 83 | box.AddWidget(inner, 1) 84 | app.SetRootWidget(box) 85 | if e := app.Run(); e != nil { 86 | fmt.Fprintln(os.Stderr, e.Error()) 87 | os.Exit(1) 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /views/_demos/vbox.go: -------------------------------------------------------------------------------- 1 | //go:build ignore 2 | // +build ignore 3 | 4 | // Copyright 2015 The Tops'l Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use file except in compliance with the License. 8 | // You may obtain a copy of the license at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | package main 19 | 20 | import ( 21 | "fmt" 22 | "os" 23 | 24 | "github.com/gdamore/tcell/v2" 25 | "github.com/gdamore/tcell/v2/views" 26 | ) 27 | 28 | type boxL struct { 29 | views.BoxLayout 30 | } 31 | 32 | var box = &boxL{} 33 | var app = &views.Application{} 34 | 35 | func (m *boxL) HandleEvent(ev tcell.Event) bool { 36 | switch ev := ev.(type) { 37 | case *tcell.EventKey: 38 | if ev.Key() == tcell.KeyEscape { 39 | app.Quit() 40 | return true 41 | } 42 | } 43 | return m.BoxLayout.HandleEvent(ev) 44 | } 45 | 46 | func main() { 47 | 48 | title := views.NewTextBar() 49 | title.SetStyle(tcell.StyleDefault. 50 | Foreground(tcell.ColorBlack). 51 | Background(tcell.ColorYellow)) 52 | title.SetCenter("Vertical Layout", tcell.StyleDefault) 53 | top := views.NewText() 54 | mid := views.NewText() 55 | bot := views.NewText() 56 | 57 | top.SetText("Top-Right (0.0)\nLine Two") 58 | mid.SetText("Center (0.7)") 59 | bot.SetText("Bottom-Left (0.3)") 60 | top.SetStyle(tcell.StyleDefault.Foreground(tcell.ColorWhite). 61 | Background(tcell.ColorRed)) 62 | mid.SetStyle(tcell.StyleDefault.Foreground(tcell.ColorWhite). 63 | Background(tcell.ColorLime)) 64 | bot.SetStyle(tcell.StyleDefault.Foreground(tcell.ColorWhite). 65 | Background(tcell.ColorBlue)) 66 | 67 | top.SetAlignment(views.VAlignTop | views.HAlignRight) 68 | mid.SetAlignment(views.VAlignCenter | views.HAlignCenter) 69 | bot.SetAlignment(views.VAlignBottom | views.HAlignLeft) 70 | 71 | box.SetOrientation(views.Vertical) 72 | box.AddWidget(title, 0) 73 | box.AddWidget(top, 0) 74 | box.AddWidget(mid, 0.7) 75 | box.AddWidget(bot, 0.3) 76 | 77 | app.SetRootWidget(box) 78 | if e := app.Run(); e != nil { 79 | fmt.Fprintln(os.Stderr, e.Error()) 80 | os.Exit(1) 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /views/constants.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Tops'l Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use file except in compliance with the License. 5 | // You may obtain a copy of the license at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package views 16 | 17 | // Alignment represents the alignment of an object, and consists of 18 | // either or both of horizontal and vertical alignment. 19 | type Alignment int 20 | 21 | const ( 22 | // HAlignLeft indicates alignment on the left edge. 23 | HAlignLeft Alignment = 1 << iota 24 | 25 | // HAlignCenter indicates horizontally centered. 26 | HAlignCenter 27 | 28 | // HAlignRight indicates alignment on the right edge. 29 | HAlignRight 30 | 31 | // VAlignTop indicates alignment on the top edge. 32 | VAlignTop 33 | 34 | // VAlignCenter indicates vertically centered. 35 | VAlignCenter 36 | 37 | // VAlignBottom indicates alignment on the bottom edge. 38 | VAlignBottom 39 | ) 40 | const ( 41 | // AlignBegin indicates alignment at the top left corner. 42 | AlignBegin = HAlignLeft | VAlignTop 43 | 44 | // AlignEnd indicates alignment at the bottom right corner. 45 | AlignEnd = HAlignRight | VAlignBottom 46 | 47 | // AlignMiddle indicates full centering. 48 | AlignMiddle = HAlignCenter | VAlignCenter 49 | ) 50 | 51 | // Orientation represents the direction of a widget or layout. 52 | type Orientation int 53 | 54 | const ( 55 | // Horizontal indicates left to right orientation. 56 | Horizontal Orientation = iota 57 | 58 | // Vertical indicates top to bottom orientation. 59 | Vertical 60 | ) 61 | -------------------------------------------------------------------------------- /views/panel.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Tops'l Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use file except in compliance with the License. 5 | // You may obtain a copy of the license at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package views 16 | 17 | // Panel is a modified Layout that includes a primary content pane, 18 | // prefixed with an optional title, and an optional menubar, and then 19 | // suffixed by an optional status. 20 | // 21 | // Only the content pane is resizable. The panel will be formatted 22 | // like this: 23 | // 24 | // +---------- 25 | // | title 26 | // | menu 27 | // | content.... 28 | // | 29 | // | status 30 | // +---------- 31 | // 32 | // Each of these components may be any valid widget; their names are 33 | // only meant to be indicative of conventional use, not prescriptive. 34 | type Panel struct { 35 | title Widget 36 | menu Widget 37 | content Widget 38 | status Widget 39 | inited bool 40 | BoxLayout 41 | } 42 | 43 | // Draw draws the Panel. 44 | func (p *Panel) Draw() { 45 | p.BoxLayout.SetOrientation(Vertical) 46 | p.BoxLayout.Draw() 47 | } 48 | 49 | // SetTitle sets the Widget to display in the title area. 50 | func (p *Panel) SetTitle(w Widget) { 51 | if p.title != nil { 52 | p.RemoveWidget(p.title) 53 | } 54 | p.InsertWidget(0, w, 0.0) 55 | p.title = w 56 | } 57 | 58 | // SetMenu sets the Widget to display in the menu area, which is 59 | // just below the title. 60 | func (p *Panel) SetMenu(w Widget) { 61 | index := 0 62 | if p.title != nil { 63 | index++ 64 | } 65 | if p.menu != nil { 66 | p.RemoveWidget(p.menu) 67 | } 68 | p.InsertWidget(index, w, 0.0) 69 | p.menu = w 70 | } 71 | 72 | // SetContent sets the Widget to display in the content area. 73 | func (p *Panel) SetContent(w Widget) { 74 | index := 0 75 | if p.title != nil { 76 | index++ 77 | } 78 | if p.menu != nil { 79 | index++ 80 | } 81 | if p.content != nil { 82 | p.RemoveWidget(p.content) 83 | } 84 | p.InsertWidget(index, w, 1.0) 85 | p.content = w 86 | } 87 | 88 | // SetStatus sets the Widget to display in the status area, which is at 89 | // the bottom of the panel. 90 | func (p *Panel) SetStatus(w Widget) { 91 | index := 0 92 | if p.title != nil { 93 | index++ 94 | } 95 | if p.menu != nil { 96 | index++ 97 | } 98 | if p.content != nil { 99 | index++ 100 | } 101 | if p.status != nil { 102 | p.RemoveWidget(p.status) 103 | } 104 | p.InsertWidget(index, w, 0.0) 105 | p.status = w 106 | } 107 | 108 | // NewPanel creates a new Panel. A zero valued panel can be created too. 109 | func NewPanel() *Panel { 110 | return &Panel{} 111 | } 112 | -------------------------------------------------------------------------------- /views/spacer.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Tcell Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use file except in compliance with the License. 5 | // You may obtain a copy of the license at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package views 16 | 17 | import ( 18 | "github.com/gdamore/tcell/v2" 19 | ) 20 | 21 | // Spacer is a Widget that occupies no visible real-estate. It is useful to 22 | // add this to layouts when expansion space is required. It expands as needed 23 | // with blank space. 24 | type Spacer struct { 25 | WidgetWatchers 26 | } 27 | 28 | // Draw is called to update the displayed content. 29 | func (*Spacer) Draw() {} 30 | 31 | // Size always returns 0, 0, since no size is ever *required* to display nothing. 32 | func (*Spacer) Size() (int, int) { 33 | return 0, 0 34 | } 35 | 36 | // SetView sets the View object used for the text bar. 37 | func (*Spacer) SetView(View) {} 38 | 39 | // HandleEvent implements a tcell.EventHandler, but does nothing. 40 | func (*Spacer) HandleEvent(tcell.Event) bool { 41 | return false 42 | } 43 | 44 | // Resize is called when our View changes sizes. 45 | func (s *Spacer) Resize() { 46 | s.PostEventWidgetResize(s) 47 | } 48 | 49 | // NewSpacer creates an empty Spacer. It's probably easier just to declare it 50 | // directly. 51 | func NewSpacer() *Spacer { 52 | return &Spacer{} 53 | } 54 | -------------------------------------------------------------------------------- /views/sstext.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Tcell Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use file except in compliance with the License. 5 | // You may obtain a copy of the license at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package views 16 | 17 | import ( 18 | "unicode" 19 | 20 | "github.com/gdamore/tcell/v2" 21 | ) 22 | 23 | // SimpleStyledText is a form of Text that offers highlighting of the text 24 | // using simple in-line markup. Its intention is to make it easier to mark 25 | // up hot // keys for menubars, etc. 26 | type SimpleStyledText struct { 27 | styles map[rune]tcell.Style 28 | markup []rune 29 | Text 30 | } 31 | 32 | // SetMarkup sets the text used for the string. It applies markup as follows 33 | // (modeled on tcsh style prompt markup): 34 | // 35 | // * %% - emit a single % in current style 36 | // * %N - normal style 37 | // * %A - alternate style 38 | // * %S - start standout (reverse) style 39 | // * %B - start bold style 40 | // * %U - start underline style 41 | // 42 | // Other styles can be set using %, if styles are registered. 43 | // Upper case characters and punctuation are reserved for use by the system. 44 | // Lower case are available for use by the user. (Users may define mappings 45 | // for upper case letters to override system defined styles.) 46 | // 47 | // Note that for simplicity, combining styles is not supported. By default 48 | // the alternate style is the same as standout (reverse) mode. 49 | // 50 | // Arguably we could have used Markdown syntax instead, but properly doing all 51 | // of Markdown is not trivial, and these escape sequences make it clearer that 52 | // we are not even attempting to do that. 53 | func (t *SimpleStyledText) SetMarkup(s string) { 54 | 55 | markup := []rune(s) 56 | styl := make([]tcell.Style, 0, len(markup)) 57 | text := make([]rune, 0, len(markup)) 58 | 59 | style := t.styles['N'] 60 | 61 | esc := false 62 | for _, r := range markup { 63 | if esc { 64 | esc = false 65 | switch r { 66 | case '%': 67 | text = append(text, '%') 68 | styl = append(styl, style) 69 | default: 70 | style = t.styles[r] 71 | } 72 | continue 73 | } 74 | switch r { 75 | case '%': 76 | esc = true 77 | continue 78 | default: 79 | text = append(text, r) 80 | styl = append(styl, style) 81 | } 82 | } 83 | 84 | t.Text.SetText(string(text)) 85 | for i, s := range styl { 86 | t.SetStyleAt(i, s) 87 | } 88 | t.markup = markup 89 | } 90 | 91 | // Registers a style for the given rune. This style will be used for 92 | // text marked with %. See SetMarkup() for more detail. Note that 93 | // this must be done before using any of the styles with SetMarkup(). 94 | // Only letters may be used when registering styles, and be advised that 95 | // the system may have predefined uses for upper case letters. 96 | func (t *SimpleStyledText) RegisterStyle(r rune, style tcell.Style) { 97 | if r == 'N' { 98 | t.Text.SetStyle(style) 99 | } 100 | if unicode.IsLetter(r) { 101 | t.styles[r] = style 102 | } 103 | } 104 | 105 | // LookupStyle returns the style registered for the given rune. 106 | // Returns tcell.StyleDefault if no style was previously registered 107 | // for the rune. 108 | func (t *SimpleStyledText) LookupStyle(r rune) tcell.Style { 109 | return t.styles[r] 110 | } 111 | 112 | // Markup returns the text that was set, including markup. 113 | func (t *SimpleStyledText) Markup() string { 114 | return string(t.markup) 115 | } 116 | 117 | // NewSimpleStyledText creates an empty Text. 118 | func NewSimpleStyledText() *SimpleStyledText { 119 | ss := &SimpleStyledText{} 120 | // Create map and establish default styles. 121 | ss.styles = make(map[rune]tcell.Style) 122 | ss.styles['N'] = tcell.StyleDefault 123 | ss.styles['S'] = tcell.StyleDefault.Reverse(true) 124 | ss.styles['U'] = tcell.StyleDefault.Underline(true) 125 | ss.styles['B'] = tcell.StyleDefault.Bold(true) 126 | return ss 127 | } 128 | -------------------------------------------------------------------------------- /views/sstextbar.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Tcell Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use file except in compliance with the License. 5 | // You may obtain a copy of the license at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package views 16 | 17 | import ( 18 | "sync" 19 | 20 | "github.com/gdamore/tcell/v2" 21 | ) 22 | 23 | // SimpleStyledTextBar is a Widget that provides a single line of text, but 24 | // with distinct left, center, and right areas. Each of the areas can be 25 | // styled differently, and can contain internal style markup. 26 | // They align to the left, center, and right respectively. 27 | // This is basically a convenience type on top SimpleStyledText and BoxLayout. 28 | type SimpleStyledTextBar struct { 29 | left *SimpleStyledText 30 | right *SimpleStyledText 31 | center *SimpleStyledText 32 | once sync.Once 33 | 34 | BoxLayout 35 | } 36 | 37 | // SetRight sets the right text for the textbar. 38 | // It is always right-aligned. 39 | func (s *SimpleStyledTextBar) SetRight(m string) { 40 | s.initialize() 41 | s.right.SetMarkup(m) 42 | } 43 | 44 | // SetLeft sets the left text for the textbar. 45 | // It is always left-aligned. 46 | func (s *SimpleStyledTextBar) SetLeft(m string) { 47 | s.initialize() 48 | s.left.SetMarkup(m) 49 | } 50 | 51 | // SetCenter sets the center text for the textbar. 52 | // It is always centered. 53 | func (s *SimpleStyledTextBar) SetCenter(m string) { 54 | s.initialize() 55 | s.center.SetMarkup(m) 56 | } 57 | 58 | func (s *SimpleStyledTextBar) RegisterRightStyle(r rune, style tcell.Style) { 59 | s.initialize() 60 | s.right.RegisterStyle(r, style) 61 | } 62 | 63 | func (s *SimpleStyledTextBar) RegisterLeftStyle(r rune, style tcell.Style) { 64 | s.initialize() 65 | s.left.RegisterStyle(r, style) 66 | } 67 | 68 | func (s *SimpleStyledTextBar) RegisterCenterStyle(r rune, style tcell.Style) { 69 | s.initialize() 70 | s.center.RegisterStyle(r, style) 71 | } 72 | 73 | func (s *SimpleStyledTextBar) Size() (int, int) { 74 | s.initialize() 75 | w, h := s.BoxLayout.Size() 76 | if h < 1 { 77 | h = 1 78 | } 79 | if w < 1 { 80 | w = 1 81 | } 82 | return w, h 83 | } 84 | 85 | func (s *SimpleStyledTextBar) initialize() { 86 | s.once.Do(func() { 87 | s.center = NewSimpleStyledText() 88 | s.left = NewSimpleStyledText() 89 | s.right = NewSimpleStyledText() 90 | s.center.SetAlignment(VAlignTop | HAlignCenter) 91 | s.left.SetAlignment(VAlignTop | HAlignLeft) 92 | s.right.SetAlignment(VAlignTop | HAlignRight) 93 | s.BoxLayout.SetOrientation(Horizontal) 94 | s.BoxLayout.AddWidget(s.left, 0.0) 95 | s.BoxLayout.AddWidget(NewSpacer(), 1.0) 96 | s.BoxLayout.AddWidget(s.center, 0.0) 97 | s.BoxLayout.AddWidget(NewSpacer(), 1.0) 98 | s.BoxLayout.AddWidget(s.right, 0.0) 99 | }) 100 | } 101 | 102 | // Init prepares the widget for use, ensuring resources needed are 103 | // allocated, etc. 104 | func (s *SimpleStyledTextBar) Init() { 105 | s.initialize() 106 | } 107 | 108 | // NewSimpleStyledTextBar creates an empty, initialized TextBar. 109 | func NewSimpleStyledTextBar() *SimpleStyledTextBar { 110 | s := &SimpleStyledTextBar{} 111 | s.initialize() 112 | return s 113 | } 114 | -------------------------------------------------------------------------------- /views/text_test.go: -------------------------------------------------------------------------------- 1 | package views 2 | 3 | import "testing" 4 | 5 | func TestText(t *testing.T) { 6 | text := &Text{} 7 | 8 | text.SetText(` 9 | This 10 | String 11 | Is 12 | Pretty 13 | Long 14 | 12345678901234567890 15 | `) 16 | if text.width != 20 { 17 | t.Errorf("Incorrect width: %d, expected: %d", text.width, 20) 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /views/textarea.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Tcell Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use file except in compliance with the License. 5 | // You may obtain a copy of the license at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package views 16 | 17 | import ( 18 | "strings" 19 | "sync" 20 | 21 | "github.com/gdamore/tcell/v2" 22 | ) 23 | 24 | // TextArea is a pannable 2 dimensional text widget. It wraps both 25 | // the view and the model for text in a single, convenient widget. 26 | // Text is provided as an array of strings, each of which represents 27 | // a single line to display. All text in the TextArea has the same 28 | // style. An optional soft cursor is available. 29 | type TextArea struct { 30 | model *linesModel 31 | once sync.Once 32 | CellView 33 | } 34 | 35 | type linesModel struct { 36 | runes [][]rune 37 | width int 38 | height int 39 | x int 40 | y int 41 | hide bool 42 | cursor bool 43 | style tcell.Style 44 | } 45 | 46 | func (m *linesModel) GetCell(x, y int) (rune, tcell.Style, []rune, int) { 47 | if x < 0 || y < 0 || y >= m.height || x >= len(m.runes[y]) { 48 | return 0, m.style, nil, 1 49 | } 50 | // XXX: extend this to support combining and full width chars 51 | return m.runes[y][x], m.style, nil, 1 52 | } 53 | 54 | func (m *linesModel) GetBounds() (int, int) { 55 | return m.width, m.height 56 | } 57 | 58 | func (m *linesModel) limitCursor() { 59 | if m.x > m.width-1 { 60 | m.x = m.width - 1 61 | } 62 | if m.y > m.height-1 { 63 | m.y = m.height - 1 64 | } 65 | if m.x < 0 { 66 | m.x = 0 67 | } 68 | if m.y < 0 { 69 | m.y = 0 70 | } 71 | } 72 | 73 | func (m *linesModel) SetCursor(x, y int) { 74 | m.x = x 75 | m.y = y 76 | m.limitCursor() 77 | } 78 | 79 | func (m *linesModel) MoveCursor(x, y int) { 80 | m.x += x 81 | m.y += y 82 | m.limitCursor() 83 | } 84 | 85 | func (m *linesModel) GetCursor() (int, int, bool, bool) { 86 | return m.x, m.y, m.cursor, !m.hide 87 | } 88 | 89 | // SetLines sets the content text to display. 90 | func (ta *TextArea) SetLines(lines []string) { 91 | ta.Init() 92 | m := ta.model 93 | m.width = 0 94 | 95 | // extend slice before using m.runes[row] to avoid panic 96 | slice := make([][]rune, len(lines)) 97 | m.runes = slice 98 | 99 | for row, line := range lines { 100 | for _, ch := range line { 101 | m.runes[row] = append(m.runes[row], ch) 102 | } 103 | if len(m.runes[row]) > m.width { 104 | m.width = len(m.runes[row]) 105 | } 106 | } 107 | 108 | m.height = len(m.runes) 109 | 110 | ta.CellView.SetModel(m) 111 | } 112 | 113 | func (ta *TextArea) SetStyle(style tcell.Style) { 114 | ta.model.style = style 115 | ta.CellView.SetStyle(style) 116 | } 117 | 118 | // EnableCursor enables a soft cursor in the TextArea. 119 | func (ta *TextArea) EnableCursor(on bool) { 120 | ta.Init() 121 | ta.model.cursor = on 122 | } 123 | 124 | // HideCursor hides or shows the cursor in the TextArea. 125 | // If on is true, the cursor is hidden. Note that a cursor is only 126 | // shown if it is enabled. 127 | func (ta *TextArea) HideCursor(on bool) { 128 | ta.Init() 129 | ta.model.hide = on 130 | } 131 | 132 | // SetContent is used to set the textual content, passed as a 133 | // single string. Lines within the string are delimited by newlines. 134 | func (ta *TextArea) SetContent(text string) { 135 | ta.Init() 136 | lines := strings.Split(strings.Trim(text, "\n"), "\n") 137 | ta.SetLines(lines) 138 | } 139 | 140 | // Init initializes the TextArea. 141 | func (ta *TextArea) Init() { 142 | ta.once.Do(func() { 143 | lm := &linesModel{runes: [][]rune{}, width: 0} 144 | ta.model = lm 145 | ta.CellView.Init() 146 | ta.CellView.SetModel(lm) 147 | }) 148 | } 149 | 150 | // NewTextArea creates a blank TextArea. 151 | func NewTextArea() *TextArea { 152 | ta := &TextArea{} 153 | ta.Init() 154 | return ta 155 | } 156 | -------------------------------------------------------------------------------- /views/textarea_test.go: -------------------------------------------------------------------------------- 1 | package views 2 | 3 | import "testing" 4 | 5 | func TestSetContent(t *testing.T) { 6 | ta := &TextArea{} 7 | 8 | ta.SetContent("This is a quite long line.") // This line is longer than 11. 9 | ta.SetContent("Four.\nFive...\n...and Six.") //"...and Six." should be 11 long. 10 | 11 | if ta.model.height != 3 { 12 | t.Errorf("Incorrect height: %d, expected: %d", ta.model.height, 3) 13 | } 14 | if ta.model.width != 11 { 15 | t.Errorf("Incorrect width: %d, expected: %d", ta.model.width, 11) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /webfiles/beep.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gdamore/tcell/781586687ddb57c9d44727dc9320340c4d049b11/webfiles/beep.wav -------------------------------------------------------------------------------- /webfiles/tcell.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Tcell 6 | 7 | 8 | 9 | 10 |

11 | 		
12 | 	
13 | 


--------------------------------------------------------------------------------
/webfiles/termstyle.css:
--------------------------------------------------------------------------------
  1 | * {
  2 |   margin: 0;
  3 |   padding: 0;
  4 |   border: 0;
  5 |   outline: 0;
  6 |   font-family: "Menlo", "Andale Mono", "Courier New", Monospace;
  7 | }
  8 | 
  9 | #terminal {
 10 |   background-color: black;
 11 |   color: green;
 12 |   display: inline-block;
 13 | 
 14 |   /* Copy paste! */
 15 |   user-select: none;
 16 |   -webkit-user-select: none;
 17 |   -khtml-user-select: none;
 18 |   -moz-user-select: none;
 19 |   -ms-user-select: none;
 20 |   --cursor-color: lightgrey;
 21 | }
 22 | 
 23 | /* Style attributes */
 24 | 
 25 | .bold {
 26 |   font-weight: bold;
 27 | }
 28 | 
 29 | .blink {
 30 |   animation: blinker 1s step-start infinite;
 31 | }
 32 | 
 33 | .underline {
 34 |   text-decoration: underline;
 35 | }
 36 | 
 37 | .dim {
 38 |   filter: brightness(50);
 39 | }
 40 | 
 41 | .italic {
 42 |   font-style: italic;
 43 | }
 44 | 
 45 | .strikethrough {
 46 |   text-decoration: line-through;
 47 | }
 48 | 
 49 | .double_underline {
 50 |   text-decoration: underline double;
 51 | }
 52 | 
 53 | .curly_underline {
 54 |   text-decoration: underline wavy;
 55 | }
 56 | 
 57 | .dotted_underline {
 58 |   text-decoration: underline dotted;
 59 | }
 60 | 
 61 | .dashed_underline {
 62 |   text-decoration: underline dashed;
 63 | }
 64 | 
 65 | /* Cursor styles */
 66 | 
 67 | .cursor-steady-block {
 68 |   background-color: var(--cursor-color) !important;
 69 | }
 70 | .cursor-blinking-block {
 71 |   animation: blinking-block 1s step-start infinite !important;
 72 | }
 73 | @keyframes blinking-block {
 74 |   50% {
 75 |     background-color: var(--cursor-color);
 76 |   }
 77 | }
 78 | 
 79 | .cursor-steady-underline {
 80 |   text-decoration: underline var(--cursor-color) !important;
 81 | }
 82 | .cursor-blinking-underline {
 83 |   animation: blinking-underline 1s step-start infinite !important;
 84 | }
 85 | @keyframes blinking-underline {
 86 |   50% {
 87 |     text-decoration: underline var(--cursor-color);
 88 |   }
 89 | }
 90 | 
 91 | .cursor-steady-bar {
 92 |   margin-left: -2px;
 93 | }
 94 | .cursor-steady-bar:before {
 95 |   content: " ";
 96 |   width: 2px;
 97 |   background-color: var(--cursor-color) !important;
 98 |   display: inline-block;
 99 | }
100 | .cursor-blinking-bar {
101 |   margin-left: -2px;
102 | }
103 | .cursor-blinking-bar:before {
104 |   content: " ";
105 |   width: 2px;
106 |   background-color: var(--cursor-color) !important;
107 |   display: inline-block;
108 |   animation: blinker 1s step-start infinite;
109 | }
110 | 
111 | /* General animations */
112 | 
113 | @keyframes blinker {
114 |   50% {
115 |     opacity: 0;
116 |   }
117 | }
118 | 


--------------------------------------------------------------------------------