components

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: May 10, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextPicker added in v0.3.0

func ContextPicker(width, height int, contexts []string, selected int, errMsg string) string

ContextPicker renders a centered modal listing available kubeconfig contexts. Used at startup when no current-context is set (or `klens` was pointed at a kubeconfig with multiple contexts and no default), so the user gets a list-pick UX instead of a cryptic "no current-context" error.

The component is purely a renderer — it doesn't own its own selection state because the shell already knows how to wire arrow-key + enter routing against a numeric index. Pass `selected` from the model.

func Help added in v0.3.0

func Help(width, height int, viewTitle string, specs []KeySpec) string

Help renders the help modal centered on a blank canvas (legacy form, kept for the existing test). Prefer `HelpBody` + Overlay for live use.

func HelpBody added in v0.3.0

func HelpBody(viewTitle string, specs []KeySpec) string

HelpBody renders the bordered help modal as an opaque block. The shell then overlays it over the live frame so the user keeps context while reading the keymap. Use `Help` for the legacy place-on-blank-canvas form.

`help.go` lives in `components` (not `layout`) because the views package already depends on both, while `layout` itself depends on `components` — putting the overlay here is the only direction that avoids an import cycle.

func LongestCommonPrefix added in v0.3.0

func LongestCommonPrefix(cmds []Command) string

LongestCommonPrefix returns the longest case-insensitive prefix shared by every command's Name in cmds. Used by Tab-complete in inline ex-mode: if the user types `dep` and only `deployments` matches, Tab fills in the rest. If multiple candidates match, Tab fills in only the shared prefix so the user sees the disambiguation point.

func NSChip added in v0.3.0

func NSChip(ns string) string

NSChip renders a small colored square + namespace name, like the design's namespace dot. The square is "▆" (U+2586). Color comes from theme.NSColorFor.

func NSChipBold added in v0.3.0

func NSChipBold(ns string) string

NSChipBold renders a more prominent variant of NSChip — both square and name in the namespace's color, with the name bolded. Used in the top bar where the namespace is the visual anchor of the screen.

func Overlay added in v0.3.0

func Overlay(base, top string, col, row int) string

Overlay paints `top` over `base` at visual position (col, row), preserving ANSI escape codes on both. `base` and `top` are multi-line strings; rows are line indices (0-based) and cols are visible cells via lipgloss.Width.

Lipgloss has no native cell-coordinate overlay — `Place` blanks the background. We need an actual overlay so the palette / help modal can float above the live table without losing context. This implementation walks each base line, slicing it by visible-cell width via ansi.Truncate and ansi.TruncateLeft so escape sequences carry through correctly.

func Sparkline added in v0.3.0

func Sparkline(samples []float64, width int, color lipgloss.Color) string

Sparkline renders samples as a Unicode-block sparkline of the given character width, colored with `color`. Returns "" for empty samples.

func StatusDot added in v0.3.0

func StatusDot(phase string) string

StatusDot returns just the colored ● glyph (no trailing name) for compact rows.

func StatusPill added in v0.3.0

func StatusPill(phase string) string

StatusPill renders a colored dot ● + the phase name, both colored from theme.StatusStyleFor (Dot for the bullet, Text for the name).

Types

type Align added in v0.3.0

type Align int

Align is the cell alignment mode.

const (
	AlignLeft Align = iota
	AlignRight
)

Alignment values for Align.

type Column

type Column struct {
	Header string
	Width  int
	Align  Align // default Left
	Flex   bool  // when true, the column grows to absorb leftover width
}

Column defines a table column's header and display width. Width is the minimum/baseline; Flex columns absorb any extra horizontal slack the table gets so the content stretches to the table's full assigned width instead of leaving an empty band on the right.

type Command added in v0.3.0

type Command struct {
	Name  string // e.g. "deployments"
	Desc  string // e.g. "list deployments"
	Alias string // e.g. ":dp"
}

Command is one entry in the shell's command vocabulary. Used by both the modal palette (ctrl+p) and the inline ex-mode prompt (`:`), so the two surfaces share a single source of truth for what's runnable.

