From dfa7098ad87e645638a52d384eebb178111d073a Mon Sep 17 00:00:00 2001 From: "Sean E. Russell" Date: Tue, 21 Apr 2020 16:14:34 -0500 Subject: [PATCH] Fixes #90. The disk widget was truncating, not rounding --- CHANGELOG.md | 2 ++ widgets/disk.go | 9 ++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 43f7437..4d2670e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Help & statusbar don't obey theme (#47). - Fix help text layout. - Merged fix from @markuspeloquin for custom color scheme loading crash +- Memory line colors were inconsistently assigned (#91) +- The disk code was truncating values instead of rounding (#90) ## [3.5.1] - 2020-04-09 diff --git a/widgets/disk.go b/widgets/disk.go index 3235a6e..b53df9d 100644 --- a/widgets/disk.go +++ b/widgets/disk.go @@ -121,17 +121,16 @@ func (self *DiskWidget) update() { delete(self.Partitions, device) } - // updates partition info + // updates partition info. We add 0.5 to all values to make sure the truncation rounds for _, partition := range self.Partitions { usage, err := psDisk.Usage(partition.MountPoint) if err != nil { log.Printf("failed to get partition usage statistics from gopsutil: %v. partition: %v", err, partition) continue } - partition.UsedPercent = uint32(usage.UsedPercent) - + partition.UsedPercent = uint32(usage.UsedPercent + 0.5) bytesFree, magnitudeFree := utils.ConvertBytes(usage.Free) - partition.Free = fmt.Sprintf("%3d%s", uint64(bytesFree), magnitudeFree) + partition.Free = fmt.Sprintf("%3d%s", uint64(bytesFree+0.5), magnitudeFree) ioCounters, err := psDisk.IOCounters(partition.Device) if err != nil { @@ -146,7 +145,7 @@ func (self *DiskWidget) update() { readFloat, readMagnitude := utils.ConvertBytes(bytesReadRecently) writeFloat, writeMagnitude := utils.ConvertBytes(bytesWrittenRecently) - bytesReadRecently, bytesWrittenRecently = uint64(readFloat), uint64(writeFloat) + bytesReadRecently, bytesWrittenRecently = uint64(readFloat+0.5), uint64(writeFloat+0.5) partition.BytesReadRecently = fmt.Sprintf("%d%s", bytesReadRecently, readMagnitude) partition.BytesWrittenRecently = fmt.Sprintf("%d%s", bytesWrittenRecently, writeMagnitude) } else {