diff --git a/decor/counters.go b/decor/counters.go index f7c239e..df8f859 100644 --- a/decor/counters.go +++ b/decor/counters.go @@ -2,6 +2,7 @@ import ( "fmt" + "io" "strconv" "strings" ) @@ -33,8 +34,8 @@ type CounterKiB int64 -func (c CounterKiB) Format(f fmt.State, r rune) { - prec, ok := f.Precision() +func (c CounterKiB) Format(st fmt.State, r rune) { + prec, ok := st.Precision() if r == 'd' || !ok { prec = 0 @@ -66,15 +67,15 @@ res = strconv.FormatInt(int64(c), 10) } - if f.Flag(int(' ')) { + if st.Flag(' ') { res += " " } res += unit - if w, ok := f.Width(); ok { + if w, ok := st.Width(); ok { if len(res) < w { pad := strings.Repeat(" ", w-len(res)) - if f.Flag(int('-')) { + if st.Flag(int('-')) { res += pad } else { res = pad + res @@ -82,22 +83,22 @@ } } - f.Write([]byte(res)) + io.WriteString(st, res) } type CounterKB int64 -func (c CounterKB) Format(f fmt.State, r rune) { - prec, ok := f.Precision() +func (c CounterKB) Format(st fmt.State, verb rune) { + prec, ok := st.Precision() - if r == 'd' || !ok { + if verb == 'd' || !ok { prec = 0 } - if r == 'f' && !ok { + if verb == 'f' && !ok { prec = 6 } // retain old beahavior if s verb used - if r == 's' { + if verb == 's' { prec = 1 } @@ -120,15 +121,15 @@ res = strconv.FormatInt(int64(c), 10) } - if f.Flag(int(' ')) { + if st.Flag(' ') { res += " " } res += unit - if w, ok := f.Width(); ok { + if w, ok := st.Width(); ok { if len(res) < w { pad := strings.Repeat(" ", w-len(res)) - if f.Flag(int('-')) { + if st.Flag(int('-')) { res += pad } else { res = pad + res @@ -136,5 +137,5 @@ } } - f.Write([]byte(res)) + io.WriteString(st, res) }