From 46f04bc5f0c884ccbf513b7a6d097649b62cc5fb Mon Sep 17 00:00:00 2001 From: greatroar <61184462+greatroar@users.noreply.github.com> Date: Tue, 21 May 2024 12:15:22 +0200 Subject: [PATCH] termstatus: Do formatting in Message, not Terminal --- internal/ui/message.go | 14 +++++++++----- internal/ui/termstatus/status.go | 12 ------------ 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/internal/ui/message.go b/internal/ui/message.go index 75e54b019..38cdaf301 100644 --- a/internal/ui/message.go +++ b/internal/ui/message.go @@ -1,6 +1,10 @@ package ui -import "github.com/restic/restic/internal/ui/termstatus" +import ( + "fmt" + + "github.com/restic/restic/internal/ui/termstatus" +) // Message reports progress with messages of different verbosity. type Message struct { @@ -19,27 +23,27 @@ func NewMessage(term *termstatus.Terminal, verbosity uint) *Message { // E reports an error func (m *Message) E(msg string, args ...interface{}) { - m.term.Errorf(msg, args...) + m.term.Error(fmt.Sprintf(msg, args...)) } // P prints a message if verbosity >= 1, this is used for normal messages which // are not errors. func (m *Message) P(msg string, args ...interface{}) { if m.v >= 1 { - m.term.Printf(msg, args...) + m.term.Print(fmt.Sprintf(msg, args...)) } } // V prints a message if verbosity >= 2, this is used for verbose messages. func (m *Message) V(msg string, args ...interface{}) { if m.v >= 2 { - m.term.Printf(msg, args...) + m.term.Print(fmt.Sprintf(msg, args...)) } } // VV prints a message if verbosity >= 3, this is used for debug messages. func (m *Message) VV(msg string, args ...interface{}) { if m.v >= 3 { - m.term.Printf(msg, args...) + m.term.Print(fmt.Sprintf(msg, args...)) } } diff --git a/internal/ui/termstatus/status.go b/internal/ui/termstatus/status.go index fc731b023..4a73ce5b3 100644 --- a/internal/ui/termstatus/status.go +++ b/internal/ui/termstatus/status.go @@ -252,23 +252,11 @@ 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...) - t.Print(s) -} - // Error writes an error to the terminal. func (t *Terminal) Error(line string) { t.print(line, true) } -// Errorf uses fmt.Sprintf to write an error line to the terminal. -func (t *Terminal) Errorf(msg string, args ...interface{}) { - s := fmt.Sprintf(msg, args...) - t.Error(s) -} - // Truncate s to fit in width (number of terminal cells) w. // If w is negative, returns the empty string. func Truncate(s string, w int) string {