gdamore/tcell
GitHub: gdamore/tcell
Stars: 5182 | Forks: 358
# Tcell
_Tcell_ is a _Go_ package that provides a cell based view for text terminals, like _XTerm_.
It was inspired by _termbox_, but includes many additional improvements.
[](https://stand-with-ukraine.pp.ua)
[](https://pkg.go.dev/github.com/gdamore/tcell/v3)
[](https://github.com/gdamore/tcell/actions/workflows/linux.yml)
[](https://github.com/gdamore/tcell/actions/workflows/macos.yml)
[](https://github.com/gdamore/tcell/actions/workflows/windows.yml)
[](https://github.com/gdamore/tcell/actions/workflows/webasm.yml)
[](https://codecov.io/gh/gdamore/tcell)
[](https://goreportcard.com/report/github.com/gdamore/tcell/v3)
[](https://discord.gg/urTTxDN)
[](https://github.com/gdamore/tcell/releases)
## Tutorial
A brief, and still somewhat rough, [tutorial](TUTORIAL.md) is available.
## Examples
A number of example are posted up on our [Gallery](https://github.com/gdamore/tcell/wikis/Gallery/).
That's a wiki, and please do submit updates if you have something you want to showcase.
There are also demonstration programs in the `./demos` directory, as well as some in `./_demos`.
## More Portable
_Tcell_ is portable to a wide variety of systems, and is pure Go, without any need for CGO.
_Tcell_ works with mainstream systems officially supported by golang.
## Working With Unicode
Internally _Tcell_ uses UTF-8, just like Go.
However, _Tcell_ understands how to
convert to and from other character sets, using the capabilities of
the `golang.org/x/text/encoding` packages.
Your application must supply
them, as the full set of the most common ones bloats the program by about 2 MB.
If you're lazy, and want them all anyway, see the `encoding` sub-directory.
## Wide & Combining Characters
The `Put()` API takes a string, which should be legal UTF-8, and displays
the first grapheme cluster (which may composed of multiple runes).
It returns the actual width displayed, which can be used to advance the column positiion
for the next display grapheme. Alternatively, `PutStr()` or `PutStrStyled()`
can be used to display a single line of text (which will be clipped at the
edge of the screen).
If a second character is displayed immediately in the cell adjacent to a
wide character (offset by one instead of by two), then the results are undefined.
## Colors
_Tcell_ assumes the ANSI/XTerm color palette for up to 256 colors, although terminals
such as legacy ANSI terminals may only support 8 colors.
## 24-bit Color
_Tcell_ _supports 24-bit color!_ (That is, if your terminal can support it.)
There are a few ways you can enable (or disable) 24-bit color.
- You can force this one by setting the `COLORTERM` environment variable to
`truecolor`. This environment variable is frequently set by terminal emulators
that support 24-bit color.
- On Windows, 24-bit color support is assumed. (All modern Windows terminal emulators support it.)
- If you set your `TERM` environment variable to a value with the suffix `-truecolor`
or `-direct`, then 24-bit color compatible with XTerm and ECMA-48 will be assumed.
- You can disable 24-bit color by setting `TCELL_TRUECOLOR=disable` in your
environment.
When using 24-bit color, programs will display the colors that the programmer
intended, overriding any "`themes`" the user may have set in their terminal
emulator. (For some cases, accurate color fidelity is more important
than respecting themes. For other cases, such as typical text apps that
only use a few colors, its more desirable to respect the themes that
the user has established.)
## Terminal Overrides
_Tcell_ normally negotiates terminal capabilities automatically, but some
terminal emulators answer those queries incorrectly. These environment
variables provide user escape hatches when the automatic path is not reliable:
- `TCELL_KEYBOARD_PROTOCOL=auto|legacy|kitty|win32|xterm` forces the keyboard
reporting protocol.
- `TCELL_NEGOTIATE=auto|disable` disables startup capability negotiation when
terminal responses themselves are problematic.
- `TCELL_MOUSE=auto|disable` prevents applications from enabling terminal mouse
reporting.
Applications can also choose a keyboard protocol with `OptKeyboardProtocol` or
disable startup negotiation with `OptNegotiation`. Environment variables take
precedence so users can recover from bad terminal behavior without modifying an
application.
## Performance
Reasonable attempts have been made to minimize sending data to terminals,
avoiding repeated sequences or drawing the same cell on refresh updates.
## Bracketed Paste
## Breaking Changes in v3
There are a number of changes in _Tcell_ version 3, which break compatibility with
version 2 and version 1.
Your application will almost certainly need some minor updates to work with version 3.
Please see the [CHANGESv3](CHANGESv3.md) document for a list.
## Platforms
### POSIX (Linux, FreeBSD, macOS, Solaris, etc.)
Everything works using pure Go on mainstream platforms.
Esoteric platforms (e.g. zOS or AIX) are supported on a best-effort
only basis. Pull requests to fix any issues found are welcome!
### Windows
Modern Windows is supported. Please see the [README-windows](README-windows.md)
document for much more detailed information.
### WASM
WASM is supported, but needs additional setup detailed in [README-wasm](README-wasm.md).
### Plan 9
Plan 9 is supported on a best-effort basis. Please see the [README-plan9](README-plan9.md)
document for more information.标签:EVTX分析