term

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUserQuit = errors.New("the user manually exited the view")
)

Canned errors for terminal interfaces.

Functions

func List

func List(list QueryableList, maxToDisplay int, vimNavigation bool) (interface{}, error)

List implements an interactive terminal list, printing the interface out to stderr and allowing the user to navigate and choose an option.

The Vim bindings are currently limited to just list navigation.

TODO: I really don't like returning an interface{} and then casting it back to the correct type later. Need to brainstorm better ways to keep this component generalizable while cleaning up the interface

Types

type Event

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

Event represents a keyboard event. If the Key is KeyChar, the char field should be checked for the specific character that was pressed.

type FormattedChunk

type FormattedChunk struct {
	Start  int
	Length int
}

FormattedChunk defines a section of contiguous text.

type FormattedContent

type FormattedContent struct {
	Content    string
	Highlights []FormattedChunk
}

FormattedContent is a set of text with certain parts marked for additional formatting. Content contains all text to be shown, with the Highlights slice specifying section that should be displayed differently.

type Key

type Key int

Key represents keyboard keys.

const (
	KeyChar Key = iota
	KeyCtrlA
	KeyCtrlB
	KeyCtrlC
)

Define various keys that are currently tracked by the application. These are mostly special keys/key combos. KeyChar represents an actual character. The definitions are split up into multiple blocks as only a few keys/key combos are currently tracked.

const (
	KeyUp Key = iota + 512
	KeyDown
)

Define additional keys.

const (
	KeyEnter  Key = 13
	KeyEscape Key = 27
	KeyDelete Key = 127
)

Define even more keys.

type ListItem

type ListItem struct {
	DisplayFields []FormattedContent
	Raw           interface{}
}

ListItem represents an individual item in the list. It is made up of a list of content to display and an associated arbitrary piece of data that will be returned to the caller if the item is selected.

type QueryableList

type QueryableList interface {
	Search(query string) []ListItem
}

QueryableList abstracts a searchable corpus of data. The Search method will be repeatedly called as the query changes.

type Tty

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

Tty represents a raw terminal interface.

func NewTty

func NewTty() (*Tty, error)

NewTty creates a new Tty. It has a side-effect of switching the current terminal to raw mode.

func (*Tty) GetKeyboardEvent

func (t *Tty) GetKeyboardEvent() (*Event, error)

GetKeyboardEvent blocks until there is a keyboard event, and then returns it.

func (*Tty) Stop

func (t *Tty) Stop() error

Stop restore the current terminal to its previous state. It should be called after the caller is done using the Tty.

Jump to

Keyboard shortcuts

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