Documentation
¶
Overview ¶
Package trail runs Kitex components inline in the terminal without switching to an alternate screen. The live UI grows or shrinks with its content. Use Static or Instance.InsertAbove to leave completed output in scrollback above the live UI.
Index ¶
- func MeasureElement(ref kitex.Ref[dom.Element]) geom.Size
- func Newline(count ...int) kitex.Node
- func Run(ctx context.Context, app kitex.Node, opts ...Option) error
- func Spacer() kitex.Node
- func Static[T any](items []T, renderItem func(item T, index int) kitex.Node) kitex.Node
- func Transform(transform func(line string, index int) string, text string) kitex.Node
- func UseFocus(ref kitex.Ref[dom.Element], opts ...FocusOptions) bool
- func UseInput(handler func(input string, k event.KeyEvent), opts ...InputOptions)
- type AppHandle
- type FocusManager
- type FocusOptions
- type InputOptions
- type Instance
- func (inst *Instance) Clear()
- func (inst *Instance) Engine() *engine.Engine
- func (inst *Instance) Exit(err error)
- func (inst *Instance) Frame()
- func (inst *Instance) InsertAbove(node kitex.Node)
- func (inst *Instance) LogWriter() io.Writer
- func (inst *Instance) Println(text string)
- func (inst *Instance) Rerender(app kitex.Node)
- func (inst *Instance) Root(app kitex.Node) kitex.Node
- func (inst *Instance) Run(ctx context.Context) error
- func (inst *Instance) Unmount()
- func (inst *Instance) WaitUntilExit() error
- type Option
- type StderrHandle
- type StdoutHandle
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MeasureElement ¶
MeasureElement measures the physical dimensions of an element ref in the current layout. If the ref is nil or not yet mounted/measured, it returns geom.Size{}.
func Static ¶
Static renders completed items permanently above the active inline frame. Newly appended items are flushed once into terminal scrollback and do not occupy space in the live inline DOM.
func Transform ¶
Transform splits text into lines, applies transform to each line (if non-nil), and returns a Text node containing the joined transformed lines.
func UseFocus ¶
UseFocus binds a focus listener to a DOM element ref and reports whether it is focused. If AutoFocus is enabled (and active), it automatically focuses the element on mount.
func UseInput ¶
func UseInput(handler func(input string, k event.KeyEvent), opts ...InputOptions)
UseInput registers a keyboard handler for raw or printable key presses. handler is called with the printable character (or empty string for control/navigation keys) and the underlying event.KeyEvent. By default, input handling is active unless explicitly disabled via InputOptions{IsActive: false}.
Types ¶
type AppHandle ¶
type AppHandle interface {
// Exit terminates the application and records an optional exit error.
Exit(err error)
// InsertAbove permanently flushes a rendered node into the terminal scrollback
// above the active inline frame.
InsertAbove(node kitex.Node)
// Println permanently writes a text line into the scrollback above the frame.
Println(text string)
// Clear clears the terminal and scrollback and repaints the mounted app.
Clear()
// Engine returns the underlying Kite Engine.
Engine() *engine.Engine
}
AppHandle provides controls to interact with the running trail instance.
type FocusManager ¶
type FocusManager struct {
// contains filtered or unexported fields
}
FocusManager provides programmatic focus navigation controls for the active Document.
func UseFocusManager ¶
func UseFocusManager() FocusManager
UseFocusManager returns a FocusManager to control document focus programmatically.
func (FocusManager) Focus ¶
func (fm FocusManager) Focus(id string) bool
Focus moves focus to the element with the specified ID.
func (FocusManager) FocusNext ¶
func (fm FocusManager) FocusNext() bool
FocusNext moves focus to the next focusable element in the document.
func (FocusManager) FocusPrevious ¶
func (fm FocusManager) FocusPrevious() bool
FocusPrevious moves focus to the previous focusable element in the document.
type FocusOptions ¶
FocusOptions configures focus management for a focusable element.
type InputOptions ¶
type InputOptions struct {
IsActive bool
}
InputOptions configures keyboard input handling for UseInput.
type Instance ¶
type Instance struct {
// contains filtered or unexported fields
}
Instance manages the lifecycle of an inline trail application.
func Render ¶
Render initializes an inline trail application, starts its event loop in a background goroutine, and returns the running Instance.
func (*Instance) Clear ¶
func (inst *Instance) Clear()
Clear clears the terminal and scrollback, then repaints the mounted app from the top of the terminal without resetting component state.
func (*Instance) Frame ¶
func (inst *Instance) Frame()
Frame runs a render pipeline pass and drains any follow-up pending tasks (such as passive effects queued during reconciliation), useful in headless tests.
func (*Instance) InsertAbove ¶
InsertAbove renders a kitex node into a temporary container and permanently flushes it to the terminal scrollback above the active inline frame.
func (*Instance) LogWriter ¶
LogWriter returns an io.Writer adapter that splits written bytes into lines and writes them permanently into the terminal scrollback above the active frame.
func (*Instance) Unmount ¶
func (inst *Instance) Unmount()
Unmount unmounts the root VDOM tree (running effect cleanups) and exits the application.
func (*Instance) WaitUntilExit ¶
WaitUntilExit blocks until the trail application completes and returns its exit error.
type Option ¶
type Option func(*options)
Option configures a trail Instance.
func WithBackend ¶
WithBackend specifies a custom backend (e.g. mock.New for testing).
func WithCtrlCExit ¶
WithCtrlCExit enables or disables automatic exit when Ctrl+C is pressed.
func WithEngineOptions ¶
WithEngineOptions supplies custom engine.Options.
func WithInterceptLog ¶
WithInterceptLog redirects standard log output (log.Default()) above the inline frame during Run.
type StderrHandle ¶
type StderrHandle struct {
// contains filtered or unexported fields
}
StderrHandle provides access to inline stderr routing above the inline frame.
func UseStderr ¶
func UseStderr() StderrHandle
UseStderr returns a StderrHandle providing ink-compatible stderr write controls.
func (StderrHandle) Write ¶
func (h StderrHandle) Write(s string)
Write writes text permanently into the terminal scrollback above the inline frame.
type StdoutHandle ¶
type StdoutHandle struct {
// contains filtered or unexported fields
}
StdoutHandle provides access to inline stdout routing and terminal sizing.
func UseStdout ¶
func UseStdout() StdoutHandle
UseStdout returns a StdoutHandle providing ink-compatible stdout write and sizing controls.
func (StdoutHandle) Size ¶
func (h StdoutHandle) Size() geom.Size
Size returns the current terminal viewport size.
func (StdoutHandle) Write ¶
func (h StdoutHandle) Write(s string)
Write writes text permanently into the terminal scrollback above the inline frame.