mirror of
https://github.com/bcicen/ctop.git
synced 2024-08-30 18:23:19 +00:00
fix byte format for compact view (short)
This commit is contained in:
parent
192d3eaa7a
commit
bbecbc66b9
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user