From f66833c2cc7d03eb993c85476de564ed9160b101 Mon Sep 17 00:00:00 2001 From: Tony Lambiris Date: Tue, 13 Nov 2018 12:29:09 -0500 Subject: [PATCH] Add --fahrenheit flag, fix CPU ordering --- main.go | 5 ++++- src/widgets/cpu.go | 4 ++-- src/widgets/temp.go | 24 +++++++++++++++++------- src/widgets/temp_darwin.go | 6 +++++- src/widgets/temp_linux.go | 6 +++++- src/widgets/temp_windows.go | 6 +++++- 6 files changed, 38 insertions(+), 13 deletions(-) diff --git a/main.go b/main.go index 53997e84..827a6c83 100644 --- a/main.go +++ b/main.go @@ -30,6 +30,7 @@ var ( averageLoad = false percpuLoad = false widgetCount = 6 + fahrenheit = false cpu *w.CPU mem *w.Mem @@ -52,6 +53,7 @@ Options: -v, --version Show version. -p, --percpu Show each CPU in the CPU widget. -a, --averagecpu Show average CPU in the CPU widget. + -f, --fahrenheit Show temperatures in fahrenheit. Colorschemes: default @@ -80,6 +82,7 @@ Colorschemes: } else { interval = time.Second / time.Duration(rate) } + fahrenheit, _ = args["--fahrenheit"].(bool) } func handleColorscheme(cs string) { @@ -204,7 +207,7 @@ func initWidgets() { wg.Done() }() go func() { - temp = w.NewTemp() + temp = w.NewTemp(fahrenheit) wg.Done() }() } diff --git a/src/widgets/cpu.go b/src/widgets/cpu.go index 1079bbb0..15c1b548 100644 --- a/src/widgets/cpu.go +++ b/src/widgets/cpu.go @@ -43,7 +43,7 @@ func NewCPU(interval time.Duration, zoom int, average bool, percpu bool) *CPU { if self.PerCPU { for i := 0; i < self.Count; i++ { - k := fmt.Sprintf("CPU%d", i) + k := fmt.Sprintf("CPU%02d", i) self.Data[k] = []float64{0} } } @@ -85,7 +85,7 @@ func (self *CPU) update() { )) } for i := 0; i < self.Count; i++ { - k := fmt.Sprintf("CPU%d", i) + k := fmt.Sprintf("CPU%02d", i) self.Data[k] = append(self.Data[k], percents[i]) self.Labels[k] = fmt.Sprintf("%3.0f%%", percents[i]) } diff --git a/src/widgets/temp.go b/src/widgets/temp.go index 2185a0f7..ab1ac5ae 100644 --- a/src/widgets/temp.go +++ b/src/widgets/temp.go @@ -13,14 +13,15 @@ import ( type Temp struct { *ui.Block - interval time.Duration - Data map[string]int - Threshold int - TempLow ui.Color - TempHigh ui.Color + interval time.Duration + Data map[string]int + Threshold int + TempLow ui.Color + TempHigh ui.Color + Fahrenheit bool } -func NewTemp() *Temp { +func NewTemp(fahrenheit bool) *Temp { self := &Temp{ Block: ui.NewBlock(), interval: time.Second * 5, @@ -29,6 +30,11 @@ func NewTemp() *Temp { } self.Label = "Temperatures" + if fahrenheit { + self.Fahrenheit = true + self.Threshold = int(self.Threshold*9/5 + 32) + } + self.update() go func() { @@ -63,7 +69,11 @@ func (self *Temp) Buffer() *ui.Buffer { s := ui.MaxString(key, (self.X - 4)) buf.SetString(1, y+1, s, self.Fg, self.Bg) - buf.SetString(self.X-2, y+1, fmt.Sprintf("%2dC", self.Data[key]), fg, self.Bg) + if self.Fahrenheit { + buf.SetString(self.X-3, y+1, fmt.Sprintf("%3dF", self.Data[key]), fg, self.Bg) + } else { + buf.SetString(self.X-3, y+1, fmt.Sprintf("%3dC", self.Data[key]), fg, self.Bg) + } } return buf diff --git a/src/widgets/temp_darwin.go b/src/widgets/temp_darwin.go index c5f246c6..f4a7d09f 100644 --- a/src/widgets/temp_darwin.go +++ b/src/widgets/temp_darwin.go @@ -53,7 +53,11 @@ func (self *Temp) update() { sensors, _ := SensorsTemperatures() for _, sensor := range sensors { if sensor.Temperature != 0 { - self.Data[sensor.SensorKey] = int(sensor.Temperature) + if self.Fahrenheit { + self.Data[sensor.SensorKey] = int(sensor.Temperature*9/5 + 32) + } else { + self.Data[sensor.SensorKey] = int(sensor.Temperature) + } } } } diff --git a/src/widgets/temp_linux.go b/src/widgets/temp_linux.go index 781288ea..38e3cce9 100644 --- a/src/widgets/temp_linux.go +++ b/src/widgets/temp_linux.go @@ -13,7 +13,11 @@ func (self *Temp) update() { if strings.Contains(sensor.SensorKey, "input") && sensor.Temperature != 0 { // removes '_input' from the end of the sensor name label := sensor.SensorKey[:strings.Index(sensor.SensorKey, "_input")] - self.Data[label] = int(sensor.Temperature) + if self.Fahrenheit { + self.Data[label] = int(sensor.Temperature*9/5 + 32) + } else { + self.Data[label] = int(sensor.Temperature) + } } } } diff --git a/src/widgets/temp_windows.go b/src/widgets/temp_windows.go index e6dbb46a..0d3f6c31 100644 --- a/src/widgets/temp_windows.go +++ b/src/widgets/temp_windows.go @@ -8,7 +8,11 @@ func (self *Temp) update() { sensors, _ := psHost.SensorsTemperatures() for _, sensor := range sensors { if sensor.Temperature != 0 { - self.Data[sensor.SensorKey] = int(sensor.Temperature) + if self.Fahrenheit { + self.Data[sensor.SensorKey] = int(sensor.Temperature*9/5 + 32) + } else { + self.Data[sensor.SensorKey] = int(sensor.Temperature) + } } } }