Repository: rivo/tview Branch: master Commit: 63ee97f9e014 Files: 92 Total size: 710.3 KB Directory structure: gitextract_rl0cd57v/ ├── .github/ │ └── FUNDING.yml ├── CONTRIBUTING.md ├── LICENSE.txt ├── README.md ├── ansi.go ├── application.go ├── borders.go ├── box.go ├── button.go ├── checkbox.go ├── demos/ │ ├── box/ │ │ ├── README.md │ │ └── main.go │ ├── button/ │ │ ├── README.md │ │ └── main.go │ ├── checkbox/ │ │ ├── README.md │ │ └── main.go │ ├── dropdown/ │ │ ├── README.md │ │ └── main.go │ ├── flex/ │ │ ├── README.md │ │ └── main.go │ ├── form/ │ │ ├── README.md │ │ └── main.go │ ├── frame/ │ │ ├── README.md │ │ └── main.go │ ├── grid/ │ │ ├── README.md │ │ └── main.go │ ├── image/ │ │ ├── README.md │ │ └── main.go │ ├── inputfield/ │ │ ├── README.md │ │ ├── autocomplete/ │ │ │ └── main.go │ │ ├── autocompleteasync/ │ │ │ └── main.go │ │ └── main.go │ ├── list/ │ │ ├── README.md │ │ └── main.go │ ├── modal/ │ │ ├── README.md │ │ └── main.go │ ├── pages/ │ │ ├── README.md │ │ └── main.go │ ├── presentation/ │ │ ├── center.go │ │ ├── code.go │ │ ├── colors.go │ │ ├── cover.go │ │ ├── end.go │ │ ├── flex.go │ │ ├── form.go │ │ ├── grid.go │ │ ├── helloworld.go │ │ ├── inputfield.go │ │ ├── introduction.go │ │ ├── main.go │ │ ├── table.go │ │ ├── textview.go │ │ └── treeview.go │ ├── primitive/ │ │ ├── README.md │ │ └── main.go │ ├── table/ │ │ ├── README.md │ │ ├── main.go │ │ └── virtualtable/ │ │ ├── README.md │ │ └── main.go │ ├── textarea/ │ │ ├── README.md │ │ └── main.go │ ├── textview/ │ │ ├── README.md │ │ ├── chat/ │ │ │ ├── README.md │ │ │ ├── chain.txt │ │ │ └── main.go │ │ └── main.go │ ├── treeview/ │ │ ├── README.md │ │ └── main.go │ └── unicode/ │ ├── README.md │ └── main.go ├── doc.go ├── dropdown.go ├── flex.go ├── form.go ├── frame.go ├── go.mod ├── go.sum ├── grid.go ├── image.go ├── inputfield.go ├── list.go ├── modal.go ├── pages.go ├── primitive.go ├── semigraphics.go ├── strings.go ├── styles.go ├── table.go ├── textarea.go ├── textview.go ├── treeview.go └── util.go ================================================ FILE CONTENTS ================================================ ================================================ FILE: .github/FUNDING.yml ================================================ github: rivo ================================================ FILE: CONTRIBUTING.md ================================================ # Contributing to tview First of all, thank you for taking the time to contribute. The following provides you with some guidance on how to contribute to this project. Mainly, it is meant to save us all some time so please read it, it's not long. Please note that this document is work in progress so I might add to it in the future. ## Issues - Please include enough information so everybody understands your request. - Screenshots or code that illustrates your point always helps. - It's fine to ask for help. But you should have checked out the [documentation](https://godoc.org/github.com/rivo/tview) first in any case. - If you request a new feature, state your motivation and share a use case that you faced where you needed that new feature. It should be something that others will also need. ## Pull Requests In my limited time I can spend on this project, I will always go through issues first before looking at pull requests. It takes a _lot_ of time to look at code that you submitted and I may not have that time. So be prepared to have your pull requests lying around for a long time. Therefore, if you have a feature request, open an issue first before sending me a pull request, and allow for some discussion. It may save you from writing code that will get rejected. If your case is strong, there is a good chance that I will add the feature for you. I'm very picky about the code that goes into this repo. So if you violate any of the following guidelines, there is a good chance I won't merge your pull request. - There must be a strong case for your additions/changes, such as: - Bug fixes - Features that are needed (see "Issues" above; state your motivation) - Improvements in stability or performance (if readability does not suffer) - Your code must follow the structure of the existing code. Don't just patch something on. Try to understand how `tview` is currently designed and follow that design. Your code needs to be consistent with existing code. - If you're adding code that increases the work required to maintain the project, you must be willing to take responsibility for that extra work. I will ask you to maintain your part of the code in the long run. - Function/type/variable/constant names must be as descriptive as they are right now. Follow the conventions of the package. - All functions/types/variables/constants, even private ones, must have comments in good English. These comments must be elaborate enough so that new users of the package understand them and can follow them. Provide examples if you have to. Start all sentences upper-case, as is common in English, and end them with a period. Comments in their own lines must not exceed the 80 character border. Break over if necessary. - A new function should be located close to related functions in the file. For example, `GetColor()` should come after (or before) `SetColor()`. - Your changes must not decrease the project's [Go Report](https://goreportcard.com/report/github.com/rivo/tview) rating. - No breaking changes unless there is absolutely no other way. - If an issue accompanies your pull request, reference it in the PR's comments, e.g. "Fixes #123", so it is closed automatically when the PR is closed. ================================================ FILE: LICENSE.txt ================================================ MIT License Copyright (c) 2018 Oliver Kuederle Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ # Rich Interactive Widgets for Terminal UIs [![PkgGoDev](https://pkg.go.dev/badge/github.com/rivo/tview)](https://pkg.go.dev/github.com/rivo/tview) [![Go Report](https://img.shields.io/badge/go%20report-A%2B-brightgreen.svg)](https://goreportcard.com/report/github.com/rivo/tview) This Go package provides commonly used components for terminal based user interfaces. ![Screenshot](tview.gif) Among these components are: - __Input forms__ (including __text input__, __selections__, __checkboxes__, and __buttons__) - Navigable multi-color __text views__ - Editable multi-line __text areas__ - Sophisticated navigable __table views__ - Flexible __tree views__ - Selectable __lists__ - __Images__ - __Grid__, __Flexbox__ and __page layouts__ - Modal __message windows__ - An __application__ wrapper They come with lots of customization options and can be easily extended to fit your needs. ## Usage To add this package to your project: ```bash go get github.com/rivo/tview@master ``` ## Hello World This basic example creates a box titled "Hello, World!" and displays it in your terminal: ```go package main import ( "github.com/rivo/tview" ) func main() { box := tview.NewBox().SetBorder(true).SetTitle("Hello, world!") if err := tview.NewApplication().SetRoot(box, true).Run(); err != nil { panic(err) } } ``` Check out the [GitHub Wiki](https://github.com/rivo/tview/wiki) for more examples along with screenshots. Or try the examples in the "demos" subdirectory. For a presentation highlighting this package, compile and run the program found in the "demos/presentation" subdirectory. ## Projects using `tview` - [K9s - Kubernetes CLI](https://github.com/derailed/k9s) - [IRCCloud Terminal Client](https://github.com/termoose/irccloud) - [Window manager for `tview`](https://github.com/epiclabs-io/winman) - [CLI bookmark manager](https://github.com/Endi1/drawer) - [A caving database interface written in Go](https://github.com/IdlePhysicist/cave-logger) - [Interactive file browse and exec any command.](https://github.com/bannzai/itree) - [A complete TUI for LDAP](https://github.com/Macmod/godap) - [A simple CRM](https://github.com/broadcastle/crm) - [Terminal UI for todist](https://github.com/cyberdummy/todoista) - [Graphical kubectl wrapper](https://github.com/dcaiafa/kpick) - [Decred Decentralized Exchange ](https://github.com/decred/dcrdex) - [A CLI file browser for Raspberry PI](https://github.com/destinmoulton/pixi) - [A tool to manage projects.](https://github.com/divramod/dp) - [A simple app for BMI monitoring](https://github.com/erleene/go-bmi) - [Stream TIDAL from command line](https://github.com/godsic/vibe) - [Secure solution for fully decentralized password management](https://github.com/guillaumemichel/passtor/) - [A growing collection of convenient little tools to work with systemd services](https://github.com/muesli/service-tools/) - [A terminal based browser for Redis written in Go](https://github.com/nitishm/redis-terminal) - [First project for the Computer Networks course.](https://github.com/pablogadhi/XMPPClient) - [Test your typing speed in the terminal!](https://github.com/shilangyu/typer-go) - [TUI Client for Docker](https://github.com/skanehira/docui) - [SSH client using certificates signed by HashiCorp Vault](https://github.com/stephane-martin/vssh) - [VMware vCenter Text UI](https://github.com/thebsdbox/vctui) - [Bookmarks on terminal](https://github.com/tryffel/bookmarker) - [A UDP testing utility](https://github.com/vaelen/udp-tester) - [A simple Kanban board for your terminal](https://github.com/witchard/toukan) - [The personal information dashboard for your terminal. ](https://github.com/wtfutil/wtf) - [MySQL database to Golang struct](https://github.com/xxjwxc/gormt) - [Discord, TUI and SIXEL.](https://gitlab.com/diamondburned/6cord) - [A CLI Audio Player](https://www.github.com/dhulihan/grump) - [GLab, a GitLab CLI tool](https://gitlab.com/profclems/glab) - [Browse your AWS ECS Clusters in the Terminal](https://github.com/swartzrock/ecsview) - [The CLI Task Manager for Geeks](https://github.com/ajaxray/geek-life) - [Fast disk usage analyzer written in Go](https://github.com/dundee/gdu) - [Multiplayer Chess On Terminal](https://github.com/qnkhuat/gochess) - [Scriptable TUI music player](https://github.com/issadarkthing/gomu) - [MangaDesk : TUI Client for downloading manga to your computer](https://github.com/darylhjd/mangadesk) - [Go How Much? a Crypto coin price tracking from terminal](https://github.com/ledongthuc/gohowmuch) - [dbui: Universal CLI for Database Connections](https://github.com/KenanBek/dbui) - [ssmbrowse: Simple and elegant cli AWS SSM parameter browser](https://github.com/bnaydenov/ssmbrowse) - [gobit: binance intelligence terminal](https://github.com/infl00p/gobit) - [viddy: A modern watch command](https://github.com/sachaos/viddy) - [s3surfer: CLI tool for browsing S3 bucket and download objects interactively](https://github.com/hirose31/s3surfer) - [libgen-tui: A terminal UI for downloading books from Library Genesis](https://github.com/audstanley/libgen-tui) - [kubectl-lazy: kubectl plugin to easy to view pod](https://github.com/togettoyou/kubectl-lazy) - [podman-tui: podman user interface](https://github.com/containers/podman-tui) - [tvxwidgets: tview extra widgets](https://github.com/navidys/tvxwidgets) - [Domino card game on terminal](https://github.com/gusti-andika/card-domino.git) - [goaround: Query stackoverflow API and get results on terminal](https://github.com/glendsoza/goaround) - [resto: a CLI app can send pretty HTTP & API requests with TUI](https://github.com/abdfnx/resto) - [twad: a WAD launcher for the terminal](https://github.com/zmnpl/twad) - [pacseek: A TUI for searching and installing Arch Linux packages](https://github.com/moson-mo/pacseek) - [7GUIs demo](https://github.com/letientai299/7guis/tree/master/tui) - [tuihub: A utility hub/dashboard for personal use](https://github.com/ashis0013/tuihub) - [l'oggo: A terminal app for structured log streaming (GCP stack driver, k8s, local streaming)](https://github.com/aurc/loggo) - [reminder: Terminal based interactive app for organising tasks with minimal efforts.](https://github.com/goyalmunish/reminder) - [tufw: A terminal UI for ufw.](https://github.com/peltho/tufw) - [gh: the GitHub CLI](https://github.com/cli/cli) - [piptui: Terminal UI to manage pip packages](https://github.com/glendsoza/piptui/) - [cross-clipboard: A cross-platform clipboard sharing](https://github.com/ntsd/cross-clipboard) - [tui-deck: nextcloud deck frontend](https://github.com/mebitek/tui-deck) - [ktop: A top-like tool for your Kubernetes clusters](https://github.com/vladimirvivien/ktop) - [blimp: UI for weather, network latency, application status, & more](https://github.com/merlinfuchs/blimp) - [Curly - A simple TUI leveraging curl to test endpoints](https://github.com/migcaraballo/curly) - [amtui: Alertmanager TUI](https://github.com/pehlicd/amtui) - [A TUI CLI manager](https://github.com/costa86/cli-manager) - [PrivateBTC](https://github.com/adrianbrad/privatebtc) - [play: A TUI playground to experiment with your favorite programs, such as grep, sed, awk, jq and yq](https://github.com/paololazzari/play) - [gorest: Enjoy making HTTP requests in your terminal, just like you do in Insomnia.](https://github.com/NathanFirmo/gorest) - [Terminal-based application to listen Radio Stations around the world!](https://github.com/vergonha/garden-tui) - [ntui: A TUI to manage Hashicorp Nomad clusters](https://github.com/SHAPPY0/ntui) - [lazysql: A cross-platform TUI database management tool written in Go](https://github.com/jorgerojas26/lazysql) - [redis-tui: A Redis Text-based UI client in CLI](https://github.com/mylxsw/redis-tui) - [fen: File manager](https://github.com/kivattt/fen) - [sqltui: A terminal UI to operate sql and nosql databases](https://github.com/LinPr/sqltui) - [DBee: Simple database browser](https://github.com/murat-cileli/dbee) - [oddshub: A TUI for sports betting odds](https://github.com/dos-2/oddshub) - [envolve: Terminal based interactive app for manage enviroment variables](https://github.com/erdemkosk/envolve) - [zfs-file-history: Terminal UI for inspecting and restoring file history on ZFS snapshots](https://github.com/markusressel/zfs-file-history) - [fan2go-tui: Terminal UI for fan2go](https://github.com/markusressel/fan2go-tui) - [NatsDash: Terminal UI for NATS Jetstream](https://nats-dash-gui.returnzero.win/) - [tuissh: A terminal UI to manage ssh connections](https://github.com/linuxexam/tuissh) - [chiko: Ultimate Beauty TUI gRPC Client](https://github.com/felangga/chiko) - [kmip-explorer: Browse & manage your KMIP objects from the terminal](https://github.com/phsym/kmip-explorer) - [stui: Slurm TUI for managing HPC clusters](https://github.com/antvirf/stui) - [nerdlog: Fast, remote-first, multi-host log viewer with timeline histogram](https://github.com/dimonomid/nerdlog) - [lxz: A powerful DevOps graphical command-line interface tool](https://github.com/liangzhaoliang95/lxz) - [vaulty: Terminal UI for Azure Keyvault](https://github.com/declan-whiting/vaulty) - [pago: Command-line password manager](https://github.com/dbohdan/pago) ## Documentation Refer to https://pkg.go.dev/github.com/rivo/tview for the package's documentation. Also check out the [Wiki](https://github.com/rivo/tview/wiki). ## Dependencies This package is based on [github.com/gdamore/tcell](https://github.com/gdamore/tcell) (and its dependencies) as well as on [github.com/rivo/uniseg](https://github.com/rivo/uniseg). ## Sponsor this Project [Become a Sponsor on GitHub](https://github.com/sponsors/rivo?metadata_source=tview_readme) to further this project! ## Backwards-Compatibility I try really hard to keep this project backwards compatible. Your software should not break when you upgrade `tview`. But this also means that some of its shortcomings that were present in the initial versions will remain. Having said that, backwards compatibility may still break when: - a new version of an imported package (most likely [`tcell`](https://github.com/gdamore/tcell)) changes in such a way that forces me to make changes in `tview` as well, - I fix something that I consider a bug, rather than a feature, something that does not work as originally intended, - I make changes to "internal" interfaces such as [`Primitive`](https://pkg.go.dev/github.com/rivo/tview#Primitive). You shouldn't need these interfaces unless you're writing your own primitives for `tview`. (Yes, I realize these are public interfaces. This has advantages as well as disadvantages. For the time being, it is what it is.) ## Your Feedback Add your issue here on GitHub. Feel free to get in touch if you have any questions. ## Code of Conduct We follow Golang's Code of Conduct which you can find [here](https://golang.org/conduct). ================================================ FILE: ansi.go ================================================ package tview import ( "bytes" "fmt" "io" "strconv" "strings" ) // The states of the ANSI escape code parser. const ( ansiText = iota ansiEscape ansiSubstring ansiControlSequence ) // ansi is a io.Writer which translates ANSI escape codes into tview color // tags. type ansi struct { io.Writer // Reusable buffers. buffer *bytes.Buffer // The entire output text of one Write(). csiParameter, csiIntermediate *bytes.Buffer // Partial CSI strings. attributes string // The buffer's current text attributes (a tview attribute string). // The current state of the parser. One of the ansi constants. state int } // ANSIWriter returns an io.Writer which translates any ANSI escape codes // written to it into tview style tags. Other escape codes don't have an effect // and are simply removed. The translated text is written to the provided // writer. func ANSIWriter(writer io.Writer) io.Writer { return &ansi{ Writer: writer, buffer: new(bytes.Buffer), csiParameter: new(bytes.Buffer), csiIntermediate: new(bytes.Buffer), state: ansiText, } } // Write parses the given text as a string of runes, translates ANSI escape // codes to style tags and writes them to the output writer. func (a *ansi) Write(text []byte) (int, error) { defer func() { a.buffer.Reset() }() for _, r := range string(text) { switch a.state { // We just entered an escape sequence. case ansiEscape: switch r { case '[': // Control Sequence Introducer. a.csiParameter.Reset() a.csiIntermediate.Reset() a.state = ansiControlSequence case 'c': // Reset. fmt.Fprint(a.buffer, "[-:-:-]") a.state = ansiText case 'P', ']', 'X', '^', '_': // Substrings and commands. a.state = ansiSubstring default: // Ignore. a.state = ansiText } // CSI Sequences. case ansiControlSequence: switch { case r >= 0x30 && r <= 0x3f: // Parameter bytes. if _, err := a.csiParameter.WriteRune(r); err != nil { return 0, err } case r >= 0x20 && r <= 0x2f: // Intermediate bytes. if _, err := a.csiIntermediate.WriteRune(r); err != nil { return 0, err } case r >= 0x40 && r <= 0x7e: // Final byte. switch r { case 'E': // Next line. count, _ := strconv.Atoi(a.csiParameter.String()) if count == 0 { count = 1 } fmt.Fprint(a.buffer, strings.Repeat("\n", count)) case 'm': // Select Graphic Rendition. var background, foreground string params := a.csiParameter.String() fields := strings.Split(params, ";") if len(params) == 0 || fields[0] == "" || fields[0] == "0" { // Reset. foreground = "-" background = "-" a.attributes = "-" } lookupColor := func(colorNumber int) string { if colorNumber < 0 || colorNumber > 15 { return "black" } return []string{ "black", "maroon", "green", "olive", "navy", "purple", "teal", "silver", "gray", "red", "lime", "yellow", "blue", "fuchsia", "aqua", "white", }[colorNumber] } FieldLoop: for index, field := range fields { switch field { case "1", "01": if !strings.ContainsRune(a.attributes, 'b') { a.attributes += "b" } case "2", "02": if !strings.ContainsRune(a.attributes, 'd') { a.attributes += "d" } case "3", "03": if !strings.ContainsRune(a.attributes, 'i') { a.attributes += "i" } case "4", "04": if !strings.ContainsRune(a.attributes, 'u') { a.attributes += "u" } case "5", "05": if !strings.ContainsRune(a.attributes, 'l') { a.attributes += "l" } case "7", "07": if !strings.ContainsRune(a.attributes, 'r') { a.attributes += "r" } case "9", "09": if !strings.ContainsRune(a.attributes, 's') { a.attributes += "s" } case "22": if i := strings.IndexRune(a.attributes, 'b'); i >= 0 { a.attributes = a.attributes[:i] + a.attributes[i+1:] } if i := strings.IndexRune(a.attributes, 'd'); i >= 0 { a.attributes = a.attributes[:i] + a.attributes[i+1:] } case "23": if i := strings.IndexRune(a.attributes, 'i'); i >= 0 { a.attributes = a.attributes[:i] + a.attributes[i+1:] } case "24": if i := strings.IndexRune(a.attributes, 'u'); i >= 0 { a.attributes = a.attributes[:i] + a.attributes[i+1:] } case "25": if i := strings.IndexRune(a.attributes, 'l'); i >= 0 { a.attributes = a.attributes[:i] + a.attributes[i+1:] } case "27": if i := strings.IndexRune(a.attributes, 'r'); i >= 0 { a.attributes = a.attributes[:i] + a.attributes[i+1:] } case "29": if i := strings.IndexRune(a.attributes, 's'); i >= 0 { a.attributes = a.attributes[:i] + a.attributes[i+1:] } case "30", "31", "32", "33", "34", "35", "36", "37": colorNumber, _ := strconv.Atoi(field) foreground = lookupColor(colorNumber - 30) case "39": foreground = "-" case "40", "41", "42", "43", "44", "45", "46", "47": colorNumber, _ := strconv.Atoi(field) background = lookupColor(colorNumber - 40) case "49": background = "-" case "90", "91", "92", "93", "94", "95", "96", "97": colorNumber, _ := strconv.Atoi(field) foreground = lookupColor(colorNumber - 82) case "100", "101", "102", "103", "104", "105", "106", "107": colorNumber, _ := strconv.Atoi(field) background = lookupColor(colorNumber - 92) case "38", "48": var color string if len(fields) > index+1 { if fields[index+1] == "5" && len(fields) > index+2 { // 8-bit colors. colorNumber, _ := strconv.Atoi(fields[index+2]) if colorNumber <= 15 { color = lookupColor(colorNumber) } else if colorNumber <= 231 { red := (colorNumber - 16) / 36 green := ((colorNumber - 16) / 6) % 6 blue := (colorNumber - 16) % 6 color = fmt.Sprintf("#%02x%02x%02x", 255*red/5, 255*green/5, 255*blue/5) } else if colorNumber <= 255 { grey := 255 * (colorNumber - 232) / 23 color = fmt.Sprintf("#%02x%02x%02x", grey, grey, grey) } } else if fields[index+1] == "2" && len(fields) > index+4 { // 24-bit colors. red, _ := strconv.Atoi(fields[index+2]) green, _ := strconv.Atoi(fields[index+3]) blue, _ := strconv.Atoi(fields[index+4]) color = fmt.Sprintf("#%02x%02x%02x", red, green, blue) } } if len(color) > 0 { if field == "38" { foreground = color } else { background = color } } break FieldLoop } } var colon string if len(a.attributes) > 1 && a.attributes[0] == '-' { a.attributes = a.attributes[1:] } if len(a.attributes) > 0 { colon = ":" } if len(foreground) > 0 || len(background) > 0 || len(a.attributes) > 0 { fmt.Fprintf(a.buffer, "[%s:%s%s%s]", foreground, background, colon, a.attributes) } } a.state = ansiText default: // Undefined byte. a.state = ansiText // Abort CSI. } // We just entered a substring/command sequence. case ansiSubstring: if r == 27 { // Most likely the end of the substring. a.state = ansiEscape } // Ignore all other characters. // "ansiText" and all others. default: if r == 27 { // This is the start of an escape sequence. a.state = ansiEscape } else { // Just a regular rune. Send to buffer. if _, err := a.buffer.WriteRune(r); err != nil { return 0, err } } } } // Write buffer to target writer. n, err := a.buffer.WriteTo(a.Writer) if err != nil { return int(n), err } return len(text), nil } // TranslateANSI replaces ANSI escape sequences found in the provided string // with tview's style tags and returns the resulting string. func TranslateANSI(text string) string { var buffer bytes.Buffer writer := ANSIWriter(&buffer) writer.Write([]byte(text)) return buffer.String() } ================================================ FILE: application.go ================================================ package tview import ( "strings" "sync" "time" "github.com/gdamore/tcell/v2" ) const ( // The size of the event/update/redraw channels. queueSize = 100 // The minimum time between two consecutive redraws. redrawPause = 50 * time.Millisecond ) // DoubleClickInterval specifies the maximum time between clicks to register a // double click rather than click. var DoubleClickInterval = 500 * time.Millisecond // MouseAction indicates one of the actions the mouse is logically doing. type MouseAction int16 // Available mouse actions. const ( MouseMove MouseAction = iota MouseLeftDown MouseLeftUp MouseLeftClick MouseLeftDoubleClick MouseMiddleDown MouseMiddleUp MouseMiddleClick MouseMiddleDoubleClick MouseRightDown MouseRightUp MouseRightClick MouseRightDoubleClick MouseScrollUp MouseScrollDown MouseScrollLeft MouseScrollRight // The following special value will not be provided as a mouse action but // indicate that an overridden mouse event was consumed. See // [Box.SetMouseCapture] for details. MouseConsumed ) // queuedUpdate represented the execution of f queued by // Application.QueueUpdate(). If "done" is not nil, it receives exactly one // element after f has executed. type queuedUpdate struct { f func() done chan struct{} } // Application represents the top node of an application. // // It is not strictly required to use this class as none of the other classes // depend on it. However, it provides useful tools to set up an application and // plays nicely with all widgets. // // The following command displays a primitive p on the screen until Ctrl-C is // pressed: // // if err := tview.NewApplication().SetRoot(p, true).Run(); err != nil { // panic(err) // } type Application struct { sync.RWMutex // The application's screen. Apart from Run(), this variable should never be // set directly. Always use the screenReplacement channel after calling // Fini(), to set a new screen (or nil to stop the application). screen tcell.Screen // The application's title. If not empty, it will be set on every new screen // that is added. title string // The root primitive to be seen on the screen. root Primitive // Whether or not the application resizes the root primitive. rootFullscreen bool // Set to true if mouse events are enabled. enableMouse bool // Set to true if paste events are enabled. enablePaste bool // An optional capture function which receives a key event and returns the // event to be forwarded to the default input handler (nil if nothing should // be forwarded). inputCapture func(event *tcell.EventKey) *tcell.EventKey // An optional callback function which is invoked just before the root // primitive is drawn. beforeDraw func(screen tcell.Screen) bool // An optional callback function which is invoked after the root primitive // was drawn. afterDraw func(screen tcell.Screen) // Used to send screen events from separate goroutine to main event loop events chan tcell.Event // Functions queued from goroutines, used to serialize updates to primitives. updates chan queuedUpdate // An object that the screen variable will be set to after Fini() was called. // Use this channel to set a new screen object for the application // (screen.Init() and draw() will be called implicitly). A value of nil will // stop the application. screenReplacement chan tcell.Screen // An optional capture function which receives a mouse event and returns the // event to be forwarded to the default mouse handler (nil if nothing should // be forwarded). mouseCapture func(event *tcell.EventMouse, action MouseAction) (*tcell.EventMouse, MouseAction) mouseCapturingPrimitive Primitive // A Primitive returned by a MouseHandler which will capture future mouse events. lastMouseX, lastMouseY int // The last position of the mouse. mouseDownX, mouseDownY int // The position of the mouse when its button was last pressed. lastMouseClick time.Time // The time when a mouse button was last clicked. lastMouseButtons tcell.ButtonMask // The last mouse button state. } // NewApplication creates and returns a new application. func NewApplication() *Application { return &Application{ events: make(chan tcell.Event, queueSize), updates: make(chan queuedUpdate, queueSize), screenReplacement: make(chan tcell.Screen, 1), } } // SetInputCapture sets a function which captures all key events before they are // forwarded to the key event handler of the primitive which currently has // focus. This function can then choose to forward that key event (or a // different one) by returning it or stop the key event processing by returning // nil. // // The only default global key event is Ctrl-C which stops the application. It // requires special handling: // // - If you do not wish to change the default behavior, return the original // event object passed to your input capture function. // - If you wish to block Ctrl-C from any functionality, return nil. // - If you do not wish Ctrl-C to stop the application but still want to // forward the Ctrl-C event to primitives down the hierarchy, return a new // key event with the same key and modifiers, e.g. // tcell.NewEventKey(tcell.KeyCtrlC, 0, tcell.ModNone). // // Pasted key events are not forwarded to the input capture function if pasting // is enabled (see [Application.EnablePaste]). func (a *Application) SetInputCapture(capture func(event *tcell.EventKey) *tcell.EventKey) *Application { a.inputCapture = capture return a } // GetInputCapture returns the function installed with SetInputCapture() or nil // if no such function has been installed. func (a *Application) GetInputCapture() func(event *tcell.EventKey) *tcell.EventKey { return a.inputCapture } // SetMouseCapture sets a function which captures mouse events (consisting of // the original tcell mouse event and the semantic mouse action) before they are // forwarded to the appropriate mouse event handler. This function can then // choose to forward that event (or a different one) by returning it or stop // the event processing by returning a nil mouse event. In such a case, the // event is considered consumed and the screen will be redrawn. func (a *Application) SetMouseCapture(capture func(event *tcell.EventMouse, action MouseAction) (*tcell.EventMouse, MouseAction)) *Application { a.mouseCapture = capture return a } // GetMouseCapture returns the function installed with SetMouseCapture() or nil // if no such function has been installed. func (a *Application) GetMouseCapture() func(event *tcell.EventMouse, action MouseAction) (*tcell.EventMouse, MouseAction) { return a.mouseCapture } // SetScreen allows you to provide your own tcell.Screen object. For most // applications, this is not needed and you should be familiar with // tcell.Screen when using this function. As the tcell.Screen interface may // change in the future, you may need to update your code when this package // updates to a new tcell version. // // This function is typically called before the first call to Run(). Init() need // not be called on the screen. func (a *Application) SetScreen(screen tcell.Screen) *Application { if screen == nil { return a // Invalid input. Do nothing. } a.Lock() if a.screen == nil { // Run() has not been called yet. a.screen = screen a.Unlock() screen.Init() return a } // Run() is already in progress. Exchange screen. oldScreen := a.screen a.Unlock() oldScreen.Fini() a.screenReplacement <- screen return a } // SetTitle sets the title of the terminal window, to the extent that the // terminal supports it. A non-empty title will be set on every new tcell.Screen // that is created by or added to this application. func (a *Application) SetTitle(title string) *Application { a.Lock() defer a.Unlock() a.title = title if a.screen != nil { a.screen.SetTitle(title) } return a } // EnableMouse enables mouse events or disables them (if "false" is provided). func (a *Application) EnableMouse(enable bool) *Application { a.Lock() defer a.Unlock() if enable != a.enableMouse && a.screen != nil { if enable { a.screen.EnableMouse() } else { a.screen.DisableMouse() } } a.enableMouse = enable return a } // EnablePaste enables the capturing of paste events or disables them (if // "false" is provided). This must be supported by the terminal. // // Widgets won't interpret paste events for navigation or selection purposes. // Paste events are typically only used to insert a block of text into an // [InputField] or a [TextArea]. func (a *Application) EnablePaste(enable bool) *Application { a.Lock() defer a.Unlock() if enable != a.enablePaste && a.screen != nil { if enable { a.screen.EnablePaste() } else { a.screen.DisablePaste() } } a.enablePaste = enable return a } // Run starts the application and thus the event loop. This function returns // when [Application.Stop] was called. // // Note that while an application is running, it fully claims stdin, stdout, and // stderr. If you use these standard streams, they may not work as expected. // Consider stopping the application first or suspending it (using // [Application.Suspend]) if you have to interact with the standard streams, for // example when needing to print a call stack during a panic. func (a *Application) Run() error { var ( err, appErr error lastRedraw time.Time // The time the screen was last redrawn. redrawTimer *time.Timer // A timer to schedule the next redraw. ) a.Lock() // Make a screen if there is none yet. if a.screen == nil { a.screen, err = tcell.NewScreen() if err != nil { a.Unlock() return err } if err = a.screen.Init(); err != nil { a.Unlock() return err } if a.enableMouse { a.screen.EnableMouse() } else { a.screen.DisableMouse() } if a.enablePaste { a.screen.EnablePaste() } else { a.screen.DisablePaste() } if a.title != "" { a.screen.SetTitle(a.title) } } // We catch panics to clean up because they mess up the terminal. defer func() { if p := recover(); p != nil { if a.screen != nil { a.screen.Fini() } panic(p) } }() // Draw the screen for the first time. a.Unlock() a.draw() // Separate loop to wait for screen events. var wg sync.WaitGroup wg.Add(1) go func() { defer wg.Done() for { a.RLock() screen := a.screen a.RUnlock() if screen == nil { // We have no screen. Let's stop. a.QueueEvent(nil) break } // Wait for next event and queue it. event := screen.PollEvent() if event != nil { // Regular event. Queue. a.QueueEvent(event) continue } // A screen was finalized (event is nil). Wait for a new screen. screen = <-a.screenReplacement if screen == nil { // No new screen. We're done. a.QueueEvent(nil) // Stop the event loop. return } // We have a new screen. Keep going. a.Lock() a.screen = screen enableMouse := a.enableMouse enablePaste := a.enablePaste a.Unlock() // Initialize and draw this screen. if err := screen.Init(); err != nil { panic(err) } if enableMouse { screen.EnableMouse() } else { screen.DisableMouse() } if enablePaste { screen.EnablePaste() } else { screen.DisablePaste() } if a.title != "" { screen.SetTitle(a.title) } a.draw() } }() // Start event loop. var ( pasteBuffer strings.Builder pasting bool // Set to true while we receive paste key events. ) EventLoop: for { select { // If we received an event, handle it. case event := <-a.events: if event == nil { break EventLoop } switch event := event.(type) { case *tcell.EventKey: // If we are pasting, collect runes, nothing else. if pasting { switch event.Key() { case tcell.KeyRune: pasteBuffer.WriteRune(event.Rune()) case tcell.KeyEnter: pasteBuffer.WriteRune('\n') case tcell.KeyCtrlJ: pasteBuffer.WriteRune('\n') case tcell.KeyTab: pasteBuffer.WriteRune('\t') } break } a.RLock() root := a.root inputCapture := a.inputCapture a.RUnlock() // Intercept keys. var draw bool originalEvent := event if inputCapture != nil { event = inputCapture(event) if event == nil { a.draw() break // Don't forward event. } draw = true } // Ctrl-C closes the application. if event == originalEvent && event.Key() == tcell.KeyCtrlC { a.Stop() break } // Pass other key events to the root primitive. if root != nil && root.HasFocus() { if handler := root.InputHandler(); handler != nil { handler(event, func(p Primitive) { a.SetFocus(p) }) draw = true } } // Redraw. if draw { a.draw() } case *tcell.EventPaste: if !a.enablePaste { break } if event.Start() { pasting = true pasteBuffer.Reset() } else if event.End() { pasting = false a.RLock() root := a.root a.RUnlock() if root != nil && root.HasFocus() && pasteBuffer.Len() > 0 { // Pass paste event to the root primitive. if handler := root.PasteHandler(); handler != nil { handler(pasteBuffer.String(), func(p Primitive) { a.SetFocus(p) }) } // Redraw. a.draw() } } case *tcell.EventResize: if time.Since(lastRedraw) < redrawPause { if redrawTimer != nil { redrawTimer.Stop() } redrawTimer = time.AfterFunc(redrawPause, func() { a.events <- event }) } a.RLock() screen := a.screen a.RUnlock() if screen == nil { break } lastRedraw = time.Now() screen.Clear() a.draw() case *tcell.EventMouse: consumed, isMouseDownAction := a.fireMouseActions(event) if consumed { a.draw() } a.lastMouseButtons = event.Buttons() if isMouseDownAction { a.mouseDownX, a.mouseDownY = event.Position() } case *tcell.EventError: appErr = event a.Stop() } // If we have updates, now is the time to execute them. case update := <-a.updates: update.f() if update.done != nil { update.done <- struct{}{} } } } // Wait for the event loop to finish. wg.Wait() a.screen = nil return appErr } // fireMouseActions analyzes the provided mouse event, derives mouse actions // from it and then forwards them to the corresponding primitives. func (a *Application) fireMouseActions(event *tcell.EventMouse) (consumed, isMouseDownAction bool) { // We want to relay follow-up events to the same target primitive. var targetPrimitive Primitive // Helper function to fire a mouse action. fire := func(action MouseAction) { switch action { case MouseLeftDown, MouseMiddleDown, MouseRightDown: isMouseDownAction = true } // Intercept event. if a.mouseCapture != nil { event, action = a.mouseCapture(event, action) if event == nil { consumed = true return // Don't forward event. } } // Determine the target primitive. var primitive, capturingPrimitive Primitive if a.mouseCapturingPrimitive != nil { primitive = a.mouseCapturingPrimitive targetPrimitive = a.mouseCapturingPrimitive } else if targetPrimitive != nil { primitive = targetPrimitive } else { primitive = a.root } if primitive != nil { if handler := primitive.MouseHandler(); handler != nil { var wasConsumed bool wasConsumed, capturingPrimitive = handler(action, event, func(p Primitive) { a.SetFocus(p) }) if wasConsumed { consumed = true } } } a.mouseCapturingPrimitive = capturingPrimitive } x, y := event.Position() buttons := event.Buttons() clickMoved := x != a.mouseDownX || y != a.mouseDownY buttonChanges := buttons ^ a.lastMouseButtons if x != a.lastMouseX || y != a.lastMouseY { fire(MouseMove) a.lastMouseX = x a.lastMouseY = y } for _, buttonEvent := range []struct { button tcell.ButtonMask down, up, click, dclick MouseAction }{ {tcell.ButtonPrimary, MouseLeftDown, MouseLeftUp, MouseLeftClick, MouseLeftDoubleClick}, {tcell.ButtonMiddle, MouseMiddleDown, MouseMiddleUp, MouseMiddleClick, MouseMiddleDoubleClick}, {tcell.ButtonSecondary, MouseRightDown, MouseRightUp, MouseRightClick, MouseRightDoubleClick}, } { if buttonChanges&buttonEvent.button != 0 { if buttons&buttonEvent.button != 0 { fire(buttonEvent.down) } else { fire(buttonEvent.up) // A user override might set event to nil. if !clickMoved && event != nil { if a.lastMouseClick.Add(DoubleClickInterval).Before(time.Now()) { fire(buttonEvent.click) a.lastMouseClick = time.Now() } else { fire(buttonEvent.dclick) a.lastMouseClick = time.Time{} // reset } } } } } for _, wheelEvent := range []struct { button tcell.ButtonMask action MouseAction }{ {tcell.WheelUp, MouseScrollUp}, {tcell.WheelDown, MouseScrollDown}, {tcell.WheelLeft, MouseScrollLeft}, {tcell.WheelRight, MouseScrollRight}} { if buttons&wheelEvent.button != 0 { fire(wheelEvent.action) } } return consumed, isMouseDownAction } // Stop stops the application, causing Run() to return. func (a *Application) Stop() { a.Lock() defer a.Unlock() screen := a.screen if screen == nil { return } a.screen = nil screen.Fini() a.screenReplacement <- nil } // Suspend temporarily suspends the application by exiting terminal UI mode and // invoking the provided function "f". When "f" returns, terminal UI mode is // entered again and the application resumes. // // A return value of true indicates that the application was suspended and "f" // was called. If false is returned, the application was already suspended, // terminal UI mode was not exited, and "f" was not called. func (a *Application) Suspend(f func()) bool { a.RLock() screen := a.screen a.RUnlock() if screen == nil { return false // Screen has not yet been initialized. } // Enter suspended mode. if err := screen.Suspend(); err != nil { return false // Suspension failed. } // Wait for "f" to return. f() // If the screen object has changed in the meantime, we need to do more. a.RLock() defer a.RUnlock() if a.screen != screen { // Calling Stop() while in suspend mode currently still leads to a // panic, see https://github.com/gdamore/tcell/issues/440. screen.Fini() if a.screen == nil { return true // If stop was called (a.screen is nil), we're done already. } } else { // It hasn't changed. Resume. screen.Resume() // Not much we can do in case of an error. } // Continue application loop. return true } // Draw refreshes the screen (during the next update cycle). It calls the Draw() // function of the application's root primitive and then syncs the screen // buffer. It is almost never necessary to call this function. It can actually // deadlock your application if you call it from the main thread (e.g. in a // callback function of a widget). Please see // https://github.com/rivo/tview/wiki/Concurrency for details. func (a *Application) Draw() *Application { a.QueueUpdate(func() { a.draw() }) return a } // ForceDraw refreshes the screen immediately. Use this function with caution as // it may lead to race conditions with updates to primitives in other // goroutines. It is always preferable to call [Application.Draw] instead. // Never call this function from a goroutine. // // It is safe to call this function during queued updates and direct event // handling. func (a *Application) ForceDraw() *Application { return a.draw() } // draw actually does what Draw() promises to do. func (a *Application) draw() *Application { a.Lock() defer a.Unlock() screen := a.screen root := a.root fullscreen := a.rootFullscreen before := a.beforeDraw after := a.afterDraw // Maybe we're not ready yet or not anymore. if screen == nil || root == nil { return a } // Resize if requested. if fullscreen { // root is not nil here. width, height := screen.Size() root.SetRect(0, 0, width, height) } // Clear screen to remove unwanted artifacts from the previous cycle. screen.Clear() // Call before handler if there is one. if before != nil { if before(screen) { screen.Show() return a } } // Draw all primitives. root.Draw(screen) // Call after handler if there is one. if after != nil { after(screen) } // Sync screen. screen.Show() return a } // Sync forces a full re-sync of the screen buffer with the actual screen during // the next event cycle. This is useful for when the terminal screen is // corrupted so you may want to offer your users a keyboard shortcut to refresh // the screen. func (a *Application) Sync() *Application { a.updates <- queuedUpdate{f: func() { a.RLock() screen := a.screen a.RUnlock() if screen == nil { return } screen.Sync() }} return a } // SetBeforeDrawFunc installs a callback function which is invoked just before // the root primitive is drawn during screen updates. If the function returns // true, drawing will not continue, i.e. the root primitive will not be drawn // (and an after-draw-handler will not be called). // // Note that the screen is not cleared by the application. To clear the screen, // you may call screen.Clear(). // // Provide nil to uninstall the callback function. func (a *Application) SetBeforeDrawFunc(handler func(screen tcell.Screen) bool) *Application { a.beforeDraw = handler return a } // GetBeforeDrawFunc returns the callback function installed with // SetBeforeDrawFunc() or nil if none has been installed. func (a *Application) GetBeforeDrawFunc() func(screen tcell.Screen) bool { return a.beforeDraw } // SetAfterDrawFunc installs a callback function which is invoked after the root // primitive was drawn during screen updates. // // Provide nil to uninstall the callback function. func (a *Application) SetAfterDrawFunc(handler func(screen tcell.Screen)) *Application { a.afterDraw = handler return a } // GetAfterDrawFunc returns the callback function installed with // SetAfterDrawFunc() or nil if none has been installed. func (a *Application) GetAfterDrawFunc() func(screen tcell.Screen) { return a.afterDraw } // SetRoot sets the root primitive for this application. If "fullscreen" is set // to true, the root primitive's position will be changed to fill the screen. // // This function must be called at least once or nothing will be displayed when // the application starts. // // It also calls SetFocus() on the primitive. func (a *Application) SetRoot(root Primitive, fullscreen bool) *Application { a.Lock() a.root = root a.rootFullscreen = fullscreen if a.screen != nil { a.screen.Clear() } a.Unlock() a.SetFocus(root) return a } // ResizeToFullScreen resizes the given primitive such that it fills the entire // screen. func (a *Application) ResizeToFullScreen(p Primitive) *Application { a.RLock() width, height := a.screen.Size() a.RUnlock() p.SetRect(0, 0, width, height) return a } // SetFocus sets the focus to a new primitive. All key events will be directed // down the hierarchy (starting at the root) until a primitive handles them, // which per default goes towards the focused primitive. // // Blur will be called on the previously focused [Primitive] and all of its // parents (including the root). Then Focus will be called on the new // [Primitive] and all of its parents (including the root). func (a *Application) SetFocus(p Primitive) *Application { a.RLock() root := a.root screen := a.screen a.RUnlock() // We make a focus chain with some pre-allocated space. chain := make([]Primitive, 0, 10) // Send blur events along the focus chain. if root != nil && root.focusChain(&chain) { for index, pr := range chain { if index == 0 { pr.Blur() } pr.blurred() } // Hide the cursor. If it's needed, the new focused primitive will show it // again. if screen != nil { screen.HideCursor() } } // At this point, no primitive has focus. // Focus the new primitive. var delegated bool if p != nil { p.Focus(func(p Primitive) { delegated = true // Avoids multiple focus notifications. a.SetFocus(p) }) } // If the primitive delegated focus to a child, that call has already // notified the focus listeners. if delegated { return a } // Send focus events along the new focus chain. chain = chain[:0] if root != nil && root.focusChain(&chain) { for _, pr := range chain { pr.focused() } } return a } // GetFocus returns the primitive which has the current focus. If none has it, // nil is returned. func (a *Application) GetFocus() Primitive { a.RLock() defer a.RUnlock() if a.root == nil { return nil } chain := make([]Primitive, 0, 10) if a.root.focusChain(&chain) && len(chain) > 0 { return chain[0] } return nil } // QueueUpdate is used to synchronize access to primitives from non-main // goroutines. The provided function will be executed as part of the event loop // and thus will not cause race conditions with other such update functions or // the Draw() function. // // Note that Draw() is not implicitly called after the execution of f as that // may not be desirable. You can call Draw() from f if the screen should be // refreshed after each update. Alternatively, use QueueUpdateDraw() to follow // up with an immediate refresh of the screen. // // This function returns after f has executed. func (a *Application) QueueUpdate(f func()) *Application { ch := make(chan struct{}) a.updates <- queuedUpdate{f: f, done: ch} <-ch return a } // QueueUpdateDraw works like QueueUpdate() except it refreshes the screen // immediately after executing f. func (a *Application) QueueUpdateDraw(f func()) *Application { a.QueueUpdate(func() { f() a.draw() }) return a } // QueueEvent sends an event to the Application event loop. // // It is not recommended for event to be nil. func (a *Application) QueueEvent(event tcell.Event) *Application { a.events <- event return a } ================================================ FILE: borders.go ================================================ package tview // Borders defines various borders used when primitives are drawn. // These may be changed to accommodate a different look and feel. var Borders = struct { Horizontal rune Vertical rune TopLeft rune TopRight rune BottomLeft rune BottomRight rune LeftT rune RightT rune TopT rune BottomT rune Cross rune HorizontalFocus rune VerticalFocus rune TopLeftFocus rune TopRightFocus rune BottomLeftFocus rune BottomRightFocus rune }{ Horizontal: BoxDrawingsLightHorizontal, Vertical: BoxDrawingsLightVertical, TopLeft: BoxDrawingsLightDownAndRight, TopRight: BoxDrawingsLightDownAndLeft, BottomLeft: BoxDrawingsLightUpAndRight, BottomRight: BoxDrawingsLightUpAndLeft, LeftT: BoxDrawingsLightVerticalAndRight, RightT: BoxDrawingsLightVerticalAndLeft, TopT: BoxDrawingsLightDownAndHorizontal, BottomT: BoxDrawingsLightUpAndHorizontal, Cross: BoxDrawingsLightVerticalAndHorizontal, HorizontalFocus: BoxDrawingsDoubleHorizontal, VerticalFocus: BoxDrawingsDoubleVertical, TopLeftFocus: BoxDrawingsDoubleDownAndRight, TopRightFocus: BoxDrawingsDoubleDownAndLeft, BottomLeftFocus: BoxDrawingsDoubleUpAndRight, BottomRightFocus: BoxDrawingsDoubleUpAndLeft, } ================================================ FILE: box.go ================================================ package tview import ( "github.com/gdamore/tcell/v2" ) // Box implements the Primitive interface with an empty background and optional // elements such as a border and a title. Box itself does not hold any content // but serves as the superclass of all other primitives. Subclasses add their // own content, typically (but not necessarily) keeping their content within the // box's rectangle. // // Box provides a number of utility functions available to all primitives. // // See https://github.com/rivo/tview/wiki/Box for an example. type Box struct { // Points to the implementing primitive at the bottom of the hierarchy. Primitive // The position of the rect. x, y, width, height int // The inner rect reserved for the box's content. If innerX is negative, // the rect is undefined and must be calculated. innerX, innerY, innerWidth, innerHeight int // Border padding. paddingTop, paddingBottom, paddingLeft, paddingRight int // The box's background color. backgroundColor tcell.Color // If set to true, the background of this box is not cleared while drawing. dontClear bool // Whether or not a border is drawn, reducing the box's space for content by // two in width and height. border bool // The border style. borderStyle tcell.Style // The title. Only visible if there is a border, too. title string // The color of the title. titleColor tcell.Color // The alignment of the title. titleAlign int // Whether or not this box has focus. At any time, this must be true only // for one primitive in the entire application. Such a primitive is usually // a visible and enabled widget but may also be a container primitive (if // no contained primitive has focus) or a primitive inaccessible to the user // (e.g. a child primitive of a widget to which interaction is delegated). hasFocus bool // Optional callback functions invoked when the primitive receives or loses // focus. focus, blur func() // Callback function invoked when the box itself is resized, nil if not set. boxResize func() // Callback function invoked when the box's inner content area is resized, // nil if not set. contentResize func() // An optional capture function which receives a key event and returns the // event to be forwarded to the primitive's default input handler (nil if // nothing should be forwarded). inputCapture func(event *tcell.EventKey) *tcell.EventKey // An optional function which is called before the box is drawn. draw func(screen tcell.Screen, x, y, width, height int) (int, int, int, int) // An optional capture function which receives a mouse event and returns the // event to be forwarded to the primitive's default mouse event handler (at // least one nil if nothing should be forwarded). mouseCapture func(action MouseAction, event *tcell.EventMouse) (MouseAction, *tcell.EventMouse) } // NewBox returns a [Box] without a border. func NewBox() *Box { b := &Box{ width: 15, height: 10, innerX: -1, // Mark as uninitialized. backgroundColor: Styles.PrimitiveBackgroundColor, borderStyle: tcell.StyleDefault.Foreground(Styles.BorderColor).Background(Styles.PrimitiveBackgroundColor), titleColor: Styles.TitleColor, titleAlign: AlignCenter, } b.Primitive = b return b } // SetBorderPadding sets the size of the borders around the box content. func (b *Box) SetBorderPadding(top, bottom, left, right int) *Box { b.paddingTop, b.paddingBottom, b.paddingLeft, b.paddingRight = top, bottom, left, right return b } // GetRect returns the current position of the rectangle, x, y, width, and // height. func (b *Box) GetRect() (int, int, int, int) { return b.x, b.y, b.width, b.height } // GetInnerRect returns the position of the inner rectangle (x, y, width, // height), without the border and without any padding. Width and height values // will clamp to 0 and thus never be negative. func (b *Box) GetInnerRect() (int, int, int, int) { if b.innerX >= 0 { return b.innerX, b.innerY, b.innerWidth, b.innerHeight } x, y, width, height := b.GetRect() if b.border { x++ y++ width -= 2 height -= 2 } x, y, width, height = x+b.paddingLeft, y+b.paddingTop, width-b.paddingLeft-b.paddingRight, height-b.paddingTop-b.paddingBottom if width < 0 { width = 0 } if height < 0 { height = 0 } return x, y, width, height } // SetRect sets a new position of the primitive. Note that this has no effect // if this primitive is part of a layout (e.g. Flex, Grid) or if it was added // like this: // // application.SetRoot(p, true) func (b *Box) SetRect(x, y, width, height int) { b.x = x b.y = y b.width, width = width, b.width b.height, height = height, b.height if b.width != width || b.height != height { if b.boxResize != nil { b.boxResize() } if b.contentResize != nil { b.contentResize() } } b.innerX = -1 // Mark inner rect as uninitialized. } // SetDrawFunc sets a callback function which is invoked after the box primitive // has been drawn. This allows you to add a more individual style to the box // (and all primitives which extend it). // // The function is provided with the box's dimensions (set via SetRect()). It // must return the box's inner dimensions (x, y, width, height) which will be // returned by GetInnerRect(), used by descendent primitives to draw their own // content. func (b *Box) SetDrawFunc(handler func(screen tcell.Screen, x, y, width, height int) (int, int, int, int)) *Box { b.draw = handler return b } // GetDrawFunc returns the callback function which was installed with // SetDrawFunc() or nil if no such function has been installed. func (b *Box) GetDrawFunc() func(screen tcell.Screen, x, y, width, height int) (int, int, int, int) { return b.draw } // SetBoxResizeFunc sets a callback function which is invoked when the size of // the box itself changes. Note that this is not called when the box is moved // (i.e. when only x and y change). Set to nil to remove the callback function. func (b *Box) SetBoxResizeFunc(handler func()) *Box { b.boxResize = handler return b } // SetContentResizeFunc sets a callback function which is invoked when the size // of the box's inner content area changes. Note that this is not called when // the area is moved (i.e. when only x and y change). Set to nil to remove the // callback function. func (b *Box) SetContentResizeFunc(handler func()) *Box { b.contentResize = handler return b } // WrapInputHandler wraps an input handler (see [Box.InputHandler]) with the // functionality to capture input (see [Box.SetInputCapture]) before passing it // on to the provided (default) input handler. // // This is only meant to be used by subclassing primitives. func (b *Box) WrapInputHandler(inputHandler func(*tcell.EventKey, func(p Primitive))) func(*tcell.EventKey, func(p Primitive)) { return func(event *tcell.EventKey, setFocus func(p Primitive)) { if b.inputCapture != nil { event = b.inputCapture(event) } if event != nil && inputHandler != nil { inputHandler(event, setFocus) } } } // InputHandler returns nil. Box has no default input handling. func (b *Box) InputHandler() func(event *tcell.EventKey, setFocus func(p Primitive)) { return b.WrapInputHandler(nil) } // WrapPasteHandler wraps a paste handler (see [Box.PasteHandler]). func (b *Box) WrapPasteHandler(pasteHandler func(string, func(p Primitive))) func(string, func(p Primitive)) { return func(text string, setFocus func(p Primitive)) { if pasteHandler != nil { pasteHandler(text, setFocus) } } } // PasteHandler returns nil. Box has no default paste handling. func (b *Box) PasteHandler() func(pastedText string, setFocus func(p Primitive)) { return b.WrapPasteHandler(nil) } // SetInputCapture installs a function which captures key events before they are // forwarded to the primitive's default key event handler. This function can // then choose to forward that key event (or a different one) to the default // handler by returning it. If nil is returned, the default handler will not // be called. // // Providing a nil handler will remove a previously existing handler. // // This function can also be used on container primitives (like Flex, Grid, or // Form) as keyboard events will be handed down until they are handled. // // Pasted key events are not forwarded to the input capture function if pasting // is enabled (see [Application.EnablePaste]). func (b *Box) SetInputCapture(capture func(event *tcell.EventKey) *tcell.EventKey) *Box { b.inputCapture = capture return b } // GetInputCapture returns the function installed with SetInputCapture() or nil // if no such function has been installed. func (b *Box) GetInputCapture() func(event *tcell.EventKey) *tcell.EventKey { return b.inputCapture } // WrapMouseHandler wraps a mouse event handler (see [Box.MouseHandler]) with the // functionality to capture mouse events (see [Box.SetMouseCapture]) before passing // them on to the provided (default) event handler. // // This is only meant to be used by subclassing primitives. func (b *Box) WrapMouseHandler(mouseHandler func(MouseAction, *tcell.EventMouse, func(p Primitive)) (bool, Primitive)) func(action MouseAction, event *tcell.EventMouse, setFocus func(p Primitive)) (consumed bool, capture Primitive) { return func(action MouseAction, event *tcell.EventMouse, setFocus func(p Primitive)) (consumed bool, capture Primitive) { if b.mouseCapture != nil { action, event = b.mouseCapture(action, event) } if event == nil { if action == MouseConsumed { consumed = true } } else if mouseHandler != nil { consumed, capture = mouseHandler(action, event, setFocus) } return } } // MouseHandler returns nil. Box has no default mouse handling. func (b *Box) MouseHandler() func(action MouseAction, event *tcell.EventMouse, setFocus func(p Primitive)) (consumed bool, capture Primitive) { return b.WrapMouseHandler(func(action MouseAction, event *tcell.EventMouse, setFocus func(p Primitive)) (consumed bool, capture Primitive) { if action == MouseLeftDown && b.InRect(event.Position()) { setFocus(b) consumed = true } return }) } // SetMouseCapture sets a function which captures mouse events (consisting of // the original tcell mouse event and the semantic mouse action) before they are // forwarded to the primitive's default mouse event handler. This function can // then choose to forward that event (or a different one) by returning it or // returning a nil mouse event, in which case the default handler will not be // called. // // When a nil event is returned, the returned mouse action value may be set to // [MouseConsumed] to indicate that the event was consumed and the screen should // be redrawn. Any other value will not cause a redraw. // // Providing a nil handler will remove a previously existing handler. // // Note that mouse events are ignored completely if the application has not been // enabled for mouse events (see [Application.EnableMouse]), which is the // default. func (b *Box) SetMouseCapture(capture func(action MouseAction, event *tcell.EventMouse) (MouseAction, *tcell.EventMouse)) *Box { b.mouseCapture = capture return b } // InRect returns true if the given coordinate is within the bounds of the box's // rectangle. func (b *Box) InRect(x, y int) bool { rectX, rectY, width, height := b.GetRect() return x >= rectX && x < rectX+width && y >= rectY && y < rectY+height } // InInnerRect returns true if the given coordinate is within the bounds of the // box's inner rectangle (within the border and padding). func (b *Box) InInnerRect(x, y int) bool { rectX, rectY, width, height := b.GetInnerRect() return x >= rectX && x < rectX+width && y >= rectY && y < rectY+height } // GetMouseCapture returns the function installed with SetMouseCapture() or nil // if no such function has been installed. func (b *Box) GetMouseCapture() func(action MouseAction, event *tcell.EventMouse) (MouseAction, *tcell.EventMouse) { return b.mouseCapture } // SetBackgroundColor sets the box's background color. func (b *Box) SetBackgroundColor(color tcell.Color) *Box { b.backgroundColor = color b.borderStyle = b.borderStyle.Background(color) return b } // SetBorder sets the flag indicating whether or not the box should have a // border. func (b *Box) SetBorder(show bool) *Box { b.border, show = show, b.border if b.border != show { if b.contentResize != nil { b.contentResize() } } return b } // SetBorderStyle sets the box's border style. func (b *Box) SetBorderStyle(style tcell.Style) *Box { b.borderStyle = style return b } // SetBorderColor sets the box's border color. func (b *Box) SetBorderColor(color tcell.Color) *Box { b.borderStyle = b.borderStyle.Foreground(color) return b } // SetBorderAttributes sets the border's style attributes. You can combine // different attributes using bitmask operations: // // box.SetBorderAttributes(tcell.AttrItalic | tcell.AttrBold) func (b *Box) SetBorderAttributes(attr tcell.AttrMask) *Box { b.borderStyle = b.borderStyle.Attributes(attr) return b } // GetBorderAttributes returns the border's style attributes. func (b *Box) GetBorderAttributes() tcell.AttrMask { _, _, attr := b.borderStyle.Decompose() return attr } // GetBorderColor returns the box's border color. func (b *Box) GetBorderColor() tcell.Color { color, _, _ := b.borderStyle.Decompose() return color } // GetBackgroundColor returns the box's background color. func (b *Box) GetBackgroundColor() tcell.Color { return b.backgroundColor } // SetTitle sets the box's title. func (b *Box) SetTitle(title string) *Box { b.title = title return b } // GetTitle returns the box's current title. func (b *Box) GetTitle() string { return b.title } // SetTitleColor sets the box's title color. func (b *Box) SetTitleColor(color tcell.Color) *Box { b.titleColor = color return b } // SetTitleAlign sets the alignment of the title, one of AlignLeft, AlignCenter, // or AlignRight. func (b *Box) SetTitleAlign(align int) *Box { b.titleAlign = align return b } // Draw draws this primitive onto the screen. func (b *Box) Draw(screen tcell.Screen) { b.DrawForSubclass(screen, b) } // DrawForSubclass draws this box under the assumption that primitive p is a // subclass of this box. This is needed e.g. to draw proper box frames which // depend on the subclass's focus. // // Only call this function from your own custom primitives. It is not needed in // applications that have no custom primitives. func (b *Box) DrawForSubclass(screen tcell.Screen, p Primitive) { // Don't draw anything if there is no space. if b.width <= 0 || b.height <= 0 { return } // Fill background. background := tcell.StyleDefault.Background(b.backgroundColor) if !b.dontClear { for y := b.y; y < b.y+b.height; y++ { for x := b.x; x < b.x+b.width; x++ { screen.SetContent(x, y, ' ', nil, background) } } } // Draw border. if b.border && b.width >= 2 && b.height >= 2 { var vertical, horizontal, topLeft, topRight, bottomLeft, bottomRight rune if p.HasFocus() { horizontal = Borders.HorizontalFocus vertical = Borders.VerticalFocus topLeft = Borders.TopLeftFocus topRight = Borders.TopRightFocus bottomLeft = Borders.BottomLeftFocus bottomRight = Borders.BottomRightFocus } else { horizontal = Borders.Horizontal vertical = Borders.Vertical topLeft = Borders.TopLeft topRight = Borders.TopRight bottomLeft = Borders.BottomLeft bottomRight = Borders.BottomRight } for x := b.x + 1; x < b.x+b.width-1; x++ { screen.SetContent(x, b.y, horizontal, nil, b.borderStyle) screen.SetContent(x, b.y+b.height-1, horizontal, nil, b.borderStyle) } for y := b.y + 1; y < b.y+b.height-1; y++ { screen.SetContent(b.x, y, vertical, nil, b.borderStyle) screen.SetContent(b.x+b.width-1, y, vertical, nil, b.borderStyle) } screen.SetContent(b.x, b.y, topLeft, nil, b.borderStyle) screen.SetContent(b.x+b.width-1, b.y, topRight, nil, b.borderStyle) screen.SetContent(b.x, b.y+b.height-1, bottomLeft, nil, b.borderStyle) screen.SetContent(b.x+b.width-1, b.y+b.height-1, bottomRight, nil, b.borderStyle) // Draw title. if b.title != "" && b.width >= 4 { printed, _ := Print(screen, b.title, b.x+1, b.y, b.width-2, b.titleAlign, b.titleColor) if len(b.title)-printed > 0 && printed > 0 { xEllipsis := b.x + b.width - 2 if b.titleAlign == AlignRight { xEllipsis = b.x + 1 } _, _, style, _ := screen.GetContent(xEllipsis, b.y) fg, _, _ := style.Decompose() Print(screen, string(SemigraphicsHorizontalEllipsis), xEllipsis, b.y, 1, AlignLeft, fg) } } } // Call custom draw function. if b.draw != nil { b.innerX, b.innerY, b.innerWidth, b.innerHeight = b.draw(screen, b.x, b.y, b.width, b.height) } else { // Remember the inner rect. b.innerX = -1 b.innerX, b.innerY, b.innerWidth, b.innerHeight = b.GetInnerRect() } } // SetFocusFunc sets a callback function which is invoked when this primitive // receives focus. Container primitives such as [Flex] or [Grid] will also be // notified if one of their descendents receive focus directly. Note that this // may result in a blur notification, immediately followed by a focus // notification, when the focus is set to a different descendent of the // container primitive. // // At this point, the order in which the focus callbacks are invoked during one // draw cycle, is not defined. However, the blur callbacks are always invoked // before the focus callbacks. // // Set to nil to remove the callback function. func (b *Box) SetFocusFunc(callback func()) *Box { b.focus = callback return b } // SetBlurFunc sets a callback function which is invoked when this primitive // loses focus. Container primitives such as [Flex] or [Grid] will also be // notified if one of their descendents lose focus. Note that this may result in // a blur notification, immediately followed by a focus notification, when the // focus is set to a different different descendent of the container primitive. // // At this point, the order in which the blur callbacks are invoked during one // draw cycle, is not defined. However, the blur callbacks are always invoked // before the focus callbacks. // // Set to nil to remove the callback function. func (b *Box) SetBlurFunc(callback func()) *Box { b.blur = callback return b } // Focus is called when this primitive directly receives focus. func (b *Box) Focus(delegate func(p Primitive)) { b.hasFocus = true } // focused is called when this primitive or one of its descendents receives // focus. func (b *Box) focused() { if b.focus != nil { b.focus() } } // Blur is called when this primitive directly loses focus. func (b *Box) Blur() { b.hasFocus = false } // blurred is called when this primitive or one of its descendents loses focus. func (b *Box) blurred() { if b.blur != nil { b.blur() } } // HasFocus returns whether or not this primitive has focus. func (b *Box) HasFocus() bool { return b.Primitive.focusChain(nil) } // focusChain implements the [Primitive]'s focusChain method. func (b *Box) focusChain(chain *[]Primitive) bool { if !b.hasFocus { return false } if chain != nil { *chain = append(*chain, b.Primitive) } return true } ================================================ FILE: button.go ================================================ package tview import ( "github.com/gdamore/tcell/v2" ) // Button is labeled box that triggers an action when selected. // // See https://github.com/rivo/tview/wiki/Button for an example. type Button struct { *Box // If set to true, the button cannot be activated. disabled bool // The text to be displayed inside the button. text string // The button's style (when deactivated). style tcell.Style // The button's style (when activated). activatedStyle tcell.Style // The button's style (when disabled). disabledStyle tcell.Style // An optional function which is called when the button was selected. selected func() // An optional function which is called when the user leaves the button. A // key is provided indicating which key was pressed to leave (tab or // backtab). exit func(tcell.Key) } // NewButton returns a new [Button]. func NewButton(label string) *Button { box := NewBox() box.SetRect(0, 0, TaggedStringWidth(label)+4, 1) b := &Button{ Box: box, text: label, style: tcell.StyleDefault.Background(Styles.ContrastBackgroundColor).Foreground(Styles.PrimaryTextColor), activatedStyle: tcell.StyleDefault.Background(Styles.PrimaryTextColor).Foreground(Styles.InverseTextColor), disabledStyle: tcell.StyleDefault.Background(Styles.ContrastBackgroundColor).Foreground(Styles.ContrastSecondaryTextColor), } b.Box.Primitive = b return b } // SetLabel sets the button text. func (b *Button) SetLabel(label string) *Button { b.text = label return b } // GetLabel returns the button text. func (b *Button) GetLabel() string { return b.text } // SetLabelColor sets the color of the button text. func (b *Button) SetLabelColor(color tcell.Color) *Button { b.style = b.style.Foreground(color) return b } // SetStyle sets the style of the button used when it is not focused. func (b *Button) SetStyle(style tcell.Style) *Button { b.style = style return b } // SetLabelColorActivated sets the color of the button text when the button is // in focus. func (b *Button) SetLabelColorActivated(color tcell.Color) *Button { b.activatedStyle = b.activatedStyle.Foreground(color) return b } // SetBackgroundColorActivated sets the background color of the button text when // the button is in focus. func (b *Button) SetBackgroundColorActivated(color tcell.Color) *Button { b.activatedStyle = b.activatedStyle.Background(color) return b } // SetActivatedStyle sets the style of the button used when it is focused. func (b *Button) SetActivatedStyle(style tcell.Style) *Button { b.activatedStyle = style return b } // SetDisabledStyle sets the style of the button used when it is disabled. func (b *Button) SetDisabledStyle(style tcell.Style) *Button { b.disabledStyle = style return b } // SetDisabled sets whether or not the button is disabled. Disabled buttons // cannot be activated. // // If the button is part of a form, you should set focus to the form itself // after calling this function to set focus to the next non-disabled form item. func (b *Button) SetDisabled(disabled bool) *Button { b.disabled = disabled return b } // GetDisabled returns whether or not the button is disabled. func (b *Button) GetDisabled() bool { return b.disabled } // IsDisabled is an alias for [Button.GetDisabled]. Only here for backwards // compatibility. func (b *Button) IsDisabled() bool { return b.GetDisabled() } // SetSelectedFunc sets a handler which is called when the button was selected. func (b *Button) SetSelectedFunc(handler func()) *Button { b.selected = handler return b } // SetExitFunc sets a handler which is called when the user leaves the button. // The callback function is provided with the key that was pressed, which is one // of the following: // // - KeyEscape: Leaving the button with no specific direction. // - KeyTab: Move to the next field. // - KeyBacktab: Move to the previous field. func (b *Button) SetExitFunc(handler func(key tcell.Key)) *Button { b.exit = handler return b } // Draw draws this primitive onto the screen. func (b *Button) Draw(screen tcell.Screen) { // Draw the box. style := b.style if b.disabled { style = b.disabledStyle } if b.HasFocus() && !b.disabled { style = b.activatedStyle } _, backgroundColor, _ := style.Decompose() b.SetBackgroundColor(backgroundColor) b.Box.DrawForSubclass(screen, b) // Draw label. x, y, width, height := b.GetInnerRect() if width > 0 && height > 0 { y = y + height/2 printWithStyle(screen, b.text, x, y, 0, width, AlignCenter, style, true) } } // InputHandler returns the handler for this primitive. func (b *Button) InputHandler() func(event *tcell.EventKey, setFocus func(p Primitive)) { return b.WrapInputHandler(func(event *tcell.EventKey, setFocus func(p Primitive)) { if b.disabled { return } // Process key event. switch key := event.Key(); key { case tcell.KeyEnter: // Selected. if b.selected != nil { b.selected() } case tcell.KeyBacktab, tcell.KeyTab, tcell.KeyEscape: // Leave. No action. if b.exit != nil { b.exit(key) } } }) } // MouseHandler returns the mouse handler for this primitive. func (b *Button) MouseHandler() func(action MouseAction, event *tcell.EventMouse, setFocus func(p Primitive)) (consumed bool, capture Primitive) { return b.WrapMouseHandler(func(action MouseAction, event *tcell.EventMouse, setFocus func(p Primitive)) (consumed bool, capture Primitive) { if b.disabled { return false, nil } if !b.InRect(event.Position()) { return false, nil } // Process mouse event. if action == MouseLeftDown { setFocus(b) consumed = true } else if action == MouseLeftClick { if b.selected != nil { b.selected() } consumed = true } return }) } ================================================ FILE: checkbox.go ================================================ package tview import ( "github.com/gdamore/tcell/v2" ) // Checkbox implements a simple box for boolean values which can be checked and // unchecked. // // See https://github.com/rivo/tview/wiki/Checkbox for an example. type Checkbox struct { *Box // Whether or not this checkbox is disabled/read-only. disabled bool // Whether or not this box is checked. checked bool // The text to be displayed before the input area. label string // The screen width of the label area. A value of 0 means use the width of // the label text. labelWidth int // The label style. labelStyle tcell.Style // The style of the unchecked checkbox. uncheckedStyle tcell.Style // The style of the checked checkbox. checkedStyle tcell.Style // The style of the checkbox when it is currently focused. focusStyle tcell.Style // The string used to display an unchecked box. uncheckedString string // The string used to display a checked box. checkedString string // An optional function which is called when the user changes the checked // state of this checkbox. changed func(checked bool) // An optional function which is called when the user indicated that they // are done entering text. The key which was pressed is provided (tab, // shift-tab, or escape). done func(tcell.Key) // A callback function set by the Form class and called when the user leaves // this form item. finished func(tcell.Key) } // NewCheckbox returns a new [Checkbox]. func NewCheckbox() *Checkbox { c := &Checkbox{ Box: NewBox(), labelStyle: tcell.StyleDefault.Foreground(Styles.SecondaryTextColor), uncheckedStyle: tcell.StyleDefault.Background(Styles.ContrastBackgroundColor).Foreground(Styles.PrimaryTextColor), checkedStyle: tcell.StyleDefault.Background(Styles.ContrastBackgroundColor).Foreground(Styles.PrimaryTextColor), focusStyle: tcell.StyleDefault.Background(Styles.PrimaryTextColor).Foreground(Styles.ContrastBackgroundColor), uncheckedString: " ", checkedString: "X", } c.Box.Primitive = c return c } // SetChecked sets the state of the checkbox. This also triggers the "changed" // callback if the state changes with this call. func (c *Checkbox) SetChecked(checked bool) *Checkbox { if c.checked != checked { if c.changed != nil { c.changed(checked) } c.checked = checked } return c } // IsChecked returns whether or not the box is checked. func (c *Checkbox) IsChecked() bool { return c.checked } // SetLabel sets the text to be displayed before the input area. func (c *Checkbox) SetLabel(label string) *Checkbox { c.label = label return c } // GetLabel returns the text to be displayed before the input area. func (c *Checkbox) GetLabel() string { return c.label } // SetLabelWidth sets the screen width of the label. A value of 0 will cause the // primitive to use the width of the label string. func (c *Checkbox) SetLabelWidth(width int) *Checkbox { c.labelWidth = width return c } // SetLabelColor sets the color of the label. func (c *Checkbox) SetLabelColor(color tcell.Color) *Checkbox { c.labelStyle = c.labelStyle.Foreground(color) return c } // SetLabelStyle sets the style of the label. func (c *Checkbox) SetLabelStyle(style tcell.Style) *Checkbox { c.labelStyle = style return c } // SetFieldBackgroundColor sets the background color of the input area. func (c *Checkbox) SetFieldBackgroundColor(color tcell.Color) *Checkbox { c.uncheckedStyle = c.uncheckedStyle.Background(color) c.checkedStyle = c.checkedStyle.Background(color) c.focusStyle = c.focusStyle.Foreground(color) return c } // SetFieldTextColor sets the text color of the input area. func (c *Checkbox) SetFieldTextColor(color tcell.Color) *Checkbox { c.uncheckedStyle = c.uncheckedStyle.Foreground(color) c.checkedStyle = c.checkedStyle.Foreground(color) c.focusStyle = c.focusStyle.Background(color) return c } // SetUncheckedStyle sets the style of the unchecked checkbox. func (c *Checkbox) SetUncheckedStyle(style tcell.Style) *Checkbox { c.uncheckedStyle = style return c } // SetCheckedStyle sets the style of the checked checkbox. func (c *Checkbox) SetCheckedStyle(style tcell.Style) *Checkbox { c.checkedStyle = style return c } // SetActivatedStyle sets the style of the checkbox when it is currently // focused. func (c *Checkbox) SetActivatedStyle(style tcell.Style) *Checkbox { c.focusStyle = style return c } // SetCheckedString sets the string to be displayed when the checkbox is // checked (defaults to "X"). The string may contain color tags (consider // adapting the checkbox's various styles accordingly). See [Escape] in // case you want to display square brackets. func (c *Checkbox) SetCheckedString(checked string) *Checkbox { c.checkedString = checked return c } // SetUncheckedString sets the string to be displayed when the checkbox is // not checked (defaults to the empty space " "). The string may contain color // tags (consider adapting the checkbox's various styles accordingly). See // [Escape] in case you want to display square brackets. func (c *Checkbox) SetUncheckedString(unchecked string) *Checkbox { c.uncheckedString = unchecked return c } // SetFormAttributes sets attributes shared by all form items. func (c *Checkbox) SetFormAttributes(labelWidth int, labelColor, bgColor, fieldTextColor, fieldBgColor tcell.Color) FormItem { c.labelWidth = labelWidth c.SetLabelColor(labelColor) c.backgroundColor = bgColor c.SetFieldTextColor(fieldTextColor) c.SetFieldBackgroundColor(fieldBgColor) return c } // GetFieldWidth returns this primitive's field width. func (c *Checkbox) GetFieldWidth() int { return 1 } // GetFieldHeight returns this primitive's field height. func (c *Checkbox) GetFieldHeight() int { return 1 } // SetDisabled sets whether or not the item is disabled / read-only. func (c *Checkbox) SetDisabled(disabled bool) FormItem { c.disabled = disabled if c.finished != nil { c.finished(-1) } return c } // GetDisabled returns whether or not the item is disabled / read-only. func (c *Checkbox) GetDisabled() bool { return c.disabled } // SetChangedFunc sets a handler which is called when the checked state of this // checkbox was changed. The handler function receives the new state. func (c *Checkbox) SetChangedFunc(handler func(checked bool)) *Checkbox { c.changed = handler return c } // SetDoneFunc sets a handler which is called when the user is done using the // checkbox. The callback function is provided with the key that was pressed, // which is one of the following: // // - KeyEscape: Abort text input. // - KeyTab: Move to the next field. // - KeyBacktab: Move to the previous field. func (c *Checkbox) SetDoneFunc(handler func(key tcell.Key)) *Checkbox { c.done = handler return c } // SetFinishedFunc sets a callback invoked when the user leaves this form item. func (c *Checkbox) SetFinishedFunc(handler func(key tcell.Key)) FormItem { c.finished = handler return c } // Focus is called when this primitive receives focus. func (c *Checkbox) Focus(delegate func(p Primitive)) { // If we're part of a form and this item is disabled, there's nothing the // user can do here so we're finished. if c.finished != nil && c.disabled { c.finished(-1) return } c.Box.Focus(delegate) } // Draw draws this primitive onto the screen. func (c *Checkbox) Draw(screen tcell.Screen) { c.Box.DrawForSubclass(screen, c) // Prepare x, y, width, height := c.GetInnerRect() rightLimit := x + width if height < 1 || rightLimit <= x { return } // Draw label. _, labelBg, _ := c.labelStyle.Decompose() if c.labelWidth > 0 { labelWidth := c.labelWidth if labelWidth > width { labelWidth = width } printWithStyle(screen, c.label, x, y, 0, labelWidth, AlignLeft, c.labelStyle, labelBg == tcell.ColorDefault) x += labelWidth width -= labelWidth } else { _, _, drawnWidth := printWithStyle(screen, c.label, x, y, 0, width, AlignLeft, c.labelStyle, labelBg == tcell.ColorDefault) x += drawnWidth width -= drawnWidth } // Draw checkbox. str := c.uncheckedString style := c.uncheckedStyle if c.checked { str = c.checkedString style = c.checkedStyle } if c.disabled { style = style.Background(c.backgroundColor) } if c.HasFocus() { style = c.focusStyle } printWithStyle(screen, str, x, y, 0, width, AlignLeft, style, c.disabled) } // InputHandler returns the handler for this primitive. func (c *Checkbox) InputHandler() func(event *tcell.EventKey, setFocus func(p Primitive)) { return c.WrapInputHandler(func(event *tcell.EventKey, setFocus func(p Primitive)) { if c.disabled { return } // Process key event. switch key := event.Key(); key { case tcell.KeyRune, tcell.KeyEnter: // Check. if key == tcell.KeyRune && event.Rune() != ' ' { break } c.checked = !c.checked if c.changed != nil { c.changed(c.checked) } case tcell.KeyTab, tcell.KeyBacktab, tcell.KeyEscape: // We're done. if c.done != nil { c.done(key) } if c.finished != nil { c.finished(key) } } }) } // MouseHandler returns the mouse handler for this primitive. func (c *Checkbox) MouseHandler() func(action MouseAction, event *tcell.EventMouse, setFocus func(p Primitive)) (consumed bool, capture Primitive) { return c.WrapMouseHandler(func(action MouseAction, event *tcell.EventMouse, setFocus func(p Primitive)) (consumed bool, capture Primitive) { if c.disabled { return false, nil } x, y := event.Position() _, rectY, _, _ := c.GetInnerRect() if !c.InRect(x, y) { return false, nil } // Process mouse event. if y == rectY { if action == MouseLeftDown { setFocus(c) consumed = true } else if action == MouseLeftClick { c.checked = !c.checked if c.changed != nil { c.changed(c.checked) } consumed = true } } return }) } ================================================ FILE: demos/box/README.md ================================================ ![Screenshot](screenshot.png) ================================================ FILE: demos/box/main.go ================================================ // Demo code for the Box primitive. package main import ( "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) func main() { box := tview.NewBox(). SetBorder(true). SetBorderAttributes(tcell.AttrBold). SetTitle("A [red]c[yellow]o[green]l[darkcyan]o[blue]r[darkmagenta]f[red]u[yellow]l[white] [black:red]c[:yellow]o[:green]l[:darkcyan]o[:blue]r[:darkmagenta]f[:red]u[:yellow]l[white:-] [::bu]title") if err := tview.NewApplication().SetRoot(box, true).Run(); err != nil { panic(err) } } ================================================ FILE: demos/button/README.md ================================================ ![Screenshot](screenshot.png) ================================================ FILE: demos/button/main.go ================================================ // Demo code for the Button primitive. package main import "github.com/rivo/tview" func main() { app := tview.NewApplication() button := tview.NewButton("Hit Enter to close").SetSelectedFunc(func() { app.Stop() }) button.SetBorder(true).SetRect(0, 0, 22, 3) if err := app.SetRoot(button, false).EnableMouse(true).Run(); err != nil { panic(err) } } ================================================ FILE: demos/checkbox/README.md ================================================ ![Screenshot](screenshot.png) ================================================ FILE: demos/checkbox/main.go ================================================ // Demo code for the Checkbox primitive. package main import "github.com/rivo/tview" func main() { app := tview.NewApplication() checkbox := tview.NewCheckbox().SetLabel("Hit Enter to check box: ") if err := app.SetRoot(checkbox, true).EnableMouse(true).Run(); err != nil { panic(err) } } ================================================ FILE: demos/dropdown/README.md ================================================ ![Screenshot](screenshot.png) ================================================ FILE: demos/dropdown/main.go ================================================ // Demo code for the DropDown primitive. package main import "github.com/rivo/tview" func main() { app := tview.NewApplication() dropdown := tview.NewDropDown(). SetLabel("Select an option (hit Enter): "). SetOptions([]string{"First", "Second", "Third", "Fourth", "Fifth"}, nil) if err := app.SetRoot(dropdown, true).EnableMouse(true).Run(); err != nil { panic(err) } } ================================================ FILE: demos/flex/README.md ================================================ ![Screenshot](screenshot.png) ================================================ FILE: demos/flex/main.go ================================================ // Demo code for the Flex primitive. package main import ( "github.com/rivo/tview" ) func main() { app := tview.NewApplication() flex := tview.NewFlex(). AddItem(tview.NewBox().SetBorder(true).SetTitle("Left (1/2 x width of Top)"), 0, 1, false). AddItem(tview.NewFlex().SetDirection(tview.FlexRow). AddItem(tview.NewBox().SetBorder(true).SetTitle("Top"), 0, 1, false). AddItem(tview.NewBox().SetBorder(true).SetTitle("Middle (3 x height of Top)"), 0, 3, false). AddItem(tview.NewBox().SetBorder(true).SetTitle("Bottom (5 rows)"), 5, 1, false), 0, 2, false). AddItem(tview.NewBox().SetBorder(true).SetTitle("Right (20 cols)"), 20, 1, false) if err := app.SetRoot(flex, true).EnableMouse(true).Run(); err != nil { panic(err) } } ================================================ FILE: demos/form/README.md ================================================ ![Screenshot](screenshot.png) ================================================ FILE: demos/form/main.go ================================================ // Demo code for the Form primitive. package main import ( "github.com/rivo/tview" ) func main() { app := tview.NewApplication() form := tview.NewForm(). AddDropDown("Title", []string{"Mr.", "Ms.", "Mrs.", "Dr.", "Prof."}, 0, nil). AddInputField("First name", "", 20, nil, nil). AddInputField("Last name", "", 20, nil, nil). AddTextArea("Address", "", 40, 0, 0, nil). AddTextView("Notes", "This is just a demo.\nYou can enter whatever you wish.", 40, 2, true, false). AddCheckbox("Age 18+", false, nil). AddPasswordField("Password", "", 10, '*', nil). AddButton("Save", nil). AddButton("Quit", func() { app.Stop() }) form.SetBorder(true).SetTitle("Enter some data").SetTitleAlign(tview.AlignLeft) if err := app.SetRoot(form, true).EnableMouse(true).EnablePaste(true).Run(); err != nil { panic(err) } } ================================================ FILE: demos/frame/README.md ================================================ ![Screenshot](screenshot.png) ================================================ FILE: demos/frame/main.go ================================================ // Demo code for the Frame primitive. package main import ( "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) func main() { app := tview.NewApplication() frame := tview.NewFrame(tview.NewBox().SetBackgroundColor(tcell.ColorBlue)). SetBorders(2, 2, 2, 2, 4, 4). AddText("Header left", true, tview.AlignLeft, tcell.ColorWhite). AddText("Header middle", true, tview.AlignCenter, tcell.ColorWhite). AddText("Header right", true, tview.AlignRight, tcell.ColorWhite). AddText("Header second middle", true, tview.AlignCenter, tcell.ColorRed). AddText("Footer middle", false, tview.AlignCenter, tcell.ColorGreen). AddText("Footer second middle", false, tview.AlignCenter, tcell.ColorGreen) if err := app.SetRoot(frame, true).EnableMouse(true).Run(); err != nil { panic(err) } } ================================================ FILE: demos/grid/README.md ================================================ ![Screenshot](screenshot.png) ================================================ FILE: demos/grid/main.go ================================================ // Demo code for the Grid primitive. package main import ( "github.com/rivo/tview" ) func main() { newPrimitive := func(text string) tview.Primitive { return tview.NewTextView(). SetTextAlign(tview.AlignCenter). SetText(text) } menu := newPrimitive("Menu") main := newPrimitive("Main content") sideBar := newPrimitive("Side Bar") grid := tview.NewGrid(). SetRows(3, 0, 3). SetColumns(30, 0, 30). SetBorders(true). AddItem(newPrimitive("Header"), 0, 0, 1, 3, 0, 0, false). AddItem(newPrimitive("Footer"), 2, 0, 1, 3, 0, 0, false) // Layout for screens narrower than 100 cells (menu and side bar are hidden). grid.AddItem(menu, 0, 0, 0, 0, 0, 0, false). AddItem(main, 1, 0, 1, 3, 0, 0, false). AddItem(sideBar, 0, 0, 0, 0, 0, 0, false) // Layout for screens wider than 100 cells. grid.AddItem(menu, 1, 0, 1, 1, 0, 100, false). AddItem(main, 1, 1, 1, 1, 0, 100, false). AddItem(sideBar, 1, 2, 1, 1, 0, 100, false) if err := tview.NewApplication().SetRoot(grid, true).EnableMouse(true).Run(); err != nil { panic(err) } } ================================================ FILE: demos/image/README.md ================================================ ![Screenshot](screenshot.jpg) ================================================ FILE: demos/image/main.go ================================================ // Demo code for the Image primitive. package main import ( "bytes" "encoding/base64" "image/jpeg" "image/png" "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) const ( beach = `/9j/4AAQSkZJRgABAQAASABIAAD/4QCMRXhpZgAATU0AKgAAAAgABgEGAAMAAAABAAIAAAESAAMAAAABAAEAAAEaAAUAAAABAAAAVgEbAAUAAAABAAAAXgEoAAMAAAABAAIAAIdpAAQAAAABAAAAZgAAAAAAAABIAAAAAQAAAEgAAAABAAKgAgAEAAAAAQAAAUCgAwAEAAAAAQAAAPAAAAAA/+EJIWh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8APD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNi4wLjAiPiA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPiA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIi8+IDwvcmRmOlJERj4gPC94OnhtcG1ldGE+ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgPD94cGFja2V0IGVuZD0idyI/PgD/7QA4UGhvdG9zaG9wIDMuMAA4QklNBAQAAAAAAAA4Q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6W3efxZ/+dkdFIFf8QuNGAt0gVUSBJ/kLAtU14KdfBkxUelhWD81w+HOc5HWpRd1ICAqE8SB+AVh0kP0YoMwZyyjGC2Nc8f7s6m0CBSBX4LAcDrGwS958D5mESgCRaAIvAyBP1piW6LKUEKJAAAAAElFTkSuQmCC` ) func main() { app := tview.NewApplication() image := tview.NewImage() b, _ := base64.StdEncoding.DecodeString(beach) photo, _ := jpeg.Decode(bytes.NewReader(b)) b, _ = base64.StdEncoding.DecodeString(chart) graphics, _ := png.Decode(bytes.NewReader(b)) image.SetImage(photo) imgType := tview.NewList(). ShowSecondaryText(false). AddItem("Photo", "", 0, func() { image.SetImage(photo) }). AddItem("Graphics", "", 0, func() { image.SetImage(graphics) }) imgType.SetTitle("Image Type").SetBorder(true) colors := tview.NewList(). ShowSecondaryText(false). AddItem("2 colors", "", 0, func() { image.SetColors(2) }). AddItem("8 colors", "", 0, func() { image.SetColors(8) }). AddItem("256 colors", "", 0, func() { image.SetColors(256) }). AddItem("True-color", "", 0, func() { image.SetColors(tview.TrueColor) }) colors.SetTitle("Colors").SetBorder(true) for i, c := range []int{2, 8, 256, tview.TrueColor} { if c == image.GetColors() { colors.SetCurrentItem(i) break } } dithering := tview.NewList(). ShowSecondaryText(false). AddItem("None", "", 0, func() { image.SetDithering(tview.DitheringNone) }). AddItem("Floyd-Steinberg", "", 0, func() { image.SetDithering(tview.DitheringFloydSteinberg) }). SetCurrentItem(1) dithering.SetTitle("Dithering").SetBorder(true) selections := []*tview.Box{imgType.Box, colors.Box, dithering.Box} for i, box := range selections { (func(index int) { box.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { switch event.Key() { case tcell.KeyTab: app.SetFocus(selections[(index+1)%len(selections)]) return nil case tcell.KeyBacktab: app.SetFocus(selections[(index+len(selections)-1)%len(selections)]) return nil } return event }) })(i) } grid := tview.NewGrid(). SetBorders(false). SetColumns(18, -1). SetRows(4, 6, 4, -1). AddItem(imgType, 0, 0, 1, 1, 0, 0, true). AddItem(colors, 1, 0, 1, 1, 0, 0, false). AddItem(dithering, 2, 0, 1, 1, 0, 0, false). AddItem(image, 0, 1, 4, 1, 0, 0, false) if err := app.SetRoot(grid, true).EnableMouse(true).Run(); err != nil { panic(err) } } ================================================ FILE: demos/inputfield/README.md ================================================ ![Screenshot](screenshot.png) ================================================ FILE: demos/inputfield/autocomplete/main.go ================================================ package main import ( "strings" "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) // 1,000 most common English words. const wordList = "ability,able,about,above,accept,according,account,across,act,action,activity,actually,add,address,administration,admit,adult,affect,after,again,against,age,agency,agent,ago,agree,agreement,ahead,air,all,allow,almost,alone,along,already,also,although,always,American,among,amount,analysis,and,animal,another,answer,any,anyone,anything,appear,apply,approach,area,argue,arm,around,arrive,art,article,artist,as,ask,assume,at,attack,attention,attorney,audience,author,authority,available,avoid,away,baby,back,bad,bag,ball,bank,bar,base,be,beat,beautiful,because,become,bed,before,begin,behavior,behind,believe,benefit,best,better,between,beyond,big,bill,billion,bit,black,blood,blue,board,body,book,born,both,box,boy,break,bring,brother,budget,build,building,business,but,buy,by,call,camera,campaign,can,cancer,candidate,capital,car,card,care,career,carry,case,catch,cause,cell,center,central,century,certain,certainly,chair,challenge,chance,change,character,charge,check,child,choice,choose,church,citizen,city,civil,claim,class,clear,clearly,close,coach,cold,collection,college,color,come,commercial,common,community,company,compare,computer,concern,condition,conference,Congress,consider,consumer,contain,continue,control,cost,could,country,couple,course,court,cover,create,crime,cultural,culture,cup,current,customer,cut,dark,data,daughter,day,dead,deal,death,debate,decade,decide,decision,deep,defense,degree,Democrat,democratic,describe,design,despite,detail,determine,develop,development,die,difference,different,difficult,dinner,direction,director,discover,discuss,discussion,disease,do,doctor,dog,door,down,draw,dream,drive,drop,drug,during,each,early,east,easy,eat,economic,economy,edge,education,effect,effort,eight,either,election,else,employee,end,energy,enjoy,enough,enter,entire,environment,environmental,especially,establish,even,evening,event,ever,every,everybody,everyone,everything,evidence,exactly,example,executive,exist,expect,experience,expert,explain,eye,face,fact,factor,fail,fall,family,far,fast,father,fear,federal,feel,feeling,few,field,fight,figure,fill,film,final,finally,financial,find,fine,finger,finish,fire,firm,first,fish,five,floor,fly,focus,follow,food,foot,for,force,foreign,forget,form,former,forward,four,free,friend,from,front,full,fund,future,game,garden,gas,general,generation,get,girl,give,glass,go,goal,good,government,great,green,ground,group,grow,growth,guess,gun,guy,hair,half,hand,hang,happen,happy,hard,have,he,head,health,hear,heart,heat,heavy,help,her,here,herself,high,him,himself,his,history,hit,hold,home,hope,hospital,hot,hotel,hour,house,how,however,huge,human,hundred,husband,idea,identify,if,image,imagine,impact,important,improve,in,include,including,increase,indeed,indicate,individual,industry,information,inside,instead,institution,interest,interesting,international,interview,into,investment,involve,issue,it,item,its,itself,job,join,just,keep,key,kid,kill,kind,kitchen,know,knowledge,land,language,large,last,late,later,laugh,law,lawyer,lay,lead,leader,learn,least,leave,left,leg,legal,less,let,letter,level,lie,life,light,like,likely,line,list,listen,little,live,local,long,look,lose,loss,lot,love,low,machine,magazine,main,maintain,major,majority,make,man,manage,management,manager,many,market,marriage,material,matter,may,maybe,me,mean,measure,media,medical,meet,meeting,member,memory,mention,message,method,middle,might,military,million,mind,minute,miss,mission,model,modern,moment,money,month,more,morning,most,mother,mouth,move,movement,movie,Mr,Mrs,much,music,must,my,myself,n't,name,nation,national,natural,nature,near,nearly,necessary,need,network,never,new,news,newspaper,next,nice,night,no,none,nor,north,not,note,nothing,notice,now,number,occur,of,off,offer,office,officer,official,often,oh,oil,ok,old,on,once,one,only,onto,open,operation,opportunity,option,or,order,organization,other,others,our,out,outside,over,own,owner,page,pain,painting,paper,parent,part,participant,particular,particularly,partner,party,pass,past,patient,pattern,pay,peace,people,per,perform,performance,perhaps,period,person,personal,phone,physical,pick,picture,piece,place,plan,plant,play,player,PM,point,police,policy,political,politics,poor,popular,population,position,positive,possible,power,practice,prepare,present,president,pressure,pretty,prevent,price,private,probably,problem,process,produce,product,production,professional,professor,program,project,property,protect,prove,provide,public,pull,purpose,push,put,quality,question,quickly,quite,race,radio,raise,range,rate,rather,reach,read,ready,real,reality,realize,really,reason,receive,recent,recently,recognize,record,red,reduce,reflect,region,relate,relationship,religious,remain,remember,remove,report,represent,Republican,require,research,resource,respond,response,responsibility,rest,result,return,reveal,rich,right,rise,risk,road,rock,role,room,rule,run,safe,same,save,say,scene,school,science,scientist,score,sea,season,seat,second,section,security,see,seek,seem,sell,send,senior,sense,series,serious,serve,service,set,seven,several,sex,sexual,shake,share,she,shoot,short,shot,should,shoulder,show,side,sign,significant,similar,simple,simply,since,sing,single,sister,sit,site,situation,six,size,skill,skin,small,smile,so,social,society,soldier,some,somebody,someone,something,sometimes,son,song,soon,sort,sound,source,south,southern,space,speak,special,specific,speech,spend,sport,spring,staff,stage,stand,standard,star,start,state,statement,station,stay,step,still,stock,stop,store,story,strategy,street,strong,structure,student,study,stuff,style,subject,success,successful,such,suddenly,suffer,suggest,summer,support,sure,surface,system,table,take,talk,task,tax,teach,teacher,team,technology,television,tell,ten,tend,term,test,than,thank,that,the,their,them,themselves,then,theory,there,these,they,thing,think,third,this,those,though,thought,thousand,threat,three,through,throughout,throw,thus,time,to,today,together,tonight,too,top,total,tough,toward,town,trade,traditional,training,travel,treat,treatment,tree,trial,trip,trouble,true,truth,try,turn,TV,two,type,under,understand,unit,until,up,upon,us,use,usually,value,various,very,victim,view,violence,visit,voice,vote,wait,walk,wall,want,war,watch,water,way,we,weapon,wear,week,weight,well,west,western,what,whatever,when,where,whether,which,while,white,who,whole,whom,whose,why,wide,wife,will,win,wind,window,wish,with,within,without,woman,wonder,word,work,worker,world,worry,would,write,writer,wrong,yard,yeah,year,yes,yet,you,young,your,yourself" func main() { words := strings.Split(wordList, ",") app := tview.NewApplication() inputField := tview.NewInputField(). SetLabel("Enter a word: "). SetFieldWidth(30). SetDoneFunc(func(key tcell.Key) { app.Stop() }) inputField.SetAutocompleteFunc(func(currentText string) (entries []string) { if len(currentText) == 0 { return } for _, word := range words { if strings.HasPrefix(strings.ToLower(word), strings.ToLower(currentText)) { entries = append(entries, word) } } if len(entries) <= 1 { entries = nil } return }) inputField.SetAutocompletedFunc(func(text string, index, source int) bool { if source != tview.AutocompletedNavigate { inputField.SetText(text) } return source == tview.AutocompletedEnter || source == tview.AutocompletedClick }) if err := app.EnableMouse(true).SetRoot(inputField, true).Run(); err != nil { panic(err) } } ================================================ FILE: demos/inputfield/autocompleteasync/main.go ================================================ package main import ( "encoding/json" "net/http" "net/url" "strings" "sync" "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) type company struct { Name string `json:"name"` } func main() { app := tview.NewApplication() inputField := tview.NewInputField(). SetLabel("Enter a company name: "). SetFieldWidth(30). SetDoneFunc(func(key tcell.Key) { app.Stop() }) // Set up autocomplete function. var mutex sync.Mutex prefixMap := make(map[string][]string) inputField.SetAutocompleteFunc(func(currentText string) []string { // Ignore empty text. prefix := strings.TrimSpace(strings.ToLower(currentText)) if prefix == "" { return nil } // Do we have entries for this text already? mutex.Lock() defer mutex.Unlock() entries, ok := prefixMap[prefix] if ok { return entries } // No entries yet. Issue a request to the API in a goroutine. go func() { // Ignore errors in this demo. url := "https://autocomplete.clearbit.com/v1/companies/suggest?query=" + url.QueryEscape(prefix) res, err := http.Get(url) if err != nil { return } // Store the result in the prefix map. var companies []*company dec := json.NewDecoder(res.Body) if err := dec.Decode(&companies); err != nil { return } entries := make([]string, 0, len(companies)) OuterLoop: for _, c := range companies { for _, entry := range entries { // Eliminate duplicates. if strings.EqualFold(entry, c.Name) { continue OuterLoop } } entries = append(entries, c.Name) } mutex.Lock() prefixMap[prefix] = entries mutex.Unlock() // Trigger an update to the input field. inputField.Autocomplete() // Also redraw the screen. app.Draw() }() return nil }) if err := app.EnableMouse(true).SetRoot(inputField, true).Run(); err != nil { panic(err) } } ================================================ FILE: demos/inputfield/main.go ================================================ // Demo code for the InputField primitive. package main import ( "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) func main() { app := tview.NewApplication() inputField := tview.NewInputField(). SetLabel("Enter a number: "). SetPlaceholder("E.g. 1234"). SetFieldWidth(10). SetAcceptanceFunc(tview.InputFieldInteger). SetDoneFunc(func(key tcell.Key) { app.Stop() }) if err := app.SetRoot(inputField, true).EnableMouse(true).EnablePaste(true).Run(); err != nil { panic(err) } } ================================================ FILE: demos/list/README.md ================================================ ![Screenshot](screenshot.png) ================================================ FILE: demos/list/main.go ================================================ // Demo code for the List primitive. package main import ( "github.com/rivo/tview" ) func main() { app := tview.NewApplication() list := tview.NewList(). AddItem("List item 1", "Some explanatory text", 'a', nil). AddItem("List item 2", "Some explanatory text", 'b', nil). AddItem("List item 3", "Some explanatory text", 'c', nil). AddItem("List item 4", "Some explanatory text", 'd', nil). AddItem("Quit", "Press to exit", 'q', func() { app.Stop() }) if err := app.SetRoot(list, true).EnableMouse(true).Run(); err != nil { panic(err) } } ================================================ FILE: demos/modal/README.md ================================================ ![Screenshot](screenshot.png) ================================================ FILE: demos/modal/main.go ================================================ // Demo code for the Modal primitive. package main import ( "github.com/rivo/tview" ) func main() { app := tview.NewApplication() modal := tview.NewModal(). SetText("Do you want to quit the application?"). AddButtons([]string{"Quit", "Cancel"}). SetDoneFunc(func(buttonIndex int, buttonLabel string) { if buttonLabel == "Quit" { app.Stop() } }) if err := app.SetRoot(modal, false).EnableMouse(true).Run(); err != nil { panic(err) } } ================================================ FILE: demos/pages/README.md ================================================ ![Screenshot](screenshot.png) ================================================ FILE: demos/pages/main.go ================================================ // Demo code for the Pages primitive. package main import ( "fmt" "github.com/rivo/tview" ) const pageCount = 5 func main() { app := tview.NewApplication() pages := tview.NewPages() for page := 0; page < pageCount; page++ { func(page int) { pages.AddPage(fmt.Sprintf("page-%d", page), tview.NewModal(). SetText(fmt.Sprintf("This is page %d. Choose where to go next.", page+1)). AddButtons([]string{"Next", "Quit"}). SetDoneFunc(func(buttonIndex int, buttonLabel string) { if buttonIndex == 0 { pages.SwitchToPage(fmt.Sprintf("page-%d", (page+1)%pageCount)) } else { app.Stop() } }), false, page == 0) }(page) } if err := app.SetRoot(pages, true).EnableMouse(true).Run(); err != nil { panic(err) } } ================================================ FILE: demos/presentation/center.go ================================================ package main import "github.com/rivo/tview" // Center returns a new primitive which shows the provided primitive in its // center, given the provided primitive's size. func Center(width, height int, p tview.Primitive) tview.Primitive { return tview.NewFlex(). AddItem(nil, 0, 1, false). AddItem(tview.NewFlex(). SetDirection(tview.FlexRow). AddItem(nil, 0, 1, false). AddItem(p, height, 1, true). AddItem(nil, 0, 1, false), width, 1, true). AddItem(nil, 0, 1, false) } ================================================ FILE: demos/presentation/code.go ================================================ package main import ( "fmt" "github.com/rivo/tview" ) // The width of the code window. const codeWidth = 56 // Code returns a primitive which displays the given primitive (with the given // size) on the left side and its source code on the right side. func Code(p tview.Primitive, width, height int, code string) tview.Primitive { // Set up code view. codeView := tview.NewTextView(). SetWrap(false). SetDynamicColors(true) codeView.SetBorderPadding(1, 1, 2, 0) fmt.Fprint(codeView, code) return tview.NewFlex(). AddItem(Center(width, height, p), 0, 1, true). AddItem(codeView, codeWidth, 1, false) } ================================================ FILE: demos/presentation/colors.go ================================================ package main import ( "strings" "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) const colorsText = `You can use style tags almost everywhere to partially change the color of a string. Simply put a color name or hex string in square brackets to change [::s]all[::-]the following characters' color. H[green]er[white]e i[yellow]s a[darkcyan]n ex[red]amp[white]le. [::i]The [black:red]tags [black:green]look [black:yellow]like [::u]this: [blue:yellow:u[] or [#00ff00[]. [:::https://github.com/rivo/tview]Hyperlinks[:::-] are also supported.` // Colors demonstrates how to use colors. func Colors(nextSlide func()) (title string, content tview.Primitive) { table := tview.NewTable(). SetBorders(true). SetBordersColor(tcell.ColorBlue). SetDoneFunc(func(key tcell.Key) { nextSlide() }) var row, column int for _, word := range strings.Split(colorsText, " ") { table.SetCellSimple(row, column, word) column++ if column > 6 { column = 0 row++ } } table.SetBorderPadding(1, 1, 2, 2). SetBorder(true). SetTitle("A [red]c[yellow]o[green]l[darkcyan]o[blue]r[darkmagenta]f[red]u[yellow]l[white] [black:red]c[:yellow]o[:green]l[:darkcyan]o[:blue]r[:darkmagenta]f[:red]u[:yellow]l[white:-] [::bu]title") return "Colors", Center(82, 19, table) } ================================================ FILE: demos/presentation/cover.go ================================================ package main import ( "fmt" "strings" "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) const logo = ` __ _ / /__ __(_)__ _ __ / __/ | / / / _ \ | /| / / / /_ | |/ / / __/ |/ |/ / \__/ |___/_/\___/|__/|__/ ` const ( subtitle = `tview - Rich Widgets for Terminal UIs` navigation = `[yellow]Ctrl-N[-]: Next slide [yellow]Ctrl-P[-]: Previous slide [yellow]Ctrl-C[-]: Exit` mouse = `(or use your mouse)` ) // Cover returns the cover page. func Cover(nextSlide func()) (title string, content tview.Primitive) { // What's the size of the logo? lines := strings.Split(logo, "\n") logoWidth := 0 logoHeight := len(lines) for _, line := range lines { if len(line) > logoWidth { logoWidth = len(line) } } logoBox := tview.NewTextView(). SetTextColor(tcell.ColorGreen). SetDoneFunc(func(key tcell.Key) { nextSlide() }) fmt.Fprint(logoBox, logo) // Create a frame for the subtitle and navigation infos. frame := tview.NewFrame(tview.NewBox()). SetBorders(0, 0, 0, 0, 0, 0). AddText(subtitle, true, tview.AlignCenter, tcell.ColorWhite). AddText("", true, tview.AlignCenter, tcell.ColorWhite). AddText(navigation, true, tview.AlignCenter, tcell.ColorDarkMagenta). AddText(mouse, true, tview.AlignCenter, tcell.ColorDarkMagenta) // Create a Flex layout that centers the logo and subtitle. flex := tview.NewFlex(). SetDirection(tview.FlexRow). AddItem(tview.NewBox(), 0, 7, false). AddItem(tview.NewFlex(). AddItem(tview.NewBox(), 0, 1, false). AddItem(logoBox, logoWidth, 1, true). AddItem(tview.NewBox(), 0, 1, false), logoHeight, 1, true). AddItem(frame, 0, 10, false) return "Start", flex } ================================================ FILE: demos/presentation/end.go ================================================ package main import ( "fmt" "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) // End shows the final slide. func End(nextSlide func()) (title string, content tview.Primitive) { textView := tview.NewTextView(). SetDynamicColors(true). SetDoneFunc(func(key tcell.Key) { nextSlide() }) url := "[:::https://github.com/rivo/tview]https://github.com/rivo/tview" fmt.Fprint(textView, url) return "End", Center(tview.TaggedStringWidth(url), 1, textView) } ================================================ FILE: demos/presentation/flex.go ================================================ package main import ( "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) // Flex demonstrates flexbox layout. func Flex(nextSlide func()) (title string, content tview.Primitive) { modalShown := false pages := tview.NewPages() flex := tview.NewFlex(). AddItem(tview.NewBox().SetBorder(true).SetTitle("Flexible width, twice of middle column"), 0, 2, true). AddItem(tview.NewFlex(). SetDirection(tview.FlexRow). AddItem(tview.NewBox().SetBorder(true).SetTitle("Flexible width"), 0, 1, false). AddItem(tview.NewBox().SetBorder(true).SetTitle("Fixed height"), 15, 1, false). AddItem(tview.NewBox().SetBorder(true).SetTitle("Flexible height"), 0, 1, false), 0, 1, false). AddItem(tview.NewBox().SetBorder(true).SetTitle("Fixed width"), 30, 1, false) flex.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { if modalShown { nextSlide() modalShown = false } else { pages.ShowPage("modal") modalShown = true } return event }) modal := tview.NewModal(). SetText("Resize the window to see the effect of the flexbox parameters"). AddButtons([]string{"Ok"}).SetDoneFunc(func(buttonIndex int, buttonLabel string) { pages.HidePage("modal") }) pages.AddPage("flex", flex, true, true). AddPage("modal", modal, false, false) return "Flex", pages } ================================================ FILE: demos/presentation/form.go ================================================ package main import ( "bytes" "encoding/base64" "image/jpeg" "github.com/rivo/tview" ) const form = `[green]package[white] main [green]import[white] ( [red]"github.com/rivo/tview"[white] ) [green]func[white] [yellow]main[white]() { form := tview.[yellow]NewForm[white](). [yellow]AddImage[white]([red]"Photo:"[white], img, [red]0[white], [red]12[white], 0[white]). [yellow]AddInputField[white]([red]"First name:"[white], [red]""[white], [red]20[white], nil, nil). [yellow]AddInputField[white]([red]"Last name:"[white], [red]""[white], [red]20[white], nil, nil). [yellow]AddDropDown[white]([red]"Role:"[white], [][green]string[white]{ [red]"Engineer"[white], [red]"Manager"[white], [red]"Administration"[white], }, [red]0[white], nil). [yellow]AddCheckbox[white]([red]"On vacation:"[white], false, nil). [yellow]AddPasswordField[white]([red]"Password:"[white], [red]""[white], [red]10[white], [red]'*'[white], nil). [yellow]AddTextArea[white]([red]"Notes:"[white], [red]""[white], [red]0[white], [red]5[white], [red]0[white], nil). [yellow]AddButton[white]([red]"Save"[white], [yellow]func[white]() { [blue]/* Save data */[white] }). [yellow]AddButton[white]([red]"Cancel"[white], [yellow]func[white]() { [blue]/* Cancel */[white] }) tview.[yellow]NewApplication[white](). [yellow]SetRoot[white](form, true). [yellow]Run[white]() }` const photo = `/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAQEBAQEBAQEBAQGBgUGBggHBwcHCAwJCQkJCQwTDA4MDA4MExEUEA8QFBEeFxUVFx4iHRsdIiolJSo0MjRERFwBBAQEBAQEBAQEBAYGBQYGCAcHBwcIDAkJCQkJDBMMDgwMDgwTERQQDxAUER4XFRUXHiIdGx0iKiUlKjQyNEREXP/CABEIARgAyAMBIgACEQEDEQH/xAAcAAABBQEBAQAAAAAAAAAAAAAGAgMEBQcBCAD/2gAIAQEAAAAAbUpXVd6nqYef0Czgr+5xPEIbnLUpXewxMVpM/D3LEk1nRJyfuIQ3PUvv1LkQHRQPmYEazTaTdU0u9eShuevqaXzeGTfpTtU9St8jT7rupbPNQievojggrSzJ7VPyS43HTIZkXGubShFgpHkoLmVJVY27corrKcXH66LYRzP1utFh3njOuc5s2tWb852vhCY6I5JRMmXsCQiw7G8RmW13Jnc2lq5XIrqIdrM5xGjY9Z6M3YqgePduPr2/vyC75VQaiio6ClxDOIO+7u1ZdqfKW/FRAUl9/cR6KFT0IyMVOeYnV7B6ObsvhPznvJaVFJhdWjNJXwhEYFqMVwsc170eix6GedPQxUUExVb2Ca2vijAkLjg3igvr3ohFgsc8wejScsJyWe98w1BHAoToAzLRfWP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w3xKUDnuJ4l74vQY2joHGRzAx4P+YiI5LY4moGMmaQA/VPu88W1IcpQvC7n5PXS3Gi5LB6c/EpdfpAocg8R1sY5BxmaZCtQHvNUQNVpEA/VnP8Q5DHHEuqs7/wASoMqkTUuOxgeZXfVRSxZx3b7esscu7OeSc/Z4W/dplHqMiVdpG4mNjg4HtGtQHuavuK5AP4MrussffyifUUDtJljt/aJeSAcmX/uv89RDPB7gC9R+RCxCDtgtYjGcRUJA4/7li75/8gWxzsu0clAikzUP3NgTVbXuPtptamxXXkTSalbEDeh3jMuzkbRWoIyGAlmorJCVDPxGs+mh9zHtLZOfiKMnJmt/3D/x9qqzHCjJmjR0oUkYYcyi4MoVo1SE5gC1rtL7sgwEnYTgYmq0zWOXUxqrEOGXHXQ6NdTlnbYekTTVUjCLiV7Egx0atiy8QawgYjarIxzCGc5MAA2hgGTGQBSzcCP5ncrxnp4beKruxv0tt/MOMTgmYBGDLKyH2nbgZ6mVjczxG8In0l5bn468HaaKx7KFZzk7Q8wEy30mMiEDMAhgJGcTUWM9rFjv0//Z` // Form demonstrates forms. func Form(nextSlide func()) (title string, content tview.Primitive) { b, _ := base64.StdEncoding.DecodeString(photo) img, _ := jpeg.Decode(bytes.NewReader(b)) f := tview.NewForm(). AddImage("Photo:", img, 0, 12, 0). AddInputField("First name:", "", 0, nil, nil). AddInputField("Last name:", "", 0, nil, nil). AddDropDown("Role:", []string{"Engineer", "Manager", "Administration"}, 0, nil). AddCheckbox("On vacation:", false, nil). AddPasswordField("Password:", "", 10, '*', nil). AddTextArea("Notes:", "", 0, 2, 0, nil). AddButton("Save", nextSlide). AddButton("Cancel", nextSlide) f.SetBorder(true).SetTitle("Employee Information") return "Forms", Code(f, 36, 31, form) } ================================================ FILE: demos/presentation/grid.go ================================================ package main import ( "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) // Grid demonstrates the grid layout. func Grid(nextSlide func()) (title string, content tview.Primitive) { modalShown := false pages := tview.NewPages() newPrimitive := func(text string) tview.Primitive { return tview.NewFrame(nil). SetBorders(0, 0, 0, 0, 0, 0). AddText(text, true, tview.AlignCenter, tcell.ColorWhite) } menu := newPrimitive("Menu") main := newPrimitive("Main content") sideBar := newPrimitive("Side Bar") grid := tview.NewGrid(). SetRows(3, 0, 3). SetColumns(0, -4, 0). SetBorders(true). AddItem(newPrimitive("Header"), 0, 0, 1, 3, 0, 0, true). AddItem(newPrimitive("Footer"), 2, 0, 1, 3, 0, 0, false) grid.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { if modalShown { nextSlide() modalShown = false } else { pages.ShowPage("modal") modalShown = true } return event }) // Layout for screens narrower than 100 cells (menu and side bar are hidden). grid.AddItem(menu, 0, 0, 0, 0, 0, 0, false). AddItem(main, 1, 0, 1, 3, 0, 0, false). AddItem(sideBar, 0, 0, 0, 0, 0, 0, false) // Layout for screens wider than 100 cells. grid.AddItem(menu, 1, 0, 1, 1, 0, 100, false). AddItem(main, 1, 1, 1, 1, 0, 100, false). AddItem(sideBar, 1, 2, 1, 1, 0, 100, false) modal := tview.NewModal(). SetText("Resize the window to see how the grid layout adapts"). AddButtons([]string{"Ok"}).SetDoneFunc(func(buttonIndex int, buttonLabel string) { pages.HidePage("modal") }) pages.AddPage("grid", grid, true, true). AddPage("modal", modal, false, false) return "Grid", pages } ================================================ FILE: demos/presentation/helloworld.go ================================================ package main import ( "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) const helloWorld = `[green]package[white] main [green]import[white] ( [red]"github.com/rivo/tview"[white] ) [green]func[white] [yellow]main[white]() { box := tview.[yellow]NewBox[white](). [yellow]SetBorder[white](true). [yellow]SetTitle[white]([red]"Hello, world!"[white]) tview.[yellow]NewApplication[white](). [yellow]SetRoot[white](box, true). [yellow]Run[white]() }` // HelloWorld shows a simple "Hello world" example. func HelloWorld(nextSlide func()) (title string, content tview.Primitive) { // We use a text view because we want to capture keyboard input. textView := tview.NewTextView().SetDoneFunc(func(key tcell.Key) { nextSlide() }) textView.SetBorder(true).SetTitle("Hello, world!") return "Hello, world", Code(textView, 30, 10, helloWorld) } ================================================ FILE: demos/presentation/inputfield.go ================================================ package main import ( "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) const inputField = `[green]package[white] main [green]import[white] ( [red]"strconv"[white] [red]"github.com/gdamore/tcell/v2"[white] [red]"github.com/rivo/tview"[white] ) [green]func[white] [yellow]main[white]() { input := tview.[yellow]NewInputField[white](). [yellow]SetLabel[white]([red]"Enter a number: "[white]). [yellow]SetAcceptanceFunc[white]( tview.InputFieldInteger, ).[yellow]SetDoneFunc[white]([yellow]func[white](key tcell.Key) { text := input.[yellow]GetText[white]() n, _ := strconv.[yellow]Atoi[white](text) [blue]// We have a number.[white] }) tview.[yellow]NewApplication[white](). [yellow]SetRoot[white](input, true). [yellow]Run[white]() }` // InputField demonstrates the InputField. func InputField(nextSlide func()) (title string, content tview.Primitive) { input := tview.NewInputField(). SetLabel("Enter a number: "). SetAcceptanceFunc(tview.InputFieldInteger).SetDoneFunc(func(key tcell.Key) { nextSlide() }) return "Input", Code(input, 30, 1, inputField) } ================================================ FILE: demos/presentation/introduction.go ================================================ package main import "github.com/rivo/tview" // Introduction returns a tview.List with the highlights of the tview package. func Introduction(nextSlide func()) (title string, content tview.Primitive) { list := tview.NewList(). AddItem("A Go package for terminal based UIs", "with a special focus on rich interactive widgets", '1', nextSlide). AddItem("Based on github.com/gdamore/tcell", "Like termbox but better (see tcell docs)", '2', nextSlide). AddItem("Designed to be simple", `"Hello world" is 5 lines of code`, '3', nextSlide). AddItem("Good for data entry", `For charts, use "termui" - for low-level views, use "gocui" - ...`, '4', nextSlide). AddItem("Extensive documentation", "Everything is documented, examples in GitHub wiki, demo code for each widget", '5', nextSlide) return "Introduction", Center(80, 10, list) } ================================================ FILE: demos/presentation/main.go ================================================ /* A presentation of the tview package, implemented with tview. # Navigation The presentation will advance to the next slide when the primitive demonstrated in the current slide is left (usually by hitting Enter or Escape). Additionally, the following shortcuts can be used: - Ctrl-N: Jump to next slide - Ctrl-P: Jump to previous slide */ package main import ( "fmt" "strconv" "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) // Slide is a function which returns the slide's main primitive and its title. // It receives a "nextSlide" function which can be called to advance the // presentation to the next slide. type Slide func(nextSlide func()) (title string, content tview.Primitive) // The application. var app = tview.NewApplication() // Starting point for the presentation. func main() { // The presentation slides. slides := []Slide{ Cover, Introduction, HelloWorld, InputField, Form, TextView1, TextView2, Table, TreeView, Flex, Grid, Colors, End, } pages := tview.NewPages() // The bottom row has some info on where we are. info := tview.NewTextView(). SetDynamicColors(true). SetRegions(true). SetWrap(false). SetHighlightedFunc(func(added, removed, remaining []string) { if len(added) == 0 { return } app.SetFocus(pages) pages.SwitchToPage(added[0]) }) // Create the pages for all slides. previousSlide := func() { slide, _ := strconv.Atoi(info.GetHighlights()[0]) slide = (slide - 1 + len(slides)) % len(slides) info.Highlight(strconv.Itoa(slide)). ScrollToHighlight() } nextSlide := func() { slide, _ := strconv.Atoi(info.GetHighlights()[0]) slide = (slide + 1) % len(slides) info.Highlight(strconv.Itoa(slide)). ScrollToHighlight() } for index, slide := range slides { title, primitive := slide(nextSlide) pages.AddPage(strconv.Itoa(index), primitive, true, index == 0) fmt.Fprintf(info, `%d ["%d"][darkcyan]%s[white][""] `, index+1, index, title) } info.Highlight("0") // Create the main layout. layout := tview.NewFlex(). SetDirection(tview.FlexRow). AddItem(pages, 0, 1, true). AddItem(info, 1, 1, false) // Shortcuts to navigate the slides. app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { if event.Key() == tcell.KeyCtrlN { nextSlide() return nil } else if event.Key() == tcell.KeyCtrlP { previousSlide() return nil } return event }) // Start the application. if err := app.SetRoot(layout, true).EnableMouse(true).EnablePaste(true).Run(); err != nil { panic(err) } } ================================================ FILE: demos/presentation/table.go ================================================ package main import ( "fmt" "strings" "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) const tableData = `OrderDate|Region|Rep|Item|Units|UnitCost|Total 1/6/2017|East|Jones|Pencil|95|1.99|189.05 1/23/2017|Central|Kivell|Binder|50|19.99|999.50 2/9/2017|Central|Jardine|Pencil|36|4.99|179.64 2/26/2017|Central|Gill|Pen|27|19.99|539.73 3/15/2017|West|Sorvino|Pencil|56|2.99|167.44 4/1/2017|East|Jones|Binder|60|4.99|299.40 4/18/2017|Central|Andrews|Pencil|75|1.99|149.25 5/5/2017|Central|Jardine|Pencil|90|4.99|449.10 5/22/2017|West|Thompson|Pencil|32|1.99|63.68 6/8/2017|East|Jones|Binder|60|8.99|539.40 6/25/2017|Central|Morgan|Pencil|90|4.99|449.10 7/12/2017|East|Howard|Binder|29|1.99|57.71 7/29/2017|East|Parent|Binder|81|19.99|1,619.19 8/15/2017|East|Jones|Pencil|35|4.99|174.65 9/1/2017|Central|Smith|Desk|2|125.00|250.00 9/18/2017|East|Jones|Pen Set|16|15.99|255.84 10/5/2017|Central|Morgan|Binder|28|8.99|251.72 10/22/2017|East|Jones|Pen|64|8.99|575.36 11/8/2017|East|Parent|Pen|15|19.99|299.85 11/25/2017|Central|Kivell|Pen Set|96|4.99|479.04 12/12/2017|Central|Smith|Pencil|67|1.29|86.43 12/29/2017|East|Parent|Pen Set|74|15.99|1,183.26 1/15/2018|Central|Gill|Binder|46|8.99|413.54 2/1/2018|Central|Smith|Binder|87|15.00|1,305.00 2/18/2018|East|Jones|Binder|4|4.99|19.96 3/7/2018|West|Sorvino|Binder|7|19.99|139.93 3/24/2018|Central|Jardine|Pen Set|50|4.99|249.50 4/10/2018|Central|Andrews|Pencil|66|1.99|131.34 4/27/2018|East|Howard|Pen|96|4.99|479.04 5/14/2018|Central|Gill|Pencil|53|1.29|68.37 5/31/2018|Central|Gill|Binder|80|8.99|719.20 6/17/2018|Central|Kivell|Desk|5|125.00|625.00 7/4/2018|East|Jones|Pen Set|62|4.99|309.38 7/21/2018|Central|Morgan|Pen Set|55|12.49|686.95 8/7/2018|Central|Kivell|Pen Set|42|23.95|1,005.90 8/24/2018|West|Sorvino|Desk|3|275.00|825.00 9/10/2018|Central|Gill|Pencil|7|1.29|9.03 9/27/2018|West|Sorvino|Pen|76|1.99|151.24 10/14/2018|West|Thompson|Binder|57|19.99|1,139.43 10/31/2018|Central|Andrews|Pencil|14|1.29|18.06 11/17/2018|Central|Jardine|Binder|11|4.99|54.89 12/4/2018|Central|Jardine|Binder|94|19.99|1,879.06 12/21/2018|Central|Andrews|Binder|28|4.99|139.72` const tableBasic = `[green]func[white] [yellow]main[white]() { table := tview.[yellow]NewTable[white](). [yellow]SetFixed[white]([red]1[white], [red]1[white]) [yellow]for[white] row := [red]0[white]; row < [red]40[white]; row++ { [yellow]for[white] column := [red]0[white]; column < [red]7[white]; column++ { color := tcell.ColorWhite [yellow]if[white] row == [red]0[white] { color = tcell.ColorYellow } [yellow]else[white] [yellow]if[white] column == [red]0[white] { color = tcell.ColorDarkCyan } align := tview.AlignLeft [yellow]if[white] row == [red]0[white] { align = tview.AlignCenter } [yellow]else[white] [yellow]if[white] column == [red]0[white] || column >= [red]4[white] { align = tview.AlignRight } table.[yellow]SetCell[white](row, column, &tview.TableCell{ Text: [red]"..."[white], Color: color, Align: align, }) } } tview.[yellow]NewApplication[white](). [yellow]SetRoot[white](table, true). [yellow]Run[white]() }` const tableSeparator = `[green]func[white] [yellow]main[white]() { table := tview.[yellow]NewTable[white](). [yellow]SetFixed[white]([red]1[white], [red]1[white]). [yellow]SetSeparator[white](Borders.Vertical) [yellow]for[white] row := [red]0[white]; row < [red]40[white]; row++ { [yellow]for[white] column := [red]0[white]; column < [red]7[white]; column++ { color := tcell.ColorWhite [yellow]if[white] row == [red]0[white] { color = tcell.ColorYellow } [yellow]else[white] [yellow]if[white] column == [red]0[white] { color = tcell.ColorDarkCyan } align := tview.AlignLeft [yellow]if[white] row == [red]0[white] { align = tview.AlignCenter } [yellow]else[white] [yellow]if[white] column == [red]0[white] || column >= [red]4[white] { align = tview.AlignRight } table.[yellow]SetCell[white](row, column, &tview.TableCell{ Text: [red]"..."[white], Color: color, Align: align, }) } } tview.[yellow]NewApplication[white](). [yellow]SetRoot[white](table, true). [yellow]Run[white]() }` const tableBorders = `[green]func[white] [yellow]main[white]() { table := tview.[yellow]NewTable[white](). [yellow]SetFixed[white]([red]1[white], [red]1[white]). [yellow]SetBorders[white](true) [yellow]for[white] row := [red]0[white]; row < [red]40[white]; row++ { [yellow]for[white] column := [red]0[white]; column < [red]7[white]; column++ { color := tcell.ColorWhite [yellow]if[white] row == [red]0[white] { color = tcell.ColorYellow } [yellow]else[white] [yellow]if[white] column == [red]0[white] { color = tcell.ColorDarkCyan } align := tview.AlignLeft [yellow]if[white] row == [red]0[white] { align = tview.AlignCenter } [yellow]else[white] [yellow]if[white] column == [red]0[white] || column >= [red]4[white] { align = tview.AlignRight } table.[yellow]SetCell[white](row, column, &tview.TableCell{ Text: [red]"..."[white], Color: color, Align: align, }) } } tview.[yellow]NewApplication[white](). [yellow]SetRoot[white](table, true). [yellow]Run[white]() }` const tableSelectRow = `[green]func[white] [yellow]main[white]() { table := tview.[yellow]NewTable[white](). [yellow]SetFixed[white]([red]1[white], [red]1[white]). [yellow]SetSelectable[white](true, false) [yellow]for[white] row := [red]0[white]; row < [red]40[white]; row++ { [yellow]for[white] column := [red]0[white]; column < [red]7[white]; column++ { color := tcell.ColorWhite [yellow]if[white] row == [red]0[white] { color = tcell.ColorYellow } [yellow]else[white] [yellow]if[white] column == [red]0[white] { color = tcell.ColorDarkCyan } align := tview.AlignLeft [yellow]if[white] row == [red]0[white] { align = tview.AlignCenter } [yellow]else[white] [yellow]if[white] column == [red]0[white] || column >= [red]4[white] { align = tview.AlignRight } table.[yellow]SetCell[white](row, column, &tview.TableCell{ Text: [red]"..."[white], Color: color, Align: align, NotSelectable: row == [red]0[white] || column == [red]0[white], }) } } tview.[yellow]NewApplication[white](). [yellow]SetRoot[white](table, true). [yellow]Run[white]() }` const tableSelectColumn = `[green]func[white] [yellow]main[white]() { table := tview.[yellow]NewTable[white](). [yellow]SetFixed[white]([red]1[white], [red]1[white]). [yellow]SetSelectable[white](false, true) [yellow]for[white] row := [red]0[white]; row < [red]40[white]; row++ { [yellow]for[white] column := [red]0[white]; column < [red]7[white]; column++ { color := tcell.ColorWhite [yellow]if[white] row == [red]0[white] { color = tcell.ColorYellow } [yellow]else[white] [yellow]if[white] column == [red]0[white] { color = tcell.ColorDarkCyan } align := tview.AlignLeft [yellow]if[white] row == [red]0[white] { align = tview.AlignCenter } [yellow]else[white] [yellow]if[white] column == [red]0[white] || column >= [red]4[white] { align = tview.AlignRight } table.[yellow]SetCell[white](row, column, &tview.TableCell{ Text: [red]"..."[white], Color: color, Align: align, NotSelectable: row == [red]0[white] || column == [red]0[white], }) } } tview.[yellow]NewApplication[white](). [yellow]SetRoot[white](table, true). [yellow]Run[white]() }` const tableSelectCell = `[green]func[white] [yellow]main[white]() { table := tview.[yellow]NewTable[white](). [yellow]SetFixed[white]([red]1[white], [red]1[white]). [yellow]SetSelectable[white](true, true) [yellow]for[white] row := [red]0[white]; row < [red]40[white]; row++ { [yellow]for[white] column := [red]0[white]; column < [red]7[white]; column++ { color := tcell.ColorWhite [yellow]if[white] row == [red]0[white] { color = tcell.ColorYellow } [yellow]else[white] [yellow]if[white] column == [red]0[white] { color = tcell.ColorDarkCyan } align := tview.AlignLeft [yellow]if[white] row == [red]0[white] { align = tview.AlignCenter } [yellow]else[white] [yellow]if[white] column == [red]0[white] || column >= [red]4[white] { align = tview.AlignRight } table.[yellow]SetCell[white](row, column, &tview.TableCell{ Text: [red]"..."[white], Color: color, Align: align, NotSelectable: row == [red]0[white] || column == [red]0[white], }) } } tview.[yellow]NewApplication[white](). [yellow]SetRoot[white](table, true). [yellow]Run[white]() }` // Table demonstrates the Table. func Table(nextSlide func()) (title string, content tview.Primitive) { table := tview.NewTable(). SetFixed(1, 1) for row, line := range strings.Split(tableData, "\n") { for column, cell := range strings.Split(line, "|") { color := tcell.ColorWhite if row == 0 { color = tcell.ColorYellow } else if column == 0 { color = tcell.ColorDarkCyan } align := tview.AlignLeft if row == 0 { align = tview.AlignCenter } else if column == 0 || column >= 4 { align = tview.AlignRight } tableCell := tview.NewTableCell(cell). SetTextColor(color). SetAlign(align). SetSelectable(row != 0 && column != 0) if column >= 1 && column <= 3 { tableCell.SetExpansion(1) } table.SetCell(row, column, tableCell) } } table.SetBorder(true).SetTitle("Table") code := tview.NewTextView(). SetWrap(false). SetDynamicColors(true) code.SetBorderPadding(1, 1, 2, 0) list := tview.NewList() basic := func() { table.SetBorders(false). SetSelectable(false, false). SetSeparator(' ') code.Clear() fmt.Fprint(code, tableBasic) } separator := func() { table.SetBorders(false). SetSelectable(false, false). SetSeparator(tview.Borders.Vertical) code.Clear() fmt.Fprint(code, tableSeparator) } borders := func() { table.SetBorders(true). SetSelectable(false, false) code.Clear() fmt.Fprint(code, tableBorders) } selectRow := func() { table.SetBorders(false). SetSelectable(true, false). SetSeparator(' ') code.Clear() fmt.Fprint(code, tableSelectRow) } selectColumn := func() { table.SetBorders(false). SetSelectable(false, true). SetSeparator(' ') code.Clear() fmt.Fprint(code, tableSelectColumn) } selectCell := func() { table.SetBorders(false). SetSelectable(true, true). SetSeparator(' ') code.Clear() fmt.Fprint(code, tableSelectCell) } navigate := func() { app.SetFocus(table) table.SetDoneFunc(func(key tcell.Key) { app.SetFocus(list) }).SetSelectedFunc(func(row int, column int) { app.SetFocus(list) }) } list.ShowSecondaryText(false). AddItem("Basic table", "", 'b', basic). AddItem("Table with separator", "", 's', separator). AddItem("Table with borders", "", 'o', borders). AddItem("Selectable rows", "", 'r', selectRow). AddItem("Selectable columns", "", 'c', selectColumn). AddItem("Selectable cells", "", 'l', selectCell). AddItem("Navigate", "", 'n', navigate). AddItem("Next slide", "", 'x', nextSlide) list.SetBorderPadding(1, 1, 2, 2) basic() return "Table", tview.NewFlex(). AddItem(tview.NewFlex(). SetDirection(tview.FlexRow). AddItem(list, 10, 1, true). AddItem(table, 0, 1, false), 0, 1, true). AddItem(code, codeWidth, 1, false) } ================================================ FILE: demos/presentation/textview.go ================================================ package main import ( "fmt" "strconv" "time" "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) const textView1 = `[green]func[white] [yellow]main[white]() { app := tview.[yellow]NewApplication[white]() textView := tview.[yellow]NewTextView[white](). [yellow]SetTextColor[white](tcell.ColorYellow). [yellow]SetScrollable[white](false). [yellow]SetChangedFunc[white]([yellow]func[white]() { app.[yellow]Draw[white]() }) [green]go[white] [yellow]func[white]() { [green]var[white] n [green]int [white] [yellow]for[white] { n++ fmt.[yellow]Fprintf[white](textView, [red]"%d "[white], n) time.[yellow]Sleep[white]([red]200[white] * time.Millisecond) } }() app.[yellow]SetRoot[white](textView, true). [yellow]Run[white]() }` // TextView1 demonstrates the basic text view. func TextView1(nextSlide func()) (title string, content tview.Primitive) { textView := tview.NewTextView(). SetTextColor(tcell.ColorYellow). SetScrollable(false). SetDoneFunc(func(key tcell.Key) { nextSlide() }) textView.SetChangedFunc(func() { if textView.HasFocus() { app.Draw() } }) go func() { var n int for { if textView.HasFocus() { n++ if n > 512 { n = 1 textView.SetText("") } fmt.Fprintf(textView, "%d ", n) time.Sleep(200 * time.Millisecond) } else { time.Sleep(time.Second) } } }() textView.SetBorder(true).SetTitle("TextView implements io.Writer") return "Text 1", Code(textView, 36, 13, textView1) } const textView2 = `[green]package[white] main [green]import[white] ( [red]"strconv"[white] [red]"github.com/gdamore/tcell/v2"[white] [red]"github.com/rivo/tview"[white] ) [green]func[white] [yellow]main[white]() { ["0"]textView[""] := tview.[yellow]NewTextView[white]() ["1"]textView[""].[yellow]SetDynamicColors[white](true). [yellow]SetWrap[white](false). [yellow]SetRegions[white](true). [yellow]SetDoneFunc[white]([yellow]func[white](key tcell.Key) { highlights := ["2"]textView[""].[yellow]GetHighlights[white]() hasHighlights := [yellow]len[white](highlights) > [red]0 [yellow]switch[white] key { [yellow]case[white] tcell.KeyEnter: [yellow]if[white] hasHighlights { ["3"]textView[""].[yellow]Highlight[white]() } [yellow]else[white] { ["4"]textView[""].[yellow]Highlight[white]([red]"0"[white]). [yellow]ScrollToHighlight[white]() } [yellow]case[white] tcell.KeyTab: [yellow]if[white] hasHighlights { current, _ := strconv.[yellow]Atoi[white](highlights[[red]0[white]]) next := (current + [red]1[white]) % [red]9 ["5"]textView[""].[yellow]Highlight[white](strconv.[yellow]Itoa[white](next)). [yellow]ScrollToHighlight[white]() } [yellow]case[white] tcell.KeyBacktab: [yellow]if[white] hasHighlights { current, _ := strconv.[yellow]Atoi[white](highlights[[red]0[white]]) next := (current - [red]1[white] + [red]9[white]) % [red]9 ["6"]textView[""].[yellow]Highlight[white](strconv.[yellow]Itoa[white](next)). [yellow]ScrollToHighlight[white]() } } }) fmt.[yellow]Fprint[white](["7"]textView[""], content) tview.[yellow]NewApplication[white](). [yellow]SetRoot[white](["8"]textView[""], true). [yellow]Run[white]() }` // TextView2 demonstrates the extended text view. func TextView2(nextSlide func()) (title string, content tview.Primitive) { codeView := tview.NewTextView(). SetWrap(false) fmt.Fprint(codeView, textView2) codeView.SetBorder(true).SetTitle("Raw text") textView := tview.NewTextView() textView.SetDynamicColors(true). SetWrap(false). SetRegions(true). SetDoneFunc(func(key tcell.Key) { if key == tcell.KeyEscape { nextSlide() return } highlights := textView.GetHighlights() hasHighlights := len(highlights) > 0 switch key { case tcell.KeyEnter: if hasHighlights { textView.Highlight() } else { textView.Highlight("0"). ScrollToHighlight() } case tcell.KeyTab: if hasHighlights { current, _ := strconv.Atoi(highlights[0]) next := (current + 1) % 9 textView.Highlight(strconv.Itoa(next)). ScrollToHighlight() } case tcell.KeyBacktab: if hasHighlights { current, _ := strconv.Atoi(highlights[0]) next := (current - 1 + 9) % 9 textView.Highlight(strconv.Itoa(next)). ScrollToHighlight() } } }) fmt.Fprint(textView, textView2) textView.SetBorder(true).SetTitle("TextView output") return "Text 2", tview.NewFlex(). AddItem(textView, 0, 1, true). AddItem(codeView, 0, 1, false) } ================================================ FILE: demos/presentation/treeview.go ================================================ package main import ( "strings" "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) const treeAllCode = `[green]package[white] main [green]import[white] [red]"github.com/rivo/tview"[white] [green]func[white] [yellow]main[white]() { $$$ root := tview.[yellow]NewTreeNode[white]([red]"Root"[white]). [yellow]AddChild[white](tview.[yellow]NewTreeNode[white]([red]"First child"[white]). [yellow]AddChild[white](tview.[yellow]NewTreeNode[white]([red]"Grandchild A"[white])). [yellow]AddChild[white](tview.[yellow]NewTreeNode[white]([red]"Grandchild B"[white]))). [yellow]AddChild[white](tview.[yellow]NewTreeNode[white]([red]"Second child"[white]). [yellow]AddChild[white](tview.[yellow]NewTreeNode[white]([red]"Grandchild C"[white])). [yellow]AddChild[white](tview.[yellow]NewTreeNode[white]([red]"Grandchild D"[white]))). [yellow]AddChild[white](tview.[yellow]NewTreeNode[white]([red]"Third child"[white])) tree.[yellow]SetRoot[white](root). [yellow]SetCurrentNode[white](root) tview.[yellow]NewApplication[white](). [yellow]SetRoot[white](tree, true). [yellow]Run[white]() }` const treeBasicCode = `tree := tview.[yellow]NewTreeView[white]()` const treeTopLevelCode = `tree := tview.[yellow]NewTreeView[white](). [yellow]SetTopLevel[white]([red]1[white])` const treeAlignCode = `tree := tview.[yellow]NewTreeView[white](). [yellow]SetAlign[white](true)` const treePrefixCode = `tree := tview.[yellow]NewTreeView[white](). [yellow]SetGraphics[white](false). [yellow]SetTopLevel[white]([red]1[white]). [yellow]SetPrefixes[white]([][green]string[white]{ [red]"[red[]* "[white], [red]"[darkcyan[]- "[white], [red]"[darkmagenta[]- "[white], })` type node struct { text string expand bool selected func() children []*node } var ( tree = tview.NewTreeView() treeNextSlide func() treeCode = tview.NewTextView().SetWrap(false).SetDynamicColors(true) ) var rootNode = &node{ text: "Root", children: []*node{ {text: "Expand all", selected: func() { tree.GetRoot().ExpandAll() }}, {text: "Collapse all", selected: func() { for _, child := range tree.GetRoot().GetChildren() { child.CollapseAll() } }}, {text: "Hide root node", expand: true, children: []*node{ {text: "Tree list starts one level down"}, {text: "Works better for lists where no top node is needed"}, {text: "Switch to this layout", selected: func() { tree.SetAlign(false).SetTopLevel(1).SetGraphics(true).SetPrefixes(nil) treeCode.SetText(strings.Replace(treeAllCode, "$$$", treeTopLevelCode, -1)) }}, }}, {text: "Align node text", expand: true, children: []*node{ {text: "For trees that are similar to lists"}, {text: "Hierarchy shown only in line drawings"}, {text: "Switch to this layout", selected: func() { tree.SetAlign(true).SetTopLevel(0).SetGraphics(true).SetPrefixes(nil) treeCode.SetText(strings.Replace(treeAllCode, "$$$", treeAlignCode, -1)) }}, }}, {text: "Prefixes", expand: true, children: []*node{ {text: "Best for hierarchical bullet point lists"}, {text: "You can define your own prefixes per level"}, {text: "Switch to this layout", selected: func() { tree.SetAlign(false).SetTopLevel(1).SetGraphics(false).SetPrefixes([]string{"[red]* ", "[darkcyan]- ", "[darkmagenta]- "}) treeCode.SetText(strings.Replace(treeAllCode, "$$$", treePrefixCode, -1)) }}, }}, {text: "Basic tree with graphics", expand: true, children: []*node{ {text: "Lines illustrate hierarchy"}, {text: "Basic indentation"}, {text: "Switch to this layout", selected: func() { tree.SetAlign(false).SetTopLevel(0).SetGraphics(true).SetPrefixes(nil) treeCode.SetText(strings.Replace(treeAllCode, "$$$", treeBasicCode, -1)) }}, }}, {text: "Next slide", selected: func() { treeNextSlide() }}, }} // TreeView demonstrates the tree view. func TreeView(nextSlide func()) (title string, content tview.Primitive) { treeNextSlide = nextSlide tree.SetBorder(true). SetTitle("TreeView") // Add nodes. var add func(target *node) *tview.TreeNode add = func(target *node) *tview.TreeNode { node := tview.NewTreeNode(target.text). SetSelectable(target.expand || target.selected != nil). SetExpanded(target == rootNode). SetReference(target) if target.expand { node.SetColor(tcell.ColorGreen) } else if target.selected != nil { node.SetColor(tcell.ColorRed) } for _, child := range target.children { node.AddChild(add(child)) } return node } root := add(rootNode) tree.SetRoot(root). SetCurrentNode(root). SetSelectedFunc(func(n *tview.TreeNode) { original := n.GetReference().(*node) if original.expand { n.SetExpanded(!n.IsExpanded()) } else if original.selected != nil { original.selected() } }) treeCode.SetText(strings.Replace(treeAllCode, "$$$", treeBasicCode, -1)). SetBorderPadding(1, 1, 2, 0) return "Tree", tview.NewFlex(). AddItem(tree, 0, 1, true). AddItem(treeCode, codeWidth, 1, false) } ================================================ FILE: demos/primitive/README.md ================================================ ![Screenshot](screenshot.png) ================================================ FILE: demos/primitive/main.go ================================================ // Demo code which illustrates how to implement your own primitive. package main import ( "fmt" "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) // RadioButtons implements a simple primitive for radio button selections. type RadioButtons struct { *tview.Box options []string currentOption int } // NewRadioButtons returns a new radio button primitive. func NewRadioButtons(options []string) *RadioButtons { return &RadioButtons{ Box: tview.NewBox(), options: options, } } // Draw draws this primitive onto the screen. func (r *RadioButtons) Draw(screen tcell.Screen) { r.Box.DrawForSubclass(screen, r) x, y, width, height := r.GetInnerRect() for index, option := range r.options { if index >= height { break } radioButton := "\u25ef" // Unchecked. if index == r.currentOption { radioButton = "\u25c9" // Checked. } line := fmt.Sprintf(`%s[white] %s`, radioButton, option) tview.Print(screen, line, x, y+index, width, tview.AlignLeft, tcell.ColorYellow) } } // InputHandler returns the handler for this primitive. func (r *RadioButtons) InputHandler() func(event *tcell.EventKey, setFocus func(p tview.Primitive)) { return r.WrapInputHandler(func(event *tcell.EventKey, setFocus func(p tview.Primitive)) { switch event.Key() { case tcell.KeyUp: r.currentOption-- if r.currentOption < 0 { r.currentOption = 0 } case tcell.KeyDown: r.currentOption++ if r.currentOption >= len(r.options) { r.currentOption = len(r.options) - 1 } } }) } // MouseHandler returns the mouse handler for this primitive. func (r *RadioButtons) MouseHandler() func(action tview.MouseAction, event *tcell.EventMouse, setFocus func(p tview.Primitive)) (consumed bool, capture tview.Primitive) { return r.WrapMouseHandler(func(action tview.MouseAction, event *tcell.EventMouse, setFocus func(p tview.Primitive)) (consumed bool, capture tview.Primitive) { x, y := event.Position() _, rectY, _, _ := r.GetInnerRect() if !r.InRect(x, y) { return false, nil } if action == tview.MouseLeftClick { setFocus(r) index := y - rectY if index >= 0 && index < len(r.options) { r.currentOption = index consumed = true } } return }) } func main() { radioButtons := NewRadioButtons([]string{"Lions", "Elephants", "Giraffes"}) radioButtons.SetBorder(true). SetTitle("Radio Button Demo"). SetRect(0, 0, 30, 5) if err := tview.NewApplication().SetRoot(radioButtons, false).EnableMouse(true).Run(); err != nil { panic(err) } } ================================================ FILE: demos/table/README.md ================================================ ![Screenshot](screenshot.png) ================================================ FILE: demos/table/main.go ================================================ // Demo code for the Table primitive. package main import ( "strings" "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) func main() { app := tview.NewApplication() table := tview.NewTable(). SetBorders(true) lorem := strings.Split("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.", " ") cols, rows := 10, 40 word := 0 for r := 0; r < rows; r++ { for c := 0; c < cols; c++ { color := tcell.ColorWhite if c < 1 || r < 1 { color = tcell.ColorYellow } table.SetCell(r, c, tview.NewTableCell(lorem[word]). SetTextColor(color). SetAlign(tview.AlignCenter)) word = (word + 1) % len(lorem) } } table.Select(0, 0).SetFixed(1, 1).SetDoneFunc(func(key tcell.Key) { if key == tcell.KeyEscape { app.Stop() } if key == tcell.KeyEnter { table.SetSelectable(true, true) } }).SetSelectedFunc(func(row int, column int) { table.GetCell(row, column).SetTextColor(tcell.ColorRed) table.SetSelectable(false, false) }) if err := app.SetRoot(table, true).EnableMouse(true).Run(); err != nil { panic(err) } } ================================================ FILE: demos/table/virtualtable/README.md ================================================ ![Screenshot](screenshot.png) ================================================ FILE: demos/table/virtualtable/main.go ================================================ package main import ( "fmt" "math" "github.com/rivo/tview" ) type TableData struct { tview.TableContentReadOnly } func (d *TableData) GetCell(row, column int) *tview.TableCell { letters := [...]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'A' + byte(row%26)} // log(math.MaxInt64) / log(26) ~= 14 start := len(letters) - 1 row /= 26 for row > 0 { start-- row-- letters[start] = 'A' + byte(row%26) row /= 26 } return tview.NewTableCell(fmt.Sprintf("[red]%s[green]%d", letters[start:], column)) } func (d *TableData) GetRowCount() int { return math.MaxInt64 } func (d *TableData) GetColumnCount() int { return math.MaxInt64 } func main() { data := &TableData{} table := tview.NewTable(). SetBorders(false). SetSelectable(true, true). SetContent(data) if err := tview.NewApplication().SetRoot(table, true).EnableMouse(true).Run(); err != nil { panic(err) } } ================================================ FILE: demos/textarea/README.md ================================================ ![Screenshot](screenshot.png) ================================================ FILE: demos/textarea/main.go ================================================ // Demo code for the TextArea primitive. package main import ( "fmt" "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) func main() { app := tview.NewApplication() textArea := tview.NewTextArea(). SetWrap(false). SetPlaceholder("Enter text here...") textArea.SetTitle("Text Area").SetBorder(true) helpInfo := tview.NewTextView(). SetText(" Press F1 for help, press Ctrl-C to exit") position := tview.NewTextView(). SetDynamicColors(true). SetTextAlign(tview.AlignRight) pages := tview.NewPages() updateInfos := func() { fromRow, fromColumn, toRow, toColumn := textArea.GetCursor() if fromRow == toRow && fromColumn == toColumn { position.SetText(fmt.Sprintf("Row: [yellow]%d[white], Column: [yellow]%d ", fromRow, fromColumn)) } else { position.SetText(fmt.Sprintf("[red]From[white] Row: [yellow]%d[white], Column: [yellow]%d[white] - [red]To[white] Row: [yellow]%d[white], To Column: [yellow]%d ", fromRow, fromColumn, toRow, toColumn)) } } textArea.SetMovedFunc(updateInfos) updateInfos() mainView := tview.NewGrid(). SetRows(0, 1). AddItem(textArea, 0, 0, 1, 2, 0, 0, true). AddItem(helpInfo, 1, 0, 1, 1, 0, 0, false). AddItem(position, 1, 1, 1, 1, 0, 0, false) help1 := tview.NewTextView(). SetDynamicColors(true). SetText(`[green]Navigation [yellow]Left arrow[white]: Move left. [yellow]Right arrow[white]: Move right. [yellow]Down arrow[white]: Move down. [yellow]Up arrow[white]: Move up. [yellow]Ctrl-A, Home[white]: Move to the beginning of the current line. [yellow]Ctrl-E, End[white]: Move to the end of the current line. [yellow]Ctrl-F, page down[white]: Move down by one page. [yellow]Ctrl-B, page up[white]: Move up by one page. [yellow]Alt-Up arrow[white]: Scroll the page up. [yellow]Alt-Down arrow[white]: Scroll the page down. [yellow]Alt-Left arrow[white]: Scroll the page to the left. [yellow]Alt-Right arrow[white]: Scroll the page to the right. [yellow]Alt-B, Ctrl-Left arrow[white]: Move back by one word. [yellow]Alt-F, Ctrl-Right arrow[white]: Move forward by one word. [blue]Press Enter for more help, press Escape to return.`) help2 := tview.NewTextView(). SetDynamicColors(true). SetText(`[green]Editing[white] Type to enter text. [yellow]Ctrl-H, Backspace[white]: Delete the left character. [yellow]Ctrl-D, Delete[white]: Delete the right character. [yellow]Ctrl-K[white]: Delete until the end of the line. [yellow]Ctrl-W[white]: Delete the rest of the word. [yellow]Ctrl-U[white]: Delete the current line. [blue]Press Enter for more help, press Escape to return.`) help3 := tview.NewTextView(). SetDynamicColors(true). SetText(`[green]Selecting Text[white] Move while holding Shift or drag the mouse. Double-click to select a word. [yellow]Ctrl-L[white] to select entire text. [green]Clipboard [yellow]Ctrl-Q[white]: Copy. [yellow]Ctrl-X[white]: Cut. [yellow]Ctrl-V[white]: Paste. [green]Undo [yellow]Ctrl-Z[white]: Undo. [yellow]Ctrl-Y[white]: Redo. [blue]Press Enter for more help, press Escape to return.`) help := tview.NewFrame(help1). SetBorders(1, 1, 0, 0, 2, 2) help.SetBorder(true). SetTitle("Help"). SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { if event.Key() == tcell.KeyEscape { pages.SwitchToPage("main") return nil } else if event.Key() == tcell.KeyEnter { switch { case help.GetPrimitive() == help1: help.SetPrimitive(help2) case help.GetPrimitive() == help2: help.SetPrimitive(help3) case help.GetPrimitive() == help3: help.SetPrimitive(help1) } return nil } return event }) pages.AddAndSwitchToPage("main", mainView, true). AddPage("help", tview.NewGrid(). SetColumns(0, 64, 0). SetRows(0, 22, 0). AddItem(help, 1, 1, 1, 1, 0, 0, true), true, false) app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { if event.Key() == tcell.KeyF1 { pages.ShowPage("help") //TODO: Check when clicking outside help window with the mouse. Then clicking help again. return nil } return event }) if err := app.SetRoot(pages, true).EnableMouse(true).EnablePaste(true).Run(); err != nil { panic(err) } } ================================================ FILE: demos/textview/README.md ================================================ ![Screenshot](screenshot.png) ================================================ FILE: demos/textview/chat/README.md ================================================ ![Screenshot](screenshot.png) ================================================ FILE: demos/textview/chat/chain.txt ================================================ H4sIAAAAAAAA/0y6DYhUV7su6Lv+qrrj5/VkxBEpmkYaCSKOn9cTvBLE8fY4XsnxNh5xMn084q69V1Vte9fedfba1W2JOI4nIyJeb+M44ogYCY6IZMRxRCQECRKCSBARCSGEIBIkiGQkhCZIeNbwrsp3uYLdpn72Xut9n/f5WTub/xdJ9M4/ROVMMfvvO1Gakz+2iCTp/6koE0f++CIy/1hFZeXIf7yI9J+fObFo0aLl/n8VRPV/+mdXlWneDp9dvGjRf+P/VRDpf/rnNK/Cd9SiRWP+f1NEf+lGvX9K8+qf/3zvxCJS/IlF+Hcr/DGCPFj7j1k6m0ab9a4i6mzWH6ZRd7P+H7rdaLOc6wz0XNHPEhF1hSt0r1PklvoqLlxFh3RVRK7ScdFtFjQhUqcO9l2lXD/uqCydsSNZWtkyyrJBLe5ERZXGOi6jwwOTFXMzdlBzcVSmttTN0kaJibK5aODUXJolI83IpTF/sR7FVZ//oS1frN60VRkNoky1SmtlXlQqS1tWVh07mtheaZ1Li9zE/dLZpBb3s6pf2hHXb7q4TJtWZWk8I7qDkTR3vZTrN9LP01lbuiiTWTRXL2ZtWaV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B3OY8qH8H/TJ87LFCQUw2/MIR0CLGzmOC+hl6H62F/pbAKeZ78hdg9pK/uof2+j8E6DnoBcQj2gR9l/e3jiB2QB4hqH3+cy7YPPkHUGbIR7n4KBygPyZ2gqrBjXvP+B9g3oN+DbPDz0PWQb9q0G/hOSpNr4X+Ioj1VYJ417OY1XP/SsLshtwNcRP0NZfwXDiYlIcJ8ggv4zLELs3YX2hA/TgGMxk8hNlD0GchjALd9k8aULshL8q8AfEcqsXtOh7OmelbHsVfxEQLKmfkn6WGfzK66cNxiJ8YliJAUbyCeA3xC6SgKeiH0l+BOQ2TQR6kHuQ3BPM11OcE2g+9nXecCej3ITv+Fxmyw0WoEurbkJjpC+IZMowbuqZDINjorzb8KchwVvmbhDgdDmkXQ13m5f4cgGwSfrfD178rIO6NQwUZfGvGWjy9Zl+DTaT+QUBcgtkP8Tqc1FJJoK9BH0o21LQLtBs0xdZfbG5AbIK4XAsH+9cgrvgbQYyudqA54uj32QwOHYOuYKYDT9BjAXrCoU3WGQFlODqUnwd3/rbmH0w0/FvQS/ZCr6EYN+r74eONGwTx2arh/z7BSfwQ1NcC6mEDdFJCfMgIhdhHEPv9G4LcBcUVVWeDs1TvqkY47PkQ6hVoO0FvhtlBoAqCk8MlfwVyG0EoyJ8J/Oklctzf8wtQP1LD/x6GTn0wfBZ5QzTGdoiJsLnvxFQDJh8+fXk5fIZ1gKBPQd4XMLvHIccJ8kOIn4dHP8eYOJbWIJa1IM0Y9LugHzesV2MtNgFiFcxyXrgIsX0Ht+6MGA/nnsPHMvKVYJegzi+uQU/609yPt40xTi0fceVXEuhXmEcEc27R/x8AAP//emnhmaA5AAA= ================================================ FILE: demos/textview/chat/main.go ================================================ // Demo code for a simple chat application using TextView regions. package main import ( "bytes" "compress/gzip" _ "embed" "encoding/base64" "encoding/gob" "fmt" "math/rand" "strings" "time" "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) // MarkovChain implements a simple order of one Markov chain for text // generation. type MarkovChain struct { Words []string // All unique words. Starts []int // Indexes of starting words in Words. Chain map[int][]int // Maps word index to possible next word indexes in Words. Ordered by frequency (highest first). } var ( //go:embed chain.txt chainData []byte // The Markov chain. chain MarkovChain ) func main() { // Load the Markov chain and generate chat lines. loadChain() ch := generateChat() app := tview.NewApplication() // Create a chat view. chat := tview.NewTextView(). SetDynamicColors(true). SetRegions(true). ScrollToEnd() // The users will be displayed separately. users := tview.NewTextView(). SetDynamicColors(true). SetTextAlign(tview.AlignRight). ScrollToEnd() // Syncing the scrolling is left to the student as an exercise. chat.SetInputCapture(func(*tcell.EventKey) *tcell.EventKey { return nil }).SetMouseCapture(func(tview.MouseAction, *tcell.EventMouse) (tview.MouseAction, *tcell.EventMouse) { return tview.MouseConsumed, nil }) users.SetInputCapture(func(*tcell.EventKey) *tcell.EventKey { return nil }).SetMouseCapture(func(tview.MouseAction, *tcell.EventMouse) (tview.MouseAction, *tcell.EventMouse) { return tview.MouseConsumed, nil }) // Add chat lines as they are generated. go func() { var ( message int userColors = [...]string{"red", "green", "yellow", "blue", "magenta", "cyan"} userToColor = make(map[string]string) ) for line := range ch { sleep := 3 * time.Second if message < 20 { sleep = 0 } time.Sleep(sleep) // Add the line to the chat view. userName := line[0] if _, ok := userToColor[userName]; !ok { userToColor[userName] = userColors[len(userToColor)%len(userColors)] } line = line[1:] // Don't display the user name here. fmt.Fprintf(chat, "[\"%d\"]%s\n\n", message, strings.Join(line, " ")) // Add the user name to the users view. Then redraw everything. app.QueueUpdateDraw(func() { lines := users.GetWrappedLineCount() regions := chat.GetRegions(lines, true) if len(regions) > 0 { lastRegion := regions[len(regions)-1] fmt.Fprintf(users, "[%s]%s", userToColor[userName], userName) for index := lastRegion.StartRow; index <= lastRegion.EndRow; index++ { fmt.Fprintln(users) } } }) message++ } }() // Make a layout and start the application. grid := tview.NewGrid(). SetGap(0, 1). SetColumns(0, 8, 40, 0). AddItem(users, 0, 1, 1, 1, 0, 0, false). AddItem(chat, 0, 2, 1, 1, 0, 0, true) grid.SetBorder(true).SetTitle("Chat") if err := app.SetRoot(grid, true).EnableMouse(true).Run(); err != nil { panic(err) } } // loadChain loads the Markov chain from the embedded base64 data. func loadChain() { b := base64.NewDecoder(base64.StdEncoding, bytes.NewReader(chainData)) zr, err := gzip.NewReader(b) if err != nil { panic(err) } defer zr.Close() g := gob.NewDecoder(zr) if err := g.Decode(&chain); err != nil { panic(err) } } // generateChat generates chat lines based on the Markov chain and sends them // to a channel. The first word of each line is always the name of a user, // followed by a colon. func generateChat() <-chan []string { ch := make(chan []string) go func() { defer close(ch) var lastStart int for { var line []string // Pick a random starting word different from the previous one. var word int for { start := chain.Starts[rand.Intn(len(chain.Starts))] if start != lastStart { word = start lastStart = start line = append(line, chain.Words[word]) break } } // Generate the rest of the line. for { // Pick a random next word. next := chain.Chain[word][rand.Intn(len(chain.Chain[word]))] // If we hit the end token, emit the line. if chain.Words[next] == "$" { ch <- line break } // Otherwise, just add the word and continue. line = append(line, chain.Words[next]) word = next } } }() return ch } ================================================ FILE: demos/textview/main.go ================================================ // Demo code for the TextView primitive. package main import ( "fmt" "strconv" "strings" "time" "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) const corporate = `Leverage agile frameworks to provide a robust synopsis for high level overviews. Iterative approaches to corporate strategy foster collaborative thinking to further the overall value proposition. Organically grow the holistic world view of disruptive innovation via workplace diversity and empowerment. Bring to the table win-win survival strategies to ensure proactive domination. At the end of the day, going forward, a new normal that has evolved from generation X is on the runway heading towards a streamlined cloud solution. User generated content in real-time will have multiple touchpoints for offshoring. Capitalize on low hanging fruit to identify a ballpark value added activity to beta test. Override the digital divide with additional clickthroughs from DevOps. Nanotechnology immersion along the information highway will close the loop on focusing solely on the bottom line. [yellow]Press Enter, then Tab/Backtab for word selections` func main() { app := tview.NewApplication() textView := tview.NewTextView(). SetDynamicColors(true). SetRegions(true). SetWordWrap(true). SetChangedFunc(func() { app.Draw() }) numSelections := 0 go func() { for _, word := range strings.Split(corporate, " ") { if word == "the" { word = "[#ff0000]the[white]" } if word == "to" { word = fmt.Sprintf(`["%d"]to[""]`, numSelections) numSelections++ } fmt.Fprintf(textView, "%s ", word) time.Sleep(200 * time.Millisecond) } }() textView.SetDoneFunc(func(key tcell.Key) { currentSelection := textView.GetHighlights() if key == tcell.KeyEnter { if len(currentSelection) > 0 { textView.Highlight() } else { textView.Highlight("0").ScrollToHighlight() } } else if len(currentSelection) > 0 { index, _ := strconv.Atoi(currentSelection[0]) if key == tcell.KeyTab { index = (index + 1) % numSelections } else if key == tcell.KeyBacktab { index = (index - 1 + numSelections) % numSelections } else { return } textView.Highlight(strconv.Itoa(index)).ScrollToHighlight() } }) textView.SetBorder(true) if err := app.SetRoot(textView, true).EnableMouse(true).Run(); err != nil { panic(err) } } ================================================ FILE: demos/treeview/README.md ================================================ ![Screenshot](screenshot.png) ================================================ FILE: demos/treeview/main.go ================================================ // Demo code for the TreeView primitive. package main import ( "os" "path/filepath" "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) // Show a navigable tree view of the current directory. func main() { rootDir := "." root := tview.NewTreeNode(rootDir). SetColor(tcell.ColorRed) tree := tview.NewTreeView(). SetRoot(root). SetCurrentNode(root) // A helper function which adds the files and directories of the given path // to the given target node. add := func(target *tview.TreeNode, path string) { files, err := os.ReadDir(path) if err != nil { panic(err) } for _, file := range files { node := tview.NewTreeNode(file.Name()). SetReference(filepath.Join(path, file.Name())). SetSelectable(file.IsDir()) if file.IsDir() { node.SetColor(tcell.ColorGreen) } target.AddChild(node) } } // Add the current directory to the root node. add(root, rootDir) // If a directory was selected, open it. tree.SetSelectedFunc(func(node *tview.TreeNode) { reference := node.GetReference() if reference == nil { return // Selecting the root node does nothing. } children := node.GetChildren() if len(children) == 0 { // Load and show files in this directory. path := reference.(string) add(node, path) } else { // Collapse if visible, expand if collapsed. node.SetExpanded(!node.IsExpanded()) } }) if err := tview.NewApplication().SetRoot(tree, true).EnableMouse(true).Run(); err != nil { panic(err) } } ================================================ FILE: demos/unicode/README.md ================================================ ![Screenshot](screenshot.png) ================================================ FILE: demos/unicode/main.go ================================================ // Demo code for unicode support (demonstrates wide Chinese characters). package main import ( "fmt" "github.com/rivo/tview" ) func main() { app := tview.NewApplication() pages := tview.NewPages() form := tview.NewForm() form.AddDropDown("称谓", []string{"先生", "女士", "博士", "老师", "师傅"}, 0, nil). AddInputField("姓名", "", 20, nil, nil). AddCheckbox("年龄 18+", false, nil). AddPasswordField("密码", "", 10, '*', nil). AddButton("保存", func() { _, title := form.GetFormItem(0).(*tview.DropDown).GetCurrentOption() userName := form.GetFormItem(1).(*tview.InputField).GetText() alert(pages, "alert-dialog", fmt.Sprintf("保存成功,%s %s!", userName, title)) }). AddButton("退出", func() { app.Stop() }) form.SetBorder(true).SetTitle("输入一些内容").SetTitleAlign(tview.AlignLeft) pages.AddPage("base", form, true, true) if err := app.SetRoot(pages, true).Run(); err != nil { panic(err) } } // alert shows a confirmation dialog. func alert(pages *tview.Pages, id string, message string) *tview.Pages { return pages.AddPage( id, tview.NewModal(). SetText(message). AddButtons([]string{"确定"}). SetDoneFunc(func(buttonIndex int, buttonLabel string) { pages.HidePage(id).RemovePage(id) }), false, true, ) } ================================================ FILE: doc.go ================================================ /* Package tview implements rich widgets for terminal based user interfaces. The widgets provided with this package are useful for data exploration and data entry. # Widgets The package implements the following widgets: - [TextView]: A scrollable window that display multi-colored text. Text may also be highlighted. - [TextArea]: An editable multi-line text area. - [Table]: A scrollable display of tabular data. Table cells, rows, or columns may also be highlighted. - [TreeView]: A scrollable display for hierarchical data. Tree nodes can be highlighted, collapsed, expanded, and more. - [List]: A navigable text list with optional keyboard shortcuts. - [InputField]: One-line input fields to enter text. - [DropDown]: Drop-down selection fields. - [Checkbox]: Selectable checkbox for boolean values. - [Image]: Displays images. - [Button]: Buttons which get activated when the user selects them. - [Form]: Forms composed of input fields, drop down selections, checkboxes, and buttons. - [Modal]: A centered window with a text message and one or more buttons. - [Grid]: A grid based layout manager. - [Flex]: A Flexbox based layout manager. - [Pages]: A page based layout manager. The package also provides Application which is used to poll the event queue and draw widgets on screen. # Hello World The following is a very basic example showing a box with the title "Hello, world!": package main import ( "github.com/rivo/tview" ) func main() { box := tview.NewBox().SetBorder(true).SetTitle("Hello, world!") if err := tview.NewApplication().SetRoot(box, true).Run(); err != nil { panic(err) } } First, we create a box primitive with a border and a title. Then we create an application, set the box as its root primitive, and run the event loop. The application exits when the application's [Application.Stop] function is called or when Ctrl-C is pressed. # More Demos You will find more demos in the "demos" subdirectory. It also contains a presentation (written using tview) which gives an overview of the different widgets and how they can be used. # Styles, Colors, and Hyperlinks Throughout this package, styles are specified using the [tcell.Style] type. Styles specify colors with the [tcell.Color] type. Functions such as [tcell.GetColor], [tcell.NewHexColor], and [tcell.NewRGBColor] can be used to create colors from W3C color names or RGB values. The [tcell.Style] type also allows you to specify text attributes such as "bold" or "italic" or a URL which some terminals use to display hyperlinks. Almost all strings which are displayed may contain style tags. A style tag's content is always wrapped in square brackets. In its simplest form, a style tag specifies the foreground color of the text. Colors in these tags are W3C color names or six hexadecimal digits following a hash tag. Examples: This is a [red]warning[white]! The sky is [#8080ff]blue[#ffffff]. A style tag changes the style of the characters following that style tag. There is no style stack and no nesting of style tags. Style tags are used in almost everything from box titles, list text, form item labels, to table cells. In a [TextView], this functionality has to be switched on explicitly. See the [TextView] documentation for more information. A style tag's full format looks like this: [:::] Each of the four fields can be left blank and trailing fields can be omitted. (Empty square brackets "[]", however, are not considered style tags.) Fields that are not specified will be left unchanged. A field with just a dash ("-") means "reset to default". You can specify the following flags to turn on certain attributes (some flags may not be supported by your terminal): l: blink b: bold i: italic d: dim r: reverse (switch foreground and background color) u: underline s: strike-through Use uppercase letters to turn off the corresponding attribute, for example, "B" to turn off bold. Uppercase letters have no effect if the attribute was not previously set. Setting a URL allows you to turn a piece of text into a hyperlink in some terminals. Specify a dash ("-") to specify the end of the hyperlink. Hyperlinks must only contain single-byte characters (e.g. ASCII) and they may not contain bracket characters ("[" or "]"). Examples: [yellow]Yellow text [yellow:red]Yellow text on red background [:red]Red background, text color unchanged [yellow::u]Yellow text underlined [::bl]Bold, blinking text [::-]Colors unchanged, flags reset [-]Reset foreground color [::i]Italic and [::I]not italic Click [:::https://example.com]here[:::-] for example.com. Send an email to [:::mailto:her@example.com]her/[:::mail:him@example.com]him/[:::mail:them@example.com]them[:::-]. [-:-:-:-]Reset everything [:]No effect []Not a valid style tag, will print square brackets as they are In the rare event that you want to display a string such as "[red]" or "[#00ff1a]" without applying its effect, you need to put an opening square bracket before the closing square bracket. Note that the text inside the brackets will be matched less strictly than region or colors tags. I.e. any character that may be used in color or region tags will be recognized. Examples: [red[] will be output as [red] ["123"[] will be output as ["123"] [#6aff00[[] will be output as [#6aff00[] [a#"[[[] will be output as [a#"[[] [] will be output as [] (see style tags above) [[] will be output as [[] (not an escaped tag) You can use the Escape() function to insert brackets automatically where needed. # Styles When primitives are instantiated, they are initialized with colors taken from the global [Styles] variable. You may change this variable to adapt the look and feel of the primitives to your preferred style. Note that most terminals will not report information about their color theme. This package therefore does not support using the terminal's color theme. The default style is a dark theme and you must change the [Styles] variable to switch to a light (or other) theme. # Unicode Support This package supports all unicode characters supported by your terminal. # Mouse Support If your terminal supports mouse events, you can enable mouse support for your application by calling [Application.EnableMouse]. Note that this may interfere with your terminal's default mouse behavior. Mouse support is disabled by default. # Concurrency Many functions in this package are not thread-safe. For many applications, this is not an issue: If your code makes changes in response to key events, the corresponding callback function will execute in the main goroutine and thus will not cause any race conditions. (Exceptions to this are documented.) If you access your primitives from other goroutines, however, you will need to synchronize execution. The easiest way to do this is to call [Application.QueueUpdate] or [Application.QueueUpdateDraw] (see the function documentation for details): go func() { app.QueueUpdateDraw(func() { table.SetCellSimple(0, 0, "Foo bar") }) }() One exception to this is the io.Writer interface implemented by [TextView]. You can safely write to a [TextView] from any goroutine. See the [TextView] documentation for details. You can also call [Application.Draw] from any goroutine without having to wrap it in [Application.QueueUpdate]. And, as mentioned above, key event callbacks are executed in the main goroutine and thus should not use [Application.QueueUpdate] as that may lead to deadlocks. It is also not necessary to call [Application.Draw] from such callbacks as it will be called automatically. # Type Hierarchy All widgets listed above contain the [Box] type. All of [Box]'s functions are therefore available for all widgets, too. Please note that if you are using the functions of [Box] on a subclass, they will return a *Box, not the subclass. This is a Golang limitation. So while tview supports method chaining in many places, these chains must be broken when using [Box]'s functions. Example: // This will cause "textArea" to be an empty Box. textArea := tview.NewTextArea(). SetMaxLength(256). SetPlaceholder("Enter text here"). SetBorder(true) You will need to call [Box.SetBorder] separately: textArea := tview.NewTextArea(). SetMaxLength(256). SetPlaceholder("Enter text here") texArea.SetBorder(true) All widgets also implement the [Primitive] interface. The tview package's rendering is based on version 2 of https://github.com/gdamore/tcell. It uses types and constants from that package (e.g. colors, styles, and keyboard values). */ package tview ================================================ FILE: dropdown.go ================================================ package tview import ( "regexp" "strings" "github.com/gdamore/tcell/v2" ) // dropDownOption is one option that can be selected in a drop-down primitive. type dropDownOption struct { Text string // The text to be displayed in the drop-down. Selected func() // The (optional) callback for when this option was selected. } // DropDown implements a selection widget whose options become visible in a // drop-down list when activated. // // See https://github.com/rivo/tview/wiki/DropDown for an example. type DropDown struct { *Box // Whether or not this drop-down is disabled/read-only. disabled bool // The options from which the user can choose. options []*dropDownOption // Strings to be placed before and after each drop-down option. optionPrefix, optionSuffix string // The index of the currently selected option. Negative if no option is // currently selected. currentOption int // Strings to be placed before and after the current option. currentOptionPrefix, currentOptionSuffix string // The text to be displayed when no option has yet been selected. noSelection string // Set to true if the options are visible and selectable. open bool // The input field containing the entered prefix for the current selection. // This is only visible when the drop-down is open. It never receives focus, // however. And it only receives events, we never call its Draw method. prefix *InputField // The list element for the options. list *List // The text to be displayed before the input area. label string // The label style. labelStyle tcell.Style // The field style. fieldStyle tcell.Style // The style of the field when it is focused and the drop-down is closed. focusedStyle tcell.Style // The style of the field when it is disabled. disabledStyle tcell.Style // The style of the prefix. prefixStyle tcell.Style // The screen width of the label area. A value of 0 means use the width of // the label text. labelWidth int // The screen width of the input area. A value of 0 means extend as much as // possible. fieldWidth int // An optional function which is called when the user indicated that they // are done selecting options. The key which was pressed is provided (tab, // shift-tab, or escape). done func(tcell.Key) // A callback function set by the Form class and called when the user leaves // this form item. finished func(tcell.Key) // A callback function which is called when the user changes the drop-down's // selection. selected func(text string, index int) dragging bool // Set to true when mouse dragging is in progress. } // NewDropDown returns a new [DropDown]. func NewDropDown() *DropDown { list := NewList() list.ShowSecondaryText(false). SetMainTextStyle(tcell.StyleDefault.Background(Styles.MoreContrastBackgroundColor).Foreground(Styles.PrimitiveBackgroundColor)). SetSelectedStyle(tcell.StyleDefault.Background(Styles.PrimaryTextColor).Foreground(Styles.PrimitiveBackgroundColor)). SetHighlightFullLine(true). SetBackgroundColor(Styles.MoreContrastBackgroundColor) prefix := NewInputField() box := NewBox() d := &DropDown{ Box: box, currentOption: -1, list: list, prefix: prefix, labelStyle: tcell.StyleDefault.Foreground(Styles.SecondaryTextColor), fieldStyle: tcell.StyleDefault.Background(Styles.ContrastBackgroundColor).Foreground(Styles.PrimaryTextColor), focusedStyle: tcell.StyleDefault.Background(Styles.PrimaryTextColor).Foreground(Styles.ContrastBackgroundColor), disabledStyle: tcell.StyleDefault.Background(box.backgroundColor).Foreground(Styles.SecondaryTextColor), prefixStyle: tcell.StyleDefault.Background(Styles.PrimaryTextColor).Foreground(Styles.ContrastBackgroundColor), } d.Box.Primitive = d return d } // SetCurrentOption sets the index of the currently selected option. This may // be a negative value to indicate that no option is currently selected. Calling // this function will also trigger the "selected" callback (if there is one). func (d *DropDown) SetCurrentOption(index int) *DropDown { if index >= 0 && index < len(d.options) { d.currentOption = index d.list.SetCurrentItem(index) if d.selected != nil { d.selected(d.options[index].Text, index) } if d.options[index].Selected != nil { d.options[index].Selected() } } else { d.currentOption = -1 d.list.SetCurrentItem(0) // Set to 0 because -1 means "last item". if d.selected != nil { d.selected("", -1) } } return d } // GetCurrentOption returns the index of the currently selected option as well // as its text. If no option was selected, -1 and an empty string is returned. func (d *DropDown) GetCurrentOption() (int, string) { var text string if d.currentOption >= 0 && d.currentOption < len(d.options) { text = d.options[d.currentOption].Text } return d.currentOption, text } // SetTextOptions sets the text to be placed before and after each drop-down // option (prefix/suffix), the text placed before and after the currently // selected option (currentPrefix/currentSuffix) as well as the text to be // displayed when no option is currently selected. Per default, all of these // strings are empty. func (d *DropDown) SetTextOptions(prefix, suffix, currentPrefix, currentSuffix, noSelection string) *DropDown { d.currentOptionPrefix = currentPrefix d.currentOptionSuffix = currentSuffix d.noSelection = noSelection d.optionPrefix = prefix d.optionSuffix = suffix for index := 0; index < d.list.GetItemCount(); index++ { d.list.SetItemText(index, prefix+d.options[index].Text+suffix, "") } return d } // SetUseStyleTags sets a flag that determines whether tags found in the option // texts are interpreted as tview tags. By default, this flag is enabled (for // backwards compatibility reasons). func (d *DropDown) SetUseStyleTags(useStyleTags bool) *DropDown { d.list.SetUseStyleTags(useStyleTags, useStyleTags) return d } // SetLabel sets the text to be displayed before the input area. func (d *DropDown) SetLabel(label string) *DropDown { d.label = label return d } // GetLabel returns the text to be displayed before the input area. func (d *DropDown) GetLabel() string { return d.label } // SetLabelWidth sets the screen width of the label. A value of 0 will cause the // primitive to use the width of the label string. func (d *DropDown) SetLabelWidth(width int) *DropDown { d.labelWidth = width return d } // SetLabelColor sets the color of the label. func (d *DropDown) SetLabelColor(color tcell.Color) *DropDown { d.labelStyle = d.labelStyle.Foreground(color) return d } // SetLabelStyle sets the style of the label. func (d *DropDown) SetLabelStyle(style tcell.Style) *DropDown { d.labelStyle = style return d } // SetFieldBackgroundColor sets the background color of the selected field. // This also overrides the prefix background color. func (d *DropDown) SetFieldBackgroundColor(color tcell.Color) *DropDown { d.fieldStyle = d.fieldStyle.Background(color) d.prefix.SetFieldBackgroundColor(color) return d } // SetFieldTextColor sets the text color of the options area. func (d *DropDown) SetFieldTextColor(color tcell.Color) *DropDown { d.fieldStyle = d.fieldStyle.Foreground(color) return d } // SetFieldStyle sets the style of the options area. func (d *DropDown) SetFieldStyle(style tcell.Style) *DropDown { d.fieldStyle = style return d } // SetFocusedStyle sets the style of the options area when the drop-down is // focused and closed. func (d *DropDown) SetFocusedStyle(style tcell.Style) *DropDown { d.focusedStyle = style return d } // SetDisabledStyle sets the style of the options area when the drop-down is // disabled. func (d *DropDown) SetDisabledStyle(style tcell.Style) *DropDown { d.disabledStyle = style return d } // SetPrefixTextColor sets the color of the prefix string. The prefix string is // shown when the user starts typing text, which directly selects the first // option that starts with the typed string. func (d *DropDown) SetPrefixTextColor(color tcell.Color) *DropDown { d.prefixStyle = d.prefixStyle.Foreground(color) return d } // SetPrefixStyle sets the style of the prefix string. The prefix string is // shown when the user starts typing text, which directly selects the first // option that starts with the typed string. func (d *DropDown) SetPrefixStyle(style tcell.Style) *DropDown { d.prefixStyle = style return d } // SetListStyles sets the styles of the items in the drop-down list (unselected // as well as selected items). Style attributes are currently ignored but may be // used in the future. func (d *DropDown) SetListStyles(unselected, selected tcell.Style) *DropDown { d.list.SetMainTextStyle(unselected).SetSelectedStyle(selected) _, bg, _ := unselected.Decompose() d.list.SetBackgroundColor(bg) return d } // SetFormAttributes sets attributes shared by all form items. func (d *DropDown) SetFormAttributes(labelWidth int, labelColor, bgColor, fieldTextColor, fieldBgColor tcell.Color) FormItem { d.labelWidth = labelWidth d.SetLabelColor(labelColor) d.SetBackgroundColor(bgColor) d.SetFieldStyle(tcell.StyleDefault.Foreground(fieldTextColor).Background(fieldBgColor)) return d } // SetFieldWidth sets the screen width of the options area. A value of 0 means // extend to as long as the longest option text. func (d *DropDown) SetFieldWidth(width int) *DropDown { d.fieldWidth = width return d } // GetFieldWidth returns this primitive's field screen width. func (d *DropDown) GetFieldWidth() int { if d.fieldWidth > 0 { return d.fieldWidth } fieldWidth := 0 for _, option := range d.options { width := TaggedStringWidth(option.Text) if width > fieldWidth { fieldWidth = width } } return fieldWidth } // GetFieldHeight returns this primitive's field height. func (d *DropDown) GetFieldHeight() int { return 1 } // SetDisabled sets whether or not the item is disabled / read-only. func (d *DropDown) SetDisabled(disabled bool) FormItem { d.disabled = disabled if d.finished != nil { d.finished(-1) } return d } // GetDisabled returns whether or not the item is disabled / read-only. func (d *DropDown) GetDisabled() bool { return d.disabled } // AddOption adds a new selectable option to this drop-down. The "selected" // callback is called when this option was selected. It may be nil. func (d *DropDown) AddOption(text string, selected func()) *DropDown { d.options = append(d.options, &dropDownOption{Text: text, Selected: selected}) d.list.AddItem(d.optionPrefix+text+d.optionSuffix, "", 0, nil) return d } // SetOptions replaces all current options with the ones provided and installs // one callback function which is called when one of the options is selected. // It will be called with the option's text and its index into the options // slice. The "selected" parameter may be nil. func (d *DropDown) SetOptions(texts []string, selected func(text string, index int)) *DropDown { d.list.Clear() d.options = nil for _, text := range texts { d.AddOption(text, nil) } d.selected = selected return d } // GetOptionCount returns the number of options in the drop-down. func (d *DropDown) GetOptionCount() int { return len(d.options) } // RemoveOption removes the specified option from the drop-down. Panics if the // index is out of range. If the currently selected option is removed, no option // will be selected. func (d *DropDown) RemoveOption(index int) *DropDown { if index == d.currentOption { d.currentOption = -1 } d.options = append(d.options[:index], d.options[index+1:]...) d.list.RemoveItem(index) return d } // SetSelectedFunc sets a handler which is called when the user changes the // drop-down's option. This handler will be called in addition and prior to // an option's optional individual handler. The handler is provided with the // selected option's text and index. If "no option" was selected, these values // are an empty string and -1. func (d *DropDown) SetSelectedFunc(handler func(text string, index int)) *DropDown { d.selected = handler return d } // SetDoneFunc sets a handler which is called when the user is done selecting // options. The callback function is provided with the key that was pressed, // which is one of the following: // // - KeyEscape: Abort selection. // - KeyTab: Move to the next field. // - KeyBacktab: Move to the previous field. func (d *DropDown) SetDoneFunc(handler func(key tcell.Key)) *DropDown { d.done = handler return d } // SetFinishedFunc sets a callback invoked when the user leaves this form item. func (d *DropDown) SetFinishedFunc(handler func(key tcell.Key)) FormItem { d.finished = handler return d } // Draw draws this primitive onto the screen. func (d *DropDown) Draw(screen tcell.Screen) { d.Box.DrawForSubclass(screen, d) // Prepare. x, y, width, height := d.GetInnerRect() rightLimit := x + width if height < 1 || rightLimit <= x { return } useStyleTags, _ := d.list.GetUseStyleTags() // Draw label. if d.labelWidth > 0 { labelWidth := d.labelWidth if labelWidth > rightLimit-x { labelWidth = rightLimit - x } printWithStyle(screen, d.label, x, y, 0, labelWidth, AlignLeft, d.labelStyle, true) x += labelWidth } else { _, _, drawnWidth := printWithStyle(screen, d.label, x, y, 0, rightLimit-x, AlignLeft, d.labelStyle, true) x += drawnWidth } // What's the longest option text? maxWidth := 0 for _, option := range d.options { str := d.optionPrefix + option.Text + d.optionSuffix if !useStyleTags { str = Escape(str) } strWidth := TaggedStringWidth(str) if strWidth > maxWidth { maxWidth = strWidth } str = d.currentOptionPrefix + option.Text + d.currentOptionSuffix if !useStyleTags { str = Escape(str) } strWidth = TaggedStringWidth(str) if strWidth > maxWidth { maxWidth = strWidth } } // Draw selection area. fieldWidth := d.fieldWidth if fieldWidth == 0 { fieldWidth = maxWidth if d.currentOption < 0 { noSelectionWidth := TaggedStringWidth(d.noSelection) if noSelectionWidth > fieldWidth { fieldWidth = noSelectionWidth } } else if d.currentOption < len(d.options) { currentOptionWidth := TaggedStringWidth(d.currentOptionPrefix + d.options[d.currentOption].Text + d.currentOptionSuffix) if currentOptionWidth > fieldWidth { fieldWidth = currentOptionWidth } } } if rightLimit-x < fieldWidth { fieldWidth = rightLimit - x } fieldStyle := d.fieldStyle if d.disabled { fieldStyle = d.disabledStyle } else if d.HasFocus() && !d.open { fieldStyle = d.focusedStyle } for index := 0; index < fieldWidth; index++ { screen.SetContent(x+index, y, ' ', nil, fieldStyle) } // Draw selected text. prefix := Escape(d.prefix.GetText()) if d.HasFocus() && d.open && len(prefix) > 0 { // The drop-down is open and we have an input prefix. // Draw current option prefix first. currentOptionPrefix := d.currentOptionPrefix currentOptionSuffix := d.currentOptionSuffix if !useStyleTags { currentOptionPrefix = Escape(currentOptionPrefix) currentOptionSuffix = Escape(currentOptionSuffix) } _, _, copWidth := printWithStyle(screen, currentOptionPrefix, x, y, 0, fieldWidth, AlignLeft, d.fieldStyle, false) if copWidth < fieldWidth { // Then draw the prefix. _, _, prefixWidth := printWithStyle(screen, prefix, x+copWidth, y, 0, fieldWidth-copWidth, AlignLeft, d.prefixStyle, false) if copWidth+prefixWidth < fieldWidth { // Then the current option remainder. var corWidth int currentItem := d.list.GetCurrentItem() if currentItem >= 0 && currentItem < len(d.options) { text := d.options[currentItem].Text if !useStyleTags { text = Escape(text) } _, _, corWidth = printWithStyle(screen, text, x+copWidth+prefixWidth, y, prefixWidth, fieldWidth-copWidth-prefixWidth, AlignLeft, d.fieldStyle, false) } if copWidth+prefixWidth+corWidth < fieldWidth { // And finally the current option suffix. printWithStyle(screen, currentOptionSuffix, x+copWidth+prefixWidth+corWidth, y, 0, fieldWidth-copWidth-prefixWidth-corWidth, AlignLeft, d.fieldStyle, false) } } } } else { // The drop-down is closed. Just draw the selected option. text := d.noSelection if d.currentOption >= 0 && d.currentOption < len(d.options) { text = d.currentOptionPrefix + d.options[d.currentOption].Text + d.currentOptionSuffix } if !useStyleTags { text = Escape(text) } printWithStyle(screen, text, x, y, 0, fieldWidth, AlignLeft, fieldStyle, false) } // Draw options list. if d.HasFocus() && d.open { lx := x ly := y + 1 lwidth := maxWidth lheight := len(d.options) swidth, sheight := screen.Size() // We prefer to align the left sides of the list and the main widget, but // if there is no space to the right, then shift the list to the left. if lx+lwidth >= swidth { lx = swidth - lwidth if lx < 0 { lx = 0 } } // We prefer to drop down but if there is no space, maybe drop up? if ly+lheight >= sheight && ly-2 > lheight-ly { ly = y - lheight if ly < 0 { ly = 0 } } if ly+lheight >= sheight { lheight = sheight - ly } d.list.SetRect(lx, ly, lwidth, lheight) d.list.Draw(screen) } } // InputHandler returns the handler for this primitive. func (d *DropDown) InputHandler() func(event *tcell.EventKey, setFocus func(p Primitive)) { return d.WrapInputHandler(func(event *tcell.EventKey, setFocus func(p Primitive)) { if d.disabled { return } // Process key event. switch key := event.Key(); key { case tcell.KeyDown, tcell.KeyUp, tcell.KeyHome, tcell.KeyEnd, tcell.KeyPgDn, tcell.KeyPgUp: // Open the list and forward the event to it. d.openList(setFocus) if handler := d.list.InputHandler(); handler != nil { handler(event, setFocus) } d.prefix.SetText("") case tcell.KeyEnter: // If the list is closed, open it. Otherwise, forward the event to // it. if !d.open { d.openList(setFocus) } else if handler := d.list.InputHandler(); handler != nil { handler(event, setFocus) } case tcell.KeyEscape, tcell.KeyTab, tcell.KeyBacktab: // Done selecting. if d.done != nil { d.done(key) } if d.finished != nil { d.finished(key) } d.closeList(setFocus) default: // Pass other key events to the input field. if handler := d.prefix.InputHandler(); handler != nil { handler(event, setFocus) } d.evalPrefix() d.openList(setFocus) } }) } // evalPrefix selects an item in the drop-down list based on the current prefix. func (d *DropDown) evalPrefix() { prefix := strings.ToLower(d.prefix.GetText()) if len(prefix) == 0 { return } useStyleTags, _ := d.list.GetUseStyleTags() for index, option := range d.options { text := option.Text if useStyleTags { text = stripTags(text) } if strings.HasPrefix(strings.ToLower(text), prefix) { d.list.SetCurrentItem(index) return } } } // openList hands control over to the embedded List primitive. func (d *DropDown) openList(setFocus func(Primitive)) { if d.open { return } d.open = true d.list.SetSelectedFunc(func(index int, mainText, secondaryText string, shortcut rune) { if d.dragging { return // If we're dragging the mouse, we don't want to trigger any events. } // An option was selected. Close the list again. d.currentOption = index d.closeList(setFocus) // Clear the prefix input field. d.prefix.SetText("") // Trigger "selected" event. currentOption := d.options[d.currentOption] if d.selected != nil { d.selected(currentOption.Text, d.currentOption) } if currentOption.Selected != nil { currentOption.Selected() } }).SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { switch key := event.Key(); key { case tcell.KeyDown, tcell.KeyUp, tcell.KeyPgDn, tcell.KeyPgUp, tcell.KeyHome, tcell.KeyEnd, tcell.KeyEnter: // Basic list navigation. break case tcell.KeyEscape: // Abort selection. d.closeList(setFocus) return nil default: // All other keys are passed to the input field. if handler := d.prefix.InputHandler(); handler != nil { handler(event, setFocus) } return nil } return event }) setFocus(d.list) } // closeList closes the embedded List element by hiding it and removing focus // from it. func (d *DropDown) closeList(setFocus func(Primitive)) { if !d.open { return } d.open = false if d.list.HasFocus() { setFocus(d) } } // IsOpen returns true if the drop-down list is currently open. func (d *DropDown) IsOpen() bool { return d.open } // Focus is called by the application when the primitive receives focus. func (d *DropDown) Focus(delegate func(p Primitive)) { // If we're part of a form and this item is disabled, there's nothing the // user can do here so we're finished. if d.finished != nil && d.disabled { d.finished(-1) return } if d.open { delegate(d.list) } else { d.Box.Focus(delegate) } } // focusChain implements the [Primitive]'s focusChain method. func (d *DropDown) focusChain(chain *[]Primitive) bool { if d.open { if hasFocus := d.list.focusChain(chain); hasFocus { if chain != nil { *chain = append(*chain, d) } return true } } return d.Box.focusChain(chain) } // MouseHandler returns the mouse handler for this primitive. func (d *DropDown) MouseHandler() func(action MouseAction, event *tcell.EventMouse, setFocus func(p Primitive)) (consumed bool, capture Primitive) { return d.WrapMouseHandler(func(action MouseAction, event *tcell.EventMouse, setFocus func(p Primitive)) (consumed bool, capture Primitive) { if d.disabled { return false, nil } // Was the mouse event in the drop-down box itself (or on its label)? x, y := event.Position() inRect := d.InInnerRect(x, y) if !d.open && !inRect { return d.InRect(x, y), nil // No, and it's not expanded either. Ignore. } // As long as the drop-down is open, we capture all mouse events. if d.open { capture = d } switch action { case MouseLeftDown: consumed = d.open || inRect capture = d if !d.open { d.openList(setFocus) d.dragging = true } else if consumed, _ := d.list.MouseHandler()(MouseLeftClick, event, setFocus); !consumed { d.closeList(setFocus) // Close drop-down if clicked outside of it. } case MouseMove: if d.dragging { // We pretend it's a left click so we can see the selection during // dragging. Because we don't act upon it, it's not a problem. d.list.MouseHandler()(MouseLeftClick, event, setFocus) consumed = true } case MouseLeftUp: if d.dragging { d.dragging = false d.list.MouseHandler()(MouseLeftClick, event, setFocus) consumed = true } } return }) } // PasteHandler returns the handler for this primitive. func (d *DropDown) PasteHandler() func(pastedText string, setFocus func(p Primitive)) { return d.WrapPasteHandler(func(pastedText string, setFocus func(p Primitive)) { if !d.open || d.disabled { return } // Strip any newline characters (simple version). pastedText = regexp.MustCompile(`\r?\n`).ReplaceAllString(pastedText, "") // Forward the pasted text to the input field. d.prefix.PasteHandler()(pastedText, setFocus) }) } ================================================ FILE: flex.go ================================================ package tview import ( "github.com/gdamore/tcell/v2" ) // Flex directions. const ( // One item per row. FlexRow = 0 // One item per column. FlexColumn = 1 // As defined in CSS, items distributed along a row. FlexRowCSS = 1 // As defined in CSS, items distributed within a column. FlexColumnCSS = 0 ) // flexItem holds layout options for one item. type flexItem struct { Item Primitive // The item to be positioned. May be nil for an empty item. FixedSize int // The item's fixed size which may not be changed, 0 if it has no fixed size. Proportion int // The item's proportion. Focus bool // Whether or not this item attracts the layout's focus. } // Flex is a basic implementation of the Flexbox layout. The contained // primitives are arranged horizontally or vertically. The way they are // distributed along that dimension depends on their layout settings, which is // either a fixed length or a proportional length. See AddItem() for details. // // See https://github.com/rivo/tview/wiki/Flex for an example. type Flex struct { *Box // The items to be positioned. items []*flexItem // FlexRow or FlexColumn. direction int // If set to true, Flex will use the entire screen as its available space // instead its box dimensions. fullScreen bool } // NewFlex returns a new flexbox layout container with no primitives and its // direction set to [FlexColumn]. To add primitives to this layout, see // [Flex.AddItem]. To change the direction, see [Flex.SetDirection]. // // Note that [Box], the superclass of Flex, will not clear its contents so that // any nil flex items will leave their background unchanged. To clear a Flex's // background before any items are drawn, set it to a new [Box]: // // flex.Box = NewBox() func NewFlex() *Flex { f := &Flex{ direction: FlexColumn, } f.Box = NewBox() f.Box.dontClear = true f.Box.Primitive = f return f } // SetDirection sets the direction in which the contained primitives are // distributed. This can be either FlexColumn (default) or FlexRow. Note that // these are the opposite of what you would expect coming from CSS. You may also // use FlexColumnCSS or FlexRowCSS, to remain in line with the CSS definition. func (f *Flex) SetDirection(direction int) *Flex { f.direction = direction return f } // SetFullScreen sets the flag which, when true, causes the flex layout to use // the entire screen space instead of whatever size it is currently assigned to. func (f *Flex) SetFullScreen(fullScreen bool) *Flex { f.fullScreen = fullScreen return f } // AddItem adds a new item to the container. The "fixedSize" argument is a width // or height that may not be changed by the layout algorithm. A value of 0 means // that its size is flexible and may be changed. The "proportion" argument // defines the relative size of the item compared to other flexible-size items. // For example, items with a proportion of 2 will be twice as large as items // with a proportion of 1. The proportion must be at least 1 if fixedSize == 0 // (ignored otherwise). // // If "focus" is set to true, the item will receive focus when the Flex // primitive receives focus. If multiple items have the "focus" flag set to // true, the first one will receive focus. // // You can provide a nil value for the primitive. This will still consume screen // space but nothing will be drawn. func (f *Flex) AddItem(item Primitive, fixedSize, proportion int, focus bool) *Flex { f.items = append(f.items, &flexItem{Item: item, FixedSize: fixedSize, Proportion: proportion, Focus: focus}) return f } // RemoveItem removes all items for the given primitive from the container, // keeping the order of the remaining items intact. func (f *Flex) RemoveItem(p Primitive) *Flex { for index := len(f.items) - 1; index >= 0; index-- { if f.items[index].Item == p { f.items = append(f.items[:index], f.items[index+1:]...) } } return f } // GetItemCount returns the number of items in this container. func (f *Flex) GetItemCount() int { return len(f.items) } // GetItem returns the primitive at the given index, starting with 0 for the // first primitive in this container. // // This function will panic for out of range indices. func (f *Flex) GetItem(index int) Primitive { return f.items[index].Item } // Clear removes all items from the container. func (f *Flex) Clear() *Flex { f.items = nil return f } // ResizeItem sets a new size for the item(s) with the given primitive. If there // are multiple Flex items with the same primitive, they will all receive the // same size. For details regarding the size parameters, see AddItem(). func (f *Flex) ResizeItem(p Primitive, fixedSize, proportion int) *Flex { for _, item := range f.items { if item.Item == p { item.FixedSize = fixedSize item.Proportion = proportion } } return f } // Draw draws this primitive onto the screen. func (f *Flex) Draw(screen tcell.Screen) { f.Box.DrawForSubclass(screen, f) // Calculate size and position of the items. // Do we use the entire screen? if f.fullScreen { width, height := screen.Size() f.SetRect(0, 0, width, height) } // How much space can we distribute? x, y, width, height := f.GetInnerRect() var proportionSum int distSize := width if f.direction == FlexRow { distSize = height } for _, item := range f.items { if item.FixedSize > 0 { distSize -= item.FixedSize } else { proportionSum += item.Proportion } } // Calculate positions and draw items. pos := x if f.direction == FlexRow { pos = y } for _, item := range f.items { size := item.FixedSize if size <= 0 { if proportionSum > 0 { size = distSize * item.Proportion / proportionSum distSize -= size proportionSum -= item.Proportion } else { size = 0 } } if item.Item != nil { if f.direction == FlexColumn { item.Item.SetRect(pos, y, size, height) } else { item.Item.SetRect(x, pos, width, size) } } pos += size if item.Item != nil { if item.Item.HasFocus() { defer item.Item.Draw(screen) } else { item.Item.Draw(screen) } } } } // Focus is called when this primitive receives focus. func (f *Flex) Focus(delegate func(p Primitive)) { for _, item := range f.items { if item.Item != nil && item.Focus { delegate(item.Item) return } } f.Box.Focus(delegate) } // focusChain implements the [Primitive]'s focusChain method. func (f *Flex) focusChain(chain *[]Primitive) bool { for _, item := range f.items { if item.Item == nil { continue } if hasFocus := item.Item.focusChain(chain); hasFocus { if chain != nil { *chain = append(*chain, f) } return true } } return f.Box.focusChain(chain) } // MouseHandler returns the mouse handler for this primitive. func (f *Flex) MouseHandler() func(action MouseAction, event *tcell.EventMouse, setFocus func(p Primitive)) (consumed bool, capture Primitive) { return f.WrapMouseHandler(func(action MouseAction, event *tcell.EventMouse, setFocus func(p Primitive)) (consumed bool, capture Primitive) { if !f.InRect(event.Position()) { return false, nil } // Pass mouse events along to the first child item that takes it. for _, item := range f.items { if item.Item == nil { continue } consumed, capture = item.Item.MouseHandler()(action, event, setFocus) if consumed { return } } return }) } // InputHandler returns the handler for this primitive. func (f *Flex) InputHandler() func(event *tcell.EventKey, setFocus func(p Primitive)) { return f.WrapInputHandler(func(event *tcell.EventKey, setFocus func(p Primitive)) { for _, i := range f.items { item := i.Item if item == nil || !item.HasFocus() { continue } if handler := item.InputHandler(); handler != nil { handler(event, setFocus) return } } }) } // PasteHandler returns the handler for this primitive. func (f *Flex) PasteHandler() func(pastedText string, setFocus func(p Primitive)) { return f.WrapPasteHandler(func(pastedText string, setFocus func(p Primitive)) { for _, item := range f.items { if item.Item != nil && item.Item.HasFocus() { if handler := item.Item.PasteHandler(); handler != nil { handler(pastedText, setFocus) return } } } }) } ================================================ FILE: form.go ================================================ package tview import ( "image" "github.com/gdamore/tcell/v2" ) var ( // DefaultFormFieldWidth is the default field screen width of form elements // whose field width is flexible (0). This is used in the Form class for // horizontal layouts. DefaultFormFieldWidth = 10 // DefaultFormFieldHeight is the default field height of multi-line form // elements whose field height is flexible (0). DefaultFormFieldHeight = 5 ) // FormItem is the interface all form items must implement to be able to be // included in a form. type FormItem interface { Primitive // GetLabel returns the item's label text. GetLabel() string // SetFormAttributes sets a number of item attributes at once. SetFormAttributes(labelWidth int, labelColor, bgColor, fieldTextColor, fieldBgColor tcell.Color) FormItem // GetFieldWidth returns the width of the form item's field (the area which // is manipulated by the user) in number of screen cells. A value of 0 // indicates the field width is flexible and may use as much space as // required. GetFieldWidth() int // GetFieldHeight returns the height of the form item's field (the area which // is manipulated by the user). This value must be greater than 0. GetFieldHeight() int // SetFinishedFunc sets the handler function for when the user finished // entering data into the item. The handler may receive events for the // Enter key (we're done), the Escape key (cancel input), the Tab key (move // to next field), the Backtab key (move to previous field), or a negative // value, indicating that the action for the last known key should be // repeated. SetFinishedFunc(handler func(key tcell.Key)) FormItem // SetDisabled sets whether or not the item is disabled / read-only. A form // must have at least one item that is not disabled. SetDisabled(disabled bool) FormItem // GetDisabled returns whether or not the item is disabled / read-only. GetDisabled() bool } // Form allows you to combine multiple one-line form elements into a vertical // or horizontal layout. Form elements include types such as InputField or // Checkbox. These elements can be optionally followed by one or more buttons // for which you can define form-wide actions (e.g. Save, Clear, Cancel). // // See https://github.com/rivo/tview/wiki/Form for an example. type Form struct { *Box // The items of the form (one row per item). items []FormItem // The buttons of the form. buttons []*Button // If set to true, instead of position items and buttons from top to bottom, // they are positioned from left to right. horizontal bool // The alignment of the buttons. buttonsAlign int // The number of empty cells between items. itemPadding int // The label color. labelColor tcell.Color // The style of the input area. fieldStyle tcell.Style // The style of the buttons when they are not focused. buttonStyle tcell.Style // The style of the buttons when they are focused. buttonActivatedStyle tcell.Style // The style of the buttons when they are disabled. buttonDisabledStyle tcell.Style // The index of the item or button for which the user requested focus. // Applied the next time the form itself receives focus. Negative if no // specific item was requested. requestedFocus int // A function to set the application's current focus. Does nothing // initially. setFocus func(Primitive) // The last (valid) key that wsa sent to a "finished" handler or -1 if no // such key is known yet. lastFinishedKey tcell.Key // An optional function which is called when the user hits Escape. cancel func() } // NewForm returns a new [Form]. func NewForm() *Form { box := NewBox().SetBorderPadding(1, 1, 1, 1) f := &Form{ Box: box, itemPadding: 1, labelColor: Styles.SecondaryTextColor, fieldStyle: tcell.StyleDefault.Background(Styles.ContrastBackgroundColor).Foreground(Styles.PrimaryTextColor), buttonStyle: tcell.StyleDefault.Background(Styles.ContrastBackgroundColor).Foreground(Styles.PrimaryTextColor), buttonActivatedStyle: tcell.StyleDefault.Background(Styles.PrimaryTextColor).Foreground(Styles.ContrastBackgroundColor), buttonDisabledStyle: tcell.StyleDefault.Background(Styles.ContrastBackgroundColor).Foreground(Styles.ContrastSecondaryTextColor), requestedFocus: -1, setFocus: func(Primitive) {}, lastFinishedKey: tcell.KeyTab, // To skip over inactive elements at the beginning of the form. } f.Box.Primitive = f return f } // SetItemPadding sets the number of empty rows between form items for vertical // layouts and the number of empty cells between form items for horizontal // layouts. In vertical layouts, there is always at least one empty line between // the last item and the buttons, if any. func (f *Form) SetItemPadding(padding int) *Form { f.itemPadding = padding return f } // SetHorizontal sets the direction the form elements are laid out. If set to // true, instead of positioning them from top to bottom (the default), they are // positioned from left to right, moving into the next row if there is not // enough space. func (f *Form) SetHorizontal(horizontal bool) *Form { f.horizontal = horizontal return f } // SetLabelColor sets the color of the labels. func (f *Form) SetLabelColor(color tcell.Color) *Form { f.labelColor = color return f } // SetFieldBackgroundColor sets the background color of the input areas. func (f *Form) SetFieldBackgroundColor(color tcell.Color) *Form { f.fieldStyle = f.fieldStyle.Background(color) return f } // SetFieldTextColor sets the text color of the input areas. func (f *Form) SetFieldTextColor(color tcell.Color) *Form { f.fieldStyle = f.fieldStyle.Foreground(color) return f } // SetFieldStyle sets the style of the input areas. Attributes are currently // still ignored to maintain backwards compatibility. func (f *Form) SetFieldStyle(style tcell.Style) *Form { f.fieldStyle = style return f } // SetButtonsAlign sets how the buttons align horizontally, one of AlignLeft // (the default), AlignCenter, and AlignRight. This is only func (f *Form) SetButtonsAlign(align int) *Form { f.buttonsAlign = align return f } // SetButtonBackgroundColor sets the background color of the buttons. This is // also the text color of the buttons when they are focused. func (f *Form) SetButtonBackgroundColor(color tcell.Color) *Form { f.buttonStyle = f.buttonStyle.Background(color) f.buttonActivatedStyle = f.buttonActivatedStyle.Foreground(color) return f } // SetButtonTextColor sets the color of the button texts. This is also the // background of the buttons when they are focused. func (f *Form) SetButtonTextColor(color tcell.Color) *Form { f.buttonStyle = f.buttonStyle.Foreground(color) f.buttonActivatedStyle = f.buttonActivatedStyle.Background(color) return f } // SetButtonStyle sets the style of the buttons when they are not focused. func (f *Form) SetButtonStyle(style tcell.Style) *Form { f.buttonStyle = style return f } // SetButtonActivatedStyle sets the style of the buttons when they are focused. func (f *Form) SetButtonActivatedStyle(style tcell.Style) *Form { f.buttonActivatedStyle = style return f } // SetButtonDisabledStyle sets the style of the buttons when they are disabled. func (f *Form) SetButtonDisabledStyle(style tcell.Style) *Form { f.buttonDisabledStyle = style return f } // SetFocus shifts the focus to the form element with the given index, counting // non-button items first and buttons last. This does not change the // application's focus immediately, but the next time the form itself receives // focus, the given element will be focused once. Set to a negative value to // focus the first (enabled) element. func (f *Form) SetFocus(index int) *Form { f.requestedFocus = index return f } // AddTextArea adds a text area to the form. It has a label, an optional initial // text, a size (width and height) referring to the actual input area (a // fieldWidth of 0 extends it as far right as possible, a fieldHeight of 0 will // cause it to be [DefaultFormFieldHeight]), and a maximum number of bytes of // text allowed (0 means no limit). // // The optional callback function is invoked when the content of the text area // has changed. Note that especially for larger texts, this is an expensive // operation due to technical constraints of the [TextArea] primitive (every key // stroke leads to a new reallocation of the entire text). func (f *Form) AddTextArea(label, text string, fieldWidth, fieldHeight, maxLength int, changed func(text string)) *Form { if fieldHeight == 0 { fieldHeight = DefaultFormFieldHeight } textArea := NewTextArea(). SetLabel(label). SetSize(fieldHeight, fieldWidth). SetMaxLength(maxLength) if text != "" { textArea.SetText(text, true) } if changed != nil { textArea.SetChangedFunc(func() { changed(textArea.GetText()) }) } textArea.SetFinishedFunc(f.finished) f.items = append(f.items, textArea) return f } // AddTextView adds a text view to the form. It has a label and text, a size // (width and height) referring to the actual text element (a fieldWidth of 0 // extends it as far right as possible, a fieldHeight of 0 will cause it to be // [DefaultFormFieldHeight]), a flag to turn on/off dynamic colors, and a flag // to turn on/off scrolling. If scrolling is turned off, the text view will not // receive focus. func (f *Form) AddTextView(label, text string, fieldWidth, fieldHeight int, dynamicColors, scrollable bool) *Form { if fieldHeight == 0 { fieldHeight = DefaultFormFieldHeight } textArea := NewTextView(). SetLabel(label). SetSize(fieldHeight, fieldWidth). SetDynamicColors(dynamicColors). SetScrollable(scrollable). SetText(text) textArea.SetFinishedFunc(f.finished) f.items = append(f.items, textArea) return f } // AddInputField adds an input field to the form. It has a label, an optional // initial value, a field width (a value of 0 extends it as far as possible), // an optional accept function to validate the item's value (set to nil to // accept any text), and an (optional) callback function which is invoked when // the input field's text has changed. func (f *Form) AddInputField(label, value string, fieldWidth int, accept func(textToCheck string, lastChar rune) bool, changed func(text string)) *Form { inputField := NewInputField(). SetLabel(label). SetText(value). SetFieldWidth(fieldWidth). SetAcceptanceFunc(accept). SetChangedFunc(changed) inputField.SetFinishedFunc(f.finished) f.items = append(f.items, inputField) return f } // AddPasswordField adds a password field to the form. This is similar to an // input field except that the user's input not shown. Instead, a "mask" // character is displayed. The password field has a label, an optional initial // value, a field width (a value of 0 extends it as far as possible), and an // (optional) callback function which is invoked when the input field's text has // changed. func (f *Form) AddPasswordField(label, value string, fieldWidth int, mask rune, changed func(text string)) *Form { if mask == 0 { mask = '*' } password := NewInputField(). SetLabel(label). SetText(value). SetFieldWidth(fieldWidth). SetMaskCharacter(mask). SetChangedFunc(changed) password.SetFinishedFunc(f.finished) f.items = append(f.items, password) return f } // AddDropDown adds a drop-down element to the form. It has a label, options, // and an (optional) callback function which is invoked when an option was // selected. The initial option may be a negative value to indicate that no // option is currently selected. func (f *Form) AddDropDown(label string, options []string, initialOption int, selected func(option string, optionIndex int)) *Form { dropDown := NewDropDown(). SetLabel(label). SetOptions(options, selected). SetCurrentOption(initialOption) dropDown.SetFinishedFunc(f.finished) f.items = append(f.items, dropDown) return f } // AddCheckbox adds a checkbox to the form. It has a label, an initial state, // and an (optional) callback function which is invoked when the state of the // checkbox was changed by the user. func (f *Form) AddCheckbox(label string, checked bool, changed func(checked bool)) *Form { checkbox := NewCheckbox(). SetLabel(label). SetChecked(checked). SetChangedFunc(changed) checkbox.SetFinishedFunc(f.finished) f.items = append(f.items, checkbox) return f } // AddImage adds an image to the form. It has a label and the image will fit in // the specified width and height (its aspect ratio is preserved). See // [Image.SetColors] for a description of the "colors" parameter. Images are not // interactive and are skipped over in a form. The "width" value may be 0 // (adjust dynamically) but "height" should generally be a positive value. func (f *Form) AddImage(label string, image image.Image, width, height, colors int) *Form { img := NewImage(). SetLabel(label). SetImage(image). SetSize(height, width). SetAlign(AlignTop, AlignLeft). SetColors(colors) img.SetFinishedFunc(f.finished) f.items = append(f.items, img) return f } // AddButton adds a new button to the form. The "selected" function is called // when the user selects this button. It may be nil. func (f *Form) AddButton(label string, selected func()) *Form { button := NewButton(label). SetSelectedFunc(selected). SetExitFunc(f.finished) f.buttons = append(f.buttons, button) return f } // GetButton returns the button at the specified 0-based index. Note that // buttons have been specially prepared for this form and modifying some of // their attributes may have unintended side effects. func (f *Form) GetButton(index int) *Button { return f.buttons[index] } // RemoveButton removes the button at the specified position, starting with 0 // for the button that was added first. func (f *Form) RemoveButton(index int) *Form { f.buttons = append(f.buttons[:index], f.buttons[index+1:]...) return f } // GetButtonCount returns the number of buttons in this form. func (f *Form) GetButtonCount() int { return len(f.buttons) } // GetButtonIndex returns the index of the button with the given label, starting // with 0 for the button that was added first. If no such label was found, -1 // is returned. func (f *Form) GetButtonIndex(label string) int { for index, button := range f.buttons { if button.GetLabel() == label { return index } } return -1 } // Clear removes all input elements from the form, including the buttons if // specified. func (f *Form) Clear(includeButtons bool) *Form { f.items = nil if includeButtons { f.ClearButtons() } return f } // ClearButtons removes all buttons from the form. func (f *Form) ClearButtons() *Form { f.buttons = nil return f } // AddFormItem adds a new item to the form. This can be used to add your own // objects to the form. Note, however, that the Form class will override some // of its attributes to make it work in the form context. Specifically, these // are: // // - The label width // - The label color // - The background color // - The field text color // - The field background color func (f *Form) AddFormItem(item FormItem) *Form { item.SetFinishedFunc(f.finished) f.items = append(f.items, item) return f } // GetFormItemCount returns the number of items in the form (not including the // buttons). func (f *Form) GetFormItemCount() int { return len(f.items) } // GetFormItem returns the form item at the given position, starting with index // 0. Elements are referenced in the order they were added. Buttons are not // included. func (f *Form) GetFormItem(index int) FormItem { return f.items[index] } // RemoveFormItem removes the form element at the given position, starting with // index 0. Elements are referenced in the order they were added. Buttons are // not included. func (f *Form) RemoveFormItem(index int) *Form { f.items = append(f.items[:index], f.items[index+1:]...) return f } // GetFormItemByLabel returns the first form element with the given label. If // no such element is found, nil is returned. Buttons are not searched and will // therefore not be returned. func (f *Form) GetFormItemByLabel(label string) FormItem { for _, item := range f.items { if item.GetLabel() == label { return item } } return nil } // GetFormItemIndex returns the index of the first form element with the given // label. If no such element is found, -1 is returned. Buttons are not searched // and will therefore not be returned. func (f *Form) GetFormItemIndex(label string) int { for index, item := range f.items { if item.GetLabel() == label { return index } } return -1 } // GetFocusedItemIndex returns the indices of the form element or button which // currently has focus. If they don't, -1 is returned respectively. func (f *Form) GetFocusedItemIndex() (formItem, button int) { index := f.focusIndex() if index < 0 { return -1, -1 } if index < len(f.items) { return index, -1 } return -1, index - len(f.items) } // SetCancelFunc sets a handler which is called when the user hits the Escape // key. func (f *Form) SetCancelFunc(callback func()) *Form { f.cancel = callback return f } // Draw draws this primitive onto the screen. func (f *Form) Draw(screen tcell.Screen) { f.Box.DrawForSubclass(screen, f) // Determine the dimensions. x, y, width, height := f.GetInnerRect() topLimit := y bottomLimit := y + height rightLimit := x + width startX := x // Find the longest label. var maxLabelWidth int for _, item := range f.items { labelWidth := TaggedStringWidth(item.GetLabel()) if labelWidth > maxLabelWidth { maxLabelWidth = labelWidth } } maxLabelWidth++ // Add one space. // Calculate positions of form items. type position struct{ x, y, width, height int } positions := make([]position, len(f.items)+len(f.buttons)) var ( focusedPosition position lineHeight = 1 ) for index, item := range f.items { // Calculate the space needed. labelWidth := TaggedStringWidth(item.GetLabel()) var itemWidth int if f.horizontal { fieldWidth := item.GetFieldWidth() if fieldWidth <= 0 { fieldWidth = DefaultFormFieldWidth } labelWidth++ itemWidth = labelWidth + fieldWidth } else { // We want all fields to align vertically. labelWidth = maxLabelWidth itemWidth = width } itemHeight := item.GetFieldHeight() if itemHeight <= 0 { itemHeight = DefaultFormFieldHeight } // Advance to next line if there is no space. if f.horizontal && x+labelWidth+1 >= rightLimit { x = startX y += lineHeight + 1 lineHeight = itemHeight } // Update line height. if itemHeight > lineHeight { lineHeight = itemHeight } // Adjust the item's attributes. if x+itemWidth >= rightLimit { itemWidth = rightLimit - x } fieldTextColor, fieldBackgroundColor, _ := f.fieldStyle.Decompose() item.SetFormAttributes( labelWidth, f.labelColor, f.backgroundColor, fieldTextColor, fieldBackgroundColor, ) // Save position. positions[index].x = x positions[index].y = y positions[index].width = itemWidth positions[index].height = itemHeight if item.HasFocus() { focusedPosition = positions[index] } // Advance to next item. if f.horizontal { x += itemWidth + f.itemPadding } else { y += itemHeight + f.itemPadding } } // How wide are the buttons? buttonWidths := make([]int, len(f.buttons)) buttonsWidth := 0 for index, button := range f.buttons { w := TaggedStringWidth(button.GetLabel()) + 4 buttonWidths[index] = w buttonsWidth += w + 1 } buttonsWidth-- // Where do we place them? if !f.horizontal && x+buttonsWidth < rightLimit { switch f.buttonsAlign { case AlignRight: x = rightLimit - buttonsWidth case AlignCenter: x = (x + rightLimit - buttonsWidth) / 2 } // In vertical layouts, buttons always appear after an empty line. if f.itemPadding == 0 && len(f.items) > 0 { y++ } } // Calculate positions of buttons. for index, button := range f.buttons { space := rightLimit - x buttonWidth := buttonWidths[index] if f.horizontal { if space < buttonWidth-4 { x = startX y += lineHeight + 1 space = width lineHeight = 1 } } else { if space < 1 { break // No space for this button anymore. } } if buttonWidth > space { buttonWidth = space } button.SetStyle(f.buttonStyle). SetActivatedStyle(f.buttonActivatedStyle). SetDisabledStyle(f.buttonDisabledStyle) buttonIndex := index + len(f.items) positions[buttonIndex].x = x positions[buttonIndex].y = y positions[buttonIndex].width = buttonWidth positions[buttonIndex].height = 1 if button.HasFocus() { focusedPosition = positions[buttonIndex] } x += buttonWidth + 1 } // Determine vertical offset based on the position of the focused item. var offset int if focusedPosition.y+focusedPosition.height > bottomLimit { offset = focusedPosition.y + focusedPosition.height - bottomLimit if focusedPosition.y-offset < topLimit { offset = focusedPosition.y - topLimit } } // Draw items. for index, item := range f.items { // Set position. y := positions[index].y - offset height := positions[index].height item.SetRect(positions[index].x, y, positions[index].width, height) // Is this item visible? if y+height <= topLimit || y >= bottomLimit { continue } // Draw items with focus last (in case of overlaps). if item.HasFocus() { defer item.Draw(screen) } else { item.Draw(screen) } } // Draw buttons. for index, button := range f.buttons { // Set position. buttonIndex := index + len(f.items) y := positions[buttonIndex].y - offset height := positions[buttonIndex].height button.SetRect(positions[buttonIndex].x, y, positions[buttonIndex].width, height) // Is this button visible? if y+height <= topLimit || y >= bottomLimit { continue } // Draw button. button.Draw(screen) } } // Focus is called by the application when the primitive receives focus. func (f *Form) Focus(delegate func(p Primitive)) { f.setFocus = delegate // If there is no current focus, pick one. focus := f.focusIndex() if f.requestedFocus >= 0 { focus = f.requestedFocus } // Delegate focus. for index, item := range f.items { if (focus < 0 || focus == index) && !item.GetDisabled() { f.requestedFocus = index delegate(item) return } } for index, button := range f.buttons { if (focus < 0 || focus == len(f.items)+index) && !button.GetDisabled() { f.requestedFocus = len(f.items) + index delegate(button) return } } f.Box.Focus(delegate) } // finished handles a form item's "finished" event. func (f *Form) finished(key tcell.Key) { focus := f.focusIndex() if key >= 0 { f.lastFinishedKey = key } totalCount := len(f.items) + len(f.buttons) switch key { case tcell.KeyTab, tcell.KeyEnter: // Find the next focusable item. for index := 0; index < totalCount; index++ { focus = (focus + 1) % totalCount if focus < len(f.items) { if !f.items[focus].GetDisabled() { f.setFocus(f.items[focus]) return } } else { if !f.buttons[focus-len(f.items)].GetDisabled() { f.setFocus(f.buttons[focus-len(f.items)]) return } } } case tcell.KeyBacktab: // Find the previous focusable item. for index := 0; index < totalCount; index++ { focus = (focus + totalCount - 1) % totalCount if focus < len(f.items) { if !f.items[focus].GetDisabled() { f.setFocus(f.items[focus]) return } } else { if !f.buttons[focus-len(f.items)].GetDisabled() { f.setFocus(f.buttons[focus-len(f.items)]) return } } } case tcell.KeyEscape: if f.cancel != nil { f.cancel() } default: if key < 0 && f.lastFinishedKey >= 0 { // Repeat the last action. f.finished(f.lastFinishedKey) } } } // focusIndex returns the index of the currently focused item, counting form // items first, then buttons. A negative value indicates that no containeed item // has focus. func (f *Form) focusIndex() int { for index, item := range f.items { if item.HasFocus() { return index } } for index, button := range f.buttons { if button.HasFocus() { return len(f.items) + index } } return -1 } // focusChain implements the [Primitive]'s focusChain method. func (f *Form) focusChain(chain *[]Primitive) bool { for _, item := range f.items { if hasFocus := item.focusChain(chain); hasFocus { if chain != nil { *chain = append(*chain, f) } return true } } for _, button := range f.buttons { if hasFocus := button.focusChain(chain); hasFocus { if chain != nil { *chain = append(*chain, f) } return true } } return f.Box.focusChain(chain) } // MouseHandler returns the mouse handler for this primitive. func (f *Form) MouseHandler() func(action MouseAction, event *tcell.EventMouse, setFocus func(p Primitive)) (consumed bool, capture Primitive) { return f.WrapMouseHandler(func(action MouseAction, event *tcell.EventMouse, setFocus func(p Primitive)) (consumed bool, capture Primitive) { // Determine items to pass mouse events to. for _, item := range f.items { if item.GetDisabled() { continue } consumed, capture = item.MouseHandler()(action, event, setFocus) if consumed { return } } for _, button := range f.buttons { if button.GetDisabled() { continue } consumed, capture = button.MouseHandler()(action, event, setFocus) if consumed { return } } // A mouse down anywhere else will focus this form. if action == MouseLeftDown && f.InRect(event.Position()) { f.Focus(setFocus) consumed = true } return }) } // InputHandler returns the handler for this primitive. func (f *Form) InputHandler() func(event *tcell.EventKey, setFocus func(p Primitive)) { return f.WrapInputHandler(func(event *tcell.EventKey, setFocus func(p Primitive)) { for _, item := range f.items { if item.HasFocus() { if handler := item.InputHandler(); handler != nil { handler(event, setFocus) return } } } for _, button := range f.buttons { if button.HasFocus() { if handler := button.InputHandler(); handler != nil { handler(event, setFocus) return } } } }) } // PasteHandler returns the handler for this primitive. func (f *Form) PasteHandler() func(pastedText string, setFocus func(p Primitive)) { return f.WrapPasteHandler(func(pastedText string, setFocus func(p Primitive)) { for _, item := range f.items { if item.HasFocus() { if handler := item.PasteHandler(); handler != nil { handler(pastedText, setFocus) return } } } for _, button := range f.buttons { if button.HasFocus() { if handler := button.PasteHandler(); handler != nil { handler(pastedText, setFocus) return } } } }) } ================================================ FILE: frame.go ================================================ package tview import ( "github.com/gdamore/tcell/v2" ) // frameText holds information about a line of text shown in the frame. type frameText struct { Text string // The text to be displayed. Header bool // true = place in header, false = place in footer. Align int // One of the Align constants. Color tcell.Color // The text color. } // Frame is a wrapper which adds space around another primitive. In addition, // the top area (header) and the bottom area (footer) may also contain text. // // See https://github.com/rivo/tview/wiki/Frame for an example. type Frame struct { *Box // The contained primitive. May be nil. primitive Primitive // The lines of text to be displayed. text []*frameText // Border spacing. top, bottom, header, footer, left, right int // Keep a reference in case we need it when we change the primitive. setFocus func(p Primitive) } // NewFrame returns a new [Frame] around the given primitive. The primitive's // size will be changed to fit within this frame. The primitive may be nil, in // which case no other primitive is embedded in the frame. func NewFrame(primitive Primitive) *Frame { box := NewBox() f := &Frame{ Box: box, primitive: primitive, top: 1, bottom: 1, header: 1, footer: 1, left: 1, right: 1, } f.Box.Primitive = f return f } // SetPrimitive replaces the contained primitive with the given one. To remove // a primitive, set it to nil. func (f *Frame) SetPrimitive(p Primitive) *Frame { var hasFocus bool if f.primitive != nil { hasFocus = f.primitive.HasFocus() } f.primitive = p if hasFocus && f.setFocus != nil { f.setFocus(p) // Restore focus. } return f } // GetPrimitive returns the primitive contained in this frame. func (f *Frame) GetPrimitive() Primitive { return f.primitive } // AddText adds text to the frame. Set "header" to true if the text is to appear // in the header, above the contained primitive. Set it to false for it to // appear in the footer, below the contained primitive. "align" must be one of // the Align constants. Rows in the header are printed top to bottom, rows in // the footer are printed bottom to top. Note that long text can overlap as // different alignments will be placed on the same row. func (f *Frame) AddText(text string, header bool, align int, color tcell.Color) *Frame { f.text = append(f.text, &frameText{ Text: text, Header: header, Align: align, Color: color, }) return f } // Clear removes all text from the frame. func (f *Frame) Clear() *Frame { f.text = nil return f } // SetBorders sets the width of the frame borders as well as "header" and // "footer", the vertical space between the header and footer text and the // contained primitive (does not apply if there is no text). func (f *Frame) SetBorders(top, bottom, header, footer, left, right int) *Frame { f.top, f.bottom, f.header, f.footer, f.left, f.right = top, bottom, header, footer, left, right return f } // Draw draws this primitive onto the screen. func (f *Frame) Draw(screen tcell.Screen) { f.Box.DrawForSubclass(screen, f) // Calculate start positions. x, top, width, height := f.GetInnerRect() bottom := top + height - 1 x += f.left top += f.top bottom -= f.bottom width -= f.left + f.right if width <= 0 || top >= bottom { return // No space left. } // Draw text. var rows [6]int // top-left, top-center, top-right, bottom-left, bottom-center, bottom-right. topMax := top bottomMin := bottom for _, text := range f.text { // Where do we place this text? var y int if text.Header { y = top + rows[text.Align] rows[text.Align]++ if y >= bottomMin { continue } if y+1 > topMax { topMax = y + 1 } } else { y = bottom - rows[3+text.Align] rows[3+text.Align]++ if y <= topMax { continue } if y-1 < bottomMin { bottomMin = y - 1 } } // Draw text. Print(screen, text.Text, x, y, width, text.Align, text.Color) } // Set the size of the contained primitive. if f.primitive != nil { if topMax > top { top = topMax + f.header } if bottomMin < bottom { bottom = bottomMin - f.footer } if top > bottom { return // No space for the primitive. } f.primitive.SetRect(x, top, width, bottom+1-top) // Finally, draw the contained primitive. f.primitive.Draw(screen) } } // Focus is called when this primitive receives focus. func (f *Frame) Focus(delegate func(p Primitive)) { f.setFocus = delegate if f.primitive != nil { delegate(f.primitive) } else { f.Box.Focus(delegate) } } // focusChain implements the [Primitive]'s focusChain method. func (f *Frame) focusChain(chain *[]Primitive) bool { if f.primitive != nil { if hasFocus := f.primitive.focusChain(chain); hasFocus { if chain != nil { *chain = append(*chain, f) } return true } } return f.Box.focusChain(chain) } // MouseHandler returns the mouse handler for this primitive. func (f *Frame) MouseHandler() func(action MouseAction, event *tcell.EventMouse, setFocus func(p Primitive)) (consumed bool, capture Primitive) { return f.WrapMouseHandler(func(action MouseAction, event *tcell.EventMouse, setFocus func(p Primitive)) (consumed bool, capture Primitive) { if !f.InRect(event.Position()) { return false, nil } // Pass mouse events on to contained primitive. if f.primitive != nil { consumed, capture = f.primitive.MouseHandler()(action, event, setFocus) if consumed { return true, capture } } // Clicking on the frame parts. if action == MouseLeftDown { setFocus(f) consumed = true } return }) } // InputHandler returns the handler for this primitive. func (f *Frame) InputHandler() func(event *tcell.EventKey, setFocus func(p Primitive)) { return f.WrapInputHandler(func(event *tcell.EventKey, setFocus func(p Primitive)) { if f.primitive == nil { return } if handler := f.primitive.InputHandler(); handler != nil { handler(event, setFocus) return } }) } // PasteHandler returns the handler for this primitive. func (f *Frame) PasteHandler() func(pastedText string, setFocus func(p Primitive)) { return f.WrapPasteHandler(func(pastedText string, setFocus func(p Primitive)) { if f.primitive == nil { return } if handler := f.primitive.PasteHandler(); handler != nil { handler(pastedText, setFocus) return } }) } ================================================ FILE: go.mod ================================================ module github.com/rivo/tview go 1.18 require ( github.com/gdamore/tcell/v2 v2.8.1 github.com/lucasb-eyer/go-colorful v1.2.0 github.com/rivo/uniseg v0.4.7 ) require ( github.com/gdamore/encoding v1.0.1 // indirect github.com/mattn/go-runewidth v0.0.16 // indirect golang.org/x/sys v0.29.0 // indirect golang.org/x/term v0.28.0 // indirect golang.org/x/text v0.21.0 // indirect ) ================================================ FILE: go.sum ================================================ github.com/gdamore/encoding v1.0.1 h1:YzKZckdBL6jVt2Gc+5p82qhrGiqMdG/eNs6Wy0u3Uhw= github.com/gdamore/encoding v1.0.1/go.mod h1:0Z0cMFinngz9kS1QfMjCP8TY7em3bZYeeklsSDPivEo= github.com/gdamore/tcell/v2 v2.8.1 h1:KPNxyqclpWpWQlPLx6Xui1pMk8S+7+R37h3g07997NU= github.com/gdamore/tcell/v2 v2.8.1/go.mod h1:bj8ori1BG3OYMjmb3IklZVWfZUJ1UBQt9JXrOCOhGWw= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc= github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.3/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU= golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU= golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY= golang.org/x/term v0.28.0 h1:/Ts8HFuMR2E6IP/jlo7QVLZHggjKQbhu/7H0LJFr3Gg= golang.org/x/term v0.28.0/go.mod h1:Sw/lC2IAUZ92udQNf3WodGtn4k/XoLyZoh8v/8uiwek= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= ================================================ FILE: grid.go ================================================ package tview import ( "math" "github.com/gdamore/tcell/v2" ) // gridItem represents one primitive and its possible position on a grid. type gridItem struct { Item Primitive // The item to be positioned. May be nil for an empty item. Row, Column int // The top-left grid cell where the item is placed. Width, Height int // The number of rows and columns the item occupies. MinGridWidth, MinGridHeight int // The minimum grid width/height for which this item is visible. Focus bool // Whether or not this item attracts the layout's focus. Only applicable for the first item for which this is set to true. visible bool // Whether or not this item was visible the last time the grid was drawn. x, y, w, h int // The last position of the item relative to the top-left corner of the grid. Undefined if visible is false. } // Grid is an implementation of a grid-based layout. It works by defining the // size of the rows and columns, then placing primitives into the grid. // // Some settings can lead to the grid exceeding its available space. SetOffset() // can then be used to scroll in steps of rows and columns. These offset values // can also be controlled with the arrow keys (or the "g","G", "j", "k", "h", // and "l" keys) while the grid has focus and none of its contained primitives // do. // // See https://github.com/rivo/tview/wiki/Grid for an example. type Grid struct { *Box // The items to be positioned. items []*gridItem // The definition of the rows and columns of the grid. See // [Grid.SetRows] / [Grid.SetColumns] for details. rows, columns []int // The minimum sizes for rows and columns. minWidth, minHeight int // The size of the gaps between neighboring primitives. This is automatically // set to 1 if borders is true. gapRows, gapColumns int // The number of rows and columns skipped before drawing the top-left corner // of the grid. rowOffset, columnOffset int // Whether or not borders are drawn around grid items. If this is set to true, // a gap size of 1 is automatically assumed (which is filled with the border // graphics). borders bool // The color of the borders around grid items. bordersColor tcell.Color } // NewGrid returns a new grid-based layout container with no initial primitives. // // Note that [Box], the superclass of Grid, will be transparent so that any grid // areas not covered by any primitives will leave their background unchanged. To // clear a [Grid]'s background before any items are drawn, reset its embedded // [Box]: // // grid.Box = NewBox() func NewGrid() *Grid { g := &Grid{ bordersColor: Styles.GraphicsColor, } g.Box = NewBox() g.Box.Primitive = g return g } // SetColumns defines how the columns of the grid are distributed. Each value // defines the size of one column, starting with the leftmost column. Values // greater than 0 represent absolute column widths (gaps not included). Values // less than or equal to 0 represent proportional column widths or fractions of // the remaining free space, where 0 is treated the same as -1. That is, a // column with a value of -3 will have three times the width of a column with a // value of -1 (or 0). The minimum width set with SetMinSize() is always // observed. // // Primitives may extend beyond the columns defined explicitly with this // function. A value of 0 is assumed for any undefined column. In fact, if you // never call this function, all columns occupied by primitives will have the // same width. On the other hand, unoccupied columns defined with this function // will always take their place. // // Assuming a total width of the grid of 100 cells and a minimum width of 0, the // following call will result in columns with widths of 30, 10, 15, 15, and 30 // cells: // // grid.SetColumns(30, 10, -1, -1, -2) // // If a primitive were then placed in the 6th and 7th column, the resulting // widths would be: 30, 10, 10, 10, 20, 10, and 10 cells. // // If you then called SetMinSize() as follows: // // grid.SetMinSize(15, 20) // // The resulting widths would be: 30, 15, 15, 15, 20, 15, and 15 cells, a total // of 125 cells, 25 cells wider than the available grid width. func (g *Grid) SetColumns(columns ...int) *Grid { g.columns = columns return g } // SetRows defines how the rows of the grid are distributed. These values behave // the same as the column values provided with [Grid.SetColumns], see there // for a definition and examples. // // The provided values correspond to row heights, the first value defining // the height of the topmost row. func (g *Grid) SetRows(rows ...int) *Grid { g.rows = rows return g } // SetSize is a shortcut for [Grid.SetRows] and [Grid.SetColumns] where // all row and column values are set to the given size values. See // [Grid.SetColumns] for details on sizes. func (g *Grid) SetSize(numRows, numColumns, rowSize, columnSize int) *Grid { g.rows = make([]int, numRows) for index := range g.rows { g.rows[index] = rowSize } g.columns = make([]int, numColumns) for index := range g.columns { g.columns[index] = columnSize } return g } // SetMinSize sets an absolute minimum width for rows and an absolute minimum // height for columns. Panics if negative values are provided. func (g *Grid) SetMinSize(row, column int) *Grid { if row < 0 || column < 0 { panic("Invalid minimum row/column size") } g.minHeight, g.minWidth = row, column return g } // SetGap sets the size of the gaps between neighboring primitives on the grid. // If borders are drawn (see SetBorders()), these values are ignored and a gap // of 1 is assumed. Panics if negative values are provided. func (g *Grid) SetGap(row, column int) *Grid { if row < 0 || column < 0 { panic("Invalid gap size") } g.gapRows, g.gapColumns = row, column return g } // SetBorders sets whether or not borders are drawn around grid items. Setting // this value to true will cause the gap values (see SetGap()) to be ignored and // automatically assumed to be 1 where the border graphics are drawn. func (g *Grid) SetBorders(borders bool) *Grid { g.borders = borders return g } // SetBordersColor sets the color of the item borders. func (g *Grid) SetBordersColor(color tcell.Color) *Grid { g.bordersColor = color return g } // AddItem adds a primitive and its position to the grid. The top-left corner // of the primitive will be located in the top-left corner of the grid cell at // the given row and column and will span "rowSpan" rows and "colSpan" columns. // For example, for a primitive to occupy rows 2, 3, and 4 and columns 5 and 6: // // grid.AddItem(p, 2, 5, 3, 2, 0, 0, true) // // If rowSpan or colSpan is 0, the primitive will not be drawn. // // You can add the same primitive multiple times with different grid positions. // The minGridWidth and minGridHeight values will then determine which of those // positions will be used. This is similar to CSS media queries. These minimum // values refer to the overall size of the grid. If multiple items for the same // primitive apply, the one with the highest minimum value (width or height, // whatever is higher) will be used, or the primitive added last if those values // are the same. Example: // // grid.AddItem(p, 0, 0, 0, 0, 0, 0, true). // Hide in small grids. // AddItem(p, 0, 0, 1, 2, 100, 0, true). // One-column layout for medium grids. // AddItem(p, 1, 1, 3, 2, 300, 0, true) // Multi-column layout for large grids. // // To use the same grid layout for all sizes, simply set minGridWidth and // minGridHeight to 0. // // If the item's focus is set to true, it will receive focus when the grid // receives focus. If there are multiple items with a true focus flag, the last // visible one that was added will receive focus. func (g *Grid) AddItem(p Primitive, row, column, rowSpan, colSpan, minGridHeight, minGridWidth int, focus bool) *Grid { g.items = append(g.items, &gridItem{ Item: p, Row: row, Column: column, Height: rowSpan, Width: colSpan, MinGridHeight: minGridHeight, MinGridWidth: minGridWidth, Focus: focus, }) return g } // RemoveItem removes all items for the given primitive from the grid, keeping // the order of the remaining items intact. func (g *Grid) RemoveItem(p Primitive) *Grid { for index := len(g.items) - 1; index >= 0; index-- { if g.items[index].Item == p { g.items = append(g.items[:index], g.items[index+1:]...) } } return g } // Clear removes all items from the grid. func (g *Grid) Clear() *Grid { g.items = nil return g } // SetOffset sets the number of rows and columns which are skipped before // drawing the first grid cell in the top-left corner. As the grid will never // completely move off the screen, these values may be adjusted the next time // the grid is drawn. The actual position of the grid may also be adjusted such // that contained primitives that have focus remain visible. func (g *Grid) SetOffset(rows, columns int) *Grid { g.rowOffset, g.columnOffset = rows, columns return g } // GetOffset returns the current row and column offset (see SetOffset() for // details). func (g *Grid) GetOffset() (rows, columns int) { return g.rowOffset, g.columnOffset } // Focus is called when this primitive receives focus. func (g *Grid) Focus(delegate func(p Primitive)) { for _, item := range g.items { if item.Focus { delegate(item.Item) return } } g.Box.Focus(delegate) } // focusChain implements the [Primitive]'s focusChain method. func (g *Grid) focusChain(chain *[]Primitive) bool { for _, item := range g.items { if !item.visible { continue } if hasFocus := item.Item.focusChain(chain); hasFocus { if chain != nil { *chain = append(*chain, g) } return true } } return g.Box.focusChain(chain) } // Draw draws this primitive onto the screen. func (g *Grid) Draw(screen tcell.Screen) { g.Box.dontClear = !g.Box.border // Avoid transparent parts inside a border. g.Box.DrawForSubclass(screen, g) x, y, width, height := g.GetInnerRect() screenWidth, screenHeight := screen.Size() // Make a list of items which apply. items := make([]*gridItem, 0, len(g.items)) ItemLoop: for _, item := range g.items { item.visible = false if item.Item == nil || item.Width <= 0 || item.Height <= 0 || width < item.MinGridWidth || height < item.MinGridHeight { continue // Disqualified. } // Check for overlaps and multiple layouts of the same item. for index, existing := range items { // Do they overlap or are identical? if item.Item != existing.Item && (item.Row >= existing.Row+existing.Height || item.Row+item.Height <= existing.Row || item.Column >= existing.Column+existing.Width || item.Column+item.Width <= existing.Column) { continue // They don't and aren't. } // What's their minimum size? itemMin := item.MinGridWidth if item.MinGridHeight > itemMin { itemMin = item.MinGridHeight } existingMin := existing.MinGridWidth if existing.MinGridHeight > existingMin { existingMin = existing.MinGridHeight } // Which one is more important? if itemMin < existingMin { continue ItemLoop // This one isn't. Drop it. } items[index] = item // This one is. Replace the other. continue ItemLoop } // This item will be visible. items = append(items, item) } // How many rows and columns do we have? rows := len(g.rows) columns := len(g.columns) for _, item := range items { rowEnd := item.Row + item.Height if rowEnd > rows { rows = rowEnd } columnEnd := item.Column + item.Width if columnEnd > columns { columns = columnEnd } } if rows == 0 || columns == 0 { return // No content. } // Where are they located? rowPos := make([]int, rows) rowHeight := make([]int, rows) columnPos := make([]int, columns) columnWidth := make([]int, columns) // How much space do we distribute? remainingWidth := width remainingHeight := height proportionalWidth := 0 proportionalHeight := 0 for index, row := range g.rows { if row > 0 { if row < g.minHeight { row = g.minHeight } remainingHeight -= row rowHeight[index] = row } else if row == 0 { proportionalHeight++ } else { proportionalHeight += -row } } for index, column := range g.columns { if column > 0 { if column < g.minWidth { column = g.minWidth } remainingWidth -= column columnWidth[index] = column } else if column == 0 { proportionalWidth++ } else { proportionalWidth += -column } } if g.borders { remainingHeight -= rows + 1 remainingWidth -= columns + 1 } else { remainingHeight -= (rows - 1) * g.gapRows remainingWidth -= (columns - 1) * g.gapColumns } if rows > len(g.rows) { proportionalHeight += rows - len(g.rows) } if columns > len(g.columns) { proportionalWidth += columns - len(g.columns) } // Distribute proportional rows/columns. for index := 0; index < rows; index++ { row := 0 if index < len(g.rows) { row = g.rows[index] } if row > 0 { continue // Not proportional. We already know the width. } else if row == 0 { row = 1 } else { row = -row } rowAbs := row * remainingHeight / proportionalHeight remainingHeight -= rowAbs proportionalHeight -= row if rowAbs < g.minHeight { rowAbs = g.minHeight } rowHeight[index] = rowAbs } for index := 0; index < columns; index++ { column := 0 if index < len(g.columns) { column = g.columns[index] } if column > 0 { continue // Not proportional. We already know the height. } else if column == 0 { column = 1 } else { column = -column } columnAbs := column * remainingWidth / proportionalWidth remainingWidth -= columnAbs proportionalWidth -= column if columnAbs < g.minWidth { columnAbs = g.minWidth } columnWidth[index] = columnAbs } // Calculate row/column positions. var columnX, rowY int if g.borders { columnX++ rowY++ } for index, row := range rowHeight { rowPos[index] = rowY gap := g.gapRows if g.borders { gap = 1 } rowY += row + gap } for index, column := range columnWidth { columnPos[index] = columnX gap := g.gapColumns if g.borders { gap = 1 } columnX += column + gap } // Calculate primitive positions. var focus *gridItem // The item which has focus. for _, item := range items { px := columnPos[item.Column] py := rowPos[item.Row] var pw, ph int for index := 0; index < item.Height; index++ { ph += rowHeight[item.Row+index] } for index := 0; index < item.Width; index++ { pw += columnWidth[item.Column+index] } if g.borders { pw += item.Width - 1 ph += item.Height - 1 } else { pw += (item.Width - 1) * g.gapColumns ph += (item.Height - 1) * g.gapRows } item.x, item.y, item.w, item.h = px, py, pw, ph item.visible = true if item.Item.HasFocus() { focus = item } } // Calculate screen offsets. var offsetX, offsetY int add := 1 if !g.borders { add = g.gapRows } for index, height := range rowHeight { if index >= g.rowOffset { break } offsetY += height + add } if !g.borders { add = g.gapColumns } for index, width := range columnWidth { if index >= g.columnOffset { break } offsetX += width + add } // The focused item must be within the visible area. if focus != nil { if focus.y+focus.h-offsetY >= height { offsetY = focus.y - height + focus.h } if focus.y-offsetY < 0 { offsetY = focus.y } if focus.x+focus.w-offsetX >= width { offsetX = focus.x - width + focus.w } if focus.x-offsetX < 0 { offsetX = focus.x } } // Adjust row/column offsets based on this value. var from, to int for index, pos := range rowPos { if pos-offsetY < 0 { from = index + 1 } if pos-offsetY < height { to = index } } if g.rowOffset < from { g.rowOffset = from } if g.rowOffset > to { g.rowOffset = to } from, to = 0, 0 for index, pos := range columnPos { if pos-offsetX < 0 { from = index + 1 } if pos-offsetX < width { to = index } } if g.columnOffset < from { g.columnOffset = from } if g.columnOffset > to { g.columnOffset = to } // Draw primitives and borders. borderStyle := tcell.StyleDefault.Background(g.backgroundColor).Foreground(g.bordersColor) for _, item := range items { // Final primitive position. if !item.visible { continue } item.x -= offsetX item.y -= offsetY if item.x >= width || item.x+item.w <= 0 || item.y >= height || item.y+item.h <= 0 { item.visible = false continue } if item.x+item.w > width { item.w = width - item.x } if item.y+item.h > height { item.h = height - item.y } if item.x < 0 { item.w += item.x item.x = 0 } if item.y < 0 { item.h += item.y item.y = 0 } if item.w <= 0 || item.h <= 0 { item.visible = false continue } item.x += x item.y += y item.Item.SetRect(item.x, item.y, item.w, item.h) // Draw primitive. if item == focus { defer item.Item.Draw(screen) } else { item.Item.Draw(screen) } // Draw border around primitive. if g.borders { for bx := item.x; bx < item.x+item.w; bx++ { // Top/bottom lines. if bx < 0 || bx >= screenWidth { continue } by := item.y - 1 if by >= 0 && by < screenHeight { PrintJoinedSemigraphics(screen, bx, by, Borders.Horizontal, borderStyle) } by = item.y + item.h if by >= 0 && by < screenHeight { PrintJoinedSemigraphics(screen, bx, by, Borders.Horizontal, borderStyle) } } for by := item.y; by < item.y+item.h; by++ { // Left/right lines. if by < 0 || by >= screenHeight { continue } bx := item.x - 1 if bx >= 0 && bx < screenWidth { PrintJoinedSemigraphics(screen, bx, by, Borders.Vertical, borderStyle) } bx = item.x + item.w if bx >= 0 && bx < screenWidth { PrintJoinedSemigraphics(screen, bx, by, Borders.Vertical, borderStyle) } } bx, by := item.x-1, item.y-1 // Top-left corner. if bx >= 0 && bx < screenWidth && by >= 0 && by < screenHeight { PrintJoinedSemigraphics(screen, bx, by, Borders.TopLeft, borderStyle) } bx, by = item.x+item.w, item.y-1 // Top-right corner. if bx >= 0 && bx < screenWidth && by >= 0 && by < screenHeight { PrintJoinedSemigraphics(screen, bx, by, Borders.TopRight, borderStyle) } bx, by = item.x-1, item.y+item.h // Bottom-left corner. if bx >= 0 && bx < screenWidth && by >= 0 && by < screenHeight { PrintJoinedSemigraphics(screen, bx, by, Borders.BottomLeft, borderStyle) } bx, by = item.x+item.w, item.y+item.h // Bottom-right corner. if bx >= 0 && bx < screenWidth && by >= 0 && by < screenHeight { PrintJoinedSemigraphics(screen, bx, by, Borders.BottomRight, borderStyle) } } } } // MouseHandler returns the mouse handler for this primitive. func (g *Grid) MouseHandler() func(action MouseAction, event *tcell.EventMouse, setFocus func(p Primitive)) (consumed bool, capture Primitive) { return g.WrapMouseHandler(func(action MouseAction, event *tcell.EventMouse, setFocus func(p Primitive)) (consumed bool, capture Primitive) { if !g.InRect(event.Position()) { return false, nil } // Pass mouse events along to the first child item that takes it. for _, item := range g.items { if item.Item == nil { continue } consumed, capture = item.Item.MouseHandler()(action, event, setFocus) if consumed { return } } return }) } // InputHandler returns the handler for this primitive. func (g *Grid) InputHandler() func(event *tcell.EventKey, setFocus func(p Primitive)) { return g.WrapInputHandler(func(event *tcell.EventKey, setFocus func(p Primitive)) { if !g.hasFocus { // Pass event on to child primitive. for _, item := range g.items { if item != nil && item.Item.HasFocus() { if handler := item.Item.InputHandler(); handler != nil { handler(event, setFocus) return } } } return } // Process our own key events if we have direct focus. switch event.Key() { case tcell.KeyRune: switch event.Rune() { case 'g': g.rowOffset, g.columnOffset = 0, 0 case 'G': g.rowOffset = math.MaxInt32 case 'j': g.rowOffset++ case 'k': g.rowOffset-- case 'h': g.columnOffset-- case 'l': g.columnOffset++ } case tcell.KeyHome: g.rowOffset, g.columnOffset = 0, 0 case tcell.KeyEnd: g.rowOffset = math.MaxInt32 case tcell.KeyUp: g.rowOffset-- case tcell.KeyDown: g.rowOffset++ case tcell.KeyLeft: g.columnOffset-- case tcell.KeyRight: g.columnOffset++ } }) } // PasteHandler returns the handler for this primitive. func (g *Grid) PasteHandler() func(pastedText string, setFocus func(p Primitive)) { return g.WrapPasteHandler(func(pastedText string, setFocus func(p Primitive)) { for _, item := range g.items { if item != nil && item.Item.HasFocus() { if handler := item.Item.PasteHandler(); handler != nil { handler(pastedText, setFocus) return } } } }) } ================================================ FILE: image.go ================================================ package tview import ( "image" "math" "github.com/gdamore/tcell/v2" ) // Types of dithering applied to images. const ( DitheringNone = iota // No dithering. DitheringFloydSteinberg // Floyd-Steinberg dithering (the default). ) // The number of colors supported by true color terminals (R*G*B = 256*256*256). const TrueColor = 16777216 // This map describes what each block element looks like. A 1 bit represents a // pixel that is drawn, a 0 bit represents a pixel that is not drawn. The least // significant bit is the top left pixel, the most significant bit is the bottom // right pixel, moving row by row from left to right, top to bottom. var blockElements = map[rune]uint64{ BlockLowerOneEighthBlock: 0b1111111100000000000000000000000000000000000000000000000000000000, BlockLowerOneQuarterBlock: 0b1111111111111111000000000000000000000000000000000000000000000000, BlockLowerThreeEighthsBlock: 0b1111111111111111111111110000000000000000000000000000000000000000, BlockLowerHalfBlock: 0b1111111111111111111111111111111100000000000000000000000000000000, BlockLowerFiveEighthsBlock: 0b1111111111111111111111111111111111111111000000000000000000000000, BlockLowerThreeQuartersBlock: 0b1111111111111111111111111111111111111111111111110000000000000000, BlockLowerSevenEighthsBlock: 0b1111111111111111111111111111111111111111111111111111111100000000, BlockLeftSevenEighthsBlock: 0b0111111101111111011111110111111101111111011111110111111101111111, BlockLeftThreeQuartersBlock: 0b0011111100111111001111110011111100111111001111110011111100111111, BlockLeftFiveEighthsBlock: 0b0001111100011111000111110001111100011111000111110001111100011111, BlockLeftHalfBlock: 0b0000111100001111000011110000111100001111000011110000111100001111, BlockLeftThreeEighthsBlock: 0b0000011100000111000001110000011100000111000001110000011100000111, BlockLeftOneQuarterBlock: 0b0000001100000011000000110000001100000011000000110000001100000011, BlockLeftOneEighthBlock: 0b0000000100000001000000010000000100000001000000010000000100000001, BlockQuadrantLowerLeft: 0b0000111100001111000011110000111100000000000000000000000000000000, BlockQuadrantLowerRight: 0b1111000011110000111100001111000000000000000000000000000000000000, BlockQuadrantUpperLeft: 0b0000000000000000000000000000000000001111000011110000111100001111, BlockQuadrantUpperRight: 0b0000000000000000000000000000000011110000111100001111000011110000, BlockQuadrantUpperLeftAndLowerRight: 0b1111000011110000111100001111000000001111000011110000111100001111, } // pixel represents a character on screen used to draw part of an image. type pixel struct { style tcell.Style element rune // The block element. } // Image implements a widget that displays one image. The original image // (specified with [Image.SetImage]) is resized according to the specified size // (see [Image.SetSize]), using the specified number of colors (see // [Image.SetColors]), while applying dithering if necessary (see // [Image.SetDithering]). // // Images are approximated by graphical characters in the terminal. The // resolution is therefore limited by the number and type of characters that can // be drawn in the terminal and the colors available in the terminal. The // quality of the final image also depends on the terminal's font and spacing // settings, none of which are under the control of this package. Results may // vary. type Image struct { *Box // The image to be displayed. If nil, the widget will be empty. image image.Image // The size of the image. If a value is 0, the corresponding size is chosen // automatically based on the other size while preserving the image's aspect // ratio. If both are 0, the image uses as much space as possible. A // negative value represents a percentage, e.g. -50 means 50% of the // available space. width, height int // The number of colors to use. If 0, the number of colors is chosen based // on the terminal's capabilities. colors int // The dithering algorithm to use, one of the constants starting with // "ImageDithering". dithering int // The width of a terminal's cell divided by its height. aspectRatio float64 // Horizontal and vertical alignment, one of the "Align" constants. alignHorizontal, alignVertical int // The text to be displayed before the image. label string // The label style. labelStyle tcell.Style // The screen width of the label area. A value of 0 means use the width of // the label text. labelWidth int // The actual image size (in cells) when it was drawn the last time. lastWidth, lastHeight int // The actual image (in cells) when it was drawn the last time. The size of // this slice is lastWidth * lastHeight, indexed by y*lastWidth + x. pixels []pixel // A callback function set by the Form class and called when the user leaves // this form item. finished func(tcell.Key) } // NewImage returns a new [Image] widget with an empty image (use // [Image.SetImage] to specify the image to be displayed). The image will use // the widget's entire available space. The default dithering algorithm is set // to Floyd-Steinberg dithering. The terminal's cell aspect ratio defaults to // 0.5. func NewImage() *Image { i := &Image{ Box: NewBox(), dithering: DitheringFloydSteinberg, aspectRatio: 0.5, alignHorizontal: AlignCenter, alignVertical: AlignCenter, } i.Box.Primitive = i return i } // SetImage sets the image to be displayed. If nil, the widget will be empty. func (i *Image) SetImage(image image.Image) *Image { i.image = image i.lastWidth, i.lastHeight = 0, 0 return i } // SetSize sets the size of the image. Positive values refer to cells in the // terminal. Negative values refer to a percentage of the available space (e.g. // -50 means 50%). A value of 0 means that the corresponding size is chosen // automatically based on the other size while preserving the image's aspect // ratio. If both are 0, the image uses as much space as possible while still // preserving the aspect ratio. func (i *Image) SetSize(rows, columns int) *Image { i.width = columns i.height = rows return i } // SetColors sets the number of colors to use. This should be the number of // colors supported by the terminal. If 0, the number of colors is chosen based // on the TERM environment variable (which may or may not be reliable). // // Only the values 0, 2, 8, 256, and 16777216 ([TrueColor]) are supported. Other // values will be rounded up to the next supported value, to a maximum of // 16777216. // // The effect of using more colors than supported by the terminal is undefined. func (i *Image) SetColors(colors int) *Image { i.colors = colors i.lastWidth, i.lastHeight = 0, 0 return i } // GetColors returns the number of colors that will be used while drawing the // image. This is one of the values listed in [Image.SetColors], except 0 which // will be replaced by the actual number of colors used. func (i *Image) GetColors() int { switch { case i.colors == 0: return availableColors case i.colors <= 2: return 2 case i.colors <= 8: return 8 case i.colors <= 256: return 256 } return TrueColor } // SetDithering sets the dithering algorithm to use, one of the constants // starting with "Dithering", for example [DitheringFloydSteinberg] (the // default). Dithering is not applied when rendering in true-color. func (i *Image) SetDithering(dithering int) *Image { i.dithering = dithering i.lastWidth, i.lastHeight = 0, 0 return i } // SetAspectRatio sets the width of a terminal's cell divided by its height. // You may change the default of 0.5 if your terminal / font has a different // aspect ratio. This is used to calculate the size of the image if the // specified width or height is 0. The function will panic if the aspect ratio // is 0 or less. func (i *Image) SetAspectRatio(aspectRatio float64) *Image { if aspectRatio <= 0 { panic("aspect ratio must be greater than 0") } i.aspectRatio = aspectRatio i.lastWidth, i.lastHeight = 0, 0 return i } // SetAlign sets the vertical and horizontal alignment of the image within the // widget's space. The possible values are [AlignTop], [AlignCenter], and // [AlignBottom] for vertical alignment and [AlignLeft], [AlignCenter], and // [AlignRight] for horizontal alignment. The default is [AlignCenter] for both // (or [AlignTop] and [AlignLeft] if the image is part of a [Form]). func (i *Image) SetAlign(vertical, horizontal int) *Image { i.alignHorizontal = horizontal i.alignVertical = vertical return i } // SetLabel sets the text to be displayed before the image. func (i *Image) SetLabel(label string) *Image { i.label = label return i } // GetLabel returns the text to be displayed before the image. func (i *Image) GetLabel() string { return i.label } // SetLabelWidth sets the screen width of the label. A value of 0 will cause the // primitive to use the width of the label string. func (i *Image) SetLabelWidth(width int) *Image { i.labelWidth = width return i } // GetFieldWidth returns this primitive's field width. This is the image's width // or, if the width is 0 or less, the proportional width of the image based on // its height as returned by [Image.GetFieldHeight]. If there is no image, 0 is // returned. func (i *Image) GetFieldWidth() int { if i.width <= 0 { if i.image == nil { return 0 } bounds := i.image.Bounds() height := i.GetFieldHeight() return bounds.Dx() * height / bounds.Dy() } return i.width } // GetFieldHeight returns this primitive's field height. This is the image's // height or 8 if the height is 0 or less. func (i *Image) GetFieldHeight() int { if i.height <= 0 { return 8 } return i.height } // SetDisabled sets whether or not the item is disabled / read-only. func (i *Image) SetDisabled(disabled bool) FormItem { return i // Images are always read-only. } // GetDisabled returns whether or not the item is disabled / read-only. func (i *Image) GetDisabled() bool { return true // Images are always read-only. } // SetFormAttributes sets attributes shared by all form items. func (i *Image) SetFormAttributes(labelWidth int, labelColor, bgColor, fieldTextColor, fieldBgColor tcell.Color) FormItem { i.labelWidth = labelWidth i.backgroundColor = bgColor i.SetLabelStyle(tcell.StyleDefault.Foreground(labelColor).Background(bgColor)) i.lastWidth, i.lastHeight = 0, 0 return i } // SetLabelStyle sets the style of the label. func (i *Image) SetLabelStyle(style tcell.Style) *Image { i.labelStyle = style return i } // GetLabelStyle returns the style of the label. func (i *Image) GetLabelStyle() tcell.Style { return i.labelStyle } // SetFinishedFunc sets a callback invoked when the user leaves this form item. func (i *Image) SetFinishedFunc(handler func(key tcell.Key)) FormItem { i.finished = handler return i } // Focus is called when this primitive receives focus. func (i *Image) Focus(delegate func(p Primitive)) { // If we're part of a form, there's nothing the user can do here so we're // finished. if i.finished != nil { i.finished(-1) return } i.Box.Focus(delegate) } // render re-populates the [Image.pixels] slice based on the current settings, // if [Image.lastWidth] and [Image.lastHeight] don't match the current image's // size. It also sets the new image size in these two variables. func (i *Image) render() { // If there is no image, there are no pixels. if i.image == nil { i.pixels = nil return } // Calculate the new (terminal-space) image size. bounds := i.image.Bounds() imageWidth, imageHeight := bounds.Dx(), bounds.Dy() if i.aspectRatio != 1.0 { imageWidth = int(float64(imageWidth) / i.aspectRatio) } width, height := i.width, i.height _, _, innerWidth, innerHeight := i.GetInnerRect() if i.labelWidth > 0 { innerWidth -= i.labelWidth } else { innerWidth -= TaggedStringWidth(i.label) } if innerWidth <= 0 { i.pixels = nil return } if width == 0 && height == 0 { // Use all available space. width, height = innerWidth, innerHeight if adjustedWidth := imageWidth * height / imageHeight; adjustedWidth < width { width = adjustedWidth } else { height = imageHeight * width / imageWidth } } else { // Turn percentages into absolute values. if width < 0 { width = innerWidth * -width / 100 } if height < 0 { height = innerHeight * -height / 100 } if width == 0 { // Adjust the width. width = imageWidth * height / imageHeight } else if height == 0 { // Adjust the height. height = imageHeight * width / imageWidth } } if width <= 0 || height <= 0 { i.pixels = nil return } // If nothing has changed, we're done. if i.lastWidth == width && i.lastHeight == height { return } i.lastWidth, i.lastHeight = width, height // This could still be larger than the available space but that's ok for now. // Generate the initial pixels by resizing the image (8x8 per cell). pixels := i.resize() // Turn them into block elements with background/foreground colors. i.stamp(pixels) } // resize resizes the image to the current size and returns the result as a // slice of pixels. It is assumed that [Image.lastWidth] (w) and // [Image.lastHeight] (h) are positive, non-zero values, and the slice has a // size of 64*w*h, with each pixel being represented by 3 float64 values in the // range of 0-1. The factor of 64 is due to the fact that we calculate 8x8 // pixels per cell. func (i *Image) resize() [][3]float64 { // Because most of the time, we will be downsizing the image, we don't even // attempt to do any fancy interpolation. For each target pixel, we // calculate a weighted average of the source pixels using their coverage // area. bounds := i.image.Bounds() srcWidth, srcHeight := bounds.Dx(), bounds.Dy() tgtWidth, tgtHeight := i.lastWidth*8, i.lastHeight*8 coverageWidth, coverageHeight := float64(tgtWidth)/float64(srcWidth), float64(tgtHeight)/float64(srcHeight) pixels := make([][3]float64, tgtWidth*tgtHeight) weights := make([]float64, tgtWidth*tgtHeight) for srcY := bounds.Min.Y; srcY < bounds.Max.Y; srcY++ { for srcX := bounds.Min.X; srcX < bounds.Max.X; srcX++ { r32, g32, b32, _ := i.image.At(srcX, srcY).RGBA() r, g, b := float64(r32)/0xffff, float64(g32)/0xffff, float64(b32)/0xffff // Iterate over all target pixels. Outer loop is Y. startY := float64(srcY-bounds.Min.Y) * coverageHeight endY := startY + coverageHeight fromY, toY := int(startY), int(endY) for tgtY := fromY; tgtY <= toY && tgtY < tgtHeight; tgtY++ { coverageY := 1.0 if tgtY == fromY { coverageY -= math.Mod(startY, 1.0) } if tgtY == toY { coverageY -= 1.0 - math.Mod(endY, 1.0) } // Inner loop is X. startX := float64(srcX-bounds.Min.X) * coverageWidth endX := startX + coverageWidth fromX, toX := int(startX), int(endX) for tgtX := fromX; tgtX <= toX && tgtX < tgtWidth; tgtX++ { coverageX := 1.0 if tgtX == fromX { coverageX -= math.Mod(startX, 1.0) } if tgtX == toX { coverageX -= 1.0 - math.Mod(endX, 1.0) } // Add a weighted contribution to the target pixel. index := tgtY*tgtWidth + tgtX coverage := coverageX * coverageY pixels[index][0] += r * coverage pixels[index][1] += g * coverage pixels[index][2] += b * coverage weights[index] += coverage } } } } // Normalize the pixels. for index, weight := range weights { if weight > 0 { pixels[index][0] /= weight pixels[index][1] /= weight pixels[index][2] /= weight } } return pixels } // stamp takes the pixels generated by [Image.resize] and populates the // [Image.pixels] slice accordingly. func (i *Image) stamp(resized [][3]float64) { // For each 8x8 pixel block, we find the best block element to represent it, // given the available colors. i.pixels = make([]pixel, i.lastWidth*i.lastHeight) colors := i.GetColors() for row := 0; row < i.lastHeight; row++ { for col := 0; col < i.lastWidth; col++ { // Calculate an error for each potential block element + color. Keep // the one with the lowest error. // Note that the values in "resize" may lie outside [0, 1] due to // the error distribution during dithering. minMSE := math.MaxFloat64 // Mean squared error. var final [64][3]float64 // The final pixel values. for element, bits := range blockElements { // Calculate the average color for the pixels covered by the set // bits and unset bits. var ( bg, fg [3]float64 setBits float64 bit uint64 = 1 ) for y := 0; y < 8; y++ { for x := 0; x < 8; x++ { index := (row*8+y)*i.lastWidth*8 + (col*8 + x) if bits&bit != 0 { fg[0] += resized[index][0] fg[1] += resized[index][1] fg[2] += resized[index][2] setBits++ } else { bg[0] += resized[index][0] bg[1] += resized[index][1] bg[2] += resized[index][2] } bit <<= 1 } } for ch := 0; ch < 3; ch++ { fg[ch] /= setBits if fg[ch] < 0 { fg[ch] = 0 } else if fg[ch] > 1 { fg[ch] = 1 } bg[ch] /= 64 - setBits if bg[ch] < 0 { bg[ch] = 0 } if bg[ch] > 1 { bg[ch] = 1 } } // Quantize to the nearest acceptable color. for _, color := range []*[3]float64{&fg, &bg} { if colors == 2 { // Monochrome. The following weights correspond better // to human perception than the arithmetic mean. gray := 0.299*color[0] + 0.587*color[1] + 0.114*color[2] if gray < 0.5 { *color = [3]float64{0, 0, 0} } else { *color = [3]float64{1, 1, 1} } } else { for index, ch := range color { switch { case colors == 8: // Colors vary wildly for each terminal. Expect // suboptimal results. if ch < 0.5 { color[index] = 0 } else { color[index] = 1 } case colors == 256: color[index] = math.Round(ch*6) / 6 } } } } // Calculate the error (and the final pixel values). var ( mse float64 values [64][3]float64 valuesIndex int ) bit = 1 for y := 0; y < 8; y++ { for x := 0; x < 8; x++ { if bits&bit != 0 { values[valuesIndex] = fg } else { values[valuesIndex] = bg } index := (row*8+y)*i.lastWidth*8 + (col*8 + x) for ch := 0; ch < 3; ch++ { err := resized[index][ch] - values[valuesIndex][ch] mse += err * err } bit <<= 1 valuesIndex++ } } // Do we have a better match? if mse < minMSE { // Yes. Save it. minMSE = mse final = values index := row*i.lastWidth + col i.pixels[index].element = element i.pixels[index].style = tcell.StyleDefault. Foreground(tcell.NewRGBColor(int32(math.Min(255, fg[0]*255)), int32(math.Min(255, fg[1]*255)), int32(math.Min(255, fg[2]*255)))). Background(tcell.NewRGBColor(int32(math.Min(255, bg[0]*255)), int32(math.Min(255, bg[1]*255)), int32(math.Min(255, bg[2]*255)))) } } // Check if there is a shade block which results in a smaller error. // What's the overall average color? var avg [3]float64 for y := 0; y < 8; y++ { for x := 0; x < 8; x++ { index := (row*8+y)*i.lastWidth*8 + (col*8 + x) for ch := 0; ch < 3; ch++ { avg[ch] += resized[index][ch] / 64 } } } for ch := 0; ch < 3; ch++ { if avg[ch] < 0 { avg[ch] = 0 } else if avg[ch] > 1 { avg[ch] = 1 } } // Quantize and choose shade element. element := BlockFullBlock var fg, bg tcell.Color shades := []rune{' ', BlockLightShade, BlockMediumShade, BlockDarkShade, BlockFullBlock} if colors == 2 { // Monochrome. gray := 0.299*avg[0] + 0.587*avg[1] + 0.114*avg[2] // See above for details. shade := int(math.Round(gray * 4)) element = shades[shade] for ch := 0; ch < 3; ch++ { avg[ch] = float64(shade) / 4 } bg = tcell.ColorBlack fg = tcell.ColorWhite } else if colors == TrueColor { // True color. fg = tcell.NewRGBColor(int32(math.Min(255, avg[0]*255)), int32(math.Min(255, avg[1]*255)), int32(math.Min(255, avg[2]*255))) bg = fg } else { // 8 or 256 colors. steps := 1.0 if colors == 256 { steps = 6.0 } var ( lo, hi, pos [3]float64 shade float64 ) for ch := 0; ch < 3; ch++ { lo[ch] = math.Floor(avg[ch]*steps) / steps hi[ch] = math.Ceil(avg[ch]*steps) / steps if r := hi[ch] - lo[ch]; r > 0 { pos[ch] = (avg[ch] - lo[ch]) / r if math.Abs(pos[ch]-0.5) < math.Abs(shade-0.5) { shade = pos[ch] } } } shade = math.Round(shade * 4) element = shades[int(shade)] shade /= 4 for ch := 0; ch < 3; ch++ { // Find the closest channel value. best := math.Abs(avg[ch] - (lo[ch] + (hi[ch]-lo[ch])*shade)) // Start shade from lo to hi. if value := math.Abs(avg[ch] - (hi[ch] - (hi[ch]-lo[ch])*shade)); value < best { best = value // Swap lo and hi. lo[ch], hi[ch] = hi[ch], lo[ch] } if value := math.Abs(avg[ch] - lo[ch]); value < best { best = value // Use lo. hi[ch] = lo[ch] } if value := math.Abs(avg[ch] - hi[ch]); value < best { lo[ch] = hi[ch] // Use hi. } avg[ch] = lo[ch] + (hi[ch]-lo[ch])*shade // Quantize. } bg = tcell.NewRGBColor(int32(math.Min(255, lo[0]*255)), int32(math.Min(255, lo[1]*255)), int32(math.Min(255, lo[2]*255))) fg = tcell.NewRGBColor(int32(math.Min(255, hi[0]*255)), int32(math.Min(255, hi[1]*255)), int32(math.Min(255, hi[2]*255))) } // Calculate the error (and the final pixel values). var ( mse float64 values [64][3]float64 valuesIndex int ) for y := 0; y < 8; y++ { for x := 0; x < 8; x++ { index := (row*8+y)*i.lastWidth*8 + (col*8 + x) for ch := 0; ch < 3; ch++ { err := resized[index][ch] - avg[ch] mse += err * err } values[valuesIndex] = avg valuesIndex++ } } // Is this shade element better than the block element? if mse < minMSE { // Yes. Save it. final = values index := row*i.lastWidth + col i.pixels[index].element = element i.pixels[index].style = tcell.StyleDefault.Foreground(fg).Background(bg) } // Apply dithering. if colors < TrueColor && i.dithering == DitheringFloydSteinberg { // The dithering mask determines how the error is distributed. // Each element has three values: dx, dy, and weight (in 16th). var mask = [4][3]int{ {1, 0, 7}, {-1, 1, 3}, {0, 1, 5}, {1, 1, 1}, } // We dither the 8x8 block as a 2x2 block, transferring errors // to its 2x2 neighbors. for ch := 0; ch < 3; ch++ { for y := 0; y < 2; y++ { for x := 0; x < 2; x++ { // What's the error for this 4x4 block? var err float64 for dy := 0; dy < 4; dy++ { for dx := 0; dx < 4; dx++ { err += (final[(y*4+dy)*8+(x*4+dx)][ch] - resized[(row*8+(y*4+dy))*i.lastWidth*8+(col*8+(x*4+dx))][ch]) / 16 } } // Distribute it to the 2x2 neighbors. for _, dist := range mask { for dy := 0; dy < 4; dy++ { for dx := 0; dx < 4; dx++ { targetX, targetY := (x+dist[0])*4+dx, (y+dist[1])*4+dy if targetX < 0 || col*8+targetX >= i.lastWidth*8 || targetY < 0 || row*8+targetY >= i.lastHeight*8 { continue } resized[(row*8+targetY)*i.lastWidth*8+(col*8+targetX)][ch] -= err * float64(dist[2]) / 16 } } } } } } } } } } // Draw draws this primitive onto the screen. func (i *Image) Draw(screen tcell.Screen) { i.DrawForSubclass(screen, i) // Regenerate image if necessary. i.render() // Draw label. viewX, viewY, viewWidth, viewHeight := i.GetInnerRect() _, labelBg, _ := i.labelStyle.Decompose() if i.labelWidth > 0 { labelWidth := i.labelWidth if labelWidth > viewWidth { labelWidth = viewWidth } printWithStyle(screen, i.label, viewX, viewY, 0, labelWidth, AlignLeft, i.labelStyle, labelBg == tcell.ColorDefault) viewX += labelWidth viewWidth -= labelWidth } else { _, _, drawnWidth := printWithStyle(screen, i.label, viewX, viewY, 0, viewWidth, AlignLeft, i.labelStyle, labelBg == tcell.ColorDefault) viewX += drawnWidth viewWidth -= drawnWidth } // Determine image placement. x, y, width, height := viewX, viewY, i.lastWidth, i.lastHeight if i.alignHorizontal == AlignCenter { x += (viewWidth - width) / 2 } else if i.alignHorizontal == AlignRight { x += viewWidth - width } if i.alignVertical == AlignCenter { y += (viewHeight - height) / 2 } else if i.alignVertical == AlignBottom { y += viewHeight - height } // Draw the image. for row := 0; row < height; row++ { if y+row < viewY || y+row >= viewY+viewHeight { continue } for col := 0; col < width; col++ { if x+col < viewX || x+col >= viewX+viewWidth { continue } index := row*width + col screen.SetContent(x+col, y+row, i.pixels[index].element, nil, i.pixels[index].style) } } } ================================================ FILE: inputfield.go ================================================ package tview import ( "math" "strconv" "strings" "sync" "github.com/gdamore/tcell/v2" "github.com/rivo/uniseg" ) const ( AutocompletedNavigate = iota // The user navigated the autocomplete list (using the errow keys). AutocompletedTab // The user selected an autocomplete entry using the tab key. AutocompletedEnter // The user selected an autocomplete entry using the enter key. AutocompletedClick // The user selected an autocomplete entry by clicking the mouse button on it. ) // Predefined InputField acceptance functions. var ( // InputFieldInteger accepts integers. InputFieldInteger = func(text string, ch rune) bool { if text == "-" { return true } _, err := strconv.Atoi(text) return err == nil } // InputFieldFloat accepts floating-point numbers. InputFieldFloat = func(text string, ch rune) bool { if text == "-" || text == "." || text == "-." { return true } _, err := strconv.ParseFloat(text, 64) return err == nil } // InputFieldMaxLength returns an input field accept handler which accepts // input strings up to a given length. Use it like this: // // inputField.SetAcceptanceFunc(InputFieldMaxLength(10)) // Accept up to 10 characters. InputFieldMaxLength = func(maxLength int) func(text string, ch rune) bool { return func(text string, ch rune) bool { return len([]rune(text)) <= maxLength } } ) // InputField is a one-line box into which the user can enter text. Use // [InputField.SetAcceptanceFunc] to accept or reject input, // [InputField.SetChangedFunc] to listen for changes, and // [InputField.SetMaskCharacter] to hide input from onlookers (e.g. for password // input). // // The input field also has an optional autocomplete feature. It is initialized // by the [InputField.SetAutocompleteFunc] function. For more control over the // autocomplete drop-down's behavior, you can also set the // [InputField.SetAutocompletedFunc]. // // Navigation and editing is the same as for a [TextArea], with the following // exceptions: // // - Tab, BackTab, Enter, Escape: Finish editing. // // Note that while pressing Tab or Enter is intercepted by the input field, it // is possible to paste such characters into the input field, possibly resulting // in multi-line input. You can use [InputField.SetAcceptanceFunc] to prevent // this. // // If autocomplete functionality is configured: // // - Down arrow: Open the autocomplete drop-down. // - Tab, Enter: Select the current autocomplete entry. // // See https://github.com/rivo/tview/wiki/InputField for an example. type InputField struct { *Box // The text area providing the core functionality of the input field. textArea *TextArea // The screen width of the input area. A value of 0 means extend as much as // possible. fieldWidth int // An optional autocomplete function which receives the current text of the // input field and returns a slice of strings to be displayed in a drop-down // selection. autocomplete func(text string) []string // The List object which shows the selectable autocomplete entries. If not // nil, the list's main texts represent the current autocomplete entries. autocompleteList *List autocompleteListMutex sync.Mutex // The styles of the autocomplete entries. autocompleteStyles struct { main tcell.Style selected tcell.Style background tcell.Color useTags bool } // An optional function which is called when the user selects an // autocomplete entry. The text and index of the selected entry (within the // list) is provided, as well as the user action causing the selection (one // of the "Autocompleted" values). The function should return true if the // autocomplete list should be closed. If nil, the input field will be // updated automatically when the user navigates the autocomplete list. autocompleted func(text string, index int, source int) bool // An optional function which may reject the last character that was entered. accept func(text string, ch rune) bool // An optional function which is called when the input has changed. changed func(text string) // An optional function which is called when the user indicated that they // are done entering text. The key which was pressed is provided (tab, // shift-tab, enter, or escape). done func(tcell.Key) // A callback function set by the Form class and called when the user leaves // this form item. finished func(tcell.Key) } // NewInputField returns a new [InputField]. func NewInputField() *InputField { i := &InputField{ Box: NewBox(), textArea: NewTextArea().SetWrap(false), } i.textArea.SetChangedFunc(func() { if i.changed != nil { i.changed(i.textArea.GetText()) } }) i.textArea.textStyle = tcell.StyleDefault.Background(Styles.ContrastBackgroundColor).Foreground(Styles.PrimaryTextColor) i.textArea.placeholderStyle = tcell.StyleDefault.Background(Styles.ContrastBackgroundColor).Foreground(Styles.ContrastSecondaryTextColor) i.autocompleteStyles.main = tcell.StyleDefault.Background(Styles.MoreContrastBackgroundColor).Foreground(Styles.PrimitiveBackgroundColor) i.autocompleteStyles.selected = tcell.StyleDefault.Background(Styles.PrimaryTextColor).Foreground(Styles.PrimitiveBackgroundColor) i.autocompleteStyles.background = Styles.MoreContrastBackgroundColor i.autocompleteStyles.useTags = true i.Box.Primitive = i return i } // SetText sets the current text of the input field. This can be undone by the // user. Calling this function will also trigger a "changed" event. func (i *InputField) SetText(text string) *InputField { i.textArea.Replace(0, i.textArea.GetTextLength(), text) return i } // GetText returns the current text of the input field. func (i *InputField) GetText() string { return i.textArea.GetText() } // SetLabel sets the text to be displayed before the input area. func (i *InputField) SetLabel(label string) *InputField { i.textArea.SetLabel(label) return i } // GetLabel returns the text to be displayed before the input area. func (i *InputField) GetLabel() string { return i.textArea.GetLabel() } // SetLabelWidth sets the screen width of the label. A value of 0 will cause the // primitive to use the width of the label string. func (i *InputField) SetLabelWidth(width int) *InputField { i.textArea.SetLabelWidth(width) return i } // SetPlaceholder sets the text to be displayed when the input text is empty. func (i *InputField) SetPlaceholder(text string) *InputField { i.textArea.SetPlaceholder(text) return i } // SetLabelColor sets the text color of the label. func (i *InputField) SetLabelColor(color tcell.Color) *InputField { i.textArea.SetLabelStyle(i.textArea.GetLabelStyle().Foreground(color)) return i } // SetLabelStyle sets the style of the label. func (i *InputField) SetLabelStyle(style tcell.Style) *InputField { i.textArea.SetLabelStyle(style) return i } // GetLabelStyle returns the style of the label. func (i *InputField) GetLabelStyle() tcell.Style { return i.textArea.GetLabelStyle() } // SetFieldBackgroundColor sets the background color of the input area. func (i *InputField) SetFieldBackgroundColor(color tcell.Color) *InputField { i.textArea.SetTextStyle(i.textArea.GetTextStyle().Background(color)) return i } // SetFieldTextColor sets the text color of the input area. func (i *InputField) SetFieldTextColor(color tcell.Color) *InputField { i.textArea.SetTextStyle(i.textArea.GetTextStyle().Foreground(color)) return i } // SetFieldStyle sets the style of the input area (when no placeholder is // shown). func (i *InputField) SetFieldStyle(style tcell.Style) *InputField { i.textArea.SetTextStyle(style) return i } // GetFieldStyle returns the style of the input area (when no placeholder is // shown). func (i *InputField) GetFieldStyle() tcell.Style { return i.textArea.GetTextStyle() } // SetPlaceholderTextColor sets the text color of placeholder text. func (i *InputField) SetPlaceholderTextColor(color tcell.Color) *InputField { i.textArea.SetPlaceholderStyle(i.textArea.GetPlaceholderStyle().Foreground(color)) return i } // SetPlaceholderStyle sets the style of the input area (when a placeholder is // shown). func (i *InputField) SetPlaceholderStyle(style tcell.Style) *InputField { i.textArea.SetPlaceholderStyle(style) return i } // GetPlaceholderStyle returns the style of the input area (when a placeholder // is shown). func (i *InputField) GetPlaceholderStyle() tcell.Style { return i.textArea.GetPlaceholderStyle() } // SetAutocompleteStyles sets the colors and style of the autocomplete entries. // For details, see [List.SetMainTextStyle], [List.SetSelectedStyle], and // [Box.SetBackgroundColor]. func (i *InputField) SetAutocompleteStyles(background tcell.Color, main, selected tcell.Style) *InputField { i.autocompleteStyles.background = background i.autocompleteStyles.main = main i.autocompleteStyles.selected = selected return i } // SetAutocompleteUseTags sets whether or not the autocomplete entries may // contain style tags affecting their appearance. The default is true. func (i *InputField) SetAutocompleteUseTags(useTags bool) *InputField { i.autocompleteStyles.useTags = useTags return i } // SetFormAttributes sets attributes shared by all form items. func (i *InputField) SetFormAttributes(labelWidth int, labelColor, bgColor, fieldTextColor, fieldBgColor tcell.Color) FormItem { i.textArea.SetFormAttributes(labelWidth, labelColor, bgColor, fieldTextColor, fieldBgColor) return i } // SetFieldWidth sets the screen width of the input area. A value of 0 means // extend as much as possible. func (i *InputField) SetFieldWidth(width int) *InputField { i.fieldWidth = width return i } // GetFieldWidth returns this primitive's field width. func (i *InputField) GetFieldWidth() int { return i.fieldWidth } // GetFieldHeight returns this primitive's field height. func (i *InputField) GetFieldHeight() int { return 1 } // SetDisabled sets whether or not the item is disabled / read-only. func (i *InputField) SetDisabled(disabled bool) FormItem { i.textArea.SetDisabled(disabled) if i.finished != nil { i.finished(-1) } return i } // GetDisabled returns whether or not the item is disabled / read-only. func (i *InputField) GetDisabled() bool { return i.textArea.GetDisabled() } // SetMaskCharacter sets a character that masks user input on a screen. A value // of 0 disables masking. func (i *InputField) SetMaskCharacter(mask rune) *InputField { if mask == 0 { i.textArea.setTransform(nil) return i } maskStr := string(mask) maskWidth := uniseg.StringWidth(maskStr) i.textArea.setTransform(func(cluster, rest string, boundaries int) (newCluster string, newBoundaries int) { return maskStr, maskWidth << uniseg.ShiftWidth }) return i } // SetAutocompleteFunc sets an autocomplete callback function which may return // strings to be selected from a drop-down based on the current text of the // input field. The drop-down appears only if len(entries) > 0. The callback is // invoked in this function and whenever the current text changes or when // [InputField.Autocomplete] is called. Entries are cleared when the user // selects an entry or presses Escape. func (i *InputField) SetAutocompleteFunc(callback func(currentText string) (entries []string)) *InputField { i.autocomplete = callback i.Autocomplete() return i } // SetAutocompletedFunc sets a callback function which is invoked when the user // selects an entry from the autocomplete drop-down list. The function is passed // the text of the selected entry (stripped of any style tags), the index of the // entry, and the user action that caused the selection, for example // [AutocompletedNavigate]. It returns true if the autocomplete drop-down should // be closed after the callback returns or false if it should remain open, in // which case [InputField.Autocomplete] is called to update the drop-down's // contents. // // If no such callback is set (or nil is provided), the input field will be // updated with the selection any time the user navigates the autocomplete // drop-down list. So this function essentially gives you more control over the // autocomplete functionality. func (i *InputField) SetAutocompletedFunc(autocompleted func(text string, index int, source int) bool) *InputField { i.autocompleted = autocompleted return i } // Autocomplete invokes the autocomplete callback (if there is one, see // [InputField.SetAutocompleteFunc]). If the length of the returned autocomplete // entries slice is greater than 0, the input field will present the user with a // corresponding drop-down list the next time the input field is drawn. // // It is safe to call this function from any goroutine. Note that the input // field is not redrawn automatically unless called from the main goroutine // (e.g. in response to events). func (i *InputField) Autocomplete() *InputField { i.autocompleteListMutex.Lock() defer i.autocompleteListMutex.Unlock() if i.autocomplete == nil { return i } // Do we have any autocomplete entries? text := i.textArea.GetText() entries := i.autocomplete(text) if len(entries) == 0 { // No entries, no list. i.autocompleteList = nil return i } // Make a list if we have none. if i.autocompleteList == nil { i.autocompleteList = NewList() i.autocompleteList.ShowSecondaryText(false). SetMainTextStyle(i.autocompleteStyles.main). SetSelectedStyle(i.autocompleteStyles.selected). SetUseStyleTags(i.autocompleteStyles.useTags, i.autocompleteStyles.useTags). SetHighlightFullLine(true). SetBackgroundColor(i.autocompleteStyles.background) } // Fill it with the entries. currentIndex := i.autocompleteList.GetCurrentItem() var currentSelection string if currentIndex >= 0 && currentIndex < i.autocompleteList.GetItemCount() { currentSelection, _ = i.autocompleteList.GetItemText(currentIndex) } currentEntry := -1 suffixLength := math.MaxInt i.autocompleteList.Clear() for index, entry := range entries { i.autocompleteList.AddItem(entry, "", 0, nil) if currentSelection != "" && entry == currentSelection { currentEntry = index } if currentSelection == "" && strings.HasPrefix(entry, text) && len(entry)-len(text) < suffixLength { currentEntry = index suffixLength = len(text) - len(entry) } } // Set the selection if we have one. if currentEntry >= 0 { i.autocompleteList.SetCurrentItem(currentEntry) } return i } // SetAcceptanceFunc sets a handler which may reject the last character that was // entered, by returning false. The handler receives the text as it would be // after the change and the last character entered. If the handler is nil, all // input is accepted. The function is only called when a single rune is inserted // at the current cursor position. // // This package defines a number of variables prefixed with InputField which may // be used for common input (e.g. numbers, maximum text length). See for example // [InputFieldInteger]. // // When text is pasted, lastChar is 0. func (i *InputField) SetAcceptanceFunc(handler func(textToCheck string, lastChar rune) bool) *InputField { i.accept = handler return i } // SetChangedFunc sets a handler which is called whenever the text of the input // field has changed. It receives the current text (after the change). func (i *InputField) SetChangedFunc(handler func(text string)) *InputField { i.changed = handler return i } // SetDoneFunc sets a handler which is called when the user is done entering // text. The callback function is provided with the key that was pressed, which // is one of the following: // // - KeyEnter: Done entering text. // - KeyEscape: Abort text input. // - KeyTab: Move to the next field. // - KeyBacktab: Move to the previous field. func (i *InputField) SetDoneFunc(handler func(key tcell.Key)) *InputField { i.done = handler return i } // SetFinishedFunc sets a callback invoked when the user leaves this form item. func (i *InputField) SetFinishedFunc(handler func(key tcell.Key)) FormItem { i.finished = handler return i } // Focus is called when this primitive receives focus. func (i *InputField) Focus(delegate func(p Primitive)) { // If we're part of a form and this item is disabled, there's nothing the // user can do here so we're finished. if i.finished != nil && i.textArea.GetDisabled() { i.finished(-1) return } delegate(i.textArea) } // focusChain implements the [Primitive]'s focusChain method. func (i *InputField) focusChain(chain *[]Primitive) bool { if hasFocus := i.textArea.focusChain(chain); hasFocus { if chain != nil { *chain = append(*chain, i) } return true } return i.Box.focusChain(chain) } // Blur is called when this primitive loses focus. func (i *InputField) Blur() { i.Box.Blur() i.autocompleteList = nil // Hide the autocomplete drop-down. } // Draw draws this primitive onto the screen. func (i *InputField) Draw(screen tcell.Screen) { i.Box.DrawForSubclass(screen, i) // Prepare x, y, width, height := i.GetInnerRect() if height < 1 || width < 1 { return } // Resize text area. labelWidth := i.textArea.GetLabelWidth() if labelWidth == 0 { labelWidth = TaggedStringWidth(i.textArea.GetLabel()) } fieldWidth := i.fieldWidth if fieldWidth == 0 { fieldWidth = width - labelWidth } i.textArea.SetRect(x, y, labelWidth+fieldWidth, 1) i.textArea.setMinCursorPadding(fieldWidth-1, 1) // Draw text area. i.textArea.hasFocus = i.HasFocus() // Force cursor positioning. i.textArea.Draw(screen) // Draw autocomplete list. i.autocompleteListMutex.Lock() defer i.autocompleteListMutex.Unlock() if i.autocompleteList != nil && i.HasFocus() { // How much space do we need? lheight := i.autocompleteList.GetItemCount() lwidth := 0 for index := 0; index < lheight; index++ { entry, _ := i.autocompleteList.GetItemText(index) width := TaggedStringWidth(entry) if width > lwidth { lwidth = width } } // We prefer to drop down but if there is no space, maybe drop up? lx := x + labelWidth ly := y + 1 _, sheight := screen.Size() if ly+lheight >= sheight && ly-2 > lheight-ly { ly = y - lheight if ly < 0 { ly = 0 } } if ly+lheight >= sheight { lheight = sheight - ly } i.autocompleteList.SetRect(lx, ly, lwidth, lheight) i.autocompleteList.Draw(screen) } } // InputHandler returns the handler for this primitive. func (i *InputField) InputHandler() func(event *tcell.EventKey, setFocus func(p Primitive)) { return i.WrapInputHandler(func(event *tcell.EventKey, setFocus func(p Primitive)) { if i.textArea.GetDisabled() { return } // Trigger changed events. var skipAutocomplete bool currentText := i.textArea.GetText() defer func() { if skipAutocomplete { return } if i.textArea.GetText() != currentText { i.Autocomplete() } }() // If we have an autocomplete list, there are certain keys we will // forward to it. i.autocompleteListMutex.Lock() defer i.autocompleteListMutex.Unlock() if i.autocompleteList != nil { i.autocompleteList.SetChangedFunc(nil) i.autocompleteList.SetSelectedFunc(nil) switch key := event.Key(); key { case tcell.KeyEscape: // Close the list. i.autocompleteList = nil return case tcell.KeyEnter, tcell.KeyTab: // Intentional selection. index := i.autocompleteList.GetCurrentItem() text, _ := i.autocompleteList.GetItemText(index) if i.autocompleted != nil { source := AutocompletedEnter if key == tcell.KeyTab { source = AutocompletedTab } if i.autocompleted(stripTags(text), index, source) { i.autocompleteList = nil currentText = i.GetText() } } else { i.SetText(text) skipAutocomplete = true i.autocompleteList = nil } return case tcell.KeyDown, tcell.KeyUp, tcell.KeyPgDn, tcell.KeyPgUp: i.autocompleteList.SetChangedFunc(func(index int, text, secondaryText string, shortcut rune) { text = stripTags(text) if i.autocompleted != nil { if i.autocompleted(text, index, AutocompletedNavigate) { i.autocompleteList = nil currentText = i.GetText() } } else { i.SetText(text) currentText = stripTags(text) // We want to keep the autocomplete list open and unchanged. } }) i.autocompleteList.InputHandler()(event, setFocus) return } } // Finish up. finish := func(key tcell.Key) { if i.done != nil { i.done(key) } if i.finished != nil { i.finished(key) } } // Process special key events for the input field. switch key := event.Key(); key { case tcell.KeyDown: i.autocompleteListMutex.Unlock() // We're still holding a lock. i.Autocomplete() i.autocompleteListMutex.Lock() case tcell.KeyEnter, tcell.KeyEscape, tcell.KeyTab, tcell.KeyBacktab: finish(key) case tcell.KeyCtrlV: if i.accept != nil && !i.accept(i.textArea.getTextBeforeCursor()+i.textArea.GetClipboardText()+i.textArea.getTextAfterCursor(), 0) { return } i.textArea.InputHandler()(event, setFocus) case tcell.KeyRune: if event.Modifiers()&tcell.ModAlt == 0 && i.accept != nil { // Check if this rune is accepted. r := event.Rune() if !i.accept(i.textArea.getTextBeforeCursor()+string(r)+i.textArea.getTextAfterCursor(), r) { return } } fallthrough default: // Forward other key events to the text area. i.textArea.InputHandler()(event, setFocus) } }) } // MouseHandler returns the mouse handler for this primitive. func (i *InputField) MouseHandler() func(action MouseAction, event *tcell.EventMouse, setFocus func(p Primitive)) (consumed bool, capture Primitive) { return i.WrapMouseHandler(func(action MouseAction, event *tcell.EventMouse, setFocus func(p Primitive)) (consumed bool, capture Primitive) { if i.textArea.GetDisabled() { return false, nil } var skipAutocomplete bool currentText := i.GetText() defer func() { if skipAutocomplete { return } if i.textArea.GetText() != currentText { i.Autocomplete() } }() // If we have an autocomplete list, forward the mouse event to it. i.autocompleteListMutex.Lock() defer i.autocompleteListMutex.Unlock() if i.autocompleteList != nil { i.autocompleteList.SetChangedFunc(nil) i.autocompleteList.SetSelectedFunc(func(index int, text, secondaryText string, shortcut rune) { text = stripTags(text) if i.autocompleted != nil { if i.autocompleted(text, index, AutocompletedClick) { i.autocompleteList = nil currentText = i.GetText() } return } i.SetText(text) skipAutocomplete = true i.autocompleteList = nil }) if consumed, _ = i.autocompleteList.MouseHandler()(action, event, setFocus); consumed { setFocus(i) return } } // Is mouse event within the input field? x, y := event.Position() if !i.InRect(x, y) { return false, nil } // Forward mouse event to the text area. consumed, capture = i.textArea.MouseHandler()(action, event, setFocus) // Focus in any case. if action == MouseLeftDown && !consumed { setFocus(i) consumed = true } return }) } // PasteHandler returns the handler for this primitive. func (i *InputField) PasteHandler() func(pastedText string, setFocus func(p Primitive)) { return i.WrapPasteHandler(func(pastedText string, setFocus func(p Primitive)) { // Input field may be disabled. if i.textArea.GetDisabled() { return } // The autocomplete drop down may be open. i.autocompleteListMutex.Lock() defer i.autocompleteListMutex.Unlock() if i.autocompleteList != nil { return } // We may not accept this text. if i.accept != nil && !i.accept(i.textArea.getTextBeforeCursor()+pastedText+i.textArea.getTextAfterCursor(), 0) { return } // Forward the pasted text to the text area. i.textArea.PasteHandler()(pastedText, setFocus) }) } ================================================ FILE: list.go ================================================ package tview import ( "fmt" "strings" "github.com/gdamore/tcell/v2" ) // listItem represents one item in a List. type listItem struct { MainText string // The main text of the list item. SecondaryText string // A secondary text to be shown underneath the main text. Shortcut rune // The key to select the list item directly, 0 if there is no shortcut. Selected func() // The optional function which is called when the item is selected. } // List displays rows of items, each of which can be selected. List items can be // shown as a single line or as two lines. They can be selected by pressing // their assigned shortcut key, navigating to them and pressing Enter, or // clicking on them with the mouse. The following key binds are available: // // - Down arrow / tab: Move down one item. // - Up arrow / backtab: Move up one item. // - Home: Move to the first item. // - End: Move to the last item. // - Page down: Move down one page. // - Page up: Move up one page. // - Enter / Space: Select the current item. // - Right / left: Scroll horizontally. Only if the list is wider than the // available space. // // By default, list item texts can contain style tags. Use // [List.SetUseStyleTags] to disable this feature. // // See [List.SetChangedFunc] for a way to be notified when the user navigates // to a list item. See [List.SetSelectedFunc] for a way to be notified when a // list item was selected. // // See https://github.com/rivo/tview/wiki/List for an example. type List struct { *Box // The items of the list. items []*listItem // The index of the currently selected item. currentItem int // Whether or not to show the secondary item texts. showSecondaryText bool // The item main text style. mainTextStyle tcell.Style // The item secondary text style. secondaryTextStyle tcell.Style // The item shortcut text style. shortcutStyle tcell.Style // The style for selected items. selectedStyle tcell.Style // If true, the selection is only shown when the list has focus. selectedFocusOnly bool // If true, the entire row is highlighted when selected. highlightFullLine bool // Whether or not style tags can be used in the main text. mainStyleTags bool // Whether or not style tags can be used in the secondary text. secondaryStyleTags bool // Whether or not navigating the list will wrap around. wrapAround bool // The number of list items skipped at the top before the first item is // drawn. itemOffset int // The number of cells skipped on the left side of an item text. Shortcuts // are not affected. horizontalOffset int // An optional function which is called when the user has navigated to a // list item. changed func(index int, mainText, secondaryText string, shortcut rune) // An optional function which is called when a list item was selected. This // function will be called even if the list item defines its own callback. selected func(index int, mainText, secondaryText string, shortcut rune) // An optional function which is called when the user presses the Escape key. done func() } // NewList returns a new [List]. func NewList() *List { l := &List{ Box: NewBox(), showSecondaryText: true, wrapAround: true, mainTextStyle: tcell.StyleDefault.Foreground(Styles.PrimaryTextColor).Background(Styles.PrimitiveBackgroundColor), secondaryTextStyle: tcell.StyleDefault.Foreground(Styles.TertiaryTextColor).Background(Styles.PrimitiveBackgroundColor), shortcutStyle: tcell.StyleDefault.Foreground(Styles.SecondaryTextColor).Background(Styles.PrimitiveBackgroundColor), selectedStyle: tcell.StyleDefault.Foreground(Styles.PrimitiveBackgroundColor).Background(Styles.PrimaryTextColor), mainStyleTags: true, secondaryStyleTags: true, } l.Box.Primitive = l return l } // SetCurrentItem sets the currently selected item by its index, starting at 0 // for the first item. If a negative index is provided, items are referred to // from the back (-1 = last item, -2 = second-to-last item, and so on). Out of // range indices are clamped to the beginning/end. // // Calling this function triggers a "changed" event if the selection changes. func (l *List) SetCurrentItem(index int) *List { if index < 0 { index = len(l.items) + index } if index >= len(l.items) { index = len(l.items) - 1 } if index < 0 { index = 0 } if index != l.currentItem && l.changed != nil { item := l.items[index] l.changed(index, item.MainText, item.SecondaryText, item.Shortcut) } l.currentItem = index return l } // GetCurrentItem returns the index of the currently selected list item, // starting at 0 for the first item. func (l *List) GetCurrentItem() int { return l.currentItem } // SetOffset sets the number of items to be skipped (vertically) as well as the // number of cells skipped horizontally when the list is drawn. Note that one // item corresponds to two rows when there are secondary texts. Shortcuts are // always drawn. // // These values may change when the list is drawn to ensure the currently // selected item is visible and item texts move out of view. Users can also // modify these values by interacting with the list. func (l *List) SetOffset(items, horizontal int) *List { l.itemOffset = items l.horizontalOffset = horizontal return l } // GetOffset returns the number of items skipped while drawing, as well as the // number of cells item text is moved to the left. See also SetOffset() for more // information on these values. func (l *List) GetOffset() (int, int) { return l.itemOffset, l.horizontalOffset } // RemoveItem removes the item with the given index (starting at 0) from the // list. If a negative index is provided, items are referred to from the back // (-1 = last item, -2 = second-to-last item, and so on). Out of range indices // are clamped to the beginning/end, i.e. unless the list is empty, an item is // always removed. // // The currently selected item is shifted accordingly. If it is the one that is // removed, a "changed" event is fired, unless no items are left. func (l *List) RemoveItem(index int) *List { if len(l.items) == 0 { return l } // Adjust index. if index < 0 { index = len(l.items) + index } if index >= len(l.items) { index = len(l.items) - 1 } if index < 0 { index = 0 } // Remove item. l.items = append(l.items[:index], l.items[index+1:]...) // If there is nothing left, we're done. if len(l.items) == 0 { return l } // Shift current item. previousCurrentItem := l.currentItem if l.currentItem > index || l.currentItem == len(l.items) { l.currentItem-- } // Fire "changed" event for removed items. if previousCurrentItem == index && l.changed != nil { item := l.items[l.currentItem] l.changed(l.currentItem, item.MainText, item.SecondaryText, item.Shortcut) } return l } // SetMainTextColor sets the color of the items' main text. func (l *List) SetMainTextColor(color tcell.Color) *List { l.mainTextStyle = l.mainTextStyle.Foreground(color) return l } // SetMainTextStyle sets the style of the items' main text. Note that the // background color is ignored in order not to override the background color of // the list itself. func (l *List) SetMainTextStyle(style tcell.Style) *List { l.mainTextStyle = style return l } // SetSecondaryTextColor sets the color of the items' secondary text. func (l *List) SetSecondaryTextColor(color tcell.Color) *List { l.secondaryTextStyle = l.secondaryTextStyle.Foreground(color) return l } // SetSecondaryTextStyle sets the style of the items' secondary text. Note that // the background color is ignored in order not to override the background color // of the list itself. func (l *List) SetSecondaryTextStyle(style tcell.Style) *List { l.secondaryTextStyle = style return l } // SetShortcutColor sets the color of the items' shortcut. func (l *List) SetShortcutColor(color tcell.Color) *List { l.shortcutStyle = l.shortcutStyle.Foreground(color) return l } // SetShortcutStyle sets the style of the items' shortcut. Note that the // background color is ignored in order not to override the background color of // the list itself. func (l *List) SetShortcutStyle(style tcell.Style) *List { l.shortcutStyle = style return l } // SetSelectedTextColor sets the text color of selected items. Note that the // color of main text characters that are different from the main text color // (e.g. style tags) is maintained. func (l *List) SetSelectedTextColor(color tcell.Color) *List { l.selectedStyle = l.selectedStyle.Foreground(color) return l } // SetSelectedBackgroundColor sets the background color of selected items. func (l *List) SetSelectedBackgroundColor(color tcell.Color) *List { l.selectedStyle = l.selectedStyle.Background(color) return l } // SetSelectedStyle sets the style of the selected items. Note that the color of // main text characters that are different from the main text color (e.g. color // tags) is maintained. func (l *List) SetSelectedStyle(style tcell.Style) *List { l.selectedStyle = style return l } // SetUseStyleTags sets a flag which determines whether style tags are used in // the main and secondary texts. The default is true. func (l *List) SetUseStyleTags(mainStyleTags, secondaryStyleTags bool) *List { l.mainStyleTags = mainStyleTags l.secondaryStyleTags = secondaryStyleTags return l } // GetUseStyleTags returns whether style tags are used in the main and secondary // texts. func (l *List) GetUseStyleTags() (mainStyleTags, secondaryStyleTags bool) { return l.mainStyleTags, l.secondaryStyleTags } // SetSelectedFocusOnly sets a flag which determines when the currently selected // list item is highlighted. If set to true, selected items are only highlighted // when the list has focus. If set to false, they are always highlighted. func (l *List) SetSelectedFocusOnly(focusOnly bool) *List { l.selectedFocusOnly = focusOnly return l } // SetHighlightFullLine sets a flag which determines whether the colored // background of selected items spans the entire width of the view. If set to // true, the highlight spans the entire view. If set to false, only the text of // the selected item from beginning to end is highlighted. func (l *List) SetHighlightFullLine(highlight bool) *List { l.highlightFullLine = highlight return l } // ShowSecondaryText determines whether or not to show secondary item texts. func (l *List) ShowSecondaryText(show bool) *List { l.showSecondaryText = show return l } // SetWrapAround sets the flag that determines whether navigating the list will // wrap around. That is, navigating downwards on the last item will move the // selection to the first item (similarly in the other direction). If set to // false, the selection won't change when navigating downwards on the last item // or navigating upwards on the first item. func (l *List) SetWrapAround(wrapAround bool) *List { l.wrapAround = wrapAround return l } // SetChangedFunc sets the function which is called when the user navigates to // a list item. The function receives the item's index in the list of items // (starting with 0), its main text, secondary text, and its shortcut rune. // // This function is also called when the first item is added or when // SetCurrentItem() is called. func (l *List) SetChangedFunc(handler func(index int, mainText string, secondaryText string, shortcut rune)) *List { l.changed = handler return l } // SetSelectedFunc sets the function which is called when the user selects a // list item by pressing Enter on the current selection. The function receives // the item's index in the list of items (starting with 0), its main text, // secondary text, and its shortcut rune. func (l *List) SetSelectedFunc(handler func(int, string, string, rune)) *List { l.selected = handler return l } // GetSelectedFunc returns the function set with [List.SetSelectedFunc] or nil // if no such function was set. func (l *List) GetSelectedFunc() func(int, string, string, rune) { return l.selected } // SetDoneFunc sets a function which is called when the user presses the Escape // key. func (l *List) SetDoneFunc(handler func()) *List { l.done = handler return l } // AddItem calls [List.InsertItem] with an index of -1. func (l *List) AddItem(mainText, secondaryText string, shortcut rune, selected func()) *List { l.InsertItem(-1, mainText, secondaryText, shortcut, selected) return l } // InsertItem adds a new item to the list at the specified index. An index of 0 // will insert the item at the beginning, an index of 1 before the second item, // and so on. An index of [List.GetItemCount] or higher will insert the item at // the end of the list. Negative indices are also allowed: An index of -1 will // insert the item at the end of the list, an index of -2 before the last item, // and so on. An index of -GetItemCount()-1 or lower will insert the item at the // beginning. // // An item has a main text which will be highlighted when selected. It also has // a secondary text which is shown underneath the main text (if it is set to // visible) but which may remain empty. // // The shortcut is a key binding. If the specified rune is entered, the item // is selected immediately. Set to 0 for no binding. // // The "selected" callback will be invoked when the user selects the item. You // may provide nil if no such callback is needed or if all events are handled // through the selected callback set with [List.SetSelectedFunc]. // // The currently selected item will shift its position accordingly. If the list // was previously empty, a "changed" event is fired because the new item becomes // selected. func (l *List) InsertItem(index int, mainText, secondaryText string, shortcut rune, selected func()) *List { item := &listItem{ MainText: mainText, SecondaryText: secondaryText, Shortcut: shortcut, Selected: selected, } // Shift index to range. if index < 0 { index = len(l.items) + index + 1 } if index < 0 { index = 0 } else if index > len(l.items) { index = len(l.items) } // Shift current item. if l.currentItem < len(l.items) && l.currentItem >= index { l.currentItem++ } // Insert item (make space for the new item, then shift and insert). l.items = append(l.items, nil) if index < len(l.items)-1 { // -1 because l.items has already grown by one item. copy(l.items[index+1:], l.items[index:]) } l.items[index] = item // Fire a "change" event for the first item in the list. if len(l.items) == 1 && l.changed != nil { item := l.items[0] l.changed(0, item.MainText, item.SecondaryText, item.Shortcut) } return l } // GetItemCount returns the number of items in the list. func (l *List) GetItemCount() int { return len(l.items) } // GetItemSelectedFunc returns the function which is called when the user // selects the item with the given index, if such a function was set. If no // function was set, nil is returned. Panics if the index is out of range. func (l *List) GetItemSelectedFunc(index int) func() { return l.items[index].Selected } // GetItemText returns an item's texts (main and secondary). Panics if the index // is out of range. func (l *List) GetItemText(index int) (main, secondary string) { return l.items[index].MainText, l.items[index].SecondaryText } // SetItemText sets an item's main and secondary text. Panics if the index is // out of range. func (l *List) SetItemText(index int, main, secondary string) *List { item := l.items[index] item.MainText = main item.SecondaryText = secondary return l } // FindItems searches the main and secondary texts for the given strings and // returns a list of item indices in which those strings are found. One of the // two search strings may be empty, it will then be ignored. Indices are always // returned in ascending order. // // If mustContainBoth is set to true, mainSearch must be contained in the main // text AND secondarySearch must be contained in the secondary text. If it is // false, only one of the two search strings must be contained. // // Set ignoreCase to true for case-insensitive search. func (l *List) FindItems(mainSearch, secondarySearch string, mustContainBoth, ignoreCase bool) (indices []int) { if mainSearch == "" && secondarySearch == "" { return } if ignoreCase { mainSearch = strings.ToLower(mainSearch) secondarySearch = strings.ToLower(secondarySearch) } for index, item := range l.items { mainText := item.MainText secondaryText := item.SecondaryText if ignoreCase { mainText = strings.ToLower(mainText) secondaryText = strings.ToLower(secondaryText) } // strings.Contains() always returns true for a "" search. mainContained := strings.Contains(mainText, mainSearch) secondaryContained := strings.Contains(secondaryText, secondarySearch) if mustContainBoth && mainContained && secondaryContained || !mustContainBoth && (mainSearch != "" && mainContained || secondarySearch != "" && secondaryContained) { indices = append(indices, index) } } return } // Clear removes all items from the list. func (l *List) Clear() *List { l.items = nil l.currentItem = 0 return l } // Draw draws this primitive onto the screen. func (l *List) Draw(screen tcell.Screen) { l.Box.DrawForSubclass(screen, l) // Determine the dimensions. x, y, width, height := l.GetInnerRect() bottomLimit := y + height _, totalHeight := screen.Size() if bottomLimit > totalHeight { bottomLimit = totalHeight } // Adjust offsets to keep the current item in view. if height == 0 { return } if l.currentItem < l.itemOffset { l.itemOffset = l.currentItem } else if l.showSecondaryText { if 2*(l.currentItem-l.itemOffset) >= height-1 { l.itemOffset = (2*l.currentItem + 3 - height) / 2 } } else { if l.currentItem-l.itemOffset >= height { l.itemOffset = l.currentItem + 1 - height } } if l.horizontalOffset < 0 { l.horizontalOffset = 0 } // Do we show any shortcuts? var showShortcuts bool for _, item := range l.items { if item.Shortcut != 0 { showShortcuts = true x += 4 width -= 4 break } } // Draw the list items. var maxWidth int // The maximum printed item width. for index, item := range l.items { if index < l.itemOffset { continue } if y >= bottomLimit { break } // Shortcuts. if showShortcuts && item.Shortcut != 0 { printWithStyle(screen, fmt.Sprintf("(%s)", string(item.Shortcut)), x-5, y, 0, 4, AlignRight, l.shortcutStyle, false) } // Main text. selected := index == l.currentItem && (!l.selectedFocusOnly || l.HasFocus()) style := l.mainTextStyle if selected { style = l.selectedStyle } mainText := item.MainText if !l.mainStyleTags { mainText = Escape(mainText) } _, _, printedWidth := printWithStyle(screen, mainText, x, y, l.horizontalOffset, width, AlignLeft, style, false) if printedWidth > maxWidth { maxWidth = printedWidth } // Draw until the end of the line if requested. if selected && l.highlightFullLine { for bx := printedWidth; bx < width; bx++ { screen.SetContent(x+bx, y, ' ', nil, style) } } y++ if y >= bottomLimit { break } // Secondary text. if l.showSecondaryText { secondaryText := item.SecondaryText if !l.secondaryStyleTags { secondaryText = Escape(secondaryText) } _, _, printedWidth := printWithStyle(screen, secondaryText, x, y, l.horizontalOffset, width, AlignLeft, l.secondaryTextStyle, false) if printedWidth > maxWidth { maxWidth = printedWidth } y++ } } // We don't want the item text to get out of view. If the horizontal offset // is too high, we reset it and redraw. (That should be about as efficient // as calculating everything up front.) if l.horizontalOffset > 0 && maxWidth < width { l.horizontalOffset -= width - maxWidth l.Draw(screen) } } // InputHandler returns the handler for this primitive. func (l *List) InputHandler() func(event *tcell.EventKey, setFocus func(p Primitive)) { return l.WrapInputHandler(func(event *tcell.EventKey, setFocus func(p Primitive)) { if event.Key() == tcell.KeyEscape { if l.done != nil { l.done() } return } else if len(l.items) == 0 { return } previousItem := l.currentItem switch key := event.Key(); key { case tcell.KeyTab, tcell.KeyDown: l.currentItem++ case tcell.KeyBacktab, tcell.KeyUp: l.currentItem-- case tcell.KeyRight: l.horizontalOffset += 2 // We shift by 2 to account for two-cell characters. case tcell.KeyLeft: l.horizontalOffset -= 2 case tcell.KeyHome: l.currentItem = 0 case tcell.KeyEnd: l.currentItem = len(l.items) - 1 case tcell.KeyPgDn: _, _, _, height := l.GetInnerRect() l.currentItem += height if l.currentItem >= len(l.items) { l.currentItem = len(l.items) - 1 } case tcell.KeyPgUp: _, _, _, height := l.GetInnerRect() l.currentItem -= height if l.currentItem < 0 { l.currentItem = 0 } case tcell.KeyEnter: if l.currentItem >= 0 && l.currentItem < len(l.items) { item := l.items[l.currentItem] if item.Selected != nil { item.Selected() } if l.selected != nil { l.selected(l.currentItem, item.MainText, item.SecondaryText, item.Shortcut) } } case tcell.KeyRune: ch := event.Rune() if ch != ' ' { // It's not a space bar. Is it a shortcut? var found bool for index, item := range l.items { if item.Shortcut == ch { // We have a shortcut. found = true l.currentItem = index break } } if !found { break } } item := l.items[l.currentItem] if item.Selected != nil { item.Selected() } if l.selected != nil { l.selected(l.currentItem, item.MainText, item.SecondaryText, item.Shortcut) } } if l.currentItem < 0 { if l.wrapAround { l.currentItem = len(l.items) - 1 } else { l.currentItem = 0 } } else if l.currentItem >= len(l.items) { if l.wrapAround { l.currentItem = 0 } else { l.currentItem = len(l.items) - 1 } } if l.currentItem != previousItem && l.currentItem < len(l.items) { if l.changed != nil { item := l.items[l.currentItem] l.changed(l.currentItem, item.MainText, item.SecondaryText, item.Shortcut) } } }) } // indexAtPoint returns the index of the list item found at the given position // or a negative value if there is no such list item. func (l *List) indexAtPoint(x, y int) int { rectX, rectY, width, height := l.GetInnerRect() if rectX < 0 || rectX >= rectX+width || y < rectY || y >= rectY+height { return -1 } index := y - rectY if l.showSecondaryText { index /= 2 } index += l.itemOffset if index >= len(l.items) { return -1 } return index } // MouseHandler returns the mouse handler for this primitive. func (l *List) MouseHandler() func(action MouseAction, event *tcell.EventMouse, setFocus func(p Primitive)) (consumed bool, capture Primitive) { return l.WrapMouseHandler(func(action MouseAction, event *tcell.EventMouse, setFocus func(p Primitive)) (consumed bool, capture Primitive) { if !l.InRect(event.Position()) { return false, nil } // Process mouse event. switch action { case MouseLeftClick: setFocus(l) index := l.indexAtPoint(event.Position()) if index != -1 { item := l.items[index] if item.Selected != nil { item.Selected() } if l.selected != nil { l.selected(index, item.MainText, item.SecondaryText, item.Shortcut) } if index != l.currentItem { if l.changed != nil { l.changed(index, item.MainText, item.SecondaryText, item.Shortcut) } } l.currentItem = index } consumed = true case MouseScrollUp: if l.itemOffset > 0 { l.itemOffset-- } consumed = true case MouseScrollDown: lines := len(l.items) - l.itemOffset if l.showSecondaryText { lines *= 2 } if _, _, _, height := l.GetInnerRect(); lines > height { l.itemOffset++ } consumed = true case MouseScrollLeft: l.horizontalOffset-- consumed = true case MouseScrollRight: l.horizontalOffset++ consumed = true } return }) } ================================================ FILE: modal.go ================================================ package tview import ( "github.com/gdamore/tcell/v2" ) // Modal is a centered message window used to inform the user or prompt them // for an immediate decision. It needs to have at least one button (added via // [Modal.AddButtons]) or it will never disappear. // // See https://github.com/rivo/tview/wiki/Modal for an example. type Modal struct { *Box // The frame embedded in the modal. frame *Frame // The form embedded in the modal's frame. form *Form // The message text (original, not word-wrapped). text string // The text color. textColor tcell.Color // The optional callback for when the user clicked one of the buttons. It // receives the index of the clicked button and the button's label. done func(buttonIndex int, buttonLabel string) } // NewModal returns a new [Modal] message window. func NewModal() *Modal { m := &Modal{ Box: NewBox().SetBorder(true).SetBackgroundColor(Styles.ContrastBackgroundColor), textColor: Styles.PrimaryTextColor, } m.form = NewForm(). SetButtonsAlign(AlignCenter). SetButtonBackgroundColor(Styles.PrimitiveBackgroundColor). SetButtonTextColor(Styles.PrimaryTextColor) m.form.SetBackgroundColor(Styles.ContrastBackgroundColor).SetBorderPadding(0, 0, 0, 0) m.form.SetCancelFunc(func() { if m.done != nil { m.done(-1, "") } }) m.frame = NewFrame(m.form).SetBorders(0, 0, 1, 0, 0, 0) m.frame.SetBackgroundColor(Styles.ContrastBackgroundColor). SetBorderPadding(1, 1, 1, 1) m.Box.Primitive = m return m } // SetBackgroundColor sets the color of the modal frame background. func (m *Modal) SetBackgroundColor(color tcell.Color) *Modal { m.form.SetBackgroundColor(color) m.frame.SetBackgroundColor(color) return m } // SetTextColor sets the color of the message text. func (m *Modal) SetTextColor(color tcell.Color) *Modal { m.textColor = color return m } // SetButtonBackgroundColor sets the background color of the buttons. func (m *Modal) SetButtonBackgroundColor(color tcell.Color) *Modal { m.form.SetButtonBackgroundColor(color) return m } // SetButtonTextColor sets the color of the button texts. func (m *Modal) SetButtonTextColor(color tcell.Color) *Modal { m.form.SetButtonTextColor(color) return m } // SetButtonStyle sets the style of the buttons when they are not focused. func (m *Modal) SetButtonStyle(style tcell.Style) *Modal { m.form.SetButtonStyle(style) return m } // SetButtonActivatedStyle sets the style of the buttons when they are focused. func (m *Modal) SetButtonActivatedStyle(style tcell.Style) *Modal { m.form.SetButtonActivatedStyle(style) return m } // SetDoneFunc sets a handler which is called when one of the buttons was // pressed. It receives the index of the button as well as its label text. The // handler is also called when the user presses the Escape key. The index will // then be negative and the label text an empty string. func (m *Modal) SetDoneFunc(handler func(buttonIndex int, buttonLabel string)) *Modal { m.done = handler return m } // SetText sets the message text of the window. The text may contain line // breaks but style tag states will not transfer to following lines. Note that // words are wrapped, too, based on the final size of the window. func (m *Modal) SetText(text string) *Modal { m.text = text return m } // AddButtons adds buttons to the window. There must be at least one button and // a "done" handler so the window can be closed again. func (m *Modal) AddButtons(labels []string) *Modal { for index, label := range labels { func(i int, l string) { m.form.AddButton(label, func() { if m.done != nil { m.done(i, l) } }) button := m.form.GetButton(m.form.GetButtonCount() - 1) button.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { switch event.Key() { case tcell.KeyDown, tcell.KeyRight: return tcell.NewEventKey(tcell.KeyTab, 0, tcell.ModNone) case tcell.KeyUp, tcell.KeyLeft: return tcell.NewEventKey(tcell.KeyBacktab, 0, tcell.ModNone) } return event }) }(index, label) } return m } // ClearButtons removes all buttons from the window. func (m *Modal) ClearButtons() *Modal { m.form.ClearButtons() return m } // SetFocus shifts the focus to the button with the given index. func (m *Modal) SetFocus(index int) *Modal { m.form.SetFocus(index) return m } // Focus is called when this primitive receives focus. func (m *Modal) Focus(delegate func(p Primitive)) { delegate(m.form) } // focusChain implements the [Primitive]'s focusChain method. func (m *Modal) focusChain(chain *[]Primitive) bool { if hasFocus := m.form.focusChain(chain); hasFocus { if chain != nil { *chain = append(*chain, m) } return true } return m.Box.focusChain(chain) } // Draw draws this primitive onto the screen. func (m *Modal) Draw(screen tcell.Screen) { // Calculate the width of this modal. buttonsWidth := 0 for _, button := range m.form.buttons { buttonsWidth += TaggedStringWidth(button.text) + 4 + 2 } buttonsWidth -= 2 screenWidth, screenHeight := screen.Size() width := screenWidth / 3 if width < buttonsWidth { width = buttonsWidth } // width is now without the box border. // Reset the text and find out how wide it is. m.frame.Clear() lines := WordWrap(m.text, width) for _, line := range lines { m.frame.AddText(line, true, AlignCenter, m.textColor) } // Set the modal's position and size. height := len(lines) + 6 width += 4 x := (screenWidth - width) / 2 y := (screenHeight - height) / 2 m.SetRect(x, y, width, height) // Draw the frame. m.Box.DrawForSubclass(screen, m) x, y, width, height = m.GetInnerRect() m.frame.SetRect(x, y, width, height) m.frame.Draw(screen) } // MouseHandler returns the mouse handler for this primitive. func (m *Modal) MouseHandler() func(action MouseAction, event *tcell.EventMouse, setFocus func(p Primitive)) (consumed bool, capture Primitive) { return m.WrapMouseHandler(func(action MouseAction, event *tcell.EventMouse, setFocus func(p Primitive)) (consumed bool, capture Primitive) { // Pass mouse events on to the form. consumed, capture = m.form.MouseHandler()(action, event, setFocus) if !consumed && action == MouseLeftDown && m.InRect(event.Position()) { setFocus(m) consumed = true } return }) } // InputHandler returns the handler for this primitive. func (m *Modal) InputHandler() func(event *tcell.EventKey, setFocus func(p Primitive)) { return m.WrapInputHandler(func(event *tcell.EventKey, setFocus func(p Primitive)) { if m.frame.HasFocus() { if handler := m.frame.InputHandler(); handler != nil { handler(event, setFocus) return } } }) } ================================================ FILE: pages.go ================================================ package tview import ( "github.com/gdamore/tcell/v2" ) // page represents one page of a Pages object. type page struct { Name string // The page's name. Item Primitive // The page's primitive. Resize bool // Whether or not to resize the page when it is drawn. Visible bool // Whether or not this page is visible. } // Pages is a container for other primitives laid out on top of each other, // overlapping or not. It is often used as the application's root primitive. It // allows to easily switch the visibility of the contained primitives. // // See https://github.com/rivo/tview/wiki/Pages for an example. type Pages struct { *Box // The contained pages. (Visible) pages are drawn from back to front. pages []*page // We keep a reference to the function which allows us to set the focus to // a newly visible page. setFocus func(p Primitive) // An optional handler which is called whenever the visibility or the order of // pages changes. changed func() } // NewPages returns a new [Pages] object. func NewPages() *Pages { p := &Pages{ Box: NewBox(), } p.Box.Primitive = p return p } // SetChangedFunc sets a handler which is called whenever the visibility or the // order of any visible pages changes. This can be used to redraw the pages. func (p *Pages) SetChangedFunc(handler func()) *Pages { p.changed = handler return p } // GetPageCount returns the number of pages currently stored in this object. func (p *Pages) GetPageCount() int { return len(p.pages) } // GetPageNames returns all page names ordered from front to back, // optionally limited to visible pages. func (p *Pages) GetPageNames(visibleOnly bool) []string { var names []string for index := len(p.pages) - 1; index >= 0; index-- { if !visibleOnly || p.pages[index].Visible { names = append(names, p.pages[index].Name) } } return names } // Clear removes all pages. func (p *Pages) Clear() *Pages { p.pages = nil return p } // AddPage adds a new page with the given name and primitive. If there was // previously a page with the same name, it is overwritten. Leaving the name // empty may cause conflicts in other functions so you should always specify a // non-empty name. // // Visible pages will be drawn in the order they were added (unless that order // was changed in one of the other functions). If "resize" is set to true, the // primitive will be set to the size available to the [Pages] primitive whenever // the pages are drawn. func (p *Pages) AddPage(name string, item Primitive, resize, visible bool) *Pages { hasFocus := p.HasFocus() for index, pg := range p.pages { if pg.Name == name { p.pages = append(p.pages[:index], p.pages[index+1:]...) break } } p.pages = append(p.pages, &page{Item: item, Name: name, Resize: resize, Visible: visible}) if p.changed != nil { p.changed() } if hasFocus { p.Focus(p.setFocus) } return p } // AddAndSwitchToPage calls [Pages.AddPage], then [Pages.SwitchToPage] on that // newly added page. func (p *Pages) AddAndSwitchToPage(name string, item Primitive, resize bool) *Pages { p.AddPage(name, item, resize, true) p.SwitchToPage(name) return p } // RemovePage removes the page with the given name. If that page was the only // visible page, visibility is assigned to the last page. func (p *Pages) RemovePage(name string) *Pages { var isVisible bool hasFocus := p.HasFocus() for index, page := range p.pages { if page.Name == name { isVisible = page.Visible p.pages = append(p.pages[:index], p.pages[index+1:]...) if page.Visible && p.changed != nil { p.changed() } break } } if isVisible { for index, page := range p.pages { if index < len(p.pages)-1 { if page.Visible { break // There is a remaining visible page. } } else { page.Visible = true // We need at least one visible page. } } } if hasFocus { p.Focus(p.setFocus) } return p } // HasPage returns true if a page with the given name exists in this object. func (p *Pages) HasPage(name string) bool { for _, page := range p.pages { if page.Name == name { return true } } return false } // ShowPage sets a page's visibility to "true" (in addition to any other pages // which are already visible). func (p *Pages) ShowPage(name string) *Pages { for _, page := range p.pages { if page.Name == name { page.Visible = true if p.changed != nil { p.changed() } break } } if p.HasFocus() { p.Focus(p.setFocus) } return p } // HidePage sets a page's visibility to "false". func (p *Pages) HidePage(name string) *Pages { for _, page := range p.pages { if page.Name == name { page.Visible = false if p.changed != nil { p.changed() } break } } if p.HasFocus() { p.Focus(p.setFocus) } return p } // SwitchToPage sets a page's visibility to "true" and all other pages' // visibility to "false". func (p *Pages) SwitchToPage(name string) *Pages { for _, page := range p.pages { if page.Name == name { page.Visible = true } else { page.Visible = false } } if p.changed != nil { p.changed() } if p.HasFocus() { p.Focus(p.setFocus) } return p } // SendToFront changes the order of the pages such that the page with the given // name comes last, causing it to be drawn last with the next update (if // visible). func (p *Pages) SendToFront(name string) *Pages { for index, page := range p.pages { if page.Name == name { if index < len(p.pages)-1 { p.pages = append(append(p.pages[:index], p.pages[index+1:]...), page) } if page.Visible && p.changed != nil { p.changed() } break } } if p.HasFocus() { p.Focus(p.setFocus) } return p } // SendToBack changes the order of the pages such that the page with the given // name comes first, causing it to be drawn first with the next update (if // visible). func (p *Pages) SendToBack(name string) *Pages { for index, pg := range p.pages { if pg.Name == name { if index > 0 { p.pages = append(append([]*page{pg}, p.pages[:index]...), p.pages[index+1:]...) } if pg.Visible && p.changed != nil { p.changed() } break } } if p.HasFocus() { p.Focus(p.setFocus) } return p } // GetFrontPage returns the front-most visible page. If there are no visible // pages, ("", nil) is returned. func (p *Pages) GetFrontPage() (name string, item Primitive) { for index := len(p.pages) - 1; index >= 0; index-- { if p.pages[index].Visible { return p.pages[index].Name, p.pages[index].Item } } return } // GetPage returns the page with the given name. If no such page exists, nil is // returned. func (p *Pages) GetPage(name string) Primitive { for _, page := range p.pages { if page.Name == name { return page.Item } } return nil } // focusChain implements the [Primitive]'s focusChain method. func (p *Pages) focusChain(chain *[]Primitive) bool { for _, page := range p.pages { if hasFocus := page.Item.focusChain(chain); hasFocus { if chain != nil { *chain = append(*chain, p) } return true } } return p.Box.focusChain(chain) } // Focus is called by the application when the primitive receives focus. func (p *Pages) Focus(delegate func(p Primitive)) { p.setFocus = delegate var topItem Primitive for _, page := range p.pages { if page.Visible { topItem = page.Item } } if topItem != nil { delegate(topItem) } else { p.Box.Focus(delegate) } } // Draw draws this primitive onto the screen. func (p *Pages) Draw(screen tcell.Screen) { p.Box.DrawForSubclass(screen, p) for _, page := range p.pages { if !page.Visible { continue } if page.Resize { x, y, width, height := p.GetInnerRect() page.Item.SetRect(x, y, width, height) } page.Item.Draw(screen) } } // MouseHandler returns the mouse handler for this primitive. func (p *Pages) MouseHandler() func(action MouseAction, event *tcell.EventMouse, setFocus func(p Primitive)) (consumed bool, capture Primitive) { return p.WrapMouseHandler(func(action MouseAction, event *tcell.EventMouse, setFocus func(p Primitive)) (consumed bool, capture Primitive) { if !p.InRect(event.Position()) { return false, nil } // Pass mouse events along to the last visible page item that takes it. for index := len(p.pages) - 1; index >= 0; index-- { page := p.pages[index] if page.Visible { consumed, capture = page.Item.MouseHandler()(action, event, setFocus) if consumed { return } } } return }) } // InputHandler returns the handler for this primitive. func (p *Pages) InputHandler() func(event *tcell.EventKey, setFocus func(p Primitive)) { return p.WrapInputHandler(func(event *tcell.EventKey, setFocus func(p Primitive)) { for _, page := range p.pages { if page.Item.HasFocus() { if handler := page.Item.InputHandler(); handler != nil { handler(event, setFocus) return } } } }) } // PasteHandler returns the handler for this primitive. func (p *Pages) PasteHandler() func(pastedText string, setFocus func(p Primitive)) { return p.WrapPasteHandler(func(pastedText string, setFocus func(p Primitive)) { for _, page := range p.pages { if page.Item.HasFocus() { if handler := page.Item.PasteHandler(); handler != nil { handler(pastedText, setFocus) return } } } }) } ================================================ FILE: primitive.go ================================================ package tview import "github.com/gdamore/tcell/v2" // Primitive is the top-most interface for all graphical primitives. type Primitive interface { // Draw draws this primitive onto the screen. Implementers can call the // screen's ShowCursor() function but should only do so when they have focus. // (They will need to keep track of this themselves.) Draw(screen tcell.Screen) // GetRect returns the current position of the primitive, x, y, width, and // height. GetRect() (int, int, int, int) // SetRect sets a new position of the primitive. SetRect(x, y, width, height int) // InputHandler returns a handler which receives key events when it has focus. // It is called by the Application class. // // A value of nil may also be returned, in which case this primitive cannot // receive focus and will not process any key events. // // The handler will receive the key event and a function that allows it to // set the focus to a different primitive, so that future key events are sent // to that primitive. // // The Application's Draw() function will be called automatically after the // handler returns. // // The Box class provides functionality to intercept keyboard input. If you // subclass from Box, it is recommended that you wrap your handler using // Box.WrapInputHandler() so you inherit that functionality. InputHandler() func(event *tcell.EventKey, setFocus func(p Primitive)) // Focus is called by the application when the primitive receives focus. // Implementers may call delegate() to pass the focus on to another // primitive which is usually a child primitive. This is not called on // parents of the primitive that receives focus. Focus(delegate func(p Primitive)) // HasFocus determines if the primitive (or any of its child primitives) has // focus. HasFocus() bool // Blur is called by the application when the primitive loses focus. This is // not called on parents of the primitive that loses focus. Blur() // MouseHandler returns a handler which receives mouse events. // It is called by the Application class. // // A value of nil may also be returned to stop the downward propagation of // mouse events. // // The Box class provides functionality to intercept mouse events. If you // subclass from Box, it is recommended that you wrap your handler using // Box.WrapMouseHandler() so you inherit that functionality. MouseHandler() func(action MouseAction, event *tcell.EventMouse, setFocus func(p Primitive)) (consumed bool, capture Primitive) // PasteHandler returns a handler which receives pasted text. // It is called by the Application class. // // A value of nil may also be returned to stop the downward propagation of // paste events. // // The Box class may provide functionality to intercept paste events in the // future. If you subclass from [Box], it is recommended that you wrap your // handler using Box.WrapPasteHandler() so you inherit that functionality. PasteHandler() func(text string, setFocus func(p Primitive)) // focusChain adds the chain of primitives that have focus to the given // slice, starting with the bottom-most primitive that has focus and ending // with this box. If this box or none of its descendents has focus, the // slice is not modified. If chain is nil, no chain is added. Returns // whether or not this box or one of its descendents has focus. focusChain(chain *[]Primitive) bool // focused is called when the current input focus changes. It is called on // the primitive which newly received focus as well as on all of its // ancestors (in no defined order). The default implementation in [Box] // invokes the callback set with [Box.SetFocusFunc]. This can also happen // when the focus is set to the primitive that already has focus. focused() // blurred is called when the current input focus changes. It is called on // the primitive which lost focus as well as on all of its ancestors (in no // defined order). The default implementation in [Box] invokes the callback // set with [Box.SetBlurFunc]. This can also happen when the focus is set to // the primitive that already has focus. blurred() } ================================================ FILE: semigraphics.go ================================================ package tview import "github.com/gdamore/tcell/v2" // Semigraphics provides an easy way to access unicode characters for drawing. // // Named like the unicode characters, 'Semigraphics'-prefix used if unicode block // isn't prefixed itself. const ( // Block: General Punctuation U+2000-U+206F (http://unicode.org/charts/PDF/U2000.pdf) SemigraphicsHorizontalEllipsis rune = '\u2026' // … // Block: Box Drawing U+2500-U+257F (http://unicode.org/charts/PDF/U2500.pdf) BoxDrawingsLightHorizontal rune = '\u2500' // ─ BoxDrawingsHeavyHorizontal rune = '\u2501' // ━ BoxDrawingsLightVertical rune = '\u2502' // │ BoxDrawingsHeavyVertical rune = '\u2503' // ┃ BoxDrawingsLightTripleDashHorizontal rune = '\u2504' // ┄ BoxDrawingsHeavyTripleDashHorizontal rune = '\u2505' // ┅ BoxDrawingsLightTripleDashVertical rune = '\u2506' // ┆ BoxDrawingsHeavyTripleDashVertical rune = '\u2507' // ┇ BoxDrawingsLightQuadrupleDashHorizontal rune = '\u2508' // ┈ BoxDrawingsHeavyQuadrupleDashHorizontal rune = '\u2509' // ┉ BoxDrawingsLightQuadrupleDashVertical rune = '\u250a' // ┊ BoxDrawingsHeavyQuadrupleDashVertical rune = '\u250b' // ┋ BoxDrawingsLightDownAndRight rune = '\u250c' // ┌ BoxDrawingsDownLightAndRightHeavy rune = '\u250d' // ┍ BoxDrawingsDownHeavyAndRightLight rune = '\u250e' // ┎ BoxDrawingsHeavyDownAndRight rune = '\u250f' // ┏ BoxDrawingsLightDownAndLeft rune = '\u2510' // ┐ BoxDrawingsDownLightAndLeftHeavy rune = '\u2511' // ┑ BoxDrawingsDownHeavyAndLeftLight rune = '\u2512' // ┒ BoxDrawingsHeavyDownAndLeft rune = '\u2513' // ┓ BoxDrawingsLightUpAndRight rune = '\u2514' // └ BoxDrawingsUpLightAndRightHeavy rune = '\u2515' // ┕ BoxDrawingsUpHeavyAndRightLight rune = '\u2516' // ┖ BoxDrawingsHeavyUpAndRight rune = '\u2517' // ┗ BoxDrawingsLightUpAndLeft rune = '\u2518' // ┘ BoxDrawingsUpLightAndLeftHeavy rune = '\u2519' // ┙ BoxDrawingsUpHeavyAndLeftLight rune = '\u251a' // ┚ BoxDrawingsHeavyUpAndLeft rune = '\u251b' // ┛ BoxDrawingsLightVerticalAndRight rune = '\u251c' // ├ BoxDrawingsVerticalLightAndRightHeavy rune = '\u251d' // ┝ BoxDrawingsUpHeavyAndRightDownLight rune = '\u251e' // ┞ BoxDrawingsDownHeavyAndRightUpLight rune = '\u251f' // ┟ BoxDrawingsVerticalHeavyAndRightLight rune = '\u2520' // ┠ BoxDrawingsDownLightAndRightUpHeavy rune = '\u2521' // ┡ BoxDrawingsUpLightAndRightDownHeavy rune = '\u2522' // ┢ BoxDrawingsHeavyVerticalAndRight rune = '\u2523' // ┣ BoxDrawingsLightVerticalAndLeft rune = '\u2524' // ┤ BoxDrawingsVerticalLightAndLeftHeavy rune = '\u2525' // ┥ BoxDrawingsUpHeavyAndLeftDownLight rune = '\u2526' // ┦ BoxDrawingsDownHeavyAndLeftUpLight rune = '\u2527' // ┧ BoxDrawingsVerticalHeavyAndLeftLight rune = '\u2528' // ┨ BoxDrawingsDownLightAndLeftUpHeavy rune = '\u2529' // ┨ BoxDrawingsUpLightAndLeftDownHeavy rune = '\u252a' // ┪ BoxDrawingsHeavyVerticalAndLeft rune = '\u252b' // ┫ BoxDrawingsLightDownAndHorizontal rune = '\u252c' // ┬ BoxDrawingsLeftHeavyAndRightDownLight rune = '\u252d' // ┭ BoxDrawingsRightHeavyAndLeftDownLight rune = '\u252e' // ┮ BoxDrawingsDownLightAndHorizontalHeavy rune = '\u252f' // ┯ BoxDrawingsDownHeavyAndHorizontalLight rune = '\u2530' // ┰ BoxDrawingsRightLightAndLeftDownHeavy rune = '\u2531' // ┱ BoxDrawingsLeftLightAndRightDownHeavy rune = '\u2532' // ┲ BoxDrawingsHeavyDownAndHorizontal rune = '\u2533' // ┳ BoxDrawingsLightUpAndHorizontal rune = '\u2534' // ┴ BoxDrawingsLeftHeavyAndRightUpLight rune = '\u2535' // ┵ BoxDrawingsRightHeavyAndLeftUpLight rune = '\u2536' // ┶ BoxDrawingsUpLightAndHorizontalHeavy rune = '\u2537' // ┷ BoxDrawingsUpHeavyAndHorizontalLight rune = '\u2538' // ┸ BoxDrawingsRightLightAndLeftUpHeavy rune = '\u2539' // ┹ BoxDrawingsLeftLightAndRightUpHeavy rune = '\u253a' // ┺ BoxDrawingsHeavyUpAndHorizontal rune = '\u253b' // ┻ BoxDrawingsLightVerticalAndHorizontal rune = '\u253c' // ┼ BoxDrawingsLeftHeavyAndRightVerticalLight rune = '\u253d' // ┽ BoxDrawingsRightHeavyAndLeftVerticalLight rune = '\u253e' // ┾ BoxDrawingsVerticalLightAndHorizontalHeavy rune = '\u253f' // ┿ BoxDrawingsUpHeavyAndDownHorizontalLight rune = '\u2540' // ╀ BoxDrawingsDownHeavyAndUpHorizontalLight rune = '\u2541' // ╁ BoxDrawingsVerticalHeavyAndHorizontalLight rune = '\u2542' // ╂ BoxDrawingsLeftUpHeavyAndRightDownLight rune = '\u2543' // ╃ BoxDrawingsRightUpHeavyAndLeftDownLight rune = '\u2544' // ╄ BoxDrawingsLeftDownHeavyAndRightUpLight rune = '\u2545' // ╅ BoxDrawingsRightDownHeavyAndLeftUpLight rune = '\u2546' // ╆ BoxDrawingsDownLightAndUpHorizontalHeavy rune = '\u2547' // ╇ BoxDrawingsUpLightAndDownHorizontalHeavy rune = '\u2548' // ╈ BoxDrawingsRightLightAndLeftVerticalHeavy rune = '\u2549' // ╉ BoxDrawingsLeftLightAndRightVerticalHeavy rune = '\u254a' // ╊ BoxDrawingsHeavyVerticalAndHorizontal rune = '\u254b' // ╋ BoxDrawingsLightDoubleDashHorizontal rune = '\u254c' // ╌ BoxDrawingsHeavyDoubleDashHorizontal rune = '\u254d' // ╍ BoxDrawingsLightDoubleDashVertical rune = '\u254e' // ╎ BoxDrawingsHeavyDoubleDashVertical rune = '\u254f' // ╏ BoxDrawingsDoubleHorizontal rune = '\u2550' // ═ BoxDrawingsDoubleVertical rune = '\u2551' // ║ BoxDrawingsDownSingleAndRightDouble rune = '\u2552' // ╒ BoxDrawingsDownDoubleAndRightSingle rune = '\u2553' // ╓ BoxDrawingsDoubleDownAndRight rune = '\u2554' // ╔ BoxDrawingsDownSingleAndLeftDouble rune = '\u2555' // ╕ BoxDrawingsDownDoubleAndLeftSingle rune = '\u2556' // ╖ BoxDrawingsDoubleDownAndLeft rune = '\u2557' // ╗ BoxDrawingsUpSingleAndRightDouble rune = '\u2558' // ╘ BoxDrawingsUpDoubleAndRightSingle rune = '\u2559' // ╙ BoxDrawingsDoubleUpAndRight rune = '\u255a' // ╚ BoxDrawingsUpSingleAndLeftDouble rune = '\u255b' // ╛ BoxDrawingsUpDoubleAndLeftSingle rune = '\u255c' // ╜ BoxDrawingsDoubleUpAndLeft rune = '\u255d' // ╝ BoxDrawingsVerticalSingleAndRightDouble rune = '\u255e' // ╞ BoxDrawingsVerticalDoubleAndRightSingle rune = '\u255f' // ╟ BoxDrawingsDoubleVerticalAndRight rune = '\u2560' // ╠ BoxDrawingsVerticalSingleAndLeftDouble rune = '\u2561' // ╡ BoxDrawingsVerticalDoubleAndLeftSingle rune = '\u2562' // ╢ BoxDrawingsDoubleVerticalAndLeft rune = '\u2563' // ╣ BoxDrawingsDownSingleAndHorizontalDouble rune = '\u2564' // ╤ BoxDrawingsDownDoubleAndHorizontalSingle rune = '\u2565' // ╥ BoxDrawingsDoubleDownAndHorizontal rune = '\u2566' // ╦ BoxDrawingsUpSingleAndHorizontalDouble rune = '\u2567' // ╧ BoxDrawingsUpDoubleAndHorizontalSingle rune = '\u2568' // ╨ BoxDrawingsDoubleUpAndHorizontal rune = '\u2569' // ╩ BoxDrawingsVerticalSingleAndHorizontalDouble rune = '\u256a' // ╪ BoxDrawingsVerticalDoubleAndHorizontalSingle rune = '\u256b' // ╫ BoxDrawingsDoubleVerticalAndHorizontal rune = '\u256c' // ╬ BoxDrawingsLightArcDownAndRight rune = '\u256d' // ╭ BoxDrawingsLightArcDownAndLeft rune = '\u256e' // ╮ BoxDrawingsLightArcUpAndLeft rune = '\u256f' // ╯ BoxDrawingsLightArcUpAndRight rune = '\u2570' // ╰ BoxDrawingsLightDiagonalUpperRightToLowerLeft rune = '\u2571' // ╱ BoxDrawingsLightDiagonalUpperLeftToLowerRight rune = '\u2572' // ╲ BoxDrawingsLightDiagonalCross rune = '\u2573' // ╳ BoxDrawingsLightLeft rune = '\u2574' // ╴ BoxDrawingsLightUp rune = '\u2575' // ╵ BoxDrawingsLightRight rune = '\u2576' // ╶ BoxDrawingsLightDown rune = '\u2577' // ╷ BoxDrawingsHeavyLeft rune = '\u2578' // ╸ BoxDrawingsHeavyUp rune = '\u2579' // ╹ BoxDrawingsHeavyRight rune = '\u257a' // ╺ BoxDrawingsHeavyDown rune = '\u257b' // ╻ BoxDrawingsLightLeftAndHeavyRight rune = '\u257c' // ╼ BoxDrawingsLightUpAndHeavyDown rune = '\u257d' // ╽ BoxDrawingsHeavyLeftAndLightRight rune = '\u257e' // ╾ BoxDrawingsHeavyUpAndLightDown rune = '\u257f' // ╿ // Block Elements. BlockUpperHalfBlock rune = '\u2580' // ▀ BlockLowerOneEighthBlock rune = '\u2581' // ▁ BlockLowerOneQuarterBlock rune = '\u2582' // ▂ BlockLowerThreeEighthsBlock rune = '\u2583' // ▃ BlockLowerHalfBlock rune = '\u2584' // ▄ BlockLowerFiveEighthsBlock rune = '\u2585' // ▅ BlockLowerThreeQuartersBlock rune = '\u2586' // ▆ BlockLowerSevenEighthsBlock rune = '\u2587' // ▇ BlockFullBlock rune = '\u2588' // █ BlockLeftSevenEighthsBlock rune = '\u2589' // ▉ BlockLeftThreeQuartersBlock rune = '\u258A' // ▊ BlockLeftFiveEighthsBlock rune = '\u258B' // ▋ BlockLeftHalfBlock rune = '\u258C' // ▌ BlockLeftThreeEighthsBlock rune = '\u258D' // ▍ BlockLeftOneQuarterBlock rune = '\u258E' // ▎ BlockLeftOneEighthBlock rune = '\u258F' // ▏ BlockRightHalfBlock rune = '\u2590' // ▐ BlockLightShade rune = '\u2591' // ░ BlockMediumShade rune = '\u2592' // ▒ BlockDarkShade rune = '\u2593' // ▓ BlockUpperOneEighthBlock rune = '\u2594' // ▔ BlockRightOneEighthBlock rune = '\u2595' // ▕ BlockQuadrantLowerLeft rune = '\u2596' // ▖ BlockQuadrantLowerRight rune = '\u2597' // ▗ BlockQuadrantUpperLeft rune = '\u2598' // ▘ BlockQuadrantUpperLeftAndLowerLeftAndLowerRight rune = '\u2599' // ▙ BlockQuadrantUpperLeftAndLowerRight rune = '\u259A' // ▚ BlockQuadrantUpperLeftAndUpperRightAndLowerLeft rune = '\u259B' // ▛ BlockQuadrantUpperLeftAndUpperRightAndLowerRight rune = '\u259C' // ▜ BlockQuadrantUpperRight rune = '\u259D' // ▝ BlockQuadrantUpperRightAndLowerLeft rune = '\u259E' // ▞ BlockQuadrantUpperRightAndLowerLeftAndLowerRight rune = '\u259F' // ▟ ) // SemigraphicJoints is a map for joining semigraphic (or otherwise) runes. // So far only light lines are supported but if you want to change the border // styling you need to provide the joints, too. // The matching will be sorted ascending by rune value, so you don't need to // provide all rune combinations, // e.g. (─) + (│) = (┼) will also match (│) + (─) = (┼) var SemigraphicJoints = map[string]rune{ // (─) + (│) = (┼) string([]rune{BoxDrawingsLightHorizontal, BoxDrawingsLightVertical}): BoxDrawingsLightVerticalAndHorizontal, // (─) + (┌) = (┬) string([]rune{BoxDrawingsLightHorizontal, BoxDrawingsLightDownAndRight}): BoxDrawingsLightDownAndHorizontal, // (─) + (┐) = (┬) string([]rune{BoxDrawingsLightHorizontal, BoxDrawingsLightDownAndLeft}): BoxDrawingsLightDownAndHorizontal, // (─) + (└) = (┴) string([]rune{BoxDrawingsLightHorizontal, BoxDrawingsLightUpAndRight}): BoxDrawingsLightUpAndHorizontal, // (─) + (┘) = (┴) string([]rune{BoxDrawingsLightHorizontal, BoxDrawingsLightUpAndLeft}): BoxDrawingsLightUpAndHorizontal, // (─) + (├) = (┼) string([]rune{BoxDrawingsLightHorizontal, BoxDrawingsLightVerticalAndRight}): BoxDrawingsLightVerticalAndHorizontal, // (─) + (┤) = (┼) string([]rune{BoxDrawingsLightHorizontal, BoxDrawingsLightVerticalAndLeft}): BoxDrawingsLightVerticalAndHorizontal, // (─) + (┬) = (┬) string([]rune{BoxDrawingsLightHorizontal, BoxDrawingsLightDownAndHorizontal}): BoxDrawingsLightDownAndHorizontal, // (─) + (┴) = (┴) string([]rune{BoxDrawingsLightHorizontal, BoxDrawingsLightUpAndHorizontal}): BoxDrawingsLightUpAndHorizontal, // (─) + (┼) = (┼) string([]rune{BoxDrawingsLightHorizontal, BoxDrawingsLightVerticalAndHorizontal}): BoxDrawingsLightVerticalAndHorizontal, // (│) + (┌) = (├) string([]rune{BoxDrawingsLightVertical, BoxDrawingsLightDownAndRight}): BoxDrawingsLightVerticalAndRight, // (│) + (┐) = (┤) string([]rune{BoxDrawingsLightVertical, BoxDrawingsLightDownAndLeft}): BoxDrawingsLightVerticalAndLeft, // (│) + (└) = (├) string([]rune{BoxDrawingsLightVertical, BoxDrawingsLightUpAndRight}): BoxDrawingsLightVerticalAndRight, // (│) + (┘) = (┤) string([]rune{BoxDrawingsLightVertical, BoxDrawingsLightUpAndLeft}): BoxDrawingsLightVerticalAndLeft, // (│) + (├) = (├) string([]rune{BoxDrawingsLightVertical, BoxDrawingsLightVerticalAndRight}): BoxDrawingsLightVerticalAndRight, // (│) + (┤) = (┤) string([]rune{BoxDrawingsLightVertical, BoxDrawingsLightVerticalAndLeft}): BoxDrawingsLightVerticalAndLeft, // (│) + (┬) = (┼) string([]rune{BoxDrawingsLightVertical, BoxDrawingsLightDownAndHorizontal}): BoxDrawingsLightVerticalAndHorizontal, // (│) + (┴) = (┼) string([]rune{BoxDrawingsLightVertical, BoxDrawingsLightUpAndHorizontal}): BoxDrawingsLightVerticalAndHorizontal, // (│) + (┼) = (┼) string([]rune{BoxDrawingsLightVertical, BoxDrawingsLightVerticalAndHorizontal}): BoxDrawingsLightVerticalAndHorizontal, // (┌) + (┐) = (┬) string([]rune{BoxDrawingsLightDownAndRight, BoxDrawingsLightDownAndLeft}): BoxDrawingsLightDownAndHorizontal, // (┌) + (└) = (├) string([]rune{BoxDrawingsLightDownAndRight, BoxDrawingsLightUpAndRight}): BoxDrawingsLightVerticalAndRight, // (┌) + (┘) = (┼) string([]rune{BoxDrawingsLightDownAndRight, BoxDrawingsLightUpAndLeft}): BoxDrawingsLightVerticalAndHorizontal, // (┌) + (├) = (├) string([]rune{BoxDrawingsLightDownAndRight, BoxDrawingsLightVerticalAndRight}): BoxDrawingsLightVerticalAndRight, // (┌) + (┤) = (┼) string([]rune{BoxDrawingsLightDownAndRight, BoxDrawingsLightVerticalAndLeft}): BoxDrawingsLightVerticalAndHorizontal, // (┌) + (┬) = (┬) string([]rune{BoxDrawingsLightDownAndRight, BoxDrawingsLightDownAndHorizontal}): BoxDrawingsLightDownAndHorizontal, // (┌) + (┴) = (┼) string([]rune{BoxDrawingsLightDownAndRight, BoxDrawingsLightUpAndHorizontal}): BoxDrawingsLightVerticalAndHorizontal, // (┌) + (┴) = (┼) string([]rune{BoxDrawingsLightDownAndRight, BoxDrawingsLightVerticalAndHorizontal}): BoxDrawingsLightVerticalAndHorizontal, // (┐) + (└) = (┼) string([]rune{BoxDrawingsLightDownAndLeft, BoxDrawingsLightUpAndRight}): BoxDrawingsLightVerticalAndHorizontal, // (┐) + (┘) = (┤) string([]rune{BoxDrawingsLightDownAndLeft, BoxDrawingsLightUpAndLeft}): BoxDrawingsLightVerticalAndLeft, // (┐) + (├) = (┼) string([]rune{BoxDrawingsLightDownAndLeft, BoxDrawingsLightVerticalAndRight}): BoxDrawingsLightVerticalAndHorizontal, // (┐) + (┤) = (┤) string([]rune{BoxDrawingsLightDownAndLeft, BoxDrawingsLightVerticalAndLeft}): BoxDrawingsLightVerticalAndLeft, // (┐) + (┬) = (┬) string([]rune{BoxDrawingsLightDownAndLeft, BoxDrawingsLightDownAndHorizontal}): BoxDrawingsLightDownAndHorizontal, // (┐) + (┴) = (┼) string([]rune{BoxDrawingsLightDownAndLeft, BoxDrawingsLightUpAndHorizontal}): BoxDrawingsLightVerticalAndHorizontal, // (┐) + (┼) = (┼) string([]rune{BoxDrawingsLightDownAndLeft, BoxDrawingsLightVerticalAndHorizontal}): BoxDrawingsLightVerticalAndHorizontal, // (└) + (┘) = (┴) string([]rune{BoxDrawingsLightUpAndRight, BoxDrawingsLightUpAndLeft}): BoxDrawingsLightUpAndHorizontal, // (└) + (├) = (├) string([]rune{BoxDrawingsLightUpAndRight, BoxDrawingsLightVerticalAndRight}): BoxDrawingsLightVerticalAndRight, // (└) + (┤) = (┼) string([]rune{BoxDrawingsLightUpAndRight, BoxDrawingsLightVerticalAndLeft}): BoxDrawingsLightVerticalAndHorizontal, // (└) + (┬) = (┼) string([]rune{BoxDrawingsLightUpAndRight, BoxDrawingsLightDownAndHorizontal}): BoxDrawingsLightVerticalAndHorizontal, // (└) + (┴) = (┴) string([]rune{BoxDrawingsLightUpAndRight, BoxDrawingsLightUpAndHorizontal}): BoxDrawingsLightUpAndHorizontal, // (└) + (┼) = (┼) string([]rune{BoxDrawingsLightUpAndRight, BoxDrawingsLightVerticalAndHorizontal}): BoxDrawingsLightVerticalAndHorizontal, // (┘) + (├) = (┼) string([]rune{BoxDrawingsLightUpAndLeft, BoxDrawingsLightVerticalAndRight}): BoxDrawingsLightVerticalAndHorizontal, // (┘) + (┤) = (┤) string([]rune{BoxDrawingsLightUpAndLeft, BoxDrawingsLightVerticalAndLeft}): BoxDrawingsLightVerticalAndLeft, // (┘) + (┬) = (┼) string([]rune{BoxDrawingsLightUpAndLeft, BoxDrawingsLightDownAndHorizontal}): BoxDrawingsLightVerticalAndHorizontal, // (┘) + (┴) = (┴) string([]rune{BoxDrawingsLightUpAndLeft, BoxDrawingsLightUpAndHorizontal}): BoxDrawingsLightUpAndHorizontal, // (┘) + (┼) = (┼) string([]rune{BoxDrawingsLightUpAndLeft, BoxDrawingsLightVerticalAndHorizontal}): BoxDrawingsLightVerticalAndHorizontal, // (├) + (┤) = (┼) string([]rune{BoxDrawingsLightVerticalAndRight, BoxDrawingsLightVerticalAndLeft}): BoxDrawingsLightVerticalAndHorizontal, // (├) + (┬) = (┼) string([]rune{BoxDrawingsLightVerticalAndRight, BoxDrawingsLightDownAndHorizontal}): BoxDrawingsLightVerticalAndHorizontal, // (├) + (┴) = (┼) string([]rune{BoxDrawingsLightVerticalAndRight, BoxDrawingsLightUpAndHorizontal}): BoxDrawingsLightVerticalAndHorizontal, // (├) + (┼) = (┼) string([]rune{BoxDrawingsLightVerticalAndRight, BoxDrawingsLightVerticalAndHorizontal}): BoxDrawingsLightVerticalAndHorizontal, // (┤) + (┬) = (┼) string([]rune{BoxDrawingsLightVerticalAndLeft, BoxDrawingsLightDownAndHorizontal}): BoxDrawingsLightVerticalAndHorizontal, // (┤) + (┴) = (┼) string([]rune{BoxDrawingsLightVerticalAndLeft, BoxDrawingsLightUpAndHorizontal}): BoxDrawingsLightVerticalAndHorizontal, // (┤) + (┼) = (┼) string([]rune{BoxDrawingsLightVerticalAndLeft, BoxDrawingsLightVerticalAndHorizontal}): BoxDrawingsLightVerticalAndHorizontal, // (┬) + (┴) = (┼) string([]rune{BoxDrawingsLightDownAndHorizontal, BoxDrawingsLightUpAndHorizontal}): BoxDrawingsLightVerticalAndHorizontal, // (┬) + (┼) = (┼) string([]rune{BoxDrawingsLightDownAndHorizontal, BoxDrawingsLightVerticalAndHorizontal}): BoxDrawingsLightVerticalAndHorizontal, // (┴) + (┼) = (┼) string([]rune{BoxDrawingsLightUpAndHorizontal, BoxDrawingsLightVerticalAndHorizontal}): BoxDrawingsLightVerticalAndHorizontal, } // PrintJoinedSemigraphics prints a semigraphics rune into the screen at the given // position with the given style, joining it with any existing semigraphics // rune.At this point, only regular single line borders are supported. func PrintJoinedSemigraphics(screen tcell.Screen, x, y int, ch rune, style tcell.Style) { previous, _, _, _ := screen.GetContent(x, y) // What's the resulting rune? var result rune if ch == previous { result = ch } else { if ch < previous { previous, ch = ch, previous } result = SemigraphicJoints[string([]rune{previous, ch})] } if result == 0 { result = ch } // We only print something if we have something. screen.SetContent(x, y, result, nil, style) } ================================================ FILE: strings.go ================================================ package tview import ( "math/rand" "regexp" "strconv" "strings" "unicode/utf8" "github.com/gdamore/tcell/v2" "github.com/rivo/uniseg" ) // escapedTagPattern matches an escaped tag, e.g. "[red[]", at the beginning of // a string. var escapedTagPattern = regexp.MustCompile(`^\[[^\[\]]+\[+\]`) // stepOptions is a bit field of options for [step]. A value of 0 results in // [step] having the same behavior as uniseg.Step, i.e. no tview-related parsing // is performed. type stepOptions int // Bit fields for [stepOptions]. const ( stepOptionsNone stepOptions = 0 stepOptionsStyle stepOptions = 1 << iota // Parse style tags. stepOptionsRegion // Parse region tags. ) // stepState represents the current state of the parser implemented in [step]. type stepState struct { unisegState int // The state of the uniseg parser. boundaries int // Information about boundaries, as returned by uniseg.Step. style tcell.Style // The style of the returned grapheme cluster. region string // The region of the returned grapheme cluster. escapedTagState int // States for parsing escaped tags (defined in [step]). grossLength int // The length of the cluster, including any tags not returned. // The styles for the initial call to [step]. initialForeground tcell.Color initialBackground tcell.Color initialAttributes tcell.AttrMask } // IsWordBoundary returns true if the boundary between the returned grapheme // cluster and the one following it is a word boundary. func (s *stepState) IsWordBoundary() bool { return s.boundaries&uniseg.MaskWord != 0 } // IsSentenceBoundary returns true if the boundary between the returned grapheme // cluster and the one following it is a sentence boundary. func (s *stepState) IsSentenceBoundary() bool { return s.boundaries&uniseg.MaskSentence != 0 } // LineBreak returns whether the string can be broken into the next line after // the returned grapheme cluster. If optional is true, the line break is // optional. If false, the line break is mandatory, e.g. after a newline // character. func (s *stepState) LineBreak() (lineBreak, optional bool) { switch s.boundaries & uniseg.MaskLine { case uniseg.LineCanBreak: return true, true case uniseg.LineMustBreak: return true, false } return false, false // uniseg.LineDontBreak. } // Width returns the grapheme cluster's width in cells. func (s *stepState) Width() int { return s.boundaries >> uniseg.ShiftWidth } // GrossLength returns the grapheme cluster's length in bytes, including any // tags that were parsed but not explicitly returned. func (s *stepState) GrossLength() int { return s.grossLength } // Style returns the style for the grapheme cluster. func (s *stepState) Style() tcell.Style { return s.style } // step uses uniseg.Step to iterate over the grapheme clusters of a string but // (optionally) also parses the string for style or region tags. // // This function can be called consecutively to extract all grapheme clusters // from str, without returning any contained (parsed) tags. The return values // are the first grapheme cluster, the remaining string, and the new state. Pass // the remaining string and the returned state to the next call. If the rest // string is empty, parsing is complete. Call the returned state's methods for // boundary and cluster width information. // // The returned cluster may be empty if the given string consists of only // (parsed) tags. The boundary and width information will be meaningless in // this case but the style will describe the style at the end of the string. // // Pass nil for state on the first call. This will assume an initial style with // [Styles.PrimitiveBackgroundColor] as the background color and // [Styles.PrimaryTextColor] as the text color, no current region. If you want // to start with a different style or region, you can set the state accordingly // but you must then set [state.unisegState] to -1. // // There is no need to call uniseg.HasTrailingLineBreakInString on the last // non-empty cluster as this function will do this for you and adjust the // returned boundaries accordingly. func step(str string, state *stepState, opts stepOptions) (cluster, rest string, newState *stepState) { // Set up initial state. if state == nil { state = &stepState{ unisegState: -1, style: tcell.StyleDefault.Background(Styles.PrimitiveBackgroundColor).Foreground(Styles.PrimaryTextColor), } } if state.unisegState < 0 { state.initialForeground, state.initialBackground, state.initialAttributes = state.style.Decompose() } if len(str) == 0 { newState = state return } // Get a grapheme cluster. preState := state.unisegState cluster, rest, state.boundaries, state.unisegState = uniseg.StepString(str, preState) state.grossLength = len(cluster) if rest == "" { if !uniseg.HasTrailingLineBreakInString(cluster) { state.boundaries &^= uniseg.MaskLine } } // Parse tags. if opts != stepOptionsNone { const ( etNone int = iota etStart etChar etClosing ) // Finite state machine for escaped tags. switch state.escapedTagState { case etStart: if cluster[0] == '[' || cluster[0] == ']' { // Invalid escaped tag. state.escapedTagState = etNone } else { // Other characters are allowed. state.escapedTagState = etChar } case etChar: if cluster[0] == ']' { // In theory, this should not happen. state.escapedTagState = etNone } else if cluster[0] == '[' { // Starting closing sequence. // Swallow the first one. cluster, rest, state.boundaries, state.unisegState = uniseg.StepString(rest, preState) state.grossLength += len(cluster) if cluster[0] == ']' { state.escapedTagState = etNone } else { state.escapedTagState = etClosing } } // More characters. Remain in etChar. case etClosing: if cluster[0] != '[' { state.escapedTagState = etNone } } // Regular tags. if state.escapedTagState == etNone { if cluster[0] == '[' { // We've already opened a tag. Parse it. length, style, region := parseTag(str, state, opts) if length > 0 { state.style = style state.region = region cluster, rest, state.boundaries, state.unisegState = uniseg.StepString(str[length:], preState) state.grossLength = len(cluster) + length if rest == "" { if !uniseg.HasTrailingLineBreakInString(cluster) { state.boundaries &^= uniseg.MaskLine } } } // Is this an escaped tag? if escapedTagPattern.MatchString(str[length:]) { state.escapedTagState = etStart } } if len(rest) > 0 && rest[0] == '[' { // A tag might follow the cluster. If so, we need to fix the state // for the boundaries to be correct. if length, _, _ := parseTag(rest, state, opts); length > 0 { if len(rest) > length { _, l := utf8.DecodeRuneInString(rest[length:]) cluster += rest[length : length+l] } var taglessRest string cluster, taglessRest, state.boundaries, state.unisegState = uniseg.StepString(cluster, preState) if taglessRest == "" { if !uniseg.HasTrailingLineBreakInString(cluster) { state.boundaries &^= uniseg.MaskLine } } } } } } newState = state return } // parseTag parses str for consecutive style and/or region tags, assuming that // str starts with the opening bracket for the first tag. It returns the string // length of all valid tags (0 if the first tag is not valid) and the updated // style and region for valid tags (based on the provided state). func parseTag(str string, state *stepState, opts stepOptions) (length int, style tcell.Style, region string) { if opts == stepOptionsNone { return // No tags to parse. } // Automata states for parsing tags. const ( tagStateNone = iota tagStateDoneTag tagStateStart tagStateRegionStart tagStateEndForeground tagStateStartBackground tagStateNumericForeground tagStateNameForeground tagStateEndBackground tagStateStartAttributes tagStateNumericBackground tagStateNameBackground tagStateAttributes tagStateRegionEnd tagStateRegionName tagStateEndAttributes tagStateStartURL tagStateEndURL tagStateURL ) // Helper function which checks if the given byte is one of a list of // characters, including letters and digits. isOneOf := func(b byte, chars string) bool { if b >= 'a' && b <= 'z' || b >= 'A' && b <= 'Z' || b >= '0' && b <= '9' { return true } return strings.IndexByte(chars, b) >= 0 } // Attribute map. attrs := map[byte]tcell.AttrMask{ 'B': tcell.AttrBold, 'I': tcell.AttrItalic, 'L': tcell.AttrBlink, 'D': tcell.AttrDim, 'S': tcell.AttrStrikeThrough, 'R': tcell.AttrReverse, } var ( tagState, tagLength int tempStr strings.Builder ) tStyle := state.style tRegion := state.region // Process state transitions. for len(str) > 0 { ch := str[0] str = str[1:] tagLength++ // Transition. switch tagState { case tagStateNone: if ch == '[' { // Start of a tag. tagState = tagStateStart } else { // Not a tag. We're done. return } case tagStateStart: if ch == '"' && opts&stepOptionsRegion == 0 { return // Region tags are not allowed. } else if ch != '"' && opts&stepOptionsStyle == 0 { return // Style tags are not allowed. } switch { case ch == '"': // Start of a region tag. tempStr.Reset() tagState = tagStateRegionStart case !isOneOf(ch, "#:-"): // Invalid style tag. return case ch == '-': // Reset foreground color. tStyle = tStyle.Foreground(state.initialForeground) tagState = tagStateEndForeground case ch == ':': // No foreground color. tagState = tagStateStartBackground default: tempStr.Reset() tempStr.WriteByte(ch) if ch == '#' { // Numeric foreground color. tagState = tagStateNumericForeground } else { // Letters or numbers. tagState = tagStateNameForeground } } case tagStateEndForeground: switch ch { case ']': // End of tag. tagState = tagStateDoneTag case ':': tagState = tagStateStartBackground default: // Invalid tag. return } case tagStateNumericForeground: if ch == ']' || ch == ':' { if tempStr.Len() != 7 { // Must be #rrggbb. return } tStyle = tStyle.Foreground(tcell.GetColor(tempStr.String())) } switch { case ch == ']': // End of tag. tagState = tagStateDoneTag case ch == ':': // Start of background color. tagState = tagStateStartBackground case strings.IndexByte("0123456789abcdefABCDEF", ch) >= 0: // Hex digit. tempStr.WriteByte(ch) tagState = tagStateNumericForeground default: // Invalid tag. return } case tagStateNameForeground: if ch == ']' || ch == ':' { name := tempStr.String() if name[0] >= '0' && name[0] <= '9' { // Must not start with a digit. return } tStyle = tStyle.Foreground(tcell.ColorNames[name]) } switch { case !isOneOf(ch, "]:"): // Invalid tag. return case ch == ']': // End of tag. tagState = tagStateDoneTag case ch == ':': // Start of background color. tagState = tagStateStartBackground default: // Letters or numbers. tempStr.WriteByte(ch) } case tagStateStartBackground: switch { case !isOneOf(ch, "#:-]"): // Invalid style tag. return case ch == ']': // End of tag. tagState = tagStateDoneTag case ch == '-': // Reset background color. tStyle = tStyle.Background(state.initialBackground) tagState = tagStateEndBackground case ch == ':': // No background color. tagState = tagStateStartAttributes default: tempStr.Reset() tempStr.WriteByte(ch) if ch == '#' { // Numeric background color. tagState = tagStateNumericBackground } else { // Letters or numbers. tagState = tagStateNameBackground } } case tagStateEndBackground: switch ch { case ']': // End of tag. tagState = tagStateDoneTag case ':': // Start of attributes. tagState = tagStateStartAttributes default: // Invalid tag. return } case tagStateNumericBackground: if ch == ']' || ch == ':' { if tempStr.Len() != 7 { // Must be #rrggbb. return } tStyle = tStyle.Background(tcell.GetColor(tempStr.String())) } if ch == ']' { // End of tag. tagState = tagStateDoneTag } else if ch == ':' { // Start of attributes. tagState = tagStateStartAttributes } else if strings.IndexByte("0123456789abcdefABCDEF", ch) >= 0 { // Hex digit. tempStr.WriteByte(ch) tagState = tagStateNumericBackground } else { // Invalid tag. return } case tagStateNameBackground: if ch == ']' || ch == ':' { name := tempStr.String() if name[0] >= '0' && name[0] <= '9' { // Must not start with a digit. return } tStyle = tStyle.Background(tcell.ColorNames[name]) } switch { case !isOneOf(ch, "]:"): // Invalid tag. return case ch == ']': // End of tag. tagState = tagStateDoneTag case ch == ':': // Start of background color. tagState = tagStateStartAttributes default: // Letters or numbers. tempStr.WriteByte(ch) } case tagStateStartAttributes: switch { case ch == ']': // End of tag. tagState = tagStateDoneTag case ch == '-': // Reset attributes. tStyle = tStyle.Attributes(state.initialAttributes) tagState = tagStateEndAttributes case ch == ':': // Start of URL. tagState = tagStateStartURL case strings.IndexByte("buildsrBUILDSR", ch) >= 0: // Attribute tag. tempStr.Reset() tempStr.WriteByte(ch) tagState = tagStateAttributes default: // Invalid tag. return } case tagStateAttributes: if ch == ']' || ch == ':' { flags := tempStr.String() _, _, a := tStyle.Decompose() for index := 0; index < len(flags); index++ { ch := flags[index] switch { case ch == 'u': tStyle = tStyle.Underline(true) case ch == 'U': tStyle = tStyle.Underline(false) case ch >= 'a' && ch <= 'z': a |= attrs[ch-('a'-'A')] default: a &^= attrs[ch] } } tStyle = tStyle.Attributes(a) } switch { case ch == ']': // End of tag. tagState = tagStateDoneTag case ch == ':': // Start of URL. tagState = tagStateStartURL case strings.IndexByte("buildsrBUILDSR", ch) >= 0: // Attribute tag. tempStr.WriteByte(ch) default: // Invalid tag. return } case tagStateEndAttributes: switch ch { case ']': // End of tag. tagState = tagStateDoneTag case ':': // Start of URL. tagState = tagStateStartURL default: // Invalid tag. return } case tagStateStartURL: switch ch { case ']': // End of tag. tagState = tagStateDoneTag case '-': // Reset URL. tStyle = tStyle.Url("").UrlId("") tagState = tagStateEndURL default: // URL character. tempStr.Reset() tempStr.WriteByte(ch) tStyle = tStyle.UrlId(strconv.Itoa(int(rand.Uint32()))) // Generate a unique ID for this URL. tagState = tagStateURL } case tagStateEndURL: if ch == ']' { // End of tag. tagState = tagStateDoneTag } else { // Invalid tag. return } case tagStateURL: if ch == ']' { // End of tag. tStyle = tStyle.Url(tempStr.String()) tagState = tagStateDoneTag } else { // URL character. tempStr.WriteByte(ch) } case tagStateRegionStart: switch { case ch == '"': // End of region tag. tagState = tagStateRegionEnd case isOneOf(ch, "_,;: -."): // Region name. tempStr.WriteByte(ch) tagState = tagStateRegionName default: // Invalid tag. return } case tagStateRegionEnd: if ch == ']' { // End of tag. tRegion = tempStr.String() tagState = tagStateDoneTag } else { // Invalid tag. return } case tagStateRegionName: switch { case ch == '"': // End of region tag. tagState = tagStateRegionEnd case isOneOf(ch, "_,;: -."): // Region name. tempStr.WriteByte(ch) default: // Invalid tag. return } } // The last transition led to a tag end. Make the tag permanent. if tagState == tagStateDoneTag { length, style, region = tagLength, tStyle, tRegion tagState = tagStateNone // Reset state. } } return } // TaggedStringWidth returns the width of the given string needed to print it on // screen. The text may contain style tags which are not counted. func TaggedStringWidth(text string) (width int) { var state *stepState for len(text) > 0 { _, text, state = step(text, state, stepOptionsStyle) width += state.Width() } return } // WordWrap splits a text such that each resulting line does not exceed the // given screen width. Split points are determined using the algorithm described // in [Unicode Standard Annex #14]. // // This function considers style tags to have no width. // // [Unicode Standard Annex #14]: https://www.unicode.org/reports/tr14/ func WordWrap(text string, width int) (lines []string) { if width <= 0 { return } var ( state *stepState lineWidth, lineLength, lastOption, lastOptionWidth int ) str := text for len(str) > 0 { // Parse the next character. _, str, state = step(str, state, stepOptionsStyle) cWidth := state.Width() // Would it exceed the line width? if lineWidth+cWidth > width { if lastOptionWidth == 0 { // No split point so far. Just split at the current position. lines = append(lines, text[:lineLength]) text = text[lineLength:] lineWidth, lineLength, lastOption, lastOptionWidth = 0, 0, 0, 0 } else { // Split at the last split point. lines = append(lines, text[:lastOption]) text = text[lastOption:] lineWidth -= lastOptionWidth lineLength -= lastOption lastOption, lastOptionWidth = 0, 0 } } // Move ahead. lineWidth += cWidth lineLength += state.GrossLength() // Check for split points. if lineBreak, optional := state.LineBreak(); lineBreak { if optional { // Remember this split point. lastOption = lineLength lastOptionWidth = lineWidth } else { // We must split here. lines = append(lines, strings.TrimRight(text[:lineLength], "\n\r")) text = text[lineLength:] lineWidth, lineLength, lastOption, lastOptionWidth = 0, 0, 0, 0 } } } lines = append(lines, text) return } // Escape escapes the given text such that color and/or region tags are not // recognized and substituted by the print functions of this package. For // example, to include a tag-like string in a box title or in a TextView: // // box.SetTitle(tview.Escape("[squarebrackets]")) // fmt.Fprint(textView, tview.Escape(`["quoted"]`)) func Escape(text string) string { return escapePattern.ReplaceAllString(text, "$1[]") } // Unescape unescapes text previously escaped with [Escape]. func Unescape(text string) string { return unescapePattern.ReplaceAllString(text, "$1]") } // stripTags strips style tags from the given string. (Region tags are not // stripped.) func stripTags(text string) string { var ( str strings.Builder state *stepState ) for len(text) > 0 { var c string c, text, state = step(text, state, stepOptionsStyle) str.WriteString(c) } return str.String() } ================================================ FILE: styles.go ================================================ package tview import "github.com/gdamore/tcell/v2" // Theme defines the colors used when primitives are initialized. type Theme struct { PrimitiveBackgroundColor tcell.Color // Main background color for primitives. ContrastBackgroundColor tcell.Color // Background color for contrasting elements. MoreContrastBackgroundColor tcell.Color // Background color for even more contrasting elements. BorderColor tcell.Color // Box borders. TitleColor tcell.Color // Box titles. GraphicsColor tcell.Color // Graphics. PrimaryTextColor tcell.Color // Primary text. SecondaryTextColor tcell.Color // Secondary text (e.g. labels). TertiaryTextColor tcell.Color // Tertiary text (e.g. subtitles, notes). InverseTextColor tcell.Color // Text on primary-colored backgrounds. ContrastSecondaryTextColor tcell.Color // Secondary text on ContrastBackgroundColor-colored backgrounds. } // Styles defines the theme for applications. The default is for a black // background and some basic colors: black, white, yellow, green, cyan, and // blue. var Styles = Theme{ PrimitiveBackgroundColor: tcell.ColorBlack, ContrastBackgroundColor: tcell.ColorBlue, MoreContrastBackgroundColor: tcell.ColorGreen, BorderColor: tcell.ColorWhite, TitleColor: tcell.ColorWhite, GraphicsColor: tcell.ColorWhite, PrimaryTextColor: tcell.ColorWhite, SecondaryTextColor: tcell.ColorYellow, TertiaryTextColor: tcell.ColorGreen, InverseTextColor: tcell.ColorBlue, ContrastSecondaryTextColor: tcell.ColorNavy, } ================================================ FILE: table.go ================================================ package tview import ( "sort" "github.com/gdamore/tcell/v2" colorful "github.com/lucasb-eyer/go-colorful" ) // TableCell represents one cell inside a Table. You can instantiate this type // directly but all colors (background and text) will be set to their default // which is black. type TableCell struct { // The reference object. Reference interface{} // The text to be displayed in the table cell. Text string // The alignment of the cell text. One of AlignLeft (default), AlignCenter, // or AlignRight. Align int // The maximum width of the cell in screen space. This is used to give a // column a maximum width. Any cell text whose screen width exceeds this width // is cut off. Set to 0 if there is no maximum width. MaxWidth int // If the total table width is less than the available width, this value is // used to add extra width to a column. See SetExpansion() for details. Expansion int // The color of the cell text. You should not use this anymore, it is only // here for backwards compatibility. Use the Style field instead. Color tcell.Color // The background color of the cell. You should not use this anymore, it is // only here for backwards compatibility. Use the Style field instead. BackgroundColor tcell.Color // The style attributes of the cell. You should not use this anymore, it is // only here for backwards compatibility. Use the Style field instead. Attributes tcell.AttrMask // The style of the cell. If this is uninitialized (tcell.StyleDefault), the // Color and BackgroundColor fields are used instead. Style tcell.Style // The style of the cell when it is selected. If this is uninitialized // (tcell.StyleDefault), the table's selected style is used instead. If that // is uninitialized as well, the cell's background and text color are // swapped. SelectedStyle tcell.Style // If set to true, the BackgroundColor is not used and the cell will have // the background color of the table. Transparent bool // If set to true, this cell cannot be selected. NotSelectable bool // An optional handler for mouse clicks. This also fires if the cell is not // selectable. If true is returned, no additional "selected" event is fired // on selectable cells. Clicked func() bool // The position and width of the cell the last time table was drawn. x, y, width int } // NewTableCell returns a new table cell with sensible defaults. That is, left // aligned text with the primary text color (see Styles) and a transparent // background (using the background of the Table). func NewTableCell(text string) *TableCell { return &TableCell{ Text: text, Align: AlignLeft, Style: tcell.StyleDefault.Foreground(Styles.PrimaryTextColor).Background(Styles.PrimitiveBackgroundColor), Transparent: true, } } // SetText sets the cell's text. func (c *TableCell) SetText(text string) *TableCell { c.Text = text return c } // SetAlign sets the cell's text alignment, one of AlignLeft, AlignCenter, or // AlignRight. func (c *TableCell) SetAlign(align int) *TableCell { c.Align = align return c } // SetMaxWidth sets maximum width of the cell in screen space. This is used to // give a column a maximum width. Any cell text whose screen width exceeds this // width is cut off. Set to 0 if there is no maximum width. func (c *TableCell) SetMaxWidth(maxWidth int) *TableCell { c.MaxWidth = maxWidth return c } // SetExpansion sets the value by which the column of this cell expands if the // available width for the table is more than the table width (prior to applying // this expansion value). This is a proportional value. The amount of unused // horizontal space is divided into widths to be added to each column. How much // extra width a column receives depends on the expansion value: A value of 0 // (the default) will not cause the column to increase in width. Other values // are proportional, e.g. a value of 2 will cause a column to grow by twice // the amount of a column with a value of 1. // // Since this value affects an entire column, the maximum over all visible cells // in that column is used. // // This function panics if a negative value is provided. func (c *TableCell) SetExpansion(expansion int) *TableCell { if expansion < 0 { panic("Table cell expansion values may not be negative") } c.Expansion = expansion return c } // SetTextColor sets the cell's text color. func (c *TableCell) SetTextColor(color tcell.Color) *TableCell { if c.Style == tcell.StyleDefault { c.Color = color } else { c.Style = c.Style.Foreground(color) } return c } // SetBackgroundColor sets the cell's background color. This will also cause the // cell's Transparent flag to be set to "false". func (c *TableCell) SetBackgroundColor(color tcell.Color) *TableCell { if c.Style == tcell.StyleDefault { c.BackgroundColor = color } else { c.Style = c.Style.Background(color) } c.Transparent = false return c } // SetTransparency sets the background transparency of this cell. A value of // "true" will cause the cell to use the table's background color, the cell's // own background color will be ignored. A value of "false" will cause it to use // its own background color. func (c *TableCell) SetTransparency(transparent bool) *TableCell { c.Transparent = transparent return c } // SetAttributes sets the cell's text attributes. You can combine different // attributes using bitmask operations: // // cell.SetAttributes(tcell.AttrItalic | tcell.AttrBold) func (c *TableCell) SetAttributes(attr tcell.AttrMask) *TableCell { if c.Style == tcell.StyleDefault { c.Attributes = attr } else { c.Style = c.Style.Attributes(attr) } return c } // SetStyle sets the cell's style (foreground color, background color, and // attributes) all at once. func (c *TableCell) SetStyle(style tcell.Style) *TableCell { c.Style = style return c } // SetSelectedStyle sets the cell's style when it is selected. If this is // uninitialized (tcell.StyleDefault), the table's selected style is used // instead. If that is uninitialized as well, the cell's background and text // color are swapped. func (c *TableCell) SetSelectedStyle(style tcell.Style) *TableCell { c.SelectedStyle = style return c } // SetSelectable sets whether or not this cell can be selected by the user. func (c *TableCell) SetSelectable(selectable bool) *TableCell { c.NotSelectable = !selectable return c } // SetReference allows you to store a reference of any type in this cell. This // will allow you to establish a mapping between the cell and your // actual data. func (c *TableCell) SetReference(reference interface{}) *TableCell { c.Reference = reference return c } // GetReference returns this cell's reference object. func (c *TableCell) GetReference() interface{} { return c.Reference } // GetLastPosition returns the position of the table cell the last time it was // drawn on screen. If the cell is not on screen, the return values are // undefined. // // Because the Table class will attempt to keep selected cells on screen, this // function is most useful in response to a "selected" event (see // SetSelectedFunc()) or a "selectionChanged" event (see // SetSelectionChangedFunc()). func (c *TableCell) GetLastPosition() (x, y, width int) { return c.x, c.y, c.width } // SetClickedFunc sets a handler which fires when this cell is clicked. This is // independent of whether the cell is selectable or not. But for selectable // cells, if the function returns "true", the "selected" event is not fired. func (c *TableCell) SetClickedFunc(clicked func() bool) *TableCell { c.Clicked = clicked return c } // TableContent defines a Table's data. You may replace a Table's default // implementation with your own using the Table.SetContent() function. This will // allow you to turn Table into a view of your own data structure. The // Table.Draw() function, which is called when the screen is updated, will then // use the (read-only) functions of this interface to update the table. The // write functions are only called when the corresponding functions of Table are // called. // // The interface's read-only functions are not called concurrently by the // package (provided that users of the package don't call Table.Draw() in a // separate goroutine, which would be uncommon and is not encouraged). type TableContent interface { // Return the cell at the given position or nil if there is no cell. The // row and column arguments start at 0 and end at what GetRowCount() and // GetColumnCount() return, minus 1. GetCell(row, column int) *TableCell // Return the total number of rows in the table. GetRowCount() int // Return the total number of columns in the table. GetColumnCount() int // The following functions are provided for completeness reasons as the // original Table implementation was not read-only. If you do not wish to // forward modifying operations to your data, you may opt to leave these // functions empty. To make this easier, you can include the // TableContentReadOnly type in your struct. See also the // demos/table/virtualtable example. // Set the cell at the given position to the provided cell. SetCell(row, column int, cell *TableCell) // Remove the row at the given position by shifting all following rows up // by one. Out of range positions may be ignored. RemoveRow(row int) // Remove the column at the given position by shifting all following columns // left by one. Out of range positions may be ignored. RemoveColumn(column int) // Insert a new empty row at the given position by shifting all rows at that // position and below down by one. Implementers may decide what to do with // out of range positions. InsertRow(row int) // Insert a new empty column at the given position by shifting all columns // at that position and to the right by one to the right. Implementers may // decide what to do with out of range positions. InsertColumn(column int) // Remove all table data. Clear() } // TableContentReadOnly is an empty struct which implements the write operations // of the TableContent interface. None of the implemented functions do anything. // You can embed this struct into your own structs to free yourself from having // to implement the empty write functions of TableContent. See // demos/table/virtualtable for an example. type TableContentReadOnly struct{} // SetCell does not do anything. func (t TableContentReadOnly) SetCell(row, column int, cell *TableCell) { // nop. } // RemoveRow does not do anything. func (t TableContentReadOnly) RemoveRow(row int) { // nop. } // RemoveColumn does not do anything. func (t TableContentReadOnly) RemoveColumn(column int) { // nop. } // InsertRow does not do anything. func (t TableContentReadOnly) InsertRow(row int) { // nop. } // InsertColumn does not do anything. func (t TableContentReadOnly) InsertColumn(column int) { // nop. } // Clear does not do anything. func (t TableContentReadOnly) Clear() { // nop. } // tableDefaultContent implements the default TableContent interface for the // Table class. type tableDefaultContent struct { // The cells of the table. Rows first, then columns. cells [][]*TableCell // The rightmost column in the data set. lastColumn int } // Clear clears all data. func (t *tableDefaultContent) Clear() { t.cells = nil t.lastColumn = -1 } // SetCell sets a cell's content. func (t *tableDefaultContent) SetCell(row, column int, cell *TableCell) { if row >= len(t.cells) { t.cells = append(t.cells, make([][]*TableCell, row-len(t.cells)+1)...) } rowLen := len(t.cells[row]) if column >= rowLen { t.cells[row] = append(t.cells[row], make([]*TableCell, column-rowLen+1)...) for c := rowLen; c < column; c++ { t.cells[row][c] = &TableCell{} } } t.cells[row][column] = cell if column > t.lastColumn { t.lastColumn = column } } // RemoveRow removes a row from the data. func (t *tableDefaultContent) RemoveRow(row int) { if row < 0 || row >= len(t.cells) { return } t.cells = append(t.cells[:row], t.cells[row+1:]...) } // RemoveColumn removes a column from the data. func (t *tableDefaultContent) RemoveColumn(column int) { for row := range t.cells { if column < 0 || column >= len(t.cells[row]) { continue } t.cells[row] = append(t.cells[row][:column], t.cells[row][column+1:]...) } if column >= 0 && column <= t.lastColumn { t.lastColumn-- } } // InsertRow inserts a new row at the given position. func (t *tableDefaultContent) InsertRow(row int) { if row >= len(t.cells) { return } t.cells = append(t.cells, nil) // Extend by one. copy(t.cells[row+1:], t.cells[row:]) // Shift down. t.cells[row] = nil // New row is uninitialized. } // InsertColumn inserts a new column at the given position. func (t *tableDefaultContent) InsertColumn(column int) { for row := range t.cells { if column >= len(t.cells[row]) { continue } t.cells[row] = append(t.cells[row], nil) // Extend by one. copy(t.cells[row][column+1:], t.cells[row][column:]) // Shift to the right. t.cells[row][column] = &TableCell{} // New element is an uninitialized table cell. } } // GetCell returns the cell at the given position. func (t *tableDefaultContent) GetCell(row, column int) *TableCell { if row < 0 || column < 0 || row >= len(t.cells) || column >= len(t.cells[row]) { return nil } return t.cells[row][column] } // GetRowCount returns the number of rows in the data set. func (t *tableDefaultContent) GetRowCount() int { return len(t.cells) } // GetColumnCount returns the number of columns in the data set. func (t *tableDefaultContent) GetColumnCount() int { if len(t.cells) == 0 { return 0 } return t.lastColumn + 1 } // Table visualizes two-dimensional data consisting of rows and columns. Each // Table cell is defined via [Table.SetCell] by the [TableCell] type. They can // be added dynamically to the table and changed any time. // // The most compact display of a table is without borders. Each row will then // occupy one row on screen and columns are separated by the rune defined via // [Table.SetSeparator] (a space character by default). // // When borders are turned on (via [Table.SetBorders]), each table cell is // surrounded by lines. Therefore one table row will require two rows on screen. // // Columns will use as much horizontal space as they need. You can constrain // their size with the [TableCell.MaxWidth] parameter of the [TableCell] type. // // # Fixed Columns // // You can define fixed rows and rolumns via [Table.SetFixed]. They will always // stay in their place, even when the table is scrolled. Fixed rows are always // the top rows. Fixed columns are always the leftmost columns. // // # Selections // // You can call [Table.SetSelectable] to set columns and/or rows to // "selectable". If the flag is set only for columns, entire columns can be // selected by the user. If it is set only for rows, entire rows can be // selected. If both flags are set, individual cells can be selected. The // "selected" handler set via [Table.SetSelectedFunc] is invoked when the user // presses Enter on a selection. // // # Navigation // // If the table extends beyond the available space, it can be navigated with // key bindings similar to Vim: // // - h, left arrow: Move left by one column. // - l, right arrow: Move right by one column. // - j, down arrow: Move down by one row. // - k, up arrow: Move up by one row. // - g, home: Move to the top. // - G, end: Move to the bottom. // - Ctrl-F, page down: Move down by one page. // - Ctrl-B, page up: Move up by one page. // // When there is no selection, this affects the entire table (except for fixed // rows and columns). When there is a selection, the user moves the selection. // The class will attempt to keep the selection from moving out of the screen. // // Use [Box.SetInputCapture] to override or modify keyboard input. // // See https://github.com/rivo/tview/wiki/Table for an example. type Table struct { *Box // Whether or not this table has borders around each cell. borders bool // The color of the borders or the separator. bordersColor tcell.Color // If there are no borders, the column separator. separator rune // The table's data structure. content TableContent // If true, when calculating the widths of the columns, all rows are evaluated // instead of only the visible ones. evaluateAllRows bool // The number of fixed rows / columns. fixedRows, fixedColumns int // Whether or not rows or columns can be selected. If both are set to true, // cells can be selected. rowsSelectable, columnsSelectable bool // The currently selected row and column. selectedRow, selectedColumn int // A temporary flag which causes the next call to Draw() to force the // current selection to remain visible. It is set to false afterwards. clampToSelection bool // If set to true, moving the selection will wrap around horizontally (last // to first column and vice versa) or vertically (last to first row and vice // versa). wrapHorizontally, wrapVertically bool // The number of rows/columns by which the table is scrolled down/to the // right. rowOffset, columnOffset int // If set to true, the table's last row will always be visible. trackEnd bool // The number of visible rows the last time the table was drawn. visibleRows int // The indices of the visible columns as of the last time the table was drawn. visibleColumnIndices []int // The net widths of the visible columns as of the last time the table was // drawn. visibleColumnWidths []int // The style of the selected rows. If this value is the empty struct, // selected rows are simply inverted. selectedStyle tcell.Style // An optional function which gets called when the user presses Enter on a // selected cell. If entire rows selected, the column value is undefined. // Likewise for entire columns. selected func(row, column int) // An optional function which gets called when the user changes the selection. // If entire rows selected, the column value is undefined. // Likewise for entire columns. selectionChanged func(row, column int) // An optional function which gets called when the user presses Escape, Tab, // or Backtab. Also when the user presses Enter if nothing is selectable. done func(key tcell.Key) } // NewTable returns a new [Table]. func NewTable() *Table { t := &Table{ Box: NewBox(), bordersColor: Styles.GraphicsColor, separator: ' ', } t.SetContent(nil) t.Box.Primitive = t return t } // SetContent sets a new content type for this table. This allows you to back // the table by a data structure of your own, for example one that cannot be // fully held in memory. For details, see the TableContent interface // documentation. // // A value of nil will return the table to its default implementation where all // of its table cells are kept in memory. func (t *Table) SetContent(content TableContent) *Table { if content != nil { t.content = content } else { t.content = &tableDefaultContent{ lastColumn: -1, } } return t } // Clear removes all table data. func (t *Table) Clear() *Table { t.content.Clear() return t } // SetBorders sets whether or not each cell in the table is surrounded by a // border. func (t *Table) SetBorders(show bool) *Table { t.borders = show return t } // SetBordersColor sets the color of the cell borders. func (t *Table) SetBordersColor(color tcell.Color) *Table { t.bordersColor = color return t } // SetSelectedStyle sets a specific style for selected cells. If no such style // is set, the cell's background and text color are swapped. If a cell defines // its own selected style, that will be used instead. // // To reset a previous setting to its default, make the following call: // // table.SetSelectedStyle(tcell.StyleDefault) func (t *Table) SetSelectedStyle(style tcell.Style) *Table { t.selectedStyle = style return t } // SetSeparator sets the character used to fill the space between two // neighboring cells. This is a space character ' ' per default but you may // want to set it to Borders.Vertical (or any other rune) if the column // separation should be more visible. If cell borders are activated, this is // ignored. // // Separators have the same color as borders. func (t *Table) SetSeparator(separator rune) *Table { t.separator = separator return t } // SetFixed sets the number of fixed rows and columns which are always visible // even when the rest of the cells are scrolled out of view. Rows are always the // top-most ones. Columns are always the left-most ones. func (t *Table) SetFixed(rows, columns int) *Table { t.fixedRows, t.fixedColumns = rows, columns return t } // SetSelectable sets the flags which determine what can be selected in a table. // There are three selection modi: // // - rows = false, columns = false: Nothing can be selected. // - rows = true, columns = false: Rows can be selected. // - rows = false, columns = true: Columns can be selected. // - rows = true, columns = true: Individual cells can be selected. func (t *Table) SetSelectable(rows, columns bool) *Table { t.rowsSelectable, t.columnsSelectable = rows, columns return t } // GetSelectable returns what can be selected in a table. Refer to // SetSelectable() for details. func (t *Table) GetSelectable() (rows, columns bool) { return t.rowsSelectable, t.columnsSelectable } // GetSelection returns the position of the current selection. // If entire rows are selected, the column index is undefined. // Likewise for entire columns. func (t *Table) GetSelection() (row, column int) { return t.selectedRow, t.selectedColumn } // Select sets the selected cell. Depending on the selection settings // specified via SetSelectable(), this may be an entire row or column, or even // ignored completely. The "selection changed" event is fired if such a callback // is available (even if the selection ends up being the same as before and even // if cells are not selectable). func (t *Table) Select(row, column int) *Table { t.selectedRow, t.selectedColumn = row, column t.clampToSelection = true if t.selectionChanged != nil { t.selectionChanged(row, column) } return t } // SetOffset sets how many rows and columns should be skipped when drawing the // table. This is useful for large tables that do not fit on the screen. // Navigating a selection can change these values. // // Fixed rows and columns are never skipped. func (t *Table) SetOffset(row, column int) *Table { t.rowOffset, t.columnOffset = row, column t.trackEnd = false return t } // GetOffset returns the current row and column offset. This indicates how many // rows and columns the table is scrolled down and to the right. func (t *Table) GetOffset() (row, column int) { return t.rowOffset, t.columnOffset } // SetEvaluateAllRows sets a flag which determines the rows to be evaluated when // calculating the widths of the table's columns. When false, only visible rows // are evaluated. When true, all rows in the table are evaluated. // // Set this flag to true to avoid shifting column widths when the table is // scrolled. (May come with a performance penalty for large tables.) // // Use with caution on very large tables, especially those not backed by the // default TableContent data structure. func (t *Table) SetEvaluateAllRows(all bool) *Table { t.evaluateAllRows = all return t } // SetSelectedFunc sets a handler which is called whenever the user presses the // Enter key on a selected cell/row/column. The handler receives the position of // the selection and its cell contents. If entire rows are selected, the column // index is undefined. Likewise for entire columns. func (t *Table) SetSelectedFunc(handler func(row, column int)) *Table { t.selected = handler return t } // SetSelectionChangedFunc sets a handler which is called whenever the current // selection changes. The handler receives the position of the new selection. // If entire rows are selected, the column index is undefined. Likewise for // entire columns. func (t *Table) SetSelectionChangedFunc(handler func(row, column int)) *Table { t.selectionChanged = handler return t } // SetDoneFunc sets a handler which is called whenever the user presses the // Escape, Tab, or Backtab key. If nothing is selected, it is also called when // user presses the Enter key (because pressing Enter on a selection triggers // the "selected" handler set via SetSelectedFunc()). func (t *Table) SetDoneFunc(handler func(key tcell.Key)) *Table { t.done = handler return t } // SetCell sets the content of a cell the specified position. It is ok to // directly instantiate a TableCell object. If the cell has content, at least // the Text and Color fields should be set. // // Note that setting cells in previously unknown rows and columns will // automatically extend the internal table representation with empty TableCell // objects, e.g. starting with a row of 100,000 will immediately create 100,000 // empty rows. // // To avoid unnecessary garbage collection, fill columns from left to right. func (t *Table) SetCell(row, column int, cell *TableCell) *Table { t.content.SetCell(row, column, cell) return t } // SetCellSimple calls SetCell() with the given text, left-aligned, in white. func (t *Table) SetCellSimple(row, column int, text string) *Table { t.SetCell(row, column, NewTableCell(text)) return t } // GetCell returns the contents of the cell at the specified position. A valid // TableCell object is always returned but it will be uninitialized if the cell // was not previously set. Such an uninitialized object will not automatically // be inserted. Therefore, repeated calls to this function may return different // pointers for uninitialized cells. func (t *Table) GetCell(row, column int) *TableCell { cell := t.content.GetCell(row, column) if cell == nil { cell = &TableCell{} } return cell } // RemoveRow removes the row at the given position from the table. If there is // no such row, this has no effect. func (t *Table) RemoveRow(row int) *Table { t.content.RemoveRow(row) return t } // RemoveColumn removes the column at the given position from the table. If // there is no such column, this has no effect. func (t *Table) RemoveColumn(column int) *Table { t.content.RemoveColumn(column) return t } // InsertRow inserts a row before the row with the given index. Cells on the // given row and below will be shifted to the bottom by one row. If "row" is // equal or larger than the current number of rows, this function has no effect. func (t *Table) InsertRow(row int) *Table { t.content.InsertRow(row) return t } // InsertColumn inserts a column before the column with the given index. Cells // in the given column and to its right will be shifted to the right by one // column. Rows that have fewer initialized cells than "column" will remain // unchanged. func (t *Table) InsertColumn(column int) *Table { t.content.InsertColumn(column) return t } // GetRowCount returns the number of rows in the table. func (t *Table) GetRowCount() int { return t.content.GetRowCount() } // GetColumnCount returns the (maximum) number of columns in the table. func (t *Table) GetColumnCount() int { return t.content.GetColumnCount() } // CellAt returns the row and column located at the given screen coordinates. // Each returned value may be negative if there is no row and/or cell. This // function will also process coordinates outside the table's inner rectangle so // callers will need to check for bounds themselves. // // The layout of the table when it was last drawn is used so if anything has // changed in the meantime, the results may not be reliable. func (t *Table) CellAt(x, y int) (row, column int) { rectX, rectY, _, _ := t.GetInnerRect() // Determine row as seen on screen. if t.borders { row = (y - rectY - 1) / 2 } else { row = y - rectY } // Respect fixed rows and row offset. if row >= 0 { if row >= t.fixedRows { row += t.rowOffset } if row >= t.content.GetRowCount() { row = -1 } } // Saerch for the clicked column. column = -1 if x >= rectX { columnX := rectX if t.borders { columnX++ } for index, width := range t.visibleColumnWidths { columnX += width + 1 if x < columnX { column = t.visibleColumnIndices[index] break } } } return } // ScrollToBeginning scrolls the table to the beginning to that the top left // corner of the table is shown. Note that this position may be corrected if // there is a selection. func (t *Table) ScrollToBeginning() *Table { t.trackEnd = false t.columnOffset = 0 t.rowOffset = 0 return t } // ScrollToEnd scrolls the table to the beginning to that the bottom left corner // of the table is shown. Adding more rows to the table will cause it to // automatically scroll with the new data. Note that this position may be // corrected if there is a selection. func (t *Table) ScrollToEnd() *Table { t.trackEnd = true t.columnOffset = 0 t.rowOffset = t.content.GetRowCount() return t } // SetWrapSelection determines whether a selection wraps vertically or // horizontally when moved. Vertically wrapping selections will jump from the // last selectable row to the first selectable row and vice versa. Horizontally // wrapping selections will jump from the last selectable column to the first // selectable column (on the next selectable row) or from the first selectable // column to the last selectable column (on the previous selectable row). If set // to false, the selection is not moved when it is already on the first/last // selectable row/column. // // The default is for both values to be false. func (t *Table) SetWrapSelection(vertical, horizontal bool) *Table { t.wrapHorizontally = horizontal t.wrapVertically = vertical return t } // Draw draws this primitive onto the screen. func (t *Table) Draw(screen tcell.Screen) { t.Box.DrawForSubclass(screen, t) // What's our available screen space? _, totalHeight := screen.Size() x, y, width, height := t.GetInnerRect() netWidth := width if t.borders { t.visibleRows = height / 2 netWidth -= 2 } else { t.visibleRows = height } // If this cell is not selectable, find the next one. rowCount, columnCount := t.content.GetRowCount(), t.content.GetColumnCount() if t.rowsSelectable || t.columnsSelectable { if t.selectedColumn < 0 { t.selectedColumn = 0 } if t.selectedRow < 0 { t.selectedRow = 0 } for t.selectedRow < rowCount { cell := t.content.GetCell(t.selectedRow, t.selectedColumn) if cell != nil && !cell.NotSelectable { break } t.selectedColumn++ if t.selectedColumn > columnCount-1 { t.selectedColumn = 0 t.selectedRow++ } } } // Clamp row offsets if requested. defer func() { t.clampToSelection = false // Only once. }() if t.clampToSelection && t.rowsSelectable { if t.selectedRow >= t.fixedRows && t.selectedRow < t.fixedRows+t.rowOffset { t.rowOffset = t.selectedRow - t.fixedRows t.trackEnd = false } if t.borders { if t.selectedRow+1-t.rowOffset >= height/2 { t.rowOffset = t.selectedRow + 1 - height/2 t.trackEnd = false } } else { if t.selectedRow+1-t.rowOffset >= height { t.rowOffset = t.selectedRow + 1 - height t.trackEnd = false } } } if t.rowOffset < 0 { t.rowOffset = 0 } if t.borders { if rowCount-t.rowOffset < height/2 { t.trackEnd = true } } else { if rowCount-t.rowOffset < height { t.trackEnd = true } } if t.trackEnd { if t.borders { t.rowOffset = rowCount - height/2 } else { t.rowOffset = rowCount - height } } if t.rowOffset < 0 { t.rowOffset = 0 } // Avoid invalid column offsets. if t.columnOffset >= columnCount-t.fixedColumns { t.columnOffset = columnCount - t.fixedColumns - 1 } if t.columnOffset < 0 { t.columnOffset = 0 } // Determine the indices of the rows which fit on the screen. var ( rows, allRows []int tableHeight int ) rowStep := 1 if t.borders { rowStep = 2 // With borders, every table row takes two screen rows. } if t.evaluateAllRows { allRows = make([]int, rowCount) for row := 0; row < rowCount; row++ { allRows[row] = row } } indexRow := func(row int) bool { // Determine if this row is visible, store its index. if tableHeight >= height { return false } rows = append(rows, row) tableHeight += rowStep return true } for row := 0; row < t.fixedRows && row < rowCount; row++ { // Do the fixed rows first. if !indexRow(row) { break } } for row := t.fixedRows + t.rowOffset; row < rowCount; row++ { // Then the remaining rows. if !indexRow(row) { break } } // Determine the columns' indices, widths, and expansion values that fit on // the screen. var ( tableWidth, expansionTotal int columns, widths, expansions []int ) includesSelection := !t.clampToSelection || !t.columnsSelectable // Helper function that evaluates one column. Returns true if the column // didn't fit at all. indexColumn := func(column int) bool { if netWidth == 0 || tableWidth >= netWidth { return true } var maxWidth, expansion int evaluationRows := rows if t.evaluateAllRows { evaluationRows = allRows } for _, row := range evaluationRows { if cell := t.content.GetCell(row, column); cell != nil { cellWidth := TaggedStringWidth(cell.Text) if cell.MaxWidth > 0 && cell.MaxWidth < cellWidth { cellWidth = cell.MaxWidth } if cellWidth > maxWidth { maxWidth = cellWidth } if cell.Expansion > expansion { expansion = cell.Expansion } } } clampedMaxWidth := maxWidth if tableWidth+maxWidth > netWidth { clampedMaxWidth = netWidth - tableWidth } columns = append(columns, column) widths = append(widths, clampedMaxWidth) expansions = append(expansions, expansion) tableWidth += clampedMaxWidth + 1 expansionTotal += expansion if t.columnsSelectable && t.clampToSelection && column == t.selectedColumn { // We want selections to appear fully. includesSelection = clampedMaxWidth == maxWidth } return false } // Helper function that evaluates multiple columns, starting at "start" and // at most ending at "maxEnd". Returns first column not included anymore (or // -1 if all are included). indexColumns := func(start, maxEnd int) int { if start == maxEnd { return -1 } if start < maxEnd { // Forward-evaluate columns. for column := start; column < maxEnd; column++ { if indexColumn(column) { return column } } return -1 } // Backward-evaluate columns. startLen := len(columns) defer func() { // Because we went backwards, we must reverse the partial slices. for i, j := startLen, len(columns)-1; i < j; i, j = i+1, j-1 { columns[i], columns[j] = columns[j], columns[i] widths[i], widths[j] = widths[j], widths[i] expansions[i], expansions[j] = expansions[j], expansions[i] } }() for column := start; column >= maxEnd; column-- { if indexColumn(column) { return column } } return -1 } // Reset the table to only its fixed columns. var fixedTableWidth, fixedExpansionTotal int resetColumns := func() { tableWidth = fixedTableWidth expansionTotal = fixedExpansionTotal columns = columns[:t.fixedColumns] widths = widths[:t.fixedColumns] expansions = expansions[:t.fixedColumns] } // Add fixed columns. if indexColumns(0, t.fixedColumns) < 0 { fixedTableWidth = tableWidth fixedExpansionTotal = expansionTotal // Add unclamped columns. if column := indexColumns(t.fixedColumns+t.columnOffset, columnCount); !includesSelection || column < 0 && t.columnOffset > 0 { // Offset is not optimal. Try again. if !includesSelection { // Clamp to selection. resetColumns() if t.selectedColumn <= t.fixedColumns+t.columnOffset { // It's on the left. Start with the selection. t.columnOffset = t.selectedColumn - t.fixedColumns indexColumns(t.fixedColumns+t.columnOffset, columnCount) } else { // It's on the right. End with the selection. if column := indexColumns(t.selectedColumn, t.fixedColumns); column >= 0 { t.columnOffset = column + 1 - t.fixedColumns } else { t.columnOffset = 0 } } } else if tableWidth < netWidth { // Don't waste space. Try to fit as much on screen as possible. resetColumns() if column := indexColumns(columnCount-1, t.fixedColumns); column >= 0 { t.columnOffset = column + 1 - t.fixedColumns } else { t.columnOffset = 0 } } } } // If we have space left, distribute it. if tableWidth < netWidth { toDistribute := netWidth - tableWidth for index, expansion := range expansions { if expansionTotal <= 0 { break } expWidth := toDistribute * expansion / expansionTotal widths[index] += expWidth toDistribute -= expWidth expansionTotal -= expansion } } // Helper function which draws border runes. borderStyle := tcell.StyleDefault.Background(t.backgroundColor).Foreground(t.bordersColor) drawBorder := func(colX, rowY int, ch rune) { screen.SetContent(x+colX, y+rowY, ch, nil, borderStyle) } // Draw the cells (and borders). var columnX int if t.borders { columnX++ } for columnIndex, column := range columns { columnWidth := widths[columnIndex] for rowY, row := range rows { if t.borders { // Draw borders. rowY *= 2 for pos := 0; pos < columnWidth && columnX+pos < width; pos++ { drawBorder(columnX+pos, rowY, Borders.Horizontal) } ch := Borders.Cross if row == 0 { if column == 0 { ch = Borders.TopLeft } else { ch = Borders.TopT } } else if column == 0 { ch = Borders.LeftT } drawBorder(columnX-1, rowY, ch) rowY++ if rowY >= height || y+rowY >= totalHeight { break // No space for the text anymore. } drawBorder(columnX-1, rowY, Borders.Vertical) } else if columnIndex < len(columns)-1 { // Draw separator. drawBorder(columnX+columnWidth, rowY, t.separator) } // Get the cell. cell := t.content.GetCell(row, column) if cell == nil { continue } // Draw text. finalWidth := columnWidth if columnX+columnWidth >= width { finalWidth = width - columnX } cell.x, cell.y, cell.width = x+columnX, y+rowY, finalWidth style := cell.Style if style == tcell.StyleDefault { style = tcell.StyleDefault.Background(cell.BackgroundColor).Foreground(cell.Color).Attributes(cell.Attributes) } start, end, _ := printWithStyle(screen, cell.Text, x+columnX, y+rowY, 0, finalWidth, cell.Align, style, cell.Transparent) printed := end - start if TaggedStringWidth(cell.Text)-printed > 0 && printed > 0 { _, _, style, _ := screen.GetContent(x+columnX+finalWidth-1, y+rowY) printWithStyle(screen, string(SemigraphicsHorizontalEllipsis), x+columnX+finalWidth-1, y+rowY, 0, 1, AlignLeft, style, false) } } // Draw bottom border. if rowY := 2 * len(rows); t.borders && rowY > 0 && rowY < height { for pos := 0; pos < columnWidth && columnX+1+pos < width; pos++ { drawBorder(columnX+pos, rowY, Borders.Horizontal) } ch := Borders.Cross if rows[len(rows)-1] == rowCount-1 { if column == 0 { ch = Borders.BottomLeft } else { ch = Borders.BottomT } } else if column == 0 { ch = Borders.BottomLeft } drawBorder(columnX-1, rowY, ch) } columnX += columnWidth + 1 } // Draw right border. columnX-- if t.borders && len(rows) > 0 && len(columns) > 0 && columnX < width { lastColumn := columns[len(columns)-1] == columnCount-1 for rowY := range rows { rowY *= 2 if rowY+1 < height { drawBorder(columnX, rowY+1, Borders.Vertical) } ch := Borders.Cross if rowY == 0 { if lastColumn { ch = Borders.TopRight } else { ch = Borders.TopT } } else if lastColumn { ch = Borders.RightT } drawBorder(columnX, rowY, ch) } if rowY := 2 * len(rows); rowY < height { ch := Borders.BottomT if lastColumn { ch = Borders.BottomRight } drawBorder(columnX, rowY, ch) } } // Helper function which colors the background of a box. // backgroundTransparent == true => Don't modify background color (when invert == false). // textTransparent == true => Don't modify text color (when invert == false). // attr == 0 => Don't change attributes. // invert == true => Ignore attr, set text to backgroundColor or t.backgroundColor; // set background to textColor. colorBackground := func(fromX, fromY, w, h int, backgroundColor, textColor tcell.Color, backgroundTransparent, textTransparent bool, attr tcell.AttrMask, invert bool) { for by := 0; by < h && fromY+by < y+height; by++ { for bx := 0; bx < w && fromX+bx < x+width; bx++ { m, c, style, _ := screen.GetContent(fromX+bx, fromY+by) fg, bg, a := style.Decompose() if invert { style = style.Background(textColor).Foreground(backgroundColor) } else { if !backgroundTransparent { bg = backgroundColor } if !textTransparent { fg = textColor } if attr != 0 { a = attr } style = style.Background(bg).Foreground(fg).Attributes(a) } screen.SetContent(fromX+bx, fromY+by, m, c, style) } } } // Color the cell backgrounds. To avoid undesirable artefacts, we combine // the drawing of a cell by background color, selected cells last. type cellInfo struct { x, y, w, h int cell *TableCell selected bool } cellsByBackgroundColor := make(map[tcell.Color][]*cellInfo) var backgroundColors []tcell.Color for rowY, row := range rows { columnX := 0 rowSelected := t.rowsSelectable && !t.columnsSelectable && row == t.selectedRow for columnIndex, column := range columns { columnWidth := widths[columnIndex] cell := t.content.GetCell(row, column) if cell == nil { continue } bx, by, bw, bh := x+columnX, y+rowY, columnWidth+1, 1 if t.borders { by = y + rowY*2 bw++ bh = 3 } columnSelected := t.columnsSelectable && !t.rowsSelectable && column == t.selectedColumn cellSelected := !cell.NotSelectable && (columnSelected || rowSelected || t.rowsSelectable && t.columnsSelectable && column == t.selectedColumn && row == t.selectedRow) backgroundColor := cell.BackgroundColor if cell.Style != tcell.StyleDefault { _, backgroundColor, _ = cell.Style.Decompose() } entries, ok := cellsByBackgroundColor[backgroundColor] cellsByBackgroundColor[backgroundColor] = append(entries, &cellInfo{ x: bx, y: by, w: bw, h: bh, cell: cell, selected: cellSelected, }) if !ok { backgroundColors = append(backgroundColors, backgroundColor) } columnX += columnWidth + 1 } } sort.Slice(backgroundColors, func(i int, j int) bool { // Draw brightest colors last (i.e. on top). r, g, b := backgroundColors[i].RGB() c := colorful.Color{R: float64(r) / 255, G: float64(g) / 255, B: float64(b) / 255} _, _, li := c.Hcl() r, g, b = backgroundColors[j].RGB() c = colorful.Color{R: float64(r) / 255, G: float64(g) / 255, B: float64(b) / 255} _, _, lj := c.Hcl() return li < lj }) for _, bgColor := range backgroundColors { entries := cellsByBackgroundColor[bgColor] for _, info := range entries { textColor := info.cell.Color if info.cell.Style != tcell.StyleDefault { textColor, _, _ = info.cell.Style.Decompose() } if info.selected { if info.cell.SelectedStyle != tcell.StyleDefault { selFg, selBg, selAttr := info.cell.SelectedStyle.Decompose() defer colorBackground(info.x, info.y, info.w, info.h, selBg, selFg, false, false, selAttr, false) } else if t.selectedStyle != tcell.StyleDefault { selFg, selBg, selAttr := t.selectedStyle.Decompose() defer colorBackground(info.x, info.y, info.w, info.h, selBg, selFg, false, false, selAttr, false) } else { defer colorBackground(info.x, info.y, info.w, info.h, bgColor, textColor, false, false, 0, true) } } else { colorBackground(info.x, info.y, info.w, info.h, bgColor, textColor, info.cell.Transparent, true, 0, false) } } } // Remember column infos. t.visibleColumnIndices, t.visibleColumnWidths = columns, widths } // InputHandler returns the handler for this primitive. func (t *Table) InputHandler() func(event *tcell.EventKey, setFocus func(p Primitive)) { return t.WrapInputHandler(func(event *tcell.EventKey, setFocus func(p Primitive)) { key := event.Key() if (!t.rowsSelectable && !t.columnsSelectable && key == tcell.KeyEnter) || key == tcell.KeyEscape || key == tcell.KeyTab || key == tcell.KeyBacktab { if t.done != nil { t.done(key) } return } // Movement functions. previouslySelectedRow, previouslySelectedColumn := t.selectedRow, t.selectedColumn lastColumn := t.content.GetColumnCount() - 1 rowCount := t.content.GetRowCount() if rowCount == 0 { return // No movement on empty tables. } var ( // Move the selection forward, don't go beyond final cell, return // true if a selection was found. forward = func(finalRow, finalColumn int) bool { row, column := t.selectedRow, t.selectedColumn for { // Stop if the current selection is fine. cell := t.content.GetCell(row, column) if cell != nil && !cell.NotSelectable { t.selectedRow, t.selectedColumn = row, column return true } // If we reached the final cell, stop. if row == finalRow && column == finalColumn { return false } // Move forward. column++ if column > lastColumn { column = 0 row++ if row >= rowCount { row = 0 } } } } // Move the selection backwards, don't go beyond final cell, return // true if a selection was found. backwards = func(finalRow, finalColumn int) bool { row, column := t.selectedRow, t.selectedColumn for { // Stop if the current selection is fine. cell := t.content.GetCell(row, column) if cell != nil && !cell.NotSelectable { t.selectedRow, t.selectedColumn = row, column return true } // If we reached the final cell, stop. if row == finalRow && column == finalColumn { return false } // Move backwards. column-- if column < 0 { column = lastColumn row-- if row < 0 { row = rowCount - 1 } } } } home = func() { if t.rowsSelectable { t.selectedRow = 0 t.selectedColumn = 0 forward(rowCount-1, lastColumn) t.clampToSelection = true } else { t.trackEnd = false t.rowOffset = 0 t.columnOffset = 0 } } end = func() { if t.rowsSelectable { t.selectedRow = rowCount - 1 t.selectedColumn = lastColumn backwards(0, 0) t.clampToSelection = true } else { t.trackEnd = true t.columnOffset = 0 } } down = func() { if t.rowsSelectable { row, column := t.selectedRow, t.selectedColumn t.selectedRow++ if t.selectedRow >= rowCount { if t.wrapVertically { t.selectedRow = 0 } else { t.selectedRow = rowCount - 1 } } finalRow, finalColumn := rowCount-1, lastColumn if t.wrapVertically { finalRow = row finalColumn = column } if !forward(finalRow, finalColumn) { backwards(row, column) } t.clampToSelection = true } else { t.rowOffset++ } } up = func() { if t.rowsSelectable { row, column := t.selectedRow, t.selectedColumn t.selectedRow-- if t.selectedRow < 0 { if t.wrapVertically { t.selectedRow = rowCount - 1 } else { t.selectedRow = 0 } } finalRow, finalColumn := 0, 0 if t.wrapVertically { finalRow = row finalColumn = column } if !backwards(finalRow, finalColumn) { forward(row, column) } t.clampToSelection = true } else { t.trackEnd = false t.rowOffset-- } } left = func() { if t.columnsSelectable { row, column := t.selectedRow, t.selectedColumn t.selectedColumn-- if t.selectedColumn < 0 { if t.wrapHorizontally { t.selectedColumn = lastColumn t.selectedRow-- if t.selectedRow < 0 { if t.wrapVertically { t.selectedRow = rowCount - 1 } else { t.selectedColumn = 0 t.selectedRow = 0 } } } else { t.selectedColumn = 0 } } finalRow, finalColumn := row, column if !t.wrapHorizontally { finalColumn = 0 } else if !t.wrapVertically { finalRow = 0 finalColumn = 0 } if !backwards(finalRow, finalColumn) { forward(row, column) } t.clampToSelection = true } else { t.columnOffset-- } } right = func() { if t.columnsSelectable { row, column := t.selectedRow, t.selectedColumn t.selectedColumn++ if t.selectedColumn > lastColumn { if t.wrapHorizontally { t.selectedColumn = 0 t.selectedRow++ if t.selectedRow >= rowCount { if t.wrapVertically { t.selectedRow = 0 } else { t.selectedColumn = lastColumn t.selectedRow = rowCount - 1 } } } else { t.selectedColumn = lastColumn } } finalRow, finalColumn := row, column if !t.wrapHorizontally { finalColumn = lastColumn } else if !t.wrapVertically { finalRow = rowCount - 1 finalColumn = lastColumn } if !forward(finalRow, finalColumn) { backwards(row, column) } t.clampToSelection = true } else { t.columnOffset++ } } pageDown = func() { offsetAmount := t.visibleRows - t.fixedRows if offsetAmount < 0 { offsetAmount = 0 } if t.rowsSelectable { row, column := t.selectedRow, t.selectedColumn t.selectedRow += offsetAmount if t.selectedRow >= rowCount { t.selectedRow = rowCount - 1 } finalRow, finalColumn := rowCount-1, lastColumn if !forward(finalRow, finalColumn) { backwards(row, column) } t.clampToSelection = true } else { t.rowOffset += offsetAmount } } pageUp = func() { offsetAmount := t.visibleRows - t.fixedRows if offsetAmount < 0 { offsetAmount = 0 } if t.rowsSelectable { row, column := t.selectedRow, t.selectedColumn t.selectedRow -= offsetAmount if t.selectedRow < 0 { t.selectedRow = 0 } finalRow, finalColumn := 0, 0 if !backwards(finalRow, finalColumn) { forward(row, column) } t.clampToSelection = true } else { t.trackEnd = false t.rowOffset -= offsetAmount } } ) switch key { case tcell.KeyRune: switch event.Rune() { case 'g': home() case 'G': end() case 'j': down() case 'k': up() case 'h': left() case 'l': right() } case tcell.KeyHome: home() case tcell.KeyEnd: end() case tcell.KeyUp: up() case tcell.KeyDown: down() case tcell.KeyLeft: left() case tcell.KeyRight: right() case tcell.KeyPgDn, tcell.KeyCtrlF: pageDown() case tcell.KeyPgUp, tcell.KeyCtrlB: pageUp() case tcell.KeyEnter: if (t.rowsSelectable || t.columnsSelectable) && t.selected != nil { t.selected(t.selectedRow, t.selectedColumn) } } // If the selection has changed, notify the handler. if t.selectionChanged != nil && (t.rowsSelectable && previouslySelectedRow != t.selectedRow || t.columnsSelectable && previouslySelectedColumn != t.selectedColumn) { t.selectionChanged(t.selectedRow, t.selectedColumn) } }) } // MouseHandler returns the mouse handler for this primitive. func (t *Table) MouseHandler() func(action MouseAction, event *tcell.EventMouse, setFocus func(p Primitive)) (consumed bool, capture Primitive) { return t.WrapMouseHandler(func(action MouseAction, event *tcell.EventMouse, setFocus func(p Primitive)) (consumed bool, capture Primitive) { x, y := event.Position() if !t.InRect(x, y) { return false, nil } switch action { case MouseLeftDown: setFocus(t) consumed = true case MouseLeftClick: selectEvent := true row, column := t.CellAt(x, y) cell := t.content.GetCell(row, column) if cell != nil && cell.Clicked != nil { if noSelect := cell.Clicked(); noSelect { selectEvent = false } } if selectEvent && (t.rowsSelectable || t.columnsSelectable) { t.Select(row, column) } consumed = true case MouseScrollUp: t.trackEnd = false t.rowOffset-- consumed = true case MouseScrollDown: t.rowOffset++ consumed = true } return }) } ================================================ FILE: textarea.go ================================================ package tview import ( "math" "strings" "unicode" "unicode/utf8" "github.com/gdamore/tcell/v2" "github.com/rivo/uniseg" ) const ( // The minimum capacity of the text area's piece chain slice. pieceChainMinCap = 10 // The minimum capacity of the text area's edit buffer. editBufferMinCap = 200 // The maximum number of bytes making up a grapheme cluster. In theory, this // could be longer but it would be highly unusual. maxGraphemeClusterSize = 40 // The default value for the [TextArea.minCursorPrefix] variable. minCursorPrefixDefault = 5 // The default value for the [TextArea.minCursorSuffix] variable. minCursorSuffixDefault = 3 ) // Types of user actions on a text area. type taAction int const ( taActionOther taAction = iota taActionTypeSpace // Typing a space character. taActionTypeNonSpace // Typing a non-space character. taActionBackspace // Deleting the previous character. taActionDelete // Deleting the next character. ) // NewLine is the string sequence to be inserted when hitting the Enter key in a // TextArea. The default is "\n" but you may change it to "\r\n" if required. var NewLine = "\n" // textAreaSpan represents a range of text in a text area. The text area widget // roughly follows the concept of Piece Chains outlined in // http://www.catch22.net/tuts/neatpad/piece-chains with some modifications. // This type represents a "span" (or "piece") and thus refers to a subset of the // text in the editor as part of a doubly-linked list. // // In most places where we reference a position in the text, we use a // three-element int array. The first element is the index of the referenced // span in the piece chain. The second element is the offset into the span's // referenced text (relative to the span's start), its value is always >= 0 and // < span.length. The third element is the state of the text parser at that // position. // // A range of text is represented by a span range which is a starting position // (3-int array) and an ending position (3-int array). The starting position // references the first character of the range, the ending position references // the position after the last character of the range. The end of the text is // therefore always [3]int{1, 0, 0}, position 0 of the ending sentinel. // // Sentinel spans are dummy spans not referring to any text. There are always // two sentinel spans: the starting span at index 0 of the [TextArea.spans] // slice and the ending span at index 1. type textAreaSpan struct { // Links to the previous and next textAreaSpan objects as indices into the // [TextArea.spans] slice. The sentinel spans (index 0 and 1) have -1 as // their previous or next links, respectively. previous, next int // The start index and the length of the text segment this span represents. // If "length" is negative, the span represents a substring of // [TextArea.initialText] and the actual length is its absolute value. If it // is positive, the span represents a substring of [TextArea.editText]. For // the sentinel spans (index 0 and 1), both values will be 0. Others will // never have a zero length. offset, length int } // textAreaUndoItem represents an undoable edit to the text area. It describes // the two spans wrapping a text change. type textAreaUndoItem struct { before, after int // The index of the copied "before" and "after" spans into the "spans" slice. originalBefore, originalAfter int // The original indices of the "before" and "after" spans. pos [3]int // The cursor position to be assumed after applying an undo. length int // The total text length at the time the undo item was created. continuation bool // If true, this item is a continuation of the previous undo item. It is handled together with all other undo items in the same continuation sequence. } // TextArea implements a simple text editor for multi-line text. Multi-color // text is not supported. Word-wrapping is enabled by default but can be turned // off or be changed to character-wrapping. // // # Navigation and Editing // // A text area is always in editing mode and no other mode exists. The following // keys can be used to move the cursor (subject to what the user's terminal // supports and how it is configured): // // - Left arrow: Move left. // - Right arrow: Move right. // - Down arrow: Move down. // - Up arrow: Move up. // - Ctrl-A, Home: Move to the beginning of the current line. // - Ctrl-E, End: Move to the end of the current line. // - Ctrl-F, page down: Move down by one page. // - Ctrl-B, page up: Move up by one page. // - Alt-Up arrow: Scroll the page up, leaving the cursor in its position. // - Alt-Down arrow: Scroll the page down, leaving the cursor in its position. // - Alt-Left arrow: Scroll the page to the left, leaving the cursor in its // position. Ignored if wrapping is enabled. // - Alt-Right arrow: Scroll the page to the right, leaving the cursor in its // position. Ignored if wrapping is enabled. // - Alt-B, Ctrl-Left arrow: Jump to the beginning of the current or previous // word. // - Alt-F, Ctrl-Right arrow: Jump to the end of the current or next word. // // Words are defined according to [Unicode Standard Annex #29]. We skip any // words that contain only spaces or punctuation. // // Entering a character will insert it at the current cursor location. // Subsequent characters are shifted accordingly. If the cursor is outside the // visible area, any changes to the text will move it into the visible area. The // following keys can also be used to modify the text: // // - Enter: Insert a newline character (see [NewLine]). // - Tab: Insert a tab character (\t). It will be rendered like [TabSize] // spaces. (This may eventually be changed to behave like regular tabs.) // - Ctrl-H, Backspace: Delete one character to the left of the cursor. // - Ctrl-D, Delete: Delete the character under the cursor (or the first // character on the next line if the cursor is at the end of a line). // - Alt-Backspace: Delete the word to the left of the cursor. // - Ctrl-K: Delete everything under and to the right of the cursor until the // next newline character. // - Ctrl-W: Delete from the start of the current word to the left of the // cursor. // - Ctrl-U: Delete the current line, i.e. everything after the last newline // character before the cursor up until the next newline character. This may // span multiple visible rows if wrapping is enabled. // // Text can be selected by moving the cursor while holding the Shift key, to the // extent that this is supported by the user's terminal. The Ctrl-L key can be // used to select the entire text. (Ctrl-A already binds to the "Home" key.) // // When text is selected: // // - Entering a character will replace the selected text with the new // character. // - Backspace, delete, Ctrl-H, Ctrl-D: Delete the selected text. // - Ctrl-Q: Copy the selected text into the clipboard, unselect the text. // - Ctrl-X: Copy the selected text into the clipboard and delete it. // - Ctrl-V: Replace the selected text with the clipboard text. If no text is // selected, the clipboard text will be inserted at the cursor location. // // The Ctrl-Q key was chosen for the "copy" function because the Ctrl-C key is // the default key to stop the application. If your application frees up the // global Ctrl-C key and you want to bind it to the "copy to clipboard" // function, you may use [Box.SetInputCapture] to override the Ctrl-Q key to // implement copying to the clipboard. Note that using your terminal's / // operating system's key bindings for copy+paste functionality may not have the // expected effect as tview will not be able to handle these keys. Pasting text // using your operating system's or terminal's own methods may be very slow as // each character will be pasted individually. However, some terminals support // pasting text blocks which is supported by the text area, see // [Application.EnablePaste] for details. // // The default clipboard is an internal text buffer local to this text area // instance, i.e. the operating system's clipboard is not used. If you want to // implement your own clipboard (or make use of your operating system's // clipboard), you can use [TextArea.SetClipboard] which provides all the // functionality needed to implement your own clipboard. // // The text area also supports Undo: // // - Ctrl-Z: Undo the last change. // - Ctrl-Y: Redo the last Undo change. // // Undo does not affect the clipboard. // // If the mouse is enabled, the following actions are available: // // - Left click: Move the cursor to the clicked position or to the end of the // line if past the last character. // - Left double-click: Select the word under the cursor. // - Left click while holding the Shift key: Select text. // - Scroll wheel: Scroll the text. // // [Unicode Standard Annex #29]: https://unicode.org/reports/tr29/ type TextArea struct { *Box // Whether or not this text area is disabled/read-only. disabled bool // The size of the text area. If set to 0, the text area will use the entire // available space. width, height int // The text to be shown in the text area when it is empty. placeholder string // The label text shown, usually when part of a form. label string // The width of the text area's label. labelWidth int // Styles: // The label style. labelStyle tcell.Style // The style of the text. Background colors different from the Box's // background color may lead to unwanted artefacts. textStyle tcell.Style // The style of the selected text. selectedStyle tcell.Style // The style of the placeholder text. placeholderStyle tcell.Style // Text manipulation related fields: // The text area's text prior to any editing. It is referenced by spans with // a negative length. initialText string // Any text that's been added by the user at some point. We only ever append // to this buffer. It is referenced by spans with a positive length. editText strings.Builder // The total length of all text in the text area. length int // The maximum number of bytes allowed in the text area. If 0, there is no // limit. maxLength int // The piece chain. The first two spans are sentinel spans which don't // reference anything and always remain in the same place. Spans are never // deleted from this slice. spans []textAreaSpan // An optional function which transforms grapheme clusters. This can be used // to hide characters from the screen while preserving the original text. transform func(cluster, rest string, boundaries int) (newCluster string, newBoundaries int) // Display, navigation, and cursor related fields: // If set to true, lines that are longer than the available width are // wrapped onto the next line. If set to false, any characters beyond the // available width are discarded. wrap bool // If set to true and if wrap is also true, lines are split at spaces or // after punctuation characters. wordWrap bool // The index of the first line shown in the text area. rowOffset int // The number of cells to be skipped on each line (not used in wrap mode). columnOffset int // The inner height and width of the text area the last time it was drawn. lastHeight, lastWidth int // The width of the currently known widest line, as determined by // [TextArea.extendLines]. widestLine int // Text positions and states of the start of lines. Each element is a span // position (see [textAreaSpan]). Not all lines of the text may be contained // at any time, extend as needed with the [TextArea.extendLines] function. lineStarts [][3]int // The cursor always points to the next position where a new character would // be placed. The selection start is the same as the cursor as long as there // is no selection. When there is one, the selection is between // selectionStart and cursor. cursor, selectionStart struct { // The row and column in screen space but relative to the start of the // text which may be outside the text area's box. The column value may // be larger than where the cursor actually is if the line the cursor // is on is shorter. The actualColumn is the position as it is seen on // screen. These three values may not be determined yet, in which case // the row is negative. row, column, actualColumn int // The textAreaSpan position with state for the actual next character. pos [3]int } // The minimum width of text (if available) to be shown left of the cursor. minCursorPrefix int // The minimum width of text (if available) to be shown right of the cursor. minCursorSuffix int // Set to true when the mouse is dragging to select text. dragging bool // Clipboard related fields: // The internal clipboard. clipboard string // The function to call when the user copies/cuts a text selection to the // clipboard. copyToClipboard func(string) // The function to call when the user pastes text from the clipboard. pasteFromClipboard func() string // Undo/redo related fields: // The last action performed by the user. lastAction taAction // The undo stack's items. Each item is a copy of the span before the // modified span range and a copy of the span after the modified span range. // To undo an action, the two referenced spans are put back into their // original place. Undos and redos decrease or increase the nextUndo value. // Thus, the next undo action is not always the last item. undoStack []textAreaUndoItem // The current undo/redo position on the undo stack. If no undo or redo has // been performed yet, this is the same as len(undoStack). nextUndo int // Event handlers: // An optional function which is called when the input has changed. changed func() // An optional function which is called when the position of the cursor or // the selection has changed. moved func() // A callback function set by the Form class and called when the user leaves // this form item. finished func(tcell.Key) } // NewTextArea returns a new [TextArea]. Use [TextArea.SetText] to set the // initial text. func NewTextArea() *TextArea { t := &TextArea{ Box: NewBox(), wrap: true, wordWrap: true, placeholderStyle: tcell.StyleDefault.Background(Styles.PrimitiveBackgroundColor).Foreground(Styles.TertiaryTextColor), labelStyle: tcell.StyleDefault.Foreground(Styles.SecondaryTextColor), textStyle: tcell.StyleDefault.Background(Styles.PrimitiveBackgroundColor).Foreground(Styles.PrimaryTextColor), selectedStyle: tcell.StyleDefault.Background(Styles.PrimaryTextColor).Foreground(Styles.PrimitiveBackgroundColor), spans: make([]textAreaSpan, 2, pieceChainMinCap), // We reserve some space to avoid reallocations right when editing starts. lastAction: taActionOther, minCursorPrefix: minCursorPrefixDefault, minCursorSuffix: minCursorSuffixDefault, lastWidth: math.MaxInt / 2, // We need this so some functions work before the first draw. lastHeight: 1, } t.editText.Grow(editBufferMinCap) t.spans[0] = textAreaSpan{previous: -1, next: 1} t.spans[1] = textAreaSpan{previous: 0, next: -1} t.cursor.pos = [3]int{1, 0, -1} t.selectionStart = t.cursor t.SetClipboard(nil, nil) t.Box.Primitive = t return t } // SetText sets the text of the text area. All existing text is deleted and // replaced with the new text. Any edits are discarded, no undos are available. // This function is typically only used to initialize the text area with a text // after it has been created. To clear the text area's text (again, no undos), // provide an empty string. // // If cursorAtTheEnd is false, the cursor is placed at the start of the text. If // it is true, it is placed at the end of the text. For very long texts, placing // the cursor at the end can be an expensive operation because the entire text // needs to be parsed and laid out. // // If you want to set text and preserve undo functionality, use // [TextArea.Replace] instead. func (t *TextArea) SetText(text string, cursorAtTheEnd bool) *TextArea { t.spans = t.spans[:2] t.initialText = text t.editText.Reset() t.lineStarts = nil t.length = len(text) t.rowOffset = 0 t.columnOffset = 0 t.reset() t.cursor.row, t.cursor.actualColumn, t.cursor.column = 0, 0, 0 t.cursor.pos = [3]int{1, 0, -1} t.undoStack = t.undoStack[:0] t.nextUndo = 0 if len(text) > 0 { t.spans = append(t.spans, textAreaSpan{ previous: 0, next: 1, offset: 0, length: -len(text), }) t.spans[0].next = 2 t.spans[1].previous = 2 if cursorAtTheEnd { t.cursor.row = -1 if t.lastWidth > 0 { t.findCursor(true, 0) } } else { t.cursor.pos = [3]int{2, 0, -1} } } else { t.spans[0].next = 1 t.spans[1].previous = 0 } t.selectionStart = t.cursor if t.changed != nil { t.changed() } if t.lastWidth > 0 && t.moved != nil { t.moved() } return t } // GetText returns the entire text of the text area. Note that this will newly // allocate the entire text. func (t *TextArea) GetText() string { if t.length == 0 { return "" } var text strings.Builder text.Grow(t.length) spanIndex := t.spans[0].next for spanIndex != 1 { span := &t.spans[spanIndex] if span.length < 0 { text.WriteString(t.initialText[span.offset : span.offset-span.length]) } else { text.WriteString(t.editText.String()[span.offset : span.offset+span.length]) } spanIndex = t.spans[spanIndex].next } return text.String() } // getTextBeforeCursor returns the text of the text area up until the cursor. // Note that this will result in a new allocation for the returned text. func (t *TextArea) getTextBeforeCursor() string { if t.length == 0 || t.cursor.pos[0] == t.spans[0].next && t.cursor.pos[1] == 0 { return "" } var text strings.Builder spanIndex := t.spans[0].next for spanIndex != 1 { span := &t.spans[spanIndex] length := span.length if length < 0 { if t.cursor.pos[0] == spanIndex { length = -t.cursor.pos[1] } text.WriteString(t.initialText[span.offset : span.offset-length]) } else { if t.cursor.pos[0] == spanIndex { length = t.cursor.pos[1] } text.WriteString(t.editText.String()[span.offset : span.offset+length]) } if t.cursor.pos[0] == spanIndex { break } spanIndex = t.spans[spanIndex].next } return text.String() } // getTextAfterCursor returns the text of the text area after the cursor. Note // that this will result in a new allocation for the returned text. func (t *TextArea) getTextAfterCursor() string { if t.length == 0 || t.cursor.pos[0] == 1 { return "" } var text strings.Builder spanIndex := t.cursor.pos[0] cursorOffset := t.cursor.pos[1] for spanIndex != 1 { span := &t.spans[spanIndex] length := span.length if length < 0 { text.WriteString(t.initialText[span.offset+cursorOffset : span.offset-length]) } else { text.WriteString(t.editText.String()[span.offset+cursorOffset : span.offset+length]) } spanIndex = t.spans[spanIndex].next cursorOffset = 0 } return text.String() } // HasSelection returns whether the selected text is non-empty. func (t *TextArea) HasSelection() bool { return t.selectionStart != t.cursor } // GetSelection returns the currently selected text and its start and end // positions within the entire text as a half-open interval. If the returned // text is an empty string, the start and end positions are the same and can be // interpreted as the cursor position. // // Calling this function will result in string allocations as well as a search // for text positions. This is expensive if the text has been edited extensively // already. Use [TextArea.HasSelection] first if you are only interested in // selected text. func (t *TextArea) GetSelection() (text string, start int, end int) { from, to := t.selectionStart.pos, t.cursor.pos if t.cursor.row < t.selectionStart.row || (t.cursor.row == t.selectionStart.row && t.cursor.actualColumn < t.selectionStart.actualColumn) { from, to = to, from } if from[0] == 1 { start = t.length } if to[0] == 1 { end = t.length } var ( index int selection strings.Builder inside bool ) for span := t.spans[0].next; span != 1; span = t.spans[span].next { var spanText string length := t.spans[span].length if length < 0 { length = -length spanText = t.initialText } else { spanText = t.editText.String() } spanText = spanText[t.spans[span].offset : t.spans[span].offset+length] if from[0] == span && to[0] == span { if from != to { selection.WriteString(spanText[from[1]:to[1]]) } start = index + from[1] end = index + to[1] break } else if from[0] == span { if from != to { selection.WriteString(spanText[from[1]:]) } start = index + from[1] inside = true } else if to[0] == span { if from != to { selection.WriteString(spanText[:to[1]]) } end = index + to[1] break } else if inside && from != to { selection.WriteString(spanText) } index += length } if selection.Len() != 0 { text = selection.String() } return } // GetCursor returns the current cursor position where the first character of // the entire text is in row 0, column 0. If the user has selected text, the // "from" values will refer to the beginning of the selection and the "to" // values to the end of the selection (exclusive). They are the same if there // is no selection. func (t *TextArea) GetCursor() (fromRow, fromColumn, toRow, toColumn int) { fromRow, fromColumn = t.selectionStart.row, t.selectionStart.actualColumn toRow, toColumn = t.cursor.row, t.cursor.actualColumn if toRow < fromRow || (toRow == fromRow && toColumn < fromColumn) { fromRow, fromColumn, toRow, toColumn = toRow, toColumn, fromRow, fromColumn } if t.length > 0 && t.wrap && fromColumn >= t.lastWidth { // This happens when a row has text all the way until the end, pushing the cursor outside the viewport. fromRow++ fromColumn = 0 } if t.length > 0 && t.wrap && toColumn >= t.lastWidth { toRow++ toColumn = 0 } return } // GetTextLength returns the string length of the text in the text area. func (t *TextArea) GetTextLength() int { return t.length } // Replace replaces a section of the text with new text. The start and end // positions refer to index positions within the entire text string (as a // half-open interval). They may be the same, in which case text is inserted at // the given position. If the text is an empty string, text between start and // end is deleted. Index positions will be shifted to line up with character // boundaries. A "changed" event will be triggered. // // Previous selections are cleared. The cursor will be located at the end of the // replaced text. Scroll offsets will not be changed. A "moved" event will be // triggered. // // The effects of this function can be undone (and redone) by the user. func (t *TextArea) Replace(start, end int, text string) *TextArea { t.Select(start, end) row := t.selectionStart.row t.cursor.pos = t.replace(t.selectionStart.pos, t.cursor.pos, text, false) t.cursor.row = -1 t.truncateLines(row - 1) t.findCursor(false, row) t.selectionStart = t.cursor if t.moved != nil { t.moved() } // The "changed" event will have been triggered by the "replace" function. return t } // Select selects a section of the text. The start and end positions refer to // index positions within the entire text string (as a half-open interval). They // may be the same, in which case the cursor is placed at the given position. // Any previous selection is removed. Scroll offsets will be preserved. // // Index positions will be shifted to line up with character boundaries. func (t *TextArea) Select(start, end int) *TextArea { oldFrom, oldTo := t.selectionStart, t.cursor defer func() { if (oldFrom != t.selectionStart || oldTo != t.cursor) && t.moved != nil { t.moved() } }() // Clamp input values. if start < 0 { start = 0 } if start > t.length { start = t.length } if end < 0 { end = 0 } if end > t.length { end = t.length } if end < start { start, end = end, start } // Find the cursor positions. var row, index int t.cursor.row, t.cursor.pos = -1, [3]int{1, 0, -1} t.selectionStart = t.cursor RowLoop: for { if row >= len(t.lineStarts) { t.extendLines(t.lastWidth, row) if row >= len(t.lineStarts) { break } } // Check the spans of this row. pos := t.lineStarts[row] var ( next [3]int lineIndex int ) if row+1 < len(t.lineStarts) { next = t.lineStarts[row+1] } else { next = [3]int{1, 0, -1} } for { if pos[0] == next[0] { if start >= index+lineIndex && start < index+lineIndex+next[1]-pos[1] || end >= index+lineIndex && end < index+lineIndex+next[1]-pos[1] || next[0] == 1 && (start == t.length || end == t.length) { // Special case for the end of the text. break } index += lineIndex + next[1] - pos[1] row++ continue RowLoop // Move on to the next row. } else { length := t.spans[pos[0]].length if length < 0 { length = -length } if start >= index+lineIndex && start < index+lineIndex+length-pos[1] || end >= index+lineIndex && end < index+lineIndex+length-pos[1] || next[0] == 1 && (start == t.length || end == t.length) { // Special case for the end of the text. break } lineIndex += length - pos[1] pos[0], pos[1] = t.spans[pos[0]].next, 0 } } // One of the indices is in this row. Step through it. pos = t.lineStarts[row] endPos := pos var ( cluster, text string column, width int ) for pos != next { if t.selectionStart.row < 0 && start <= index { t.selectionStart.row, t.selectionStart.column, t.selectionStart.actualColumn = row, column, column t.selectionStart.pos = pos } if t.cursor.row < 0 && end <= index { t.cursor.row, t.cursor.column, t.cursor.actualColumn = row, column, column t.cursor.pos = pos break RowLoop } cluster, text, _, width, pos, endPos = t.step(text, pos, endPos) index += len(cluster) column += width } row++ } if t.cursor.row < 0 { t.findCursor(false, 0) // This only happens if we couldn't find the locations above. t.selectionStart = t.cursor } return t } // SetWrap sets the flag that, if true, leads to lines that are longer than the // available width being wrapped onto the next line. If false, any characters // beyond the available width are not displayed. func (t *TextArea) SetWrap(wrap bool) *TextArea { if t.wrap != wrap { t.wrap = wrap t.reset() } return t } // SetWordWrap sets the flag that causes lines that are longer than the // available width to be wrapped onto the next line at spaces or after // punctuation marks (according to [Unicode Standard Annex #14]). This flag is // ignored if the flag set with [TextArea.SetWrap] is false. The text area's // default is word-wrapping. // // [Unicode Standard Annex #14]: https://www.unicode.org/reports/tr14/ func (t *TextArea) SetWordWrap(wrapOnWords bool) *TextArea { if t.wordWrap != wrapOnWords { t.wordWrap = wrapOnWords t.reset() } return t } // SetPlaceholder sets the text to be displayed when the text area is empty. func (t *TextArea) SetPlaceholder(placeholder string) *TextArea { t.placeholder = placeholder return t } // SetLabel sets the text to be displayed before the text area. func (t *TextArea) SetLabel(label string) *TextArea { t.label = label return t } // GetLabel returns the text to be displayed before the text area. func (t *TextArea) GetLabel() string { return t.label } // SetLabelWidth sets the screen width of the label. A value of 0 will cause the // primitive to use the width of the label string. func (t *TextArea) SetLabelWidth(width int) *TextArea { t.labelWidth = width return t } // GetLabelWidth returns the screen width of the label. func (t *TextArea) GetLabelWidth() int { return t.labelWidth } // SetSize sets the screen size of the input element of the text area. The input // element is always located next to the label which is always located in the // top left corner. If any of the values are 0 or larger than the available // space, the available space will be used. func (t *TextArea) SetSize(rows, columns int) *TextArea { t.width = columns t.height = rows return t } // GetFieldWidth returns this primitive's field width. func (t *TextArea) GetFieldWidth() int { return t.width } // GetFieldHeight returns this primitive's field height. func (t *TextArea) GetFieldHeight() int { return t.height } // SetDisabled sets whether or not the item is disabled / read-only. func (t *TextArea) SetDisabled(disabled bool) FormItem { t.disabled = disabled if t.finished != nil { t.finished(-1) } return t } // GetDisabled returns whether or not the item is disabled / read-only. func (t *TextArea) GetDisabled() bool { return t.disabled } // SetMaxLength sets the maximum number of bytes allowed in the text area. A // value of 0 means there is no limit. If the text area currently contains more // bytes than this, it may violate this constraint. func (t *TextArea) SetMaxLength(maxLength int) *TextArea { t.maxLength = maxLength return t } // setMinCursorPadding sets a minimum width to be reserved left and right of the // cursor. This is ignored if wrapping is enabled. func (t *TextArea) setMinCursorPadding(prefix, suffix int) *TextArea { t.minCursorPrefix = prefix t.minCursorSuffix = suffix return t } // SetLabelStyle sets the style of the label. func (t *TextArea) SetLabelStyle(style tcell.Style) *TextArea { t.labelStyle = style return t } // GetLabelStyle returns the style of the label. func (t *TextArea) GetLabelStyle() tcell.Style { return t.labelStyle } // SetTextStyle sets the style of the text. func (t *TextArea) SetTextStyle(style tcell.Style) *TextArea { t.textStyle = style return t } // GetTextStyle returns the style of the text. func (t *TextArea) GetTextStyle() tcell.Style { return t.textStyle } // SetSelectedStyle sets the style of the selected text. func (t *TextArea) SetSelectedStyle(style tcell.Style) *TextArea { t.selectedStyle = style return t } // SetPlaceholderStyle sets the style of the placeholder text. func (t *TextArea) SetPlaceholderStyle(style tcell.Style) *TextArea { t.placeholderStyle = style return t } // GetPlaceholderStyle returns the style of the placeholder text. func (t *TextArea) GetPlaceholderStyle() tcell.Style { return t.placeholderStyle } // GetOffset returns the text's offset, that is, the number of rows and columns // skipped during drawing at the top or on the left, respectively. Note that the // column offset is ignored if wrapping is enabled. func (t *TextArea) GetOffset() (row, column int) { return t.rowOffset, t.columnOffset } // SetOffset sets the text's offset, that is, the number of rows and columns // skipped during drawing at the top or on the left, respectively. If wrapping // is enabled, the column offset is ignored. These values may get adjusted // automatically to ensure that some text is always visible. func (t *TextArea) SetOffset(row, column int) *TextArea { t.rowOffset, t.columnOffset = row, column return t } // SetClipboard allows you to implement your own clipboard by providing a // function that is called when the user wishes to store text in the clipboard // (copyToClipboard) and a function that is called when the user wishes to // retrieve text from the clipboard (pasteFromClipboard). // // Providing nil values will cause the default clipboard implementation to be // used. Note that the default clipboard is local to this text area instance. // Copying text to other widgets will not work. func (t *TextArea) SetClipboard(copyToClipboard func(string), pasteFromClipboard func() string) *TextArea { t.copyToClipboard = copyToClipboard if t.copyToClipboard == nil { t.copyToClipboard = func(text string) { t.clipboard = text } } t.pasteFromClipboard = pasteFromClipboard if t.pasteFromClipboard == nil { t.pasteFromClipboard = func() string { return t.clipboard } } return t } // GetClipboardText returns the current text of the clipboard by calling the // pasteFromClipboard function set with [TextArea.SetClipboard]. func (t *TextArea) GetClipboardText() string { return t.pasteFromClipboard() } // SetChangedFunc sets a handler which is called whenever the text of the text // area has changed. func (t *TextArea) SetChangedFunc(handler func()) *TextArea { t.changed = handler return t } // SetMovedFunc sets a handler which is called whenever the cursor position or // the text selection has changed. func (t *TextArea) SetMovedFunc(handler func()) *TextArea { t.moved = handler return t } // SetFinishedFunc sets a callback invoked when the user leaves this form item. func (t *TextArea) SetFinishedFunc(handler func(key tcell.Key)) FormItem { t.finished = handler return t } // Focus is called when this primitive receives focus. func (t *TextArea) Focus(delegate func(p Primitive)) { // If we're part of a form and this item is disabled, there's nothing the // user can do here so we're finished. if t.finished != nil && t.disabled { t.finished(-1) return } t.Box.Focus(delegate) } // SetFormAttributes sets attributes shared by all form items. func (t *TextArea) SetFormAttributes(labelWidth int, labelColor, bgColor, fieldTextColor, fieldBgColor tcell.Color) FormItem { t.labelWidth = labelWidth t.backgroundColor = bgColor t.labelStyle = t.labelStyle.Foreground(labelColor) t.textStyle = tcell.StyleDefault.Foreground(fieldTextColor).Background(fieldBgColor) return t } // replace deletes a range of text and inserts the given text at that position. // If the resulting text would exceed the maximum length, the function does not // do anything. The function returns the end position of the deleted/inserted // range. // // The function can hang if "deleteStart" is located after "deleteEnd". // // Undo events are always generated unless continuation is true and text is // either appended to the end of a span or a span is shortened at the beginning // or the end (and nothing else). // // This function only modifies [TextArea.lineStarts] to update span references // but does not change it to reflect the new layout. // // A "changed" event will be triggered. func (t *TextArea) replace(deleteStart, deleteEnd [3]int, insert string, continuation bool) [3]int { // Maybe nothing needs to be done? if deleteStart == deleteEnd && insert == "" || t.maxLength > 0 && len(insert) > 0 && t.length+len(insert) >= t.maxLength { return deleteEnd } // Notify at the end. if t.changed != nil { defer t.changed() } // Handle a few cases where we don't put anything onto the undo stack for // increased efficiency. if continuation { // Same action as the one before. An undo item was already generated for // this block of (same) actions. We're also only changing one character. switch { case insert == "" && deleteStart[1] != 0 && deleteEnd[1] == 0: // Simple backspace. Just shorten this span. length := t.spans[deleteStart[0]].length if length < 0 { t.length -= -length - deleteStart[1] length = -deleteStart[1] } else { t.length -= length - deleteStart[1] length = deleteStart[1] } t.spans[deleteStart[0]].length = length return deleteEnd case insert == "" && deleteStart[1] == 0 && deleteEnd[1] != 0: // Simple delete. Just clip the beginning of this span. t.spans[deleteEnd[0]].offset += deleteEnd[1] if t.spans[deleteEnd[0]].length < 0 { t.spans[deleteEnd[0]].length += deleteEnd[1] } else { t.spans[deleteEnd[0]].length -= deleteEnd[1] } t.length -= deleteEnd[1] deleteEnd[1] = 0 return deleteEnd case insert != "" && deleteStart == deleteEnd && deleteEnd[1] == 0: previous := t.spans[deleteStart[0]].previous bufferSpan := t.spans[previous] if bufferSpan.length > 0 && bufferSpan.offset+bufferSpan.length == t.editText.Len() { // Typing individual characters. Simply extend the edit buffer. length, _ := t.editText.WriteString(insert) t.spans[previous].length += length t.length += length return deleteEnd } } } // All other cases generate an undo item. before := t.spans[deleteStart[0]].previous after := deleteEnd[0] if deleteEnd[1] > 0 { after = t.spans[deleteEnd[0]].next } t.undoStack = t.undoStack[:t.nextUndo] t.undoStack = append(t.undoStack, textAreaUndoItem{ before: len(t.spans), after: len(t.spans) + 1, originalBefore: before, originalAfter: after, length: t.length, pos: t.cursor.pos, continuation: continuation, }) t.spans = append(t.spans, t.spans[before]) t.spans = append(t.spans, t.spans[after]) t.nextUndo++ // Adjust total text length by subtracting everything between "before" and // "after". Inserted spans will be added back. for index := deleteStart[0]; index != after; index = t.spans[index].next { if t.spans[index].length < 0 { t.length += t.spans[index].length } else { t.length -= t.spans[index].length } } t.spans[before].next = after t.spans[after].previous = before // We go from left to right, connecting new spans as needed. We update // "before" as the span to connect new spans to. // If we start deleting in the middle of a span, connect a partial span. if deleteStart[1] != 0 { span := textAreaSpan{ previous: before, next: after, offset: t.spans[deleteStart[0]].offset, length: deleteStart[1], } if t.spans[deleteStart[0]].length < 0 { span.length = -span.length } t.length += deleteStart[1] // This was previously subtracted. t.spans[before].next = len(t.spans) t.spans[after].previous = len(t.spans) before = len(t.spans) for row, lineStart := range t.lineStarts { // Also redirect line starts until the end of this new span. if lineStart[0] == deleteStart[0] { if lineStart[1] >= deleteStart[1] { t.lineStarts = t.lineStarts[:row] // Everything else is unknown at this point. break } t.lineStarts[row][0] = len(t.spans) } } t.spans = append(t.spans, span) } // If we insert text, connect a new span. if insert != "" { span := textAreaSpan{ previous: before, next: after, offset: t.editText.Len(), } span.length, _ = t.editText.WriteString(insert) t.length += span.length t.spans[before].next = len(t.spans) t.spans[after].previous = len(t.spans) before = len(t.spans) t.spans = append(t.spans, span) } // If we stop deleting in the middle of a span, connect a partial span. if deleteEnd[1] != 0 { span := textAreaSpan{ previous: before, next: after, offset: t.spans[deleteEnd[0]].offset + deleteEnd[1], } length := t.spans[deleteEnd[0]].length if length < 0 { span.length = length + deleteEnd[1] t.length -= span.length // This was previously subtracted. } else { span.length = length - deleteEnd[1] t.length += span.length // This was previously subtracted. } t.spans[before].next = len(t.spans) t.spans[after].previous = len(t.spans) deleteEnd[0], deleteEnd[1] = len(t.spans), 0 t.spans = append(t.spans, span) } return deleteEnd } // Draw draws this primitive onto the screen. func (t *TextArea) Draw(screen tcell.Screen) { t.Box.DrawForSubclass(screen, t) // Prepare x, y, width, height := t.GetInnerRect() if width <= 0 || height <= 0 { return // We have no space for anything. } columnOffset := t.columnOffset if t.wrap { columnOffset = 0 } // Draw label. _, labelBg, _ := t.labelStyle.Decompose() if t.labelWidth > 0 { labelWidth := t.labelWidth if labelWidth > width { labelWidth = width } printWithStyle(screen, t.label, x, y, 0, labelWidth, AlignLeft, t.labelStyle, labelBg == tcell.ColorDefault) x += labelWidth width -= labelWidth } else { _, _, drawnWidth := printWithStyle(screen, t.label, x, y, 0, width, AlignLeft, t.labelStyle, labelBg == tcell.ColorDefault) x += drawnWidth width -= drawnWidth } // What's the space for the input element? if t.width > 0 && t.width < width { width = t.width } if t.height > 0 && t.height < height { height = t.height } if width <= 0 { return // No space left for the text area. } // Draw the input element if necessary. _, bg, _ := t.textStyle.Decompose() if t.disabled { bg = t.backgroundColor } if bg != t.backgroundColor { for row := 0; row < height; row++ { for column := 0; column < width; column++ { screen.SetContent(x+column, y+row, ' ', nil, t.textStyle) } } } // Show/hide the cursor at the end. defer func() { if t.HasFocus() { row, column := t.cursor.row, t.cursor.actualColumn if t.length > 0 && t.wrap && column >= t.lastWidth { // This happens when a row has text all the way until the end, pushing the cursor outside the viewport. row++ column = 0 } if row >= 0 && row-t.rowOffset >= 0 && row-t.rowOffset < height && column-columnOffset >= 0 && column-columnOffset < width { screen.ShowCursor(x+column-columnOffset, y+row-t.rowOffset) } else { screen.HideCursor() } } }() // No text, show placeholder. if t.length == 0 { t.lastHeight, t.lastWidth = height, width t.cursor.row, t.cursor.column, t.cursor.actualColumn, t.cursor.pos = 0, 0, 0, [3]int{1, 0, -1} t.rowOffset, t.columnOffset = 0, 0 if len(t.placeholder) > 0 { t.drawPlaceholder(screen, x, y, width, height) } return // We're done already. } // Make sure the visible lines are broken over. firstDrawing := t.lastWidth == 0 if t.lastWidth != width && t.lineStarts != nil { t.reset() } t.lastHeight, t.lastWidth = height, width t.extendLines(width, t.rowOffset+height) if len(t.lineStarts) <= t.rowOffset { return // It's scrolled out of view. } // If the cursor position is unknown, find it. This usually only happens // before the screen is drawn for the first time. if t.cursor.row < 0 { t.findCursor(true, 0) if t.selectionStart.row < 0 { t.selectionStart = t.cursor } if firstDrawing && t.moved != nil { t.moved() } } // Print the text. var cluster, text string line := t.rowOffset pos := t.lineStarts[line] endPos := pos posX, posY := 0, 0 for pos[0] != 1 { var clusterWidth int cluster, text, _, clusterWidth, pos, endPos = t.step(text, pos, endPos) // Prepare drawing. runes := []rune(cluster) style := t.selectedStyle fromRow, fromColumn := t.cursor.row, t.cursor.actualColumn toRow, toColumn := t.selectionStart.row, t.selectionStart.actualColumn if fromRow > toRow || fromRow == toRow && fromColumn > toColumn { fromRow, fromColumn, toRow, toColumn = toRow, toColumn, fromRow, fromColumn } if toRow < line || toRow == line && toColumn <= posX || fromRow > line || fromRow == line && fromColumn > posX { style = t.textStyle if t.disabled { style = style.Background(t.backgroundColor) } } // Selected tabs are a bit special. if cluster == "\t" && style == t.selectedStyle { for colX := 0; colX < clusterWidth && posX+colX-columnOffset < width; colX++ { screen.SetContent(x+posX+colX-columnOffset, y+posY, ' ', nil, style) } } // Draw character. if posX+clusterWidth-columnOffset <= width && posX-columnOffset >= 0 && clusterWidth > 0 { screen.SetContent(x+posX-columnOffset, y+posY, runes[0], runes[1:], style) } // Advance. posX += clusterWidth if line+1 < len(t.lineStarts) && t.lineStarts[line+1] == pos { // We must break over. posY++ if posY >= height { break // Done. } posX = 0 line++ } } } // drawPlaceholder draws the placeholder text into the given rectangle. It does // not do anything if the text area already contains text or if there is no // placeholder text. func (t *TextArea) drawPlaceholder(screen tcell.Screen, x, y, width, height int) { // We use a TextView to draw the placeholder. It will take care of word // wrapping etc. textView := NewTextView(). SetText(t.placeholder). SetTextStyle(t.placeholderStyle) textView.SetRect(x, y, width, height) textView.Draw(screen) } // reset resets many of the local variables of the text area because they cannot // be used anymore and must be recalculated, typically after the text area's // size has changed. func (t *TextArea) reset() { t.truncateLines(0) if t.wrap { t.cursor.row = -1 t.selectionStart.row = -1 } t.widestLine = 0 } // extendLines traverses the current text and extends [TextArea.lineStarts] such // that it describes at least maxLines+1 lines (or less if the text is shorter). // Text is laid out for the given width while respecting the wrapping settings. // It is assumed that if [TextArea.lineStarts] already has entries, they obey // the same rules. // // If width is 0, nothing happens. func (t *TextArea) extendLines(width, maxLines int) { if width <= 0 { return } // Start with the first span. if len(t.lineStarts) == 0 { if len(t.spans) > 2 { t.lineStarts = append(t.lineStarts, [3]int{t.spans[0].next, 0, -1}) } else { return // No text. } } // Determine starting positions and starting spans. pos := t.lineStarts[len(t.lineStarts)-1] // The starting position is the last known line. endPos := pos var ( cluster, text string lineWidth, clusterWidth, boundaries int lastGraphemeBreak, lastLineBreak [3]int widthSinceLineBreak int ) for pos[0] != 1 { // Get the next grapheme cluster. cluster, text, boundaries, clusterWidth, pos, endPos = t.step(text, pos, endPos) lineWidth += clusterWidth widthSinceLineBreak += clusterWidth // Any line breaks? if !t.wrap || lineWidth <= width { if boundaries&uniseg.MaskLine == uniseg.LineMustBreak && (len(text) > 0 || uniseg.HasTrailingLineBreakInString(cluster)) { // We must break over. t.lineStarts = append(t.lineStarts, pos) if lineWidth > t.widestLine { t.widestLine = lineWidth } lineWidth = 0 lastGraphemeBreak = [3]int{} lastLineBreak = [3]int{} widthSinceLineBreak = 0 if len(t.lineStarts) > maxLines { break // We have enough lines, we can stop. } continue } } else { // t.wrap && lineWidth > width if !t.wordWrap || lastLineBreak == [3]int{} { if lastGraphemeBreak != [3]int{} { // We have at least one character on each line. // Break after last grapheme. t.lineStarts = append(t.lineStarts, lastGraphemeBreak) if lineWidth > t.widestLine { t.widestLine = lineWidth } lineWidth = clusterWidth lastLineBreak = [3]int{} } } else { // t.wordWrap && lastLineBreak != [3]int{} // Break after last line break opportunity. t.lineStarts = append(t.lineStarts, lastLineBreak) if lineWidth > t.widestLine { t.widestLine = lineWidth } lineWidth = widthSinceLineBreak lastLineBreak = [3]int{} } } // Analyze break opportunities. if boundaries&uniseg.MaskLine == uniseg.LineCanBreak { lastLineBreak = pos widthSinceLineBreak = 0 } lastGraphemeBreak = pos // Can we stop? if len(t.lineStarts) > maxLines { break } } if lineWidth > t.widestLine { t.widestLine = lineWidth } } // truncateLines truncates the trailing lines of the [TextArea.lineStarts] // slice such that len(lineStarts) <= fromLine. If fromLine is negative, a value // of 0 is assumed. If it is greater than the length of lineStarts, nothing // happens. func (t *TextArea) truncateLines(fromLine int) { if fromLine < 0 { fromLine = 0 } if fromLine < len(t.lineStarts) { t.lineStarts = t.lineStarts[:fromLine] } } // findCursor determines the cursor position if its "row" value is < 0 // (=unknown) but only its span position ("pos" value) is known. If the cursor // position is already known (row >= 0), it can also be used to modify row and // column offsets such that the cursor is visible during the next call to // [TextArea.Draw], by setting "clamp" to true. // // To determine the cursor position, "startRow" helps reduce processing time by // indicating the lowest row in which searching should start. Set this to 0 if // you don't have any information where the cursor might be (but know that this // is expensive for long texts). // // The cursor's desired column will be set to its actual column. func (t *TextArea) findCursor(clamp bool, startRow int) { defer func() { t.cursor.column = t.cursor.actualColumn }() if !clamp && t.cursor.row >= 0 || t.lastWidth <= 0 { return // Nothing to do. } // Clamp to viewport. if clamp && t.cursor.row >= 0 { cursorRow := t.cursor.row if t.wrap && t.cursor.actualColumn >= t.lastWidth { cursorRow++ // A row can push the cursor just outside the viewport. It will wrap onto the next line. } if cursorRow < t.rowOffset { // We're above the viewport. t.rowOffset = cursorRow } else if cursorRow >= t.rowOffset+t.lastHeight { // We're below the viewport. t.rowOffset = cursorRow - t.lastHeight + 1 if t.rowOffset >= len(t.lineStarts) { t.extendLines(t.lastWidth, t.rowOffset) if t.rowOffset >= len(t.lineStarts) { t.rowOffset = len(t.lineStarts) - 1 if t.rowOffset < 0 { t.rowOffset = 0 } } } } if !t.wrap { if t.cursor.actualColumn < t.columnOffset+t.minCursorPrefix { // We're left of the viewport. t.columnOffset = t.cursor.actualColumn - t.minCursorPrefix if t.columnOffset < 0 { t.columnOffset = 0 } } else if t.cursor.actualColumn >= t.columnOffset+t.lastWidth-t.minCursorSuffix { // We're right of the viewport. t.columnOffset = t.cursor.actualColumn - t.lastWidth + t.minCursorSuffix if t.columnOffset >= t.widestLine { t.columnOffset = t.widestLine - 1 if t.columnOffset < 0 { t.columnOffset = 0 } } } } return } // The screen position of the cursor is unknown. Find it. This can be // expensive. First, find the row. row := startRow if row < 0 { row = 0 } RowLoop: for { // Examine the current row. if row+1 >= len(t.lineStarts) { t.extendLines(t.lastWidth, row+1) } if row >= len(t.lineStarts) { t.cursor.row, t.cursor.actualColumn, t.cursor.pos = row, 0, [3]int{1, 0, -1} break // It's the end of the text. } // Check this row's spans to see if the cursor is in this row. pos := t.lineStarts[row] for pos[0] != 1 { if row+1 >= len(t.lineStarts) { break // It's the last row so the cursor must be in this row. } if t.cursor.pos[0] == pos[0] { // The cursor is in this span. if t.lineStarts[row+1][0] == pos[0] { // The next row starts with the same span. if t.cursor.pos[1] >= t.lineStarts[row+1][1] { // The cursor is not in this row. row++ continue RowLoop } else { // The cursor is in this row. break } } else { // The next row starts with a different span. The cursor // must be in this row. break } } else { // The cursor is in a different span. if t.lineStarts[row+1][0] == pos[0] { // The next row starts with the same span. This row is // irrelevant. row++ continue RowLoop } else { // The next row starts with a different span. Move towards it. pos = [3]int{t.spans[pos[0]].next, 0, -1} } } } // Try to find the screen position in this row. pos = t.lineStarts[row] endPos := pos column := 0 var text string for { if pos[0] == 1 || t.cursor.pos[0] == pos[0] && t.cursor.pos[1] == pos[1] { // We found the position. We're done. t.cursor.row, t.cursor.actualColumn, t.cursor.pos = row, column, pos break RowLoop } var clusterWidth int _, text, _, clusterWidth, pos, endPos = t.step(text, pos, endPos) if row+1 < len(t.lineStarts) && t.lineStarts[row+1] == pos { // We reached the end of the line. Go to the next one. row++ continue RowLoop } column += clusterWidth } } if clamp && t.cursor.row >= 0 { // We know the position now. Adapt offsets. t.findCursor(true, startRow) } } // setTransform sets the transform function to be used when drawing the text. // This function is called for each grapheme cluster and can be used to modify // the cluster, the cluster's screen width, and the cluster's boundaries. The // function is called with the original cluster, the rest of the text, the // original cluster's width, and the original cluster's boundaries. The function // must return the new cluster, the new width, and the new boundaries. This only // affects the drawing of the text, not the text content itself. The boundaries // values correspond to the values returned by // [github.com/rivo/uniseg.StepString]. func (t *TextArea) setTransform(transform func(cluster, rest string, boundaries int) (newCluster string, newBoundaries int)) { t.transform = transform } // step is similar to [github.com/rivo/uniseg.StepString] but it iterates over // the piece chain, starting with "pos", a span position plus state (which may // be -1 for the start of the text). The returned "boundaries" value is the same // value returned by [github.com/rivo/uniseg.StepString], "width" is the screen // width of the grapheme. The "pos" and "endPos" positions refer to the start // and the end of the "text" string, respectively. For the first call, text may // be empty and pos/endPos may be the same. For consecutive calls, provide // "rest" as the text and "newPos" and "newEndPos" as the new positions/states. // An empty "rest" string indicates the end of the text. The "endPos" state is // irrelevant. func (t *TextArea) step(text string, pos, endPos [3]int) (cluster, rest string, boundaries, width int, newPos, newEndPos [3]int) { if pos[0] == 1 { return // We're already past the end. } // We want to make sure we have a text at least the size of a grapheme // cluster. span := t.spans[pos[0]] if len(text) < maxGraphemeClusterSize && (span.length < 0 && -span.length-pos[1] >= maxGraphemeClusterSize || span.length > 0 && t.spans[pos[0]].length-pos[1] >= maxGraphemeClusterSize) { // We can use a substring of one span. if span.length < 0 { text = t.initialText[span.offset+pos[1] : span.offset-span.length] } else { text = t.editText.String()[span.offset+pos[1] : span.offset+span.length] } endPos = [3]int{span.next, 0, -1} } else { // We have to compose the text from multiple spans. for len(text) < maxGraphemeClusterSize && endPos[0] != 1 { endSpan := t.spans[endPos[0]] var moreText string if endSpan.length < 0 { moreText = t.initialText[endSpan.offset+endPos[1] : endSpan.offset-endSpan.length] } else { moreText = t.editText.String()[endSpan.offset+endPos[1] : endSpan.offset+endSpan.length] } if len(moreText) > maxGraphemeClusterSize { moreText = moreText[:maxGraphemeClusterSize] } text += moreText endPos[1] += len(moreText) if endPos[1] >= endSpan.length { endPos[0], endPos[1] = endSpan.next, 0 } } } // Run the grapheme cluster iterator. cluster, text, boundaries, pos[2] = uniseg.StepString(text, pos[2]) pos[1] += len(cluster) for pos[0] != 1 && (span.length < 0 && pos[1] >= -span.length || span.length >= 0 && pos[1] >= span.length) { pos[0] = span.next if span.length < 0 { pos[1] += span.length } else { pos[1] -= span.length } span = t.spans[pos[0]] } if t.transform != nil { cluster, boundaries = t.transform(cluster, text, boundaries) } if cluster == "\t" { width = TabSize } else { width = boundaries >> uniseg.ShiftWidth } return cluster, text, boundaries, width, pos, endPos } // moveCursor sets the cursor's screen position and span position for the given // row and column which are screen space coordinates relative to the top-left // corner of the text area's full text (visible or not). The column value may be // negative, in which case, the cursor will be placed at the end of the line. // The cursor's actual position will be aligned with a grapheme cluster // boundary. The next call to [TextArea.Draw] will attempt to keep the cursor in // the viewport. func (t *TextArea) moveCursor(row, column int) { // Are we within the range of rows? if len(t.lineStarts) <= row { // No. Extent the line buffer. t.extendLines(t.lastWidth, row) } if len(t.lineStarts) == 0 { return // No lines. Nothing to do. } if row < 0 { // We're at the start of the text. row = 0 column = 0 } else if row >= len(t.lineStarts) { // We're already past the end. row = len(t.lineStarts) - 1 column = -1 } // Iterate through this row until we find the position. t.cursor.row, t.cursor.actualColumn = row, 0 if t.wrap { t.cursor.actualColumn = 0 } pos := t.lineStarts[row] endPos := pos var text string for pos[0] != 1 { var clusterWidth int oldPos := pos // We may have to revert to this position. _, text, _, clusterWidth, pos, endPos = t.step(text, pos, endPos) if len(t.lineStarts) > row+1 && pos == t.lineStarts[row+1] || // We've reached the end of the line. column >= 0 && t.cursor.actualColumn+clusterWidth > column { // We're past the requested column. pos = oldPos break } t.cursor.actualColumn += clusterWidth } if column < 0 { t.cursor.column = t.cursor.actualColumn } else { t.cursor.column = column } t.cursor.pos = pos t.findCursor(true, row) } // moveWordRight moves the cursor to the end of the current or next word. If // after is set to true, the cursor will be placed after the word. If false, the // cursor will be placed on the last character of the word. If clamp is set to // true, the cursor will be visible during the next call to [TextArea.Draw]. func (t *TextArea) moveWordRight(after, clamp bool) { // Because we rely on clampToCursor to calculate the new screen position, // this is an expensive operation for large texts. pos := t.cursor.pos endPos := pos var ( cluster, text string inWord bool ) for pos[0] != 0 { var boundaries int oldPos := pos cluster, text, boundaries, _, pos, endPos = t.step(text, pos, endPos) if oldPos == t.cursor.pos { continue // Skip the first character. } firstRune, _ := utf8.DecodeRuneInString(cluster) if !unicode.IsSpace(firstRune) && !unicode.IsPunct(firstRune) { inWord = true } if inWord && boundaries&uniseg.MaskWord != 0 { if !after { pos = oldPos } break } } startRow := t.cursor.row t.cursor.row, t.cursor.column, t.cursor.actualColumn = -1, 0, 0 t.cursor.pos = pos t.findCursor(clamp, startRow) } // moveWordLeft moves the cursor to the beginning of the current or previous // word. If clamp is true, the cursor will be visible during the next call to // [TextArea.Draw]. func (t *TextArea) moveWordLeft(clamp bool) { // We go back row by row, trying to find the last word boundary before the // cursor. row := t.cursor.row if row+1 < len(t.lineStarts) { t.extendLines(t.lastWidth, row+1) } if row >= len(t.lineStarts) { row = len(t.lineStarts) - 1 } for row >= 0 { pos := t.lineStarts[row] endPos := pos var lastWordBoundary [3]int var ( cluster, text string inWord bool boundaries int ) for pos[0] != 1 && pos != t.cursor.pos { oldBoundaries := boundaries oldPos := pos cluster, text, boundaries, _, pos, endPos = t.step(text, pos, endPos) firstRune, _ := utf8.DecodeRuneInString(cluster) wordRune := !unicode.IsSpace(firstRune) && !unicode.IsPunct(firstRune) if oldBoundaries&uniseg.MaskWord != 0 { if pos != t.cursor.pos && !inWord && wordRune { // A boundary transitioning from a space/punctuation word to // a letter word. lastWordBoundary = oldPos } inWord = false } if wordRune { inWord = true } } if lastWordBoundary[0] != 0 { // We found something. t.cursor.pos = lastWordBoundary break } row-- } if row < 0 { // We didn't find anything. We're at the start of the text. t.cursor.pos = [3]int{t.spans[0].next, 0, -1} row = 0 } t.cursor.row, t.cursor.column, t.cursor.actualColumn = -1, 0, 0 t.findCursor(clamp, row) } // deleteLine deletes all characters between the last newline before the cursor // and the next newline after the cursor (inclusive). func (t *TextArea) deleteLine() { // We go back row by row, trying to find the last mandatory line break // before the cursor. startRow := t.cursor.row if t.cursor.actualColumn == 0 && t.cursor.pos[0] == 1 { startRow-- // If we're at the very end, delete the row before. } if startRow+1 < len(t.lineStarts) { t.extendLines(t.lastWidth, startRow+1) } if len(t.lineStarts) == 0 { return // Nothing to delete. } if startRow >= len(t.lineStarts) { startRow = len(t.lineStarts) - 1 } for startRow >= 0 { // What's the last rune before the start of the line? pos := t.lineStarts[startRow] span := t.spans[pos[0]] var text string if pos[1] > 0 { // Extract text from this span. if span.length < 0 { text = t.initialText } else { text = t.editText.String() } text = text[:span.offset+pos[1]] } else { // Extract text from the previous span. if span.previous != 0 { span = t.spans[span.previous] if span.length < 0 { text = t.initialText[:span.offset-span.length] } else { text = t.editText.String()[:span.offset+span.length] } } } if uniseg.HasTrailingLineBreakInString(text) { // The row before this one ends with a mandatory line break. This is // the first line we will delete. break } startRow-- } if startRow < 0 { // We didn't find anything. It'll be the first line. startRow = 0 } // Find the next line break after the cursor. pos := t.cursor.pos endPos := pos var cluster, text string for pos[0] != 1 { cluster, text, _, _, pos, endPos = t.step(text, pos, endPos) if uniseg.HasTrailingLineBreakInString(cluster) { break } } // Delete the text. t.cursor.pos = t.replace(t.lineStarts[startRow], pos, "", false) t.cursor.row = -1 t.truncateLines(startRow) t.findCursor(true, startRow) } // getSelection returns the current selection as span locations where the first // returned location is always before or the same as the second returned // location. This assumes that the cursor and selection positions are known. The // third return value is the starting row of the selection. func (t *TextArea) getSelection() ([3]int, [3]int, int) { from := t.selectionStart.pos to := t.cursor.pos row := t.selectionStart.row if t.cursor.row < t.selectionStart.row || (t.cursor.row == t.selectionStart.row && t.cursor.actualColumn < t.selectionStart.actualColumn) { from, to = to, from row = t.cursor.row } return from, to, row } // getSelectedText returns the text of the current selection. func (t *TextArea) getSelectedText() string { var text strings.Builder from, to, _ := t.getSelection() for from[0] != to[0] { span := t.spans[from[0]] if span.length < 0 { text.WriteString(t.initialText[span.offset+from[1] : span.offset-span.length]) } else { text.WriteString(t.editText.String()[span.offset+from[1] : span.offset+span.length]) } from[0], from[1] = span.next, 0 } if from[0] != 1 && from[1] < to[1] { span := t.spans[from[0]] if span.length < 0 { text.WriteString(t.initialText[span.offset+from[1] : span.offset+to[1]]) } else { text.WriteString(t.editText.String()[span.offset+from[1] : span.offset+to[1]]) } } return text.String() } // InputHandler returns the handler for this primitive. func (t *TextArea) InputHandler() func(event *tcell.EventKey, setFocus func(p Primitive)) { return t.WrapInputHandler(func(event *tcell.EventKey, setFocus func(p Primitive)) { if t.disabled { return } // All actions except a few specific ones are "other" actions. newLastAction := taActionOther defer func() { t.lastAction = newLastAction }() // Trigger a "moved" event if requested. if t.moved != nil { selectionStart, cursor := t.selectionStart, t.cursor defer func() { if selectionStart != t.selectionStart || cursor != t.cursor { t.moved() } }() } // Process the different key events. switch key := event.Key(); key { case tcell.KeyLeft: // Move one grapheme cluster to the left. if event.Modifiers()&tcell.ModAlt == 0 { // Regular movement. if event.Modifiers()&tcell.ModShift == 0 && t.selectionStart.pos != t.cursor.pos { // Move to the start of the selection. if t.selectionStart.row < t.cursor.row || (t.selectionStart.row == t.cursor.row && t.selectionStart.actualColumn < t.cursor.actualColumn) { t.cursor = t.selectionStart } t.findCursor(true, t.cursor.row) } else if event.Modifiers()&tcell.ModMeta != 0 || event.Modifiers()&tcell.ModCtrl != 0 { // This captures Ctrl-Left on some systems. t.moveWordLeft(event.Modifiers()&tcell.ModShift != 0) } else if t.cursor.actualColumn == 0 { // Move to the end of the previous row. if t.cursor.row > 0 { t.moveCursor(t.cursor.row-1, -1) } } else { // Move one grapheme cluster to the left. t.moveCursor(t.cursor.row, t.cursor.actualColumn-1) } if event.Modifiers()&tcell.ModShift == 0 { t.selectionStart = t.cursor } } else if !t.wrap { // This doesn't work on all terminals. // Just scroll. t.columnOffset-- if t.columnOffset < 0 { t.columnOffset = 0 } } case tcell.KeyRight: // Move one grapheme cluster to the right. if event.Modifiers()&tcell.ModAlt == 0 { // Regular movement. if event.Modifiers()&tcell.ModShift == 0 && t.selectionStart.pos != t.cursor.pos { // Move to the end of the selection. if t.selectionStart.row > t.cursor.row || (t.selectionStart.row == t.cursor.row && t.selectionStart.actualColumn > t.cursor.actualColumn) { t.cursor = t.selectionStart } t.findCursor(true, t.cursor.row) } else if t.cursor.pos[0] != 1 { if event.Modifiers()&tcell.ModMeta != 0 || event.Modifiers()&tcell.ModCtrl != 0 { // This captures Ctrl-Right on some systems. t.moveWordRight(event.Modifiers()&tcell.ModShift != 0, true) } else { // Move one grapheme cluster to the right. var clusterWidth int _, _, _, clusterWidth, t.cursor.pos, _ = t.step("", t.cursor.pos, t.cursor.pos) if len(t.lineStarts) <= t.cursor.row+1 { t.extendLines(t.lastWidth, t.cursor.row+1) } if t.cursor.row+1 < len(t.lineStarts) && t.lineStarts[t.cursor.row+1] == t.cursor.pos { // We've reached the end of the line. t.cursor.row++ t.cursor.actualColumn = 0 t.cursor.column = 0 t.findCursor(true, t.cursor.row) } else { // Move one character to the right. t.moveCursor(t.cursor.row, t.cursor.actualColumn+clusterWidth) } } } if event.Modifiers()&tcell.ModShift == 0 { t.selectionStart = t.cursor } } else if !t.wrap { // This doesn't work on all terminals. // Just scroll. t.columnOffset++ if t.columnOffset >= t.widestLine { t.columnOffset = t.widestLine - 1 if t.columnOffset < 0 { t.columnOffset = 0 } } } case tcell.KeyDown: // Move one row down. if event.Modifiers()&tcell.ModAlt == 0 { // Regular movement. column := t.cursor.column t.moveCursor(t.cursor.row+1, t.cursor.column) t.cursor.column = column if event.Modifiers()&tcell.ModShift == 0 { t.selectionStart = t.cursor } } else { // Just scroll. t.rowOffset++ if t.rowOffset >= len(t.lineStarts) { t.extendLines(t.lastWidth, t.rowOffset) if t.rowOffset >= len(t.lineStarts) { t.rowOffset = len(t.lineStarts) - 1 if t.rowOffset < 0 { t.rowOffset = 0 } } } } case tcell.KeyUp: // Move one row up. if event.Modifiers()&tcell.ModAlt == 0 { // Regular movement. column := t.cursor.column t.moveCursor(t.cursor.row-1, t.cursor.column) t.cursor.column = column if event.Modifiers()&tcell.ModShift == 0 { t.selectionStart = t.cursor } } else { // Just scroll. t.rowOffset-- if t.rowOffset < 0 { t.rowOffset = 0 } } case tcell.KeyHome, tcell.KeyCtrlA: // Move to the start of the line. t.moveCursor(t.cursor.row, 0) if event.Modifiers()&tcell.ModShift == 0 { t.selectionStart = t.cursor } case tcell.KeyEnd, tcell.KeyCtrlE: // Move to the end of the line. t.moveCursor(t.cursor.row, -1) if event.Modifiers()&tcell.ModShift == 0 { t.selectionStart = t.cursor } case tcell.KeyPgDn, tcell.KeyCtrlF: // Move one page down. column := t.cursor.column t.moveCursor(t.cursor.row+t.lastHeight, t.cursor.column) t.cursor.column = column if event.Modifiers()&tcell.ModShift == 0 { t.selectionStart = t.cursor } case tcell.KeyPgUp, tcell.KeyCtrlB: // Move one page up. column := t.cursor.column t.moveCursor(t.cursor.row-t.lastHeight, t.cursor.column) t.cursor.column = column if event.Modifiers()&tcell.ModShift == 0 { t.selectionStart = t.cursor } case tcell.KeyEnter: // Insert a newline. from, to, row := t.getSelection() t.cursor.pos = t.replace(from, to, NewLine, t.lastAction == taActionTypeSpace) t.cursor.row = -1 t.truncateLines(row - 1) t.findCursor(true, row) t.selectionStart = t.cursor newLastAction = taActionTypeSpace case tcell.KeyTab: // Insert a tab character. It will be rendered as TabSize spaces. // But forwarding takes precedence. if t.finished != nil { t.finished(key) return } from, to, row := t.getSelection() t.cursor.pos = t.replace(from, to, "\t", t.lastAction == taActionTypeSpace) t.cursor.row = -1 t.truncateLines(row - 1) t.findCursor(true, row) t.selectionStart = t.cursor newLastAction = taActionTypeSpace case tcell.KeyBacktab, tcell.KeyEscape: // Only used in forms. if t.finished != nil { t.finished(key) return } case tcell.KeyRune: if event.Modifiers()&tcell.ModAlt > 0 { // We accept some Alt- key combinations. switch event.Rune() { case 'f': if event.Modifiers()&tcell.ModShift == 0 { t.moveWordRight(false, true) t.selectionStart = t.cursor } else { t.moveWordRight(true, true) } case 'b': t.moveWordLeft(true) if event.Modifiers()&tcell.ModShift == 0 { t.selectionStart = t.cursor } } } else { // Other keys are simply accepted as regular characters. r := event.Rune() from, to, row := t.getSelection() newLastAction = taActionTypeNonSpace if unicode.IsSpace(r) { newLastAction = taActionTypeSpace } t.cursor.pos = t.replace(from, to, string(r), newLastAction == t.lastAction || t.lastAction == taActionTypeNonSpace && newLastAction == taActionTypeSpace) t.cursor.row = -1 t.truncateLines(row - 1) t.findCursor(true, row) t.selectionStart = t.cursor } case tcell.KeyBackspace, tcell.KeyBackspace2: // Delete backwards. tcell.KeyBackspace is the same as tcell.CtrlH. from, to, row := t.getSelection() if from != to { // Simply delete the current selection. t.cursor.pos = t.replace(from, to, "", false) t.cursor.row = -1 t.truncateLines(row - 1) t.findCursor(true, row) t.selectionStart = t.cursor break } beforeCursor := t.cursor if event.Modifiers()&tcell.ModAlt == 0 { // Move the cursor back by one grapheme cluster. if t.cursor.actualColumn == 0 { // Move to the end of the previous row. if t.cursor.row > 0 { t.moveCursor(t.cursor.row-1, -1) } } else { // Move one grapheme cluster to the left. t.moveCursor(t.cursor.row, t.cursor.actualColumn-1) } newLastAction = taActionBackspace } else { // Move the cursor back by one word. t.moveWordLeft(false) } // Remove that last grapheme cluster. if t.cursor.pos != beforeCursor.pos { t.cursor, beforeCursor = beforeCursor, t.cursor // So we put the right position on the stack. t.cursor.pos = t.replace(beforeCursor.pos, t.cursor.pos, "", t.lastAction == taActionBackspace) // Delete the character. t.cursor.row = -1 t.truncateLines(beforeCursor.row - 1) t.findCursor(true, beforeCursor.row-1) } t.selectionStart = t.cursor case tcell.KeyDelete, tcell.KeyCtrlD: // Delete forward. from, to, row := t.getSelection() if from != to { // Simply delete the current selection. t.cursor.pos = t.replace(from, to, "", false) t.cursor.row = -1 t.truncateLines(row - 1) t.findCursor(true, row) t.selectionStart = t.cursor break } if t.cursor.pos[0] != 1 { _, _, _, _, endPos, _ := t.step("", t.cursor.pos, t.cursor.pos) t.cursor.pos = t.replace(t.cursor.pos, endPos, "", t.lastAction == taActionDelete) // Delete the character. t.cursor.pos[2] = endPos[2] t.truncateLines(t.cursor.row - 1) t.findCursor(true, t.cursor.row) newLastAction = taActionDelete } t.selectionStart = t.cursor case tcell.KeyCtrlK: // Delete everything under and to the right of the cursor until before the next newline character. pos := t.cursor.pos endPos := pos var cluster, text string for pos[0] != 1 { var boundaries int oldPos := pos cluster, text, boundaries, _, pos, endPos = t.step(text, pos, endPos) if boundaries&uniseg.MaskLine == uniseg.LineMustBreak { if uniseg.HasTrailingLineBreakInString(cluster) { pos = oldPos } break } } t.cursor.pos = t.replace(t.cursor.pos, pos, "", false) row := t.cursor.row t.cursor.row = -1 t.truncateLines(row - 1) t.findCursor(true, row) t.selectionStart = t.cursor case tcell.KeyCtrlW: // Delete from the start of the current word to the left of the cursor. pos := t.cursor.pos t.moveWordLeft(true) t.cursor.pos = t.replace(t.cursor.pos, pos, "", false) row := t.cursor.row - 1 t.cursor.row = -1 t.truncateLines(row) t.findCursor(true, row) t.selectionStart = t.cursor case tcell.KeyCtrlU: // Delete the current line. t.deleteLine() t.selectionStart = t.cursor case tcell.KeyCtrlL: // Select everything. t.selectionStart.row, t.selectionStart.column, t.selectionStart.actualColumn = 0, 0, 0 t.selectionStart.pos = [3]int{t.spans[0].next, 0, -1} row := t.cursor.row t.cursor.row = -1 t.cursor.pos = [3]int{1, 0, -1} t.findCursor(false, row) case tcell.KeyCtrlQ: // Copy to clipboard. if t.cursor != t.selectionStart { t.copyToClipboard(t.getSelectedText()) t.selectionStart = t.cursor } case tcell.KeyCtrlX: // Cut to clipboard. if t.cursor != t.selectionStart { t.copyToClipboard(t.getSelectedText()) from, to, row := t.getSelection() t.cursor.pos = t.replace(from, to, "", false) t.cursor.row = -1 t.truncateLines(row - 1) t.findCursor(true, row) t.selectionStart = t.cursor } case tcell.KeyCtrlV: // Paste from clipboard. from, to, row := t.getSelection() t.cursor.pos = t.replace(from, to, t.pasteFromClipboard(), false) t.cursor.row = -1 t.truncateLines(row - 1) t.findCursor(true, row) t.selectionStart = t.cursor case tcell.KeyCtrlZ: // Undo. if t.nextUndo <= 0 { break } for t.nextUndo > 0 { t.nextUndo-- undo := t.undoStack[t.nextUndo] t.spans[undo.originalBefore], t.spans[undo.before] = t.spans[undo.before], t.spans[undo.originalBefore] t.spans[undo.originalAfter], t.spans[undo.after] = t.spans[undo.after], t.spans[undo.originalAfter] t.cursor.pos, t.undoStack[t.nextUndo].pos = undo.pos, t.cursor.pos t.length, t.undoStack[t.nextUndo].length = undo.length, t.length if !undo.continuation { break } } t.cursor.row = -1 t.truncateLines(0) // This is why Undo is expensive for large texts. (t.lineStarts can get largely unusable after an undo.) t.findCursor(true, 0) t.selectionStart = t.cursor if t.changed != nil { defer t.changed() } case tcell.KeyCtrlY: // Redo. if t.nextUndo >= len(t.undoStack) { break } for t.nextUndo < len(t.undoStack) { undo := t.undoStack[t.nextUndo] t.spans[undo.originalBefore], t.spans[undo.before] = t.spans[undo.before], t.spans[undo.originalBefore] t.spans[undo.originalAfter], t.spans[undo.after] = t.spans[undo.after], t.spans[undo.originalAfter] t.cursor.pos, t.undoStack[t.nextUndo].pos = undo.pos, t.cursor.pos t.length, t.undoStack[t.nextUndo].length = undo.length, t.length t.nextUndo++ if t.nextUndo < len(t.undoStack) && !t.undoStack[t.nextUndo].continuation { break } } t.cursor.row = -1 t.truncateLines(0) // This is why Redo is expensive for large texts. (t.lineStarts can get largely unusable after an undo.) t.findCursor(true, 0) t.selectionStart = t.cursor if t.changed != nil { defer t.changed() } } }) } // MouseHandler returns the mouse handler for this primitive. func (t *TextArea) MouseHandler() func(action MouseAction, event *tcell.EventMouse, setFocus func(p Primitive)) (consumed bool, capture Primitive) { return t.WrapMouseHandler(func(action MouseAction, event *tcell.EventMouse, setFocus func(p Primitive)) (consumed bool, capture Primitive) { if t.disabled { return false, nil } x, y := event.Position() rectX, rectY, _, _ := t.GetInnerRect() if !t.InRect(x, y) { return false, nil } // Trigger a "moved" event at the end if requested. if t.moved != nil { selectionStart, cursor := t.selectionStart, t.cursor defer func() { if selectionStart != t.selectionStart || cursor != t.cursor { t.moved() } }() } // Turn mouse coordinates into text coordinates. labelWidth := t.labelWidth if labelWidth == 0 && t.label != "" { labelWidth = TaggedStringWidth(t.label) } column := x - rectX - labelWidth row := y - rectY if !t.wrap { column += t.columnOffset } row += t.rowOffset // Process mouse actions. switch action { case MouseLeftDown: t.moveCursor(row, column) if event.Modifiers()&tcell.ModShift == 0 { t.selectionStart = t.cursor } setFocus(t) consumed = true capture = t t.dragging = true case MouseMove: if !t.dragging { break } t.moveCursor(row, column) consumed = true case MouseLeftUp: t.moveCursor(row, column) consumed = true capture = nil t.dragging = false case MouseLeftDoubleClick: // Select word. // Left down/up was already triggered so we are at the correct // position. t.moveWordLeft(false) t.selectionStart = t.cursor t.moveWordRight(true, false) consumed = true case MouseScrollUp: if t.rowOffset > 0 { t.rowOffset-- } consumed = true case MouseScrollDown: t.rowOffset++ if t.rowOffset >= len(t.lineStarts) { t.rowOffset = len(t.lineStarts) - 1 if t.rowOffset < 0 { t.rowOffset = 0 } } consumed = true case MouseScrollLeft: if t.columnOffset > 0 { t.columnOffset-- } consumed = true case MouseScrollRight: t.columnOffset++ if t.columnOffset >= t.widestLine { t.columnOffset = t.widestLine - 1 if t.columnOffset < 0 { t.columnOffset = 0 } } consumed = true } return }) } // PasteHandler returns the handler for this primitive. func (t *TextArea) PasteHandler() func(pastedText string, setFocus func(p Primitive)) { return t.WrapPasteHandler(func(pastedText string, setFocus func(p Primitive)) { from, to, row := t.getSelection() t.cursor.pos = t.replace(from, to, pastedText, false) t.cursor.row = -1 t.truncateLines(row - 1) t.findCursor(true, row) t.selectionStart = t.cursor }) } ================================================ FILE: textview.go ================================================ package tview import ( "math" "strings" "sync" "github.com/gdamore/tcell/v2" colorful "github.com/lucasb-eyer/go-colorful" ) // TabSize is the number of spaces with which a tab character will be replaced. var TabSize = 4 // textViewLine contains information about a line displayed in the text view. type textViewLine struct { offset int // The string position in the buffer where this line starts. width int // The screen width of this line. length int // The string length (in bytes) of this line. state *stepState // The parser state at the beginning of the line, before parsing the first character. regions []*Region // The regions on this line, in the order of their appearance. } // Region represents a region in a [TextView]. Note that depending on how the // region is retrieved, the end positions and locations may not correspond to // the true end of the region but to the end of the last line that was parsed. type Region struct { // The region ID. ID string // The start and end offsets into the text string of the region. The end // points to the first byte after the region. Start, End int // The start and end positions of the region in screen coordinates, relative // to the position of where the first character of the text view would be // drawn. StartRow, StartColumn, EndRow, EndColumn int } // batchWriter is a writer that can be used to write to and clear a TextView // in batches, i.e. multiple writes with the lock only being acquired once. // Don't instantiated this class directly but use the [TextView.BatchWriter] // method instead. type batchWriter struct { *TextView } // Close implements io.Closer for the writer by unlocking the original TextView. func (w *batchWriter) Close() error { w.TextView.Unlock() return nil } // Clear removes all text from the buffer. func (w *batchWriter) Clear() { w.TextView.clear() } // Write implements the io.Writer interface. It behaves like the TextView's // Write() method except that it does not acquire the lock. func (w *batchWriter) Write(p []byte) (n int, err error) { return w.TextView.write(p) } // focusChain implements the [Primitive]'s focusChain method. func (w *batchWriter) focusChain(chain *[]Primitive) bool { return w.TextView.Box.focusChain(chain) } // TextView is a component to display read-only text. While the text to be // displayed can be changed or appended to, there is no functionality that // allows the user to edit it. For that, [TextArea] should be used. // // TextView implements the io.Writer interface so you can stream text to it, // appending to the existing text. This does not trigger a redraw automatically // but if a handler is installed via [TextView.SetChangedFunc], you can cause it // to be redrawn. (See [TextView.SetChangedFunc] for more details.) // // Tab characters advance the text to the next tab stop at every [TabSize] // screen columns, but only if the text is left-aligned. If the text is centered // or right-aligned, tab characters are simply replaced with [TabSize] spaces. // // Word wrapping is enabled by default. Use [TextView.SetWrap] and // [TextView.SetWordWrap] to change this. // // # Navigation // // If the text view is set to be scrollable (which is the default), text is kept // in a buffer which may be larger than the screen and can be navigated // with Vim-like key binds: // // - h, left arrow: Move left. // - l, right arrow: Move right. // - j, down arrow: Move down. // - k, up arrow: Move up. // - g, home: Move to the top. // - G, end: Move to the bottom. // - Ctrl-F, page down: Move down by one page. // - Ctrl-B, page up: Move up by one page. // // If the text is not scrollable, any text above the top visible line is // discarded. This can be useful when you want to continuously stream text to // the text view and only keep the latest lines. // // Use [Box.SetInputCapture] to override or modify keyboard input. // // # Styles / Colors // // If dynamic colors are enabled via [TextView.SetDynamicColors], text style can // be changed dynamically by embedding color strings in square brackets. This // works the same way as anywhere else. See the package documentation for more // information. // // # Regions and Highlights // // If regions are enabled via [TextView.SetRegions], you can define text regions // within the text and assign region IDs to them. Text regions start with region // tags. Region tags are square brackets that contain a region ID in double // quotes, for example: // // We define a ["rg"]region[""] here. // // A text region ends with the next region tag. Tags with no region ID ([""]) // don't start new regions. They can therefore be used to mark the end of a // region. Region IDs must satisfy the following regular expression: // // [a-zA-Z0-9_,;: \-\.]+ // // Regions can be highlighted by calling the [TextView.Highlight] function with // one or more region IDs. This can be used to display search results, for // example. // // The [TextView.ScrollToHighlight] function can be used to jump to the // currently highlighted region once when the text view is drawn the next time. // // # Large Texts // // The text view can handle reasonably large texts. It will parse the text as // needed. For optimal performance, it is best to access or display parts of the // text very far down only if really needed. For example, call // [TextView.ScrollToBeginning] before adding the text to the text view, to // avoid scrolling the text all the way to the bottom, forcing a full-text // parse. // // For even larger texts or "infinite" streams of text such as log files, you // should consider using [TextView.SetMaxLines] to limit the number of lines in // the text view buffer. Or disable the text view's scrollability altogether // (using [TextView.SetScrollable]). This will cause the text view to discard // lines moving out of the visible area at the top. // // See https://github.com/rivo/tview/wiki/TextView for an example. type TextView struct { sync.Mutex *Box // The size of the text area. If set to 0, the text view will use the entire // available space. width, height int // The text buffer. text strings.Builder // The line index. It is valid at any time but may not contain trailing // lines which are not visible. lineIndex []*textViewLine // The screen width of the longest line in the index. longestLine int // Regions mapped by their ID to the line where they start. Regions which // cannot be found in [TextView.lineIndex] are not contained. regions map[string]int // The label text shown, usually when part of a form. label string // The width of the text area's label. labelWidth int // The label style. labelStyle tcell.Style // The text alignment, one of AlignLeft, AlignCenter, or AlignRight. align int // Currently highlighted regions. highlights map[string]struct{} // The last width for which the current text view was drawn. lastWidth int // The height of the content the last time the text view was drawn. pageSize int // The index of the first line shown in the text view. lineOffset int // If set to true, the text view will always remain at the end of the // content when text is added. trackEnd bool // The width of the characters to be skipped on each line (not used in wrap // mode). columnOffset int // The maximum number of lines kept in the line index, effectively the // latest word-wrapped lines. Ignored if 0. maxLines int // If set to true, the text view will keep a buffer of text which can be // navigated when the text is longer than what fits into the box. scrollable bool // If set to true, lines that are longer than the available width are // wrapped onto the next line. If set to false, any characters beyond the // available width are discarded. wrap bool // If set to true and if wrap is also true, Unicode line breaking is // applied. wordWrap bool // The (starting) style of the text. This also defines the background color // of the main text element. textStyle tcell.Style // Whether or not style tags are used. styleTags bool // Whether or not region tags are used. regionTags bool // A temporary flag which, when true, will automatically bring the current // highlight(s) into the visible screen the next time the text view is // drawn. scrollToHighlights bool // If true, setting new highlights will be a XOR instead of an overwrite // operation. toggleHighlights bool // An optional function which is called when the content of the text view // has changed. changed func() // An optional function which is called when the user presses one of the // following keys: Escape, Enter, Tab, Backtab. done func(tcell.Key) // An optional function which is called when one or more regions were // highlighted. highlighted func(added, removed, remaining []string) // A callback function set by the Form class and called when the user leaves // this form item. finished func(tcell.Key) } // NewTextView returns a new [TextView]. func NewTextView() *TextView { t := &TextView{ Box: NewBox(), labelStyle: tcell.StyleDefault.Foreground(Styles.SecondaryTextColor), highlights: make(map[string]struct{}), lineOffset: -1, scrollable: true, align: AlignLeft, wrap: true, wordWrap: true, textStyle: tcell.StyleDefault.Background(Styles.PrimitiveBackgroundColor).Foreground(Styles.PrimaryTextColor), regionTags: false, styleTags: false, } t.Box.Primitive = t return t } // SetLabel sets the text to be displayed before the text view. func (t *TextView) SetLabel(label string) *TextView { t.label = label return t } // GetLabel returns the text to be displayed before the text view. func (t *TextView) GetLabel() string { return t.label } // SetLabelWidth sets the screen width of the label. A value of 0 will cause the // primitive to use the width of the label string. func (t *TextView) SetLabelWidth(width int) *TextView { t.labelWidth = width return t } // SetSize sets the screen size of the main text element of the text view. This // element is always located next to the label which is always located in the // top left corner. If any of the values are 0 or larger than the available // space, the available space will be used. func (t *TextView) SetSize(rows, columns int) *TextView { t.width = columns t.height = rows return t } // GetFieldWidth returns this primitive's field width. func (t *TextView) GetFieldWidth() int { return t.width } // GetFieldHeight returns this primitive's field height. func (t *TextView) GetFieldHeight() int { return t.height } // SetDisabled sets whether or not the item is disabled / read-only. func (t *TextView) SetDisabled(disabled bool) FormItem { return t // Text views are always read-only. } // GetDisabled returns whether or not the item is disabled / read-only. func (t *TextView) GetDisabled() bool { return true // Text views are always read-only. } // SetScrollable sets the flag that decides whether or not the text view is // scrollable. If false, text that moves above the text view's top row will be // permanently deleted. func (t *TextView) SetScrollable(scrollable bool) *TextView { t.scrollable = scrollable if !scrollable { t.trackEnd = true } return t } // SetWrap sets the flag that, if true, leads to lines that are longer than the // available width being wrapped onto the next line. If false, any characters // beyond the available width are not displayed. func (t *TextView) SetWrap(wrap bool) *TextView { if t.wrap != wrap { t.resetIndex() // This invalidates the entire index. } t.wrap = wrap return t } // SetWordWrap sets the flag that, if true and if the "wrap" flag is also true // (see [TextView.SetWrap]), wraps according to [Unicode Standard Annex #14]. // // This flag is ignored if the "wrap" flag is false. func (t *TextView) SetWordWrap(wrapOnWords bool) *TextView { if t.wrap && t.wordWrap != wrapOnWords { t.resetIndex() // This invalidates the entire index. } t.wordWrap = wrapOnWords return t } // SetMaxLines sets the maximum number of lines for this text view. Lines at the // beginning of the text will be discarded when the text view is drawn, so as to // remain below this value. Only lines above the first visible line are removed. // // Broken-over lines via word/character wrapping are counted individually. // // Note that [TextView.GetText] will return the shortened text. // // A value of 0 (the default) will keep all lines in place. func (t *TextView) SetMaxLines(maxLines int) *TextView { t.maxLines = maxLines return t } // SetTextAlign sets the text alignment within the text view. This must be // either AlignLeft, AlignCenter, or AlignRight. func (t *TextView) SetTextAlign(align int) *TextView { t.align = align return t } // SetTextColor sets the initial color of the text. func (t *TextView) SetTextColor(color tcell.Color) *TextView { t.textStyle = t.textStyle.Foreground(color) t.resetIndex() return t } // SetBackgroundColor overrides its implementation in Box to set the background // color of this primitive. For backwards compatibility reasons, it also sets // the background color of the main text element. func (t *TextView) SetBackgroundColor(color tcell.Color) *Box { t.Box.SetBackgroundColor(color) t.textStyle = t.textStyle.Background(color) t.resetIndex() return t.Box } // SetTextStyle sets the initial style of the text. This style's background // color also determines the background color of the main text element. func (t *TextView) SetTextStyle(style tcell.Style) *TextView { t.textStyle = style t.resetIndex() return t } // SetText sets the text of this text view to the provided string. Previously // contained text will be removed. As with writing to the text view io.Writer // interface directly, this does not trigger an automatic redraw but it will // trigger the "changed" callback if one is set. func (t *TextView) SetText(text string) *TextView { t.Lock() defer t.Unlock() t.text.Reset() t.text.WriteString(text) t.resetIndex() if t.changed != nil { go t.changed() } return t } // GetText returns the current text of this text view. If "stripAllTags" is set // to true, any region/style tags are stripped from the text. Note that any text // that has been discarded due to [TextView.SetMaxLines] or // [TextView.SetScrollable] will not be part of the returned text. func (t *TextView) GetText(stripAllTags bool) string { if !stripAllTags || (!t.styleTags && !t.regionTags) { return t.text.String() } var ( str strings.Builder state *stepState text = t.text.String() opts stepOptions ch string ) if t.styleTags { opts = stepOptionsStyle } if t.regionTags { opts |= stepOptionsRegion } for len(text) > 0 { ch, text, state = step(text, state, opts) str.WriteString(ch) } return str.String() } // GetOriginalLineCount returns the number of lines in the original text buffer, // without applying any wrapping. This is an expensive call as it needs to // iterate over the entire text. Note that any text that has been discarded due // to [TextView.SetMaxLines] or [TextView.SetScrollable] will not be part of the // count. func (t *TextView) GetOriginalLineCount() int { if t.text.Len() == 0 { return 0 } var ( state *stepState str = t.text.String() lines int = 1 ) for len(str) > 0 { _, str, state = step(str, state, stepOptionsNone) if lineBreak, optional := state.LineBreak(); lineBreak && !optional { lines++ } } return lines } // GetWrappedLineCount returns the number of lines in the text view, taking // wrapping into account (if activated). This is an even more expensive call // than [TextView.GetOriginalLineCount] as it needs to parse the text until the // end and calculate the line breaks. It will also allocate memory for each // line. Note that any text that has been discarded due to // [TextView.SetMaxLines] or [TextView.SetScrollable] will not be part of the // count. Calling this method before the text view was drawn for the first time // will assume no wrapping. func (t *TextView) GetWrappedLineCount() int { t.parseAhead(t.width, func(int, *textViewLine) bool { return false }) return len(t.lineIndex) } // SetDynamicColors sets the flag that allows the text color to be changed // dynamically with style tags. See class description for details. func (t *TextView) SetDynamicColors(dynamic bool) *TextView { if t.styleTags != dynamic { t.resetIndex() // This invalidates the entire index. } t.styleTags = dynamic return t } // SetRegions sets the flag that allows to define regions in the text. See class // description for details. func (t *TextView) SetRegions(regions bool) *TextView { if t.regionTags != regions { t.resetIndex() // This invalidates the entire index. } t.regionTags = regions return t } // SetChangedFunc sets a handler function which is called when the text of the // text view has changed. This is useful when text is written to this // [io.Writer] in a separate goroutine. Doing so does not automatically cause // the screen to be refreshed so you may want to use the "changed" handler to // redraw the screen. // // Note that to avoid race conditions or deadlocks, there are a few rules you // should follow: // // - You can call [Application.Draw] from this handler. // - You can call [TextView.HasFocus] from this handler. // - During the execution of this handler, access to any other variables from // this primitive or any other primitive must be queued using // [Application.QueueUpdate]. // // See package description for details on dealing with concurrency. func (t *TextView) SetChangedFunc(handler func()) *TextView { t.changed = handler return t } // SetDoneFunc sets a handler which is called when the user presses on the // following keys: Escape, Enter, Tab, Backtab. The key is passed to the // handler. func (t *TextView) SetDoneFunc(handler func(key tcell.Key)) *TextView { t.done = handler return t } // SetHighlightedFunc sets a handler which is called when the list of currently // highlighted regions change. It receives a list of region IDs which were newly // highlighted, those that are not highlighted anymore, and those that remain // highlighted. // // Note that because regions are only determined when drawing the text view, // this function can only fire for regions that have existed when the text view // was last drawn. func (t *TextView) SetHighlightedFunc(handler func(added, removed, remaining []string)) *TextView { t.highlighted = handler return t } // SetFinishedFunc sets a callback invoked when the user leaves this form item. func (t *TextView) SetFinishedFunc(handler func(key tcell.Key)) FormItem { t.finished = handler return t } // SetFormAttributes sets attributes shared by all form items. func (t *TextView) SetFormAttributes(labelWidth int, labelColor, bgColor, fieldTextColor, fieldBgColor tcell.Color) FormItem { t.labelWidth = labelWidth t.backgroundColor = bgColor t.labelStyle = t.labelStyle.Foreground(labelColor) // We ignore the field background color because this is a read-only element. t.textStyle = tcell.StyleDefault.Foreground(fieldTextColor).Background(bgColor) return t } // ScrollTo scrolls to the specified row and column (both starting with 0). func (t *TextView) ScrollTo(row, column int) *TextView { if !t.scrollable { return t } t.lineOffset = row t.columnOffset = column t.trackEnd = false return t } // ScrollToBeginning scrolls to the top left corner of the text if the text view // is scrollable. func (t *TextView) ScrollToBeginning() *TextView { if !t.scrollable { return t } t.trackEnd = false t.lineOffset = 0 t.columnOffset = 0 return t } // ScrollToEnd scrolls to the bottom left corner of the text if the text view // is scrollable. Adding new rows to the end of the text view will cause it to // scroll with the new data. func (t *TextView) ScrollToEnd() *TextView { if !t.scrollable { return t } t.trackEnd = true t.columnOffset = 0 return t } // GetScrollOffset returns the number of rows and columns that are skipped at // the top left corner when the text view has been scrolled. func (t *TextView) GetScrollOffset() (row, column int) { return t.lineOffset, t.columnOffset } // Clear removes all text from the buffer. This triggers the "changed" callback. func (t *TextView) Clear() *TextView { t.Lock() defer t.Unlock() t.clear() if t.changed != nil { go t.changed() } return t } // clear is the internal implementation of clear. It is used by [batchWriter] // and anywhere that we need to perform a write without locking the buffer. func (t *TextView) clear() { t.text.Reset() t.resetIndex() } // Highlight specifies which regions should be highlighted. If highlight // toggling is set to true (see [TextView.SetToggleHighlights]), the highlight // of the provided regions is toggled (i.e. highlighted regions are // un-highlighted and vice versa). If toggling is set to false, the provided // regions are highlighted and all other regions will not be highlighted (you // may also provide nil to turn off all highlights). // // For more information on regions, see class description. Empty region strings // or regions not contained in the text are ignored. // // Text in highlighted regions will be drawn inverted, i.e. with their // background and foreground colors swapped. // // If toggling is set to false, clicking outside of any region will remove all // highlights. // // This function is expensive if a specified region is in a part of the text // that has not yet been parsed, as is typically the case for lines below the // visible area. func (t *TextView) Highlight(regionIDs ...string) *TextView { // Make sure we know these regions. t.parseAhead(t.lastWidth, func(lineNumber int, line *textViewLine) bool { for _, regionID := range regionIDs { if _, ok := t.regions[regionID]; !ok { return false } } return true }) // Remove unknown regions. newRegions := make([]string, 0, len(regionIDs)) for _, regionID := range regionIDs { if _, ok := t.regions[regionID]; ok { newRegions = append(newRegions, regionID) } } regionIDs = newRegions // Toggle highlights. if t.toggleHighlights { var newIDs []string HighlightLoop: for regionID := range t.highlights { for _, id := range regionIDs { if regionID == id { continue HighlightLoop } } newIDs = append(newIDs, regionID) } for _, regionID := range regionIDs { if _, ok := t.highlights[regionID]; !ok { newIDs = append(newIDs, regionID) } } regionIDs = newIDs } // Now we have a list of region IDs that end up being highlighted. // Determine added and removed regions. var added, removed, remaining []string if t.highlighted != nil { for _, regionID := range regionIDs { if _, ok := t.highlights[regionID]; ok { remaining = append(remaining, regionID) delete(t.highlights, regionID) } else { added = append(added, regionID) } } for regionID := range t.highlights { removed = append(removed, regionID) } } // Make new selection. t.highlights = make(map[string]struct{}) for _, id := range regionIDs { if id == "" { continue } t.highlights[id] = struct{}{} } // Notify. if t.highlighted != nil && (len(added) > 0 || len(removed) > 0) { t.highlighted(added, removed, remaining) } return t } // GetHighlights returns the IDs of all currently highlighted regions. func (t *TextView) GetHighlights() (regionIDs []string) { for id := range t.highlights { regionIDs = append(regionIDs, id) } return } // SetToggleHighlights sets a flag to determine how regions are highlighted. // When set to true, the [TextView.Highlight] function (or a mouse click) will // toggle the provided/selected regions. When set to false, [TextView.Highlight] // (or a mouse click) will simply highlight the provided regions. func (t *TextView) SetToggleHighlights(toggle bool) *TextView { t.toggleHighlights = toggle return t } // ScrollToHighlight will cause the visible area to be scrolled so that the // highlighted regions appear in the visible area of the text view. This // repositioning happens the next time the text view is drawn. It happens only // once so you will need to call this function repeatedly to always keep // highlighted regions in view. // // Nothing happens if there are no highlighted regions or if the text view is // not scrollable. func (t *TextView) ScrollToHighlight() *TextView { if len(t.highlights) == 0 || !t.scrollable || !t.regionTags { return t } t.scrollToHighlights = true t.trackEnd = false return t } // GetRegionText returns the text of the first region with the given ID. If // dynamic colors are enabled, style tags are stripped from the text. // // If the region does not exist or if regions are turned off, an empty string // is returned. // // This function can be expensive if the specified region is way beyond the // visible area of the text view as the text needs to be parsed until the region // can be found, or if the region does not contain any text. func (t *TextView) GetRegionText(regionID string) string { if !t.regionTags || regionID == "" { return "" } // Parse until we find the region. lineNumber, ok := t.regions[regionID] if !ok { lineNumber = -1 t.parseAhead(t.lastWidth, func(number int, line *textViewLine) bool { lineNumber, ok = t.regions[regionID] return ok }) if lineNumber < 0 { return "" // We couldn't find this region. } } // Extract text from region. var ( line = t.lineIndex[lineNumber] text = t.text.String()[line.offset:] st = *line.state state = &st options = stepOptionsRegion regionText strings.Builder ) if t.styleTags { options |= stepOptionsStyle } for len(text) > 0 { var ch string ch, text, state = step(text, state, options) if state.region == regionID { regionText.WriteString(ch) } else if regionText.Len() > 0 { break } } return regionText.String() } // GetRegions returns the regions in this [TextView]. If tail is set to false, // only regions from the startRow row to the end of the currently visible area // are returned. If tail is set to true, the regions below the visible area of // the view are also included. Note that the latter will require parsing the // entire text and can therefore be expensive. Setting startRow to a value // larger than the last visible row results in nil being returned. To obtain // only visible regions, set startRow to the current row offset (see // [TextView.GetScrollOffset]) and tail to false. // // Regions are returned in the order of their appearance in the text. Do not // modify the returned [Region] objects. Region positions change when the text // view is resized or when the text changes. Such changes will render the // returned slice invalid. // // If this function is called before the text view was drawn for the first // time, the return value is undefined. func (t *TextView) GetRegions(startRow int, tail bool) []*Region { _, _, _, height := t.GetInnerRect() if !t.regionTags || !tail && startRow >= t.lineOffset+height { return nil } // Parse until we have all (complete) regions we need. var lastRegion *Region t.parseAhead(t.lastWidth, func(lineNumber int, line *textViewLine) bool { if tail || lineNumber < t.lineOffset+height { if len(line.regions) > 0 { lastRegion = line.regions[len(line.regions)-1] } return false // These must be parsed in any case. } return len(line.regions) == 0 || line.regions[0] != lastRegion // Keep parsing to complete the last region. }) if startRow >= len(t.lineIndex) { return nil // We don't have that many lines. } // Merge regions into a slice. var regions []*Region for row, line := range t.lineIndex { if tail && row >= t.lineOffset+height { break } for _, region := range line.regions { if len(regions) > 0 && regions[len(regions)-1] == region { continue // Already added. } regions = append(regions, region) } } return regions } // Focus is called when this primitive receives focus. func (t *TextView) Focus(delegate func(p Primitive)) { // Implemented here with locking because this is used by layout primitives. t.Lock() // But if we're part of a form and not scrollable, there's nothing the user // can do here so we're finished. if finished := t.finished; finished != nil && !t.scrollable { t.Unlock() finished(-1) return } t.Box.Focus(delegate) t.Unlock() } // focusChain implements the [Primitive]'s focusChain method. func (t *TextView) focusChain(chain *[]Primitive) bool { // Implemented here with locking because this may be used in the "changed" // callback. t.Lock() defer t.Unlock() return t.Box.focusChain(chain) } // Write lets us implement the io.Writer interface. func (t *TextView) Write(p []byte) (n int, err error) { t.Lock() defer t.Unlock() return t.write(p) } // write is the internal implementation of Write. It is used by [batchWriter] // and anywhere that we need to perform a write without locking the buffer. func (t *TextView) write(p []byte) (n int, err error) { // Notify at the end. changed := t.changed if changed != nil { defer func() { // We always call the "changed" function in a separate goroutine to avoid // deadlocks. go changed() }() } return t.text.Write(p) } // BatchWriter returns a new writer that can be used to write into the buffer // but without Locking/Unlocking the buffer on every write, as [TextView.Write] // and [TextView.Clear] do. The lock will be acquired once when BatchWriter is // called, and will be released when the returned writer is closed. Example: // // tv := tview.NewTextView() // w := tv.BatchWriter() // defer w.Close() // w.Clear() // fmt.Fprintln(w, "To sit in solemn silence") // fmt.Fprintln(w, "on a dull, dark, dock") // fmt.Println(tv.GetText(false)) // // Note that using the batch writer requires you to manage any issues that may // arise from concurrency yourself. See package description for details on // dealing with concurrency. func (t *TextView) BatchWriter() *batchWriter { t.Lock() return &batchWriter{ TextView: t, } } // resetIndex resets all indexed data, including the line index. func (t *TextView) resetIndex() { t.lineIndex = nil t.regions = make(map[string]int) t.longestLine = 0 } // parseAhead parses the text buffer starting at the last line in // [TextView.lineIndex] until either the end of the buffer or until stop returns // true for the last complete line that was parsed. If wrapping is enabled, // width will be used as the available screen width. If width is 0, it is // assumed that there is no wrapping. This can happen when this function is // called before the first time [TextView.Draw] is called. // // There is no guarantee that stop will ever be called. // // The function adds entries to the [TextView.lineIndex] slice and the // [TextView.regions] map and adjusts [TextView.longestLine]. func (t *TextView) parseAhead(width int, stop func(lineNumber int, line *textViewLine) bool) { if t.text.Len() == 0 { return // No text. Nothing to parse. } // If width is 0, make it infinite. if width == 0 { width = math.MaxInt } // What kind of tags do we scan for? var options stepOptions if t.styleTags { options |= stepOptionsStyle } if t.regionTags { options |= stepOptionsRegion } // Start parsing at the last line in the index. var ( lastLine *textViewLine region *Region ) str := t.text.String() // The remaining text to parse. if len(t.lineIndex) == 0 { // Insert the first line. lastLine = &textViewLine{ state: &stepState{ unisegState: -1, style: t.textStyle, }, } t.lineIndex = append(t.lineIndex, lastLine) } else { // Reset the last line. lastLine = t.lineIndex[len(t.lineIndex)-1] lastLine.width = 0 lastLine.length = 0 str = str[lastLine.offset:] } if len(lastLine.regions) > 0 { region = lastLine.regions[0] lastLine.regions = lastLine.regions[:1] } // Parse. var ( lastOption int // Text index of the last optional split point, relative to the beginning of the line. lastOptionWidth int // Line width at last optional split point. lastOptionState *stepState // State at last optional split point. lastOptionRegion *Region // Region at last optional split point or nil if none. leftPos int // The current position in the line (assuming left-alignment). offset = lastLine.offset // Text index of the current position. st = *lastLine.state // Current state. state = &st // Pointer to current state. ) for len(str) > 0 { var c string c, str, state = step(str, state, options) w := state.Width() if c == "\t" { if t.align == AlignLeft { w = TabSize - leftPos%TabSize } else { w = TabSize } } length := state.GrossLength() // Would it exceed the line width? if t.wrap && lastLine.width+w > width { if lastOptionWidth == 0 { // No split point so far. Just split at the current position. if stop(len(t.lineIndex)-1, lastLine) { return } st := *state lastLine = &textViewLine{ offset: offset, state: &st, } if state.region != "" { if state.region == region.ID { lastLine.regions = []*Region{region} } else { region = &Region{ ID: state.region, Start: offset, StartRow: len(t.lineIndex), StartColumn: 0, } } } else { region = nil } lastOption, lastOptionWidth, leftPos = 0, 0, 0 } else { // Split at the last split point. newLine := &textViewLine{ offset: lastLine.offset + lastOption, width: lastLine.width - lastOptionWidth, length: lastLine.length - lastOption, state: lastOptionState, } lastLine.width = lastOptionWidth lastLine.length = lastOption if stop(len(t.lineIndex)-1, lastLine) { return } lastLine = newLine if lastOptionRegion != nil { lastLine.regions = []*Region{lastOptionRegion} } region = lastOptionRegion leftPos -= lastOptionWidth lastOption, lastOptionWidth = 0, 0 } t.lineIndex = append(t.lineIndex, lastLine) } // Is there a region switch? if state.region != "" && (region == nil || state.region != region.ID) { // Start a new region. region = &Region{ ID: state.region, Start: offset, StartRow: len(t.lineIndex) - 1, StartColumn: leftPos, } lastLine.regions = append(lastLine.regions, region) if _, ok := t.regions[state.region]; !ok { t.regions[state.region] = len(t.lineIndex) - 1 } } else if state.region == "" && region != nil { // End the previous region. region = nil } // Move ahead. lastLine.width += w lastLine.length += length offset += length leftPos += w if region != nil { region.End = offset region.EndRow = len(t.lineIndex) - 1 region.EndColumn = leftPos } // Do we have a new longest line? if lastLine.width > t.longestLine { t.longestLine = lastLine.width } // Check for split points. if lineBreak, optional := state.LineBreak(); lineBreak { if optional { if t.wrap && t.wordWrap { // Remember this split point. lastOption = offset - lastLine.offset lastOptionWidth = lastLine.width st := *state lastOptionState = &st lastOptionRegion = region } } else { // We must split here. if stop(len(t.lineIndex)-1, lastLine) { return } st := *state lastLine = &textViewLine{ offset: offset, state: &st, } if region != nil { lastLine.regions = []*Region{region} } t.lineIndex = append(t.lineIndex, lastLine) lastOption, lastOptionWidth, leftPos = 0, 0, 0 } } } } // Draw draws this primitive onto the screen. func (t *TextView) Draw(screen tcell.Screen) { t.Box.DrawForSubclass(screen, t) t.Lock() defer t.Unlock() // Get the available size. x, y, width, height := t.GetInnerRect() t.pageSize = height // Draw label. _, labelBg, _ := t.labelStyle.Decompose() if t.labelWidth > 0 { labelWidth := t.labelWidth if labelWidth > width { labelWidth = width } printWithStyle(screen, t.label, x, y, 0, labelWidth, AlignLeft, t.labelStyle, labelBg == tcell.ColorDefault) x += labelWidth width -= labelWidth } else { _, _, drawnWidth := printWithStyle(screen, t.label, x, y, 0, width, AlignLeft, t.labelStyle, labelBg == tcell.ColorDefault) x += drawnWidth width -= drawnWidth } // What's the space for the text element? if t.width > 0 && t.width < width { width = t.width } if t.height > 0 && t.height < height { height = t.height } if width <= 0 { return // No space left for the text area. } // Draw the text element if necessary. _, bg, _ := t.textStyle.Decompose() if bg != t.backgroundColor { for row := 0; row < height; row++ { for column := 0; column < width; column++ { screen.SetContent(x+column, y+row, ' ', nil, t.textStyle) } } } // If the width has changed, we need to reindex. if width != t.lastWidth && t.wrap { t.resetIndex() } t.lastWidth = width // What are our parse options? var options stepOptions if t.styleTags { options |= stepOptionsStyle } if t.regionTags { options |= stepOptionsRegion } // Scroll to highlighted regions. if t.regionTags && t.scrollToHighlights { // Make sure we know all highlighted regions. t.parseAhead(width, func(lineNumber int, line *textViewLine) bool { for regionID := range t.highlights { if _, ok := t.regions[regionID]; !ok { return false } t.highlights[regionID] = struct{}{} } return true }) // What is the line range for all highlighted regions? var ( firstRegion string fromHighlight, toHighlight int ) for regionID := range t.highlights { // We can safely assume that the region is known. line := t.regions[regionID] if firstRegion == "" || line > toHighlight { toHighlight = line } if firstRegion == "" || line < fromHighlight { fromHighlight = line firstRegion = regionID } } if firstRegion != "" { // Do we fit the entire height? if toHighlight-fromHighlight+1 < height { // Yes, let's center the highlights. t.lineOffset = (fromHighlight + toHighlight - height) / 2 } else { // No, let's move to the start of the highlights. t.lineOffset = fromHighlight } // If the highlight is too far to the right, move it to the middle. if t.wrap { // Find the first highlight's column in screen space. line := t.lineIndex[fromHighlight] st := *line.state state := &st str := t.text.String()[line.offset:] var posHighlight int for len(str) > 0 && posHighlight < line.width && state.region != firstRegion { _, str, state = step(str, state, options) posHighlight += state.Width() } if posHighlight-t.columnOffset > 3*width/4 { t.columnOffset = posHighlight - width/2 } // If the highlight is off-screen on the left, move it on-screen. if posHighlight-t.columnOffset < 0 { t.columnOffset = posHighlight - width/4 } } } } t.scrollToHighlights = false // Make sure our index has enough lines. t.parseAhead(width, func(lineNumber int, line *textViewLine) bool { return lineNumber >= t.lineOffset+height }) // Adjust line offset. if t.trackEnd { t.parseAhead(width, func(lineNumber int, line *textViewLine) bool { return false }) t.lineOffset = len(t.lineIndex) - height } if t.lineOffset > len(t.lineIndex)-height { t.lineOffset = len(t.lineIndex) - height } if t.lineOffset < 0 { t.lineOffset = 0 } // Adjust column offset. if t.align == AlignLeft || t.align == AlignRight { if t.columnOffset+width > t.longestLine { t.columnOffset = t.longestLine - width } if t.columnOffset < 0 { t.columnOffset = 0 } } else { // AlignCenter. half := (t.longestLine - width) / 2 if half > 0 { if t.columnOffset > half { t.columnOffset = half } if t.columnOffset < -half { t.columnOffset = -half } } else { t.columnOffset = 0 } } // Draw visible lines. for line := t.lineOffset; line < len(t.lineIndex); line++ { // Are we done? if line-t.lineOffset >= height { break } // Determine starting point of the text and the screen. var skipWidth, xPos int info := t.lineIndex[line] switch t.align { case AlignLeft: skipWidth = t.columnOffset case AlignCenter: skipWidth = t.columnOffset + (info.width-width)/2 if skipWidth < 0 { skipWidth = 0 xPos = (width-info.width)/2 - t.columnOffset } case AlignRight: maxWidth := width if t.longestLine > width { maxWidth = t.longestLine } skipWidth = t.columnOffset - (maxWidth - info.width) if skipWidth < 0 { skipWidth = 0 xPos = maxWidth - info.width - t.columnOffset } } // Draw the line text. str := t.text.String()[info.offset:] st := *info.state state := &st var processed int for len(str) > 0 && xPos < width && processed < info.length { var ch string ch, str, state = step(str, state, options) w := state.Width() if ch == "\t" { if t.align == AlignLeft { w = TabSize - xPos%TabSize } else { w = TabSize } } processed += state.GrossLength() // Don't draw anything while we skip characters. if skipWidth > 0 { skipWidth -= w continue } // Draw this character. if w > 0 { style := state.Style() // Do we highlight this character? var highlighted bool if state.region != "" { if _, ok := t.highlights[state.region]; ok { highlighted = true } } if highlighted { fg, bg, _ := style.Decompose() if bg == t.backgroundColor { r, g, b := fg.RGB() c := colorful.Color{R: float64(r) / 255, G: float64(g) / 255, B: float64(b) / 255} _, _, li := c.Hcl() if li < .5 { bg = tcell.ColorWhite } else { bg = tcell.ColorBlack } } style = style.Background(fg).Foreground(bg) } // Paint on screen. for offset := w - 1; offset >= 0; offset-- { runes := []rune(ch) if offset == 0 { screen.SetContent(x+xPos+offset, y+line-t.lineOffset, runes[0], runes[1:], style) } else { screen.SetContent(x+xPos+offset, y+line-t.lineOffset, ' ', nil, style) } } } xPos += w } } // If this view is not scrollable, we'll purge the buffer of lines that have // scrolled out of view. var purgeStart int if !t.scrollable && t.lineOffset > 0 { purgeStart = t.lineOffset } // If we reached the maximum number of lines, we'll purge the buffer of the // oldest lines. if t.maxLines > 0 && len(t.lineIndex) > t.maxLines { purgeStart = len(t.lineIndex) - t.maxLines } // Purge. if purgeStart > 0 && purgeStart < len(t.lineIndex) { newText := t.text.String()[t.lineIndex[purgeStart].offset:] t.text.Reset() t.text.WriteString(newText) t.resetIndex() t.lineOffset = 0 } } // InputHandler returns the handler for this primitive. func (t *TextView) InputHandler() func(event *tcell.EventKey, setFocus func(p Primitive)) { return t.WrapInputHandler(func(event *tcell.EventKey, setFocus func(p Primitive)) { key := event.Key() if key == tcell.KeyEscape || key == tcell.KeyEnter || key == tcell.KeyTab || key == tcell.KeyBacktab { if t.done != nil { t.done(key) } if t.finished != nil { t.finished(key) } return } if !t.scrollable { return } switch key { case tcell.KeyRune: switch event.Rune() { case 'g': // Home. t.trackEnd = false t.lineOffset = 0 t.columnOffset = 0 case 'G': // End. t.trackEnd = true t.columnOffset = 0 case 'j': // Down. t.lineOffset++ case 'k': // Up. t.trackEnd = false t.lineOffset-- case 'h': // Left. t.columnOffset-- case 'l': // Right. t.columnOffset++ } case tcell.KeyHome: t.trackEnd = false t.lineOffset = 0 t.columnOffset = 0 case tcell.KeyEnd: t.trackEnd = true t.columnOffset = 0 case tcell.KeyUp: t.trackEnd = false t.lineOffset-- case tcell.KeyDown: t.lineOffset++ case tcell.KeyLeft: t.columnOffset-- case tcell.KeyRight: t.columnOffset++ case tcell.KeyPgDn, tcell.KeyCtrlF: t.lineOffset += t.pageSize case tcell.KeyPgUp, tcell.KeyCtrlB: t.trackEnd = false t.lineOffset -= t.pageSize } }) } // MouseHandler returns the mouse handler for this primitive. func (t *TextView) MouseHandler() func(action MouseAction, event *tcell.EventMouse, setFocus func(p Primitive)) (consumed bool, capture Primitive) { return t.WrapMouseHandler(func(action MouseAction, event *tcell.EventMouse, setFocus func(p Primitive)) (consumed bool, capture Primitive) { x, y := event.Position() if !t.InRect(x, y) { return false, nil } rectX, rectY, width, height := t.GetInnerRect() switch action { case MouseLeftDown: setFocus(t) consumed = true case MouseLeftClick: if t.regionTags && t.InInnerRect(x, y) { // Find a region to highlight. column := x - rectX row := y - rectY + t.lineOffset var highlightedID string if row < len(t.lineIndex) { line := t.lineIndex[row] for _, region := range line.regions { if !(row < region.StartRow || row > region.EndRow || (row == region.StartRow && column < region.StartColumn) || (row == region.EndRow && column >= region.EndColumn)) { highlightedID = region.ID break } } } if highlightedID != "" { t.Highlight(highlightedID) } else if !t.toggleHighlights { t.Highlight() } } consumed = true case MouseScrollUp: if !t.scrollable { break } t.trackEnd = false t.lineOffset-- consumed = true case MouseScrollDown: if !t.scrollable { break } t.lineOffset++ if len(t.lineIndex)-t.lineOffset < height { // If we scroll to the end, turn on tracking. t.parseAhead(width, func(lineNumber int, line *textViewLine) bool { return len(t.lineIndex)-t.lineOffset < height }) if len(t.lineIndex)-t.lineOffset < height { t.trackEnd = true } } consumed = true } return }) } ================================================ FILE: treeview.go ================================================ package tview import ( "github.com/gdamore/tcell/v2" ) // Tree navigation events. const ( treeNone int = iota treeHome treeEnd treeMove treeParent treeChild treeScroll // Move without changing the selection, even when off screen. ) // TreeNode represents one node in a tree view. type TreeNode struct { // The reference object. reference interface{} // This node's child nodes. children []*TreeNode // The item's text. text string // The text style. textStyle tcell.Style // The style of selected text. selectedTextStyle tcell.Style // Whether or not this node can be selected. selectable bool // Whether or not this node's children should be displayed. expanded bool // The additional horizontal indent of this node's text. indent int // An optional function which is called when the user selects this node. selected func() // The hierarchy level (0 for the root, 1 for its children, and so on). This // is only up to date immediately after a call to process() (e.g. via // Draw()). level int // Temporary member variables. parent *TreeNode // The parent node (nil for the root). graphicsX int // The x-coordinate of the left-most graphics rune. textX int // The x-coordinate of the first rune of the text. } // NewTreeNode returns a new tree node. func NewTreeNode(text string) *TreeNode { return &TreeNode{ text: text, textStyle: tcell.StyleDefault.Foreground(Styles.PrimaryTextColor).Background(Styles.PrimitiveBackgroundColor), selectedTextStyle: tcell.StyleDefault.Foreground(Styles.PrimitiveBackgroundColor).Background(Styles.PrimaryTextColor), indent: 2, expanded: true, selectable: true, } } // Walk traverses this node's subtree in depth-first, pre-order (NLR) order and // calls the provided callback function on each traversed node (which includes // this node) with the traversed node and its parent node (nil for this node). // The callback returns whether traversal should continue with the traversed // node's child nodes (true) or not recurse any deeper (false). func (n *TreeNode) Walk(callback func(node, parent *TreeNode) bool) *TreeNode { n.parent = nil nodes := []*TreeNode{n} for len(nodes) > 0 { // Pop the top node and process it. node := nodes[len(nodes)-1] nodes = nodes[:len(nodes)-1] if !callback(node, node.parent) { // Don't add any children. continue } // Add children in reverse order. for index := len(node.children) - 1; index >= 0; index-- { node.children[index].parent = node nodes = append(nodes, node.children[index]) } } return n } // SetReference allows you to store a reference of any type in this node. This // will allow you to establish a mapping between the TreeView hierarchy and your // internal tree structure. func (n *TreeNode) SetReference(reference interface{}) *TreeNode { n.reference = reference return n } // GetReference returns this node's reference object. func (n *TreeNode) GetReference() interface{} { return n.reference } // SetChildren sets this node's child nodes. func (n *TreeNode) SetChildren(childNodes []*TreeNode) *TreeNode { n.children = childNodes return n } // GetText returns this node's text. func (n *TreeNode) GetText() string { return n.text } // GetChildren returns this node's children. func (n *TreeNode) GetChildren() []*TreeNode { return n.children } // ClearChildren removes all child nodes from this node. func (n *TreeNode) ClearChildren() *TreeNode { n.children = nil return n } // AddChild adds a new child node to this node. func (n *TreeNode) AddChild(node *TreeNode) *TreeNode { n.children = append(n.children, node) return n } // RemoveChild removes a child node from this node. If the child node cannot be // found, nothing happens. func (n *TreeNode) RemoveChild(node *TreeNode) *TreeNode { for index, child := range n.children { if child == node { n.children = append(n.children[:index], n.children[index+1:]...) break } } return n } // SetSelectable sets a flag indicating whether this node can be selected by // the user. func (n *TreeNode) SetSelectable(selectable bool) *TreeNode { n.selectable = selectable return n } // SetSelectedFunc sets a function which is called when the user selects this // node by hitting Enter when it is selected. func (n *TreeNode) SetSelectedFunc(handler func()) *TreeNode { n.selected = handler return n } // SetExpanded sets whether or not this node's child nodes should be displayed. func (n *TreeNode) SetExpanded(expanded bool) *TreeNode { n.expanded = expanded return n } // Expand makes the child nodes of this node appear. func (n *TreeNode) Expand() *TreeNode { n.expanded = true return n } // Collapse makes the child nodes of this node disappear. func (n *TreeNode) Collapse() *TreeNode { n.expanded = false return n } // ExpandAll expands this node and all descendent nodes. func (n *TreeNode) ExpandAll() *TreeNode { n.Walk(func(node, parent *TreeNode) bool { node.expanded = true return true }) return n } // CollapseAll collapses this node and all descendent nodes. func (n *TreeNode) CollapseAll() *TreeNode { n.Walk(func(node, parent *TreeNode) bool { node.expanded = false return true }) return n } // IsExpanded returns whether the child nodes of this node are visible. func (n *TreeNode) IsExpanded() bool { return n.expanded } // SetText sets the node's text which is displayed. func (n *TreeNode) SetText(text string) *TreeNode { n.text = text return n } // GetColor returns the node's text color. func (n *TreeNode) GetColor() tcell.Color { color, _, _ := n.textStyle.Decompose() return color } // SetColor sets the node's text color. For compatibility reasons, this also // sets the background color of the selected text style. For more control over // styles, use [TreeNode.SetTextStyle] and [TreeNode.SetSelectedTextStyle]. func (n *TreeNode) SetColor(color tcell.Color) *TreeNode { n.textStyle = n.textStyle.Foreground(color) n.selectedTextStyle = n.selectedTextStyle.Background(color) return n } // SetTextStyle sets the text style for this node. func (n *TreeNode) SetTextStyle(style tcell.Style) *TreeNode { n.textStyle = style return n } // GetTextStyle returns the text style for this node. func (n *TreeNode) GetTextStyle() tcell.Style { return n.textStyle } // SetSelectedTextStyle sets the text style for this node when it is selected. func (n *TreeNode) SetSelectedTextStyle(style tcell.Style) *TreeNode { n.selectedTextStyle = style return n } // GetSelectedTextStyle returns the text style for this node when it is // selected. func (n *TreeNode) GetSelectedTextStyle() tcell.Style { return n.selectedTextStyle } // SetIndent sets an additional indentation for this node's text. A value of 0 // keeps the text as far left as possible with a minimum of line graphics. Any // value greater than that moves the text to the right. func (n *TreeNode) SetIndent(indent int) *TreeNode { n.indent = indent return n } // GetLevel returns the node's level within the hierarchy, where 0 corresponds // to the root node, 1 corresponds to its children, and so on. This is only // guaranteed to be up to date immediately after the tree that contains this // node is drawn. func (n *TreeNode) GetLevel() int { return n.level } // TreeView displays tree structures. A tree consists of nodes (TreeNode // objects) where each node has zero or more child nodes and exactly one parent // node (except for the root node which has no parent node). // // The SetRoot() function is used to specify the root of the tree. Other nodes // are added locally to the root node or any of its descendents. See the // TreeNode documentation for details on node attributes. (You can use // SetReference() to store a reference to nodes of your own tree structure.) // // Nodes can be selected by calling SetCurrentNode(). The user can navigate the // selection or the tree by using the following keys: // // - j, down arrow, right arrow: Move (the selection) down by one node. // - k, up arrow, left arrow: Move (the selection) up by one node. // - g, home: Move (the selection) to the top. // - G, end: Move (the selection) to the bottom. // - J: Move (the selection) up one level (if that node is selectable). // - K: Move (the selection) to the last node one level down (if any). // - Ctrl-F, page down: Move (the selection) down by one page. // - Ctrl-B, page up: Move (the selection) up by one page. // // Selected nodes can trigger the "selected" callback when the user hits Enter. // // The root node corresponds to level 0, its children correspond to level 1, // their children to level 2, and so on. Per default, the first level that is // displayed is 0, i.e. the root node. You can call SetTopLevel() to hide // levels. // // If graphics are turned on (see SetGraphics()), lines indicate the tree's // hierarchy. Alternative (or additionally), you can set different prefixes // using SetPrefixes() for different levels, for example to display hierarchical // bullet point lists. // // See https://github.com/rivo/tview/wiki/TreeView for an example. type TreeView struct { *Box // The root node. root *TreeNode // The currently selected node or nil if no node is selected. currentNode *TreeNode // The last note that was selected or nil of there is no such node. lastNode *TreeNode // The movement to be performed during the call to Draw(), one of the // constants defined above. movement int // The number of nodes to move down or up, when movement is treeMove, // excluding non-selectable nodes for selection movement, including them for // scrolling. step int // The top hierarchical level shown. (0 corresponds to the root level.) topLevel int // Strings drawn before the nodes, based on their level. prefixes []string // Vertical scroll offset. offsetY int // If set to true, all node texts will be aligned horizontally. align bool // If set to true, the tree structure is drawn using lines. graphics bool // The color of the lines. graphicsColor tcell.Color // An optional function which is called when the user has navigated to a new // tree node. changed func(node *TreeNode) // An optional function which is called when a tree item was selected. selected func(node *TreeNode) // An optional function which is called when the user moves away from this // primitive. done func(key tcell.Key) // The visible nodes, top-down, as set by process(). nodes []*TreeNode // Temporarily set to true while we know that the tree has not changed and // therefore does not need to be reprocessed. stableNodes bool } // NewTreeView returns a new [TreeView]. func NewTreeView() *TreeView { t := &TreeView{ Box: NewBox(), graphics: true, graphicsColor: Styles.GraphicsColor, } t.Box.Primitive = t return t } // SetRoot sets the root node of the tree. func (t *TreeView) SetRoot(root *TreeNode) *TreeView { t.root = root return t } // GetRoot returns the root node of the tree. If no such node was previously // set, nil is returned. func (t *TreeView) GetRoot() *TreeNode { return t.root } // SetCurrentNode sets the currently selected node. Provide nil to clear all // selections. Selected nodes must be visible and selectable, or else the // selection will be changed to the top-most selectable and visible node. // // This function does NOT trigger the "changed" callback because the actual node // that will be selected is not known until the tree is drawn. Triggering the // "changed" callback is thus deferred until the next call to [TreeView.Draw]. func (t *TreeView) SetCurrentNode(node *TreeNode) *TreeView { t.currentNode = node return t } // GetCurrentNode returns the currently selected node or nil of no node is // currently selected. func (t *TreeView) GetCurrentNode() *TreeNode { return t.currentNode } // GetPath returns all nodes located on the path from the root to the given // node, including the root and the node itself. If there is no root node, nil // is returned. If there are multiple paths to the node, a random one is chosen // and returned. func (t *TreeView) GetPath(node *TreeNode) []*TreeNode { if t.root == nil { return nil } var f func(current *TreeNode, path []*TreeNode) []*TreeNode f = func(current *TreeNode, path []*TreeNode) []*TreeNode { if current == node { return path } for _, child := range current.children { newPath := make([]*TreeNode, len(path), len(path)+1) copy(newPath, path) if p := f(child, append(newPath, child)); p != nil { return p } } return nil } return f(t.root, []*TreeNode{t.root}) } // SetTopLevel sets the first tree level that is visible with 0 referring to the // root, 1 to the root's child nodes, and so on. Nodes above the top level are // not displayed. func (t *TreeView) SetTopLevel(topLevel int) *TreeView { t.topLevel = topLevel return t } // SetPrefixes defines the strings drawn before the nodes' texts. This is a // slice of strings where each element corresponds to a node's hierarchy level, // i.e. 0 for the root, 1 for the root's children, and so on (levels will // cycle). // // For example, to display a hierarchical list with bullet points: // // treeView.SetGraphics(false). // SetPrefixes([]string{"* ", "- ", "x "}) // // Deeper levels will cycle through the prefixes. func (t *TreeView) SetPrefixes(prefixes []string) *TreeView { t.prefixes = prefixes return t } // SetAlign controls the horizontal alignment of the node texts. If set to true, // all texts except that of top-level nodes will be placed in the same column. // If set to false, they will indent with the hierarchy. func (t *TreeView) SetAlign(align bool) *TreeView { t.align = align return t } // SetGraphics sets a flag which determines whether or not line graphics are // drawn to illustrate the tree's hierarchy. func (t *TreeView) SetGraphics(showGraphics bool) *TreeView { t.graphics = showGraphics return t } // SetGraphicsColor sets the colors of the lines used to draw the tree structure. func (t *TreeView) SetGraphicsColor(color tcell.Color) *TreeView { t.graphicsColor = color return t } // SetChangedFunc sets the function which is called when the currently selected // node changes, for example when the user navigates to a new tree node. func (t *TreeView) SetChangedFunc(handler func(node *TreeNode)) *TreeView { t.changed = handler return t } // SetSelectedFunc sets the function which is called when the user selects a // node by pressing Enter on the current selection. func (t *TreeView) SetSelectedFunc(handler func(node *TreeNode)) *TreeView { t.selected = handler return t } // GetSelectedFunc returns the function set with [TreeView.SetSelectedFunc] // or nil if no such function has been set. func (t *TreeView) GetSelectedFunc() func(node *TreeNode) { return t.selected } // SetDoneFunc sets a handler which is called whenever the user presses the // Escape, Tab, or Backtab key. func (t *TreeView) SetDoneFunc(handler func(key tcell.Key)) *TreeView { t.done = handler return t } // GetScrollOffset returns the number of node rows that were skipped at the top // of the tree view. Note that when the user navigates the tree view, this value // is only updated after the tree view has been redrawn. func (t *TreeView) GetScrollOffset() int { return t.offsetY } // GetRowCount returns the number of "visible" nodes. This includes nodes which // fall outside the tree view's box but notably does not include the children // of collapsed nodes. Note that this value is only up to date after the tree // view has been drawn. func (t *TreeView) GetRowCount() int { return len(t.nodes) } // Move moves the selection (if a node is currently selected) or scrolls the // tree view (if there is no selection), by the given offset (positive values to // move/scroll down, negative values to move/scroll up). For selection changes, // the offset refers to the number selectable, visible nodes. For scrolling, the // offset refers to the number of visible nodes. // // If the offset is 0, nothing happens. func (t *TreeView) Move(offset int) *TreeView { if offset == 0 { return t } t.movement = treeMove t.step = offset t.process(false) return t } // process builds the visible tree, populates the "nodes" slice, and processes // pending movement actions. Set "drawingAfter" to true if you know that // [TreeView.Draw] will be called immediately after this function (to avoid // having [TreeView.Draw] call it again). func (t *TreeView) process(drawingAfter bool) { t.stableNodes = drawingAfter _, _, _, height := t.GetInnerRect() // Determine visible nodes and their placement. t.nodes = nil if t.root == nil { return } parentSelectedIndex, selectedIndex, topLevelGraphicsX := -1, -1, -1 var graphicsOffset, maxTextX int if t.graphics { graphicsOffset = 1 } t.root.Walk(func(node, parent *TreeNode) bool { // Set node attributes. node.parent = parent if parent == nil { node.level = 0 node.graphicsX = 0 node.textX = 0 } else { node.level = parent.level + 1 node.graphicsX = parent.textX node.textX = node.graphicsX + graphicsOffset + node.indent } if !t.graphics && t.align { // Without graphics, we align nodes on the first column. node.textX = 0 } if node.level == t.topLevel { // No graphics for top level nodes. node.graphicsX = 0 node.textX = 0 } // Add the node to the list. if node.level >= t.topLevel { // This node will be visible. if node.textX > maxTextX { maxTextX = node.textX } if node == t.currentNode && node.selectable { selectedIndex = len(t.nodes) // Also find parent node. for index := len(t.nodes) - 1; index >= 0; index-- { if t.nodes[index] == parent && t.nodes[index].selectable { parentSelectedIndex = index break } } } // Maybe we want to skip this level. if t.topLevel == node.level && (topLevelGraphicsX < 0 || node.graphicsX < topLevelGraphicsX) { topLevelGraphicsX = node.graphicsX } t.nodes = append(t.nodes, node) } // Recurse if desired. return node.expanded }) // Post-process positions. for _, node := range t.nodes { // If text must align, we correct the positions. if t.align && node.level > t.topLevel { node.textX = maxTextX } // If we skipped levels, shift to the left. if topLevelGraphicsX > 0 { node.graphicsX -= topLevelGraphicsX node.textX -= topLevelGraphicsX } } // Process selection. (Also trigger events if necessary.) if selectedIndex >= 0 { // Move the selection. switch t.movement { case treeMove: for t.step < 0 { // Going up. index := selectedIndex for index > 0 { index-- if t.nodes[index].selectable { selectedIndex = index break } } t.step++ } for t.step > 0 { // Going down. index := selectedIndex for index < len(t.nodes)-1 { index++ if t.nodes[index].selectable { selectedIndex = index break } } t.step-- } case treeParent: if parentSelectedIndex >= 0 { selectedIndex = parentSelectedIndex } case treeChild: index := selectedIndex for index < len(t.nodes)-1 { index++ if t.nodes[index].selectable && t.nodes[index].parent == t.nodes[selectedIndex] { selectedIndex = index } } } t.currentNode = t.nodes[selectedIndex] // Move selection into viewport. if t.movement != treeScroll { if selectedIndex-t.offsetY >= height { t.offsetY = selectedIndex - height + 1 } if selectedIndex < t.offsetY { t.offsetY = selectedIndex } if t.movement != treeHome && t.movement != treeEnd { // treeScroll, treeHome, and treeEnd are handled by Draw(). t.movement = treeNone t.step = 0 } } } else { // If selection is not visible or selectable, select the first candidate. if t.currentNode != nil { for index, node := range t.nodes { if node.selectable { selectedIndex = index t.currentNode = node break } } } if selectedIndex < 0 { t.currentNode = nil } } // Trigger "changed" callback. if t.changed != nil && t.currentNode != nil && t.currentNode != t.lastNode { t.changed(t.currentNode) } t.lastNode = t.currentNode } // Draw draws this primitive onto the screen. func (t *TreeView) Draw(screen tcell.Screen) { t.Box.DrawForSubclass(screen, t) if t.root == nil { return } _, totalHeight := screen.Size() if !t.stableNodes { t.process(false) } else { t.stableNodes = false } // Scroll the tree, t.movement is treeNone after process() when there is a // selection, except for treeScroll, treeHome, and treeEnd. x, y, width, height := t.GetInnerRect() switch t.movement { case treeMove, treeScroll: t.offsetY += t.step case treeHome: t.offsetY = 0 case treeEnd: t.offsetY = len(t.nodes) } t.movement = treeNone // Fix invalid offsets. if t.offsetY >= len(t.nodes)-height { t.offsetY = len(t.nodes) - height } if t.offsetY < 0 { t.offsetY = 0 } // Draw the tree. posY := y lineStyle := tcell.StyleDefault.Background(t.backgroundColor).Foreground(t.graphicsColor) for index, node := range t.nodes { // Skip invisible parts. if posY >= y+height+1 || posY >= totalHeight { break } if index < t.offsetY { continue } // Draw the graphics. if t.graphics { // Draw ancestor branches. ancestor := node.parent for ancestor != nil && ancestor.parent != nil && ancestor.parent.level >= t.topLevel { if ancestor.graphicsX >= width { continue } // Draw a branch if this ancestor is not a last child. if ancestor.parent.children[len(ancestor.parent.children)-1] != ancestor { if posY-1 >= y && ancestor.textX > ancestor.graphicsX { PrintJoinedSemigraphics(screen, x+ancestor.graphicsX, posY-1, Borders.Vertical, lineStyle) } if posY < y+height { screen.SetContent(x+ancestor.graphicsX, posY, Borders.Vertical, nil, lineStyle) } } ancestor = ancestor.parent } if node.textX > node.graphicsX && node.graphicsX < width { // Connect to the node above. if posY-1 >= y && t.nodes[index-1].graphicsX <= node.graphicsX && t.nodes[index-1].textX > node.graphicsX { PrintJoinedSemigraphics(screen, x+node.graphicsX, posY-1, Borders.TopLeft, lineStyle) } // Join this node. if posY < y+height { screen.SetContent(x+node.graphicsX, posY, Borders.BottomLeft, nil, lineStyle) for pos := node.graphicsX + 1; pos < node.textX && pos < width; pos++ { screen.SetContent(x+pos, posY, Borders.Horizontal, nil, lineStyle) } } } } // Draw the prefix and the text. if node.textX < width && posY < y+height { // Prefix. var prefixWidth int if len(t.prefixes) > 0 { _, _, prefixWidth = printWithStyle(screen, t.prefixes[(node.level-t.topLevel)%len(t.prefixes)], x+node.textX, posY, 0, width-node.textX, AlignLeft, node.textStyle, true) } // Text. if node.textX+prefixWidth < width { style := node.textStyle if node == t.currentNode { style = node.selectedTextStyle } printWithStyle(screen, node.text, x+node.textX+prefixWidth, posY, 0, width-node.textX-prefixWidth, AlignLeft, style, false) } } // Advance. posY++ } } // InputHandler returns the handler for this primitive. func (t *TreeView) InputHandler() func(event *tcell.EventKey, setFocus func(p Primitive)) { return t.WrapInputHandler(func(event *tcell.EventKey, setFocus func(p Primitive)) { selectNode := func() { node := t.currentNode if node != nil { if t.selected != nil { t.selected(node) } if node.selected != nil { node.selected() } } } // Because the tree is flattened into a list only at drawing time, we also // postpone the (selection) movement to drawing time. switch key := event.Key(); key { case tcell.KeyTab, tcell.KeyBacktab, tcell.KeyEscape: if t.done != nil { t.done(key) } case tcell.KeyDown, tcell.KeyRight: t.movement = treeMove t.step = 1 case tcell.KeyUp, tcell.KeyLeft: t.movement = treeMove t.step = -1 case tcell.KeyHome: t.movement = treeHome case tcell.KeyEnd: t.movement = treeEnd case tcell.KeyPgDn, tcell.KeyCtrlF: _, _, _, height := t.GetInnerRect() t.movement = treeMove t.step = height case tcell.KeyPgUp, tcell.KeyCtrlB: _, _, _, height := t.GetInnerRect() t.movement = treeMove t.step = -height case tcell.KeyRune: switch event.Rune() { case 'g': t.movement = treeHome case 'G': t.movement = treeEnd case 'j': t.movement = treeMove t.step = 1 case 'J': t.movement = treeChild case 'k': t.movement = treeMove t.step = -1 case 'K': t.movement = treeParent case ' ': selectNode() } case tcell.KeyEnter: selectNode() } t.process(true) }) } // MouseHandler returns the mouse handler for this primitive. func (t *TreeView) MouseHandler() func(action MouseAction, event *tcell.EventMouse, setFocus func(p Primitive)) (consumed bool, capture Primitive) { return t.WrapMouseHandler(func(action MouseAction, event *tcell.EventMouse, setFocus func(p Primitive)) (consumed bool, capture Primitive) { x, y := event.Position() if !t.InRect(x, y) { return false, nil } switch action { case MouseLeftDown: setFocus(t) consumed = true case MouseLeftClick: _, rectY, _, _ := t.GetInnerRect() y += t.offsetY - rectY if y >= 0 && y < len(t.nodes) { node := t.nodes[y] if node.selectable { previousNode := t.currentNode t.currentNode = node if previousNode != node && t.changed != nil { t.changed(node) } if t.selected != nil { t.selected(node) } if node.selected != nil { node.selected() } } } consumed = true case MouseScrollUp: t.movement = treeScroll t.step = -1 consumed = true case MouseScrollDown: t.movement = treeScroll t.step = 1 consumed = true } return }) } ================================================ FILE: util.go ================================================ package tview import ( "math" "os" "regexp" "github.com/gdamore/tcell/v2" ) // Text alignment within a box. Also used to align images. const ( AlignLeft = iota AlignCenter AlignRight AlignTop = 0 AlignBottom = 2 ) var ( // Regular expression used to escape style/region tags. escapePattern = regexp.MustCompile(`(\[[a-zA-Z0-9_,;: \-\."#]+\[*)\]`) // Regular expression used to unescape escaped style/region tags. unescapePattern = regexp.MustCompile(`(\[[a-zA-Z0-9_,;: \-\."#]+\[*)\[\]`) // The number of colors available in the terminal. availableColors = 256 ) // Package initialization. func init() { // Determine the number of colors available in the terminal. info, err := tcell.LookupTerminfo(os.Getenv("TERM")) if err == nil { availableColors = info.Colors } } // Print prints text onto the screen into the given box at (x,y,maxWidth,1), // not exceeding that box. "align" is one of AlignLeft, AlignCenter, or // AlignRight. The screen's background color will not be changed. // // You can change the colors and text styles mid-text by inserting a style tag. // See the package description for details. // // Returns the number of actual bytes of the text printed (including style tags) // and the actual width used for the printed runes. func Print(screen tcell.Screen, text string, x, y, maxWidth, align int, color tcell.Color) (int, int) { start, end, width := printWithStyle(screen, text, x, y, 0, maxWidth, align, tcell.StyleDefault.Foreground(color), true) return end - start, width } // printWithStyle works like [Print] but it takes a style instead of just a // foreground color. The skipWidth parameter specifies the number of cells // skipped at the beginning of the text. It returns the start index, end index // (exclusively), and screen width of the text actually printed. If // maintainBackground is "true", the existing screen background is not changed // (i.e. the style's background color is ignored). func printWithStyle(screen tcell.Screen, text string, x, y, skipWidth, maxWidth, align int, style tcell.Style, maintainBackground bool) (start, end, printedWidth int) { totalWidth, totalHeight := screen.Size() if maxWidth <= 0 || len(text) == 0 || y < 0 || y >= totalHeight { return 0, 0, 0 } // If we don't overwrite the background, we use the default color. if maintainBackground { style = style.Background(tcell.ColorDefault) } // Skip beginning and measure width. var textWidth int state := &stepState{ unisegState: -1, style: style, } newState := *state str := text for len(str) > 0 { _, str, state = step(str, state, stepOptionsStyle) if skipWidth > 0 { skipWidth -= state.Width() text = str newState = *state start += state.GrossLength() } else { textWidth += state.Width() } } state = &newState // Reduce all alignments to AlignLeft. if align == AlignRight { // Chop off characters on the left until it fits. for len(text) > 0 && textWidth > maxWidth { _, text, state = step(text, state, stepOptionsStyle) textWidth -= state.Width() start += state.GrossLength() } x, maxWidth = x+maxWidth-textWidth, textWidth } else if align == AlignCenter { // Chop off characters on the left until it fits. subtracted := (textWidth - maxWidth) / 2 for len(text) > 0 && subtracted > 0 { _, text, state = step(text, state, stepOptionsStyle) subtracted -= state.Width() textWidth -= state.Width() start += state.GrossLength() } if textWidth < maxWidth { x, maxWidth = x+maxWidth/2-textWidth/2, textWidth } } // Draw left-aligned text. end = start rightBorder := x + maxWidth for len(text) > 0 && x < rightBorder && x < totalWidth { var c string c, text, state = step(text, state, stepOptionsStyle) if c == "" { break // We don't care about the style at the end. } width := state.Width() if width > 0 { finalStyle := state.Style() if maintainBackground { _, backgroundColor, _ := finalStyle.Decompose() if backgroundColor == tcell.ColorDefault { _, _, existingStyle, _ := screen.GetContent(x, y) _, background, _ := existingStyle.Decompose() finalStyle = finalStyle.Background(background) } } for offset := width - 1; offset >= 0; offset-- { // To avoid undesired effects, we populate all cells. runes := []rune(c) if offset == 0 { screen.SetContent(x+offset, y, runes[0], runes[1:], finalStyle) } else { screen.SetContent(x+offset, y, ' ', nil, finalStyle) } } } x += width end += state.GrossLength() printedWidth += width } return } // PrintSimple prints white text to the screen at the given position. func PrintSimple(screen tcell.Screen, text string, x, y int) { Print(screen, text, x, y, math.MaxInt32, AlignLeft, Styles.PrimaryTextColor) }