components

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const ToastDuration = 2500 * time.Millisecond

ToastDuration is how long a toast notification is displayed before expiring.

Variables

This section is empty.

Functions

func ContentLineCount

func ContentLineCount(content string) int

ContentLineCount counts the number of lines in a content string (for computing equal panel heights).

func Footer(width int, hints []HintPair) string

Footer renders a horizontal rule followed by a newline and footer hints.

func FooterHints

func FooterHints(hints []HintPair) string

FooterHints renders a row of key-description pairs separated by two spaces.

key desc  key desc  key desc

func FormatPercent

func FormatPercent(percent float64) string

FormatPercent formats a percentage with color based on threshold. Values >= 66.7% are rendered in green; below that in yellow.

func HRule

func HRule(width int) string

HRule renders a full-width horizontal rule in Slate700.

func KV

func KV(label, value string) string

KV renders a single key-value line: label in Slate500 (fixed width 16) and value in Slate200.

func KVBlock

func KVBlock(pairs []KVPair) string

KVBlock renders multiple KV pairs, one per line.

func KVBold

func KVBold(label, value string) string

KVBold renders a key-value line where the value uses Slate100 bold (heading weight).

func KVMuted

func KVMuted(label, value string) string

KVMuted renders a key-value line where both label and value use Slate500 (muted).

func ProgressBar

func ProgressBar(percent float64, width int) string

ProgressBar renders a progress bar with the given percentage (0-1) using bubbles/progress. Filled blocks use theme.Slate200 and empty blocks use theme.Slate700.

func ProgressBarWithLabel

func ProgressBarWithLabel(percent float64, width int, label string) string

ProgressBarWithLabel renders a progress bar with a text label centered inside it.

func Section

func Section(title string, width int) string

Section renders a section heading (bold Slate100) followed by a red accent rule of the given width.

func SectionWithKV

func SectionWithKV(title string, width int, pairs []KVPair) string

SectionWithKV renders a Section heading followed by a KVBlock.

func Sparkline

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

Sparkline renders a mini bar chart from a slice of float64 values. Each value maps to one character column. The color parameter controls the foreground color of the bars. Width limits the number of data points shown (uses the rightmost values if data exceeds width).

func StateTag

func StateTag(state string) string

StateTag renders an inline state tag like │active│ with color-mapped borders. The Unicode box-drawing character │ is used as the border, not a lipgloss rounded border (which would produce a 3-line box).

func StateTagWidth

func StateTagWidth(state string) int

StateTagWidth returns the display width of a state tag for column alignment. The width is the label length plus 2 for the border characters.

func TitledPanel

func TitledPanel(title, content string, width int) string

TitledPanel renders content inside a bordered box with the title embedded in the top border line:

┌─ TITLE ──────────────────┐
│ content line 1            │
│ content line 2            │
└───────────────────────────┘

The width parameter is the outer width including border characters. Content lines are left-padded with 1 space and right-padded to fill.

func TitledPanelHeight

func TitledPanelHeight(title, content string, width, minLines int) string

TitledPanelHeight is like TitledPanel but enforces a minimum number of content lines (minLines). If the content has fewer lines, empty lines are appended so that all panels in a row can be the same height. Pass 0 for minLines to auto-size (no padding).

Types

type Alignment

type Alignment int

Alignment controls how cell text is aligned within a column.

const (
	// AlignLeft pads text on the right.
	AlignLeft Alignment = iota
	// AlignRight pads text on the left.
	AlignRight
)

type CancelMsg

type CancelMsg struct{}

CancelMsg is sent when the user cancels the dialog.

type ConfirmData

type ConfirmData struct {
	Title   string
	Body    string
	Danger  bool   // if true, red border instead of neutral
	Fee     string // e.g., "0.0142 AKT"
	Account string // e.g., "akash1abc...def"
}

ConfirmData holds the content displayed inside the confirmation dialog.

type ConfirmDialog

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

ConfirmDialog is a modal overlay for destructive actions.

func NewConfirmDialog

func NewConfirmDialog(kind ConfirmKind, data ConfirmData) ConfirmDialog

NewConfirmDialog creates a confirmation dialog for the given kind and data.

func (ConfirmDialog) Active

func (d ConfirmDialog) Active() bool

Active returns whether the dialog is currently visible.

func (*ConfirmDialog) Close

func (d *ConfirmDialog) Close()

Close hides the dialog.

func (*ConfirmDialog) Open

func (d *ConfirmDialog) Open()

Open makes the dialog visible and resets focus state.

func (*ConfirmDialog) SetSize

func (d *ConfirmDialog) SetSize(w, h int)

SetSize updates the available terminal dimensions for centering.

func (*ConfirmDialog) Update

func (d *ConfirmDialog) Update(msg tea.Msg) tea.Cmd

Update handles key events while the dialog is active.

