Documentation ¶
Overview ¶
Copyright (c) 2016 Company 0, LLC. Use of this source code is governed by an ISC license that can be found in the LICENSE file.
Index ¶
- Constants
- Variables
- func Color(at, fg, bg int) (string, error)
- func Deinit()
- func EscapedLen(s string) int
- func Exit(format string, args ...interface{})
- func Flush()
- func Focus(w *Window)
- func FocusPrevious()
- func ForwardKey(k Key)
- func Init() error
- func KeyChannel() chan Key
- func Panic(format string, args ...interface{})
- func Queue(f func())
- func Unescape(s string) string
- type Attributes
- type Cell
- type Edit
- func (e *Edit) CanFocus() bool
- func (e *Edit) Focus()
- func (e *Edit) GetText() string
- func (e *Edit) KeyHandler(ev termbox.Event) bool
- func (e *Edit) Render()
- func (e *Edit) Resize()
- func (e *Edit) SetAttributes(a Attributes)
- func (e *Edit) SetText(s *string, end bool)
- func (e *Edit) Visibility(op Visibility) Visibility
- type Justify
- type Key
- type Label
- func (l *Label) CanFocus() bool
- func (l *Label) Focus()
- func (l *Label) KeyHandler(ev termbox.Event) bool
- func (l *Label) Render()
- func (l *Label) Resize()
- func (l *Label) SetAttributes(a Attributes)
- func (l *Label) SetText(format string, args ...interface{})
- func (l *Label) Visibility(op Visibility) Visibility
- type List
- func (l *List) Append(format string, args ...interface{})
- func (l *List) CanFocus() bool
- func (l *List) Display(where Location)
- func (l *List) Focus()
- func (l *List) IsPaging() bool
- func (l *List) KeyHandler(ev termbox.Event) bool
- func (l *List) Len() int
- func (l *List) Render()
- func (l *List) Resize()
- func (l *List) SetAttributes(a Attributes)
- func (l *List) Visibility(op Visibility) Visibility
- func (l *List) Width() int
- type Location
- type Visibility
- type Widget
- type Widgeter
- type Window
- func (w *Window) AddEdit(x, y, width int, target *string) *Edit
- func (w *Window) AddLabel(x, y int, format string, args ...interface{}) *Label
- func (w *Window) AddList(x, y, width, height int) *List
- func (w *Window) AddStatus(y int, j Justify, format string, args ...interface{}) *Label
- func (w *Window) AddWidget(id string, x, y int) (Widgeter, error)
- func (w *Window) FocusNext()
- func (w *Window) FocusPrevious()
- type Windower
Constants ¶
const ( // see http://en.wikipedia.org/wiki/ANSI_escape_code#Colors ANSIFg = 30 ANSIBg = 40 AttrNA = -1 AttrReset = 0 AttrBold = 1 AttrUnderline = 3 AttrReverse = 7 ColorBlack = 0 ColorRed = 1 ColorGreen = 2 ColorYellow = 3 ColorBlue = 4 ColorMagenta = 5 ColorCyan = 6 ColorWhite = 7 )
const (
WidgetEdit = "edit"
)
WidgetEdit uniquely identifies the edit widget.
const (
WidgetLabel = "label"
)
WidgetLabel uniquely identifies the label widget.
const (
WidgetList = "list"
)
WidgetList uniquely identifies the list widget.
Variables ¶
var ( ErrNotEscSequence = errors.New("not an escape sequence") ErrInvalidColor = errors.New("invalid parameters for sequence") ErrInvalidAttribute = errors.New("invalid attribute") ErrInvalidForeground = errors.New("invalid foreground") ErrInvalidBackground = errors.New("invalid background") )
var ( // ErrAlreadyInitialized is used on reentrant calls of Init. ErrAlreadyInitialized = errors.New("terminal already initialized") )
var ( // ErrWidgetNotRegistered is generated when a NewWidget call is made // and the widget was not registered. Widgets must be registered so // that applications may define their own and fully participate in ttk // rules. ErrWidgetNotRegistered = errors.New("widget not registered") )
Functions ¶
func Deinit ¶
func Deinit()
Deinit switches the terminal back to cooked mode and it terminates managed window mode. Init must be called again if a switch is required again. Deinit shall be called on application exit; failing to do so may leave the terminal corrupted. If that does happen typing "reset" on the shell usually fixes this problem.
func EscapedLen ¶
EscapedLen returns total length of all escape sequences in a given string.
func Exit ¶
func Exit(format string, args ...interface{})
Exit application but deinit first so that the terminal will not be corrupt.
func Focus ¶
func Focus(w *Window)
Focus on provided window. This will implicitly focus on a window widget that can have focus. Render and flush it onto the terminal.
func FocusPrevious ¶
func FocusPrevious()
FocusPrevious focus on previous focused window. This will implicitly focus on a window widget that can have focus. Render and flush it onto the terminal.
func ForwardKey ¶
func ForwardKey(k Key)
ForwardKey must be called from the application to route key strokes to windows. The life cycle of keystrokes is as follows: widgets -> global application context -> window. Care must be taken in the application to not rely on keystrokes that widgets may use.
func Init ¶
func Init() error
Init switches the terminal to raw mode and commences managed window mode. This function shall be called prior to any ttk calls.
func KeyChannel ¶
func KeyChannel() chan Key
KeyChannel returns the the Key channel that can be used in the application to handle keystrokes.
Types ¶
type Attributes ¶
type Attributes struct { Fg termbox.Attribute // foreground Bg termbox.Attribute // background }
Attributes represents attributes which are defined as text color, bold, blink etc.
func DecodeColor ¶
func DecodeColor(esc string) (*Attributes, int, error)
DecodeColor decodes an ANSI color escape sequence and ignores trailing characters. It returns an Attributes type that can be used directly in termbox (note that the termbox colors are off by one). The skip contains the location of the next character that was not consumed by the escape sequence.
func DefaultAttributes ¶
func DefaultAttributes() Attributes
DefaultAttributes returns the default attributes. This is a blocking call.
type Cell ¶
type Cell struct { termbox.Cell // anon since we are only adding the dirty bit // contains filtered or unexported fields }
Cell contains a single screen cell. This structure exists in order to mark cells that require rendering. This is required in order to only render deltas, this matters over slow links.
type Edit ¶
type Edit struct { Widget // contains filtered or unexported fields }
Edit is a text entry widget. It prints the contents of target onto the window. Note: all spaces are trimmed before and after the target string.
func (*Edit) CanFocus ¶
CanFocus implements the interface. This is called from queue context so be careful to not use blocking calls.
func (*Edit) Focus ¶
func (e *Edit) Focus()
Focus implements the interface. This is called from queue context so be careful to not use blocking calls.
func (*Edit) KeyHandler ¶
KeyHandler implements the interface. This is called from queue context so be careful to not use blocking calls.
func (*Edit) Render ¶
func (e *Edit) Render()
Render implements the Render interface. This is called from queue context so be careful to not use blocking calls.
func (*Edit) SetAttributes ¶
func (e *Edit) SetAttributes(a Attributes)
SetAttributes sets the Attributes. This will not be displayed immediately. SetAttributes shall be called from queue context.
func (*Edit) SetText ¶
SetText sets the edit text. if end is set to true the cursor and text will be set to the end of the string. This will not be displayed immediately. SetText shall be called from queue context.
func (*Edit) Visibility ¶
func (e *Edit) Visibility(op Visibility) Visibility
type Justify ¶
type Justify int
Justify is used to determine where text is printed on the Status widget (special Label)
type Key ¶
type Key struct { Mod termbox.Modifier // key modifier Key termbox.Key // special key Ch rune // normal key Window Windower // window that contains widget Widget Widgeter // widget that emitted key }
Key contains a key stroke and possible modifiers.
type Label ¶
type Label struct { Widget // contains filtered or unexported fields }
Label is a text only widget. It prints the contents of text onto the window.
func (*Label) CanFocus ¶
CanFocus implements the interface. This is called from queue context so be careful to not use blocking calls.
func (*Label) Focus ¶
func (l *Label) Focus()
Focus implements the interface. This is called from queue context so be careful to not use blocking calls.
func (*Label) KeyHandler ¶
KeyHandler implements the interface. This is called from queue context so be careful to not use blocking calls.
func (*Label) Render ¶
func (l *Label) Render()
Render implements the Render interface. This is called from queue context so be careful to not use blocking calls.
func (*Label) SetAttributes ¶
func (l *Label) SetAttributes(a Attributes)
SetAttributes sets the Attributes. This will not be displayed immediately. SetAttributes shall be called from queue context.
func (*Label) SetText ¶
SetText sets the label caption. This will not be displayed immediately. SetText shall be called from queue context.
func (*Label) Visibility ¶
func (l *Label) Visibility(op Visibility) Visibility
type List ¶
type List struct { Widget // contains filtered or unexported fields }
List is a text only widget. It prints the contents of text onto the window.
func (*List) CanFocus ¶
CanFocus implements the interface. This is called from queue context so be careful to not use blocking calls.
func (*List) Display ¶
Display renders the widget. This is called from queue context so be careful to not use blocking calls.
func (*List) Focus ¶
func (l *List) Focus()
Focus implements the interface. This is called from queue context so be careful to not use blocking calls.
func (*List) IsPaging ¶
IsPaging indicates if the widget is displaying bottom line. If the bottom line is being displayed it means that the appended text is rendered.
func (*List) KeyHandler ¶
KeyHandler implements the interface. This is called from queue context so be careful to not use blocking calls.
func (*List) Render ¶
func (l *List) Render()
Render implements the Render interface. This is called from queue context so be careful to not use blocking calls.
func (*List) SetAttributes ¶
func (l *List) SetAttributes(a Attributes)
SetAttributes sets the Attributes. This will not be displayed immediately. SetAttributes shall be called from queue context.
func (*List) Visibility ¶
func (l *List) Visibility(op Visibility) Visibility
type Visibility ¶
type Visibility int
const ( VisibilityGet Visibility = iota VisibilityHide VisibilityShow )
type Widget ¶
type Widget struct {
// contains filtered or unexported fields
}
Widget is the base structure of all widgets.
func MakeWidget ¶
MakeWidget creates a generic Widget structure.
type Widgeter ¶
type Widgeter interface { CanFocus() bool // return true if widget can focus Focus() // Focus on widget Render() // Render the widget Resize() // Resize the widget KeyHandler(termbox.Event) bool // handle key strokes Visibility(Visibility) Visibility // show/hide widget }
Widgeter is the generic Widget interface. All widgets shall conform to it. Since the Widgeter functions are called from queue context the Widget must take care to not call blocking queue context calls.
func NewEdit ¶
NewEdit is the Edit initializer. This call implements the NewWidget convention by taking a *Window and and an anchor point to render the widget.
type Window ¶
type Window struct {
// contains filtered or unexported fields
}
Window contains a window context.
func (*Window) AddEdit ¶
AddEdit is a convenience function to add a new edit to a window. Capacity and width determine the maxima of the returned value. It wraps the AddWidget call. AddEdit must be called from queue.
func (*Window) AddLabel ¶
AddLabel is a convenience function to add a new label to a window. It wraps the AddWidget call. AddLabel must be called from queue.
func (*Window) AddList ¶
AddList is a convenience function to add a new list to a window. It wraps the AddWidget call. AddList must be called from queue.
func (*Window) AddStatus ¶
AddStatus is an alternative Label initializer. A Status is a label that has the property that it fills an entire line and is justified. This call implements the NewWidget convention by taking a *Window and and an anchor point to render the widget.
func (*Window) AddWidget ¶
AddWidget is the generic function to add a widget to a window. This function should only be called by widgets. Application code, by convention, should call the non-generic type asserted call (i.e. AddLabel). AddWidget shall be called from queue context.
func (*Window) FocusNext ¶
func (w *Window) FocusNext()
FocusNext focuses on the next available widget.
func (*Window) FocusPrevious ¶
func (w *Window) FocusPrevious()
FocusPrevious focuses on the next available widget.