tui

package
v0.0.0-...-9aa4175 Latest Latest
Warning

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

Go to latest
Published: May 16, 2023 License: BSD-2-Clause Imports: 12 Imported by: 0

Documentation

Overview

Package tui contains routines for creating the TUI.

Index

Constants

This section is empty.

Variables

View Source
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}
)
View Source
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 AskYesNo

func AskYesNo(scr tcell.Screen, text string) bool

func Box

func Box(scr tcell.Screen, x, y, width, height int, style tcell.Style)

func FillRect

func FillRect(scr tcell.Screen, x, y, width, height int, char rune, style tcell.Style)

func HLine

func HLine(scr tcell.Screen, x, y int, width int, char rune, style tcell.Style)

func Init

func Init(cfg *Config) tcell.Screen

func InputBox

func InputBox(
	scr tcell.Screen, caption, placeholder string, suggest func(string) []string,
) Optional[string]
func MenuLocationFromString(s string) int

func MessageBox

func MessageBox(scr tcell.Screen, text string, buttons []string, initialSelection int) string

func Quit

func Quit(scr tcell.Screen)

func RightText

func RightText(scr tcell.Screen, x, y, width int, text string, style tcell.Style)

RightText prints a right aligned string.

func Text

func Text(scr tcell.Screen, x, y int, text string, style tcell.Style) int

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.

func VLine

func VLine(scr tcell.Screen, x, y int, height int, char rune, style tcell.Style)

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 BoxStyleFromString(set string) BoxStyle

func GetBoxStyle

func GetBoxStyle(description string) BoxStyle

type Cell

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

func NewCell

func NewCell(char rune, style tcell.Style) Cell

type Dock

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

func NewDock

func NewDock(vAlign, hAlign, columnCount, dynRows, permRows int) Dock

func (*Dock) AlwaysShowSelection

func (self *Dock) AlwaysShowSelection(show bool)

func (*Dock) Click

func (self *Dock) Click(x, y int, button tcell.ButtonMask) Optional[any]

func (*Dock) Down

func (self *Dock) Down()

func (*Dock) GetSelected

func (self *Dock) GetSelected() any

func (*Dock) Left

func (self *Dock) Left()

func (*Dock) Motion

func (self *Dock) Motion(x, y int) bool

func (*Dock) Rect

func (self *Dock) Rect() Rectangle

func (*Dock) Redraw

func (self *Dock) Redraw(scr tcell.Screen)

func (*Dock) Right

func (self *Dock) Right()

func (*Dock) SetItems

func (self *Dock) SetItems(items []string)

func (*Dock) SetPermanentItems

func (self *Dock) SetPermanentItems(items []KeyAction)

func (*Dock) SetViewport

func (self *Dock) SetViewport(viewport Rectangle)

func (*Dock) TranslateAction

func (self *Dock) TranslateAction(f func(int, int) any)

func (*Dock) Up

func (self *Dock) Up()

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 KeyAction

type KeyAction interface {
	Key() rune
	Label() string
	Action() any
}

type Layout

type Layout interface {
	Create()
	Layout(width, height int)
	Update(scr tcell.Screen, widget any)
}

type Line

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

type ListView

type ListView struct {
	AlwaysShowSelection bool
	// contains filtered or unexported fields
}

func NewGenericListView

func NewGenericListView(columnCount int) ListView

func NewListView

func NewListView(
	columnCount int,
	columnWidth Optional[int],
	padColumns bool,
	parenAfterKey bool,
	style tcell.Style,
) ListView

func (*ListView) AddGroup

func (self *ListView) AddGroup(rows int) int

func (*ListView) AddItem

func (self *ListView) AddItem(group, id int, key rune, label string)

func (*ListView) ClearGroup

func (self *ListView) ClearGroup(group int)

ClearGroup empties a group.

func (*ListView) Click

func (self *ListView) Click(x, y int, button tcell.ButtonMask) Optional[any]

func (*ListView) Down

func (self *ListView) Down()

func (*ListView) GetSelected

func (self *ListView) GetSelected() any

func (*ListView) Height

func (self *ListView) Height() (height int)

Height returns the number of rows.

func (*ListView) Left

func (self *ListView) Left()

func (*ListView) Motion

