gonsole

package module
v0.0.0-...-c70c77a Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2016 License: MIT Imports: 5 Imported by: 0

README

gonsole

This project offers a high level user interface library for golang.

Example

asciicast

Projects used

See also

  • blessed – A high-level terminal interface library for node.js.
  • termui – Golang terminal dashboard

License

See here

Battle Plan

v0.1
Basics
  • Focus handling
  • Event Dispatching/Bubbling
  • Event Registering/Defining
  • Text rendering (multiline, alignment)
Controls
  • Panel
  • Label
  • Button
  • Edit
  • Checkbox
  • Radiobutton
  • List
  • Dropdown
v0.2
Basics
  • Theming (Colors, Chars)
  • Mouse Support
  • LayoutManager
Controls
  • Textarea
  • Slider
  • Spinner
  • Dialog (Modal)
  • ProgressBar
v0.3
Basics
  • Performance Optimizations
Controls
  • Menu
  • Toolbar
  • Statusbar
  • Tree
  • Grid
  • ContextMenu

Documentation

Overview

Higher level helper functions for termbox TODO support theming

Index

Constants

View Source
const (
	LineNone = iota
	LineTransparent
	LineSingle
	LineSingleCorners
	LineDouble
	LineDoubleCorners
	LineDashed
	LineDotted
)
View Source
const (
	HorizontalAlignmentLeft = iota
	HorizontalAlignmentCenter
	HorizontalAlignmentRight
)
View Source
const (
	HorizontalAlignmentTop = iota
	HorizontalAlignmentMiddle
	HorizontalAlignmentBottom
)

Variables

This section is empty.

Functions

func ClearRect

func ClearRect(box Box, color, backgroundColor termbox.Attribute)

func DrawBorder

func DrawBorder(box Box, lineType LineType, color, backgroundColor termbox.Attribute)

func DrawCursor

func DrawCursor()

func DrawLineHorizontal

func DrawLineHorizontal(left, top, width int, lineType LineType, color, backgroundColor termbox.Attribute)

func DrawLineVertical

func DrawLineVertical(left, top, height int, lineType LineType, color, backgroundColor termbox.Attribute)

func DrawTextBox

func DrawTextBox(text string, box Box, foreground termbox.Attribute, background termbox.Attribute)

TODO support line breaking for multiline strings TODO support alignment

func DrawTextSimple

func DrawTextSimple(text string, box Box, foreground termbox.Attribute, background termbox.Attribute)

func FillRect

func FillRect(box Box, color, backgroundColor termbox.Attribute)

Types

type App

type App struct {
	CloseKey        termbox.Key
	EventDispatcher *EventDispatcher
	// contains filtered or unexported fields
}

App holds the global gonsole state.

func NewApp

func NewApp() *App

NewApp creates a new app

func (*App) ActivateWindow

func (app *App) ActivateWindow(win *Window)

func (*App) AddWindow

func (app *App) AddWindow(win *Window)

func (*App) Repaint

func (app *App) Repaint()

func (*App) Run

func (app *App) Run()

type BasicControl

type BasicControl struct {
	Position Position
	Visible  bool
	Enabled  bool

	ZIndex   int
	TabIndex int

	// styling
	Foreground termbox.Attribute
	Background termbox.Attribute

	HAlign  HorizontalAlignment
	VAlign  VerticalAlignment
	Margin  Sides
	Padding Sides
	// contains filtered or unexported fields
}

Control is the base model for a UI control

func (*BasicControl) AddEventListener

func (ctrl *BasicControl) AddEventListener(eventType string, handler func(ev *Event) bool)

func (*BasicControl) Border

func (ctrl *BasicControl) Border() LineType

func (*BasicControl) BorderBox

func (ctrl *BasicControl) BorderBox() Box

func (*BasicControl) ContentBox

func (ctrl *BasicControl) ContentBox() Box

func (*BasicControl) Dirty

func (ctrl *BasicControl) Dirty() bool

func (*BasicControl) DrawBorder

func (ctrl *BasicControl) DrawBorder()

func (*BasicControl) Focus

func (ctrl *BasicControl) Focus()

func (*BasicControl) Focussable

func (ctrl *BasicControl) Focussable() bool

func (*BasicControl) Focussed

func (ctrl *BasicControl) Focussed() bool

func (*BasicControl) GetAbsolutePosition

func (ctrl *BasicControl) GetAbsolutePosition() Box

func (*BasicControl) HasBorder

func (ctrl *BasicControl) HasBorder() bool

func (*BasicControl) ID

func (ctrl *BasicControl) ID() string

func (*BasicControl) Init

func (ctrl *BasicControl) Init(id string)

func (*BasicControl) Parent

func (ctrl *BasicControl) Parent() Control

func (*BasicControl) ParseEvent

func (ctrl *BasicControl) ParseEvent(ev *termbox.Event) bool

func (*BasicControl) Pollute

func (ctrl *BasicControl) Pollute()

func (*BasicControl) Repaint

func (ctrl *BasicControl) Repaint()

func (*BasicControl) SetBorder

func (ctrl *BasicControl) SetBorder(border LineType)

func (*BasicControl) SetFocussable

func (ctrl *BasicControl) SetFocussable(focussable bool)

func (*BasicControl) SetID

func (ctrl *BasicControl) SetID(id string)

func (*BasicControl) SetParent

func (ctrl *BasicControl) SetParent(parent Control)

