Apply linter autofixes: internal/storage, types, ui (refs #61)
This commit is contained in:
@@ -94,10 +94,12 @@ func shouldColor(w io.Writer) bool {
|
||||
if os.Getenv("NO_COLOR") != "" {
|
||||
return false
|
||||
}
|
||||
|
||||
f, ok := w.(*os.File)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
|
||||
return term.IsTerminal(int(f.Fd()))
|
||||
}
|
||||
|
||||
@@ -106,6 +108,7 @@ func (w *Writer) paint(color, s string) string {
|
||||
if !w.color {
|
||||
return s
|
||||
}
|
||||
|
||||
return color + s + ansiReset
|
||||
}
|
||||
|
||||
@@ -116,6 +119,7 @@ func (w *Writer) Begin(format string, args ...any) {
|
||||
if w.quiet {
|
||||
return
|
||||
}
|
||||
|
||||
w.emit(ansiWhite, Marker, "", format, args)
|
||||
}
|
||||
|
||||
@@ -124,6 +128,7 @@ func (w *Writer) Complete(format string, args ...any) {
|
||||
if w.quiet {
|
||||
return
|
||||
}
|
||||
|
||||
w.emit(ansiGreen, Marker, ansiGreen, format, args)
|
||||
}
|
||||
|
||||
@@ -132,6 +137,7 @@ func (w *Writer) Info(format string, args ...any) {
|
||||
if w.quiet {
|
||||
return
|
||||
}
|
||||
|
||||
w.emit(ansiWhite, Marker, "", format, args)
|
||||
}
|
||||
|
||||
@@ -140,6 +146,7 @@ func (w *Writer) Notice(format string, args ...any) {
|
||||
if w.quiet {
|
||||
return
|
||||
}
|
||||
|
||||
w.emit(ansiCyan, Marker, "", format, args)
|
||||
}
|
||||
|
||||
@@ -167,6 +174,7 @@ func (w *Writer) Detail(format string, args ...any) {
|
||||
if w.quiet {
|
||||
return
|
||||
}
|
||||
|
||||
w.emit(ansiWhite, " "+Marker, "", format, args)
|
||||
}
|
||||
|
||||
@@ -181,6 +189,7 @@ func (w *Writer) Progress(format string, args ...any) {
|
||||
if w.quiet {
|
||||
return
|
||||
}
|
||||
|
||||
w.emit(ansiWhite, " "+Marker, "", format, args)
|
||||
}
|
||||
|
||||
@@ -190,10 +199,12 @@ func (w *Writer) Banner(format string, args ...any) {
|
||||
if w.quiet {
|
||||
return
|
||||
}
|
||||
|
||||
body := fmt.Sprintf(format, args...)
|
||||
if w.color {
|
||||
body = ansiBold + body + ansiReset
|
||||
}
|
||||
|
||||
_, _ = fmt.Fprintln(w.out, body)
|
||||
}
|
||||
|
||||
@@ -204,6 +215,7 @@ func (w *Writer) emit(prefixColor, prefix, bodyColor, format string, args []any)
|
||||
if bodyColor != "" {
|
||||
body = w.paint(bodyColor, body)
|
||||
}
|
||||
|
||||
_, _ = fmt.Fprintln(w.out, w.paint(prefixColor, prefix)+" "+body)
|
||||
}
|
||||
|
||||
@@ -219,6 +231,7 @@ func (w *Writer) Hex(s string) string {
|
||||
if len(s) > 12 {
|
||||
short = s[:12] + "..."
|
||||
}
|
||||
|
||||
return w.paint(ansiCyan, short)
|
||||
}
|
||||
|
||||
@@ -244,8 +257,11 @@ func (w *Writer) Speed(bytesPerSec float64) string {
|
||||
if bytesPerSec <= 0 {
|
||||
return w.paint(ansiMagenta, "N/A")
|
||||
}
|
||||
|
||||
bitsPerSec := bytesPerSec * 8
|
||||
|
||||
var s string
|
||||
|
||||
switch {
|
||||
case bitsPerSec >= 1e9:
|
||||
s = fmt.Sprintf("%.1f Gbit/sec", bitsPerSec/1e9)
|
||||
@@ -256,6 +272,7 @@ func (w *Writer) Speed(bytesPerSec float64) string {
|
||||
default:
|
||||
s = fmt.Sprintf("%.0f bit/sec", bitsPerSec)
|
||||
}
|
||||
|
||||
return w.paint(ansiMagenta, s)
|
||||
}
|
||||
|
||||
@@ -270,10 +287,12 @@ func (w *Writer) Duration(d time.Duration) string {
|
||||
// displayed in the process's local zone.
|
||||
func (w *Writer) Time(t time.Time) string {
|
||||
t = t.Local()
|
||||
|
||||
now := time.Now()
|
||||
if t.Year() == now.Year() && t.YearDay() == now.YearDay() {
|
||||
return w.paint(ansiYellow, t.Format("15:04:05"))
|
||||
}
|
||||
|
||||
return w.paint(ansiYellow, t.Format("2006-01-02 15:04:05"))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user