ttuy

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2023 License: GPL-2.0 Imports: 7 Imported by: 0

README

ttuy

ttuy

Build GoDoc

ttuy (pronounced tee-tee-YU-Y or like TUI) is an easy-to-use, performant, procedural TUI framework.

go get github.com/electrikmilk/ttuy
import "github.com/electrikmilk/ttuy"

Documentation

ttuy uses ANSI escape codes to manipulate the terminal.

Documentation

Index

Constants

View Source
const CSI = "\033["
View Source
const Reset = CSI + "0m"

Variables

View Source
var BlackBg = bg + black
View Source
var BlackText = fg + black
View Source
var BlueBg = bg + blue
View Source
var BlueText = fg + blue
View Source
var BrightBlueBg = bg + brightBlue
View Source
var BrightBlueText = fg + brightBlue
View Source
var BrightCyanBg = bg + brightCyan
View Source
var BrightCyanText = fg + brightCyan
View Source
var BrightGreenBg = bg + brightGreen
View Source
var BrightGreenText = fg + brightGreen
View Source
var BrightMagentaBg = bg + brightMagenta
View Source
var BrightMagentaText = fg + brightMagenta
View Source
var BrightRedBg = bg + brightRed
View Source
var BrightRedText = fg + brightRed
View Source
var BrightYellowBg = bg + brightYellow
View Source
var BrightYellowText = fg + brightYellow
View Source
var CyanBg = bg + cyan
View Source
var CyanText = fg + cyan
View Source
var GrayBg = bg + gray
View Source
var GrayText = fg + gray
View Source
var GreenBg = bg + green
View Source
var GreenText = fg + green
View Source
var MagentaBg = bg + magenta
View Source
var MagentaText = fg + magenta
View Source
var RedBg = bg + red
View Source
var RedText = fg + red
View Source
var WhiteBg = bg + white
View Source
var WhiteText = fg + white
View Source
var YellowBg = bg + yellow
View Source
var YellowText = fg + yellow

Functions

func Ask

func Ask(prompt string, store *string)

Ask prints your prompt and feeds input from os.Stdin into store

func AskSecret

func AskSecret(prompt string, store *string)

AskSecret prints your prompt and feeds input from os.Stdin into store but hides the input

func BackUp

func BackUp()

BackUp passes `currentLine` to LinePrev to go to the previous line `currentLine` number of times. It then resets `currentLine` to 0.

func Background

func Background(str string, code int) string

Background style str using code

func Banner(message string) (banner string)

Banner returns a banner around `message` made of # signs. ######## EXAMPLE ########

func Bell

func Bell()

Bell triggers the system bell which makes the machine make an alarm noise.

func BigBanner

func BigBanner(message string) (banner string)

BigBanner returns a box around `message` made of # signs. ########### # EXAMPLE # ###########

func ClearDisplay

func ClearDisplay()

ClearDisplay clears part of the screen

func ClearLine

func ClearLine()

ClearLine clears the current line

func Cursor

func Cursor(row int, col int)

Cursor moves the cursor to a specific position on the screen. `row` sets the cursors Y position `col` sets the cursors X position

func CursorBack

func CursorBack(columns int)

CursorBack moves the cursor back `columns` number of times

func CursorFwd

func CursorFwd(columns int)

CursorFwd moves the cursor forward `columns` number of times

func CursorHide

func CursorHide()

CursorHide makes the cursor hidden

func CursorShow

func CursorShow()

CursorShow makes the cursor visible

func CursorStart

func CursorStart()

CursorStart moves the cursor to the start of the current line

func Fail

func Fail(message string)

Fail prints message styled as an error then exits

func FailErr

func FailErr(label string, err error)

FailErr handles err and prints label with err as a string styled then exits

func Failf

func Failf(message string, v ...any)

Failf prints message formatted and styled as an error then exits

func File

func File(path string)

File print the content of the file at path

func Foreground

func Foreground(str string, code int) string

Foreground style str using code

