Documentation
¶
Overview ¶
Package vttest provides a virtual terminal implementation for testing terminal applications. It allows you to create a terminal instance with a pseudo-terminal (PTY) and capture its state at any moment, enabling you to write tests that verify the behavior of terminal applications.
Index ¶
- Variables
- type Cell
- type Color
- type Cursor
- type Drawer
- type Link
- type Modes
- type Position
- type Snapshot
- type Style
- type Terminal
- func (t *Terminal) Close() error
- func (t *Terminal) Image() image.Image
- func (t *Terminal) Input() io.Reader
- func (t *Terminal) Output() io.Writer
- func (t *Terminal) Paste(text string)
- func (t *Terminal) Resize(cols, rows int) error
- func (t *Terminal) SendKey(k uv.KeyEvent)
- func (t *Terminal) SendMouse(m uv.MouseEvent)
- func (t *Terminal) SendText(text string)
- func (t *Terminal) Snapshot() Snapshot
- func (t *Terminal) Start(cmd *exec.Cmd) error
- func (t *Terminal) Wait(cmd *exec.Cmd) error
Constants ¶
This section is empty.
Variables ¶
var DefaultDrawer = func() *Drawer { cellW, cellH := 10, 16 regular, _ := freetype.ParseFont(gomono.TTF) bold, _ := freetype.ParseFont(gomonobold.TTF) italic, _ := freetype.ParseFont(gomonoitalic.TTF) boldItalic, _ := freetype.ParseFont(gomonobolditalic.TTF) faceOpts := &truetype.Options{ Size: 14, DPI: 72, Hinting: font.HintingFull, } regularFace := truetype.NewFace(regular, faceOpts) boldFace := truetype.NewFace(bold, faceOpts) italicFace := truetype.NewFace(italic, faceOpts) boldItalicFace := truetype.NewFace(boldItalic, faceOpts) return &Drawer{ CellWidth: cellW, CellHeight: cellH, RegularFace: regularFace, BoldFace: boldFace, ItalicFace: italicFace, BoldItalicFace: boldItalicFace, } }()
DefaultDrawer are the default options used for creating terminal screen images.
Functions ¶
This section is empty.
Types ¶
type Cell ¶
type Cell struct {
// Content is the [Cell]'s content, which consists of a single grapheme
// cluster. Most of the time, this will be a single rune as well, but it
// can also be a combination of runes that form a grapheme cluster.
Content string `json:"content,omitempty" yaml:"content,omitempty"`
// The style of the cell. Nil style means no style. Zero value prints a
// reset sequence.
Style Style `json:"style,omitzero" yaml:"style,omitzero"`
// Link is the hyperlink of the cell.
Link Link `json:"link,omitzero" yaml:"link,omitzero"`
// Width is the mono-spaced width of the grapheme cluster.
Width int `json:"width,omitzero" yaml:"width,omitzero"`
}
Cell represents a single cell in the terminal screen.
type Color ¶
Color represents a terminal color, which can be one of the following: - An ANSI 16 color (0-15) of type ansi.BasicColor. - An ANSI 256 color (0-255) of type ansi.IndexedColor. - Or any other 24-bit color that implements color.Color.
func (Color) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface for Color.
func (*Color) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface for Color.
type Cursor ¶
type Cursor struct {
Position Position `json:"position," yaml:"position"`
Visible bool `json:"visible" yaml:"visible"`
Color Color `json:"color,omitzero" yaml:"color,omitzero"`
Style vt.CursorStyle `json:"style" yaml:"style"`
Blink bool `json:"blink" yaml:"blink"`
}
Cursor represents the cursor state.
type Drawer ¶
type Drawer struct {
// CellWidth is the width of each cell in pixels. Default is 10.
CellWidth int
// CellHeight is the height of each cell in pixels. Default is 16.
CellHeight int
// RegularFace is the font face to use for regular text. Default is Go
// mono.
RegularFace font.Face
// BoldFace is the font face to use for bold text. If nil, Go mono bold is
// used.
BoldFace font.Face
// ItalicFace is the font face to use for italic text. If nil, Go mono italic
// is used.
ItalicFace font.Face
// BoldItalicFace is the font face to use for bold italic text. If nil, Go
// mono bold italic is used.
BoldItalicFace font.Face
}
Drawer contains options for drawing a terminal emulator screen to an image.
type Link ¶
type Link struct {
URL string `json:"url,omitempty" yaml:"url,omitempty"`
Params string `json:"params,omitempty" yaml:"params,omitempty"`
}
Link represents a hyperlink in the terminal screen.
type Modes ¶
type Modes struct {
ANSI map[ansi.ANSIMode]ansi.ModeSetting `json:"ansi" yaml:"ansi"`
DEC map[ansi.DECMode]ansi.ModeSetting `json:"dec" yaml:"dec"`
}
Modes represents terminal modes.
type Snapshot ¶
type Snapshot struct {
Modes Modes `json:"modes" yaml:"modes"`
Title string `json:"title" yaml:"title"`
Rows int `json:"rows" yaml:"rows"`
Cols int `json:"cols" yaml:"cols"`
AltScreen bool `json:"alt_screen" yaml:"alt_screen"`
Cursor Cursor `json:"cursor" yaml:"cursor"`
BgColor Color `json:"bg_color,omitzero" yaml:"bg_color,omitzero"`
FgColor Color `json:"fg_color,omitzero" yaml:"fg_color,omitzero"`
Cells [][]Cell `json:"cells" yaml:"cells"`
}
Snapshot represents a snapshot of the terminal state at a given moment.
type Style ¶
type Style struct {
Fg Color `json:"fg,omitzero" yaml:"fg,omitzero"`
Bg Color `json:"bg,omitzero" yaml:"bg,omitzero"`
UnderlineColor Color `json:"underline_color,omitzero" yaml:"underline_color,omitzero"`
Underline uv.Underline `json:"underline,omitempty" yaml:"underline,omitempty"`
Attrs byte `json:"attrs,omitempty" yaml:"attrs,omitempty"`
}
Style represents the Style of a cell.
type Terminal ¶
type Terminal struct {
Emulator *vt.SafeEmulator
// contains filtered or unexported fields
}
Terminal represents a virtual terminal with it's PTY and state.
func NewTerminal ¶
NewTerminal creates a new virtual terminal with the given size for testing purposes. At any moment, you can take a snapshot of the terminal state by calling the Terminal.Snapshot method on the returned Terminal instance.
func (*Terminal) Paste ¶
Paste sends the given text to the terminal emulator as if pasted by a user.
func (*Terminal) SendKey ¶
SendKey sends the given key event to the terminal emulator as if typed by a user.
func (*Terminal) SendMouse ¶
func (t *Terminal) SendMouse(m uv.MouseEvent)
SendMouse sends the given mouse event to the terminal emulator as if performed by a user.
func (*Terminal) SendText ¶
SendText sends the given raw text to the terminal emulator as if typed by a user.
func (*Terminal) Snapshot ¶
Snapshot takes a snapshot of the current terminal state. The returned Snapshot can be used to inspect the terminal state at the moment the snapshot was taken. It can also be serialized to JSON or YAML for further analysis or testing purposes.