ui

package
v0.0.0-...-f2f0a72 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2016 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DirectionNone means no movement (initial state)
	DirectionNone = iota

	// DirectionRight means a clockwise rotation.
	DirectionRight

	// DirectionLeft means a counter-clockwise rotation.
	DirectionLeft
)

Variables

This section is empty.

Functions

func Run

func Run(cfg *Config, ctx context.Context) error

Run starts the UI with the settings in `cfg` and until `ctx` is canceled.

func RunClock

func RunClock(lw *display.LineWriter, width int, ctx context.Context)

RunClock displays the current time in the "clock" window.

func RunSysinfo

func RunSysinfo(lw *display.LineWriter, width int, ctx context.Context)

RunSysinfo displays system information in the "sysinfo" window. The data is obtained from the "radio-sysinfo.sh" script.

func RunWeather

func RunWeather(lw *display.LineWriter, width int, ctx context.Context)

RunWeather displays a weather forecast in the "weather" window.

Types

type Action

type Action func() error

Action is a callback function that might fail

type ClickEntry

type ClickEntry struct {
	// Text is the static text displayed in the menu line.
	Text string
	// ActionFunc is called when the entry is clicked.
	ActionFunc Action
}

ClickEntry is a menu entry that can be clicked with the rotary switch.

func (*ClickEntry) Action

func (en *ClickEntry) Action() error

Action calls ActionFunc.

func (*ClickEntry) Render

func (en *ClickEntry) Render(w int, active bool) string

Render will display the text and a indicator if the entry is currently selected.

func (*ClickEntry) Selectable

func (en *ClickEntry) Selectable() bool

Selectable is always true.

type Config

type Config struct {
	Width  int
	Height int

	DisplayHost string
	DisplayPort int

	MPDHost string
	MPDPort int

	AmbilightHost string
	AmbilightPort int

	LightdHost string
	LightdPort int
}

Config allows the user to configure to which services the ui connects.

type Entry

type Entry interface {
	// Selectable returns true when the user can select the entry
	Selectable() bool

	// Render draws the line as string (with len of w), possibly with an
	// "active" marker as indicated by `active`.
	Render(w int, active bool) string

	// Action gets called when the user clicks the button.
	// Errors are logged but not handled otherwise.
	Action() error
}

Entry is the common interface of each menu line

type Menu struct {
	// Name is the name of the menu window.
	// Should start with menu-[...]
	Name string

	// Entries is a list of Entry interfaces
	Entries []Entry

	// Cursor is the current offset in the entries
	Cursor int
	// contains filtered or unexported fields
}

Menu is a collection of Entry interfaces grouped in a window. It supports the usual menu semantics, i.e. moving down and clicking an entry.

func NewMenu

func NewMenu(name string, lw *display.LineWriter) (*Menu, error)

NewMenu returns a new menu that will use `lw` to display itself on the window `name`.

func (mn *Menu) Click() error

Click executes the action under the cursor

func (mn *Menu) Display(width int) error

Display draws the menu onto the display

func (mn *Menu) Scroll(move int)

Scroll moves the menu `move` down (or up if negative)

type MenuManager struct {
	sync.Mutex
	Config *Config
	// contains filtered or unexported fields
}

MenuManager handles the switching and drawing of several Menus and possibly "normal" windows.

func NewMenuManager

func NewMenuManager(cfg *Config, lw *display.LineWriter, initialWin string) (*MenuManager, error)

NewMenuManager returns a new MenuManager that sends it's data to `lw` and switches to `initialWin`.

func (mgr *MenuManager) ActiveWindow() string

ActiveWindow returns the currently active window shown by the display server.

func (mgr *MenuManager) AddMenu(name string, entries []Entry) error

AddMenu adds a (potentially new) menu to the manager with `name` and `entries`. If the menu already exists it will be subsituted with the new one.

func (mgr *MenuManager) AddTimedAction(after time.Duration, action Action)

AddTimedAction register an action to be called after pressing the rotary button with a duration of `after`.

func (mgr *MenuManager) Close() error

Close closes all input resources

func (mgr *MenuManager) Direction() int

Direction returns the direction in which the rotary button was rotated last. If it was not rotated yet, the duration is DirectionNone.

func (mgr *MenuManager) Display()

Display sends the current active menu to the display server. (but it does not switch to it!)

func (mgr *MenuManager) ReleaseAction(a Action)

ReleaseAction registers an action to be called when the rotary button is released.

func (mgr *MenuManager) RotateAction(a Action)

RotateAction registers an action to be called when the user rotates the knob.

func (mgr *MenuManager) SwitchTo(name string) error

SwitchTo switches to the menu named `menu`. NOTE: use this instead of directly talking to the display server since it also switches the input focus.

func (mgr *MenuManager) Value() int

Value returns the current value of the rotary button.

type Separator

type Separator struct {
	// Title of the separator (drawn centered)
	Title string
}

Separator is a visual separator between several other menu entries. Other than that it has no function.

func (*Separator) Action

func (sp *Separator) Action() error

Action is a no-op.

func (*Separator) Render

func (sp *Separator) Render(w int, active bool) string

Render draws the separator centered in `w`. `active` is ignored.

func (*Separator) Selectable

func (sp *Separator) Selectable() bool

Selectable is always false.

type ToggleEntry

type ToggleEntry struct {
	// Text is the text displayed along the state
	Text string

	// Order in which the states are toggled through
	Order []string

	// Actions is a map of state to Actions.
	// When changing to a state the respective
	// Action is called.
	Actions map[string]Action
	// contains filtered or unexported fields
}

ToggleEntry skips through an ordered list of states.

func (*ToggleEntry) Action

func (te *ToggleEntry) Action() error

Action goes to the next state and executes it's associated action

func (*ToggleEntry) Render

func (te *ToggleEntry) Render(w int, active bool) string

Render draws an activity marker, the text and the current state.

func (*ToggleEntry) Selectable

func (te *ToggleEntry) Selectable() bool

Selectable is true when there is a non-zero amount of actions

func (*ToggleEntry) SetState

func (te *ToggleEntry) SetState(state string)

SetState sets the current state but does not call the associated action It's useful to set the state if it was changed by extern resources (i.e. a different mpd client)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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