cmd

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package cmd implements vigo's command bus: a CommandSet for grouping command IDs, an Enabler that tracks which commands are currently active, and a key-binding table that maps KeyEvents to commands.

Views consult cmd.IsEnabled to decide their dim state; bindings resolve framework keys (F1 = CmdHelp) and host-defined ones (Ctrl-S = save). Hosts toggle commands via Enable/Disable; the Enabler notifies subscribers so menus can repaint.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bindings

type Bindings map[event.KeyEvent]event.CommandID

Bindings maps a KeyEvent to a command ID. The map key compares all three KeyEvent fields (Key, Mod, Rune) so Alt-X and a bare X do not collide.

func NewBindings

func NewBindings() Bindings

NewBindings returns an empty binding table.

func (Bindings) Bind

func (b Bindings) Bind(k event.KeyEvent, id event.CommandID)

Bind installs k -> id, replacing any prior binding for k.

func (Bindings) Lookup

func (b Bindings) Lookup(k event.KeyEvent) event.CommandID

Lookup returns the command bound to k, or CmdNone if none.

func (Bindings) Unbind

func (b Bindings) Unbind(k event.KeyEvent)

Unbind removes the binding for k, if any.

type Enabler

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

Enabler tracks which commands are enabled. It also keeps a list of subscribers that get notified when the enabled set changes; the menu uses that signal to dim or undim items without polling.

func NewEnabler

func NewEnabler(initial Set) *Enabler

NewEnabler returns an Enabler with the given initial set enabled. Pass nil for an empty starting set.

func (*Enabler) Disable

func (e *Enabler) Disable(s Set)

Disable turns each id in s off. Subscribers are notified once after the bulk update if any state actually changed.

func (*Enabler) Enable

func (e *Enabler) Enable(s Set)

Enable turns each id in s on. Subscribers are notified once after the bulk update if any state actually changed.

func (*Enabler) IsEnabled

func (e *Enabler) IsEnabled(id event.CommandID) bool

IsEnabled reports whether id is currently enabled.

func (*Enabler) Subscribe

func (e *Enabler) Subscribe(fn func()) func()

Subscribe registers fn to be called after every Enable/Disable that changes state. The returned function removes the subscription.

type Set

type Set map[event.CommandID]struct{}

Set is a collection of command IDs. Use it to flip many commands on or off in one call. The zero value is an empty set.

func NewSet

func NewSet(ids ...event.CommandID) Set

NewSet returns a set seeded with ids.

func (Set) Add

func (s Set) Add(id event.CommandID)

Add adds id to the set.

func (Set) Has

func (s Set) Has(id event.CommandID) bool

Has reports whether id is in the set.

func (Set) Remove

func (s Set) Remove(id event.CommandID)

Remove removes id from the set.

Directories

Path Synopsis
Command vigo launches the Vigo terminal IDE.
Command vigo launches the Vigo terminal IDE.
Command vigo-demos boots the vigo desktop with the four classic Turbo Vision sample tools (Calculator, Calendar, ASCIITable, Puzzle) reachable from the menu bar.
Command vigo-demos boots the vigo desktop with the four classic Turbo Vision sample tools (Calculator, Calendar, ASCIITable, Puzzle) reachable from the menu bar.

Jump to

Keyboard shortcuts

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