ui

package
v0.0.0-...-3300148 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2023 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command struct {
	Callback    func()
	Description string
}

Command stores a callback function and a description of the command for the footer.

type CommandKey

type CommandKey struct {
	Key  tcell.Key
	Rune rune
	Mod  tcell.ModMask
}

CommandKey stores a tcell compatible key that can be compared to an EventKey event. The Rune for a non-alphabetical key must be set as the Rune value for that key. e.g. KeyEnter == rune(13)

type Drawable

type Drawable interface {
	Draw(ui *PneumaUI)
}

A Drawable is any struct (typically) that can be drawn to a PneumaUI. It must implement a relevant draw call by directly modifying the PneumaUI.

type Label

type Label struct {
	X, Y    int
	Content string
}

A Label is any text string. Essentially just a wrapper around PenumaUI.putStr, but with coordinates.

func (Label) Draw

func (l Label) Draw(ui *PneumaUI)

Draw renders a label to the given PneumaUI.

type Mode

type Mode int

Mode defines the behaviour of the UI: Navigate or Input. It controls how EventKeys are handled in the Tick() method.

const (
	Navigate Mode = iota
	Input
)

Modes for the UI are: Navigate, and Input.

type PneumaUI

type PneumaUI struct {
	Screen      tcell.Screen
	Cursor      cursor
	Exit        bool
	Style       tcell.Style
	Mode        Mode
	InputBuffer string
	Content     []Drawable
	Commands    map[CommandKey]Command
	// contains filtered or unexported fields
}

PneumaUI represents a UI that the user can interact with. It contains a tcell.Screen as well as commands and content.

func Init

func Init() PneumaUI

Init creates everything necessary for an interactive user-interface by creating and initialising a new tcell.Screen, blank command map and setting the cursor to 0,0. It returns a PneumaUI strict.

func (*PneumaUI) AddLabel

func (ui *PneumaUI) AddLabel(x, y int, text string) *Label

AddLabel creates a new Label widget an adds it to the content.

func (*PneumaUI) AddTable

func (ui *PneumaUI) AddTable(x, y int, headings []string, content [][]string) *Table

AddTable appends a new Table widget to the content.

func (PneumaUI) Close

func (ui PneumaUI) Close()

Close finalises the tcell.Screen and exits the program with status code 0.

func (*PneumaUI) Confirm

func (ui *PneumaUI) Confirm(prompt string) bool

Confirm stalls user interaction with a prompt and waits for the user to either accept or reject the prompt (default: reject). This then returns the choice as a boolean.

func (*PneumaUI) Draw

func (ui *PneumaUI) Draw()

Draw renders all of the content to the screen, in order. It does not care about clearing things that are already on screen, meaning that successive Draw() calls can be made with modified content without replacing anything on the screen.

func (*PneumaUI) MoveCursor

func (ui *PneumaUI) MoveCursor(x, y int) error

MoveCursor attempts to place the cursor at a given location and checks for out of bounds errors.

func (*PneumaUI) Redraw

func (ui *PneumaUI) Redraw()

Redraw clears the screen and re-renders all of the widgets in content. It does not reset the cursor or any other state of the PneumaUI

func (*PneumaUI) Reset

func (ui *PneumaUI) Reset()

Reset clears the screen, content and cursor. It essentially puts the ui into the same state as Init does.

func (*PneumaUI) Resume

func (ui *PneumaUI) Resume()

Resume creates a new screen after the previous one was destroyed with Suspend

func (*PneumaUI) SetCommands

func (ui *PneumaUI) SetCommands(commands map[CommandKey]Command)

SetCommands takes a map of CommandKeys and callback functions that will be checked against EventKeys in Tick().

func (*PneumaUI) Suspend

func (ui *PneumaUI) Suspend()

Suspend stops and destroys the screen and allows another program to run

func (*PneumaUI) Tick

func (ui *PneumaUI) Tick()

Tick is the main method that applications using the ui should spin on. It makes sure to check against the Commands while in Navigate mode, executing callbacks if necessary. During Input mode, it ensures to capture alphanumerical letters to the input buffer (terminating on escape or enter) and rendering the character to screen at the cursor.

func (*PneumaUI) WaitForInput

func (ui *PneumaUI) WaitForInput() string

WaitForInput blocks until the user finished entering a string, and returns the inputBuffer of the PneumaUI.

type Table

type Table struct {
	X, Y     int
	Headings []string
	Content  [][]string
	Active   bool
	Index    int
}

A Table is a structured widget that contains string data in rows and columns. It does not manage headers or support non-string content, merely renders it. The Index represents the row (0 indexed) that is currently highlighted.

func (*Table) AddRow

func (t *Table) AddRow(row []string)

AddRow appends a row to the content of a table. It does not redraw the table.

func (Table) Draw

func (t Table) Draw(ui *PneumaUI)

Draw renders a table to the given PneumaUI. It makes sure to size the columns to the max width of the widest item and does not truncate the contents. Furthermore, the selected item is higlighted with tcell.Style.Reverse

func (*Table) NextItem

func (t *Table) NextItem()

NextItem sets the index of the selected item to the next one in the content list, wrapping around when it reaches the end.

func (*Table) PreviousItem

func (t *Table) PreviousItem()

PreviousItem sets the index to the previous item in the content list wrapping around to the end when it reaches the start.

func (*Table) SetContent

func (t *Table) SetContent(headings []string, content [][]string)

SetContent allows the table headings and rows to be changed dynamically. This does not trigger a redraw, but the changes will be seen upon the Draw() function being called.

Jump to

Keyboard shortcuts

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