mock

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 12 Imported by: ? 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

Package mock provides a headless Kite backend that records frames and accepts synthetic input so tests can exercise a UI without a terminal.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend struct {

	// BeginFrameCalls counts how many times BeginFrame was called.
	BeginFrameCalls int
	// EndFrameCalls counts how many times EndFrame was called.
	EndFrameCalls int
	// RestoreCalls counts how many times Restore was called.
	RestoreCalls int
	// ClearCalls counts how many times Clear was called.
	ClearCalls int
	// Frames records all completed frames (EndFrame called successfully).
	Frames []FrameRecord

	// Cursor is the most recent cursor state set via the backend methods.
	Cursor CursorRecord

	// Output captures all raw sequences written to the backend via Writer().
	Output OutputBuffer

	// ProgramStatus records the most recently set program status.
	ProgramStatus *backend.ProgramStatus

	// ProgramResume records the most recently set program resume.
	ProgramResume *backend.ProgramResume

	// Inline reports whether inline mode is enabled.
	Inline bool
	// InsertedAbove stores buffers inserted above the inline frame.
	InsertedAbove []*backend.Buffer
	// contains filtered or unexported fields
}

Backend is a recording backend for tests. It implements backend.Backend and tracks every BeginFrame / EndFrame call so tests can assert on the sequence of frames and the cell content painted into each one.

Backend is safe for concurrent use.

func New

func New(width, height int) *Backend

New creates a recording Backend for a terminal of the given dimensions.

func NewWithCaps

func NewWithCaps(width, height int, caps backend.Caps) *Backend

NewWithCaps creates a recording Backend with the given dimensions and terminal capabilities.

func (*Backend) AllFrames

func (b *Backend) AllFrames() []FrameRecord

AllFrames returns a shallow copy of all recorded frames.

func (*Backend) AllInsertedAbove

func (b *Backend) AllInsertedAbove() []*backend.Buffer

AllInsertedAbove returns a copy of the slice of buffers inserted above.

func (*Backend) BeginFrame

func (b *Backend) BeginFrame() backend.Surface

BeginFrame allocates a fresh Buffer, records the call, and returns the buffer as a backend.Surface.

func (*Backend) Bell

func (b *Backend) Bell()

Bell writes the BEL character to Output.

func (*Backend) Caps

func (b *Backend) Caps() backend.Caps

Caps returns the simulated terminal capabilities.

func (*Backend) Clear

func (b *Backend) Clear()

Clear clears the simulated screen, records the scrollback mark, and increments ClearCalls.

func (*Backend) Clipboard

func (b *Backend) Clipboard() backend.Clipboard

Clipboard returns the mock clipboard provider.

func (*Backend) CloseEvents

func (b *Backend) CloseEvents()

CloseEvents closes the mock backend's event channel to simulate terminal loss.

func (*Backend) Counts

func (b *Backend) Counts() (begin, end, restore, clear int)

Counts returns snapshot of call counters.

func (*Backend) CurrentProgramResume

func (b *Backend) CurrentProgramResume() *backend.ProgramResume

CurrentProgramResume returns a copy of the most recently set program resume.

func (*Backend) CurrentProgramStatus

func (b *Backend) CurrentProgramStatus() *backend.ProgramStatus

CurrentProgramStatus returns the most recently set program status.

func (*Backend) CursorState

func (b *Backend) CursorState() CursorRecord

CursorState returns a copy of the current cursor state.

func (*Backend) DumpState

func (b *Backend) DumpState()

DumpState writes a debug dump of the backend state to a file.

func (*Backend) EndFrame

func (b *Backend) EndFrame() error

EndFrame records the completed frame and returns nil. It panics if BeginFrame has not been called first.

func (*Backend) Events

func (b *Backend) Events() <-chan backend.RawEvent

Events returns a channel of input events.

func (*Backend) Frame

func (b *Backend) Frame(i int) (FrameRecord, bool)

Frame returns the recorded frame at index i, or false if out of range.

func (*Backend) FrameCount

func (b *Backend) FrameCount() int

FrameCount returns the total number of completed frames recorded.

func (*Backend) InsertAbove

func (b *Backend) InsertAbove(buf *backend.Buffer)

InsertAbove stores a copy of the given buffer in InsertedAbove.

func (*Backend) InsertAboveForFrame

func (b *Backend) InsertAboveForFrame(buf *backend.Buffer)

InsertAboveForFrame implements backend.FrameInserter.

func (*Backend) InsertedAboveCount

func (b *Backend) InsertedAboveCount() int

InsertedAboveCount returns the number of buffers inserted above the inline frame.

func (*Backend) InsertedAboveSinceClear

func (b *Backend) InsertedAboveSinceClear() []*backend.Buffer

InsertedAboveSinceClear returns a copy of the slice of buffers inserted above since the most recent Clear() call (or all inserted buffers if Clear has not been called).

func (*Backend) InsertedAboveSinceClearCount

func (b *Backend) InsertedAboveSinceClearCount() int

InsertedAboveSinceClearCount returns the number of buffers inserted above since the most recent Clear() call.

func (*Backend) IsInline

func (b *Backend) IsInline() bool

IsInline reports whether inline mode is enabled.

