menuify

package module
v0.0.0-...-066ef22 Latest Latest
Warning

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

Go to latest
Published: May 25, 2024 License: AGPL-3.0 Imports: 10 Imported by: 2

Documentation

Index

Constants

View Source
const (
	ERR_CANCELLED = Error("calibrator: cancelled")
)

Variables

This section is empty.

Functions

func Interval

func Interval(dur time.Duration, call func() error)

func Run

func Run(prog string, args ...string) ([]byte, error)

func RunRealtime

func RunRealtime(prog string, args ...string) error

func ScreenPrintf

func ScreenPrintf(ms MenuScreen, format string, args ...interface{})

func ScreenPrintln

func ScreenPrintln(ms MenuScreen, line string)

Types

type Error

type Error string

func (Error) Error

func (e Error) Error() string

type KeyCalibration

type KeyCalibration struct {
	Ready  bool
	Cancel bool
	Action string
	KLs    []*KeycodeListener
}

func (*KeyCalibration) Input

func (kc *KeyCalibration) Input(keyboard string, keycode uint16, onRelease bool)

type KeycodeBinding

type KeycodeBinding struct {
	Handler   func() //The binding handler function that will be called when this binding activates
	Keycode   uint16 //The Linux-designated keycode for this binding
	OnRelease bool   //If this binding should activate when the button is released instead of when pressed
}

KeycodeBinding holds a binding between a Linux keycode and a bare Go handler

type KeycodeListener

type KeycodeListener struct {
	RootBind  func(keyboard string, keycode uint16, onRelease bool) //Fallback if no other bindings match an event
	Bindings  []*KeycodeBinding
	Keyboard  string
	KeyLogger *keylogger.KeyLogger
	// contains filtered or unexported fields
}

KeycodeListener holds a Linux keycode listener

func NewKeycodeListener

func NewKeycodeListener(keyboard string) (*KeycodeListener, error)

NewKeycodeListener returns a new keycode listener

func (*KeycodeListener) Bind

func (kl *KeycodeListener) Bind(keycode uint16, onRelease bool, handler func())

Bind binds a keycode to a handler, bind nil to remove all bindings to the keycode

func (*KeycodeListener) Close

func (kl *KeycodeListener) Close()

Close closes the keycode listener

func (*KeycodeListener) RemoveBind

func (kl *KeycodeListener) RemoveBind(keycode uint16)

RemoveBind removes all bindings to a keycode

func (*KeycodeListener) Run

func (kl *KeycodeListener) Run()

Run starts the keycode listener and blocks until it's closed

type Menu struct {
	Config *MenuConfig
	Engine *MenuEngine
	Screen *MenuScreen
	Keysrv []*KeycodeListener
}

func NewMenu

func NewMenu() *Menu
func (m *Menu) Load(configPath string) error
func (m *Menu) SetScreen(screen MenuScreen)
type MenuConfig struct {
	Environment map[string]string        `json:"environment"`
	Keybinds    []*MenuKeycodeBinding    `json:"keybinds"`
	HomeMenu    string                   `json:"home"`
	Menus       map[string]*MenuItemList `json:"menus"`
}
type MenuEngine struct {
	//Menu navigation
	Menus       map[string]*MenuItemList
	HomeMenu    string
	LoadedMenu  string
	MenuHistory []string
	ItemHistory []int
	Environment map[string]string //global variables set by menus
	ItemCursor  int
	Locked      bool
	Return      string                          //return value set by some menu types
	Hooks       map[string]func(me *MenuEngine) //run a hook after changing to a menu

	//Rendering control
	Screen         MenuScreen
	LinesV, LinesH int
}

MenuEngine holds a list of menus and acts as the menu interface

func NewMenuEngine

func NewMenuEngine() *MenuEngine

NewMenuEngine returns a menu engine ready to be used

func (me *MenuEngine) Action()

Action activates the selected item's action, such as navigating to a menu or executing a program

func (me *MenuEngine) AddMenu(menuID string, menu *MenuItemList)

AddMenu adds a menu to the menu list

func (me *MenuEngine) BindKeys()
func (me *MenuEngine) Calibrate(keyCalibrationFile string) error
func (me *MenuEngine) ChangeMenu(menuID string)

