termlab

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 27 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Real terminal emulators under a private Xvfb display running icebath, driven by injected input and judged by screenshots

Index

Constants

View Source
const BinaryEnv = "TERMLAB_ICEBATH"

Environment variable naming a prebuilt icebath binary the tests run instead of building one

View Source
const BuildLimit = 12000000 * 1024

Address space limit of builds, the 12000000 KiB of ulimit -v the project builds under

View Source
const BuildMemLimit = "4GiB"

Soft heap limit of the Go toolchain during builds

View Source
const DriverEnv = "TERMLAB_DRIVER"

Environment variable naming the unix socket a driver serves

View Source
const ProbeEnv = "TERMLAB_PROBE"

Environment variable that turns the test binary into the probe program the rig checks itself with

Variables

View Source
var Konsole = Emulator{Name: "konsole", /* contains filtered or unexported fields */}

KDE terminal without its menu and tab bars at 160 by 48 cells

View Source
var Xterm = Emulator{Name: "xterm", /* contains filtered or unexported fields */}

X terminal emulating a vt340 so it draws sixel, at 160 by 48 cells

Functions

func Coverage

func Coverage(img image.Image, r image.Rectangle, bg color.Color) float64

Share of pixels of the rectangle whose color is not the background

func DiffBounds

func DiffBounds(a, b image.Image, r image.Rectangle) image.Rectangle

Bounding box of the pixels inside the rectangle that differ between the two images

func Differs

func Differs(a, b image.Image, r image.Rectangle) float64

Share of pixels of the rectangle whose color differs between the two images

func Icebath

func Icebath() (string, error)

Builds cmd/icebath once per test binary under the project memory limits, or takes the prebuilt binary named

func Limited

func Limited(bytes uint64, argv ...string) (*exec.Cmd, error)

Command running argv under the address space limit, through this test binary as the limiting helper

func Line

func Line(cells []string) string

One row of the mirrored screen as plain text

func Missing

func Missing(tools ...string) error

Error naming every given tool absent from PATH, nil when all of them are there

func MouseSeq

func MouseSeq(x, y, button int, press bool) []byte

SGR 1006 bytes of a mouse press or release, button 0 left, 1 middle, 2 right, 64 and 65 wheel

func RemoveBuild

func RemoveBuild() error

Removes the directory the icebath build went into

func RunHelper

func RunHelper()

Runs the driver, the probe or a memory limited command when the environment asks for one, returns at once otherwise

func Sample

func Sample(img image.Image, rects []image.Rectangle) []color.RGBA

Colors of every pixel inside any of the rectangles, each clipped to the image

func SavePNG

func SavePNG(path string, img image.Image) error

Writes the image as a PNG file

func Uniform

func Uniform(img image.Image, r image.Rectangle) bool

Reports whether every pixel of the rectangle inside the image has one color

func WriteConfig

func WriteConfig(dir string, settings map[string]string) error

Writes an icebath home with a loopback provider and the settings given

Types

type Chunk

type Chunk struct {
	At   time.Time
	Data []byte
}

Bytes the program wrote and when the driver read them

type Emulator

type Emulator struct {
	Name string
	// contains filtered or unexported fields
}

Terminal emulator a session runs in, with the command line that runs a program inside it

type Lab

type Lab struct {
	Display int
	W, H    int
	// contains filtered or unexported fields
}

Private X display served by Xvfb, its framebuffer kept in a file the lab reads screenshots from

func Start

func Start(w, h int) (*Lab, error)

Starts Xvfb with a w by h screen on the first display number holding no socket or lock file

func (*Lab) Close

func (l *Lab) Close() error

Stops the X server, asking first so it removes its socket and lock, then killing it, and deletes its framebuffer

func (*Lab) Name

func (l *Lab) Name() string

Display name for the DISPLAY variable

func (*Lab) Open

func (l *Lab) Open(e Emulator, p Program) (*Session, error)

Starts the emulator on the display running the test binary as driver, calibrates the cell grid and starts the program

func (*Lab) Shot

func (l *Lab) Shot() (*image.RGBA, error)

Captures the whole screen of the display by reading the framebuffer file Xvfb maps, no X request or process involved

func (*Lab) ShotOf

func (l *Lab) ShotOf(region image.Rectangle) (*image.RGBA, error)

Captures the pixels of the region from the framebuffer file, the whole screen for an empty region

