Documentation ¶
Overview ¶
Package tui contains routines for creating the TUI.
Index ¶
- Variables
- func Ansi2Style(sequence string) (style tcell.Style)
- func AskYesNo(scr tcell.Screen, text string) bool
- func Box(scr tcell.Screen, x, y, width, height int, style tcell.Style)
- func FillRect(scr tcell.Screen, x, y, width, height int, char rune, style tcell.Style)
- func HLine(scr tcell.Screen, x, y int, width int, char rune, style tcell.Style)
- func Init(cfg *Config) tcell.Screen
- func InputBox(scr tcell.Screen, caption, placeholder string, suggest func(string) []string) Optional[string]
- func MenuLocationFromString(s string) int
- func MessageBox(scr tcell.Screen, text string, buttons []string, initialSelection int) string
- func Quit(scr tcell.Screen)
- func RightText(scr tcell.Screen, x, y, width int, text string, style tcell.Style)
- func Text(scr tcell.Screen, x, y int, text string, style tcell.Style) int
- func TextWithHighlight(scr tcell.Screen, x, y int, text string, highlight int, ...) int
- func TranslateControls(ev *tcell.EventKey) (tcell.Key, rune)
- func VLine(scr tcell.Screen, x, y int, height int, char rune, style tcell.Style)
- type ArrowReceiver
- type BoxStyle
- type Cell
- type Dock
- func (self *Dock) AlwaysShowSelection(show bool)
- func (self *Dock) Click(x, y int, button tcell.ButtonMask) Optional[any]
- func (self *Dock) Down()
- func (self *Dock) GetSelected() any
- func (self *Dock) Left()
- func (self *Dock) Motion(x, y int) bool
- func (self *Dock) Rect() Rectangle
- func (self *Dock) Redraw(scr tcell.Screen)
- func (self *Dock) Right()
- func (self *Dock) SetItems(items []string)
- func (self *Dock) SetPermanentItems(items []KeyAction)
- func (self *Dock) SetViewport(viewport Rectangle)
- func (self *Dock) TranslateAction(f func(int, int) any)
- func (self *Dock) Up()
- func (self *Dock) UpdateMouseMap()
- type GetLineState
- func (self *GetLineState) Backspace() bool
- func (self *GetLineState) Clear() bool
- func (self *GetLineState) Display(width int) (string, int)
- func (self *GetLineState) Event(event *tcell.EventKey) bool
- func (self *GetLineState) MergeHistory(eventTime time.Time)
- func (self *GetLineState) String() string
- func (self *GetLineState) Undo() bool
- func (self *GetLineState) WriteRune(char rune)
- type KeyAction
- type Layout
- type Line
- type ListView
- func (self *ListView) AddGroup(rows int) int
- func (self *ListView) AddItem(group, id int, key rune, label string)
- func (self *ListView) ClearGroup(group int)
- func (self *ListView) Click(x, y int, button tcell.ButtonMask) Optional[any]
- func (self *ListView) Down()
- func (self *ListView) GetSelected() any
- func (self *ListView) Height() (height int)
- func (self *ListView) Left()
- func (self *ListView) Motion(x, y int) bool
- func (self *ListView) Redraw(scr tcell.Screen, x, y int)
- func (self *ListView) ResetSelection()
- func (self *ListView) Right()
- func (self *ListView) SetColumnWidth(width Optional[int])
- func (self *ListView) SetPosition(x, y int)
- func (self *ListView) SetRows(group, rows int)
- func (self *ListView) TranslateAction(f func(int, int) any)
- func (self *ListView) Up()
- func (self *ListView) Width() (width int)
- type Menu
- func (self *Menu) Click(x, y int, button tcell.ButtonMask) Optional[any]
- func (self *Menu) Down()
- func (self *Menu) Evade(rect, inside Rectangle) Optional[int]
- func (self *Menu) GetSelected() any
- func (self *Menu) Left()
- func (self *Menu) Motion(x, y int) bool
- func (self *Menu) Redraw(scr tcell.Screen)
- func (self *Menu) Right()
- func (self *Menu) SetItems(items []string)
- func (self *Menu) SetPosition(x, y, wordWidth int, inside Rectangle, updatePos bool)
- func (self *Menu) TranslateAction(f func(int, int) any)
- func (self *Menu) Up()
- type MenuContainer
- type MouseReceiver
- type PaletteSpec
- type Rectangle
- type SliceIndex
- type StatusBar
- type TextBuffer
- func (self *TextBuffer) AddSlice(slice string) SliceIndex
- func (self *TextBuffer) AddTabbedSlice(text string)
- func (self *TextBuffer) CurrentIndex() SliceIndex
- func (self *TextBuffer) ForEach(f func(string))
- func (self *TextBuffer) ForEachInLine(line int, f func(string, SliceIndex))
- func (self *TextBuffer) ForEachSliceInRange(begin, end SliceIndex, f func(*TextSlice, bool))
- func (self *TextBuffer) GetSlice(idx SliceIndex) *TextSlice
- func (self *TextBuffer) Newline()
- func (self *TextBuffer) NextIndex() SliceIndex
- func (self *TextBuffer) PrintLineAt(scr tcell.Screen, line, x, y int)
- func (self *TextBuffer) RemoveLastLineIfEmpty()
- func (self *TextBuffer) RequiredCapacity() int
- func (self *TextBuffer) SetSliceText(idx SliceIndex, text string)
- func (self *TextBuffer) SetStyle(style tcell.Style)
- type TextBufferView
- func (self *TextBufferView) Redraw(scr tcell.Screen)
- func (self *TextBufferView) Scroll() int
- func (self *TextBufferView) ScrollTo(line, linesAbove int, forceAbove bool)
- func (self *TextBufferView) SetTextBuffer(tb *TextBuffer)
- func (self *TextBufferView) SetViewport(viewport Rectangle)
- func (self *TextBufferView) SlicePosition(index SliceIndex) (int, int)
- func (self *TextBufferView) Text() *TextBuffer
- func (self *TextBufferView) UpdateLine(scr tcell.Screen, line int)
- func (self *TextBufferView) UpdateSlice(scr tcell.Screen, index SliceIndex)
- type TextSlice
- type Tui
- func (self *Tui) Layout()
- func (self *Tui) RemoveKey(key rune)
- func (self *Tui) RunUntilAction() any
- func (self *Tui) SetArrowReceiver(receiver ArrowReceiver)
- func (self *Tui) SetInterrupt(action any)
- func (self *Tui) SetKey(key rune, action any)
- func (self *Tui) SetKeys(keys []rune, action any)
- func (self *Tui) SetMouseReceivers(receivers []MouseReceiver)
- func (self *Tui) SetUndo(action any)
- func (self *Tui) Update(widget any)
Constants ¶
This section is empty.
Variables ¶
var ( // FIXME: this is ugly and feels out of place here Colors = struct { Comment, LineNumber, CurrentLineNumber, BoxOutline, Menu, StatusBar tcell.Style }{ tcell.StyleDefault, tcell.StyleDefault, tcell.StyleDefault, tcell.StyleDefault, tcell.StyleDefault, tcell.StyleDefault, } Alignment = struct{ Begin, Center, End, Fill int }{0, 1, 2, 3} )
var MenuLocation = struct { Right int Below int BelowRight int }{0, 1, 2}
Functions ¶
func Ansi2Style ¶
func Ansi2Style(sequence string) (style tcell.Style)
Ansi2Style converts a SGR ansi escape sequence to a tcell Style.
func MenuLocationFromString ¶
func MessageBox ¶
func TextWithHighlight ¶
func TextWithHighlight( scr tcell.Screen, x, y int, text string, highlight int, normalStyle, highlightStyle tcell.Style, ) int
TextWithHighlight prints the given strings, highlighting one character.
func TranslateControls ¶
func TranslateControls(ev *tcell.EventKey) (tcell.Key, rune)
TranslateControls gets the key and rune from the given event, translating upper and lowercase HJKL to arrow keys. Additionally converts space to enter.
Types ¶
type ArrowReceiver ¶
type ArrowReceiver interface { Up() Down() Left() Right() GetSelected() any }
type BoxStyle ¶
type BoxStyle struct { Vertical rune Horizontal rune TopLeft rune TopRight rune BottomLeft rune BottomRight rune VerticalRight rune VerticalLeft rune HorizontalDown rune HorizontalUp rune Cross rune }
func BoxStyleFromString ¶
func GetBoxStyle ¶
type Dock ¶
type Dock struct {
// contains filtered or unexported fields
}
func (*Dock) AlwaysShowSelection ¶
func (*Dock) GetSelected ¶
func (*Dock) SetPermanentItems ¶
func (*Dock) SetViewport ¶
func (*Dock) UpdateMouseMap ¶
func (self *Dock) UpdateMouseMap()
type GetLineState ¶
type GetLineState struct {
// contains filtered or unexported fields
}
func (*GetLineState) Backspace ¶
func (self *GetLineState) Backspace() bool
func (*GetLineState) Clear ¶
func (self *GetLineState) Clear() bool
func (*GetLineState) Display ¶
func (self *GetLineState) Display(width int) (string, int)
Display returns the string to display the state and a character to highlight.
func (*GetLineState) Event ¶
func (self *GetLineState) Event(event *tcell.EventKey) bool
Event processes a key event, returning true if a redraw is necessary.
func (*GetLineState) MergeHistory ¶
func (self *GetLineState) MergeHistory(eventTime time.Time)
MergeHistory merges the last addition to the history if it's close in time to the last non-merged change.
func (*GetLineState) String ¶
func (self *GetLineState) String() string
func (*GetLineState) Undo ¶
func (self *GetLineState) Undo() bool
func (*GetLineState) WriteRune ¶
func (self *GetLineState) WriteRune(char rune)
type ListView ¶
type ListView struct { AlwaysShowSelection bool // contains filtered or unexported fields }
func NewGenericListView ¶
func NewListView ¶
func (*ListView) ClearGroup ¶
ClearGroup empties a group.
func (*ListView) GetSelected ¶
func (*ListView) ResetSelection ¶
func (self *ListView) ResetSelection()
func (*ListView) SetColumnWidth ¶
SetColumnWidth sets or removes the fixed column width. This does not update the mouse map.
func (*ListView) SetPosition ¶
func (*ListView) SetRows ¶
SetRows sets the allowed number of rows in a group. This also clears that group.
func (*ListView) TranslateAction ¶
TranslateAction specifies how to translate the current selection into an action. The parameters are f(groupIndex, itemIndexInGroup).
type Menu ¶
type Menu struct {
// contains filtered or unexported fields
}
func (*Menu) Evade ¶
Evade attempts to evade rect while staying inside inside. The resulting viewport will always be inside inside but it cannot guarantee that rect will always be evaded. If the menu needs to go above the word, the lines that need to be visible above the words line are returned. NOTE: rect is assumed to be to the bottom right of the menu.
func (*Menu) GetSelected ¶
func (*Menu) SetPosition ¶
SetPosition sets the position on the menu next to a word. x and y are position of the word and wordWidth is the width of that word. The menu will be appropriately position inside the given rectangle to be next to that word. If updatePos is false the list views position is not updated.
type MenuContainer ¶
type MenuContainer struct {
// contains filtered or unexported fields
}
MenuContainer manages the area inside of which a menu may exist.
func NewMenuContainer ¶
func NewMenuContainer() MenuContainer
func (*MenuContainer) SetEvade ¶
func (self *MenuContainer) SetEvade(evade Optional[Rectangle]) Optional[int]
func (*MenuContainer) SetMenu ¶
func (self *MenuContainer) SetMenu(menu *Menu)
func (*MenuContainer) SetMenuPosition ¶
func (self *MenuContainer) SetMenuPosition(x, y, wordWidth int) Optional[int]
func (*MenuContainer) SetViewport ¶
func (self *MenuContainer) SetViewport(viewport Rectangle)
type MouseReceiver ¶
type PaletteSpec ¶
type PaletteSpec struct {
// contains filtered or unexported fields
}
type SliceIndex ¶
type SliceIndex struct {
// contains filtered or unexported fields
}
func NewSliceIndex ¶
func NewSliceIndex(line, slice int) SliceIndex
func (*SliceIndex) IsBefore ¶
func (self *SliceIndex) IsBefore(other SliceIndex) bool
IsBefore returns true is this slice comes before the given slice.
func (*SliceIndex) IsSameOrAfter ¶
func (self *SliceIndex) IsSameOrAfter(other SliceIndex) bool
IsSameOrAfter returns true if this slice is equal to or after the given slice.
func (*SliceIndex) Line ¶
func (self *SliceIndex) Line() int
func (*SliceIndex) OffsetLine ¶
func (self *SliceIndex) OffsetLine(by int)
type StatusBar ¶
type StatusBar struct {
// contains filtered or unexported fields
}
func NewStausBar ¶
func NewStausBar() StatusBar
type TextBuffer ¶
type TextBuffer struct {
// contains filtered or unexported fields
}
TextBuffer holds lines of text that are themselves split into slices. It also acts as a builder for itself.
func NewTextBuffer ¶
func NewTextBuffer(tabSize int) TextBuffer
func (*TextBuffer) AddSlice ¶
func (self *TextBuffer) AddSlice(slice string) SliceIndex
AddSlice adds a single slice to the buffer. The given slice may not contain tab characters.
func (*TextBuffer) AddTabbedSlice ¶
func (self *TextBuffer) AddTabbedSlice(text string)
AddTabbedSlice adds a slice that may contain tabs.
func (*TextBuffer) CurrentIndex ¶
func (self *TextBuffer) CurrentIndex() SliceIndex
CurrentIndex returns the index of the most recently added slice.
func (*TextBuffer) ForEach ¶
func (self *TextBuffer) ForEach(f func(string))
ForEach calls the given function for each slice and line ending of the text buffer. For newlines it is always called with "\n".
func (*TextBuffer) ForEachInLine ¶
func (self *TextBuffer) ForEachInLine(line int, f func(string, SliceIndex))
ForEachInLine calls the given function for each slice in the specified line.
func (*TextBuffer) ForEachSliceInRange ¶
func (self *TextBuffer) ForEachSliceInRange(begin, end SliceIndex, f func(*TextSlice, bool))
ForEachSliceInRange calls the given function for each slice in the given range. The function also receives a boolean which is true if it's the last slice in its line.
func (*TextBuffer) GetSlice ¶
func (self *TextBuffer) GetSlice(idx SliceIndex) *TextSlice
func (*TextBuffer) Newline ¶
func (self *TextBuffer) Newline()
func (*TextBuffer) NextIndex ¶
func (self *TextBuffer) NextIndex() SliceIndex
NextIndex returns the index of the next slice being added, assuming no newline is added before.
func (*TextBuffer) PrintLineAt ¶
func (self *TextBuffer) PrintLineAt(scr tcell.Screen, line, x, y int)
func (*TextBuffer) RemoveLastLineIfEmpty ¶
func (self *TextBuffer) RemoveLastLineIfEmpty()
func (*TextBuffer) RequiredCapacity ¶
func (self *TextBuffer) RequiredCapacity() int
RequiredCapacity returns the number of bytes needed to store the text inside the text buffer.
func (*TextBuffer) SetSliceText ¶
func (self *TextBuffer) SetSliceText(idx SliceIndex, text string)
func (*TextBuffer) SetStyle ¶
func (self *TextBuffer) SetStyle(style tcell.Style)
type TextBufferView ¶
type TextBufferView struct {
// contains filtered or unexported fields
}
TextBufferView manages drawing of a TextBuffer
func NewTextBufferView ¶
func NewTextBufferView() TextBufferView
func (*TextBufferView) Redraw ¶
func (self *TextBufferView) Redraw(scr tcell.Screen)
func (*TextBufferView) Scroll ¶
func (self *TextBufferView) Scroll() int
func (*TextBufferView) ScrollTo ¶
func (self *TextBufferView) ScrollTo(line, linesAbove int, forceAbove bool)
func (*TextBufferView) SetTextBuffer ¶
func (self *TextBufferView) SetTextBuffer(tb *TextBuffer)
func (*TextBufferView) SetViewport ¶
func (self *TextBufferView) SetViewport(viewport Rectangle)
func (*TextBufferView) SlicePosition ¶
func (self *TextBufferView) SlicePosition(index SliceIndex) (int, int)
SlicePosition returns the (x, y) coordinates of the slice at index in the current viewport.
func (*TextBufferView) Text ¶
func (self *TextBufferView) Text() *TextBuffer
func (*TextBufferView) UpdateLine ¶
func (self *TextBufferView) UpdateLine(scr tcell.Screen, line int)
UpdateLine repaints a line if its currently inside the viewport.
func (*TextBufferView) UpdateSlice ¶
func (self *TextBufferView) UpdateSlice(scr tcell.Screen, index SliceIndex)
UpdateSlice repaints a single slice if its currently inside the viewport.
type TextSlice ¶
type TextSlice struct {
// contains filtered or unexported fields
}
func (*TextSlice) ReverseColors ¶
func (self *TextSlice) ReverseColors()
ReverseColors toggles the reverse attribute of the slices style.
type Tui ¶
type Tui struct {
// contains filtered or unexported fields
}
func (*Tui) Layout ¶
func (self *Tui) Layout()
Layout calls the layouts Layout method with the current screen size.
func (*Tui) RunUntilAction ¶
func (*Tui) SetArrowReceiver ¶
func (self *Tui) SetArrowReceiver(receiver ArrowReceiver)
func (*Tui) SetInterrupt ¶
func (*Tui) SetMouseReceivers ¶
func (self *Tui) SetMouseReceivers(receivers []MouseReceiver)