windigo

package module
v0.0.0-...-4df8e37 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2019 License: Apache-2.0 Imports: 8 Imported by: 0

README

windigo - instumentation CUI builder for go/termbox.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var OutlineChars []rune
View Source
var ScreenSizeX, ScreenSizeY int

The size of the initial screen, set from termbox.Size().

Functions

func AddComm

func AddComm(c Container, w Object)

func Close

func Close()

func DrawScale

func DrawScale(o Object) error

func EventMgr

func EventMgr(o Object)

func Fill

func Fill(o Object, c rune) error

func Flush

func Flush()

func InitObject

func InitObject(w Object)

func Manage

func Manage(c Container, w Object) error

func RegClickable

func RegClickable(w Object, r Region) (chan *termbox.Event, error)

func SetCell

func SetCell(w Object, x, y int, r rune, fg, bg Attribute) error

SetCell function that should be used by a widget's SetCell method.

func SetRegion

func SetRegion(w Object, r *Region)

func Within

func Within(o Sizer, p *Point) bool

func Wprint

func Wprint(o Object, x, y int, fg, bg Attribute, msg string) error

func Yang

func Yang(w Object) (chan *Event, error)

func Yin

func Yin(w Object) (chan *Event, error)

Types

type ArgType

type ArgType struct {
	Type PayloadType
	Val  []int
	Sval []string
	Cval chan *termbox.Event
	Tbox *termbox.Event
}

type Attribute

type Attribute termbox.Attribute

Alias some useful termbox constants.

const AttrBold Attribute = Attribute(termbox.AttrBold)
const AttrReverse Attribute = Attribute(termbox.AttrReverse)
const AttrUnderline Attribute = Attribute(termbox.AttrUnderline)

type ButtonType

type ButtonType struct {
	WidgetType
}

func NewButton

func NewButton(r *Region, activeStates ...Sigil) (*ButtonType, error)

func (*ButtonType) Init

func (b *ButtonType) Init() error

func (*ButtonType) Map

func (b *ButtonType) Map(r *Region, ev *termbox.Event, cs FiniteState) interface{}

type Cell

type Cell struct {
	Ch     rune
	Fg, Bg Attribute
}

type ClickableRegion

type ClickableRegion struct {
	X, Y int
	W, H int
	C    chan *termbox.Event
}

Register interest in mouse input events by calling RegClickable with the following struct.

type Color

type Color struct {
	Fg, Bg Attribute
}

type Communicator

type Communicator interface {
	AddComm(IChing)
	GetComm() []IChing
}

type Container

type Container interface {
	Object
	Manage(Object) error
	AddChild(Object)
	Done()
}

type ElasticType

type ElasticType int
const (
	ElasticNone ElasticType = iota
	ElasticHorz
	ElasticVert
	ElasticBoth
)

Elastic is actually a bit field. None = 00, Horz = 01, Vert = 10, Both = 11.

type Embelishments

type Embelishments interface {
	Colors() (Attribute, Attribute)
	SetColors(Attribute, Attribute)
}

type Event

type Event struct {
	EventType WindigoEventType
	Args      *ArgType
	Result    *ResultType
}

func NewEvent

func NewEvent(et WindigoEventType, args ...interface{}) *Event

func WidgetResult

func WidgetResult(rc RetCode, n ...interface{}) *Event

For use in a widget's finite state machine state functions. Widgets are finite state machines that turn termbox.Events into Windigo EventOut Events. These may be 0 or more ints, strings, or termbox.Events (altho this is intended for a passthru of a single termbox event.)

Result constructs and returns a Windigo event from RetCode and 0 or more int, string or termbox.Event results. RetCode is the Finite State Machine state transition value, Ok, Fail, Repeat or Nop. Ok typically transitions to the next state, Fail transitions to exit, Repeat returns to the first active state, and Nop is the same as repeat, but generates NO windigo event. The termbox.Event result is meant to provide a passthru function.

type EventType

type EventType termbox.EventType // uint8

