menu

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Overview

Package menu implements vigo's top-of-screen menu bar and bottom-of-screen status line. v0.1 paints the bars with a fixed list of items; activation and pull-down menus arrive in v0.2.

Index

Constants

This section is empty.

Variables

View Source
var DefaultHints = []Hint{
	{Key: "F1", Action: "Help", Cmd: event.CmdHelp},
	{Key: "F10", Action: "Menu", Cmd: event.CmdMenu},
	{Key: "Alt-X", Action: "Exit", Cmd: event.CmdQuit},
}

DefaultHints is the v0.1 status line: F1 Help, F10 Menu, Alt-X Exit.

View Source
var DefaultItems = []Item{
	{Title: "≡", Hotkey: -1},
	{Title: "File", Hotkey: 0},
	{Title: "Edit", Hotkey: 0},
	{Title: "Search", Hotkey: 0},
	{Title: "Run", Hotkey: 0},
	{Title: "Compile", Hotkey: 0},
	{Title: "Debug", Hotkey: 0},
	{Title: "Project", Hotkey: 0},
	{Title: "Options", Hotkey: 0},
	{Title: "Window", Hotkey: 0},
	{Title: "Help", Hotkey: 0},
}

DefaultItems is the Turbo Vision IDE menu list: the system menu marker, followed by the nine top-level menus.

Functions

func SaveTOML added in v0.2.0

func SaveTOML(w io.Writer, menus []Item) error

SaveTOML writes menus to w in the format LoadTOML accepts.

Types

type Bar

type Bar struct {
	*view.View

	Items   []Item
	Enabler *cmd.Enabler
	Runner  MenuRunner

	// Last command chosen from a pull-down. Hosts read it after a Bar
	// event returns to broadcast a CmdCommand on its behalf.
	LastChosen event.CommandID
}

Bar is the horizontal strip of menu titles painted at the top of the screen. With Runner installed and Children populated on each Item, the Bar opens pull-downs on click, F10, and Alt-letter accelerators.

func NewBar

func NewBar(w int, items []Item) *Bar

NewBar returns a one-row menu bar pinned to the top of an owner of width w, populated with the supplied items. Pass DefaultItems for the IDE list.

func (*Bar) Draw

func (b *Bar) Draw(s *vio.Surface)

Draw paints the bar background and each item separated by spaces. The hotkey character is drawn in the menu-shortcut palette color.

func (*Bar) HandleEvent

func (b *Bar) HandleEvent(e *event.Event)

HandleEvent intercepts F10 and Alt-letter accelerators, plus mouse clicks on the bar itself, and runs the corresponding pull-down via Runner. It is a pre-process handler so the accelerators work even when focus is in a window.

type Hint

type Hint struct {
	Key    string
	Action string
	Cmd    event.CommandID
}

Hint is a single label on the status line: a key indicator (e.g. "F1") and the action it triggers ("Help"). The Cmd field is the command broadcast when the key is pressed; v0.1 paints the labels but does not fire commands yet (that ships with menu activation in v0.2).

type Item

type Item struct {
	Title    string
	Hotkey   int
	Cmd      event.CommandID
	Shortcut string
	Children []Item
	Sep      bool
}

Item is a single label on the menu bar or a row in a pull-down. Hotkey is the index of the highlighted character within Title, or -1 for none. Cmd is the command fired when the row is activated. Shortcut is the right-aligned accelerator label (e.g. "F3"). Children, when non-empty, marks this row as a submenu trigger. Sep == true renders as a horizontal separator and ignores every other field.

func LoadTOML added in v0.2.0

func LoadTOML(r io.Reader) ([]Item, error)

LoadTOML reads a menu tree from r. The format is a minimal TOML subset: each top-level menu starts with [menu], each row inside a menu starts with [[menu.items]]. Recognized keys are title, hotkey, cmd, shortcut, sep. Unknown keys are ignored.

[[menu]]
title = "File"
hotkey = 0

  [[menu.items]]
  title = "New"
  cmd = 101
  shortcut = "F3"

  [[menu.items]]
  sep = true

Returns the slice of top-level Items (each with Children populated) or an error pointing at the first malformed line.

type Line

type Line struct {
	*view.View

	Hints []Hint
}

Line is the one-row status bar pinned to the bottom of the screen.

func NewLine

func NewLine(w, y int, hints []Hint) *Line

NewLine returns a status line of width w, anchored at row y, with the supplied hints. Pass DefaultHints for the IDE defaults.

func (*Line) Draw

func (l *Line) Draw(s *vio.Surface)

Draw paints the bar background and each hint as "<key> <action>".

func (*Line) HandleEvent

func (l *Line) HandleEvent(e *event.Event)

HandleEvent is a no-op for v0.1; the demo binary handles Alt-X directly.

type MenuBox struct {
	*view.View

	Items   []Item
	Enabler *cmd.Enabler
	// contains filtered or unexported fields
}

MenuBox is the vertical pull-down that drops below a Bar item or nests under another MenuBox. It paints a single-line border, lays out items top to bottom, and exposes Result so a host can drive it like a modal sub-loop.

Disabled rows are dimmed, separators paint as a horizontal rule, submenu rows show a "▶" cap. Arrow keys move focus skipping separators; Enter fires the row's command (or sets ChildOpen on a submenu); Esc closes; a hot-key letter jumps to the matching row and fires it.

func NewMenuBox added in v0.2.0

func NewMenuBox(x, y int, items []Item, enabler *cmd.Enabler) *MenuBox

NewMenuBox returns a pull-down anchored at (x, y) sized to fit items. The width is the longest title plus shortcut plus padding; the height is len(items) plus 2 for the border.

func (m *MenuBox) AckChild()

AckChild clears the ChildOpen flag.

func (m *MenuBox) ChildOpen() bool

ChildOpen reports whether the focused row is a submenu trigger that the user just activated. The Bar/host clears this after spawning a nested MenuBox.

func (m *MenuBox) Chosen() event.CommandID

Chosen returns the command attached to the activated row, or CmdNone if the user canceled.

func (m *MenuBox) Draw(s *vio.Surface)

Draw paints the box.

func (m *MenuBox) HandleEvent(e *event.Event)

HandleEvent moves focus and dispatches.

func (m *MenuBox) IsEnabled(i int) bool

IsEnabled reports whether row i can be activated. Separators, out-of-range indices, and rows whose Cmd is in a disabled state return false.

func (m *MenuBox) Result() event.CommandID

Result returns CmdNone while the menu is still open, CmdCancel when the user closed it without picking, CmdMenu when a row fired a command (the bound command is available via Chosen), or CmdNext / CmdPrev when the user pressed ArrowRight / ArrowLeft on a non- submenu row to walk to the adjacent Bar item.

func (m *MenuBox) Selected() Item

Selected returns the focused item.

func (m *MenuBox) SelectedIndex() int

SelectedIndex returns the focused row index.

func (m *MenuBox) SetSelectedIndex(i int)

SetSelectedIndex moves focus to i, skipping separators and disabled rows in the supplied direction (1 forward, -1 backward, 0 forward).

type MenuRunner func(*MenuBox) event.CommandID

MenuRunner runs an open MenuBox to completion. The host (typically the Application) installs one that wraps ExecView; the Bar invokes it whenever the user opens a pull-down. Tests pass a stub that drives the box synchronously.

Jump to

Keyboard shortcuts

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