tui

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

internal/tui/statusbar.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Injector added in v0.5.4

type Injector interface {
	Inject(b []byte) error
}

Writer wraps an io.Writer and adds a status bar at the bottom using a dual-mode approach:

Scroll mode (default): DECSTBM scroll region pins the footer. Output passes through to the real terminal so scrollback works with zero overhead.

Compositor mode: activated when the child process enters alternate screen mode. Output is fed to a VT emulator and the emulator screen is rendered to the real terminal with the footer appended.

Injector forwards bytes the VT emulator generates as replies (e.g., Primary Device Attributes for CSI c, cursor-position reports for CSI 6n, in-band resize notifications) back into the child's input stream so the child sees the responses it queried for.

Compositor mode requires an injector to be wired up via SetInjector; the emulator's reply handlers write into an internal io.Pipe and the reader side MUST be drained or the next reply-bearing handler deadlocks while holding the Writer's mutex, freezing the screen.

type StatusBar

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

StatusBar renders run context at the bottom of the terminal.

func NewStatusBar

func NewStatusBar(runID, name, runtime string) *StatusBar

NewStatusBar creates a status bar with the given run metadata.

func (*StatusBar) ClearMessage

func (s *StatusBar) ClearMessage()

ClearMessage removes any message overlay and restores normal status bar content.

func (*StatusBar) Content

func (s *StatusBar) Content() string

Content returns the status bar content string (with ANSI styling).

func (*StatusBar) Render

func (s *StatusBar) Render() string

Render returns the status bar content with ANSI styling. The caller is responsible for cursor positioning and line clearing.

func (*StatusBar) SetDimensions

func (s *StatusBar) SetDimensions(width, height int)

SetDimensions sets terminal width and height.

func (*StatusBar) SetGrants

func (s *StatusBar) SetGrants(grants []string)

SetGrants sets the granted credentials to display.

func (*StatusBar) SetMessage

func (s *StatusBar) SetMessage(msg string)

SetMessage sets a temporary message overlay that replaces the normal status bar content. This is useful for displaying context-sensitive information like escape sequence hints. Call ClearMessage() to restore normal status display.

func (*StatusBar) SetWarning added in v0.3.0

func (s *StatusBar) SetWarning(warning string)

SetWarning sets a persistent warning shown in the status bar (e.g. "proxy stale").

type Writer

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

Writer is goroutine-safe for all methods.

func NewWriter

func NewWriter(w io.Writer, bar *StatusBar, runtime string) *Writer

NewWriter creates a Writer that composites container output with a status bar. The runtime parameter should be "apple" or "docker" to enable runtime-specific behavior (e.g., detecting Apple container CLI's ready marker).

func (*Writer) Cleanup

func (w *Writer) Cleanup() error

Cleanup resets the terminal state.

func (*Writer) ClearMessage

func (w *Writer) ClearMessage()

ClearMessage removes any message overlay and restores normal status display.

func (*Writer) Reset added in v0.5.1

func (w *Writer) Reset() error

Reset attempts to recover the terminal from a corrupted state. It exits alternate screen mode if active, drops the VT emulator, emits a soft terminal reset (DECSTR), clears the screen, and re-establishes the scroll region and footer.

Soft reset (ESC[!p) is used rather than full RIS (ESC c) so the user's scrollback is preserved. The caller is responsible for nudging the child process to redraw (typically via a no-op TTY resize).

Reset is best-effort. If the terminal write fails partway through, internal state (altScreen, emulator, footerTimer, escBuf) has already been cleared, so the Writer is left in a valid scroll-mode initial state from which the caller may retry. The scroll region/footer redraw may not have completed.

func (*Writer) Resize

func (w *Writer) Resize(width, height int) error

Resize updates the terminal dimensions and re-establishes the layout. This must be called on SIGWINCH to maintain the status bar after terminal resize.

func (*Writer) SetInjector added in v0.5.4

func (w *Writer) SetInjector(injector Injector)

SetInjector wires up the destination for VT-emulator-generated replies (Primary DA, cursor-position reports, in-band resize notifications, etc.).

Emulator replies are ALWAYS drained from the emulator regardless of whether an injector is set — that's a strict invariant of compositor mode, otherwise the next reply-bearing handler deadlocks. If no injector is set, drained bytes are discarded, the child's capability queries go unanswered, and the child falls back to defaults.

The drain goroutine captures the injector at compositor-entry time, so SetInjector must be called BEFORE the first byte of container output reaches Write to take effect for the first compositor session. Calls after entry don't affect the in-flight session.

func (*Writer) SetMessage

func (w *Writer) SetMessage(msg string)

SetMessage sets a temporary message overlay on the status bar. This replaces the normal status content until ClearMessage is called.

func (*Writer) Setup

func (w *Writer) Setup() error

Setup initializes the terminal for status bar display using scrolling regions. Sets DECSTBM to create a scrolling region for content (lines 1 to height-1) and pins the status bar at the bottom line.

func (*Writer) SetupEscapeHints

func (w *Writer) SetupEscapeHints(proxy *term.EscapeProxy)

SetupEscapeHints configures the escape proxy to show escape sequence hints in the status bar when Ctrl-/ is pressed.

func (*Writer) UpdateStatus

func (w *Writer) UpdateStatus() error

UpdateStatus updates the status bar content. This is safe to call while the container is running.

func (*Writer) Write

func (w *Writer) Write(p []byte) (n int, err error)

Write processes container output, scanning for alternate screen mode transitions. In scroll mode, output passes through directly. In compositor mode, output is fed to the VT emulator for rendering.

Jump to

Keyboard shortcuts

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