Documentation ¶
Overview ¶
Package xui is a console user interface toolkit based on gocui.
Index ¶
- Constants
- func ErrorHandler(err error) func(*gocui.Gui, *gocui.View) error
- func GetLine(view *gocui.View) int
- func Handler(f func()) func(*gocui.Gui, *gocui.View) error
- func MoveLines(view *gocui.View, current, max, delta int) error
- func Pad(s string, n int) string
- func PromptEditor(g *gocui.Gui, offset int, callback func(bool, string)) gocui.Editor
- func ResizeLayout(layout func(g *gocui.Gui) error) func(g *gocui.Gui) error
- func StringWidth(s string) int
- type ErrAction
- type ListWidget
- type Region
- type ScrollWidget
- func (w *ScrollWidget) Current() int
- func (w *ScrollWidget) HandleAction(action string) error
- func (w *ScrollWidget) NextLine() error
- func (w *ScrollWidget) NextPage() error
- func (w *ScrollWidget) PreviousLine() error
- func (w *ScrollWidget) PreviousPage() error
- func (w *ScrollWidget) SetCurrent(idx int) error
- func (w *ScrollWidget) SetMax(max int)
- func (w *ScrollWidget) SetView(view *gocui.View)
- func (w *ScrollWidget) View() *gocui.View
- type TextWidget
- type Widget
- type Xui
- func (gx *Xui) Err() error
- func (gx *Xui) Focus(view *gocui.View)
- func (gx *Xui) FocusName(name string)
- func (gx *Xui) SetCurrentView(name string)
- func (gx *Xui) SetKeybinding(viewname string, key interface{}, mod gocui.Modifier, ...)
- func (gx *Xui) SetPostActionHandler(f func(error) error)
- func (gx *Xui) SetPreActionHandler(f func())
- func (gx *Xui) SetRegionView(name string, r Region) *gocui.View
- func (gx *Xui) SetView(name string, x0, y0, x1, y1 int) *gocui.View
- func (gx *Xui) SetViewOnTop(name string)
- func (gx *Xui) SetWidgetAction(widget Widget, key interface{}, mod gocui.Modifier, action string)
- func (gx *Xui) SetWidgetKeybinding(widget Widget, key interface{}, mod gocui.Modifier, handler func() error)
Constants ¶
const ( ActionNextLine = "next_line" ActionNextPage = "next_page" ActionPreviousLine = "prev_line" ActionPreviousPage = "prev_page" )
Widget movements
Variables ¶
This section is empty.
Functions ¶
func ErrorHandler ¶
ErrorHandler returns a gocui keybinding handler that returns provided error.
func Handler ¶
Handler returns a gocui keybinding handler that executes provided function and returns a nil error.
func Pad ¶
Pad appends spaces to provided string so that its length matches the width of the widget, while taking double-width unicode characters and ANSI escape sequences into account.
func PromptEditor ¶
PromptEditor builds a gocui.Editor function letting user enter a line of text.
func ResizeLayout ¶
ResizeLayout calls provided layout function if view was resized.
func StringWidth ¶
StringWidth returns the width of string in single-width unicode character units.
Types ¶
type ErrAction ¶
type ErrAction struct {
// contains filtered or unexported fields
}
ErrAction represents an error encountered during a widet action.
func UnknownAction ¶
func UnknownAction() ErrAction
UnknownAction builds an widget action error indicating that the widget didn't understand the action.
type ListWidget ¶
type ListWidget struct { Highlight bool // contains filtered or unexported fields }
A ListWidget displays a list of lines.
func (*ListWidget) Current ¶
func (w *ListWidget) Current() int
Current returns currently selected line.
func (*ListWidget) HandleAction ¶
func (w *ListWidget) HandleAction(action string) error
HandleAction executes an action command.
func (*ListWidget) SetCurrent ¶
func (w *ListWidget) SetCurrent(idx int) error
SetCurrent updates currently selected line.
func (*ListWidget) SetModel ¶
func (w *ListWidget) SetModel(model []string)
SetModel updates the list of lines to display.
func (*ListWidget) SetView ¶
func (w *ListWidget) SetView(view *gocui.View)
SetView binds a gocui.View to this widget.
func (*ListWidget) View ¶
func (w *ListWidget) View() *gocui.View
View returns the gocui.View currently bound to this widget.
type ScrollWidget ¶
type ScrollWidget struct { Highlight bool // contains filtered or unexported fields }
ScrollWidget provides vertical scrolling to other widgets.
func (*ScrollWidget) Current ¶
func (w *ScrollWidget) Current() int
Current returns currently selected line.
func (*ScrollWidget) HandleAction ¶
func (w *ScrollWidget) HandleAction(action string) error
HandleAction executes an action command.
func (*ScrollWidget) NextLine ¶
func (w *ScrollWidget) NextLine() error
NextLine selects the next line.
func (*ScrollWidget) NextPage ¶
func (w *ScrollWidget) NextPage() error
NextPage scrolls down one page.
func (*ScrollWidget) PreviousLine ¶
func (w *ScrollWidget) PreviousLine() error
PreviousLine selects the previous line.
func (*ScrollWidget) PreviousPage ¶
func (w *ScrollWidget) PreviousPage() error
PreviousPage scrolls up one page.
func (*ScrollWidget) SetCurrent ¶
func (w *ScrollWidget) SetCurrent(idx int) error
SetCurrent updates currently selected line.
func (*ScrollWidget) SetMax ¶
func (w *ScrollWidget) SetMax(max int)
SetMax updates maximum number of lines for the widget.
func (*ScrollWidget) SetView ¶
func (w *ScrollWidget) SetView(view *gocui.View)
SetView binds a gocui.View to this widget.
func (*ScrollWidget) View ¶
func (w *ScrollWidget) View() *gocui.View
View returns the gocui.View currently bound to this widget.
type TextWidget ¶
type TextWidget struct {
BgColor, FgColor gocui.Attribute
// contains filtered or unexported fields
}
A TextWidget displays a string.
func (*TextWidget) SetPrompt ¶
func (w *TextWidget) SetPrompt(g *gocui.Gui, prefix, content string, callback func(bool, string)) error
SetPrompt focuses this widget and makes it editable.
func (*TextWidget) SetText ¶
func (w *TextWidget) SetText(text string)
SetText updates the string to display.
func (*TextWidget) SetView ¶
func (w *TextWidget) SetView(view *gocui.View)
SetView binds a gocui.View to this widget.
func (*TextWidget) View ¶
func (w *TextWidget) View() *gocui.View
View returns the gocui.View currently bound to this widget.
type Xui ¶
type Xui struct {
// contains filtered or unexported fields
}
Xui is a wrapper around gocui.Gui.
func (*Xui) Err ¶
Err returns the first encountered error. Always returns nil if a post-action handler has been set.
func (*Xui) SetCurrentView ¶
SetCurrentView is a wrapper around gocui.Gui.SetCurrentView.
func (*Xui) SetKeybinding ¶
func (gx *Xui) SetKeybinding(viewname string, key interface{}, mod gocui.Modifier, handler func(*gocui.Gui, *gocui.View) error)
SetKeybinding is a wrapper around gocui.Gui.SetKeybinding.
func (*Xui) SetPostActionHandler ¶
SetPostActionHandler sets a hook that is called after a widget action is executed.
func (*Xui) SetPreActionHandler ¶
func (gx *Xui) SetPreActionHandler(f func())
SetPreActionHandler sets a hook that is called before a widget action is executed.
func (*Xui) SetRegionView ¶
SetRegionView is a wrapper around gocui.Gui.SetRegionView for changing view size to size of provided region.
func (*Xui) SetViewOnTop ¶
SetViewOnTop is a wrapper around gocui.Gui.SetViewOnTop.
func (*Xui) SetWidgetAction ¶
SetWidgetAction is a wrapper around gocui.Gui.SetKeybinding for sending an action command to widget.