Documentation
¶
Overview ¶
Package songocui is a small, reusable wrapper around jroimartin/gocui.
It turns a declarative panel/keybind configuration into a running terminal UI and dispatches keybinding events to registered subscribers, letting an application stay decoupled from the underlying gocui primitives.
Index ¶
- func ColorStrToCode(color string) gocui.Attribute
- func KeyStrToCode(keyStr string) gocui.Key
- type Config
- type Coordinate
- type Keybind
- type KeybindGroup
- type Logger
- type Panel
- type SelectionColor
- type Songocui
- func (s *Songocui) Boot() error
- func (s *Songocui) Configure(cfg Config) error
- func (s *Songocui) CreateView(p *Panel) *gocui.View
- func (s *Songocui) CreateViews() []*gocui.View
- func (s *Songocui) CursorDown(viewName string) error
- func (s *Songocui) CursorUp(viewName string) error
- func (s *Songocui) DisableSelection(viewName string) error
- func (s *Songocui) EnableSelection(viewName string) error
- func (s *Songocui) Focus(viewName string) error
- func (s *Songocui) GetCurrentBuffer(viewName string) string
- func (s *Songocui) GetCurrentLine(v *gocui.View) string
- func (s *Songocui) GetNextLine(v *gocui.View) string
- func (s *Songocui) Hide(viewName string) error
- func (s *Songocui) Quit() error
- func (s *Songocui) RegisterSubscribers(subscribers []Subscriber)
- func (s *Songocui) ResetCursor(viewName string) error
- func (s *Songocui) Show(viewName string) error
- func (s *Songocui) UpdateListView(viewName string, data []string)
- func (s *Songocui) UpdateTextView(viewName string, data string) error
- type Subscriber
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ColorStrToCode ¶
ColorStrToCode converts a configuration color name to its gocui attribute. Unknown names fall back to the terminal default.
func KeyStrToCode ¶
KeyStrToCode converts a configuration key name to its gocui key code. Unknown names fall back to Ctrl+2 (an effectively unbindable key) so a typo never silently aliases a real key.
Types ¶
type Config ¶
type Config struct {
Panels []*Panel
Keybinds []KeybindGroup
DefaultFocus string
}
Config fully describes the UI: its panels, keybindings and the view that receives focus on start-up.
func LoadConfig ¶
LoadConfig reads panel and keybind definitions from JSON files and returns a Config ready to pass to Configure.
type Coordinate ¶
type Coordinate struct {
TopLeftXrel, TopLeftYrel, BottomRightXrel, BottomRightYrel int
TopLeftXabs, TopLeftYabs, BottomRightXabs, BottomRightYabs int
}
Coordinate defines a panel's bounding box. Each edge can be given either as an absolute cell position (*abs) or relative to the terminal size (*rel); relative values are resolved into absolute ones by Scale.
func (*Coordinate) Scale ¶
func (c *Coordinate) Scale(maxX, maxY int)
Scale resolves the relative coordinates against the terminal size (maxX, maxY), writing the results into the absolute fields. A relative value of 0 leaves the corresponding absolute field untouched.
type KeybindGroup ¶
KeybindGroup binds a set of keybinds to a view (empty ViewName = global).
type Logger ¶
type Logger interface {
Infof(format string, args ...interface{})
Warnf(format string, args ...interface{})
Errorf(format string, args ...interface{})
}
Logger is the minimal logging surface Songocui needs. It is satisfied by *logrus.Logger and most other structured loggers, so consumers are not forced to adopt a specific logging library. Songocui logs through it rather than writing to stderr, which would corrupt the terminal UI.
type Panel ¶
type Panel struct {
Title string
Name string
Highlight, Frame, Overwrite, Hidden, Editable, Wrap bool
Coordinate Coordinate
SelectionColor SelectionColor
}
Panel is the declarative description of a single view: its identity, gocui rendering flags, position and selection colors.
func (*Panel) DisableSelection ¶
func (p *Panel) DisableSelection()
DisableSelection sets the current selection colors to their "unactive" values.
func (*Panel) EnableSelection ¶
func (p *Panel) EnableSelection()
EnableSelection sets the current selection colors to their "active" values.
type SelectionColor ¶
type SelectionColor struct {
BgColorCurrent, FgColorCurrent,
BgColorActive, FgColorActive,
BgColorUnactive, FgColorUnactive string
}
SelectionColor holds the foreground/background colors used to render a panel's selection in its three states: current (what is drawn now), active (focused) and unactive (unfocused). Colors are named strings resolved by ColorStrToCode.
type Songocui ¶
type Songocui struct {
// contains filtered or unexported fields
}
Songocui is a wrapper for gocui.
func NewWithLogger ¶
NewWithLogger creates a Songocui instance that logs through the given logger. A nil logger is treated as a no-op logger.
func (*Songocui) Boot ¶
Boot dispatches the "Launch" event and runs the main GUI loop until the UI quits. Configure must be called first.
func (*Songocui) Configure ¶
Configure initializes the GUI, panels and keybindings from cfg. It performs no file I/O, so the configuration can be embedded, generated or loaded any way the consumer prefers.
func (*Songocui) CreateView ¶
CreateView creates a gocui.View based on panel specifications.
func (*Songocui) CreateViews ¶
CreateViews generates and returns all visible views from the panels.
func (*Songocui) CursorDown ¶
CursorDown moves the cursor one line down.
func (*Songocui) DisableSelection ¶
DisableSelection disables selection for a given view.
func (*Songocui) EnableSelection ¶
EnableSelection enables selection for a given view.
func (*Songocui) GetCurrentBuffer ¶
GetCurrentBuffer returns the current buffer content of a view.
func (*Songocui) GetCurrentLine ¶
GetCurrentLine returns the line where the cursor is located in a view.
func (*Songocui) GetNextLine ¶
GetNextLine returns the line below the cursor.
func (*Songocui) RegisterSubscribers ¶
func (s *Songocui) RegisterSubscribers(subscribers []Subscriber)
RegisterSubscribers registers the subscribers notified on every event.
func (*Songocui) ResetCursor ¶
ResetCursor resets the cursor position to the top-left of the view.
func (*Songocui) UpdateListView ¶
UpdateListView replaces a view's content with the given lines, padding each one to the view width so the full-width selection highlight is preserved.
type Subscriber ¶
Subscriber receives dispatched event names (keybind actions plus the built-in "Launch" event emitted on boot).