xui

package module
v0.0.0-...-ceb8cf2 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2020 License: MIT Imports: 6 Imported by: 1

README

xui

GoDoc Go Report Card

A console user interface toolkit based on gocui (but currently uses my branch). Used by mört.

Pre-alpha software. Expect plenty of bugs and frequent breaking API changes.

TODO

  • Explain why this project was needed.
  • Add documentation.
  • Add examples.
  • Finish this TODO list.

Documentation

Overview

Package xui is a console user interface toolkit based on gocui.

Index

Constants

View Source
const (
	ActionNextLine     = "next_line"
	ActionNextPage     = "next_page"
	ActionPreviousLine = "prev_line"
	ActionPreviousPage = "prev_page"
)

Widget movements

Variables

This section is empty.

Functions

func ErrorHandler

func ErrorHandler(err error) func(*gocui.Gui, *gocui.View) error

ErrorHandler returns a gocui keybinding handler that returns provided error.

func GetLine

func GetLine(view *gocui.View) int

GetLine returns currently selected line for a view (relative to origin).

func Handler

func Handler(f func()) func(*gocui.Gui, *gocui.View) error

Handler returns a gocui keybinding handler that executes provided function and returns a nil error.

func MoveLines

func MoveLines(view *gocui.View, current, max, delta int) error

MoveLines changes selected line of a view.

func Pad

func Pad(s string, n int) string

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

func PromptEditor(g *gocui.Gui, offset int, callback func(bool, string)) gocui.Editor

PromptEditor builds a gocui.Editor function letting user enter a line of text.

func ResizeLayout

func ResizeLayout(layout func(g *gocui.Gui) error) func(g *gocui.Gui) error

ResizeLayout calls provided layout function if view was resized.

func StringWidth

func StringWidth(s string) int

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 Error

func Error(msg string) ErrAction

Error builds an widget action error

func UnknownAction

func UnknownAction() ErrAction

UnknownAction builds an widget action error indicating that the widget didn't understand the action.

func (ErrAction) Error

func (e ErrAction) Error() string

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 Region

type Region struct {
	Left   int
	Top    int
	Right  int
	Bottom int
}

A Region represents the area occupied by a gocui.View without the outer frame.

func (Region) Rect

func (r Region) Rect(g *gocui.Gui) (int, int, int, int)

Rect returns the area occupied by a gocui.View including the outer frame.

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 Widget

type Widget interface {
	View() *gocui.View
	SetView(*gocui.View)
	HandleAction(string) error
}

A Widget can be bound to gocui.View and handle action commands.

type Xui

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

Xui is a wrapper around gocui.Gui.

func New

func New(g *gocui.Gui) *Xui

New wraps a gocui.Gui instance.

func (*Xui) Err

func (gx *Xui) Err() error

Err returns the first encountered error. Always returns nil if a post-action handler has been set.

func (*Xui) Focus

func (gx *Xui) Focus(view *gocui.View)

Focus changes focus to provided view.

func (*Xui) FocusName

func (gx *Xui) FocusName(name string)

FocusName changes focus to view with provided name.

func (*Xui) SetCurrentView

func (gx *Xui) SetCurrentView(name string)

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

func (gx *Xui) SetPostActionHandler(f func(error) error)

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

func (gx *Xui) SetRegionView(name string, r Region) *gocui.View

SetRegionView is a wrapper around gocui.Gui.SetRegionView for changing view size to size of provided region.

func (*Xui) SetView

func (gx *Xui) SetView(name string, x0, y0, x1, y1 int) *gocui.View

SetView is a wrapper around gocui.Gui.SetView.

func (*Xui) SetViewOnTop

func (gx *Xui) SetViewOnTop(name string)

SetViewOnTop is a wrapper around gocui.Gui.SetViewOnTop.

func (*Xui) SetWidgetAction

func (gx *Xui) SetWidgetAction(widget Widget, key interface{}, mod gocui.Modifier, action string)

SetWidgetAction is a wrapper around gocui.Gui.SetKeybinding for sending an action command to widget.

func (*Xui) SetWidgetKeybinding

func (gx *Xui) SetWidgetKeybinding(widget Widget, key interface{}, mod gocui.Modifier, handler func() error)

SetWidgetKeybinding is a wrapper around gocui.Gui.SetKeybinding.

Jump to

Keyboard shortcuts

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