mirror of
https://github.com/restic/restic.git
synced 2024-12-22 15:57:07 +00:00
ui/termstatus: simplify cleaning up on termination
`writeStatus` also cleans no longer used status lines. The old code actually cleaned one line too much. However, as that line was never used it makes no difference.
This commit is contained in:
parent
6696195f38
commit
6bdca13603
2 changed files with 3 additions and 28 deletions
|
@ -105,7 +105,7 @@ func (t *Terminal) run(ctx context.Context) {
|
|||
select {
|
||||
case <-ctx.Done():
|
||||
if !IsProcessBackground(t.fd) {
|
||||
t.undoStatus(len(status))
|
||||
t.writeStatus([]string{})
|
||||
}
|
||||
|
||||
return
|
||||
|
@ -235,30 +235,6 @@ func (t *Terminal) runWithoutStatus(ctx context.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
func (t *Terminal) undoStatus(lines int) {
|
||||
for i := 0; i < lines; i++ {
|
||||
t.clearCurrentLine(t.wr, t.fd)
|
||||
|
||||
_, err := t.wr.WriteRune('\n')
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "write failed: %v\n", err)
|
||||
}
|
||||
|
||||
// flush is needed so that the current line is updated
|
||||
err = t.wr.Flush()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "flush failed: %v\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
t.moveCursorUp(t.wr, t.fd, lines)
|
||||
|
||||
err := t.wr.Flush()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "flush failed: %v\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (t *Terminal) print(line string, isErr bool) {
|
||||
// make sure the line ends with a line break
|
||||
if line[len(line)-1] != '\n' {
|
||||
|
|
|
@ -39,11 +39,10 @@ func TestSetStatus(t *testing.T) {
|
|||
term.SetStatus([]string{"quux", "needs\nquote"})
|
||||
exp += home + clear + "quux\n" +
|
||||
home + clear + "\"needs\\nquote\"\n" +
|
||||
home + clear + home + up + up // Third line implicit.
|
||||
home + clear + home + up + up // Clear third line
|
||||
|
||||
cancel()
|
||||
exp += home + clear + "\n" + home + clear + "\n" +
|
||||
home + up + up // Status cleared.
|
||||
exp += home + clear + "\n" + home + clear + home + up // Status cleared
|
||||
|
||||
<-term.closed
|
||||
rtest.Equals(t, exp, buf.String())
|
||||
|
|
Loading…
Reference in a new issue