diff --git a/src/widgets/mem.go b/src/widgets/mem.go index 9fcaf88..a3f1c65 100644 --- a/src/widgets/mem.go +++ b/src/widgets/mem.go @@ -46,6 +46,6 @@ func (self *Mem) update() { swapTotalBytes, swapTotalMagnitude := utils.ConvertBytes(swap.Total) mainUsedBytes, mainUsedMagnitude := utils.ConvertBytes(main.Used) swapUsedBytes, swapUsedMagnitude := utils.ConvertBytes(swap.Used) - self.Labels["Main"] = fmt.Sprintf("%3.0f%% %.0f%s/%.0f%s", main.UsedPercent, mainUsedBytes, mainUsedMagnitude, mainTotalBytes, mainTotalMagnitude) - self.Labels["Swap"] = fmt.Sprintf("%3.0f%% %.0f%s/%.0f%s", swap.UsedPercent, swapUsedBytes, swapUsedMagnitude, swapTotalBytes, swapTotalMagnitude) + self.Labels["Main"] = fmt.Sprintf("%3.0f%% %5.1f%s/%.0f%s", main.UsedPercent, mainUsedBytes, mainUsedMagnitude, mainTotalBytes, mainTotalMagnitude) + self.Labels["Swap"] = fmt.Sprintf("%3.0f%% %5.1f%s/%.0f%s", swap.UsedPercent, swapUsedBytes, swapUsedMagnitude, swapTotalBytes, swapTotalMagnitude) } diff --git a/src/widgets/net.go b/src/widgets/net.go index 14b1522..21a675e 100644 --- a/src/widgets/net.go +++ b/src/widgets/net.go @@ -48,10 +48,12 @@ func (self *Net) update() { interfaces, _ := psNet.IOCounters(false) curRecvTotal := interfaces[0].BytesRecv curSentTotal := interfaces[0].BytesSent + var recvRecent uint64 = 0 + var sentRecent uint64 = 0 if self.prevRecvTotal != 0 { // if this isn't the first update - recvRecent := curRecvTotal - self.prevRecvTotal - sentRecent := curSentTotal - self.prevSentTotal + recvRecent = curRecvTotal - self.prevRecvTotal + sentRecent = curSentTotal - self.prevSentTotal self.Lines[0].Data = append(self.Lines[0].Data, int(recvRecent)) self.Lines[1].Data = append(self.Lines[1].Data, int(sentRecent)) @@ -77,23 +79,17 @@ func (self *Net) update() { // render widget titles for i := 0; i < 2; i++ { - var method string // either 'Rx' or 'Tx' - var total float64 - recent := self.Lines[i].Data[len(self.Lines[i].Data)-1] + total, label, recent := func() (uint64, string, uint64) { + if i == 0 { + return curRecvTotal, "RX", recvRecent + } + return curSentTotal, "Tx", sentRecent + }() - if i == 0 { - total = float64(curRecvTotal) - method = "Rx" - } else { - total = float64(curSentTotal) - method = "Tx" - } + recentConv, unitRecent := utils.ConvertBytes(uint64(recent)) + totalConv, unitTotal := utils.ConvertBytes(uint64(total)) - recentFloat, unitRecent := utils.ConvertBytes(uint64(recent)) - recent = int(recentFloat) - total, unitTotal := utils.ConvertBytes(uint64(total)) - - self.Lines[i].Title1 = fmt.Sprintf(" Total %s: %5.1f %s", method, total, unitTotal) - self.Lines[i].Title2 = fmt.Sprintf(" %s/s: %9d %2s/s", method, recent, unitRecent) + self.Lines[i].Title1 = fmt.Sprintf(" Total %s: %5.1f %s", label, totalConv, unitTotal) + self.Lines[i].Title2 = fmt.Sprintf(" %s/s: %9.1f %2s/s", label, recentConv, unitRecent) } }