Add --fahrenheit flag, fix CPU ordering

This commit is contained in:
Tony Lambiris 2018-11-13 12:29:09 -05:00 committed by Caleb Bassi
parent b98d308fab
commit f66833c2cc
6 changed files with 38 additions and 13 deletions

View File

@ -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()
}()
}

View File

@ -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])
}

View File

@ -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

View File

@ -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)
}
}
}
}

View File

@ -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)
}
}
}
}

View File

@ -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)
}
}
}
}