mirror of
https://github.com/tw93/Mole.git
synced 2026-02-16 00:21:11 +00:00
Fix the display issue of swap
This commit is contained in:
BIN
bin/status-go
BIN
bin/status-go
Binary file not shown.
@@ -321,8 +321,8 @@ func renderMemoryCard(mem MemoryStatus) cardData {
|
|||||||
if mem.SwapTotal > 0 {
|
if mem.SwapTotal > 0 {
|
||||||
swapPercent = (float64(mem.SwapUsed) / float64(mem.SwapTotal)) * 100.0
|
swapPercent = (float64(mem.SwapUsed) / float64(mem.SwapTotal)) * 100.0
|
||||||
}
|
}
|
||||||
swapText := subtleStyle.Render(fmt.Sprintf("%s / %s swap", humanBytes(mem.SwapUsed), humanBytes(mem.SwapTotal)))
|
swapText := subtleStyle.Render(fmt.Sprintf("(%s/%s)", humanBytesCompact(mem.SwapUsed), humanBytesCompact(mem.SwapTotal)))
|
||||||
lines = append(lines, fmt.Sprintf("Swap %s %5.1f%% %s", progressBar(swapPercent), swapPercent, swapText))
|
lines = append(lines, fmt.Sprintf("Swap %s %5.1f%% %s", progressBar(swapPercent), swapPercent, swapText))
|
||||||
} else {
|
} else {
|
||||||
lines = append(lines, fmt.Sprintf("Swap %s", subtleStyle.Render("not in use")))
|
lines = append(lines, fmt.Sprintf("Swap %s", subtleStyle.Render("not in use")))
|
||||||
}
|
}
|
||||||
@@ -719,6 +719,21 @@ func humanBytesShort(v uint64) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func humanBytesCompact(v uint64) string {
|
||||||
|
switch {
|
||||||
|
case v >= 1<<40:
|
||||||
|
return fmt.Sprintf("%.1fT", float64(v)/(1<<40))
|
||||||
|
case v >= 1<<30:
|
||||||
|
return fmt.Sprintf("%.1fG", float64(v)/(1<<30))
|
||||||
|
case v >= 1<<20:
|
||||||
|
return fmt.Sprintf("%.1fM", float64(v)/(1<<20))
|
||||||
|
case v >= 1<<10:
|
||||||
|
return fmt.Sprintf("%.1fK", float64(v)/(1<<10))
|
||||||
|
default:
|
||||||
|
return strconv.FormatUint(v, 10)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func shorten(s string, max int) string {
|
func shorten(s string, max int) string {
|
||||||
if len(s) <= max {
|
if len(s) <= max {
|
||||||
return s
|
return s
|
||||||
|
|||||||
Reference in New Issue
Block a user