func (self *ListView) Motion(x, y int) bool

func (*ListView) Redraw

func (self *ListView) Redraw(scr tcell.Screen, x, y int)

func (*ListView) ResetSelection

func (self *ListView) ResetSelection()

func (*ListView) Right

func (self *ListView) Right()

func (*ListView) SetColumnWidth

func (self *ListView) SetColumnWidth(width Optional[int])

SetColumnWidth sets or removes the fixed column width. This does not update the mouse map.

func (*ListView) SetPosition

func (self *ListView) SetPosition(x, y int)

func (*ListView) SetRows

func (self *ListView) SetRows(group, rows int)

SetRows sets the allowed number of rows in a group. This also clears that group.

func (*ListView) TranslateAction

func (self *ListView) TranslateAction(f func(int, int) any)

TranslateAction specifies how to translate the current selection into an action. The parameters are f(groupIndex, itemIndexInGroup).

func (*ListView) Up

func (self *ListView) Up()

func (*ListView) Width

func (self *ListView) Width() (width int)

Width returns the combines width of all columns, the fixed column width is ignored for this.

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

func NewMenu

func NewMenu(preferredLocation, rows, cols, topGap int) 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]

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 (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)

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.

func (self *Menu) TranslateAction(f func(int, int) any)
func (self *Menu) Up()
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 (self *MenuContainer) SetEvade(evade Optional[Rectangle]) Optional[int]
func (self *MenuContainer) SetMenu(menu *Menu)
func (self *MenuContainer) SetMenuPosition(x, y, wordWidth int) Optional[int]
func (self *MenuContainer) SetViewport(viewport Rectangle)

type MouseReceiver

type MouseReceiver interface {
	Motion(x, y int) bool
	Click(x, y int, button tcell.ButtonMask) Optional[any]
}

type PaletteSpec

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

type Rectangle

type Rectangle struct {
	X, Y, Width, Height int
}

func NewRectangle

func NewRectangle(x, y, width, height int) Rectangle

func (*Rectangle) Bottom

func (self *Rectangle) Bottom() int

func (*Rectangle) Clamp

func (self *Rectangle) Clamp(inside Rectangle)

func (*Rectangle) Contains

func (self *Rectangle) Contains(x, y int) bool

func (*Rectangle) Overlaps

func (self *Rectangle) Overlaps(other Rectangle) bool

func (*Rectangle) Parts

func (self *Rectangle) Parts() (int, int, int, int)

func (*Rectangle) Right

func (self *Rectangle) Right() int

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

func (*StatusBar) Redraw

func (self *StatusBar) Redraw(scr tcell.Screen)

func (*StatusBar) SetLeft

func (self *StatusBar) SetLeft(text string)

func (*StatusBar) SetRight

func (self *StatusBar) SetRight(text string)

func (*StatusBar) Viewport

func (self *StatusBar) Viewport(y, width int)

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.

func (*TextSlice) Style

func (self *TextSlice) Style() tcell.Style

func (*TextSlice) Text

func (self *TextSlice) Text() string

func (*TextSlice) Width

func (self *TextSlice) Width() int

type Tui

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

func NewTui

func NewTui(scr tcell.Screen, layout Layout) Tui

func (*Tui) Layout

func (self *Tui) Layout()

Layout calls the layouts Layout method with the current screen size.

func (*Tui) RemoveKey

func (self *Tui) RemoveKey(key rune)

func (*Tui) RunUntilAction

func (self *Tui) RunUntilAction() any

func (*Tui) SetArrowReceiver

func (self *Tui) SetArrowReceiver(receiver ArrowReceiver)

func (*Tui) SetInterrupt

func (self *Tui) SetInterrupt(action any)

func (*Tui) SetKey

func (self *Tui) SetKey(key rune, action any)

func (*Tui) SetKeys

func (self *Tui) SetKeys(keys []rune, action any)

func (*Tui) SetMouseReceivers

func (self *Tui) SetMouseReceivers(receivers []MouseReceiver)

func (*Tui) SetUndo

func (self *Tui) SetUndo(action any)

func (*Tui) Update

func (self *Tui) Update(widget any)

Update calls the layouts Update method and shows the screen.

Jump to

Keyboard shortcuts

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