func (*Backend) LastFrame

func (b *Backend) LastFrame() FrameRecord

LastFrame returns the most recently completed frame, or a zero FrameRecord if no frames have been completed yet.

func (*Backend) PostEvent

func (b *Backend) PostEvent(ev backend.RawEvent)

PostEvent sends a raw input event to the mock backend's event channel. It is safe for concurrent use.

func (*Backend) PostEventContext

func (b *Backend) PostEventContext(ctx context.Context, ev backend.RawEvent) error

PostEventContext sends a raw input event with context cancellation support.

func (*Backend) Resize

func (b *Backend) Resize(size geom.Size)

Resize updates the simulated terminal dimensions.

func (*Backend) Restore

func (b *Backend) Restore()

Restore records the call. In the mock backend this is a no-op.

func (*Backend) Resume

func (b *Backend) Resume() error

func (*Backend) ResumeCount

func (b *Backend) ResumeCount() int

func (*Backend) SetCaps

func (b *Backend) SetCaps(caps backend.Caps)

SetCaps updates the simulated terminal capabilities.

func (*Backend) SetColorScheme

func (b *Backend) SetColorScheme(scheme style.ColorScheme)

func (*Backend) SetCursorColor

func (b *Backend) SetCursorColor(c color.Color)

SetCursorColor sets the terminal hardware cursor color.

func (*Backend) SetCursorPos

func (b *Backend) SetCursorPos(x, y int)

SetCursorPos sets the cursor position.

func (*Backend) SetCursorShape

func (b *Backend) SetCursorShape(s backend.CursorShape)

SetCursorShape sets the cursor visual shape.

func (*Backend) SetInline

func (b *Backend) SetInline(inline bool)

SetInline configures whether inline mode is enabled.

func (*Backend) SetProgramResume

func (b *Backend) SetProgramResume(resume *backend.ProgramResume)

SetProgramResume records and writes OSC 7577 Program Resume to Output.

func (*Backend) SetProgramStatus

func (b *Backend) SetProgramStatus(status *backend.ProgramStatus)

SetProgramStatus records and writes OSC 7501 Program Status to Output.

func (*Backend) SetProgressBar

func (b *Backend) SetProgressBar(state backend.ProgressBarState, percentage int)

SetProgressBar updates the terminal native progress bar escape sequence in Output.

func (*Backend) SetSuspendErrors

func (b *Backend) SetSuspendErrors(suspend, resume error)

func (*Backend) SetTitle

func (b *Backend) SetTitle(s string)

SetTitle sets the simulated window title and writes the OSC 2 sequence to Output.

func (*Backend) ShowCursor

func (b *Backend) ShowCursor(v bool)

ShowCursor sets the cursor visibility.

func (*Backend) Size

func (b *Backend) Size() geom.Size

Size returns the simulated dimensions.

func (*Backend) Start

func (b *Backend) Start() error

Start records the startup call.

func (*Backend) Suspend

func (b *Backend) Suspend() error

func (*Backend) SuspendCount

func (b *Backend) SuspendCount() int

func (*Backend) Suspended

func (b *Backend) Suspended() bool

func (*Backend) Title

func (b *Backend) Title() string

Title returns the current simulated terminal window title.

func (*Backend) TryPostEvent

func (b *Backend) TryPostEvent(ev backend.RawEvent) bool

TryPostEvent attempts to send an event without blocking. Returns true if queued.

func (*Backend) WaitForFrame

func (b *Backend) WaitForFrame(timeout time.Duration) (FrameRecord, error)

WaitForFrame blocks until a frame is completed or the timeout expires.

func (*Backend) WaitForNextFrame

func (b *Backend) WaitForNextFrame(ctx context.Context) (FrameRecord, error)

WaitForNextFrame blocks until the next frame is committed or ctx is cancelled.

func (*Backend) Writer

func (b *Backend) Writer() io.Writer

Writer returns the mock output buffer.

type CursorRecord

type CursorRecord struct {
	Visible bool
	X, Y    int
	Shape   backend.CursorShape
	Color   color.Color
}

CursorRecord captures one call to the cursor-management methods.

type FrameRecord

type FrameRecord struct {
	// Surface is the Buffer that was returned by BeginFrame and
	// subsequently drawn into by the paint engine.
	Surface *backend.Buffer
}

FrameRecord captures the state of one completed frame.

type OutputBuffer

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

OutputBuffer is a thread-safe bytes.Buffer wrapper used by Backend to record terminal output sequences.

func (*OutputBuffer) Bytes

func (o *OutputBuffer) Bytes() []byte

Bytes returns a copy of the buffer contents as a byte slice.

func (*OutputBuffer) Len

func (o *OutputBuffer) Len() int

Len returns the number of bytes in the buffer.

func (*OutputBuffer) Reset

func (o *OutputBuffer) Reset()

Reset clears the buffer contents.

func (*OutputBuffer) String

func (o *OutputBuffer) String() string

String returns the contents of the buffer as a string.

func (*OutputBuffer) Write

func (o *OutputBuffer) Write(p []byte) (n int, err error)

Write appends p to the output buffer in a thread-safe manner.

Jump to

Keyboard shortcuts

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