type Program

type Program struct {
	Path string
	Args []string
	Env  []string
	Dir  string
}

Command the driver starts on its pseudo terminal, Env laid over the environment the emulator gave the driver

type Session

type Session struct {
	// contains filtered or unexported fields
}

Program running in an emulator on a lab display, reached through the driver socket, with the cell geometry calibration found

func (*Session) Cells

func (s *Session) Cells(col, row, w, h int) image.Rectangle

Pixel rectangle of the screen covering w by h cells from the zero based column and row

func (*Session) Chunks

func (s *Session) Chunks() []Chunk

Program output in the pieces the driver read, each with its read time

func (*Session) Close

func (s *Session) Close() error

Stops polling and kills the emulator with the driver and the program under it

func (*Session) Ended

func (s *Session) Ended() string

Why the session stopped receiving output, empty while it still does

func (*Session) Find

func (s *Session) Find(text string) (col, row int, ok bool)

Zero based column and row where the text starts on the mirrored screen, false when it is not there

func (*Session) Grid

func (s *Session) Grid() [][]uv.Cell

Cells of the screen as the program painted them, read from a mirror emulator fed the same output

func (*Session) Input

func (s *Session) Input() []Chunk

What the emulator sent the program, key presses and query answers, in the pieces the driver read

func (*Session) Key

func (s *Session) Key(seq []byte) (time.Time, error)

Sends one key as its escape sequence

func (*Session) Latency

func (s *Session) Latency(timeout time.Duration) (time.Duration, error)

Time from the last injected write to the next program output, failing when none arrives within the timeout

func (*Session) Mouse

func (s *Session) Mouse(x, y, button int, press bool) (time.Time, error)

Sends an SGR 1006 mouse press or release of a button at the one based column x and row y

func (*Session) Output

func (s *Session) Output() []byte

Everything the program wrote so far, a view that later output never changes

func (*Session) Pitch

func (s *Session) Pitch() (float64, float64)

Pixels across and down one cell

func (*Session) Screen

func (s *Session) Screen() [][]string

Text of each mirrored cell, a space for a blank cell and empty for the tail of a wide one

func (*Session) Shot

func (s *Session) Shot() (*image.RGBA, error)

Screenshot of the whole lab display

func (*Session) ShotOf

func (s *Session) ShotOf(region image.Rectangle) (*image.RGBA, error)

Screenshot of a pixel region of the lab display

func (*Session) Size

func (s *Session) Size() (cols, rows int)

Columns and rows of the grid the emulator gave the program

func (*Session) Type

func (s *Session) Type(keys string) (time.Time, error)

Types text as the keyboard would send it

func (*Session) WaitChange

func (s *Session) WaitChange(from image.Image, region image.Rectangle, timeout time.Duration) (*image.RGBA, error)

Takes screenshots until the region differs from the given one, returning the first that does

func (*Session) WaitFor

func (s *Session) WaitFor(cond func([]byte) bool, timeout time.Duration) error

Waits until the output satisfies the condition, failing at the timeout or when the program ends first

func (*Session) Watch

func (s *Session) Watch(box image.Rectangle) *Watch

Starts recording the box, given in cells, from the state the mirror holds now

func (*Session) Write

func (s *Session) Write(b []byte) (time.Time, error)

Injects raw bytes as terminal input, returning when the driver wrote them into the pseudo terminal

type Watch

type Watch struct {
	// contains filtered or unexported fields
}

Recorder of every change to a box of mirrored cells, stamped with the read time of the output causing it

func (*Watch) Answer

func (w *Watch) Answer(after time.Time, cells []int, share float64) (time.Time, bool)

Read time of the first chunk after the moment leaving at least the share of cells changed from that moment

func (*Watch) At

func (w *Watch) At(t time.Time) []uv.Cell

State of the box after every chunk read at or before the time

func (*Watch) Cell

func (w *Watch) Cell(i int) image.Point

Screen column and row of a box index

func (*Watch) Diff

func (w *Watch) Diff(from, to time.Time) []int

Indexes of the box cells that differ between the states at the two times

func (*Watch) Moved

func (w *Watch) Moved(from, to time.Time) map[int]bool

Indexes of the box cells some chunk read after from and at or before to changed

func (*Watch) Stop

func (w *Watch) Stop()

Stops recording

Jump to

Keyboard shortcuts

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