Skip to content

Commit

Permalink
Fixes #90. The disk widget was truncating, not rounding
Browse files Browse the repository at this point in the history
  • Loading branch information
xxxserxxx committed Apr 21, 2020
1 parent 4895f5e commit dfa7098
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 4 additions & 5 deletions widgets/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit dfa7098

Please sign in to comment.