Commit ea94d45
Changed files (3)
cmd/get/get_system_info.go
@@ -36,8 +36,9 @@ type SystemInfo struct {
DiskTotal uint64
// battery
- BatteryCurrent float64
- BatteryFull float64
+ BatteryCurrent float64
+ BatteryFull float64
+ BatteryDesignCapacity float64
}
func convertKBtoGB(v uint64) float64 {
@@ -101,24 +102,27 @@ func getSystemInfo() SystemInfo {
var batteryCurrent float64
var batteryFull float64
+ var batteryDesignCapacity float64
if len(batteries) > 0 {
batteryCurrent = batteries[0].Current
batteryFull = batteries[0].Full
+ batteryDesignCapacity = batteries[0].Design
}
// return
return SystemInfo{
- Username: username.Username,
- Hostname: hostStat.Hostname,
- Platform: fmt.Sprintf("%s %s", hostStat.Platform, hostStat.PlatformVersion),
- CPUModelName: cpuStat[0].ModelName,
- CPUThreads: cpuThreads,
- MemoryUsed: memoryUsed,
- MemoryTotal: memoryTotal,
- DiskUsed: diskUsed,
- DiskTotal: diskTotal,
- BatteryCurrent: batteryCurrent,
- BatteryFull: batteryFull,
+ Username: username.Username,
+ Hostname: hostStat.Hostname,
+ Platform: fmt.Sprintf("%s %s", hostStat.Platform, hostStat.PlatformVersion),
+ CPUModelName: cpuStat[0].ModelName,
+ CPUThreads: cpuThreads,
+ MemoryUsed: memoryUsed,
+ MemoryTotal: memoryTotal,
+ DiskUsed: diskUsed,
+ DiskTotal: diskTotal,
+ BatteryCurrent: batteryCurrent,
+ BatteryFull: batteryFull,
+ BatteryDesignCapacity: batteryDesignCapacity,
}
}
@@ -150,6 +154,7 @@ var getSystemInfoCmd = &cobra.Command{
// only print battery info if is a laptop
if systemInfo.BatteryFull > 0 {
batteryPercent := convertToPercent(systemInfo.BatteryCurrent / systemInfo.BatteryFull)
+ batteryHealth := convertToPercent(systemInfo.BatteryFull / systemInfo.BatteryDesignCapacity)
batteryFormat := fmt.Sprintf("%v%%", batteryPercent)
var batteryPercentStr string
if batteryPercent > 80 {
@@ -160,7 +165,7 @@ var getSystemInfoCmd = &cobra.Command{
batteryPercentStr = color.Red(batteryFormat)
}
- batteryStdout := fmt.Sprintf("%s: %s", color.Green("Battery"), batteryPercentStr)
+ batteryStdout := fmt.Sprintf("%s: %s (Health: %s)", color.Green("Battery"), batteryPercentStr, color.Blue(strconv.Itoa(batteryHealth)+"%"))
fmt.Println(batteryStdout)
}
},
go.mod
@@ -19,7 +19,6 @@ require (
github.com/shirou/gopsutil/v4 v4.25.3
github.com/showwin/speedtest-go v1.7.10
github.com/skanehira/clipboard-image v1.0.0
- github.com/skanehira/clipboard-image/v2 v2.0.0
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
github.com/spf13/cobra v1.9.1
golang.org/x/crypto v0.36.0
go.sum
@@ -91,7 +91,6 @@ github.com/showwin/speedtest-go v1.7.10 h1:9o5zb7KsuzZKn+IE2//z5btLKJ870JwO6ETay
github.com/showwin/speedtest-go v1.7.10/go.mod h1:Ei7OCTmNPdWofMadzcfgq1rUO7mvJy9Jycj//G7vyfA=
github.com/skanehira/clipboard-image v1.0.0 h1:MJ5PeXxDMteS0HCsjvuoMscBi+AtoqCiPX7bZ2OAxDE=
github.com/skanehira/clipboard-image v1.0.0/go.mod h1:WAxMgBkENpa206RHfrqV/5y8Kq7CitAozlvVxQxa9gs=
-github.com/skanehira/clipboard-image/v2 v2.0.0/go.mod h1:NXSYl4FJinIUFKJfeP1lGz8DIEUYjnEqwdMZ777S1E0=
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0=
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M=
github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=