Documentation
¶
Index ¶
- type CaptureOption
- type RecordedEvent
- type ScreenCapture
- type Session
- func (s *Session) AssertContains(text string) error
- func (s *Session) AssertContainsPattern(pattern *regexp.Regexp) error
- func (s *Session) AssertFileContains(relPath string, content string) error
- func (s *Session) AssertFileExists(relPath string) error
- func (s *Session) AssertLine(predicate func(line string) bool, message string) error
- func (s *Session) AssertNotContains(text string) error
- func (s *Session) Capture(opts ...CaptureOption) (string, error)
- func (s *Session) Close() error
- func (s *Session) FindTextLocation(text string) (row, col int, found bool, err error)
- func (s *Session) GetCursorPosition() (row, col int, err error)
- func (s *Session) GetKeyHistory() []string
- func (s *Session) GetVisibleLines() ([]string, error)
- func (s *Session) NavigateToText(text string) error
- func (s *Session) SaveRecording() error
- func (s *Session) SelectItem(predicate func(line string) bool) error
- func (s *Session) SelectItemWithKey(predicate func(line string) bool, key string) error
- func (s *Session) SendKeys(keys ...string) error
- func (s *Session) SendKeysAndWaitForChange(timeout time.Duration, keys ...string) error
- func (s *Session) StartRecording(outputPath string) error
- func (s *Session) StopRecording() error
- func (s *Session) TakeScreenshot(filepath string) error
- func (s *Session) Type(keys ...string) error
- func (s *Session) WaitForAnyText(texts []string, timeout time.Duration) (string, error)
- func (s *Session) WaitForFile(relPath string, timeout time.Duration) error
- func (s *Session) WaitForText(text string, timeout time.Duration) error
- func (s *Session) WaitForTextPattern(pattern *regexp.Regexp, timeout time.Duration) (string, error)
- func (s *Session) WaitForUIStable(timeout time.Duration, pollInterval time.Duration, ...) error
- func (s *Session) WaitStable() error
- type SessionRecording
- type StartConfig
- type StartOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CaptureOption ¶
type CaptureOption func(*captureConfig)
CaptureOption configures capture behavior
func WithCleanedOutput ¶
func WithCleanedOutput() CaptureOption
WithCleanedOutput is a capture option to get pane content with ANSI codes stripped.
func WithRawOutput ¶
func WithRawOutput() CaptureOption
WithRawOutput is a capture option to get the raw pane content with ANSI codes.
type RecordedEvent ¶
type RecordedEvent struct {
Timestamp time.Time `json:"timestamp"`
Type string `json:"type"` // "key", "capture", "assert", "wait", "navigate"
Data interface{} `json:"data"`
Result string `json:"result,omitempty"`
Error string `json:"error,omitempty"`
}
RecordedEvent represents a single action or assertion in the session.
type ScreenCapture ¶
type ScreenCapture struct {
Timestamp time.Time `json:"timestamp"`
Content string `json:"content"`
Raw string `json:"raw,omitempty"`
}
ScreenCapture represents a snapshot of the TUI at a point in time.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session represents an active TUI application running in a tmux session. It provides a high-level API for interaction and assertion.
func NewSession ¶
NewSession creates a new TUI session handle. It is intended for internal use by the harness.
func (*Session) AssertContains ¶
AssertContains immediately checks if the TUI's current content contains the specified text. NOTE: For better test reporting, it is recommended to use this with the harness context:
err := ctx.Check("should show welcome message", session.AssertContains("Welcome"))
func (*Session) AssertContainsPattern ¶
AssertContainsPattern checks if the current screen content matches the regex pattern.
func (*Session) AssertFileContains ¶
AssertFileContains asserts that a file within the scenario's temporary directory contains specific content.
func (*Session) AssertFileExists ¶
AssertFileExists asserts that a file exists within the scenario's temporary directory.
func (*Session) AssertLine ¶
AssertLine iterates through each visible line of the TUI and passes if the predicate function returns true for any line. This is a flexible way to assert complex states like focus or selection without relying on specific ANSI codes.
func (*Session) AssertNotContains ¶
AssertNotContains immediately checks if the TUI's current content does not contain the specified text. NOTE: For better test reporting, it is recommended to use this with the harness context:
err := ctx.Check("should not show error", session.AssertNotContains("Error:"))
func (*Session) Capture ¶
func (s *Session) Capture(opts ...CaptureOption) (string, error)
Capture returns the visible text content of the TUI pane. By default, it returns raw content with ANSI escape codes.
func (*Session) Close ¶
Close terminates the tmux session associated with the TUI. This is typically called automatically by the test harness on cleanup.
func (*Session) FindTextLocation ¶
FindTextLocation searches the screen for the given text and returns its 1-based (row, col) position if found.
func (*Session) GetCursorPosition ¶
GetCursorPosition returns the 1-based (row, col) of the cursor.
func (*Session) GetKeyHistory ¶
GetKeyHistory returns all keys sent during the session.
func (*Session) GetVisibleLines ¶
GetVisibleLines returns the current screen content as a slice of lines.
func (*Session) NavigateToText ¶
NavigateToText moves the selection to the line containing the specified text. For selection-based TUIs (like lists), it finds lines with selection indicators (">", "*", "•") and calculates navigation from the current selection. For cursor-based interfaces, it uses tmux cursor position. Waits for UI to stabilize after each keypress.
func (*Session) SaveRecording ¶
SaveRecording exports the session data to multiple formats.
func (*Session) SelectItem ¶
SelectItem navigates to and selects an item matching the predicate. It searches visible lines and moves the cursor to the first match, then presses Enter.
func (*Session) SelectItemWithKey ¶
SelectItemWithKey navigates to an item matching the predicate and presses the specified key.
func (*Session) SendKeys ¶
SendKeys sends a sequence of keystrokes to the TUI without waiting. Special keys can be sent (e.g., "Enter", "Esc", "Ctrl+c").
NOTE: In most cases, you should use Type() instead, which automatically waits for the screen to stabilize after sending keys.
func (*Session) SendKeysAndWaitForChange ¶
SendKeysAndWaitForChange sends keys and waits for the screen to change.
func (*Session) StartRecording ¶
StartRecording begins recording the session to the specified output path.
func (*Session) StopRecording ¶
StopRecording stops recording and saves the session data.
func (*Session) TakeScreenshot ¶
TakeScreenshot captures the current TUI state to a file.
func (*Session) Type ¶
Type sends keys to the TUI and waits for the screen to stabilize. This is the recommended method for most interactions, as it combines SendKeys + WaitStable which is the pattern used in 90% of tests.
Special handling for vim-style chord commands: When multiple identical single-character keys are passed (like "g", "g"), they are sent individually with stabilization between each key. This ensures vim chord commands like "gg" are properly recognized.
Example:
session.Type("j") // Navigate down and wait
session.Type("g", "g") // Go to top (sends separately for chord recognition)
session.Type("/", "search") // Open search and type
func (*Session) WaitForAnyText ¶
WaitForAnyText waits for any of the specified texts to appear on screen. Returns the first matching text found, or an error if timeout is reached.
func (*Session) WaitForFile ¶
WaitForFile waits for a file to exist within the scenario's temporary directory.
func (*Session) WaitForText ¶
WaitForText polls the TUI's content until the specified text appears or the timeout is reached.
func (*Session) WaitForTextPattern ¶
WaitForTextPattern waits for text matching the regex pattern to appear. Returns the matched text, or an error if timeout is reached.
func (*Session) WaitForUIStable ¶
func (s *Session) WaitForUIStable(timeout time.Duration, pollInterval time.Duration, stableDuration time.Duration) error
WaitForUIStable polls the TUI screen until its content remains unchanged for the specified stable duration, or until the timeout is reached. This is useful for waiting for animations or asynchronous updates to complete.
Parameters: - timeout: Maximum time to wait for stability (e.g., 10*time.Second) - pollInterval: How often to check the screen (e.g., 100*time.Millisecond) - stableDuration: How long the screen must be unchanged to be considered stable (e.g., 200*time.Millisecond)
For most use cases, use WaitStable() instead, which provides sensible defaults.
func (*Session) WaitStable ¶
WaitStable waits for the UI to stabilize using sensible defaults. This is equivalent to WaitForUIStable(10*time.Second, 100*time.Millisecond, 200*time.Millisecond).
The 10 second timeout accommodates slow CI environments but returns immediately once the UI stabilizes (typically 300-500ms for test fixtures).
Use this method for most testing scenarios. Use WaitForUIStable() directly only if you need custom timing parameters.
type SessionRecording ¶
type SessionRecording struct {
// contains filtered or unexported fields
}
SessionRecording tracks all events and captures during a TUI session.
type StartConfig ¶
StartConfig holds configuration for launching a TUI session.
type StartOption ¶
type StartOption func(*StartConfig)
StartOption is a function that configures a StartConfig.
func WithCwd ¶
func WithCwd(cwd string) StartOption
WithCwd sets the working directory for the TUI session.
func WithEnv ¶
func WithEnv(env ...string) StartOption
WithEnv sets environment variables for the TUI session. Variables should be in KEY=VALUE format.