Documentation ¶
Index ¶
- Constants
- Variables
- func AppDraw()
- func AppFini()
- func AppInit() error
- func AppLock()
- func AppRedraw()
- func AppUnlock()
- func RunApplication()
- func SetApplication(app Widget)
- type Attribute
- type CellModel
- type CellView
- func (a *CellView) Draw()
- func (a *CellView) HandleEvent(e Event) bool
- func (a *CellView) MakeCursorVisible()
- func (a *CellView) MakeVisible(x, y int)
- func (a *CellView) Resize()
- func (a *CellView) SetCursor(x, y int)
- func (a *CellView) SetCursorX(x int)
- func (a *CellView) SetCursorY(y int)
- func (a *CellView) SetModel(model CellModel)
- func (a *CellView) SetView(view View)
- type Event
- type KeyBar
- type KeyCode
- type KeyEvent
- type Panel
- type ResizeEvent
- type Screen
- type StatusBar
- func (s *StatusBar) Draw()
- func (s *StatusBar) HandleEvent(Event) bool
- func (s *StatusBar) Resize()
- func (s *StatusBar) SetFail()
- func (s *StatusBar) SetGood()
- func (s *StatusBar) SetNormal()
- func (s *StatusBar) SetStatus(text string)
- func (s *StatusBar) SetView(view View)
- func (s *StatusBar) SetWarn()
- type Style
- type TextArea
- func (ta *TextArea) Draw()
- func (ta *TextArea) EnableCursor(on bool)
- func (ta *TextArea) HandleEvent(ev Event) bool
- func (ta *TextArea) HideCursor(on bool)
- func (ta *TextArea) Resize()
- func (ta *TextArea) SetContent(text string)
- func (ta *TextArea) SetLines(lines []string)
- func (ta *TextArea) SetView(view View)
- type TextBar
- func (t *TextBar) Draw()
- func (t *TextBar) HandleEvent(Event) bool
- func (t *TextBar) Resize()
- func (t *TextBar) SetCenter(s string, style Style)
- func (t *TextBar) SetLeft(s string, style Style)
- func (t *TextBar) SetRight(s string, style Style)
- func (t *TextBar) SetStyle(style Style)
- func (t *TextBar) SetView(view View)
- type TitleBar
- type View
- type ViewPort
- func (v *ViewPort) Center(x, y int)
- func (v *ViewPort) Clear(s Style)
- func (v *ViewPort) GetContentSize() (int, int)
- func (v *ViewPort) MakeVisible(x, y int)
- func (v *ViewPort) Reset()
- func (v *ViewPort) Resize(x, y, width, height int)
- func (v *ViewPort) ScrollDown(rows int)
- func (v *ViewPort) ScrollLeft(cols int)
- func (v *ViewPort) ScrollRight(cols int)
- func (v *ViewPort) ScrollUp(rows int)
- func (v *ViewPort) SetCell(x, y int, ch rune, s Style)
- func (v *ViewPort) SetContentSize(width, height int)
- func (v *ViewPort) SetSize(width, height int)
- func (v *ViewPort) SetView(view View)
- func (v *ViewPort) Size() (int, int)
- func (v *ViewPort) ValidateView()
- func (v *ViewPort) ValidateViewX()
- func (v *ViewPort) ValidateViewY()
- type Widget
Constants ¶
const ( KeyF1 KeyCode = KeyCode(termbox.KeyF1) KeyF2 = KeyCode(termbox.KeyF2) KeyF3 = KeyCode(termbox.KeyF3) KeyF4 = KeyCode(termbox.KeyF4) KeyF5 = KeyCode(termbox.KeyF5) KeyF6 = KeyCode(termbox.KeyF6) KeyF7 = KeyCode(termbox.KeyF7) KeyF8 = KeyCode(termbox.KeyF8) KeyF9 = KeyCode(termbox.KeyF9) KeyF10 = KeyCode(termbox.KeyF10) KeyF11 = KeyCode(termbox.KeyF11) KeyF12 = KeyCode(termbox.KeyF12) KeyInsert = KeyCode(termbox.KeyInsert) KeyDelete = KeyCode(termbox.KeyDelete) KeyHome = KeyCode(termbox.KeyHome) KeyEnd = KeyCode(termbox.KeyEnd) KeyUp = KeyCode(termbox.KeyArrowUp) KeyDown = KeyCode(termbox.KeyArrowDown) KeyLeft = KeyCode(termbox.KeyArrowLeft) KeyRight = KeyCode(termbox.KeyArrowRight) KeyPgDn = KeyCode(termbox.KeyPgdn) KeyPgUp = KeyCode(termbox.KeyPgup) KeyCtrlA = KeyCode(termbox.KeyCtrlA) KeyCtrlB = KeyCode(termbox.KeyCtrlB) KeyCtrlC = KeyCode(termbox.KeyCtrlC) KeyCtrlD = KeyCode(termbox.KeyCtrlD) KeyCtrlE = KeyCode(termbox.KeyCtrlE) KeyCtrlF = KeyCode(termbox.KeyCtrlF) KeyCtrlG = KeyCode(termbox.KeyCtrlG) KeyCtrlH = KeyCode(termbox.KeyCtrlH) KeyCtrlI = KeyCode(termbox.KeyCtrlI) KeyCtrlJ = KeyCode(termbox.KeyCtrlJ) KeyCtrlK = KeyCode(termbox.KeyCtrlK) KeyCtrlL = KeyCode(termbox.KeyCtrlL) KeyCtrlM = KeyCode(termbox.KeyCtrlM) KeyCtrlN = KeyCode(termbox.KeyCtrlN) KeyCtrlO = KeyCode(termbox.KeyCtrlO) KeyCtrlP = KeyCode(termbox.KeyCtrlP) KeyCtrlQ = KeyCode(termbox.KeyCtrlQ) KeyCtrlR = KeyCode(termbox.KeyCtrlR) KeyCtrlS = KeyCode(termbox.KeyCtrlS) KeyCtrlT = KeyCode(termbox.KeyCtrlT) KeyCtrlU = KeyCode(termbox.KeyCtrlU) KeyCtrlV = KeyCode(termbox.KeyCtrlV) KeyCtrlW = KeyCode(termbox.KeyCtrlW) KeyCtrlX = KeyCode(termbox.KeyCtrlX) KeyCtrlY = KeyCode(termbox.KeyCtrlY) KeyCtrlZ = KeyCode(termbox.KeyCtrlZ) KeyTab = KeyCode(termbox.KeyTab) KeyBackspace = KeyCode(termbox.KeyBackspace) KeyEnter = KeyCode(termbox.KeyEnter) KeyEsc = KeyCode(termbox.KeyEsc) )
We take a very simplistic approach here, and do not expose every possible key code. Only those codes which are likely to be useful in real apps are listed. Applications shouldn't rely on non-portable key codes.
const ( ColorDefault Attribute = Attribute(termbox.ColorDefault) ColorBlack = Attribute(termbox.ColorBlack) ColorWhite = Attribute(termbox.ColorWhite) ColorRed = Attribute(termbox.ColorRed) ColorCyan = Attribute(termbox.ColorCyan) ColorGreen = Attribute(termbox.ColorGreen) ColorBlue = Attribute(termbox.ColorBlue) ColorYellow = Attribute(termbox.ColorYellow) ColorMagenta = Attribute(termbox.ColorMagenta) AttrBold = Attribute(termbox.AttrBold) AttrReverse = Attribute(termbox.AttrReverse) AttrUnderline = Attribute(termbox.AttrUnderline) )
Variables ¶
var ( StyleDefault = NewStyle(ColorWhite, ColorBlack) StyleText = NewStyle(ColorWhite, ColorBlack) StyleTextBar = NewStyle(ColorBlack, ColorWhite) StyleTitle = NewStyle(ColorBlack, ColorWhite) StyleGood = NewStyle(ColorGreen, ColorBlack) StyleError = NewStyle(ColorRed, ColorBlack) StyleWarn = NewStyle(ColorYellow, ColorBlack) StyleStatus = NewStyle(ColorBlack, ColorWhite) StyleStatusError = NewStyle(ColorWhite|AttrBold, ColorRed) StyleStatusGood = NewStyle(ColorWhite|AttrBold, ColorGreen) StyleStatusWarn = NewStyle(ColorWhite|AttrBold, ColorYellow) StyleStatusDim = NewStyle(ColorWhite|AttrBold, ColorWhite) StyleKey = NewStyle(ColorBlack, ColorWhite) StyleKeyHot = NewStyle(ColorBlue|AttrBold, ColorWhite) )
Some stock styles
var DefaultScreen = &screen{}
Screen represents the default screen.
Functions ¶
func RunApplication ¶
func RunApplication()
func SetApplication ¶
func SetApplication(app Widget)
Types ¶
type Attribute ¶
type Attribute uint16
Attribute represents a single color, or additional attributes such as bold, reverse, underline. For the moment, we are not supporting the entire 256 color palette. We should explore that later.
type CellModel ¶
type CellModel interface { GetCell(x, y int) (rune, Style) GetBounds() (int, int) SetCursor(int, int) GetCursor() (int, int, bool, bool) MoveCursor(offx, offy int) }
CellModel models the content of a CellView. The dimensions used within a CellModel are always logical, and have origin 0, 0.
type CellView ¶
type CellView struct {
// contains filtered or unexported fields
}
A CellView is a flexible view of a CellModel, offering both cursor management and a panning.
func NewCellView ¶
func NewCellView() *CellView
func (*CellView) HandleEvent ¶
func (*CellView) MakeCursorVisible ¶
func (a *CellView) MakeCursorVisible()
func (*CellView) MakeVisible ¶
func (*CellView) SetCursorX ¶
func (*CellView) SetCursorY ¶
type KeyBar ¶
type KeyBar struct {
// contains filtered or unexported fields
}
func (*KeyBar) HandleEvent ¶
type Panel ¶
type Panel struct {
// contains filtered or unexported fields
}
func (*Panel) HandleEvent ¶
func (*Panel) SetContent ¶
type ResizeEvent ¶
type ResizeEvent struct { }
type Screen ¶
type StatusBar ¶
type StatusBar struct {
// contains filtered or unexported fields
}
func NewStatusBar ¶
func NewStatusBar() *StatusBar
func (*StatusBar) HandleEvent ¶
type Style ¶
type Style uint32
Style incorporates the various elements of a style, both foreground and background. Logically the foreground occupies the upper 16 bits, and the background the lower 16, but applications must not depend on that.
type TextArea ¶
type TextArea struct {
// contains filtered or unexported fields
}
func NewTextArea ¶
func NewTextArea() *TextArea
func (*TextArea) EnableCursor ¶
func (*TextArea) HandleEvent ¶
func (*TextArea) HideCursor ¶
func (*TextArea) SetContent ¶
type TextBar ¶
type TextBar struct {
// contains filtered or unexported fields
}
func NewTextBar ¶
func NewTextBar() *TextBar
func (*TextBar) HandleEvent ¶
type TitleBar ¶
type TitleBar struct {
// contains filtered or unexported fields
}
func NewTitleBar ¶
func NewTitleBar() *TitleBar
func (*TitleBar) HandleEvent ¶
type View ¶
type View interface { // SetCell writes a single Unicode rune to a given x/y coordinate, // using the specified Style. SetCell(x int, y int, ch rune, style Style) // Clear clears the visible view, by filling it with spaces using // the specified Style. Clear(style Style) // Size represents the visible size. The actual content may be // larger or smaller. Size() (int, int) }
type ViewPort ¶
type ViewPort struct {
// contains filtered or unexported fields
}
func NewViewPort ¶
Return a new view. The x and y coordinates are an offset relative to the parent. 0,0 represents the upper left. The width and height indicate a width and height. If the value -1 is supplied, then the dimension is calculated from the parent.
func (*ViewPort) GetContentSize ¶
func (*ViewPort) MakeVisible ¶
This moves the ViewPort the minimum necessary to make the given point visible.
func (*ViewPort) Reset ¶
func (v *ViewPort) Reset()
Reset resets the record of content, and also resets the offset back to the origin. It doesn't alter the dimensions of the view port, nor the physical location relative to its parent.
func (*ViewPort) Resize ¶
Resize is called with the new dimensions, and also the new location in the the parent.
func (*ViewPort) ScrollDown ¶
func (*ViewPort) ScrollLeft ¶
func (*ViewPort) ScrollRight ¶
func (*ViewPort) SetContentSize ¶
func (*ViewPort) ValidateView ¶
func (v *ViewPort) ValidateView()
ValidateView does both ValidateViewX and ValidateViewY, ensuring both offsets are valid.
func (*ViewPort) ValidateViewX ¶
func (v *ViewPort) ValidateViewX()
ValidateViewX ensures that the X offset of the view port is limited so that it cannot scroll away from the content.
func (*ViewPort) ValidateViewY ¶
func (v *ViewPort) ValidateViewY()
ValidateViewY ensures that the Y offset of the view port is limited so that it cannot scroll away from the content.
type Widget ¶
type Widget interface { // Draw is called to inform the widget to draw itself. Draw() // Resize is called in response to a window resize. Unlike with // other events, Resize performed by parents first, and they must // then call their children. This is because the children need to // see the updated sizes from the parents before they are called. Resize() // HandleEvent is called to ask the widget to handle any events. // If the widget has consumed the event, it should return true. // Generally, events are handled by the lower layers first, that // is for example, a button may have a chance to handle an event // before the enclosing window or panel. HandleEvent(ev Event) bool // SetView is used by callers to set the visual parent of the // Widget. The Widget should use the View as a context for // drawing. SetView(view View) }