Help us shape the future of Go! Take the 2026 Go Developer Survey

ui

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package ui implements prettytail's full-screen follow view: a bubbletea program with a scrolling viewport and a one-row status bar. It consumes tail Events, coalesces bursts of activity behind a 100ms debounce and re-renders the whole tail window via the render package so block-structured formats stay correct as the file grows.

Terminal hygiene: bubbletea's alt-screen teardown restores the main screen and cursor on q/ctrl+c and on a normal program end; Run wraps the program so error and signal paths restore too.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Name    string
	Version string
	// Format is the initial format the follow view renders with, resolved
	// by the caller from the file head. The TUI never runs its
	// own initial detection — the first content arrives as an Append, which
	// does not detect — so without this seed the model would fall back to
	// its zero value (Markdown) and mis-render a console/log file until a
	// Reset or `r`. Detector re-runs on Reset/`r`; this seeds the first
	// render.
	Format   detect.Format
	Detector Detector
	Events   <-chan tail.Event
}

Config carries the immutable inputs for a follow session.

type Detector

type Detector func(head []byte) detect.Format

Detector resolves the format from the current content head. The caller (cli) supplies it so --format overrides and the binary guard live in one place; Reset re-runs it so a rotated file changing shape is reclassified.

type Model

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

Model is the bubbletea model for the follow view.

func (Model) Init

func (m Model) Init() tea.Cmd

Init starts the tail pump.

func (Model) Update

func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update handles keys, resize, tail events and the debounce tick.

func (Model) View

func (m Model) View() string

View renders the viewport above the status bar.

type Program

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

Program wraps a bubbletea program so callers can Run it and be sure the terminal is restored on every exit path.

func New

func New(cfg Config, out io.Writer) *Program

New builds a follow-view Program writing to out. Alt-screen and mouse cell-motion (wheel scroll) are enabled per spec §6.

func (*Program) Run

func (p *Program) Run(ctx context.Context) error

Run starts the program and blocks until it exits, always leaving the terminal on the main screen with the cursor visible (spec §6, a hard Accept item). bubbletea's Run defers an internal shutdown that calls restoreTerminalState on EVERY return — clean quit (q/ctrl+c, ctx-driven Quit), runtime error, and recovered panic alike — so the restore is guaranteed the moment Run returns; this wrapper therefore never needs to force a teardown itself (calling Kill after Run has returned would be wrong, not defensive). ctx cancellation (SIGINT/SIGTERM, wired via signal.NotifyContext in cli.run) is bridged to prog.Quit so signal-driven shutdown runs that same graceful teardown.

Jump to

Keyboard shortcuts

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