mirror of
https://github.com/octoleo/restic.git
synced 2024-11-30 00:33:57 +00:00
Refactor termstatus.Term.{Print,Error} methods
This commit is contained in:
parent
7c0b6a82db
commit
863a590a81
@ -234,19 +234,23 @@ func (t *Terminal) undoStatus(lines int) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print writes a line to the terminal.
|
func (t *Terminal) print(line string, isErr bool) {
|
||||||
func (t *Terminal) Print(line string) {
|
|
||||||
// make sure the line ends with a line break
|
// make sure the line ends with a line break
|
||||||
if line[len(line)-1] != '\n' {
|
if line[len(line)-1] != '\n' {
|
||||||
line += "\n"
|
line += "\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case t.msg <- message{line: line}:
|
case t.msg <- message{line: line, err: isErr}:
|
||||||
case <-t.closed:
|
case <-t.closed:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Print writes a line to the terminal.
|
||||||
|
func (t *Terminal) Print(line string) {
|
||||||
|
t.print(line, false)
|
||||||
|
}
|
||||||
|
|
||||||
// Printf uses fmt.Sprintf to write a line to the terminal.
|
// Printf uses fmt.Sprintf to write a line to the terminal.
|
||||||
func (t *Terminal) Printf(msg string, args ...interface{}) {
|
func (t *Terminal) Printf(msg string, args ...interface{}) {
|
||||||
s := fmt.Sprintf(msg, args...)
|
s := fmt.Sprintf(msg, args...)
|
||||||
@ -255,15 +259,7 @@ func (t *Terminal) Printf(msg string, args ...interface{}) {
|
|||||||
|
|
||||||
// Error writes an error to the terminal.
|
// Error writes an error to the terminal.
|
||||||
func (t *Terminal) Error(line string) {
|
func (t *Terminal) Error(line string) {
|
||||||
// make sure the line ends with a line break
|
t.print(line, true)
|
||||||
if line[len(line)-1] != '\n' {
|
|
||||||
line += "\n"
|
|
||||||
}
|
|
||||||
|
|
||||||
select {
|
|
||||||
case t.msg <- message{line: line, err: true}:
|
|
||||||
case <-t.closed:
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Errorf uses fmt.Sprintf to write an error line to the terminal.
|
// Errorf uses fmt.Sprintf to write an error line to the terminal.
|
||||||
|
Loading…
Reference in New Issue
Block a user