StatusBar
Sections
Section titled “Sections”StatusBar renders left-aligned and right-aligned sections, each with an optional icon and dynamic color:
sb := layout.NewStatusBar()sb.SetSections([]layout.StatusSection{ {Icon: " ", Text: "main", ColorFunc: branchColor}, {Icon: " ", Text: "12 pods"},})sb.SetRightSections([]layout.StatusSection{ {Icon: " ", Text: "Connected", Color: tcell.ColorGreen},})ColorFunc takes precedence over Color and is called on every redraw — use it for status that changes at runtime (e.g., connection state).
Command mode
Section titled “Command mode”Call EnterCommandMode() to show an inline input field for command entry. Wire SetOnSubmit and SetOnCancel to handle the result. Completion popup and history navigation are available via SetOnComplete, SetOnHistoryPrev, and SetOnHistoryNext.
Usage
bar := components.NewStatusBar(). SetLeft( components.StatusSection{Icon: "", Text: "main"}, components.StatusSection{Text: "12 pods"}, ). SetRight( components.StatusSection{Icon: "", Text: "Connected", Color: tcell.ColorGreen}, ). SetShowBorder(true)
fmt.Println(bar != nil)Methods
| Method | Signature | Description |
|---|---|---|
AddLeft | func (s *StatusBar) AddLeft(section StatusSection) *StatusBar | AddLeft adds a left section |
AddRight | func (s *StatusBar) AddRight(section StatusSection) *StatusBar | AddRight adds a right section |
Clear | func (s *StatusBar) Clear() *StatusBar | Clear removes all sections |
GetFieldHeight | func (s *StatusBar) GetFieldHeight() int | GetFieldHeight returns preferred height |
SetCenter | func (s *StatusBar) SetCenter(sections ...StatusSection) *StatusBar | SetCenter sets center-aligned sections |
SetLeft | func (s *StatusBar) SetLeft(sections ...StatusSection) *StatusBar | SetLeft sets left-aligned sections |
SetRight | func (s *StatusBar) SetRight(sections ...StatusSection) *StatusBar | SetRight sets right-aligned sections |
SetSeparator | func (s *StatusBar) SetSeparator(sep rune) *StatusBar | SetSeparator sets the section separator character |
SetShowBorder | func (s *StatusBar) SetShowBorder(show bool) *StatusBar | SetShowBorder enables/disables the top border |
UpdateSection | func (s *StatusBar) UpdateSection(prefix, newText string) *StatusBar | UpdateSection updates a section by matching text prefix |
Types
type StatusSection struct StatusSection represents a section of the status bar | Field | Type | Description |
|---|---|---|
Text | string | |
Icon | string | |
Color | tcell.Color | 0 = default |
MinWidth | int | |
Align | int | tview.AlignLeft, AlignCenter, AlignRight |