clui

package module
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2023 License: MIT Imports: 14 Imported by: 24

README

clui

Go Reference Go Report Card

Command Line User Interface library for building user interfaces that interact with humans. You can find a more comprehensive example here.

demo

Usage

Printing messages
ui := clui.NewUI()
ui.Normal().Msg("The quick brown fox jumps over the lazy dog!")
Asking for input
ui := clui.NewUI()

var stringResult string
ui.Normal().
  WithAskString("What's your name?", &stringResult).
  Do()
Spinner progress
ui := clui.NewUI()
p := ui.Progress("Doing something in the background")
p.Start()
defer p.Stop()
time.Sleep(5 * time.Second)
Tables
ui := clui.NewUI()
ui.Normal().WithTable("#", "Name", "Age", "Link").
  WithTableRow("1", "Stephen J. Fry", "20", "https://aserto.com").Do()

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DotProgress

type DotProgress struct {
	Delay time.Duration // Delay is the speed of the indicator
	// contains filtered or unexported fields
}

DotProgress implements a progress indicator by printing a series of dots as time goes by.

func NewDotProgress

func NewDotProgress(ui *UI, message string) *DotProgress

NewDotProgress creates a new DotProgress

func (*DotProgress) ChangeMessage

func (p *DotProgress) ChangeMessage(message string)

ChangeMessage extends the dot-based progress with the ability to change the message mid-flight

func (*DotProgress) ChangeMessagef

func (p *DotProgress) ChangeMessagef(message string, a ...interface{})

ChangeMessagef extends the dot-based progress with the ability to change the message mid-flight

func (*DotProgress) Start

func (p *DotProgress) Start()

Start start

func (*DotProgress) Stop

func (p *DotProgress) Stop()

Stop stops displaying the dot progress spinner

type Message

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

Message represents a piece of information we want displayed to the user

func (*Message) Compact

func (u *Message) Compact() *Message

Compact disables the printing of a newline before starting output

func (*Message) Do

func (u *Message) Do()

Do is syntactic sugar for Msg("")

func (*Message) Msg

func (u *Message) Msg(message string)

Msg prints a message on the CLI, resolving emoji as it goes

func (*Message) Msgf

func (u *Message) Msgf(message string, a ...interface{})

Msgf prints a formatted message on the CLI

func (*Message) NoNewline

func (u *Message) NoNewline() *Message

NoNewline disables the printing of a newline after a message output

func (*Message) WithAskBool

func (u *Message) WithAskBool(name string, result *bool) *Message

WithAskBool waits for the user's input for a boolean value

func (*Message) WithAskBoolMap added in v0.1.5

func (u *Message) WithAskBoolMap(name string, result *bool, answerMap map[string]bool) *Message

WithAskBool waits for the user's input for a boolean value

func (*Message) WithAskInt

func (u *Message) WithAskInt(name string, result *int64, allowedValues ...int) *Message

WithAskInt waits for the user's input for an int value

func (*Message) WithAskPassword added in v0.1.7

func (u *Message) WithAskPassword(name string, stdin bool, result *string) *Message

WithAskPassword waits for the user's input for a password value

func (*Message) WithAskString

func (u *Message) WithAskString(name string, result *string) *Message

WithAskString waits for the user's input for a string value

func (*Message) WithBoolValue

func (u *Message) WithBoolValue(name string, value bool) *Message

WithBoolValue adds a bool value to be printed in the message

func (*Message) WithEnd

func (u *Message) WithEnd(code int) *Message

WithEnd ends the entire process after printing the message.

func (*Message) WithErr

func (u *Message) WithErr(err error) *Message

WithErr adds an error value to be printed in the message

func (*Message) WithIntValue

func (u *Message) WithIntValue(name string, value int64) *Message

WithIntValue adds an int value to be printed in the message

func (*Message) WithStacks added in v0.1.2

func (u *Message) WithStacks() *Message

WithStack causes error stacks to be printed.

func (*Message) WithStringValue

func (u *Message) WithStringValue(name string, value string) *Message

WithStringValue adds a string value to be printed in the message

func (*Message) WithTable

func (u *Message) WithTable(headers ...string) *Message

WithTable prints a new table

func (*Message) WithTableNoAutoWrapText added in v0.8.1

func (u *Message) WithTableNoAutoWrapText() *Message

func (*Message) WithTableRow

func (u *Message) WithTableRow(values ...string) *Message

WithTableRow adds a row in the latest table

type Progress

type Progress interface {
	Start()
	Stop()
	ChangeMessage(message string)
	ChangeMessagef(message string, a ...interface{})
}

Progress abstracts the operations for a progress meter and/or spinner used to indicate the cli waiting for some background operation to complete.

type UI

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

UI contains functionality for dealing with the user on the CLI

func NewUI

func NewUI() *UI

NewUI creates a new UI

func NewUIWithOutput

func NewUIWithOutput(output io.Writer) *UI

NewUI creates a new UI with a specific output

func NewUIWithOutputAndInput

func NewUIWithOutputAndInput(output io.Writer, input io.Reader) *UI

func NewUIWithOutputErrorAndInput added in v0.1.9

func NewUIWithOutputErrorAndInput(output, err io.Writer, input io.Reader) *UI

NewUI creates a new UI with a specific input, error output and output

func (*UI) Err added in v0.1.9

func (u *UI) Err() io.Writer

func (*UI) Exclamation

func (u *UI) Exclamation() *Message

Exclamation returns a UIMessage that prints an exclamation message

func (*UI) Input added in v0.1.3

func (u *UI) Input() io.Reader

Input returns the io.Reader used to read user input

func (*UI) Normal

func (u *UI) Normal() *Message

Normal returns a UIMessage that prints a normal message

func (*UI) Note

func (u *UI) Note() *Message

Note returns a UIMessage that prints a note message

func (*UI) Output added in v0.1.3

func (u *UI) Output() io.Writer

Output returns the io.Write used to print

func (*UI) Problem

func (u *UI) Problem() *Message

Problem returns a Message that prints a message that describes a problem

func (*UI) Progress

func (u *UI) Progress(message string) Progress

Progress creates, configures, and returns an active progress meter. It accepts a fixed message.

func (*UI) ProgressNote

func (u *UI) ProgressNote() *Message

ProgressNote returns a UIMessage that prints a progress-related message

func (*UI) Progressf

func (u *UI) Progressf(message string, a ...interface{}) Progress

Progressf creates, configures, and returns an active progress meter. It accepts a formatted message.

func (*UI) Success

func (u *UI) Success() *Message

Success returns a UIMessage that prints a success message

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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