gonsole

package module
v0.0.0-...-56430bd Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2016 License: MIT Imports: 8 Imported by: 1

README

Battle Plan

v0.1

Basics

  • Focus handling
  • Event Dispatching/Bubbling
  • Event Registering/Defining
  • Text rendering (multiline, alignment)
Controls
  • Panel
  • Label
  • Button
  • Edit
  • Checkbox
  • Radiobutton
  • Dropdown
  • ProgressBar
  • Dialog (Modal)

v0.2

Basics

  • Theming (Colors, Chars)
  • Mouse Support
  • LayoutManager
Controls
  • Textarea
  • List
  • Slider
  • Spinner

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 DrawBorder

func DrawBorder(box Box, lineType LineType, fg, bg termbox.Attribute)

func DrawCursor

func DrawCursor(x, y int)

func DrawLineHorizontal

func DrawLineHorizontal(left, top, width int, ch rune, fg, bg termbox.Attribute)

func DrawLineVertical

func DrawLineVertical(left, top, height int, ch rune, fg, bg termbox.Attribute)

func DrawScrollBar

func DrawScrollBar(left, top, height, pos int, fg, bg termbox.Attribute)

func DrawShadow

func DrawShadow(box Box, shadow termbox.Attribute)

func DrawTextBox

func DrawTextBox(text string, box Box, fg, bg termbox.Attribute)

TODO support line breaking for multiline strings TODO support alignment

func DrawTextSimple

func DrawTextSimple(text string, fill bool, box Box, fg, bg termbox.Attribute)

func FillRect

func FillRect(box Box, fg, bg termbox.Attribute)

func HideCursor

func HideCursor()

func ScrollPos

func ScrollPos(index, count, height int) int

Types

type App

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

App holds the global gonsole state.

func NewApp

func NewApp() *App

NewApp creates a new app

func (*App) AddEventListener

func (app *App) AddEventListener(key termbox.Key, handler func())

func (*App) ID

func (app *App) ID() string

func (*App) Redraw

func (app *App) Redraw()

func (*App) Repaint

func (app *App) Repaint()

func (*App) Run

func (app *App) Run()

func (*App) SetTheme

func (app *App) SetTheme(theme *Theme)

func (*App) Stop

func (app *App) Stop()

func (*App) Theme

func (app *App) Theme() *Theme

type AppWindow

type AppWindow interface {
	Container

	App() *App
	Close()

	FocusedControl() Control
	FocusControl(control Control)
}

A window which is a top level container for controls. TODO: a better name for this interface. ideally "window"

type Attribute

type Attribute uint16
const (
	ColorDefault Attribute = iota
	ColorBlack
	ColorRed
	ColorGreen
	ColorYellow
	ColorBlue
	ColorMagenta
	ColorCyan
	ColorWhite
)
const (
	AttrBold Attribute = 1 << (iota + 9)
	AttrUnderline
	AttrReverse
)

func ColorRGB

func ColorRGB(r, g, b int) Attribute

type BaseContainer

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

func (*BaseContainer) AddControl

func (c *BaseContainer) AddControl(ctrl Control)

func (*BaseContainer) Children

func (c *BaseContainer) Children() []Control

func (*BaseContainer) ChildrenDeep

func (c *BaseContainer) ChildrenDeep() []Control

func (*BaseContainer) DirtyChildren

func (c *BaseContainer) DirtyChildren() bool

func (*BaseContainer) RepaintChildren

func (c *BaseContainer) RepaintChildren()

func (*BaseContainer) SetTitle

func (c *BaseContainer) SetTitle(title string)

func (*BaseContainer) Title

func (c *BaseContainer) Title() string

type BaseControl

type BaseControl struct {
	BaseElement
	// contains filtered or unexported fields
}

Control is the base model for a UI control

func (*BaseControl) Cursorable

func (c *BaseControl) Cursorable() bool

func (*BaseControl) Focus

func (c *BaseControl) Focus()

func (*BaseControl) Focusable

func (c *BaseControl) Focusable() bool

func (*BaseControl) Focused

func (c *BaseControl) Focused() bool

func (*BaseControl) Repaint

func (c *BaseControl) Repaint()

func (*BaseControl) SetCursorable

func (c *BaseControl) SetCursorable(cursorable bool)

func (*BaseControl) SetFocusable

func (c *BaseControl) SetFocusable(focusable bool)

type BaseElement

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

func (*BaseElement) AbsolutePosition

func (e *BaseElement) AbsolutePosition() Box

func (*BaseElement) BorderBox

func (e *BaseElement) BorderBox() Box

func (*BaseElement) BorderColors

func (e *BaseElement) BorderColors() (fg Attribute, bg Attribute)

func (*BaseElement) BorderType

func (e *BaseElement) BorderType() LineType

func (*BaseElement) Colors

func (e *BaseElement) Colors() (fg Attribute, bg Attribute)

func (*BaseElement) ContentBox

func (e *BaseElement) ContentBox() Box

func (*BaseElement) Dirty

func (e *BaseElement) Dirty() bool

func (*BaseElement) Enabled

func (e *BaseElement) Enabled() bool

func (*BaseElement) FocusColors

