2018-04-22 09:57:20 +00:00
|
|
|
package ui
|
|
|
|
|
2024-05-21 10:15:22 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
2018-04-22 09:57:20 +00:00
|
|
|
|
|
|
|
// Message reports progress with messages of different verbosity.
|
|
|
|
type Message struct {
|
2024-07-27 23:06:26 +00:00
|
|
|
term Terminal
|
2018-04-22 09:57:20 +00:00
|
|
|
v uint
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewMessage returns a message progress reporter with underlying terminal
|
|
|
|
// term.
|
2024-07-27 23:06:26 +00:00
|
|
|
func NewMessage(term Terminal, verbosity uint) *Message {
|
2018-04-22 09:57:20 +00:00
|
|
|
return &Message{
|
|
|
|
term: term,
|
|
|
|
v: verbosity,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// E reports an error
|
|
|
|
func (m *Message) E(msg string, args ...interface{}) {
|
2024-05-21 10:15:22 +00:00
|
|
|
m.term.Error(fmt.Sprintf(msg, args...))
|
2018-04-22 09:57:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// P prints a message if verbosity >= 1, this is used for normal messages which
|
|
|
|
// are not errors.
|
|
|
|
func (m *Message) P(msg string, args ...interface{}) {
|
|
|
|
if m.v >= 1 {
|
2024-05-21 10:15:22 +00:00
|
|
|
m.term.Print(fmt.Sprintf(msg, args...))
|
2018-04-22 09:57:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// V prints a message if verbosity >= 2, this is used for verbose messages.
|
|
|
|
func (m *Message) V(msg string, args ...interface{}) {
|
|
|
|
if m.v >= 2 {
|
2024-05-21 10:15:22 +00:00
|
|
|
m.term.Print(fmt.Sprintf(msg, args...))
|
2018-04-22 09:57:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// VV prints a message if verbosity >= 3, this is used for debug messages.
|
|
|
|
func (m *Message) VV(msg string, args ...interface{}) {
|
|
|
|
if m.v >= 3 {
|
2024-05-21 10:15:22 +00:00
|
|
|
m.term.Print(fmt.Sprintf(msg, args...))
|
2018-04-22 09:57:20 +00:00
|
|
|
}
|
|
|
|
}
|