Documentation ¶
Overview ¶
Package ui defines common UI utilities for gruid: menu/table widget, pager, text input, label, text drawing facilities and replay functionality.
Index ¶
- type Box
- type Label
- type Menu
- type MenuAction
- type MenuConfig
- type MenuEntry
- type MenuKeys
- type MenuStyle
- type Pager
- type PagerAction
- type PagerConfig
- type PagerKeys
- type PagerStyle
- type Replay
- type ReplayConfig
- type ReplayKeys
- type StyledText
- func (stt StyledText) Draw(gd gruid.Grid) gruid.Grid
- func (stt StyledText) Format(width int) StyledText
- func (stt StyledText) Iter(fn func(gruid.Point, gruid.Cell)) gruid.Point
- func (stt StyledText) Markups() map[rune]gruid.Style
- func (stt StyledText) Size() gruid.Point
- func (stt StyledText) Style() gruid.Style
- func (stt StyledText) Text() string
- func (stt StyledText) With(text string, style gruid.Style) StyledText
- func (stt StyledText) WithMarkup(r rune, style gruid.Style) StyledText
- func (stt StyledText) WithMarkups(markups map[rune]gruid.Style) StyledText
- func (stt StyledText) WithStyle(style gruid.Style) StyledText
- func (stt StyledText) WithText(text string) StyledText
- func (stt StyledText) WithTextf(format string, a ...interface{}) StyledText
- type TextInput
- type TextInputAction
- type TextInputConfig
- type TextInputKeys
- type TextInputStyle
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Box ¶
type Box struct { Style gruid.Style // box style Title StyledText // optional title }
Box contains information to draw a rectangle using box characters, with an optional title.
type Label ¶
type Label struct { StyledText StyledText // styled text with initial label text content Box *Box // draw optional box around the label AdjustWidth bool // reduce the width of the label if possible }
Label represents a bunch of text in a grid. It may be boxed and provided with a title.
func NewLabel ¶
func NewLabel(stt StyledText) *Label
NewLabel returns a new label with given styled text and AdjustWidth set to true.
type Menu ¶
type Menu struct {
// contains filtered or unexported fields
}
Menu is a widget that displays a list of entries to the user. It allows to move the active entry, as well as invoke a particular entry.
Menu implements gruid.Model, but is not suitable for use as main model of an application.
func NewMenu ¶
func NewMenu(cfg MenuConfig) *Menu
NewMenu returns a menu with a given configuration.
func (*Menu) Action ¶
func (m *Menu) Action() MenuAction
Action returns the last action performed in the menu.
func (*Menu) SetActive ¶
SetActive updates the active entry among entries. It may be used to launch the menu at a specific default starting index.
func (*Menu) SetEntries ¶
SetEntries updates the list of menu entries.
type MenuAction ¶
type MenuAction int
MenuAction represents an user action with the menu.
const ( // MenuPass reports that the menu state did not change (for example a // mouse motion outside the menu, or within a same entry line). MenuPass MenuAction = iota // MenuMove reports that the user moved the active entry. This happens // by default when using the arrow keys or a mouse motion. MenuMove // MenuInvoke reports that the user clicked or pressed enter to invoke // an already active entry, or used a shortcut key to both activate and // invoke a specific entry. MenuInvoke // MenuQuit reports that the user requested to quit the menu, either by // clicking outside the menu, or by using a key shortcut. MenuQuit )
These constants represent the available actions in a menu.
type MenuConfig ¶
type MenuConfig struct { Grid gruid.Grid // grid slice where the menu is drawn Entries []MenuEntry // menu entries Keys MenuKeys // optional custom key bindings Box *Box // draw optional box around the menu Style MenuStyle }
MenuConfig contains configuration options for creating a menu.
type MenuEntry ¶
type MenuEntry struct { // Text is the styled text displayed on the entry line. Text StyledText // Disabled means that the entry is not invokable. It may represent a // header or an unavailable choice, for example. Disabled bool // Keys contains entry shortcuts, if any, and only for activable // entries. Other menu key bindings take precedence over those. Keys []gruid.Key }
MenuEntry represents an entry in the menu. By default they behave much like a button and can be activated and invoked.
type MenuKeys ¶
type MenuKeys struct { Up []gruid.Key // move up active entry (default: ArrowUp, k) Down []gruid.Key // move down active entry (default: ArrowDown, j) Left []gruid.Key // move left active entry (default: ArrowLeft, h) Right []gruid.Key // move right active entry (default: ArrowRight, l) PageDown []gruid.Key // go one page down (default: PageDown) PageUp []gruid.Key // go one page up (default: PageUp) Invoke []gruid.Key // invoke selection (default: Enter) Quit []gruid.Key // requist menu quit (default: Escape, q, Q) }
MenuKeys contains key bindings configuration for the menu. One step movement keys skip disabled entries.
type MenuStyle ¶
type MenuStyle struct { Layout gruid.Point // menu layout in (columns, lines); 0 means any Active gruid.Style // specific styling for active entry (no change if default) PageNum gruid.Style // page num display style (for boxed menu) }
MenuStyle describes styling options for a menu.
type Pager ¶
type Pager struct {
// contains filtered or unexported fields
}
Pager represents a pager widget for viewing a long list of lines.
Pager implements gruid.Model and can be used as main model of an application.
func NewPager ¶
func NewPager(cfg PagerConfig) *Pager
NewPager returns a new pager with given configuration options.
func (*Pager) Action ¶
func (pg *Pager) Action() PagerAction
Action returns the last action performed with the pager.
func (*Pager) Draw ¶
Draw implements gruid.Model.Draw for Pager. It returns the grid slice that was drawn, or the whole grid if it is used as main model.
func (*Pager) SetLines ¶
func (pg *Pager) SetLines(lines []StyledText)
SetLines updates the pager text lines.
type PagerAction ¶
type PagerAction int
PagerAction represents an user action with the pager.
const ( // PagerPass reports that the pager state did not change (for example a // mouse motion outside the menu, or within a same entry line). PagerPass PagerAction = iota // PagerMove reports a scrolling movement. PagerMove // PagerQuit reports that the user clicked outside the menu, or pressed // Esc, Space or X. PagerQuit )
type PagerConfig ¶
type PagerConfig struct { Grid gruid.Grid // grid slice where the viewable content is drawn Lines []StyledText // content lines to be read Box *Box // draw optional box around the label Keys PagerKeys // optional custom key bindings for the pager Style PagerStyle }
PagerConfig describes configuration options for creating a pager.
type PagerKeys ¶
type PagerKeys struct { Down []gruid.Key // go one line down (default: ArrowDown, j) Up []gruid.Key // go one line up (default: ArrowUp, k) Left []gruid.Key // go left (default: ArrowLeft, h) Right []gruid.Key // go right (default: ArrowRight, l) Start []gruid.Key // go to start of line (default: 0, ^) PageDown []gruid.Key // go one page down (default: PageDown, f) PageUp []gruid.Key // go one page up (default: PageUp, b) HalfPageDown []gruid.Key // go half page down (default: Enter, d) HalfPageUp []gruid.Key // go half page up (default: Backspace, u) Top []gruid.Key // go to the top (default: Home, g) Bottom []gruid.Key // go to the bottom (default: End, G) Quit []gruid.Key // quit pager (default: Escape, q, Q) }
PagerKeys contains key bindings configuration for the pager.
type PagerStyle ¶
PagerStyle describes styling options for a Pager.
type Replay ¶
type Replay struct {
// contains filtered or unexported fields
}
Replay represents an application's session with the given recorded frames.
Replay implements gruid.Model and can be used as main model of an application.
func NewReplay ¶
func NewReplay(cfg ReplayConfig) *Replay
NewReplay returns a new Replay with a given configuration.
type ReplayConfig ¶
type ReplayConfig struct { Grid gruid.Grid // grid to use for drawing FrameDecoder *gruid.FrameDecoder // frame decoder Keys ReplayKeys // optional custom key bindings }
ReplayConfig contains replay configuration.
type ReplayKeys ¶
type ReplayKeys struct { Quit []gruid.Key // quit replay Pause []gruid.Key // pause replay SpeedMore []gruid.Key // increase replay speed SpeedLess []gruid.Key // decrease replay speed FrameNext []gruid.Key // manually go to next frame FramePrev []gruid.Key // manually go to previous frame }
ReplayKeys contains key bindings configuration for the replay.
type StyledText ¶
type StyledText struct {
// contains filtered or unexported fields
}
StyledText is a simple text formatter and styler. The zero value can be used, but you may prefer using Text and Textf.
func NewStyledText ¶
func NewStyledText(text string, st gruid.Style) StyledText
NewStyledText returns a new styled text with the given text and style. It is a shorthand for StyledText{}.With.
func Text ¶
func Text(text string) StyledText
Text is a shorthand for StyledText{}.WithText and creates a new styled text with the given text and the default style.
func Textf ¶
func Textf(format string, a ...interface{}) StyledText
Textf returns a new styled text with the given formatted text, and default style.
func (StyledText) Draw ¶
func (stt StyledText) Draw(gd gruid.Grid) gruid.Grid
Draw displays the styled text in a given grid. It returns the smallest grid slice containing the drawn part. Note that the grid is not cleared with spaces beforehand by this function, not even the returned one, you should use the styled text with a label for this.
func (StyledText) Format ¶
func (stt StyledText) Format(width int) StyledText
Format formats the text so that lines longer than a certain width get wrapped at word boundaries, if possible. It preserves spaces at the beginning of a line. It returns the modified style for convenience.
func (StyledText) Iter ¶
Iter iterates a function for all couples positions and cells representing the styled text, and returns the minimum (w, h) size in cells which can fit the text.
func (StyledText) Markups ¶
func (stt StyledText) Markups() map[rune]gruid.Style
Markups returns a copy of the markups currently defined for the styled text.
func (StyledText) Size ¶
func (stt StyledText) Size() gruid.Point
Size returns the minimum (w, h) size in cells which can fit the text.
func (StyledText) Style ¶
func (stt StyledText) Style() gruid.Style
Style returns the text default style.
func (StyledText) Text ¶
func (stt StyledText) Text() string
Text returns the current styled text as a string.
func (StyledText) With ¶
func (stt StyledText) With(text string, style gruid.Style) StyledText
With returns a derived styled text with new next and style.
func (StyledText) WithMarkup ¶
func (stt StyledText) WithMarkup(r rune, style gruid.Style) StyledText
WithMarkup returns a derived styled text with a new markup @r available for a given style. Markup starts by a @ sign, and is followed then by a rune indicating the particular style. Default style is marked by @N.
This simple markup is inspired from github/gdamore/tcell, but with somewhat different defaults: unless at least one non-default markup is registered, markup commands processing is not activated, and @ is treated as any other character.
func (StyledText) WithMarkups ¶
func (stt StyledText) WithMarkups(markups map[rune]gruid.Style) StyledText
WithMarkups is the same as WithMarkup but passing a whole map of rune-style associations.
func (StyledText) WithStyle ¶
func (stt StyledText) WithStyle(style gruid.Style) StyledText
WithStyle returns a derived styled text with a updated default style.
func (StyledText) WithText ¶
func (stt StyledText) WithText(text string) StyledText
WithText returns a derived styled text with updated text.
func (StyledText) WithTextf ¶
func (stt StyledText) WithTextf(format string, a ...interface{}) StyledText
WithTextf returns a derived styled text with updated formatted text.
type TextInput ¶
type TextInput struct {
// contains filtered or unexported fields
}
TextInput represents a line entry with text supplied from the user that can be validated. It offers only basic editing shortcuts.
TextInput implements gruid.Model, but is not suitable for use as main model of an application.
func NewTextInput ¶
func NewTextInput(cfg TextInputConfig) *TextInput
NewTextInput returns a new text input with given configuration options.
func (*TextInput) Action ¶
func (ti *TextInput) Action() TextInputAction
Action returns the action performed with the TextInput in the last call to Update.
type TextInputAction ¶
type TextInputAction int
TextInputAction represents last user action with the text input.
const ( TextInputPass TextInputAction = iota // no change in state TextInputChange // changed content or moved cursor TextInputInvoke // invoke/accept content TextInputQuit // quit/cancel text input )
These constants represent possible actions raising from interaction with the text input.
type TextInputConfig ¶
type TextInputConfig struct { Grid gruid.Grid // grid slice where the text input is drawn Text StyledText // styled text with initial text input content Prompt StyledText // optional prompt text Box *Box // draw optional box around the text input Keys TextInputKeys // optional custom key bindings for the text input Style TextInputStyle }
TextInputConfig describes configuration options for creating a text input.
type TextInputKeys ¶
TextInputKeys contains key bindings configuration for the text input.
type TextInputStyle ¶
TextInputStyle describes styling options for a TextInput.