Documentation ¶
Overview ¶
Package gocui allows to create console user interfaces.
Create a new GUI:
g, err := gocui.NewGui(gocui.OutputNormal, false) if err != nil { // handle error } defer g.Close() // Set GUI managers and key bindings // ... if err := g.MainLoop(); err != nil && !gocui.IsQuit(err) { // handle error }
Set GUI managers:
g.SetManager(mgr1, mgr2)
Managers are in charge of GUI's layout and can be used to build widgets. On each iteration of the GUI's main loop, the Layout function of each configured manager is executed. Managers are used to set-up and update the application's main views, being possible to freely change them during execution. Also, it is important to mention that a main loop iteration is executed on each reported event (key-press, mouse event, window resize, etc).
GUIs are composed by Views, you can think of it as buffers. Views implement the io.ReadWriter interface, so you can just write to them if you want to modify their content. The same is valid for reading.
Create and initialize a view with absolute coordinates:
if v, err := g.SetView("viewname", 2, 2, 22, 7, 0); err != nil { if !gocui.IsUnknownView(err) { // handle error } fmt.Fprintln(v, "This is a new view") // ... }
Views can also be created using relative coordinates:
maxX, maxY := g.Size() if v, err := g.SetView("viewname", maxX/2-30, maxY/2, maxX/2+30, maxY/2+2, 0); err != nil { // ... }
Configure keybindings:
if err := g.SetKeybinding("viewname", gocui.KeyEnter, gocui.ModNone, fcn); err != nil { // handle error }
gocui implements full mouse support that can be enabled with:
g.Mouse = true
Mouse events are handled like any other keybinding:
if err := g.SetKeybinding("viewname", gocui.MouseLeft, gocui.ModNone, fcn); err != nil { // handle error }
IMPORTANT: Views can only be created, destroyed or updated in three ways: from the Layout function within managers, from keybinding callbacks or via *Gui.Update(). The reason for this is that it allows gocui to be concurrent-safe. So, if you want to update your GUI from a goroutine, you must use *Gui.Update(). For example:
g.Update(func(g *gocui.Gui) error { v, err := g.View("viewname") if err != nil { // handle error } v.Clear() fmt.Fprintln(v, "Writing from different goroutines") return nil })
By default, gocui provides a basic editing mode. This mode can be extended and customized creating a new Editor and assigning it to *View.Editor:
type Editor interface { Edit(v *View, key Key, ch rune, mod Modifier) }
DefaultEditor can be taken as example to create your own custom Editor:
var DefaultEditor Editor = EditorFunc(simpleEditor) func simpleEditor(v *View, key Key, ch rune, mod Modifier) { switch { case ch != 0 && mod == 0: v.EditWrite(ch) case key == KeySpace: v.EditWrite(' ') case key == KeyBackspace || key == KeyBackspace2: v.EditDelete(true) // ... } }
Colored text:
Views allow to add colored text using ANSI colors. For example:
fmt.Fprintln(v, "\x1b[0;31mHello world")
For more information, see the examples in folder "_examples/".
Index ¶
- Constants
- Variables
- func IsMouseKey(key interface{}) bool
- func IsMouseScrollKey(key interface{}) bool
- func IsQuit(err error) bool
- func IsUnknownView(err error) bool
- func Loader() cell
- func MustParseAll(input []string) map[interface{}]Modifier
- func ParseAll(input []string) (map[interface{}]Modifier, error)
- func SimpleEditor(v *View, key Key, ch rune, mod Modifier) bool
- type Attribute
- type Editor
- type EditorFunc
- type GocuiEvent
- type Gui
- func (g *Gui) BlacklistKeybinding(k Key) error
- func (g *Gui) Close()
- func (g *Gui) CopyContent(fromView *View, toView *View)
- func (g *Gui) CurrentView() *View
- func (g *Gui) DeleteAllKeybindings()
- func (g *Gui) DeleteKeybinding(viewname string, key interface{}, mod Modifier) error
- func (g *Gui) DeleteView(name string) error
- func (g *Gui) DeleteViewKeybindings(viewname string)
- func (g *Gui) MainLoop() error
- func (g *Gui) Resume() error
- func (g *Gui) Rune(x, y int) (rune, error)
- func (g *Gui) SetCurrentView(name string) (*View, error)
- func (g *Gui) SetKeybinding(viewname string, key interface{}, mod Modifier, ...) error
- func (g *Gui) SetManager(managers ...Manager)
- func (g *Gui) SetManagerFunc(manager func(*Gui) error)
- func (g *Gui) SetRune(x, y int, ch rune, fgColor, bgColor Attribute) error
- func (g *Gui) SetTabClickBinding(viewName string, handler tabClickHandler) error
- func (g *Gui) SetView(name string, x0, y0, x1, y1 int, overlaps byte) (*View, error)
- func (g *Gui) SetViewBeneath(name string, aboveViewName string, height int) (*View, error)
- func (g *Gui) SetViewClickBinding(binding *ViewMouseBinding) error
- func (g *Gui) SetViewOnBottom(name string) (*View, error)
- func (g *Gui) SetViewOnTop(name string) (*View, error)
- func (g *Gui) SetViewOnTopOf(toMove string, other string) error
- func (g *Gui) Size() (x, y int)
- func (g *Gui) Snapshot() string
- func (g *Gui) StartTicking(ctx context.Context)
- func (g *Gui) Suspend() error
- func (g *Gui) Update(f func(*Gui) error)
- func (g *Gui) UpdateAsync(f func(*Gui) error)
- func (g *Gui) View(name string) (*View, error)
- func (g *Gui) ViewPosition(name string) (x0, y0, x1, y1 int, err error)
- func (g *Gui) Views() []*View
- func (g *Gui) VisibleViewByPosition(x, y int) (*View, error)
- func (g *Gui) WhitelistKeybinding(k Key) error
- type GuiMutexes
- type Key
- type Manager
- type ManagerFunc
- type Modifier
- type OutputMode
- type RecordingConfig
- type TcellKeyEventWrapper
- type TcellResizeEventWrapper
- type TextArea
- func (self *TextArea) BackSpaceChar()
- func (self *TextArea) BackSpaceCharPrompt()
- func (self *TextArea) BackSpaceWord()
- func (self *TextArea) Clear()
- func (self *TextArea) DeleteChar()
- func (self *TextArea) DeleteToEndOfLine()
- func (self *TextArea) DeleteToStartOfLine()
- func (self *TextArea) GetContent() string
- func (self *TextArea) GetCursorXY() (int, int)
- func (self *TextArea) GoToEndOfLine()
- func (self *TextArea) GoToStartOfLine()
- func (self *TextArea) GoToStartOfLinePrompt()
- func (self *TextArea) MoveCursorDown()
- func (self *TextArea) MoveCursorLeft()
- func (self *TextArea) MoveCursorLeftPrompt()
- func (self *TextArea) MoveCursorRight()
- func (self *TextArea) MoveCursorUp()
- func (self *TextArea) MoveLeftWord()
- func (self *TextArea) MoveLeftWordPrompt()
- func (self *TextArea) MoveRightWord()
- func (self *TextArea) SetCursor2D(x int, y int)
- func (self *TextArea) ToggleOverwrite()
- func (self *TextArea) TypeRune(r rune)
- func (self *TextArea) TypeString(str string)
- func (self *TextArea) Yank()
- type View
- func (v *View) Buffer() string
- func (v *View) BufferLines() []string
- func (v *View) Clear()
- func (v *View) ClearSearch()
- func (v *View) ClearTextArea()
- func (v *View) CopyContent(from *View)
- func (v *View) Cursor() (x, y int)
- func (v *View) CursorX() int
- func (v *View) CursorY() int
- func (v *View) Dimensions() (int, int, int, int)
- func (v *View) FlushStaleCells()
- func (v *View) FocusPoint(cx int, cy int)
- func (v *View) GetClickedTabIndex(x int) int
- func (v *View) GetViewPosition() (int, int, int, int)
- func (v *View) Height() int
- func (v *View) InnerHeight() int
- func (v *View) InnerWidth() int
- func (v *View) IsSearching() bool
- func (v *View) IsTainted() bool
- func (v *View) Line(y int) (string, error)
- func (v *View) LinesHeight() int
- func (v *View) Name() string
- func (v *View) Origin() (x, y int)
- func (v *View) OriginX() int
- func (v *View) OriginY() int
- func (v *View) OverwriteLines(y int, content string)
- func (v *View) Read(p []byte) (n int, err error)
- func (v *View) ReadPos() (x, y int)
- func (v *View) RenderTextArea()
- func (v *View) Reset()
- func (v *View) Rewind()
- func (v *View) ScrollDown(amount int)
- func (v *View) ScrollLeft(amount int)
- func (v *View) ScrollRight(amount int)
- func (v *View) ScrollUp(amount int)
- func (v *View) Search(str string) error
- func (v *View) SelectSearchResult(index int) error
- func (v *View) SelectedLine() string
- func (v *View) SelectedLineIdx() int
- func (v *View) SelectedPoint() (int, int)
- func (v *View) SetContent(str string)
- func (v *View) SetCursor(x, y int) error
- func (v *View) SetCursorX(x int)
- func (v *View) SetCursorY(y int)
- func (v *View) SetHighlight(y int, on bool) error
- func (v *View) SetOnSelectItem(onSelectItem func(int, int, int) error)
- func (v *View) SetOrigin(x, y int) error
- func (v *View) SetOriginX(x int) error
- func (v *View) SetOriginY(y int) error
- func (v *View) SetReadPos(x, y int) error
- func (v *View) SetWritePos(x, y int) error
- func (v *View) Size() (x, y int)
- func (v *View) ViewBuffer() string
- func (v *View) ViewBufferLines() []string
- func (v *View) ViewLinesHeight() int
- func (v *View) Width() int
- func (v *View) Word(x, y int) (string, error)
- func (v *View) Write(p []byte) (n int, err error)
- func (v *View) WritePos() (x, y int)
- func (v *View) WriteRunes(p []rune)
- func (v *View) WriteString(s string)
- type ViewMouseBinding
- type ViewMouseBindingOpts
Constants ¶
const ( // ColorDefault is used to leave the Color unchanged from whatever system or teminal default may exist. ColorDefault = Attribute(tcell.ColorDefault) // AttrIsValidColor is used to indicate the color value is actually // valid (initialized). This is useful to permit the zero value // to be treated as the default. AttrIsValidColor = Attribute(tcell.ColorValid) // AttrIsRGBColor is used to indicate that the Attribute value is RGB value of color. // The lower order 3 bytes are RGB. // (It's not a color in basic ANSI range 256). AttrIsRGBColor = Attribute(tcell.ColorIsRGB) // AttrColorBits is a mask where color is located in Attribute AttrColorBits = 0xffffffffff // roughly 5 bytes, tcell uses 4 bytes and half-byte as a special flags for color (rest is reserved for future) // AttrStyleBits is a mask where character attributes (e.g.: bold, italic, underline) are located in Attribute AttrStyleBits = 0xffffff0000000000 // remaining 3 bytes in the 8 bytes Attribute (tcell is not using it, so we should be fine) )
const ( KeyF1 Key = Key(tcell.KeyF1) KeyF2 = Key(tcell.KeyF2) KeyF3 = Key(tcell.KeyF3) KeyF4 = Key(tcell.KeyF4) KeyF5 = Key(tcell.KeyF5) KeyF6 = Key(tcell.KeyF6) KeyF7 = Key(tcell.KeyF7) KeyF8 = Key(tcell.KeyF8) KeyF9 = Key(tcell.KeyF9) KeyF10 = Key(tcell.KeyF10) KeyF11 = Key(tcell.KeyF11) KeyF12 = Key(tcell.KeyF12) KeyInsert = Key(tcell.KeyInsert) KeyDelete = Key(tcell.KeyDelete) KeyHome = Key(tcell.KeyHome) KeyEnd = Key(tcell.KeyEnd) KeyPgdn = Key(tcell.KeyPgDn) KeyPgup = Key(tcell.KeyPgUp) KeyArrowUp = Key(tcell.KeyUp) KeyArrowDown = Key(tcell.KeyDown) KeyArrowLeft = Key(tcell.KeyLeft) KeyArrowRight = Key(tcell.KeyRight) )
Special keys.
const ( KeyCtrlTilde = Key(tcell.KeyF64) // arbitrary assignment KeyCtrlSpace = Key(tcell.KeyCtrlSpace) KeyCtrlA = Key(tcell.KeyCtrlA) KeyCtrlB = Key(tcell.KeyCtrlB) KeyCtrlC = Key(tcell.KeyCtrlC) KeyCtrlD = Key(tcell.KeyCtrlD) KeyCtrlE = Key(tcell.KeyCtrlE) KeyCtrlF = Key(tcell.KeyCtrlF) KeyCtrlG = Key(tcell.KeyCtrlG) KeyBackspace = Key(tcell.KeyBackspace) KeyCtrlH = Key(tcell.KeyCtrlH) KeyTab = Key(tcell.KeyTab) KeyBacktab = Key(tcell.KeyBacktab) KeyCtrlI = Key(tcell.KeyCtrlI) KeyCtrlJ = Key(tcell.KeyCtrlJ) KeyCtrlK = Key(tcell.KeyCtrlK) KeyCtrlL = Key(tcell.KeyCtrlL) KeyEnter = Key(tcell.KeyEnter) KeyCtrlM = Key(tcell.KeyCtrlM) KeyCtrlN = Key(tcell.KeyCtrlN) KeyCtrlO = Key(tcell.KeyCtrlO) KeyCtrlP = Key(tcell.KeyCtrlP) KeyCtrlQ = Key(tcell.KeyCtrlQ) KeyCtrlR = Key(tcell.KeyCtrlR) KeyCtrlS = Key(tcell.KeyCtrlS) KeyCtrlT = Key(tcell.KeyCtrlT) KeyCtrlU = Key(tcell.KeyCtrlU) KeyCtrlV = Key(tcell.KeyCtrlV) KeyCtrlW = Key(tcell.KeyCtrlW) KeyCtrlX = Key(tcell.KeyCtrlX) KeyCtrlY = Key(tcell.KeyCtrlY) KeyCtrlZ = Key(tcell.KeyCtrlZ) KeyEsc = Key(tcell.KeyEscape) KeyCtrlUnderscore = Key(tcell.KeyCtrlUnderscore) KeySpace = Key(32) KeyBackspace2 = Key(tcell.KeyBackspace2) KeyCtrl8 = Key(tcell.KeyBackspace2) // same key as in termbox-go KeyAltEnter = Key(tcell.KeyF64) // arbitrary assignments MouseLeft = Key(tcell.KeyF63) MouseRight = Key(tcell.KeyF62) MouseMiddle = Key(tcell.KeyF61) MouseRelease = Key(tcell.KeyF60) MouseWheelUp = Key(tcell.KeyF59) MouseWheelDown = Key(tcell.KeyF58) MouseWheelLeft = Key(tcell.KeyF57) MouseWheelRight = Key(tcell.KeyF56) KeyCtrl2 = Key(tcell.KeyNUL) // termbox defines theses KeyCtrl3 = Key(tcell.KeyEscape) KeyCtrl4 = Key(tcell.KeyCtrlBackslash) KeyCtrl5 = Key(tcell.KeyCtrlRightSq) KeyCtrl6 = Key(tcell.KeyCtrlCarat) KeyCtrl7 = Key(tcell.KeyCtrlUnderscore) KeyCtrlSlash = Key(tcell.KeyCtrlUnderscore) KeyCtrlRsqBracket = Key(tcell.KeyCtrlRightSq) KeyCtrlBackslash = Key(tcell.KeyCtrlBackslash) KeyCtrlLsqBracket = Key(tcell.KeyCtrlLeftSq) )
Keys combinations.
const ( ModNone Modifier = Modifier(0) ModAlt = Modifier(tcell.ModAlt) ModMotion = Modifier(2) // just picking an arbitrary number here that doesn't clash with tcell.ModAlt )
Modifiers.
const ( NOT_DRAGGING int = iota MAYBE_DRAGGING DRAGGING )
const ( WHITESPACES = " \t" WORD_SEPARATORS = "*?_+-.[]~=/&;!#$%^(){}<>" )
const ( TOP = 1 // view is overlapping at top edge BOTTOM = 2 // view is overlapping at bottom edge LEFT = 4 // view is overlapping at left edge RIGHT = 8 // view is overlapping at right edge )
Constants for overlapping edges
const AttrAll = AttrBold | AttrBlink | AttrReverse | AttrUnderline | AttrDim | AttrItalic
AttrAll represents all the text effect attributes turned on
Variables ¶
var ( // ErrAlreadyBlacklisted is returned when the keybinding is already blacklisted. ErrAlreadyBlacklisted = standardErrors.New("keybind already blacklisted") // ErrBlacklisted is returned when the keybinding being parsed / used is blacklisted. ErrBlacklisted = standardErrors.New("keybind blacklisted") // ErrNotBlacklisted is returned when a keybinding being whitelisted is not blacklisted. ErrNotBlacklisted = standardErrors.New("keybind not blacklisted") // ErrNoSuchKeybind is returned when the keybinding being parsed does not exist. ErrNoSuchKeybind = standardErrors.New("no such keybind") // ErrUnknownView allows to assert if a View must be initialized. ErrUnknownView = standardErrors.New("unknown view") // ErrQuit is used to decide if the MainLoop finished successfully. ErrQuit = standardErrors.New("quit") )
var ErrInvalidPoint = errors.New("invalid point")
ErrInvalidPoint is returned when client passed invalid coordinates of a cell. Most likely client has passed negative coordinates of a cell.
var Screen tcell.Screen
We probably don't want this being a global variable for YOLO for now
Functions ¶
func IsMouseKey ¶
func IsMouseKey(key interface{}) bool
func IsMouseScrollKey ¶
func IsMouseScrollKey(key interface{}) bool
func IsUnknownView ¶
IsUnknownView reports whether the contents of an error is "unknown view".
func MustParseAll ¶
MustParseAll takes an array of strings and returns a map of all keybindings. It will panic if any error occured.
Types ¶
type Attribute ¶
type Attribute uint64
Attribute affects the presentation of characters, such as color, boldness, etc.
const ( ColorBlack Attribute = AttrIsValidColor + iota ColorRed ColorGreen ColorYellow ColorBlue ColorMagenta ColorCyan ColorWhite )
Color attributes. These colors are compatible with tcell.Color type and can be expanded like:
g.FgColor := gocui.Attribute(tcell.ColorLime)
const ( AttrBold Attribute = 1 << (40 + iota) AttrBlink AttrReverse AttrUnderline AttrDim AttrItalic AttrStrikeThrough AttrNone Attribute = 0 // Just normal text. )
Attributes are not colors, but effects (e.g.: bold, dim) which affect the display of text. They can be combined.
func Get256Color ¶
Get256Color creates Attribute which stores ANSI color (0-255)
func GetColor ¶
GetColor creates a Color from a color name (W3C name). A hex value may be supplied as a string in the format "#ffffff".
func GetRGBColor ¶
GetRGBColor creates Attribute which stores RGB color. Color is passed as 24bit RGB value, where R << 16 | G << 8 | B
func NewRGBColor ¶
NewRGBColor creates Attribute which stores RGB color.
func (Attribute) Hex ¶
Hex returns the color's hexadecimal RGB 24-bit value with each component consisting of a single byte, ala R << 16 | G << 8 | B. If the color is unknown or unset, -1 is returned.
This function produce the same output as `tcell.Hex()` with additional support for `termbox-go` colors (to 256).
func (Attribute) IsValidColor ¶
IsValidColor indicates if the Attribute is a valid color value (has been set).
func (Attribute) RGB ¶
RGB returns the red, green, and blue components of the color, with each component represented as a value 0-255. If the color is unknown or unset, -1 is returned for each component.
This function produce the same output as `tcell.RGB()` with additional support for `termbox-go` colors (to 256).
type Editor ¶
Editor interface must be satisfied by gocui editors.
var DefaultEditor Editor = EditorFunc(SimpleEditor)
DefaultEditor is the default editor.
type EditorFunc ¶
The EditorFunc type is an adapter to allow the use of ordinary functions as Editors. If f is a function with the appropriate signature, EditorFunc(f) is an Editor object that calls f.
type GocuiEvent ¶
type GocuiEvent struct { Type gocuiEventType Mod Modifier Key Key Ch rune Width int Height int Err error MouseX int MouseY int N int }
GocuiEvent represents events like a keys, mouse actions, or window resize.
The 'Mod', 'Key' and 'Ch' fields are valid if 'Type' is 'eventKey'. The 'MouseX' and 'MouseY' fields are valid if 'Type' is 'eventMouse'. The 'Width' and 'Height' fields are valid if 'Type' is 'eventResize'. The 'Err' field is valid if 'Type' is 'eventError'.
type Gui ¶
type Gui struct { RecordingConfig // ReplayedEvents is for passing pre-recorded input events, for the purposes of testing ReplayedEvents replayedEvents GocuiEvent *GocuiEvent // BgColor and FgColor allow to configure the background and foreground // colors of the GUI. BgColor, FgColor, FrameColor Attribute // SelBgColor and SelFgColor allow to configure the background and // foreground colors of the frame of the current view. SelBgColor, SelFgColor, SelFrameColor Attribute // If Highlight is true, Sel{Bg,Fg}Colors will be used to draw the // frame of the current view. Highlight bool ShowListFooter bool // If Cursor is true then the cursor is enabled. Cursor bool // If Mouse is true then mouse events will be enabled. Mouse bool // If InputEsc is true, when ESC sequence is in the buffer and it doesn't // match any known sequence, ESC means KeyEsc. InputEsc bool // SupportOverlaps is true when we allow for view edges to overlap with other // view edges SupportOverlaps bool Mutexes GuiMutexes OnSearchEscape func() error // these keys must either be of type Key of rune SearchEscapeKey interface{} NextSearchMatchKey interface{} PrevSearchMatchKey interface{} // contains filtered or unexported fields }
Gui represents the whole User Interface, including the views, layouts and keybindings.
func NewGui ¶
func NewGui(mode OutputMode, supportOverlaps bool, playRecording bool, headless bool, runeReplacements map[rune]string) (*Gui, error)
NewGui returns a new Gui object with a given output mode.
func (*Gui) BlacklistKeybinding ¶
BlackListKeybinding adds a keybinding to the blacklist
func (*Gui) Close ¶
func (g *Gui) Close()
Close finalizes the library. It should be called after a successful initialization and when gocui is not needed anymore.
func (*Gui) CopyContent ¶
replaces the content in toView with the content in fromView
func (*Gui) CurrentView ¶
CurrentView returns the currently focused view, or nil if no view owns the focus.
func (*Gui) DeleteAllKeybindings ¶
func (g *Gui) DeleteAllKeybindings()
DeleteKeybindings deletes all keybindings of view.
func (*Gui) DeleteKeybinding ¶
DeleteKeybinding deletes a keybinding.
func (*Gui) DeleteView ¶
DeleteView deletes a view by name.
func (*Gui) DeleteViewKeybindings ¶
DeleteKeybindings deletes all keybindings of view.
func (*Gui) MainLoop ¶
MainLoop runs the main loop until an error is returned. A successful finish should return ErrQuit.
func (*Gui) Rune ¶
Rune returns the rune contained in the cell at the given position. It checks if the position is valid.
func (*Gui) SetCurrentView ¶
SetCurrentView gives the focus to a given view.
func (*Gui) SetKeybinding ¶
func (g *Gui) SetKeybinding(viewname string, key interface{}, mod Modifier, handler func(*Gui, *View) error) error
SetKeybinding creates a new keybinding. If viewname equals to "" (empty string) then the keybinding will apply to all views. key must be a rune or a Key.
When mouse keys are used (MouseLeft, MouseRight, ...), modifier might not work correctly. It behaves differently on different platforms. Somewhere it doesn't register Alt key press, on others it might report Ctrl as Alt. It's not consistent and therefore it's not recommended to use with mouse keys.
func (*Gui) SetManager ¶
SetManager sets the given GUI managers. It deletes all views and keybindings.
func (*Gui) SetManagerFunc ¶
SetManagerFunc sets the given manager function. It deletes all views and keybindings.
func (*Gui) SetRune ¶
SetRune writes a rune at the given point, relative to the top-left corner of the terminal. It checks if the position is valid and applies the given colors.
func (*Gui) SetTabClickBinding ¶
SetTabClickBinding sets a binding for a tab click event
func (*Gui) SetView ¶
SetView creates a new view with its top-left corner at (x0, y0) and the bottom-right one at (x1, y1). If a view with the same name already exists, its dimensions are updated; otherwise, the error ErrUnknownView is returned, which allows to assert if the View must be initialized. It checks if the position is valid.
func (*Gui) SetViewBeneath ¶
SetViewBeneath sets a view stacked beneath another view
func (*Gui) SetViewClickBinding ¶
func (g *Gui) SetViewClickBinding(binding *ViewMouseBinding) error
func (*Gui) SetViewOnBottom ¶
SetViewOnBottom sets the given view on bottom of the existing ones.
func (*Gui) SetViewOnTop ¶
SetViewOnTop sets the given view on top of the existing ones.
func (*Gui) Snapshot ¶
returns a string representation of the current state of the gui, character-for-character
func (*Gui) StartTicking ¶
func (*Gui) Update ¶
Update executes the passed function. This method can be called safely from a goroutine in order to update the GUI. It is important to note that the passed function won't be executed immediately, instead it will be added to the user events queue. Given that Update spawns a goroutine, the order in which the user events will be handled is not guaranteed.
func (*Gui) UpdateAsync ¶
UpdateAsync is a version of Update that does not spawn a go routine, it can be a bit more efficient in cases where Update is called many times like when tailing a file. In general you should use Update()
func (*Gui) View ¶
View returns a pointer to the view with the given name, or error ErrUnknownView if a view with that name does not exist.
func (*Gui) ViewPosition ¶
ViewPosition returns the coordinates of the view with the given name, or error ErrUnknownView if a view with that name does not exist.
func (*Gui) VisibleViewByPosition ¶
VisibleViewByPosition returns a pointer to a view matching the given position, or error ErrUnknownView if a view in that position does not exist.
func (*Gui) WhitelistKeybinding ¶
WhiteListKeybinding removes a keybinding from the blacklist
type GuiMutexes ¶
type Manager ¶
type Manager interface { // Layout is called every time the GUI is redrawn, it must contain the // base views and its initializations. Layout(*Gui) error }
A Manager is in charge of GUI's layout and can be used to build widgets.
type ManagerFunc ¶
The ManagerFunc type is an adapter to allow the use of ordinary functions as Managers. If f is a function with the appropriate signature, ManagerFunc(f) is an Manager object that calls f.
type Modifier ¶
type Modifier tcell.ModMask
Modifier allows to define special keys combinations. They can be used in combination with Keys or Runes when a new keybinding is defined.
type OutputMode ¶
type OutputMode int
OutputMode represents an output mode, which determines how colors are used.
const ( // OutputNormal provides 8-colors terminal mode. OutputNormal OutputMode = iota // Output256 provides 256-colors terminal mode. Output256 // Output216 provides 216 ansi color terminal mode. Output216 // OutputGrayscale provides greyscale terminal mode. OutputGrayscale // OutputTrue provides 24bit color terminal mode. // This mode is recommended even if your terminal doesn't support // such mode. The colors are represented exactly as you // write them (no clamping or truncating). `tcell` should take care // of what your terminal can do. OutputTrue )
type RecordingConfig ¶
type TcellKeyEventWrapper ¶
this wrapper struct has public keys so we can easily serialize/deserialize to JSON
func NewTcellKeyEventWrapper ¶
func NewTcellKeyEventWrapper(event *tcell.EventKey, timestamp int64) *TcellKeyEventWrapper
type TcellResizeEventWrapper ¶
func NewTcellResizeEventWrapper ¶
func NewTcellResizeEventWrapper(event *tcell.EventResize, timestamp int64) *TcellResizeEventWrapper
type TextArea ¶
type TextArea struct {
// contains filtered or unexported fields
}
func (*TextArea) BackSpaceChar ¶
func (self *TextArea) BackSpaceChar()
func (*TextArea) BackSpaceCharPrompt ¶
func (self *TextArea) BackSpaceCharPrompt()
func (*TextArea) BackSpaceWord ¶
func (self *TextArea) BackSpaceWord()
func (*TextArea) DeleteChar ¶
func (self *TextArea) DeleteChar()
func (*TextArea) DeleteToEndOfLine ¶
func (self *TextArea) DeleteToEndOfLine()
func (*TextArea) DeleteToStartOfLine ¶
func (self *TextArea) DeleteToStartOfLine()
func (*TextArea) GetContent ¶
func (*TextArea) GetCursorXY ¶
func (*TextArea) GoToEndOfLine ¶
func (self *TextArea) GoToEndOfLine()
func (*TextArea) GoToStartOfLine ¶
func (self *TextArea) GoToStartOfLine()
func (*TextArea) GoToStartOfLinePrompt ¶
func (self *TextArea) GoToStartOfLinePrompt()
func (*TextArea) MoveCursorDown ¶
func (self *TextArea) MoveCursorDown()
func (*TextArea) MoveCursorLeft ¶
func (self *TextArea) MoveCursorLeft()
func (*TextArea) MoveCursorLeftPrompt ¶
func (self *TextArea) MoveCursorLeftPrompt()
func (*TextArea) MoveCursorRight ¶
func (self *TextArea) MoveCursorRight()
func (*TextArea) MoveCursorUp ¶
func (self *TextArea) MoveCursorUp()
func (*TextArea) MoveLeftWord ¶
func (self *TextArea) MoveLeftWord()
func (*TextArea) MoveLeftWordPrompt ¶
func (self *TextArea) MoveLeftWordPrompt()
func (*TextArea) MoveRightWord ¶
func (self *TextArea) MoveRightWord()
func (*TextArea) SetCursor2D ¶
takes an x,y position and maps it to a 1D cursor position
func (*TextArea) ToggleOverwrite ¶
func (self *TextArea) ToggleOverwrite()
func (*TextArea) TypeString ¶
type View ¶
type View struct { // Visible specifies whether the view is visible. Visible bool // BgColor and FgColor allow to configure the background and foreground // colors of the View. BgColor, FgColor Attribute // SelBgColor and SelFgColor are used to configure the background and // foreground colors of the selected line, when it is highlighted. SelBgColor, SelFgColor Attribute // If Editable is true, keystrokes will be added to the view's internal // buffer at the cursor position. Editable bool // Editor allows to define the editor that manages the editing mode, // including keybindings or cursor behaviour. DefaultEditor is used by // default. Editor Editor // Overwrite enables or disables the overwrite mode of the view. Overwrite bool // If Highlight is true, Sel{Bg,Fg}Colors will be used // for the line under the cursor position. Highlight bool // If Frame is true, a border will be drawn around the view. Frame bool // FrameColor allow to configure the color of the Frame when it is not highlighted. FrameColor Attribute // FrameRunes allows to define custom runes for the frame edges. // The rune slice can be defined with 3 different lengths. // If slice doesn't match these lengths, default runes will be used instead of missing one. // // 2 runes with only horizontal and vertical edges. // []rune{'─', '│'} // []rune{'═','║'} // 6 runes with horizontal, vertical edges and top-left, top-right, bottom-left, bottom-right cornes. // []rune{'─', '│', '┌', '┐', '└', '┘'} // []rune{'═','║','╔','╗','╚','╝'} // 11 runes which can be used with `gocui.Gui.SupportOverlaps` property. // []rune{'─', '│', '┌', '┐', '└', '┘', '├', '┤', '┬', '┴', '┼'} // []rune{'═','║','╔','╗','╚','╝','╠','╣','╦','╩','╬'} FrameRunes []rune // If Wrap is true, the content that is written to this View is // automatically wrapped when it is longer than its width. If true the // view's x-origin will be ignored. Wrap bool // If Autoscroll is true, the View will automatically scroll down when the // text overflows. If true the view's y-origin will be ignored. Autoscroll bool // If Frame is true, Title allows to configure a title for the view. Title string Tabs []string TabIndex int // TitleColor allow to configure the color of title and subtitle for the view. TitleColor Attribute // If Frame is true, Subtitle allows to configure a subtitle for the view. Subtitle string // If Mask is true, the View will display the mask instead of the real // content Mask rune // Overlaps describes which edges are overlapping with another view's edges Overlaps byte // If HasLoader is true, the message will be appended with a spinning loader animation HasLoader bool // IgnoreCarriageReturns tells us whether to ignore '\r' characters IgnoreCarriageReturns bool // ParentView is the view which catches events bubbled up from the given view if there's no matching handler ParentView *View // KeybindOnEdit should be set to true when you want to execute keybindings even when the view is editable // (this is usually not the case) KeybindOnEdit bool TextArea *TextArea Footer string // if true, the user can scroll all the way past the last item until it appears at the top of the view CanScrollPastBottom bool // contains filtered or unexported fields }
A View is a window. It maintains its own internal buffer and cursor position.
func (*View) BufferLines ¶
BufferLines returns the lines in the view's internal buffer.
func (*View) Clear ¶
func (v *View) Clear()
Clear empties the view's internal buffer. And resets reading and writing offsets.
func (*View) ClearSearch ¶
func (v *View) ClearSearch()
func (*View) ClearTextArea ¶
func (v *View) ClearTextArea()
func (*View) CopyContent ¶
func (*View) Dimensions ¶
Dimensions returns the dimensions of the View
func (*View) FlushStaleCells ¶
func (v *View) FlushStaleCells()
This is for when we've done a restart for the sake of avoiding a flicker and we've reached the end of the new content to display: we need to clear the remaining content from the previous round. We do this by setting v.viewLines to nil so that we just render the new content from v.lines directly
func (*View) FocusPoint ¶
func (*View) GetClickedTabIndex ¶
GetClickedTabIndex tells us which tab was clicked
func (*View) InnerHeight ¶
func (*View) InnerWidth ¶
if a view has a frame, that leaves less space for its writeable area
func (*View) IsSearching ¶
func (*View) Line ¶
Line returns a string with the line of the view's internal buffer at the position corresponding to the point (x, y).
func (*View) LinesHeight ¶
LinesHeight is the count of view lines (i.e. lines excluding wrapping)
func (*View) OverwriteLines ¶
only call this function if you don't care where v.wx and v.wy end up
func (*View) Read ¶
Read reads data into p from the current reading position set by SetReadPos. It returns the number of bytes read into p. At EOF, err will be io.EOF.
func (*View) RenderTextArea ¶
func (v *View) RenderTextArea()
func (*View) Reset ¶
func (v *View) Reset()
similar to Rewind but clears lines. Also similar to Clear but doesn't reset viewLines
func (*View) ScrollDown ¶
ensures we don't scroll past the end of the view's content
func (*View) ScrollLeft ¶
func (*View) SelectSearchResult ¶
func (*View) SelectedLineIdx ¶
func (*View) SelectedPoint ¶
func (*View) SetContent ¶
func (*View) SetCursor ¶
SetCursor sets the cursor position of the view at the given point, relative to the view. It checks if the position is valid.
func (*View) SetCursorX ¶
func (*View) SetCursorY ¶
func (*View) SetHighlight ¶
SetHighlight toggles highlighting of separate lines, for custom lists or multiple selection in views.
func (*View) SetOnSelectItem ¶
func (*View) SetOrigin ¶
SetOrigin sets the origin position of the view's internal buffer, so the buffer starts to be printed from this point, which means that it is linked with the origin point of view. It can be used to implement Horizontal and Vertical scrolling with just incrementing or decrementing ox and oy.
func (*View) SetOriginX ¶
func (*View) SetOriginY ¶
func (*View) SetReadPos ¶
SetReadPos sets the read position of the view's internal buffer. So the next Read call would read from the specified position.
func (*View) SetWritePos ¶
SetWritePos sets the write position of the view's internal buffer. So the next Write call would write directly to the specified position.
func (*View) ViewBuffer ¶
ViewBuffer returns a string with the contents of the view's buffer that is shown to the user.
func (*View) ViewBufferLines ¶
ViewBufferLines returns the lines in the view's internal buffer that is shown to the user.
func (*View) ViewLinesHeight ¶
ViewLinesHeight is the count of view lines (i.e. lines including wrapping)
func (*View) Word ¶
Word returns a string with the word of the view's internal buffer at the position corresponding to the point (x, y).
func (*View) Write ¶
Write appends a byte slice into the view's internal buffer. Because View implements the io.Writer interface, it can be passed as parameter of functions like fmt.Fprintf, fmt.Fprintln, io.Copy, etc. Clear must be called to clear the view's buffer.
func (*View) WriteRunes ¶
func (*View) WriteString ¶
exported functions use the mutex. Non-exported functions are for internal use and a calling function should use a mutex
type ViewMouseBinding ¶
type ViewMouseBinding struct { // the view that is clicked ViewName string // the view that has focus when the click occurs. FocusedView string Handler func(ViewMouseBindingOpts) error Modifier Modifier // must be a mouse key Key Key }
TODO: would be good to define inbound and outbound click handlers e.g. clicking on a file is an inbound thing where we don't care what context you're in when it happens, whereas clicking on the main view from the files view is an outbound click with a specific handler. But this requires more thinking about where handlers should live.