Merge pull request #3026 from greatroar/refactor-ui

internal/ui refactoring
This commit is contained in:
MichaelEischer
2020-10-25 17:51:39 +01:00
committed by GitHub
3 changed files with 27 additions and 56 deletions

View File

@@ -234,19 +234,23 @@ func (t *Terminal) undoStatus(lines int) {
}
}
// Print writes a line to the terminal.
func (t *Terminal) Print(line string) {
func (t *Terminal) print(line string, isErr bool) {
// make sure the line ends with a line break
if line[len(line)-1] != '\n' {
line += "\n"
}
select {
case t.msg <- message{line: line}:
case t.msg <- message{line: line, err: isErr}:
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.
func (t *Terminal) Printf(msg string, args ...interface{}) {
s := fmt.Sprintf(msg, args...)
@@ -255,15 +259,7 @@ func (t *Terminal) Printf(msg string, args ...interface{}) {
// Error writes an error to the terminal.
func (t *Terminal) Error(line string) {
// make sure the line ends with a line break
if line[len(line)-1] != '\n' {
line += "\n"
}
select {
case t.msg <- message{line: line, err: true}:
case <-t.closed:
}
t.print(line, true)
}
// Errorf uses fmt.Sprintf to write an error line to the terminal.