func (e *BaseElement) FocusColors() (fg Attribute, bg Attribute)

func (*BaseElement) GetWindow

func (e *BaseElement) GetWindow() AppWindow

func (*BaseElement) ID

func (e *BaseElement) ID() string

func (*BaseElement) Init

func (e *BaseElement) Init(window AppWindow, parent Container, id, themePrefix string)

func (*BaseElement) Margin

func (e *BaseElement) Margin() Sides

func (*BaseElement) Padding

func (e *BaseElement) Padding() Sides

func (*BaseElement) Parent

func (e *BaseElement) Parent() Container

func (*BaseElement) ParseEvent

func (e *BaseElement) ParseEvent(ev *termbox.Event) (handled, repaint bool)

func (*BaseElement) Position

func (e *BaseElement) Position() Position

func (*BaseElement) SetBorderColors

func (e *BaseElement) SetBorderColors(fg Attribute, bg Attribute)

func (*BaseElement) SetBorderType

func (e *BaseElement) SetBorderType(border LineType)

func (*BaseElement) SetColors

func (e *BaseElement) SetColors(fg Attribute, bg Attribute)

func (*BaseElement) SetDirty

func (e *BaseElement) SetDirty(dirty bool)

func (*BaseElement) SetEnabled

func (e *BaseElement) SetEnabled(enabled bool)

func (*BaseElement) SetFocusColors

func (e *BaseElement) SetFocusColors(fg Attribute, bg Attribute)

func (*BaseElement) SetMargin

func (e *BaseElement) SetMargin(margins Sides)

func (*BaseElement) SetPadding

func (e *BaseElement) SetPadding(paddings Sides)

func (*BaseElement) SetPosition

func (e *BaseElement) SetPosition(pos Position)

func (*BaseElement) SetShadowColor

func (e *BaseElement) SetShadowColor(color Attribute)

func (*BaseElement) SetShadowType

func (e *BaseElement) SetShadowType(shadow LineType)

func (*BaseElement) ShadowColor

func (e *BaseElement) ShadowColor() Attribute

func (*BaseElement) ShadowType

func (e *BaseElement) ShadowType() LineType

func (*BaseElement) Theme

func (e *BaseElement) Theme() *Theme

type BaseWindow

type BaseWindow struct {
	BaseElement
	BaseContainer
	// contains filtered or unexported fields
}

Window is the top-level struct in gonsole library.

func (*BaseWindow) App

func (win *BaseWindow) App() *App

func (*BaseWindow) Close

func (win *BaseWindow) Close()

func (*BaseWindow) Focus

func (win *BaseWindow) Focus()

func (*BaseWindow) FocusControl

func (win *BaseWindow) FocusControl(control Control)

func (*BaseWindow) Focused

func (win *BaseWindow) Focused() bool

func (*BaseWindow) FocusedControl

func (win *BaseWindow) FocusedControl() Control

func (*BaseWindow) Init

func (win *BaseWindow) Init(app *App, id string)

func (*BaseWindow) OnClose

func (win *BaseWindow) OnClose(handler func())

func (*BaseWindow) ParseEvent

func (win *BaseWindow) ParseEvent(ev *termbox.Event) (handled, repaint bool)

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

func (*BaseWindow) Repaint

func (win *BaseWindow) Repaint()

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 {
	BaseControl
	// contains filtered or unexported fields
}

func NewButton

func NewButton(win AppWindow, parent Container, id string) *Button

func (*Button) OnClick

func (b *Button) OnClick(handler func())

func (*Button) ParseEvent

func (b *Button) ParseEvent(ev *termbox.Event) (handled, repaint bool)

func (*Button) Repaint

func (b *Button) Repaint()

func (*Button) SetText

func (b *Button) SetText(text string)

func (*Button) Text

func (b *Button) Text() string

type Checkbox

type Checkbox struct {
	BaseControl
	// contains filtered or unexported fields
}

func NewCheckbox

func NewCheckbox(win AppWindow, parent Container, id string) *Checkbox

func (*Checkbox) Checked

func (c *Checkbox) Checked() bool

func (*Checkbox) OnChange

func (c *Checkbox) OnChange(handler func(checked bool))

func (*Checkbox) ParseEvent

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

func (*Checkbox) Repaint

func (c *Checkbox) Repaint()

func (*Checkbox) SeChecked

func (c *Checkbox) SeChecked(checked bool)

func (*Checkbox) SetText

func (c *Checkbox) SetText(text string)

func (*Checkbox) Text

func (c *Checkbox) Text() string

type Container

type Container interface {
	Element

	Title() string
	SetTitle(title string)

	AddControl(control Control)

	Children() []Control
	ChildrenDeep() []Control
}

An element that is a container for controls

type Control

type Control interface {
	Element

	Focusable() bool
	SetFocusable(active bool)

	Cursorable() bool
	SetCursorable(cursorable bool)
}

A control which is an element that can optional be focused

type Edit

type Edit struct {
	BaseControl
	// contains filtered or unexported fields
}

func NewEdit

func NewEdit(win AppWindow, parent Container, id string) *Edit

func (*Edit) MaxWidth

