Skip to content

Commit

Permalink
add -ts flag #8
Browse files Browse the repository at this point in the history
  • Loading branch information
nwg-piotr committed Nov 4, 2024
1 parent 7389ad4 commit 2614c8c
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions gopsuinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,31 @@ func cpuAvSpeed(asIcon bool, delay *string) string {
func listSensors() {
temps, _ := host.SensorsTemperatures()
for _, temp := range temps {
fmt.Printf("%s %v\n", temp.SensorKey, temp.Temperature)
if strings.HasSuffix(temp.SensorKey, "_input") {
fmt.Printf("%s (%v°C)\n", temp.SensorKey, temp.Temperature)
}
}
os.Exit(0)
}

func temperatures(asIcon bool) string {
func temperatures(asIcon bool, tempSensor string) string {
output := ""
if !asIcon {
output += g.glyphTemp
}
vals := make(map[string]float64)

temps, _ := host.SensorsTemperatures()

if tempSensor != "" {
for _, temp := range temps {
if temp.SensorKey == tempSensor {
return fmt.Sprintf("%v℃", int(math.Round(temp.Temperature)))
}
}
return fmt.Sprintf("No such sensor as '%s', try the -ls flag", tempSensor)
}

for _, temp := range temps {
// Some machines may return multiple sensors of the same name. Let's accept the 1st non-zero temp value.
if vals["acpitz"] == 0 && temp.SensorKey == "acpitz_input" {
Expand Down Expand Up @@ -221,7 +233,8 @@ func main() {
setPtr := flag.Bool("dark", false, "use (dark) icon set")
textPtr := flag.Bool("t", false, "Just (t)ext, no glyphs")
displayVersion := flag.Bool("v", false, "display (v)ersion information")
listTempSensors := flag.Bool("s", false, "list temperature (s)ensors")
listTempSensors := flag.Bool("ls", false, "list temperature (s)ensors")
tempSensor := flag.String("ts", "", "show temperature for a certain Temperature Sensor (-ls to list available sensors)")

flag.Parse()

Expand Down Expand Up @@ -257,7 +270,7 @@ func main() {
output += cpuAvSpeed(true, cpuDelayPtr)
} else if *iconPtr == "t" {
output += path + "/temp.svg\n"
output += temperatures(true)
output += temperatures(true, *tempSensor)
} else if *iconPtr == "n" {
output += path + "/hdd.svg\n"
output += diskUsage(pathsPtr)
Expand All @@ -279,7 +292,7 @@ func main() {
output += cpuAvSpeed(false, cpuDelayPtr) + " "
}
if string(char) == "t" {
output += temperatures(false) + " "
output += temperatures(false, *tempSensor) + " "
}
if string(char) == "u" {
output += uptime(false) + " "
Expand Down

0 comments on commit 2614c8c

Please sign in to comment.