Name is the canonical spelling typed in the modal palette; Alias is the short form (vim-style `:dp`). Either matches in FilterCommands.

func DefaultCommands added in v0.3.0

func DefaultCommands() []Command

DefaultCommands is the built-in command list — resource jumps, the runtime context switcher, and quit. Adding a new command here makes it reachable from both ctrl+p (modal) and `:` (inline) automatically.

func ExactCommand added in v0.3.0

func ExactCommand(cmds []Command, q string) *Command

ExactCommand returns the command whose Name or Alias matches q exactly, or nil. Used by the inline ex-mode to short-circuit Enter when the user typed an unambiguous key like `q` or `dp`, even if the substring match would have surfaced multiple candidates.

func FilterCommands added in v0.3.0

func FilterCommands(cmds []Command, q string) []Command

FilterCommands returns commands matching q (case-insensitive substring on Name or Alias). Empty q returns the full slice in declaration order so the modal palette has a stable rendering when first opened.

Alias matching is prefix-anchored *after* the leading `:` is stripped — so `dp` finds `:dp` but `p` doesn't match every command whose alias starts with `:p…`. Substring on Name still applies, so typing `de` still surfaces `deployments`.

type Form

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

Form is an immutable key/value editor for secrets and configmaps. All mutation methods return a new Form — safe for Bubble Tea models.

func NewForm

func NewForm(data map[string][]byte) Form

NewForm creates a Form pre-populated from a decoded secret/configmap Data map. The same map is also stashed as the diff baseline.

func (Form) AddRow

func (f Form) AddRow(k, v string) Form

AddRow appends a new row with the given key/value and lands on it in edit mode so the user can fill it in immediately.

func (Form) Data

func (f Form) Data() map[string][]byte

Data exports all non-empty key rows as a map[string][]byte.

func (Form) DeleteSelected

func (f Form) DeleteSelected() Form

DeleteSelected removes the currently selected row.

func (Form) IsDirty

func (f Form) IsDirty() bool

IsDirty reports whether the in-memory data differs from the baseline captured by NewForm/WithOriginal. Computed (not flagged) so reverting a typo back to its original value correctly reports clean.

func (Form) IsHidden

func (f Form) IsHidden(i int) bool

IsHidden reports whether row i is rendered as ••••.

func (Form) Mode added in v0.3.0

func (f Form) Mode() FormMode

Mode exposes the form's current input state.

func (Form) RowCount

func (f Form) RowCount() int

RowCount returns the number of rows currently in the form.

func (Form) SetWidth added in v0.3.0

func (f Form) SetWidth(w int) Form

SetWidth sets the form's content width. Hosts call this from their Table() method so the form fills the focus frame's full width instead of the legacy 72-col default.

func (Form) Update

func (f Form) Update(msg tea.Msg) (Form, tea.Cmd)

Update routes input by mode. Non-key messages reach the active textinput so cursor blinks keep flowing.

func (Form) View

func (f Form) View() string

View renders the editor body, mode-aware.

func (Form) WithName added in v0.3.0

func (f Form) WithName(name string) Form

WithName attaches a label rendered in the status strip ("secret: foo").

func (Form) WithOriginal added in v0.3.0

func (f Form) WithOriginal(data map[string][]byte) Form

WithOriginal swaps the diff baseline. Callers use this after a successful save so subsequent edits compare against the new state.

type FormMode added in v0.3.0

type FormMode int

FormMode is the editor's input state. Three modes — that's the whole state machine.

ModeNav         — j/k navigate, ↵ to edit a row, esc to exit (or
                  open ModeConfirmExit when the form is dirty).
ModeEdit        — the selected row's value field is a textinput; the
                  form captures every keystroke until esc commits and
                  drops back to ModeNav. The value lands in the form's
                  in-memory data; the API write happens on confirm.
ModeConfirmExit — single inline bar at the bottom: `s` save & exit,
                  `d` discard & exit, `esc` cancel back to ModeNav.
const (
	ModeNav FormMode = iota
	ModeEdit
	ModeConfirmExit
)

Mode values for FormMode.