func Grid

func Grid(rows []Row) (grid string)

Grid arranges cells in rows in a grid

func Info

func Info(message string)

Info prints message highlighted

func Infof

func Infof(message string, v ...any)

Infof prints message formatted and highlighted

func LineDown

func LineDown(lines int)

LineDown moves the cursor down `lines` number of lines

func LineFeed

func LineFeed()

LineFeed simulates a line feed by going to the next line and scrolling up once

func LineNext

func LineNext(lines int)

LineNext moves the cursor to the next line, `lines` number of times

func LinePrev

func LinePrev(lines int)

LinePrev moves the cursor to the previous line, `lines` number of times

func LineUp

func LineUp(lines int)

LineUp moves the cursor up `lines` number of lines

func Menu(title string, options []Option)

Menu displays a menu of options and triggers the callback corresponding to the option chosen

func Painter

func Painter(callback Template)

Painter prints and updates content received from Template Learn more: https://github.com/electrikmilk/ttuy/wiki/Painter()

func ProgressBar

func ProgressBar(status int)

ProgressBar prints a progress bar

func Prompt

func Prompt(prompt string) (proceed bool)

Prompt prints a prompt for the user to choose yes or no using the arrow keys then returns a boolean based on the option chosen

func ScrollDown

func ScrollDown(lines int)

ScrollDown scrolls the whole page down by `lines` lines

func ScrollUp

func ScrollUp(lines int)

ScrollUp scrolls the whole page up by `lines` lines

func Segmented

func Segmented(n string) string

Segmented transforms n into a series of characters resembling a segmented display. It accepts numbers 0-9 and colons. Example: "20:00"

func Spinner

func Spinner(status string, style SpinnerStyle)

Spinner prints a progress indicator in style until StopSpinner() is called You must use a goroutine when running this function (e.g. go Spinner(...))

func StopPainting

func StopPainting()

StopPainting triggers current usage of Painter to stop

func StopSpinner

func StopSpinner()

StopSpinner stops the current spinner

func Style

func Style(str string, styles ...SGR) string

Style formats str using styles to prefix str with SGR sequences

func StylePersist

func StylePersist(styles ...SGR) string

StylePersist outputs SGR sequences with no reset Anything after will be formatted using styles until the Reset constant is used

func Success

func Success(message string)

Success prints message styled as a success

func Successf

func Successf(message string, v ...any)

Successf prints message styled and formatted as a success

func Table

func Table(headers []string, rows []Row)

Table prints rows with headers in a text table

func Typewriter

func Typewriter(message string)

Typewriter prints characters in message out one at a time

func TypewriterTimed

func TypewriterTimed(message string, duration time.Duration)

TypewriterTimed prints characters in message out one at a time at duration

func Viewport

func Viewport(content string)

Viewport displays content in a scrollable widget

func Warn

func Warn(message string)

Warn prints message styled as a warning

func Warnf

func Warnf(message string, v ...any)

Warnf prints message formatted and styled as a warning

func YesNo

func YesNo(prompt string) (proceed bool)

YesNo prints a prompt that waits for "y" or "n" from os.Stdin and returns a boolean based on the input

Types

type Option

type Option struct {
	Label    string
	Callback func()
	Disabled bool
}

type Row

type Row struct {
	Columns []string
}

type SGR

type SGR string
const Blink SGR = "5"
const BlinkFast SGR = "6"
const Bold SGR = "1"
const Crossed SGR = "9"
const Dim SGR = "2"
const Hidden SGR = "8"
const Inverted SGR = "7"
const Italic SGR = "3"
const Underlined SGR = "4"

type SpinnerStyle

type SpinnerStyle string
const Blinker SpinnerStyle = "blinker"
const DotDotDot SpinnerStyle = "dotdotdot"
const Throbber SpinnerStyle = "throbber"
const Ticker SpinnerStyle = "ticker"

type Template

type Template func() string

Jump to

Keyboard shortcuts

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