Alias these from termbox.

type FiniteState

type FiniteState int

type FiniteStateMachine

type FiniteStateMachine struct {
	CurrentState, EntryState, ExitState FiniteState
	// On screen representation of widget. An array of termbox Cells
	// representing enough information for the widget writer's supplied
	// Refresh to draw the widget via the widget's SetCell call.
	// This may represent every cell of the widget or as in
	// the case of a scrollbar, plus, minus and filler characters.
	// This info is separate for each "state", so each state can
	// represent the widget via different colors and or characters.
	Sigil []Sigil
	// State functions with index representing state.
	StateFunc []WidgetStateFunc
	// Table of src, rc, dst transitions, where src and dst are
	// indices(states) into the statefunc array, and rc is one of the
	// Finite State Machine return codes(Ok, Fail, Repeat, Nop).
	Transitions []Transition
}

func NewFSM

func NewFSM(w Widget, activeStates ...Sigil) *FiniteStateMachine

NewFSM returns a State (the entry state for the new state machine), and a pointer to the new FSM struct. It expects a Sigil for each of the widget's active states. This may be 1 for an indicator or 1 or more for a button/switch. An indicator is just a button with no clickable regions and only windigo events to transition states. Normally, widgets may transition states on windigo events or termbox input events.

This function provides a simple round-robin state machine. For more complex state machines, create the new state machine with 0 states, and add the states and transition table entries manually with AddState and AddTransition. Calling NewFSM with no Sigils(state representations) will return a pointer to a new FSM, with NO state table entries and NO transition table entries and -1 as the entry point. You should then use AddState and AddTransition to populate the finite state machine's tables. This allows for a more complex state machine (than the one provided here) to be used. State functions are: func (*termbbox.Event) *Event. WidgetResult should be used for return values.

func (*FiniteStateMachine) AddState

func (fsm *FiniteStateMachine) AddState(f WidgetStateFunc, glyph Sigil) FiniteState

AddState adds a StateFunc to the widget's Finite State Machine statefunc table and establishes the characters and colors associated with it's on screen look. These are used by the widget writer's Refresh method to actually draw the widget on screen.

func (*FiniteStateMachine) AddTransition

func (fsm *FiniteStateMachine) AddTransition(src FiniteState, rc RetCode, dst FiniteState)

There are no checks done here to ensure that destination states actually exist. If the destination state doesn't exist the state machine's NextState function will return Fail when it attempts to transition to that state. Source states are not a problem b/c if the source state doesn't exist, the entry will simply never be used.

func (*FiniteStateMachine) Entry

func (fsm *FiniteStateMachine) Entry() FiniteState

func (*FiniteStateMachine) Exit

func (fsm *FiniteStateMachine) Exit() FiniteState

func (*FiniteStateMachine) NextState

func (fsm *FiniteStateMachine) NextState(rc RetCode) (FiniteState, error)

func (*FiniteStateMachine) SetEntry

func (fsm *FiniteStateMachine) SetEntry(e FiniteState)

func (*FiniteStateMachine) SetExit

func (fsm *FiniteStateMachine) SetExit(e FiniteState)

func (*FiniteStateMachine) SetState

func (fsm *FiniteStateMachine) SetState(s FiniteState)

Getter and Setter methods.

func (*FiniteStateMachine) State

func (fsm *FiniteStateMachine) State() FiniteState

type Gadget

type Gadget interface {
	Manage(Object)
}

type GadgetStateFunc

type GadgetStateFunc func(ev *Event) *Event

type GadgetType

type GadgetType struct {
	TopLeft
	WidthHeight
	MinSize WidthHeight

	Color
	Gravity GravityType
	Elastic ElasticType

	BackingStore []Cell

	// comm[n].yin and comm[n].yang channels for communication with
	// parent window(comm[0]) and subordinate widgets(n > 0).
	Children []Object
	Comm     []IChing

	Parent Container
	// contains filtered or unexported fields
}

func NewGadget

