Skip to content
This repository has been archived by the owner on Aug 29, 2020. It is now read-only.

Commit

Permalink
Add --fahrenheit flag, fix CPU ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony Lambiris authored and cjbassi committed Dec 2, 2018
1 parent b98d308 commit f66833c
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 13 deletions.
5 changes: 4 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var (
averageLoad = false
percpuLoad = false
widgetCount = 6
fahrenheit = false

cpu *w.CPU
mem *w.Mem
Expand All @@ -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
Expand Down Expand Up @@ -80,6 +82,7 @@ Colorschemes:
} else {
interval = time.Second / time.Duration(rate)
}
fahrenheit, _ = args["--fahrenheit"].(bool)
}

func handleColorscheme(cs string) {
Expand Down Expand Up @@ -204,7 +207,7 @@ func initWidgets() {
wg.Done()
}()
go func() {
temp = w.NewTemp()
temp = w.NewTemp(fahrenheit)
wg.Done()
}()
}
Expand Down
4 changes: 2 additions & 2 deletions src/widgets/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
}
Expand Down Expand Up @@ -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])
}
Expand Down
24 changes: 17 additions & 7 deletions src/widgets/temp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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() {
Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/widgets/temp_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
}
6 changes: 5 additions & 1 deletion src/widgets/temp_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
}
6 changes: 5 additions & 1 deletion src/widgets/temp_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
}

0 comments on commit f66833c

Please sign in to comment.