diff --git a/cwidgets/compact/gauge.go b/cwidgets/compact/gauge.go index 0862569..2ef7f32 100644 --- a/cwidgets/compact/gauge.go +++ b/cwidgets/compact/gauge.go @@ -38,7 +38,7 @@ func NewMemCol() CompactCol { func (w *MemCol) SetMetrics(m models.Metrics) { w.BarColor = ui.ThemeAttr("gauge.bar.bg") - w.Label = fmt.Sprintf("%s / %s", cwidgets.ByteFormat(m.MemUsage), cwidgets.ByteFormat(m.MemLimit)) + w.Label = fmt.Sprintf("%s / %s", cwidgets.ByteFormat64Short(m.MemUsage), cwidgets.ByteFormat64Short(m.MemLimit)) w.Percent = m.MemPercent } diff --git a/cwidgets/compact/text.go b/cwidgets/compact/text.go index 4b419a0..3a6aa44 100644 --- a/cwidgets/compact/text.go +++ b/cwidgets/compact/text.go @@ -49,7 +49,7 @@ func NewNetCol() CompactCol { } func (w *NetCol) SetMetrics(m models.Metrics) { - label := fmt.Sprintf("%s / %s", cwidgets.ByteFormat(m.NetRx), cwidgets.ByteFormat(m.NetTx)) + label := fmt.Sprintf("%s / %s", cwidgets.ByteFormat64Short(m.NetRx), cwidgets.ByteFormat64Short(m.NetTx)) w.Text = label } @@ -62,7 +62,7 @@ func NewIOCol() CompactCol { } func (w *IOCol) SetMetrics(m models.Metrics) { - label := fmt.Sprintf("%s / %s", cwidgets.ByteFormat(m.IOBytesRead), cwidgets.ByteFormat(m.IOBytesWrite)) + label := fmt.Sprintf("%s / %s", cwidgets.ByteFormat64Short(m.IOBytesRead), cwidgets.ByteFormat64Short(m.IOBytesWrite)) w.Text = label } diff --git a/cwidgets/util.go b/cwidgets/util.go index edb1a92..31c614a 100644 --- a/cwidgets/util.go +++ b/cwidgets/util.go @@ -33,16 +33,6 @@ var ( [2]string{"T", "TiB"}, [2]string{"P", "PiB"}, } - - // maximum displayed precision per unit - maxPrecision = []int{ - 0, // B - 0, // kib - 1, // mib - 1, // gib - 2, // tib - 2, // pib - } ) // convenience methods @@ -63,9 +53,9 @@ func byteFormat(n float64, short bool) string { } if short { - return unpadFloat(n, maxPrecision[i]) + labels[i][0] + return unpadFloat(n, 0) + labels[i][0] } - return unpadFloat(n, maxPrecision[i]) + labels[i][1] + return unpadFloat(n, 2) + labels[i][1] } func unpadFloat(f float64, maxp int) string {