func NewGadget(r *Region, fg, bg Attribute) *GadgetType

func (*GadgetType) AddChild

func (g *GadgetType) AddChild(o Object)

func (*GadgetType) AddComm

func (g *GadgetType) AddComm(c IChing)

func (*GadgetType) Ancestor

func (g *GadgetType) Ancestor() Container

func (*GadgetType) Clear

func (g *GadgetType) Clear()

func (*GadgetType) Colors

func (g *GadgetType) Colors() (Attribute, Attribute)

func (*GadgetType) Done

func (g *GadgetType) Done()

func (*GadgetType) EventMgr

func (g *GadgetType) EventMgr()

func (*GadgetType) GetComm

func (g *GadgetType) GetComm() []IChing

func (*GadgetType) Init

func (g *GadgetType) Init() error

func (*GadgetType) Loc

func (g *GadgetType) Loc() (int, int)

func (*GadgetType) Manage

func (g *GadgetType) Manage(o Object) error

func (*GadgetType) Managed

func (g *GadgetType) Managed() bool

func (*GadgetType) Refresh

func (g *GadgetType) Refresh()

func (*GadgetType) SetAncestor

func (g *GadgetType) SetAncestor(p Container)

func (*GadgetType) SetColors

func (g *GadgetType) SetColors(fg, bg Attribute)

func (*GadgetType) SetLoc

func (g *GadgetType) SetLoc(x, y int)

func (*GadgetType) SetManaged

func (g *GadgetType) SetManaged()

func (*GadgetType) SetSize

func (g *GadgetType) SetSize(width, height int)

func (*GadgetType) Size

func (g *GadgetType) Size() (int, int)

type Genealogy

type Genealogy interface {
	Managed() bool
	SetManaged()
	Ancestor() Container
	SetAncestor(Container)
}

type Graviton

type Graviton interface {
	Gravity() GravityType
	SetGravity(GravityType)
}

type GravityType

type GravityType int
const (
	GravityNone GravityType = 0
	GravityTop  GravityType = 1 << iota
	GravityBottom
	GravityLeft
	GravityRight
)

Note: (GravityTop | GravityBottom) or (GravityLeft | GravityRight)

makes no sense, however (GravityTop | GravityRight) and the
other 3 similar constructs should be useful.

type IChing

type IChing struct {
	Yin  chan *Event
	Yang chan *Event
}

type InputMode

type InputMode termbox.InputMode // int

Alias these from termbox.

type Key

type Key termbox.Key // uint16 Attribute  termbox.Attribute

Alias these from termbox.

type Keyboarder

type Keyboarder interface {
	HaveFocus() bool
	ReqFocus() (chan *termbox.Event, error)
	SetAllowFocus(bool)
}

type LayoutType

type LayoutType struct {
	Regions []Region
	Lines   []Line
}

type Line

type Line struct {
	P1, P2      Point
	Orientation OrientationType
}

func NewLine

func NewLine(x1, y1, x2, y2 int) *Line

func (*Line) GreaterThan

func (l *Line) GreaterThan(ol *Line) bool

Is ol (other line) further down/to the right of l.

func (*Line) LessThan

func (l *Line) LessThan(ol *Line) bool

Is ol (other line) further up/to the left than l.

type Modifier

type Modifier termbox.Modifier // uint8

Alias these from termbox.

type Mouser

type Mouser interface {
	Click(FiniteState, *Region, termbox.Key)
	RegClickable(*Region) (chan *termbox.Event, error)
}

type NexusType

type NexusType Point

type Object

type Object interface {
	Poser
	Sizer
	Embelishments
	Genealogy
	Communicator
	Refresh()
	Init() error
}

type OrientationType

type OrientationType int
const (
	UnOriented OrientationType = iota
	Horizontal
	Vertical
)

type OutlineChar

type OutlineChar int

The outline characters to use when drawing borders. There is also a set of const defOutlinechars.

