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 ¶
- type Backend
- func (b *Backend) AllFrames() []FrameRecord
- func (b *Backend) AllInsertedAbove() []*backend.Buffer
- func (b *Backend) BeginFrame() backend.Surface
- func (b *Backend) Bell()
- func (b *Backend) Caps() backend.Caps
- func (b *Backend) Clear()
- func (b *Backend) Clipboard() backend.Clipboard
- func (b *Backend) CloseEvents()
- func (b *Backend) Counts() (begin, end, restore, clear int)
- func (b *Backend) CurrentProgramResume() *backend.ProgramResume
- func (b *Backend) CurrentProgramStatus() *backend.ProgramStatus
- func (b *Backend) CursorState() CursorRecord
- func (b *Backend) DumpState()
- func (b *Backend) EndFrame() error
- func (b *Backend) Events() <-chan backend.RawEvent
- func (b *Backend) Frame(i int) (FrameRecord, bool)
- func (b *Backend) FrameCount() int
- func (b *Backend) InsertAbove(buf *backend.Buffer)
- func (b *Backend) InsertAboveForFrame(buf *backend.Buffer)
- func (b *Backend) InsertedAboveCount() int
- func (b *Backend) InsertedAboveSinceClear() []*backend.Buffer
- func (b *Backend) InsertedAboveSinceClearCount() int
- func (b *Backend) IsInline() bool
- func (b *Backend) LastFrame() FrameRecord
- func (b *Backend) PostEvent(ev backend.RawEvent)
- func (b *Backend) PostEventContext(ctx context.Context, ev backend.RawEvent) error
- func (b *Backend) Resize(size geom.Size)
- func (b *Backend) Restore()
- func (b *Backend) Resume() error
- func (b *Backend) ResumeCount() int
- func (b *Backend) SetCaps(caps backend.Caps)
- func (b *Backend) SetColorScheme(scheme style.ColorScheme)
- func (b *Backend) SetCursorColor(c color.Color)
- func (b *Backend) SetCursorPos(x, y int)
- func (b *Backend) SetCursorShape(s backend.CursorShape)
- func (b *Backend) SetInline(inline bool)
- func (b *Backend) SetProgramResume(resume *backend.ProgramResume)
- func (b *Backend) SetProgramStatus(status *backend.ProgramStatus)
- func (b *Backend) SetProgressBar(state backend.ProgressBarState, percentage int)
- func (b *Backend) SetSuspendErrors(suspend, resume error)
- func (b *Backend) SetTitle(s string)
- func (b *Backend) ShowCursor(v bool)
- func (b *Backend) Size() geom.Size
- func (b *Backend) Start() error
- func (b *Backend) Suspend() error
- func (b *Backend) SuspendCount() int
- func (b *Backend) Suspended() bool
- func (b *Backend) Title() string
- func (b *Backend) TryPostEvent(ev backend.RawEvent) bool
- func (b *Backend) WaitForFrame(timeout time.Duration) (FrameRecord, error)
- func (b *Backend) WaitForNextFrame(ctx context.Context) (FrameRecord, error)
- func (b *Backend) Writer() io.Writer
- type CursorRecord
- type FrameRecord
- type OutputBuffer
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 NewWithCaps ¶
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 ¶
AllInsertedAbove returns a copy of the slice of buffers inserted above.
func (*Backend) BeginFrame ¶
BeginFrame allocates a fresh Buffer, records the call, and returns the buffer as a backend.Surface.
func (*Backend) Clear ¶
func (b *Backend) Clear()
Clear clears the simulated screen, records the scrollback mark, and increments ClearCalls.
func (*Backend) CloseEvents ¶
func (b *Backend) CloseEvents()
CloseEvents closes the mock backend's event channel to simulate terminal loss.
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 ¶
EndFrame records the completed frame and returns nil. It panics if BeginFrame has not been called first.
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 ¶
FrameCount returns the total number of completed frames recorded.
func (*Backend) InsertAbove ¶
InsertAbove stores a copy of the given buffer in InsertedAbove.
func (*Backend) InsertAboveForFrame ¶
InsertAboveForFrame implements backend.FrameInserter.
func (*Backend) InsertedAboveCount ¶
InsertedAboveCount returns the number of buffers inserted above the inline frame.
func (*Backend) InsertedAboveSinceClear ¶
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 ¶
InsertedAboveSinceClearCount returns the number of buffers inserted above since the most recent Clear() call.
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 ¶
PostEvent sends a raw input event to the mock backend's event channel. It is safe for concurrent use.
func (*Backend) PostEventContext ¶
PostEventContext sends a raw input event with context cancellation support.
func (*Backend) Restore ¶
func (b *Backend) Restore()
Restore records the call. In the mock backend this is a no-op.
func (*Backend) ResumeCount ¶
func (*Backend) SetColorScheme ¶
func (b *Backend) SetColorScheme(scheme style.ColorScheme)
func (*Backend) SetCursorColor ¶
SetCursorColor sets the terminal hardware cursor color.
func (*Backend) SetCursorPos ¶
SetCursorPos sets the cursor position.
func (*Backend) SetCursorShape ¶
func (b *Backend) SetCursorShape(s backend.CursorShape)
SetCursorShape sets the cursor visual shape.
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 (*Backend) SetTitle ¶
SetTitle sets the simulated window title and writes the OSC 2 sequence to Output.
func (*Backend) ShowCursor ¶
ShowCursor sets the cursor visibility.
func (*Backend) SuspendCount ¶
func (*Backend) TryPostEvent ¶
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.
type CursorRecord ¶
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) String ¶
func (o *OutputBuffer) String() string
String returns the contents of the buffer as a string.