Documentation ¶
Overview ¶
Package ui provides the terminal UI formatter for Hermit.
This encapsulates both logging and progress.
Output will be cleared if the higher level Hermit operation is successful.
Hermit progress is conveyed via a single progress bar at the bottom of its output, ala modern Ubuntu apt progress. The line below the progress bar will be the list of concurrent actions being run. The capacity of the progress bar will dynamically adjust as new tasks are added.
The progress bar will use partial Unicode blocks: https://en.wikipedia.org/wiki/Block_Elements#Character_table
Log output appears above the progress bar.
Index ¶
- func LogElapsed(log Logger, message string, args ...interface{}) func()
- type Level
- type Logger
- type SyncWriter
- type Task
- func (o *Task) Add(n int)
- func (l *Task) Debugf(format string, args ...interface{})
- func (o *Task) Done()
- func (l *Task) Errorf(format string, args ...interface{})
- func (l *Task) Fatalf(format string, args ...interface{})
- func (l *Task) Infof(format string, args ...interface{})
- func (o *Task) ProgressWriter() io.Writer
- func (o *Task) Size(n int) *Task
- func (o *Task) SubProgress(subtask string, size int) *Task
- func (o *Task) SubTask(subtask string) *Task
- func (l *Task) Tracef(format string, args ...interface{})
- func (l *Task) Warnf(format string, args ...interface{})
- func (o *Task) WillLog(level Level) bool
- func (l *Task) WriterAt(level Level) SyncWriter
- type UI
- func (w *UI) Clear()
- func (w *UI) Confirmation(message string, args ...interface{}) (bool, error)
- func (l UI) Debugf(format string, args ...interface{})
- func (l UI) Errorf(format string, args ...interface{})
- func (l UI) Fatalf(format string, args ...interface{})
- func (l UI) Infof(format string, args ...interface{})
- func (w *UI) Printf(format string, args ...interface{})
- func (w *UI) Progress(task string, size int) *Task
- func (w *UI) SetLevel(level Level)
- func (w *UI) SetProgressBarEnabled(enabled bool)
- func (w *UI) Task(task string) *Task
- func (l UI) Tracef(format string, args ...interface{})
- func (l UI) Warnf(format string, args ...interface{})
- func (w *UI) WillLog(level Level) bool
- func (l UI) WriterAt(level Level) SyncWriter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LogElapsed ¶
LogElapsed logs the duration of a function call. Use with defer:
defer LogElapsed(log, "something")()
Types ¶
type Level ¶
type Level int
Level for a log message.
const ( // LevelAuto will detect the log level from the environment via // HERMIT_LOG=<level>, DEBUG=1, then finally from flag. LevelAuto Level = iota // auto LevelTrace // trace LevelDebug // debug LevelInfo // info LevelWarn // warn LevelError // error LevelFatal // fatal )
Log levels.
func AutoLevel ¶ added in v0.10.0
AutoLevel sets the log level from environment variables if set to LevelAuto.
func LevelFromString ¶
LevelFromString maps a level to a string.
func (*Level) UnmarshalText ¶
type Logger ¶
type Logger interface { io.Writer Tracef(format string, args ...interface{}) Debugf(format string, args ...interface{}) Infof(format string, args ...interface{}) Warnf(format string, args ...interface{}) Errorf(format string, args ...interface{}) Fatalf(format string, args ...interface{}) WriterAt(level Level) SyncWriter }
Logger interface.
type SyncWriter ¶
SyncWriter is an io.Writer that can be Sync()ed.
type Task ¶
type Task struct {
// contains filtered or unexported fields
}
Task encapsulates progress and logging for a single operation.
Operations are not thread safe.
func (*Task) Debugf ¶
func (l *Task) Debugf(format string, args ...interface{})
Debugf logs a message at debug level.
func (*Task) Errorf ¶
func (l *Task) Errorf(format string, args ...interface{})
Errorf logs a message at error level.
func (*Task) Fatalf ¶
func (l *Task) Fatalf(format string, args ...interface{})
Fatalf logs a fatal message and exits with a non-zero status.
Additionally, log output will not be cleared.
func (*Task) Infof ¶
func (l *Task) Infof(format string, args ...interface{})
Infof logs a message at info level.
func (*Task) ProgressWriter ¶
ProgressWriter returns a writer that moves the progress bar as it is written to.
The Size() should have previously been set to the maximum number of bytes that will be written.
func (*Task) SubProgress ¶
SubProgress registers and returns a new subtask with progress.
func (*Task) SubTask ¶
SubTask creates a new unsized subtask.
The size of the operations progress can be configured later.
func (*Task) Tracef ¶
func (l *Task) Tracef(format string, args ...interface{})
Tracef logs a message at trace level.
func (*Task) Warnf ¶
func (l *Task) Warnf(format string, args ...interface{})
Warnf logs a message at warning level.
func (*Task) WriterAt ¶
func (l *Task) WriterAt(level Level) SyncWriter
type UI ¶
type UI struct {
// contains filtered or unexported fields
}
UI controls the display of logs and task progress.
func New ¶
func New(level Level, stdout, stderr SyncWriter, stdoutIsTTY, stderrIsTTY bool) *UI
New creates a new UI.
func NewForTesting ¶
NewForTesting returns a new UI that writes all output to the returned bytes.Buffer.
func (*UI) Confirmation ¶ added in v0.2.21
Confirmation from the user with y/N options to proceed
func (UI) Debugf ¶
func (l UI) Debugf(format string, args ...interface{})
Debugf logs a message at debug level.
func (UI) Errorf ¶
func (l UI) Errorf(format string, args ...interface{})
Errorf logs a message at error level.
func (UI) Fatalf ¶
func (l UI) Fatalf(format string, args ...interface{})
Fatalf logs a fatal message and exits with a non-zero status.
Additionally, log output will not be cleared.
func (UI) Infof ¶
func (l UI) Infof(format string, args ...interface{})
Infof logs a message at info level.
func (*UI) Progress ¶
Progress creates a new task with progress indicator of size.
The resulting Task can be used as a ui.Logger.
func (*UI) SetProgressBarEnabled ¶
SetProgressBarEnabled defines if we want to show the progress bar to the user
func (*UI) Task ¶
Task creates a new unstarted task.
The resulting Task can be used as a ui.Logger.
Task progress can be modified later.
func (UI) Tracef ¶
func (l UI) Tracef(format string, args ...interface{})
Tracef logs a message at trace level.
func (UI) Warnf ¶
func (l UI) Warnf(format string, args ...interface{})
Warnf logs a message at warning level.
func (UI) WriterAt ¶
func (l UI) WriterAt(level Level) SyncWriter