ChangeMenu changes to another available menu

func (me *MenuEngine) ClearMenus()

ClearMenus clears the total menu list

func (me *MenuEngine) DisplayText(txt string)

DisplayText generates a text message menu with menuID "INTERNAL_DISPLAY_TEXT" and navigates to it It is used internally as well as being made available, so refrain from using menuIDs starting with "INTERNAL"

func (me *MenuEngine) ErrorText(err, extra string)

ErrorText generates an error message menu with menuID "INTERNAL_ERROR_TEXT" and navigates to it It is used internally as well as being made available, so refrain from using menuIDs starting with "INTERNAL"

func (me *MenuEngine) Explorer(workingDir, bin string)

Explorer abuses the powers of AddMenu, ChangeMenu, and PrevMenu to create a file browser with support for passing a selected file to an executable

func (me *MenuEngine) GetRender() *MenuFrame

GetRender returns a rendered menu text to be displayed immediately, as the menu state can change freely before and after

func (me *MenuEngine) Home()

Home returns to the home menu

func (me *MenuEngine) Hook(id string, hook func(me *MenuEngine))
func (me *MenuEngine) LoadMenu(id string, itemList *MenuItemList)
func (me *MenuEngine) Lock()
func (me *MenuEngine) NextItem()

NextItem navigates to the next menu item, or to the first if none next

func (me *MenuEngine) PrevItem()

PrevItem navigates to the previous menu item, or to the last if none previous

func (me *MenuEngine) PrevMenu()

PrevMenu returns to the last menu in history

func (me *MenuEngine) Redraw()
func (me *MenuEngine) RemoveMenu(menuID string)

RemoveMenu removes a menu from the menu list

func (me *MenuEngine) ResetHistory()

ResetHistory clears the linked item and menu histories, and resets the cursor to item 0

func (me *MenuEngine) Run(command string)

Run runs the given command, but halts the menu engine until completion

func (me *MenuEngine) RunRealtime(command string)

RunRealtime runs the given command, but doesn't halt the menu engine

func (me *MenuEngine) SetScreen(screen MenuScreen)
func (me *MenuEngine) Unlock()
func (me *MenuEngine) Vars(in string) string

Vars returns a string formatted with all vars replaced, in order from longest var name to shortest to avoid partial var name replacements

type MenuFrame struct {
	Header, Menu, Footer string
}
func (mf *MenuFrame) Empty() bool
func (mf *MenuFrame) Vars(me *MenuEngine) *MenuFrame
type MenuItem struct {
	Text   string `json:"text"`
	Desc   string `json:"desc"`
	Type   string `json:"type"`   //menu, exec, explorer[:pwd], note, var name
	Action string `json:"action"` //var: string[:limit]|number[:min[:max]]|file[:extension1[,extension2,...]]|bool|opts:opt1,opt2,[opt3,...]
}

MenuItem holds an item for a menu, such as a button, a checkbox, or an input box

type MenuItemList struct {
	Title      string      `json:"title"`
	Subtitle   string      `json:"subtitle"`
	Items      []*MenuItem `json:"items"`      //items to display on the page
	NoGoBack   bool        `json:"noGoBack"`   //hides the go back button
	NoSelector bool        `json:"noSelector"` //hides the item cursor
	DefaultCur int         `json:"defaultCur"` //the cursor to set by default
	Exec       string      `json:"exec"`       //a line interpreted as an exec action
}

MenuItemList holds a list of items to interact with

func (m *MenuItemList) AddItem(name, desc, itemType, action string)
type MenuKeycodeBinding struct {
	Keycode   uint16 `json:"keycode"`
	Action    string `json:"action"`
	OnRelease bool   `json:"onRelease"`
}
type MenuScreen interface {
	//Offloading for rendering the menu string, locks the menu until method returns
	Render(*MenuFrame)
	GetFrame() *MenuFrame //Returns the cached menu frame
	Clear()

	//Monospaced terminal screen size
	GetWidth() int
	GetHeight() int
}

MenuScreen is a wrapper for a screen manager, which could theoretically wrap multiple screens...

Directories

Path Synopsis
screens

Jump to

Keyboard shortcuts

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