Expand description
This crate provides the core of the virtual terminal emulator implementation used by wezterm. The home for this crate is in the wezterm repo and development is tracked at https://github.com/wezterm/wezterm/.
It is full featured, providing terminal escape sequence parsing, keyboard and mouse input encoding, a model for the screen cells including scrollback, sixel and iTerm2 image support, OSC 8 Hyperlinks and a wide range of terminal cell attributes.
This crate does not provide any kind of gui, nor does it directly
manage a PTY; you provide a std::io::Write implementation that
could connect to a PTY, and supply bytes to the model via the
advance_bytes method.
The entrypoint to the crate is the Terminal struct.
Re-exports§
pub use config::TerminalConfiguration;pub use crate::input::*;pub use crate::screen::*;pub use crate::terminal::*;pub use crate::terminalstate::*;
Modules§
- color
- Colors for attributes
- config
- image
- Images. This module has some helpers for modeling terminal cells that are filled with image data. We’re targeting the iTerm image protocol initially, with sixel as an obvious follow up. Kitty has an extensive and complex graphics protocol whose docs are here: https://github.com/kovidgoyal/kitty/blob/master/docs/graphics-protocol.rst Both iTerm2 and Sixel appear to have semantics that allow replacing the contents of a single chararcter cell with image data, whereas the kitty protocol appears to track the images out of band as attachments with z-order.
- input
- screen
- terminal
- terminalstate
Structs§
- Cell
- Models the contents of a cell on the terminal display
- Cell
Attributes - Holds the attributes for a cell. Most style attributes are stored internally as part of a bitfield to reduce per-cell overhead. The setter methods return a mutable self reference so that they can be chained together.
- Cursor
Position - Describes the location of the cursor in the visible portion of the screen.
- Hyperlink
- Line
- Semantic
Zone - Unicode
Version
Enums§
- Attribute
Change - Models a change in the attributes of a cell in a stream of changes. Each variant specifies one of the possible attributes; the corresponding value holds the new value to be used for that attribute.
- Blink
- Specify whether you want to slowly or rapidly annoy your users
- CellRef
- Double
Click Range - Intensity
- The
Intensityof a cell describes its boldness. Most terminals implementIntensity::Boldby either using a bold font or by simply using an alternative color. Some terminals implementIntensity::Halfas a dimmer color variant. - Position
- Position allows referring to an absolute visible row number or a position relative to some existing row number (typically where the cursor is located). Both of the cases are represented as signed numbers so that the math and error checking for out of range values can be deferred to the point where we execute the request.
- Presentation
- Semantic
Type - Describes the semantic “type” of the cell. This categorizes cells into Output (from the actions the user is taking; this is the default if left unspecified), Input (that the user typed) and Prompt (effectively, “chrome” provided by the shell or application that the user is interacting with.
- Underline
- Specify just how underlined you want your
Cellto be - Vertical
Align
Constants§
Functions§
- grapheme_
column_ width - Returns the number of cells visually occupied by a grapheme. The input string must be a single grapheme.
- intersects_
range - Returns true if r1 intersects r2
- is_
white_ space_ char - Returns true if the char
chas the unicode White_Space property - is_
white_ space_ grapheme - Returns true if the grapheme string
gconsists entirely of characters that have the unicode White_Space property. - unicode_
column_ width - Returns the number of cells visually occupied by a sequence
of graphemes.
Calls through to
grapheme_column_widthfor each grapheme and sums up the length.
Type Aliases§
- Phys
RowIndex - Represents the index into screen.lines. Index 0 is the top of the scrollback (if any). The index of the top of the visible screen depends on the terminal dimensions and the scrollback size.
- Scrollback
OrVisible RowIndex - Like
VisibleRowIndexabove, but can index backwards into scrollback. This is deliberately a differently sized signed type to catch accidentally blending together the wrong types of indices. This is explicitly 32-bit rather than 64-bit as it seems unreasonable to want to scroll back or select more than ~2billion lines of scrollback. - Stable
RowIndex - Allows referencing a logical line in the scrollback, allowing for scrolling. The StableRowIndex counts from the top of the scrollback, growing larger as you move down through the display rows. Initially the very first line as StableRowIndex==0. If the scrollback is filled and lines are purged (say we need to purge 5 lines), then whichever line is first in the scrollback (PhysRowIndex==0) will now have StableRowIndex==5 which is the same value that that logical line had prior to data being purged out of the scrollback.
- Visible
RowIndex - Represents an index into the visible portion of the screen.
Value 0 is the first visible row.
VisibleRowIndexneeds to be resolved into aPhysRowIndexto obtain an actual row. It is not valid to have a negativeVisibleRowIndexvalue so this type logically should be unsigned, however, having a different sign is helpful to have the compiler catch accidental arithmetic performed betweenPhysRowIndexandVisibleRowIndex. We could define our own type with its ownAddandSuboperators, but then we’d not be able to iterate overRangesof these types without also laboriously implementing an iteratorSkiptrait that is currently only in unstable rust.