const (
	TL OutlineChar = iota
	TR
	BL
	BR
	VB
	HB
	LT
	RT
	TT
	BT
	CR
)

This is the order that outline characters need to be in an outlinChar type

type OutputMode

type OutputMode termbox.OutputMode // int

Alias these from termbox.

type PanelType

type PanelType struct {
	GadgetType
}

func NewPanel

func NewPanel(r *Region, fg, bg Attribute) *PanelType

func (*PanelType) Manage

func (p *PanelType) Manage(o Object) error

type PayloadType

type PayloadType int
const (
	// StateFuncs always return a *Event with an Rc
	// set to inform the state machine.
	Int PayloadType = iota
	// passthru means that Result.Tbox is a valid termbox input
	// event and is being passed thru as the result of the widget.
	String
	Channel
	PassThru
	None
)

type Point

type Point struct {
	X, Y int
}

func Intersection

func Intersection(l1, l2 *Line) (*Point, error)

Return the intersection of the 2 lines.

type PosSizeColor

type PosSizeColor interface {
	Poser
	Sizer
	Embelishments
}

type PosSizer

type PosSizer interface {
	Poser
	Sizer
}

type Poser

type Poser interface {
	Loc() (int, int)
	SetLoc(int, int)
}

type Region

type Region struct {
	TopLeft
	WidthHeight
	RightMost, BottomMost bool
	Valid                 bool
}

func NewRegion

func NewRegion(x, y, width, height int) *Region

func (*Region) Bottom

func (r *Region) Bottom() *Line

func (*Region) Left

func (r *Region) Left() *Line

This is the left edge of the region in it's window's coordinates.

func (*Region) Loc

func (r *Region) Loc() (x, y int)

func (*Region) Right

func (r *Region) Right() *Line

func (*Region) Size

func (r *Region) Size() (w, h int)

func (*Region) Top

func (r *Region) Top() *Line

type RegionType

type RegionType []Region

func (RegionType) Len

func (r RegionType) Len() int

func (RegionType) Less

func (r RegionType) Less(i, j int) bool

func (RegionType) Swap

func (r RegionType) Swap(i, j int)

type Resizer

type Resizer interface {
	Elastic() ElasticType
	SetElastic(ElasticType)
}

type ResultType

type ResultType struct {
	Rc   RetCode
	Err  error
	Type PayloadType
	Val  []int
	Sval []string
	Cval chan *termbox.Event
	Tbox *termbox.Event
}

type RetCode

type RetCode int
const (
	Fail RetCode = iota - 1
	Ok
	Repeat
	Nop
)

type Screen

type Screen struct {
	WidthHeight

	Comm IChing
	// contains filtered or unexported fields
}

func (*Screen) InputEventRouter

func (s *Screen) InputEventRouter()

func (*Screen) RequestFocus

func (s *Screen) RequestFocus() (chan *termbox.Event, error)

func (*Screen) Size

func (s *Screen) Size() (int, int)

type Sigil

type Sigil []Cell

func String2Sigil

func String2Sigil(s string, fg, bg Attribute) *Sigil

type Sizer

type Sizer interface {
	Size() (int, int)
	SetSize(int, int)
}

type TopLeft

type TopLeft Point

type Transition

type Transition struct {
	SrcState FiniteState
	Rc       RetCode
	DstState FiniteState
}

type Widget

type Widget interface {
	// MapEvent is called by (is?) the widget's StateFunctions to
	// determine state trasitions.
	Map(*Region, *termbox.Event, FiniteState) interface{}
}

type WidgetStateFunc

type WidgetStateFunc func(ev *termbox.Event) *Event

type WidgetType

type WidgetType struct {
	// A widgets location within its containing gadget/window
	TopLeft
	// A widgets size
	WidthHeight
	MinSize WidthHeight

	Color

	InputChan []chan *termbox.Event

	Comm []IChing

	Fsm *FiniteStateMachine

	BackingStore []Cell

	Elastic ElasticType
	Gravity GravityType

	// Our container.
	Parent Container
	// contains filtered or unexported fields
}

