Documentation
¶
Index ¶
- type ConsoleUiBuilder
- func (b *ConsoleUiBuilder) Build() (UserInterface, error)
- func (b *ConsoleUiBuilder) WithErrorOutputWriter(callback func(writer io.Writer) io.Writer) *ConsoleUiBuilder
- func (b *ConsoleUiBuilder) WithInputReader(callback func(reader *bufio.Reader) *bufio.Reader) *ConsoleUiBuilder
- func (b *ConsoleUiBuilder) WithOutputWriter(callback func(writer io.Writer) io.Writer) *ConsoleUiBuilder
- func (b *ConsoleUiBuilder) WithProgressBarGenerator(generator func() ProgressBar) *ConsoleUiBuilder
- type ProgressBar
- type UserInterface
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConsoleUiBuilder ¶
type ConsoleUiBuilder struct {
// contains filtered or unexported fields
}
func NewConsoleUiBuilder ¶
func NewConsoleUiBuilder() *ConsoleUiBuilder
func (*ConsoleUiBuilder) Build ¶
func (b *ConsoleUiBuilder) Build() (UserInterface, error)
func (*ConsoleUiBuilder) WithErrorOutputWriter ¶
func (b *ConsoleUiBuilder) WithErrorOutputWriter(callback func(writer io.Writer) io.Writer) *ConsoleUiBuilder
func (*ConsoleUiBuilder) WithInputReader ¶
func (b *ConsoleUiBuilder) WithInputReader(callback func(reader *bufio.Reader) *bufio.Reader) *ConsoleUiBuilder
func (*ConsoleUiBuilder) WithOutputWriter ¶
func (b *ConsoleUiBuilder) WithOutputWriter(callback func(writer io.Writer) io.Writer) *ConsoleUiBuilder
func (*ConsoleUiBuilder) WithProgressBarGenerator ¶
func (b *ConsoleUiBuilder) WithProgressBarGenerator(generator func() ProgressBar) *ConsoleUiBuilder
type ProgressBar ¶
type ProgressBar interface { // UpdateProgress updates the state of the progress bar. // The argument `progress` should be a float64 between 0 and 1, // where 0 represents 0% completion, and 1 represents 100% completion. // Returns an error if the update operation fails. UpdateProgress(progress float64) error // SetTitle sets the title of the progress bar, which is displayed next to the bar. // The title provides context or description for the operation that is being tracked. SetTitle(title string) // Clear removes the progress bar from the terminal. // Returns an error if the clearing operation fails. Clear() error }
ProgressBar is an interface for interacting with some visual progress-bar. It is used to show the progress of some running task (or multiple). Example:
var pBar ProgressBar = ui.DefaultUi().NewProgressBar(os.Stdout) pBar.SetTitle("Downloading...") for i := 0; i <= 100; i++ { pBar.UpdateProgress(float64(i) / 100.0) time.Sleep(time.Millisecond * 50) } pBar.Clear()
Calling `Clear()` is not required, but the caret will remain at the end of the progress bar, so a linebreak is required. Example:
var pBar ProgressBar = ui.DefaultUi().NewProgressBar(os.Stdout) pBar.SetTitle("Downloading...") for i := 0; i <= 100; i++ { pBar.UpdateProgress(float64(i) / 100.0) time.Sleep(time.Millisecond * 50) } fmt.Println()
The title can be changed in the middle of the progress bar, but it will not be visible until the next update.
type UserInterface ¶
type UserInterface interface { Output(output string) error OutputError(err error) error NewProgressBar() ProgressBar Input(prompt string) (string, error) }
func DefaultUi ¶
func DefaultUi() UserInterface
Click to show internal directories.
Click to hide internal directories.