func (*BasicControl) SetWindow

func (ctrl *BasicControl) SetWindow(win *Window)

func (*BasicControl) SubmitEvent

func (ctrl *BasicControl) SubmitEvent(ev *Event)

func (*BasicControl) Window

func (ctrl *BasicControl) Window() *Window

type Box

type Box struct {
	Left   int
	Top    int
	Width  int
	Height int
}

func (Box) Absolute

func (b Box) Absolute(bParent Box) Box

func (Box) Bottom

func (b Box) Bottom() int

func (Box) Minus

func (b Box) Minus(s Sides) Box

func (Box) Plus

func (b Box) Plus(s Sides) Box

func (Box) Position

func (b Box) Position() Position

func (Box) Right

func (b Box) Right() int

type Button

type Button struct {
	BasicControl

	// custom
	Text string
}

func NewButton

func NewButton(id string) *Button

func (*Button) ParseEvent

func (btn *Button) ParseEvent(ev *termbox.Event) bool

func (*Button) Repaint

func (c *Button) Repaint()

type Checkbox

type Checkbox struct {
	BasicControl

	// custom
	Text    string
	Checked bool
	// contains filtered or unexported fields
}

func NewCheckbox

func NewCheckbox(id string) *Checkbox

func (*Checkbox) ParseEvent

func (chk *Checkbox) ParseEvent(ev *termbox.Event) bool

func (*Checkbox) Repaint

func (c *Checkbox) Repaint()

type Container

type Container interface {
	Control
	Children() []Control
	ChildrenDeep() []Control
}

type ContainerControl

type ContainerControl struct {
	BasicControl
	// contains filtered or unexported fields
}

func (*ContainerControl) AddControl

func (ctrl *ContainerControl) AddControl(control Control)

func (*ContainerControl) Children

func (ctrl *ContainerControl) Children() []Control

func (*ContainerControl) ChildrenDeep

func (ctrl *ContainerControl) ChildrenDeep() []Control

func (*ContainerControl) Repaint

func (ctrl *ContainerControl) Repaint()

type Control

type Control interface {
	ID() string
	SetID(id string)
	Init(id string)

	Focussed() bool
	Focus()
	Focussable() bool
	SetFocussable(focussable bool)

	SetWindow(win *Window)
	Window() *Window

	Parent() Control
	SetParent(parent Control)

	Border() LineType
	SetBorder(lineType LineType)
	HasBorder() bool

	Dirty() bool
	Pollute()
	Repaint()

	GetAbsolutePosition() Box
	ContentBox() Box

	// return true if event was parsed and should not continue bubbling up
	ParseEvent(ev *termbox.Event) bool
	SubmitEvent(ev *Event)
	AddEventListener(eventType string, handler func(ev *Event) bool)
}

type Event

type Event struct {
	Type   string
	Source Control
	Data   map[string]interface{}
}

type EventDispatcher

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

func NewEventDispatcher

func NewEventDispatcher() *EventDispatcher

func (*EventDispatcher) AddEventListener

func (ed *EventDispatcher) AddEventListener(source Control, eventType string, handler func(ev *Event) bool)

func (*EventDispatcher) SubmitEvent

func (ed *EventDispatcher) SubmitEvent(ev *Event)

type HorizontalAlignment

type HorizontalAlignment int

type Label

type Label struct {
	BasicControl
	Text string
}

func NewLabel

func NewLabel(id string) *Label

func (*Label) Repaint

func (l *Label) Repaint()

type LineType

type LineType int

type Panel

type Panel struct {
	ContainerControl

	// custom
	Title string
}

func NewPanel

func NewPanel(id string) *Panel

func (*Panel) Repaint

func (c *Panel) Repaint()

type Position

type Position struct {
	Left   string
	Top    string
	Width  string
	Height string
}

func (Position) Box

func (p Position) Box(w, h int) Box

type Sides

type Sides struct {
	Top    int
	Right  int
	Bottom int
	Left   int
}

func (Sides) Minus

func (s Sides) Minus(s2 Sides) Sides

func (Sides) Plus

func (s Sides) Plus(s2 Sides) Sides

type VerticalAlignment

type VerticalAlignment int

type Window

type Window struct {
	App        *App
	ID         string
	Width      int
	Height     int
	Background termbox.Attribute
	Foreground termbox.Attribute
	// contains filtered or unexported fields
}

Window is the top-level struct in gonsole library.

func NewWindow

func NewWindow(id string) *Window

NewWindow creates a new window for later display

func (*Window) AddControl

func (win *Window) AddControl(ctrl Control)

func (*Window) FocusNext

func (win *Window) FocusNext()

func (*Window) FocusPrev

func (win *Window) FocusPrev()

func (*Window) FocussedControl

func (win *Window) FocussedControl() Control

func (*Window) FullRepaint

func (win *Window) FullRepaint()

func (*Window) GetControls

func (win *Window) GetControls() []Control

func (*Window) IsDirty

func (win *Window) IsDirty() bool

IsDirty returns true if the window is marked as dirty

func (*Window) ParseEvent

func (win *Window) ParseEvent(ev *termbox.Event) bool

return true if event was parsed and should not continue bubbling up

func (*Window) Pollute

func (win *Window) Pollute()

func (*Window) Repaint

func (win *Window) Repaint()

Repaint the window

func (*Window) SetFocussedControl

func (win *Window) SetFocussedControl(ctrl Control)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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