Widgets accept input Events from the screen's InputEventRouter and generate their own Event sending it down it's eventchan[0] channel where its container's EventMgr is waiting for it. Input events are handled by the windigo main screen's InputEventRouter which first finds any objects interested in receiving particular types of events from particular absolute coordinates and channels them to the the object(widget) that registered interest via it's own virtual coordinates. Gadgets handle Events generated by their widgets.

func NewWidget

func NewWidget(r *Region, activeStates ...Sigil) (*WidgetType, error)

func (*WidgetType) AddComm

func (w *WidgetType) AddComm(c IChing)

func (*WidgetType) AddInput

func (w *WidgetType) AddInput(c chan *termbox.Event)

func (*WidgetType) AllowFocus

func (w *WidgetType) AllowFocus() bool

func (*WidgetType) Ancestor

func (w *WidgetType) Ancestor() Container

func (*WidgetType) Clear

func (w *WidgetType) Clear()

func (*WidgetType) Colors

func (w *WidgetType) Colors() (Attribute, Attribute)

func (*WidgetType) GetComm

func (w *WidgetType) GetComm() []IChing

func (*WidgetType) HaveFocus

func (w *WidgetType) HaveFocus() bool

func (*WidgetType) Init

func (w *WidgetType) Init() error

func (*WidgetType) InputEventMgr

func (w *WidgetType) InputEventMgr()

func (*WidgetType) Loc

func (w *WidgetType) Loc() (int, int)

func (*WidgetType) Managed

func (w *WidgetType) Managed() bool

func (*WidgetType) PollEvent

func (w *WidgetType) PollEvent() *termbox.Event

func (*WidgetType) PushEvent

func (w *WidgetType) PushEvent(e *Event)

func (*WidgetType) Refresh

func (widget *WidgetType) Refresh()

func (*WidgetType) ReqFocus

func (w *WidgetType) ReqFocus() (chan *termbox.Event, error)

func (*WidgetType) SetAllowFocus

func (w *WidgetType) SetAllowFocus(f bool)

func (*WidgetType) SetAncestor

func (w *WidgetType) SetAncestor(p Container)

func (*WidgetType) SetColors

func (w *WidgetType) SetColors(fg, bg Attribute)

func (*WidgetType) SetFSM

func (w *WidgetType) SetFSM(fsm *FiniteStateMachine)

func (*WidgetType) SetHaveFocus

func (w *WidgetType) SetHaveFocus(f bool)

func (*WidgetType) SetLoc

func (w *WidgetType) SetLoc(x, y int)

func (*WidgetType) SetManaged

func (w *WidgetType) SetManaged()

func (*WidgetType) SetSize

func (w *WidgetType) SetSize(width, height int)

func (*WidgetType) Size

func (w *WidgetType) Size() (int, int)

func (*WidgetType) Start

func (w *WidgetType) Start()

type WidthHeight

type WidthHeight struct {
	W, H int
}

type WindigoEventType

type WindigoEventType int
const (
	WindEventNone WindigoEventType = iota
	WindEventInit
	WindEventExit
	WindEventError
	WindEventRestart
	WindEventOutput
	WindEventMove
	WindEventResize
)

type Window

type Window interface {
	Container
	Main()
}

type WindowType

type WindowType struct {
	TopLeft
	WidthHeight

	Color
	Elastic ElasticType
	Gravity GravityType

	BackingStore []Cell

	Children []Object
	Comm     []IChing

	Parent Container

	Layout     LayoutType
	RightMost  bool
	BottomMost bool
	// contains filtered or unexported fields
}

func Init

func Init() *WindowType

func NewWindow

func NewWindow(r *Region, fg, bg Attribute) *WindowType

func (*WindowType) AddBorder

func (w *WindowType) AddBorder() error

