ui

package
v0.0.0-...-9759625 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package ui defines the shared tab contract and helpers used by all wrongtop tabs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BorderFor

func BorderFor(name string) lipgloss.Border

BorderFor resolves the configured panel corner style: "square" gives btop's sharp corners, "thick"/"double" the heavy ruled sets, anything else the rounded default.

func Box

func Box(border lipgloss.Border, boxStyle, charStyle, titleStyle lipgloss.Style, title, right, content string) string

Box draws content inside a border with the title embedded at the left of the top border line and an optional pre-styled live value flush right — the same chrome the grid Frame gives its panels. charStyle colors the border runes themselves (a color-only style — passing the bordered style here would recursively box the border characters).

func ClickedRowIndex

func ClickedRowIndex(t table.Model, viewportRow int) int

ClickedRowIndex maps a mouse click on a bubbles table to the index of the data row displayed viewportRow lines below the header. The table keeps its scroll offset private, so rows are located by content instead: cells render truncated and space-padded to the column width, which lets us reproduce each row's first cell and match it against the ANSI-stripped clicked line — correct no matter how far the table has scrolled. Returns -1 when the click misses every row.

func EnsureRowVisible

func EnsureRowVisible(t *table.Model, idx int)

EnsureRowVisible scrolls the table so the row at data index idx is on screen, without moving the selection. Bubbles' SetCursor re-renders the viewport content around the cursor but never adjusts its scroll offset, so a restored selection can silently end up just off-screen. The check scans the displayed lines; the fix jumps to the row btop-style, pinned to the bottom edge.

func Frame

func Frame(panels []Panel, border lipgloss.Style, corners lipgloss.Border) string

Frame renders panels inside one connected border grid. Adjacent panel borders coincide, junctions resolve into the proper box-drawing characters (├ ┤ ┬ ┴) and corners come from the given border set (rounded ╭╮╰╯ or square ┌┐└┘). Content that is smaller than its panel is padded with spaces; overflow is truncated. Panels with their own Border style color their border cells individually — where two colors meet, the later panel in the slice wins. The outer size is exactly the union of the panel rectangles.

func Icon

func Icon(name string, nerd bool) string

Icon returns the glyph for a named UI role. Unknown names yield "".

func SetTableColumns

func SetTableColumns(t *table.Model, cols []table.Column)

SetTableColumns replaces a bubbles table's columns without the resize panic: the viewport renderer indexes row cells by column count, so a count change while old rows are still in place crashes (index out of range in renderRow). Rows are cleared whenever the column count changes; the caller must rebuild them right after — every tab does, from its latest snapshot.

func Shadow

func Shadow(box string, dim lipgloss.Style) string

Shadow adds a btop-style drop shadow under a rendered box: two dim shade columns on the right and a dim shade row underneath. The box lines may carry ANSI styling; they are padded to a common width first so the shadow edge stays straight.

func StripANSI

func StripANSI(s string) string

StripANSI removes ANSI escape sequences (CSI and OSC) from s so that rendered rows can be matched against plain text.

func Trunc

func Trunc(s string, w int) string

Trunc shortens s to at most w runes plus an ellipsis, cutting at rune boundaries so multi-byte names stay valid UTF-8.

Types

type Panel

type Panel struct {
	X, Y, W, H int
	Title      string
	TitleStyle lipgloss.Style
	// Right is a pre-styled live value (e.g. "47.2% · 45°C") spliced
	// right-aligned into the top border line — the btop panel readout.
	Right string
	// Border colors this panel's border cells individually; nil falls
	// back to the Frame-wide border style.
	Border *lipgloss.Style
	Lines  []string // content lines, exactly W-2 cells wide each
}

Panel is one titled region of a Frame. Rectangles are inclusive border coordinates: a panel's right border column may be the next panel's left border column, in which case the two share that divider line — the btop-style connected look.

type Tab

type Tab interface {
	// Title is the label shown in the tab bar.
	Title() string
	// SetSize receives the current content area dimensions on startup
	// and on every terminal resize.
	SetSize(width, height int)
	// Update handles a message and may return a command.
	Update(msg tea.Msg) tea.Cmd
	// View renders the tab inside the content area.
	View() string
	// SetTheme swaps the color theme without losing tab state.
	SetTheme(th *theme.Theme)
	// SetVisible marks the tab as the active one. Snapshots still reach
	// hidden tabs (history buffers stay warm), but heavy per-snapshot
	// work — table rebuilds above all — may be skipped while hidden,
	// provided SetVisible(true) catches up from the latest data.
	SetVisible(visible bool)
}

Tab is a single page of the wrongtop UI. The root model forwards messages to tabs; tabs keep their own state (history buffers, cursor position, selection) so switching tabs is lossless.

Directories

Path Synopsis
Package canvas draws time-series graphs with braille characters, btop-style: 4 dot rows and 2 dot columns packed per terminal cell.
Package canvas draws time-series graphs with braille characters, btop-style: 4 dot rows and 2 dot columns packed per terminal cell.
Package conns renders the connections tab: the live TCP table, live traffic first, with per-state coloring and best-effort process names.
Package conns renders the connections tab: the live TCP table, live traffic first, with per-state coloring and best-effort process names.
Package dashboard renders the wrongtop overview tab: a btop-style single-screen grid of host, CPU, memory, network, disk and top-process panels.
Package dashboard renders the wrongtop overview tab: a btop-style single-screen grid of host, CPU, memory, network, disk and top-process panels.
Package disks renders the disks tab: filesystem usage and per-device I/O rates.
Package disks renders the disks tab: filesystem usage and per-device I/O rates.
Package docker renders the Docker tab: container list with live stats, lifecycle actions and a follow-mode log viewer.
Package docker renders the Docker tab: container list with live stats, lifecycle actions and a follow-mode log viewer.
Package network renders the network tab: per-interface traffic rates and totals.
Package network renders the network tab: per-interface traffic rates and totals.
Package processes renders the process table tab: sortable, filterable, flat or tree view, with a signal picker behind a confirmation prompt.
Package processes renders the process table tab: sortable, filterable, flat or tree view, with a signal picker behind a confirmation prompt.
Package sensors renders the sensors tab: rolling temperature graphs, fan speeds and battery state — everything the platform reports about its own hardware.
Package sensors renders the sensors tab: rolling temperature graphs, fan speeds and battery state — everything the platform reports about its own hardware.

Jump to

Keyboard shortcuts

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