mirror of
https://github.com/restic/restic.git
synced 2025-12-08 06:09:56 +00:00
Merge pull request #5626 from MichaelEischer/lazy-status
ui: only redraw status bar if it has not changed
This commit is contained in:
commit
ebc51e60c9
2 changed files with 18 additions and 5 deletions
|
|
@ -7,3 +7,4 @@ anything in the terminal with certain terminal emulators.
|
||||||
|
|
||||||
https://github.com/restic/restic/issues/5383
|
https://github.com/restic/restic/issues/5383
|
||||||
https://github.com/restic/restic/pull/5551
|
https://github.com/restic/restic/pull/5551
|
||||||
|
https://github.com/restic/restic/pull/5626
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
|
@ -204,6 +205,7 @@ func (t *Terminal) Run(ctx context.Context) {
|
||||||
// run listens on the channels and updates the terminal screen.
|
// run listens on the channels and updates the terminal screen.
|
||||||
func (t *Terminal) run(ctx context.Context) {
|
func (t *Terminal) run(ctx context.Context) {
|
||||||
var status []string
|
var status []string
|
||||||
|
var lastWrittenStatus []string
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
|
|
@ -240,6 +242,7 @@ func (t *Terminal) run(ctx context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
t.writeStatus(status)
|
t.writeStatus(status)
|
||||||
|
lastWrittenStatus = append([]string{}, status...)
|
||||||
case stat := <-t.status:
|
case stat := <-t.status:
|
||||||
status = append(status[:0], stat.lines...)
|
status = append(status[:0], stat.lines...)
|
||||||
|
|
||||||
|
|
@ -248,7 +251,11 @@ func (t *Terminal) run(ctx context.Context) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
t.writeStatus(status)
|
if !slices.Equal(status, lastWrittenStatus) {
|
||||||
|
t.writeStatus(status)
|
||||||
|
// Copy the status slice to avoid aliasing
|
||||||
|
lastWrittenStatus = append([]string{}, status...)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -287,6 +294,7 @@ func (t *Terminal) writeStatus(status []string) {
|
||||||
// runWithoutStatus listens on the channels and just prints out the messages,
|
// runWithoutStatus listens on the channels and just prints out the messages,
|
||||||
// without status lines.
|
// without status lines.
|
||||||
func (t *Terminal) runWithoutStatus(ctx context.Context) {
|
func (t *Terminal) runWithoutStatus(ctx context.Context) {
|
||||||
|
var lastStatus []string
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
|
|
@ -309,11 +317,15 @@ func (t *Terminal) runWithoutStatus(ctx context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
case stat := <-t.status:
|
case stat := <-t.status:
|
||||||
for _, line := range stat.lines {
|
if !slices.Equal(stat.lines, lastStatus) {
|
||||||
// Ensure that each message ends with exactly one newline.
|
for _, line := range stat.lines {
|
||||||
if _, err := fmt.Fprintln(t.wr, strings.TrimRight(line, "\n")); err != nil {
|
// Ensure that each message ends with exactly one newline.
|
||||||
_, _ = fmt.Fprintf(t.errWriter, "write failed: %v\n", err)
|
if _, err := fmt.Fprintln(t.wr, strings.TrimRight(line, "\n")); err != nil {
|
||||||
|
_, _ = fmt.Fprintf(t.errWriter, "write failed: %v\n", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// Copy the status slice to avoid aliasing
|
||||||
|
lastStatus = append([]string{}, stat.lines...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue