bless

package module
v0.0.0-...-965577f Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2024 License: MIT Imports: 9 Imported by: 0

README

bless

A TUI library for go. https://github.com/fatih/color is used for colored/formatted text.

Getting started

Once you import and go get github.com/junglehornet/bless use bless.New() to create a new blessing. Parameters are in order as follows:

Selector Open: Opening character when selecting an option.

Selector Close: Closing character when selecting an option.

Frame: Frame character that will be printed around the terminal.

Ex.

b := bless.New("{", "}", '#')

Printing

Use methods to print to a blessing:

b.Println("Hello,")

line := b.Print("World!") // Println and Print return line number where printing started

b.Overwrite(line, "Gophers") // Overwrite takes a line number (int) and overwrites the line with new text

b.Print("!\n this is a new line")

b.RmLine(line + 1) // RmLine removes the line with the line number passed to it.

Output:

Hello,
Gophers!

Color

Use https://github.com/fatih/color for inserting colored strings into the blessing.

red := color.New(color.FgRed).SprintFunc()
b.Print(red("Red text, "))
blue := color.New(color.FgBlue)
b.Print(blue.Sprint("Blue text"))

UI Functions:

Options:

You can use the LROptions function to provide the user with multiple options to choose between. The user can navigate the options with the arrow keys and submit their answer with the Enter/Return key. The first parameter is a prompt, and the rest are options. It returns the index of the chosen option:

b.Print(b.LROptions("Which option?", "option 1", "option 2"))

Output:

Which option?
 option 1 {OPTION 2} // user chooses option 2
1

or,

Which option?
{OPTION 1} option 2 // user chooses option 1
0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Blessing

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

func New

func New(selectorOpen string, selectorClose string, frame rune) Blessing

func (*Blessing) Close

func (b *Blessing) Close()

func (*Blessing) HorizontalOptions

func (b *Blessing) HorizontalOptions(prompt string, options ...string) int

func (*Blessing) Overwrite

func (b *Blessing) Overwrite(startLine int, output ...any)

func (*Blessing) Print

func (b *Blessing) Print(output ...any) int

func (*Blessing) Println

func (b *Blessing) Println(output ...any) int

func (*Blessing) RmLines

func (b *Blessing) RmLines(lines ...int)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