gluey

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2023 License: MIT Imports: 15 Imported by: 0

README

Gluey

Go Reference

Graphical Line User Experience Yes

Gluey is an opinionated graphic input library for CLI applications. It aims to have a simple cross platform interface over configuability. It is meant to be a port of CLI::UI for Go.

Example

A simple example of how easy it is to use

ctx := gluey.New()
// required text input
username, err := ctx.Ask("Username")
// Hidden output
passwd, err := ctx.Password("Password")
// confirm with default to true
agree, err := ctx.ConfirmDefault("Do you agree to our terms", true)
// Select Single
id, hardness, err := ctx.Select(
  "How hard is it to use this library?",
  []string{"Easy", "Medium", "Hard", "WTF"},
)
// Select Many
ids, editors, err := ctx.SelectMultiple(
  "Which Text Editors do you use",
  []string{"Vim", "Emacs", "Sublime", "VSCode", "Atom", "other"},
)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fmt

func Fmt(template string, data interface{}) string

Fmt will format a string template with color and icons

Types

type Bar

type Bar struct {
	Title   string
	DoneBar string
	RestBar string
	Prefix  string
	Percent string
	// contains filtered or unexported fields
}

Bar is a single progress bar

func (*Bar) Set

func (bar *Bar) Set(val float64)

Set allows to set the current value of the bar

func (*Bar) Tick

func (bar *Bar) Tick(inc float64)

Tick allows to increment the value of the bar

type Ctx

type Ctx struct {
	*log.Logger
	Indent int
}

Ctx allows use to keep a root object for all elements

func New

func New() *Ctx

New builds a new UI context that every element will be based on

func (*Ctx) Ask

func (ctx *Ctx) Ask(label string) (input string, err error)

Ask will prompt the user for a string input and will not return until a value is passed. If the value is an empty string, the user will be re-prompted.

func (*Ctx) AskDefault

func (ctx *Ctx) AskDefault(label, what string) (string, error)

AskDefault will prompt the user for a string input. If the input is an empty string then the defalt value will be returned

func (*Ctx) AskFile

func (ctx *Ctx) AskFile(label string) (string, error)

AskFile will prompt the user for a filepath with autocomplete

func (*Ctx) Confirm

func (ctx *Ctx) Confirm(question string) (bool, error)

Confirm will as a yes or no question and wait for an answer that is one of those.

func (*Ctx) ConfirmSelect added in v0.0.2

func (ctx *Ctx) ConfirmSelect(label string, dflt bool) (bool, error)

ConfirmSelect will prompt the user with a yes/no option. The dflt setting will decide if the first option is yes or no so that the user can just press enter

func (*Ctx) Debreif

func (ctx *Ctx) Debreif(errors map[string]error) error

Debreif is a convienience method to format multi error return from spin groups and progress groups, it will also return the first error for returning errors inside frames

func (*Ctx) InFrame

func (ctx *Ctx) InFrame(title string, fn FrameFunc) error

InFrame will format output to be inside a frame

func (*Ctx) NewProgressGroup

func (ctx *Ctx) NewProgressGroup() *ProgressGroup

NewProgressGroup will create a new progress bar group the will track multiple bars

func (*Ctx) NewSpinGroup

func (ctx *Ctx) NewSpinGroup() *SpinGroup

NewSpinGroup creates a new group of spinners to track multiple statuses

func (*Ctx) Password

func (ctx *Ctx) Password(label string) (string, error)

Password prompts the user for a password input. Characters are not echoed

func (*Ctx) Progress

func (ctx *Ctx) Progress(total float64, fn func(*Ctx, *Bar) error) error

Progress creates a singel progress bar

func (*Ctx) Select

func (ctx *Ctx) Select(label string, items []string) (int, string, error)

Select will propt the user with a list and will allow them to select a single option

func (*Ctx) SelectMultiple

func (ctx *Ctx) SelectMultiple(label string, items []string) ([]int, []string, error)

SelectMultiple will propt the user with a list and will allow them to select multiple options

func (*Ctx) Spinner

func (ctx *Ctx) Spinner(title string, fn func(*Spinner) error) error

Spinner creates a single spinner and waits for it to finish

type Frame

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

Frame is a box around output that can be nested

func (*Frame) Divider

func (frame *Frame) Divider(label, color string)

Divider adds a ┣━━━━ divider to the output

func (*Frame) SetCloseTitle

func (frame *Frame) SetCloseTitle(label string)

SetCloseTitle sets a label that will show on the closing divider

func (*Frame) SetColor

func (frame *Frame) SetColor(color string)

SetColor will set the frames color from this point onward.

func (*Frame) SetShowElapsed added in v0.0.2

func (frame *Frame) SetShowElapsed(show bool)

SetShowElapsed enabled/disables showing the elapsed time when the frame is closed

type FrameFunc

type FrameFunc func(*Ctx, *Frame) error

FrameFunc is the function call that is called inside the frame

type GroupError added in v0.0.2

type GroupError struct {
	Errors map[string]error
}

GroupError will combine errors for a group of concurrent jobs and make them act as a single error but with the ability to still access the errors

func (*GroupError) Error added in v0.0.2

func (err *GroupError) Error() string

type ProgressGroup

type ProgressGroup struct {
	Items []*Bar
	// contains filtered or unexported fields
}

ProgressGroup tracks a group of progress bars

func (*ProgressGroup) Error added in v0.0.2

func (pg *ProgressGroup) Error() error

func (*ProgressGroup) Go

func (pg *ProgressGroup) Go(title string, max float64, fn func(*Ctx, *Bar) error)

Go will add another bar to the group

func (*ProgressGroup) Wait

func (pg *ProgressGroup) Wait()

Wait will pause until all of the progress bars are complete

type Select

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

Select represents a list of items used to enable selections, they can be used as search engines, menus or as a list of items in a cli based prompt.

func (*Select) Selected

func (s *Select) Selected() ([]int, []string)

Selected returns the options that have been chosen

func (*Select) SetCursor

func (s *Select) SetCursor(i int)

SetCursor will set the list cursor to a single item in the list

type SpinGroup

type SpinGroup struct {
	Items []*Spinner
	// contains filtered or unexported fields
}

SpinGroup keeps a group of spinners and their statuses

func (*SpinGroup) Error added in v0.0.2

func (sg *SpinGroup) Error() error

func (*SpinGroup) Go

func (sg *SpinGroup) Go(title string, fn func(*Spinner) error)

Go adds another process to the spin group

func (*SpinGroup) Wait

func (sg *SpinGroup) Wait()

Wait will pause until all spinners are complete

type Spinner

type Spinner struct {
	Title string
	Err   error
	Done  bool
	// contains filtered or unexported fields
}

Spinner is a single spinning status indicator

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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