type FormQuitRequestedMsg added in v0.3.0

type FormQuitRequestedMsg struct{}

FormQuitRequestedMsg is emitted when the user picks `d` in ModeConfirmExit (or hits esc on a clean form). The host view drops the form without saving.

type FormSaveRequestedMsg added in v0.3.0

type FormSaveRequestedMsg struct{}

FormSaveRequestedMsg is emitted when the user picks `s` in ModeConfirmExit. The host view persists via its service then closes the form on the SecretSavedMsg / ConfigMapSavedMsg success path.

type KeySpec added in v0.3.0

type KeySpec struct {
	Key   string
	Label string
	Soon  bool
}

KeySpec is one row in the help overlay: a key, what it does, and whether it's wired today. `Soon` keys render dimmed.

type Palette

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

Palette is an immutable command palette component (the modal surface). The inline ex-mode (`:`) doesn't use this — it renders its own one-line suggestion strip and shares only the underlying command list helpers.

func NewPalette

func NewPalette(cmds []Command) Palette

NewPalette creates a Palette. Pass nil for cmds to use DefaultCommands.

func (Palette) Filtered

func (p Palette) Filtered() []Command

Filtered returns commands matching the current input.

func (Palette) MoveDown

func (p Palette) MoveDown() (Palette, tea.Cmd)

MoveDown moves the selection down one row.

func (Palette) MoveUp

func (p Palette) MoveUp() (Palette, tea.Cmd)

MoveUp moves the selection up one row.

func (Palette) Selected

func (p Palette) Selected() *Command

Selected returns the currently highlighted command, or nil if the list is empty.

func (Palette) SetInput

func (p Palette) SetInput(s string) Palette

SetInput sets the filter text directly (used in tests and keyboard shortcuts).

func (Palette) Update

func (p Palette) Update(msg tea.Msg) (Palette, tea.Cmd)

Update handles tea.KeyMsg for input and navigation. Returns updated Palette + Cmd.

func (Palette) View

func (p Palette) View(width int) string

View renders the palette content (not the overlay — the parent renders the overlay).

type PaletteCmd

type PaletteCmd = Command

PaletteCmd is preserved as a name alias for backwards-compatibility with callers/tests that constructed palette entries directly. New code should use components.Command + DefaultCommands / FilterCommands from commands.go.

type Row

type Row []string

Row is a slice of string cells, one per column. Cells may contain pre-rendered ANSI styling (chips, pills, sparklines) — the table preserves it.

type Table

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

Table is an immutable, value-type table component. All mutation methods return a new Table — safe to embed in Bubble Tea models.

func NewTable

func NewTable(cols []Column, rows []Row) Table

NewTable creates a Table with the given columns and initial rows.

func (Table) MoveBottom

func (t Table) MoveBottom() Table

MoveBottom moves the selection to the last row.

func (Table) MoveDown

func (t Table) MoveDown() Table

MoveDown advances the selection by one row, stopping at the last row.

func (Table) MoveTop

func (t Table) MoveTop() Table

MoveTop moves the selection to the first row.

func (Table) MoveUp

func (t Table) MoveUp() Table

MoveUp moves the selection up by one row, stopping at the first row.

func (Table) RowCount

func (t Table) RowCount() int

RowCount returns the total number of rows in the table.

func (Table) SelectedIndex

func (t Table) SelectedIndex() int

SelectedIndex returns the zero-based index of the focused row.

func (Table) SelectedRow

func (t Table) SelectedRow() Row

SelectedRow returns the currently focused Row, or nil if the table is empty.

func (Table) SetHeight added in v0.3.0

func (t Table) SetHeight(h int) Table

SetHeight sets the number of terminal rows allocated to the table.

func (Table) SetRows

func (t Table) SetRows(rows []Row) Table

SetRows replaces the row data and clamps the selection to the new length.

func (Table) SetWidth

func (t Table) SetWidth(w int) Table

SetWidth sets the terminal width allocated to the table.

func (Table) View

func (t Table) View() string

View renders the table to a string, including the header row and selection cursor.

Jump to

Keyboard shortcuts

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