Documentation
¶
Overview ¶
Package ui defines unified user interface to decouple the information source from the presentation
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Progress ¶
Progress simply sends progress updates along the provided channel. It also logs to the provides `logging.LogFrontend`. All methods are thread-safe.
func (*Progress) SubTaskWithProgress ¶
SubTaskWithProgress creates a task supporting progress. You must call Complete() on the progress when finished.
type Task ¶
type Task struct {
// contains filtered or unexported fields
}
Task simply sends task updates along the provided channel. It also logs everything to the provided log. All methods are thread-safe.
func FromContextOrNoop ¶
FromContextOrNoop returns the current Task.
func (*Task) Info ¶
Info suggests an informational message to be displayed. This is a transient informational message.
func (*Task) Infof ¶
Infof suggests an informational message to be displayed. The message uses Printf style formatting. This is a transient informational message.
func (*Task) SubTask ¶
SubTask returns a new nested Task where everything send is related to the parent and this child task with name. This is a "prefix" for all information in this task. You must call Complete() when done with the work in this Task.
func (*Task) SubTaskWithProgress ¶
SubTaskWithProgress creates a task supporting progress. You must call Complete() on the progress when finished.
type UI ¶
type UI interface { // Root task Root(ctx context.Context) *Task // Run will block until the context is exceeded or Close() is called. This runs the actual UI updating the screen. Run(ctx context.Context) error // Shutdown shuts down the UI. It returns immediately but has the side-effect that Run() should return shortly there-after. Shutdown() }
UI is a simple user interface abstraction.
func NewComplexUI ¶
NewComplexUI returns a new fancy UI that outputs messages to "out". Task names are prefixed to messages to provide the necessary context. Progress is displayed as a progress bar
out must be a terminal.
func NewDebugUI ¶
NewDebugUI returns a debug UI. Output is expected to be a log file.
func NewSilentUI ¶
func NewSilentUI() UI
NewSilentUI returns a UI that outputs nothing (quiet mode).
func NewSimpleUI ¶
NewSimpleUI returns a new simple UI that simply outputs messages to "out". Task names are prefixed to messages to provide the necessary context. Progress is updated regularly.
out need not be a terminal for this UI.
Example ¶
var ui = NewSimpleUI(os.Stdout) rootUI := ui.Root(context.Background()) defer rootUI.Complete() gX := rootUI.SubTask("Processing X") defer gX.Complete() gX.Infof("Doing something now") gY := rootUI.SubTask("Processing Y") defer gY.Complete() gY.Infof("Doing other work") // some time has elapsed... p := gX.SubTaskWithProgress("Transferring") p.Update(4, 100) p.Infof("Finished X") p.Update(99, 100) p.Complete()