AddBorder takes the lines which were used to create regions to draw the border(s) for this window. Instantiating the border has side effects. The bottom/rightmost window will contain both a top AND bottom (left AND right) abstract line within the region. In an 80x24 window, you can draw a horizontal line at 12 and have 2 regions, 12 high. The line (once drawn) has to come from somewhere and since we are left-right/top-down oriented, the top(left) border is in the top(left) region and the new line IS the top(left) border of the bottom(right) region. This means that we can split the window into 2 regions 12 high, but if we draw borders, the top is then 11 high and the bottom is 10 high. The border belongs to the containing window. That said, NOT instantiating a window's borders means subordinate objects may use the full area, including windows which draw their own borders. Drawing borders in the containing window means that we can use one character to separate objects instead of 2. Drawing borders in the containing window may be a requirement of resizing.

func (*WindowType) AddChild

func (w *WindowType) AddChild(o Object)

func (*WindowType) AddComm

func (w *WindowType) AddComm(c IChing)

func (*WindowType) AddLine

func (w *WindowType) AddLine(l1, l2 *Line, n int) (*Line, error)

AddLine creates a new line orthogonal to l1 and l2 at a distnace n from p1 of the left/top line. Each new line must have end points on an existing line. When a New Window is created, the first 4 lines are established. These represent the edges of the window. This will define a single "region" should GetRegion be called. The correct order is to add any additional lines to the parent window using NewLine and then call GetRegion/NewWindow to create the non-overlapping subordinate windows. Although there is no reason this can't be done in any window, the idea was to allow one to establish regions, have the borders drawn and not waste any more real estate.

Every new line divides at least one region, invalidating it/them and adding 2 for each one invalidated.

func (*WindowType) Ancestor

func (w *WindowType) Ancestor() Container

func (*WindowType) Border

func (w *WindowType) Border() bool

func (*WindowType) Bottom

func (w *WindowType) Bottom() *Line

func (*WindowType) Clear

func (w *WindowType) Clear()

func (*WindowType) Colors

func (w *WindowType) Colors() (Attribute, Attribute)

func (*WindowType) Done

func (w *WindowType) Done()

func (*WindowType) EventMgr

func (w *WindowType) EventMgr()

func (*WindowType) GetComm

func (w *WindowType) GetComm() []IChing

func (*WindowType) GetRegion

func (w *WindowType) GetRegion(n int) *Region

Return the position/dimensions of the region n.

func (*WindowType) HorizLines

func (w *WindowType) HorizLines() []Line

From a window's "lines" array, that was used to create regions, return only the horizontal lines.

func (*WindowType) Init

func (w *WindowType) Init() error

Make WindowType an Object.

func (*WindowType) Left

func (w *WindowType) Left() *Line

This is the left edge of the window in it's container's coordinates.

func (*WindowType) Lines

func (w *WindowType) Lines() []Line

func (*WindowType) Loc

func (w *WindowType) Loc() (int, int)

func (*WindowType) Main

func (w *WindowType) Main()

Make WindowType a Window.

func (*WindowType) Manage

func (w *WindowType) Manage(o Object) error

Make WindowType a Container.

func (*WindowType) Managed

func (w *WindowType) Managed() bool

func (*WindowType) Refresh

func (w *WindowType) Refresh()

func (*WindowType) Regions

func (w *WindowType) Regions() []Region

func (*WindowType) Right

func (w *WindowType) Right() *Line

func (*WindowType) SetAncestor

func (w *WindowType) SetAncestor(p Container)

func (*WindowType) SetColors

func (w *WindowType) SetColors(fg, bg Attribute)

func (*WindowType) SetLoc

func (w *WindowType) SetLoc(x, y int)

func (*WindowType) SetManaged

func (w *WindowType) SetManaged()

func (*WindowType) SetSize

func (w *WindowType) SetSize(width, height int)

func (*WindowType) Size

func (w *WindowType) Size() (int, int)

func (*WindowType) Top

func (w *WindowType) Top() *Line

func (*WindowType) VertLines

func (w *WindowType) VertLines() []Line

Jump to

Keyboard shortcuts

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