2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-22 04:45:15 +00:00

Merge pull request #4649 from MichaelEischer/simplify-termstatus-shutdown

ui/termstatus: simplify cleaning up on termination
This commit is contained in:
Michael Eischer 2024-01-23 19:16:21 +01:00 committed by GitHub
commit 2927982256
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 28 deletions

View File

@ -105,7 +105,7 @@ func (t *Terminal) run(ctx context.Context) {
select { select {
case <-ctx.Done(): case <-ctx.Done():
if !IsProcessBackground(t.fd) { if !IsProcessBackground(t.fd) {
t.undoStatus(len(status)) t.writeStatus([]string{})
} }
return 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) { func (t *Terminal) print(line string, isErr bool) {
// 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' {

View File

@ -39,11 +39,10 @@ func TestSetStatus(t *testing.T) {
term.SetStatus([]string{"quux", "needs\nquote"}) term.SetStatus([]string{"quux", "needs\nquote"})
exp += home + clear + "quux\n" + exp += home + clear + "quux\n" +
home + clear + "\"needs\\nquote\"\n" + home + clear + "\"needs\\nquote\"\n" +
home + clear + home + up + up // Third line implicit. home + clear + home + up + up // Clear third line
cancel() cancel()
exp += home + clear + "\n" + home + clear + "\n" + exp += home + clear + "\n" + home + clear + home + up // Status cleared
home + up + up // Status cleared.
<-term.closed <-term.closed
rtest.Equals(t, exp, buf.String()) rtest.Equals(t, exp, buf.String())