mock

package
v3.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 31, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cell

type Cell struct {
	C     []rune // Content, for now only a single rune is supported
	Fg    color.Color
	Bg    color.Color
	Attr  vt.Attr
	Width int // Display width of C.
}

Cell is a representation of a display cell.

type MockBackend added in v3.0.6

type MockBackend interface {
	vt.Backend

	// GetCell returns the cell at the given position, or the zero value if the
	// position is out of the bounds of the window.
	GetCell(vt.Coord) Cell

	// Bells counts the number of bells rung.
	Bells() int

	// GetTitle gets the current window title.
	GetTitle() string

	// SetSize is used to resize the window.
	// Newly added cells are empty, and content in old cells that out of range is lost.
	SetSize(vt.Coord)
}

MockBackend provides additional mock-specific capabilities on top of Backend. This is meant to facilitate test cases

func NewMockBackend added in v3.0.6

func NewMockBackend(options ...MockOpt) MockBackend

NewMockBackend returns a MockBackend modified by the given options. The default is a fully featured 256-color backend with initial size 80x24.

type MockOpt added in v3.0.6

type MockOpt interface{ SetMockOpt(mb *mockBackend) }

MockOpt is an interface by which options can change the behavior of the mocked terminal. This is intended to permit easier testing.

type MockOptColors added in v3.0.6

type MockOptColors int

MockOptColors changes the number of colors the terminal supports.

func (MockOptColors) SetMockOpt added in v3.0.6

func (o MockOptColors) SetMockOpt(mb *mockBackend)

type MockOptSize added in v3.0.6

type MockOptSize vt.Coord

MockOptSize changes the default terminal size, which is normally 80x24.

func (MockOptSize) SetMockOpt added in v3.0.6

func (mbs MockOptSize) SetMockOpt(mb *mockBackend)

type MockTerm added in v3.0.6

type MockTerm interface {
	tty.Tty

	// Pos reports the current cursor position.
	Pos() vt.Coord

	// GetCell returns the current cell.
	GetCell(vt.Coord) Cell

	// Bells returns the number of times the bell has been rung.
	Bells() int

	// Inject a keyboard event.
	KeyEvent(vt.KbdEvent)

	// GetTitle obtains the current window title.
	GetTitle() string

	// SetSize is used to resize the terminal.
	SetSize(vt.Coord)
}

MockTerm is a mock terminal (emulator). It can be used to test the emulator itself, or to test applications (or tcell) that uses the terminal. It also implements the Tty interface used by tcell itself.

func NewMockTerm added in v3.0.6

func NewMockTerm(opts ...MockOpt) MockTerm

NewMockTerm gives a mock terminal emulator.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL