ui

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HeightCategoryTooSmall   = -1 // <= 30 rows - show modal
	HeightCategorySmall      = 0  // 31-45 rows
	HeightCategoryMedium     = 1  // 46-50 rows
	HeightCategoryLarge      = 2  // 51-64 rows
	HeightCategoryExtraLarge = 3  // >= 65 rows (dynamic sizing)

	// MinTerminalHeight is the minimum terminal height required for ktop
	// Modal shows when height < MinTerminalHeight (i.e., <= 30)
	MinTerminalHeight = 31
)

Height category constants for dynamic layout adjustment

View Source
const (
	DoubleBorderHorizontal  = '═'
	DoubleBorderVertical    = '║'
	DoubleBorderTopLeft     = '╔'
	DoubleBorderTopRight    = '╗'
	DoubleBorderBottomLeft  = '╚'
	DoubleBorderBottomRight = '╝'
)

Double-border Unicode box-drawing characters

Variables

View Source
var Icons = struct {
	// Braille bargraph characters (fractional precision using 8-dot braille)
	// Pattern fills from bottom-left, going up then right: ⡀ ⡄ ⡆ ⡇ ⣇ ⣧ ⣷ ⣿
	BargraphFull     string   // ⣿ - all 8 dots (100% of character)
	BargraphEmpty    string   // ⠀ - blank braille (0% of character)
	BargraphPartials []string // Progressive fill: 1/8 through 7/8
	BargraphLBorder  string
	BargraphRBorder  string
	Factory          string
	Battery          string
	Package          string
	Anchor           string
	Rocket           string
	Thermometer      string
	Sun              string
	Knobs            string
	Drum             string
	M                string
	Plane            string
	Controller       string
	Clock            string
	TrafficLight     string
	// Status icons for visual indicators (using strings for multi-byte emojis)
	Healthy   string
	Error     string
	Warning   string
	Pending   string
	Info      string
	Unknown   string
	Completed string
	// Trend indicators for sparklines (skinny arrows)
	TrendUp   string
	TrendDown string
}{
	BargraphFull:  "⣿",
	BargraphEmpty: "⠀",

	BargraphPartials: []string{"⡀", "⡄", "⡆", "⡇", "⣇", "⣧", "⣷"},
	BargraphLBorder:  "[",
	BargraphRBorder:  "]",
	Factory:          "🏭",
	Battery:          "🔋",
	Package:          "📦",
	Anchor:           "⚓",
	Rocket:           "🚀",
	Thermometer:      "🌡",
	Sun:              "☀",
	Knobs:            "🎛",
	Drum:             "🥁",
	M:                "Ⓜ",
	Plane:            "🛩",
	Controller:       "🛂",
	Clock:            "⏰",
	TrafficLight:     "🚦",

	Healthy:   "✅",
	Error:     "❌",
	Warning:   "⚠️",
	Pending:   "⏳",
	Info:      "ℹ️",
	Unknown:   "⛔️",
	Completed: "✅",

	TrendUp:   "↑",
	TrendDown: "↓",
}
View Source
var Theme = struct {
	// Header colors (used for table column headers)
	HeaderBackground    string
	HeaderForeground    string
	HeaderShortcutKey   string // Color for keyboard shortcut highlighting
	HeaderSortIndicator string // Color for sort arrows (▲/▼)

	// Selection colors
	SelectionBackground string
	SelectionForeground string

	// Status colors
	StatusOK      string
	StatusWarning string
	StatusError   string
	StatusUnknown string
	StatusInfo    string // For informational states

	// Data display colors
	DataPrimary   string // Primary data text
	DataSecondary string // Secondary/dimmed data text
	DataHighlight string // Emphasized data

	// Graph/meter colors
	GraphLow    string // For low usage (0-50%)
	GraphMedium string // For medium usage (50-90%)
	GraphHigh   string // For high usage (90-100%)

	// Border and separator colors
	BorderColor    string
	SeparatorColor string

	// Resource usage thresholds and colors
	ResourceLowThreshold    float64 // 0-70%
	ResourceMediumThreshold float64 // 70-90%
	ResourceHighThreshold   float64 // 90-100%
	ResourceLowColor        string
	ResourceMediumColor     string
	ResourceHighColor       string

	// Restart count thresholds and colors
	RestartsLowThreshold    int // 0-2
	RestartsMediumThreshold int // 3-9
	RestartsHighThreshold   int // 10+
	RestartsLowColor        string
	RestartsMediumColor     string
	RestartsHighColor       string

	// Sparkline colors (single-line uses 2 colors, multi-line uses 3)
	SparklineNormal    string  // Normal/low usage (olivedrab)
	SparklineMedium    string  // Medium usage (multi-line only)
	SparklineHigh      string  // High usage (red)
	SparklineEmpty     string  // Zero/empty values (gray)
	SparklineThreshold float64 // Threshold for high color (0.70 = 70%)

	// Trend arrow colors (↑/↓)
	TrendNormalColor   string  // Normal color for trend arrows (olivedrab)
	TrendHighColor     string  // Color when percentage >= 80% (red)
	TrendThreshold     float64 // Percentage change threshold (0.05 = 5%)
	TrendHighThreshold float64 // Percentage threshold for red arrow (0.80 = 80%)

	// Panel focus colors
	FocusBorderColor   string // Border color when panel is focused (yellow)
	UnfocusBorderColor string // Border color when panel is unfocused (white)
}{

	HeaderBackground:    "darkcyan",
	HeaderForeground:    "white",
	HeaderShortcutKey:   "orange",
	HeaderSortIndicator: "white",

	SelectionBackground: "lightgray",
	SelectionForeground: "black",

	StatusOK:      "olivedrab",
	StatusWarning: "yellow",
	StatusError:   "red",
	StatusUnknown: "gray",
	StatusInfo:    "cyan",

	DataPrimary:   "yellow",
	DataSecondary: "white",
	DataHighlight: "cyan",

	GraphLow:    "green",
	GraphMedium: "yellow",
	GraphHigh:   "red",

	BorderColor:    "white",
	SeparatorColor: "gray",

	ResourceLowThreshold:    70.0,
	ResourceMediumThreshold: 90.0,
	ResourceHighThreshold:   100.0,
	ResourceLowColor:        "green",
	ResourceMediumColor:     "yellow",
	ResourceHighColor:       "red",

	RestartsLowThreshold:    2,
	RestartsMediumThreshold: 9,
	RestartsHighThreshold:   10,
	RestartsLowColor:        "green",
	RestartsMediumColor:     "yellow",
	RestartsHighColor:       "red",

	SparklineNormal:    "olivedrab",
	SparklineMedium:    "yellow",
	SparklineHigh:      "red",
	SparklineEmpty:     "gray",
	SparklineThreshold: 0.70,

	TrendNormalColor:   "olivedrab",
	TrendHighColor:     "red",
	TrendThreshold:     0.05,
	TrendHighThreshold: 0.80,

	FocusBorderColor:   "dodgerblue",
	UnfocusBorderColor: "lightgray",
}

Theme contains all color and style constants for the ktop UI This allows for centralized theming and easy color customization

Functions

func BarGraph

func BarGraph(scale int, ratio Ratio, colors ColorKeys) string

BarGraph returns a colorized string using braille characters with fractional precision. Each character position can show 8 levels of fill (using braille dot patterns), giving much finer granularity than simple filled/empty blocks. Colors provide key mapping to colorize the graph based on the value of ratio.

func DrawDoubleBorder added in v0.5.0

func DrawDoubleBorder(screen tcell.Screen, x, y, width, height int, color tcell.Color)

DrawDoubleBorder draws a double-line border around the given rectangle

func FocusBorderColor added in v0.5.0

func FocusBorderColor() tcell.Color

FocusBorderColor returns the tcell color for focused panels

func FormatBytes added in v0.5.0

func FormatBytes(bytes int64) string

FormatBytes formats bytes as human-readable (e.g., "1.2G") Uses K/M/G suffixes for compact display

func FormatBytesRate added in v0.5.0

func FormatBytesRate(bytesPerSec float64) string

FormatBytesRate formats bytes/sec as human-readable (e.g., "1.2M/s") Uses K/M/G suffixes for compact display

func FormatMemory added in v0.5.0

func FormatMemory(qty *resource.Quantity) string

FormatMemory formats a memory quantity in the most appropriate unit (Mi or Gi) Uses Gi only when >= 10Gi to match kubectl behavior, otherwise uses Mi Returns fixed-width string for consistent column alignment

func FormatShortcut added in v0.5.0

func FormatShortcut(key, action string) string

FormatShortcut formats a single shortcut for display (utility function)

func FormatTag added in v0.5.0

func FormatTag(foreground, background, attributes string) string

FormatTag returns a tview color/style tag string Usage: FormatTag(Theme.HeaderShortcutKey, "", "b") returns "[orange::b]"

func GetHeightCategory added in v0.5.0

func GetHeightCategory(height int) int

GetHeightCategory returns the height category for a given terminal height

func GetReadyColor added in v0.5.0

func GetReadyColor(ready, total int) string

GetReadyColor returns color based on ready/total ratio As containers drift from ready state, color shifts toward red

func GetResourcePercentageColor added in v0.5.0

func GetResourcePercentageColor(percentage float64) string

GetResourcePercentageColor returns color based on resource usage percentage Uses same 2-color scheme as sparklines for consistency (olivedrab < 70%, red >= 70%)

func GetRestartsColor added in v0.5.0

func GetRestartsColor(restarts int) string

GetRestartsColor returns color based on restart count thresholds

func GetRowColorForStatus added in v0.5.0

func GetRowColorForStatus(status string, resourceType string) tcell.Color

GetRowColorForStatus returns the tcell.Color for an entire row based on resource status Healthy resources get default yellow text, unhealthy resources get their status color

func GetStatusColor added in v0.5.0

func GetStatusColor(status string, resourceType string) string

GetStatusColor returns the appropriate color for a given status resourceType can be "node" or "pod"

func GetStatusIcon added in v0.5.0

func GetStatusIcon(status string, resourceType string) string

GetStatusIcon returns the appropriate icon for a given status resourceType can be "node" or "pod"

func GetTcellColor added in v0.5.0

func GetTcellColor(color string) tcell.Color

GetTcellColor converts a theme color string to tcell.Color

func GetTerminalHeight added in v0.5.0

func GetTerminalHeight(root RectGetter) int

GetTerminalHeight returns the terminal height from a primitive's GetRect Returns 50 (medium default) if the primitive is nil or not yet rendered

func HistoryToValues added in v0.5.0

func HistoryToValues(history *metrics.ResourceHistory) []float64

HistoryToValues extracts float64 values from ResourceHistory

func IsBelowMinHeight added in v0.5.0

func IsBelowMinHeight(height int) bool

IsBelowMinHeight returns true if the terminal height is below minimum

func NewToast added in v0.5.0

func NewToast(message string, level ToastLevel) *tview.Modal

NewToast creates a styled tview.Modal for toast notifications (no buttons) If a callback is provided, ESC key will trigger it with "Quit"

func NewToastWithButtons added in v0.5.0

func NewToastWithButtons(message string, level ToastLevel, buttons []string, callback ToastCallback) *tview.Modal

NewToastWithButtons creates a modal toast with buttons The callback is called with the button label when any button is pressed ESC key triggers "Quit" callback if Quit button exists, otherwise dismisses

func NewToastWithEscHandler added in v0.5.0

func NewToastWithEscHandler(message string, level ToastLevel, callback ToastCallback) *tview.Modal

NewToastWithEscHandler creates a toast that handles ESC key to quit

func ResetTag added in v0.5.0

func ResetTag(resetForeground, resetBackground, resetAttributes bool) string

ResetTag returns a tview reset tag that resets to default colors Optionally specify which fields to reset: foreground, background, attributes

func SetBoxFocused added in v0.5.0

func SetBoxFocused(box *tview.Box, focused bool)

SetBoxFocused applies focus styling to a tview.Box (or any type that embeds it) Focused: yellow border color (double-border effect via styling) Unfocused: white border color

func SetFlexFocused added in v0.5.0

func SetFlexFocused(flex *tview.Flex, focused bool)

SetFlexFocused applies focus styling to a tview.Flex container Uses border color change for focus indication Note: Double-border via SetDrawFunc was removed as it overwrites the panel title

func SetTableFocused added in v0.5.0

func SetTableFocused(table *tview.Table, focused bool)

SetTableFocused applies focus styling to a tview.Table

func SparkGraph added in v0.5.0

func SparkGraph(width int, history *metrics.ResourceHistory, ratio Ratio, colors ColorKeys) string

SparkGraph renders a sparkline graph that replaces BarGraph. It shows historical data if available, otherwise shows empty graph. Data flows right-to-left: oldest data on left, newest on right. Width is in characters (like BarGraph scale). The ratio parameter is the current percentage (0-1) and is used to derive the scale so that bar heights reflect actual percentages (not relative to history max). Returns a colored string (caller should wrap in [ ] brackets).

func SparkGraphTrend added in v0.5.0

func SparkGraphTrend(history *metrics.ResourceHistory) string

SparkGraphTrend returns a trend indicator for the given history Uses 0 as percentage since historical data doesn't have current percentage context

func Truncate added in v0.5.0

func Truncate(s string, max int) string

Truncate truncates a string to max length, adding "..." if truncated

func UnfocusBorderColor added in v0.5.0

func UnfocusBorderColor() tcell.Color

UnfocusBorderColor returns the tcell color for unfocused panels

Types

type ColorKeys

type ColorKeys map[int]string

ColorKeys represents color gradients mapping of a percentage value (expressed as integer i.e. 20 for 20%) to a color.

func ColorKeysFromSlice

func ColorKeysFromSlice(colors []string) ColorKeys

ColorKeysFromSlice automatically builds a color key mapping by equally dividing the slice items into a key value. For instance, []string{"green", "yellow", "red"} returns ColorKeys{33:"green",66:"yellow",100:"red"}

func DefaultColorKeys added in v0.5.0

func DefaultColorKeys() ColorKeys

DefaultColorKeys returns standard color thresholds for sparklines.

func (ColorKeys) Keys

func (ck ColorKeys) Keys() []int

Keys returns a ascending sorted slice of color keys

type ContainerDetailContext added in v0.5.0

type ContainerDetailContext struct {
	FocusedPanel string // "detail" or "logs"
}

ContainerDetailContext provides footer items for Container Detail page

func (ContainerDetailContext) GetItems added in v0.5.0

func (c ContainerDetailContext) GetItems() []FooterItem

GetItems returns footer items based on focused panel

type EscapablePanel added in v0.5.0

type EscapablePanel interface {
	// HasEscapableState returns true if the panel has state that ESC should clear
	// (e.g., active filter, edit mode, selection)
	HasEscapableState() bool
	// HandleEscape handles ESC key press - clears state and returns true if handled
	HandleEscape() bool
}

EscapablePanel is an optional interface that panels can implement to indicate they have state that ESC should clear before quitting the app

type FilterState added in v0.5.0

type FilterState struct {
	Active    bool   // Filter is confirmed and active
	Editing   bool   // Currently typing in filter
	Text      string // Current filter text
	TotalRows int    // Total rows before filtering
	MatchRows int    // Rows matching filter
}

FilterState manages text filtering for a panel

func (*FilterState) AppendChar added in v0.5.0

func (f *FilterState) AppendChar(ch rune)

AppendChar adds a character to the filter text

func (*FilterState) Cancel added in v0.5.0

func (f *FilterState) Cancel()

Cancel exits editing mode

func (*FilterState) Clear added in v0.5.0

func (f *FilterState) Clear()

Clear resets the filter state completely

func (*FilterState) Confirm added in v0.5.0

func (f *FilterState) Confirm()

Confirm finalizes the filter

func (*FilterState) FormatTitle added in v0.5.0

func (f *FilterState) FormatTitle(baseTitle, icon string) string

FormatTitle formats a panel title with filter state indicator baseTitle: the panel name (e.g., "Nodes", "Pods") icon: the panel icon Returns formatted title string

func (*FilterState) FormatTitleWithScroll added in v0.5.0

func (f *FilterState) FormatTitleWithScroll(baseTitle, icon string, firstVisible, lastVisible, totalRows int, scrollIndicator, disconnectedSuffix string) string

FormatTitleWithScroll formats a panel title with filter state and scroll indicators

func (*FilterState) HandleBackspace added in v0.5.0

func (f *FilterState) HandleBackspace() bool

HandleBackspace removes the last character from the filter text

func (*FilterState) HasEscapableState added in v0.5.0

func (f *FilterState) HasEscapableState() bool

HasEscapableState returns true if there's state that ESC should clear (either editing mode or active filter)

func (*FilterState) IsFiltering added in v0.5.0

func (f *FilterState) IsFiltering() bool

IsFiltering returns true if filter is active or being edited

func (*FilterState) MatchesRow added in v0.5.0

func (f *FilterState) MatchesRow(cells []string) bool

MatchesRow checks if any cell in the row contains the filter text (case-insensitive)

func (*FilterState) StartEditing added in v0.5.0

func (f *FilterState) StartEditing()

StartEditing begins filter input mode

type FocusablePanel added in v0.5.0

type FocusablePanel interface {
	// SetFocused updates the panel's visual state for focus
	SetFocused(focused bool)
}

FocusablePanel is an optional interface that panels can implement to support visual focus indication with double-border and color change

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

Footer creates and manages the navigation footer

func NewFooter added in v0.5.0

func NewFooter() *Footer

NewFooter creates a new footer component with border

func (*Footer) GetView added in v0.5.0

func (f *Footer) GetView() tview.Primitive

GetView returns the underlying tview primitive (bordered container)

func (*Footer) SetContext added in v0.5.0

func (f *Footer) SetContext(ctx FooterContext)

SetContext updates the footer with new context and re-renders

type FooterContext added in v0.5.0

type FooterContext interface {
	GetItems() []FooterItem
}

FooterContext defines the interface for footer content providers

type FooterItem added in v0.5.0

type FooterItem struct {
	Key    string // e.g., "Tab", "ESC", "↑↓"
	Action string // e.g., "Next", "Back", "Navigate"
}

FooterItem represents a single keyboard shortcut in the footer

type NodeDetailContext added in v0.5.0

type NodeDetailContext struct {
	FocusedPanel string // "events", "pods"
}

NodeDetailContext provides footer items for Node Detail page

func (NodeDetailContext) GetItems added in v0.5.0

func (c NodeDetailContext) GetItems() []FooterItem

GetItems returns footer items based on focused panel

type OverviewContext added in v0.5.0

type OverviewContext struct {
	FocusedPanel string // "header", "summary", "nodes", "pods"
}

OverviewContext provides footer items for Overview page panels

func (OverviewContext) GetItems added in v0.5.0

func (c OverviewContext) GetItems() []FooterItem

GetItems returns footer items based on focused panel

type Panel

type Panel interface {
	Layout(data interface{})
	DrawHeader(data interface{})
	// TODO add context to DrawXXX methods
	DrawBody(data interface{})
	DrawFooter(param interface{})
	Clear()
	GetTitle() string
	GetRootView() tview.Primitive
	GetChildrenViews() []tview.Primitive
}

type PanelController added in v0.1.0

type PanelController interface {
	Panel
	Run(context.Context) error
}

type PodDetailContext added in v0.5.0

type PodDetailContext struct {
	FocusedPanel string // "events", "containers", "volumes"
}

PodDetailContext provides footer items for Pod Detail page

func (PodDetailContext) GetItems added in v0.5.0

func (c PodDetailContext) GetItems() []FooterItem

GetItems returns footer items based on focused panel

type Ratio

type Ratio float64

Ratio float64 type used to represents ratio values

func GetRatio

func GetRatio(val0, val1 float64) Ratio

GetRatio returns a ration between val0/val1. If val <= 0, it return 0.

type RectGetter added in v0.5.0

type RectGetter interface {
	GetRect() (x, y, width, height int)
}

RectGetter is an interface for types that can provide their dimensions

type SparkStyle added in v0.5.0

type SparkStyle int

SparkStyle defines the rendering style for sparklines

const (
	// SparkStyleBar renders histogram bars from bottom up
	SparkStyleBar SparkStyle = iota
	// SparkStyleLine renders a connected line graph (future)
	SparkStyleLine
	// SparkStyleArea renders filled area under line (future)
	SparkStyleArea
)

type Sparkline added in v0.5.0

type Sparkline struct {
	*tview.Box
	// contains filtered or unexported fields
}

Sparkline is a tview primitive that displays a sparkline chart. It embeds tview.Box and maintains internal state for smooth animation.

func NewSparkline added in v0.5.0

func NewSparkline() *Sparkline

NewSparkline creates a new sparkline primitive.

func (*Sparkline) Clear added in v0.5.0

func (s *Sparkline) Clear() *Sparkline

Clear resets all values to zero.

func (*Sparkline) Draw added in v0.5.0

func (s *Sparkline) Draw(screen tcell.Screen)

Draw implements tview.Primitive. Like tview's Table and TextArea, this method adapts to container dimensions.

func (*Sparkline) Height added in v0.5.0

func (s *Sparkline) Height() int

Height returns the current sparkline height (rows).

func (*Sparkline) Push added in v0.5.0

func (s *Sparkline) Push(value float64) *Sparkline

Push adds a new value (0.0 to 1.0), shifting old values left.

func (*Sparkline) RenderText added in v0.5.0

func (s *Sparkline) RenderText() string

RenderText returns the sparkline as a colored string for inline use (e.g., table cells).

func (*Sparkline) Resize added in v0.5.0

func (s *Sparkline) Resize(width int) *Sparkline

Resize changes the sparkline width (number of data points).

func (*Sparkline) SetBorder added in v0.5.0

func (s *Sparkline) SetBorder(show bool) *Sparkline

SetBorder enables/disables the border (chainable, returns *Sparkline).

func (*Sparkline) SetBorderColor added in v0.5.0

func (s *Sparkline) SetBorderColor(color tcell.Color) *Sparkline

SetBorderColor sets the border color (chainable, returns *Sparkline).

func (*Sparkline) SetColorKeys added in v0.5.0

func (s *Sparkline) SetColorKeys(colors ColorKeys) *Sparkline

SetColorKeys sets the color thresholds.

func (*Sparkline) SetDimensions added in v0.5.0

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

SetDimensions sets the sparkline data dimensions (width = data points, height = rows).

func (*Sparkline) SetTitle added in v0.5.0

func (s *Sparkline) SetTitle(title string) *Sparkline

SetTitle sets the panel title (chainable, returns *Sparkline).

func (*Sparkline) SetTitleAlign added in v0.5.0

func (s *Sparkline) SetTitleAlign(align int) *Sparkline

SetTitleAlign sets the title alignment (chainable, returns *Sparkline).

func (*Sparkline) TrendIndicator added in v0.5.0

func (s *Sparkline) TrendIndicator(percent float64) string

TrendIndicator returns trend arrow for the given percentage.

func (*Sparkline) Width added in v0.5.0

func (s *Sparkline) Width() int

Width returns the current sparkline width (data points).

type SparklineRenderer added in v0.5.0

type SparklineRenderer struct {
	// Data points (raw values, will be normalized)
	Data []float64

	// Dimensions
	Width  int // Characters wide (each char = 2 data columns)
	Height int // Text rows tall (each row = 4 dot rows)

	// Appearance
	Colors     ColorKeys  // Color thresholds (reuses existing ColorKeys)
	EmptyColor string     // Color for empty space (default: darkgray)
	Style      SparkStyle // Rendering style

	// Scaling
	Min float64 // Minimum value (auto if 0)
	Max float64 // Maximum value (auto if 0)

	// Optional
	Inverted bool // Flip vertically (high=bad scenarios)
}

SparklineRenderer renders time-series data as a braille-based chart

func NewSparklineRenderer added in v0.5.0

func NewSparklineRenderer(data []float64, width, height int) *SparklineRenderer

NewSparklineRenderer creates a new sparkline renderer with the given data and dimensions

func NewSparklineRendererFromHistory added in v0.5.0

func NewSparklineRendererFromHistory(history *metrics.ResourceHistory, width, height int) *SparklineRenderer

NewSparklineRendererFromHistory creates a sparkline renderer from a ResourceHistory

func (*SparklineRenderer) AddPoint added in v0.5.0

func (s *SparklineRenderer) AddPoint(value float64, maxPoints int)

AddPoint appends a new data point, trimming old if exceeds maxPoints

func (*SparklineRenderer) LastValue added in v0.5.0

func (s *SparklineRenderer) LastValue() float64

LastValue returns the most recent data point

func (*SparklineRenderer) Render added in v0.5.0

func (s *SparklineRenderer) Render() string

Render returns the sparkline as a colored string

func (*SparklineRenderer) TrendIndicator added in v0.5.0

func (s *SparklineRenderer) TrendIndicator(percentage float64) string

TrendIndicator returns a colored trend arrow (↑/↓) or empty string for stable. percentage is used to determine color: red if >= 80%, white otherwise. Returns empty string when trend is stable or there's insufficient data.

type SparklineRow added in v0.5.0

type SparklineRow struct {
	*tview.Box
	// contains filtered or unexported fields
}

SparklineRow displays multiple sparklines in a horizontal row. Used for CPU/MEM (and optionally NET/DISK in prometheus mode). Each Sparkline is self-sizing and adapts to its container during Draw().

func NewSparklineRow added in v0.5.0

func NewSparklineRow(prometheusMode bool) *SparklineRow

NewSparklineRow creates a row of metric sparklines.

func (*SparklineRow) CPUTrend added in v0.5.0

func (r *SparklineRow) CPUTrend(percent float64) string

CPUTrend returns CPU trend indicator.

func (*SparklineRow) Draw added in v0.5.0

func (r *SparklineRow) Draw(screen tcell.Screen)

Draw implements tview.Primitive.

func (*SparklineRow) IsPrometheusMode added in v0.5.0

func (r *SparklineRow) IsPrometheusMode() bool

IsPrometheusMode returns whether prometheus mode is enabled.

func (*SparklineRow) MEMTrend added in v0.5.0

func (r *SparklineRow) MEMTrend(percent float64) string

MEMTrend returns memory trend indicator.

func (*SparklineRow) NumColumns added in v0.5.0

func (r *SparklineRow) NumColumns() int

NumColumns returns number of sparkline columns (2 or 4).

func (*SparklineRow) Reset added in v0.5.0

func (r *SparklineRow) Reset()

Reset clears all sparklines.

func (*SparklineRow) SetPrometheusMode added in v0.5.0

func (r *SparklineRow) SetPrometheusMode(enabled bool) *SparklineRow

SetPrometheusMode changes whether NET/DISK sparklines are shown.

func (*SparklineRow) UpdateCPU added in v0.5.0

func (r *SparklineRow) UpdateCPU(ratio float64, title string)

UpdateCPU pushes CPU ratio and updates title.

func (*SparklineRow) UpdateDisk added in v0.5.0

func (r *SparklineRow) UpdateDisk(ratio float64, title string)

UpdateDisk pushes disk ratio and updates title (prometheus mode only).

func (*SparklineRow) UpdateMEM added in v0.5.0

func (r *SparklineRow) UpdateMEM(ratio float64, title string)

UpdateMEM pushes memory ratio and updates title.

func (*SparklineRow) UpdateNET added in v0.5.0

func (r *SparklineRow) UpdateNET(ratio float64, title string)

UpdateNET pushes network ratio and updates title (prometheus mode only).

type SparklineState added in v0.5.0

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

SparklineState maintains a sliding window buffer for smooth sparkline animation. Instead of re-querying history each render, this maintains its own state and new values are pushed in, causing old values to slide left.

func NewSparklineState added in v0.5.0

func NewSparklineState(width int, colors ColorKeys) *SparklineState

NewSparklineState creates a new stateful sparkline with the given width. All values start at 0 (gray baseline). Uses block characters by default for better resolution at low values.

func NewSparklineStateWithHeight added in v0.5.0

func NewSparklineStateWithHeight(width, height int, colors ColorKeys) *SparklineState

NewSparklineStateWithHeight creates a multi-line stateful sparkline. Height > 1 enables multi-row rendering with stacked blocks.

func (*SparklineState) Clear added in v0.5.0

func (s *SparklineState) Clear()

Clear resets all values to zero

func (*SparklineState) Height added in v0.5.0

func (s *SparklineState) Height() int

Height returns the current height of the sparkline

func (*SparklineState) Push added in v0.5.0

func (s *SparklineState) Push(value float64)

Push adds a new value (0.0 to 1.0) to the right, shifting all values left. The oldest value (leftmost) is discarded.

func (*SparklineState) Render added in v0.5.0

func (s *SparklineState) Render() string

Render returns the sparkline as a colored string. For single-line (height=1): each character represents one value with variable height. For multi-line (height>1): returns multiple lines separated by \n, bars stack vertically.

func (*SparklineState) RenderBottomAligned added in v0.5.0

func (s *SparklineState) RenderBottomAligned(totalHeight int) string

RenderBottomAligned returns the sparkline padded to totalHeight with empty lines at top. This makes the sparkline appear bottom-aligned within a container of totalHeight rows. If totalHeight <= s.height, behaves the same as Render().

func (*SparklineState) Resize added in v0.5.0

func (s *SparklineState) Resize(newWidth int)

Resize changes the sparkline width, preserving recent data. When width increases: old data stays right-aligned, zeros pad on left. When width decreases: old data truncated from left, recent data preserved.

func (*SparklineState) SetStyle added in v0.5.0

func (s *SparklineState) SetStyle(style SparklineStyle)

SetStyle changes the rendering style (braille or block characters)

func (*SparklineState) TrendIndicator added in v0.5.0

func (s *SparklineState) TrendIndicator(percentage float64) string

TrendIndicator returns a colored trend arrow (↑/↓) or empty string for stable. Compares first 20% of buffer to last 20% to determine trend direction. percentage is used to determine color: red if >= 80%, white otherwise. Returns empty string when trend is stable or there's insufficient data.

func (*SparklineState) Values added in v0.5.0

func (s *SparklineState) Values() []float64

Values returns a copy of the current values (for debugging/testing)

func (*SparklineState) Width added in v0.5.0

func (s *SparklineState) Width() int

Width returns the sparkline width

type SparklineStyle added in v0.5.0

type SparklineStyle int

SparklineStyle defines the character set used for rendering

const (
	// SparklineStyleBraille uses braille characters (4 levels)
	SparklineStyleBraille SparklineStyle = iota
	// SparklineStyleBlock uses block characters (8 levels)
	SparklineStyleBlock
)

type Toast added in v0.5.0

type Toast struct {
	Message  string
	Level    ToastLevel
	Duration time.Duration
	Expires  time.Time
}

Toast represents a temporary notification message with expiration

type ToastCallback added in v0.5.0

type ToastCallback func(buttonLabel string)

ToastCallback is called when a button is pressed on the toast buttonLabel is the text of the button that was pressed

type ToastLevel added in v0.5.0

type ToastLevel int

ToastLevel defines the severity level of a toast notification

const (
	ToastInfo ToastLevel = iota
	ToastSuccess
	ToastWarning
	ToastError
)

type ToastManager added in v0.5.0

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

ToastManager handles toast notification display and lifecycle

func NewToastManager added in v0.5.0

func NewToastManager() *ToastManager

NewToastManager creates a new toast manager

func (*ToastManager) Clear added in v0.5.0

func (t *ToastManager) Clear()

Clear removes the current toast immediately

func (*ToastManager) GetActive added in v0.5.0

func (t *ToastManager) GetActive() *Toast

GetActive returns the currently active toast, or nil if expired/none

func (*ToastManager) HasActive added in v0.5.0

func (t *ToastManager) HasActive() bool

HasActive returns true if there's an active (non-expired) toast

func (*ToastManager) Show added in v0.5.0

func (t *ToastManager) Show(message string, level ToastLevel, duration time.Duration)

Show displays a toast message for the specified duration

func (*ToastManager) ShowError added in v0.5.0

func (t *ToastManager) ShowError(message string, duration time.Duration)

ShowError displays an error toast

func (*ToastManager) ShowInfo added in v0.5.0

func (t *ToastManager) ShowInfo(message string, duration time.Duration)

ShowInfo displays an info toast

func (*ToastManager) ShowSuccess added in v0.5.0

func (t *ToastManager) ShowSuccess(message string, duration time.Duration)

ShowSuccess displays a success toast

func (*ToastManager) ShowWarning added in v0.5.0

func (t *ToastManager) ShowWarning(message string, duration time.Duration)

ShowWarning displays a warning toast

Jump to

Keyboard shortcuts

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