mirror of
https://github.com/octoleo/restic.git
synced 2024-12-22 02:48:55 +00:00
Merge pull request #2648 from nairb774/iowritestring
termstatus: Use io.WriteString to output messages.
This commit is contained in:
commit
7910ff4c0e
@ -89,10 +89,6 @@ func (t *Terminal) Run(ctx context.Context) {
|
||||
t.runWithoutStatus(ctx)
|
||||
}
|
||||
|
||||
type stringWriter interface {
|
||||
WriteString(string) (int, error)
|
||||
}
|
||||
|
||||
// run listens on the channels and updates the terminal screen.
|
||||
func (t *Terminal) run(ctx context.Context) {
|
||||
var status []string
|
||||
@ -128,22 +124,14 @@ func (t *Terminal) run(ctx context.Context) {
|
||||
dst = t.wr
|
||||
}
|
||||
|
||||
var err error
|
||||
if w, ok := dst.(stringWriter); ok {
|
||||
_, err = w.WriteString(msg.line)
|
||||
} else {
|
||||
_, err = dst.Write([]byte(msg.line))
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
if _, err := io.WriteString(dst, msg.line); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "write failed: %v\n", err)
|
||||
continue
|
||||
}
|
||||
|
||||
t.writeStatus(status)
|
||||
|
||||
err = t.wr.Flush()
|
||||
if err != nil {
|
||||
if err := t.wr.Flush(); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "flush failed: %v\n", err)
|
||||
}
|
||||
|
||||
@ -194,7 +182,6 @@ func (t *Terminal) runWithoutStatus(ctx context.Context) {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case msg := <-t.msg:
|
||||
var err error
|
||||
var flush func() error
|
||||
|
||||
var dst io.Writer
|
||||
@ -205,13 +192,7 @@ func (t *Terminal) runWithoutStatus(ctx context.Context) {
|
||||
flush = t.wr.Flush
|
||||
}
|
||||
|
||||
if w, ok := dst.(stringWriter); ok {
|
||||
_, err = w.WriteString(msg.line)
|
||||
} else {
|
||||
_, err = dst.Write([]byte(msg.line))
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
if _, err := io.WriteString(dst, msg.line); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "write failed: %v\n", err)
|
||||
}
|
||||
|
||||
@ -219,8 +200,7 @@ func (t *Terminal) runWithoutStatus(ctx context.Context) {
|
||||
continue
|
||||
}
|
||||
|
||||
err = flush()
|
||||
if err != nil {
|
||||
if err := flush(); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "flush failed: %v\n", err)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user