termutil

package module
v0.0.0-...-ed9f503 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2019 License: MIT Imports: 7 Imported by: 5

README

termbox-util

GoDoc

These are some nice functions torn out of Gomacs which I think are better suited to be out of the project for reuse. It's imported as termutil.

Output Functions

	ClearLine(sx, y int)

Pass the screenwidth and a line number; this function will clear the given line.

	Runewidth(ru rune) int

Returns how many cells wide the given rune is.

	RunewidthStr(s string) int

Returns how many cells wide the given string is.

	PrintRune(x, y int, ru rune, col termbox.Attribute)

Prints the rune given on the screen. Uses reverse colors for unprintable
characters.

	Printstring(s string, x, y int)

Prints the string given on the screen. Uses the above functions to choose how it
appears.

	PrintstringColored(c termbox.Attribute, s string, x, y int)

Same as Printstring, but passes a color to PrintRune.

	DisplayScreenMessage(messages ...string)

Prints all strings given to the screen, and allows the user to scroll through,
rather like less(1).

Input Functions

Most functions take a function they can use to refresh the screen; they pass it the x and y size of the screen (calculated using termbox.Size)

	Prompt(prompt string, refresh func(int, int)) string

Get a string from the user. They can use typical emacs-ish editing commands,
or press C-c or C-g to cancel.

	PromptWithCallback(prompt string, refresh func(int, int), callback func(string, string)) string

As prompt, but calls a function after every keystroke.

	DynamicPromptWithCallback(prompt string, refresh func(int, int), callback func(string, string) string) string

As prompt, but calls a function after every keystroke that can modify the query.

	ChoiceIndex(title string, choices []string, def int) int

Allows the user to select one of many choices displayed on-screen.
Takes a title, choices, and default selection. Returns an index into the choices
array; or def (default)

	ChoiceIndexCallback(title string, choices []string, def int, f func(sel int, sx int, sy int)) int

As ChoiceIndex, but calls a function after drawing the interface, passing it the
currently selected choice, screen width, and screen height.

   ParseTermboxEvent(ev termbox.Event) string

Parses a termbox.EventKey event and returns it as an emacs-ish keybinding string
(e.g. "C-c", "LEFT", "TAB", etc.)

	YesNo(p string, refresh func(int, int)) bool {

Displays the prompt p and asks the user to say y or n. Returns true if y; false
if no.

	YesNoCancel(p string, refresh func(int, int)) (bool, error)

As above, but will return a non-nil error if the user presses C-g.

Documentation

Overview

These are some nice functions torn out of Gomacs which I think are better suited to be out of the project for reuse. It's imported as termutil.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChoiceIndex

func ChoiceIndex(title string, choices []string, def int) int

Allows the user to select one of many choices displayed on-screen. Takes a title, choices, and default selection. Returns an index into the choices array; or def (default)

func ChoiceIndexCallback

func ChoiceIndexCallback(title string, choices []string, def int, f func(int, int, int)) int

As ChoiceIndex, but calls a function after drawing the interface, passing it the current selected choice, screen width, and screen height.

func ClearLine

func ClearLine(sx, y int)

Pass the screenwidth and a line number; this function will clear the given line.

func DisplayScreenMessage

func DisplayScreenMessage(messages ...string)

Prints all strings given to the screen, and allows the user to scroll through, rather like less(1).

func DynamicPromptWithCallback

func DynamicPromptWithCallback(prompt string, refresh func(int, int), callback func(string, string) string) string

As prompt, but calls a function after every keystroke that can modify the query.

func Edit

func Edit(defval, prompt string, refresh func(int, int)) string

Edit takes a default value and a refresh function. It allows the user to edit the default value. It returns what the user entered.

func EditDynamicWithCallback

func EditDynamicWithCallback(defval, prompt string, refresh func(int, int), callback func(string, string) string) string

EditDynamicWithCallback takes a default value, prompt, refresh function, and callback. It allows the user to edit the default value. It returns what the user entered.

func GetRawChar

func GetRawChar(refresh func(int, int)) string

Get a raw character from termbox

func IsControl

func IsControl(ru rune) bool

Returns true if the rune is a control character or invalid rune

func ParseTermboxEvent

func ParseTermboxEvent(ev termbox.Event) string

Parses a termbox.EventKey event and returns it as an emacs-ish keybinding string (e.g. "C-c", "LEFT", "TAB", etc.)

func PressKey

func PressKey(p string, refresh func(int, int), keys ...string) string

Asks the user to press one of a set of keys. Returns the one which they pressed.

func PrintRune

func PrintRune(x, y int, ru rune, col termbox.Attribute)

Prints the rune given on the screen. Uses reverse colors for control characters.

func PrintRuneBgFg

func PrintRuneBgFg(x, y int, ru rune, fg, bg termbox.Attribute)

Print the rune with reverse colors for control characters

func PrintStringFgBg

func PrintStringFgBg(x, y int, s string, fg, bg termbox.Attribute)

Print string with an FG and a BG; API mimicking termbox itself

func Printstring

func Printstring(s string, x, y int)

Prints the string given on the screen. Uses the above functions to choose how it appears.

func PrintstringColored

func PrintstringColored(color termbox.Attribute, s string, x, y int)

Same as Printstring, but passes a color to PrintRune.

func Prompt

func Prompt(prompt string, refresh func(int, int)) string

Get a string from the user. They can use typical emacs-ish editing commands, or press C-c or C-g to cancel.

func PromptWithCallback

func PromptWithCallback(prompt string, refresh func(int, int), callback func(string, string)) string

As prompt, but calls a function after every keystroke.

func Runewidth

func Runewidth(ru rune) int

Returns how many cells wide the given rune is.

func RunewidthStr

func RunewidthStr(s string) int

Returns how many cells wide the given string is

func WordCharacter

func WordCharacter(c rune) bool

Indicate whether the given rune is a word character

func YesNo

func YesNo(p string, refresh func(int, int)) bool

Displays the prompt p and asks the user to say y or n. Returns true if y; false if no.

func YesNoCancel

func YesNoCancel(p string, refresh func(int, int)) (bool, error)

Same as YesNo, but will return a non-nil error if the user presses C-g.

Types

This section is empty.

Jump to

Keyboard shortcuts

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