fix byte format for compact view (short)

This commit is contained in:
Bradley Cicenas 2020-10-25 16:02:31 +00:00
parent 192d3eaa7a
commit bbecbc66b9
No known key found for this signature in database
GPG Key ID: AF579ED4B93CBB5C
3 changed files with 5 additions and 15 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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 {