func (ConfirmDialog) View

func (d ConfirmDialog) View() string

View renders the dialog as a centered overlay.

type ConfirmKind

type ConfirmKind int

ConfirmKind identifies the type of destructive action being confirmed.

const (
	ConfirmClose      ConfirmKind = iota // close deployment
	ConfirmVote                          // governance vote
	ConfirmDelegate                      // delegate tokens
	ConfirmUnbond                        // unbond tokens
	ConfirmRedelegate                    // redelegate tokens
)

type ConfirmMsg

type ConfirmMsg struct {
	Kind       ConfirmKind
	VoteOption string // "yes","no","abstain","veto" — only for vote variant
	Amount     string // for delegate/unbond variants
}

ConfirmMsg is sent when the user confirms the action.

type HintPair

type HintPair struct {
	Key    string
	Desc   string
	Accent bool
}

HintPair represents a single key-description pair in the footer. When Accent is true the key is rendered in AccentRed instead of the default Slate400.

type KVPair

type KVPair struct {
	Label string
	Value string
}

KVPair holds a label–value pair for rendering in a detail block.

type ResourceTable

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

ResourceTable is a reusable table component for list views. It renders fixed-width columns using fmt.Sprintf("%-*s") to prevent row wrapping.

func NewResourceTable

func NewResourceTable(cfg ResourceTableConfig) ResourceTable

NewResourceTable creates a new ResourceTable with the given configuration.

func (*ResourceTable) ClearFilter

func (t *ResourceTable) ClearFilter()

ClearFilter removes the active filter.

func (*ResourceTable) CursorBottom

func (t *ResourceTable) CursorBottom()

CursorBottom moves the cursor to the last row.

func (*ResourceTable) CursorDown

func (t *ResourceTable) CursorDown()

CursorDown moves the cursor down one row.

func (*ResourceTable) CursorTop

func (t *ResourceTable) CursorTop()

CursorTop moves the cursor to the first row.

func (*ResourceTable) CursorUp

func (t *ResourceTable) CursorUp()

CursorUp moves the cursor up one row.

func (*ResourceTable) FilteredCount

func (t *ResourceTable) FilteredCount() int

FilteredCount returns the number of visible (filtered) rows.

func (*ResourceTable) SelectedIndex

func (t *ResourceTable) SelectedIndex() int

SelectedIndex returns the current cursor position.

func (*ResourceTable) SelectedRow

func (t *ResourceTable) SelectedRow() *TableRow

SelectedRow returns the currently highlighted row, or nil if empty.

func (*ResourceTable) SetFilter

func (t *ResourceTable) SetFilter(query string)

SetFilter sets a case-insensitive substring filter across all cells.

func (*ResourceTable) SetRows

func (t *ResourceTable) SetRows(rows []TableRow)

SetRows replaces the table rows and rebuilds the filtered/sorted view.

func (*ResourceTable) SetSize

func (t *ResourceTable) SetSize(w, h int)

SetSize updates the available width and height for rendering.

func (*ResourceTable) Sort

func (t *ResourceTable) Sort(col int, ascending bool)

Sort sets the sort column and direction, then re-applies filtering and sorting.

func (ResourceTable) View

func (t ResourceTable) View() string

View renders the table as a string.

func (*ResourceTable) Width

func (t *ResourceTable) Width() int

Width returns the current table width.

type ResourceTableConfig

type ResourceTableConfig struct {
	Columns   []TableColumn
	EmptyText string // shown when no rows
}

ResourceTableConfig configures a ResourceTable.

type TableColumn

type TableColumn struct {
	Header     string
	Width      int                       // character width (0 = fill remaining space)
	Align      Alignment                 // left or right alignment
	RenderFunc func(value string) string // optional custom cell renderer (e.g., state tags)
}

TableColumn defines a single column in a ResourceTable.

type TableRow

type TableRow struct {
	Cells []string
	ID    string // optional identifier
}

TableRow holds the cell values for a single row.

type Toast

type Toast struct {
	Message   string
	Tone      ToastTone
	CreatedAt time.Time
}

Toast is a transient notification that auto-dismisses after toastDuration.

func NewToast

func NewToast(message string, tone ToastTone) Toast

NewToast creates a toast stamped with the current time.

func (Toast) Expired

func (t Toast) Expired() bool

Expired reports whether the toast has exceeded its display duration.

func (Toast) View

func (t Toast) View() string

View renders the toast as a rounded box with an icon and message.

type ToastExpiredMsg

type ToastExpiredMsg struct{}

ToastExpiredMsg is sent when a toast should be removed.

type ToastTone

type ToastTone int

ToastTone controls the icon and border color of a toast notification.

const (
	ToastOK ToastTone = iota
	ToastInfo
	ToastError
)

Jump to

Keyboard shortcuts

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