func (e *Edit) MaxWidth() int

func (*Edit) OnSubmit

func (e *Edit) OnSubmit(handler func(string))

func (*Edit) ParseEvent

func (e *Edit) ParseEvent(ev *termbox.Event) (handled, repaint bool)

func (*Edit) Repaint

func (e *Edit) Repaint()

func (*Edit) SetMaxWidth

func (e *Edit) SetMaxWidth(width int)

func (*Edit) SetValue

func (e *Edit) SetValue(value string)

func (*Edit) Value

func (e *Edit) Value() string

type Element

type Element interface {
	GetWindow() AppWindow
	Parent() Container
	ID() string

	Dirty() bool
	SetDirty(dirty bool)

	Enabled() bool
	SetEnabled(enabled bool)

	Focused() bool
	Focus()

	Position() Position
	SetPosition(pos Position)

	Margin() Sides
	SetMargin(margins Sides)

	Padding() Sides
	SetPadding(margins Sides)

	Colors() (fg Attribute, bg Attribute)
	SetColors(fg Attribute, bg Attribute)

	FocusColors() (fg Attribute, bg Attribute)
	SetFocusColors(fg Attribute, bg Attribute)

	BorderType() LineType
	SetBorderType(border LineType)

	BorderColors() (fg Attribute, bg Attribute)
	SetBorderColors(fg Attribute, bg Attribute)

	AbsolutePosition() Box
	BorderBox() Box
	ContentBox() Box

	ParseEvent(ev *termbox.Event) (handled, repaint bool)

	Repaint()

	Theme() *Theme
}

An UI element. It has a position, margin, padding, colors and other style properties.

type HorizontalAlignment

type HorizontalAlignment int

type InputDialog

type InputDialog struct {
	BaseWindow
	// contains filtered or unexported fields
}

func NewInputDialog

func NewInputDialog(app *App, id, title, message string, buttons []string) *InputDialog

func (*InputDialog) InputValue

func (d *InputDialog) InputValue() string

func (*InputDialog) SelectedButton

func (d *InputDialog) SelectedButton() int

type Label

type Label struct {
	BaseControl
	// contains filtered or unexported fields
}

func NewLabel

func NewLabel(win AppWindow, parent Container, id string) *Label

func (*Label) Repaint

func (l *Label) Repaint()

func (*Label) SetText

func (l *Label) SetText(text string)

func (*Label) Text

func (l *Label) Text() string

type LineType

type LineType int

type List

type List struct {
	BaseControl
	// contains filtered or unexported fields
}

func NewList

func NewList(win AppWindow, parent Container, id string) *List

func (*List) OnSumbit

func (l *List) OnSumbit(handler func(int))

func (*List) Options

func (l *List) Options() []string

func (*List) ParseEvent

func (l *List) ParseEvent(ev *termbox.Event) (handled, repaint bool)

func (*List) Repaint

func (l *List) Repaint()

func (*List) SelectedItem

func (l *List) SelectedItem() int

func (*List) SetOptions

func (l *List) SetOptions(options []string)

type MessageDialog

type MessageDialog struct {
	BaseWindow
	// contains filtered or unexported fields
}

func NewMessageDialog

func NewMessageDialog(app *App, id, title, message string, buttons []string) *MessageDialog

func (*MessageDialog) SelectedButton

func (d *MessageDialog) SelectedButton() int

type Panel

type Panel struct {
	BaseControl
	BaseContainer
}

func NewPanel

func NewPanel(win *Window, parent Container, id string) *Panel

func (*Panel) Repaint

func (p *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 Progress

type Progress struct {
	BaseControl
	// contains filtered or unexported fields
}

func NewProgress

func NewProgress(win *Window, parent Container, id string) *Progress

func (*Progress) Repaint

func (p *Progress) Repaint()

func (*Progress) SetValue

func (p *Progress) SetValue(value float32)

func (*Progress) Value

func (p *Progress) Value() float32

type SelectionDialog

type SelectionDialog struct {
	BaseWindow
	// contains filtered or unexported fields
}

func NewSelectionDialog

func NewSelectionDialog(app *App, id, title, message string, buttons []string, items []string) *SelectionDialog

func (*SelectionDialog) SelectedButton

func (d *SelectionDialog) SelectedButton() int

func (*SelectionDialog) SelectedItem

func (d *SelectionDialog) SelectedItem() int

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 Theme

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

func NewTheme

func NewTheme(prefix string, baseTheme *Theme) *Theme

func (*Theme) Border

func (t *Theme) Border(key string) LineType

func (*Theme) Color

func (t *Theme) Color(key string) Attribute

func (*Theme) ColorTermbox

func (t *Theme) ColorTermbox(key string) termbox.Attribute

func (*Theme) SetBorder

func (t *Theme) SetBorder(key string, border LineType)

func (*Theme) SetColor

func (t *Theme) SetColor(key string, color Attribute)

type VerticalAlignment

type VerticalAlignment int

type Window

type Window struct {
	BaseWindow
}

Window is the top-level struct in gonsole library.

func NewWindow

func NewWindow(app *App, id string) *Window

NewWindow creates a new window for later display

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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