2022-01-26 06:54:36 -08:00
|
|
|
package segments
|
2021-11-13 14:46:06 -08:00
|
|
|
|
|
|
|
import (
|
2023-01-05 12:57:38 -08:00
|
|
|
"github.com/jandedobbeleer/oh-my-posh/src/properties"
|
2024-07-02 03:02:57 -07:00
|
|
|
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
|
2021-11-13 14:46:06 -08:00
|
|
|
)
|
|
|
|
|
2022-01-26 05:10:18 -08:00
|
|
|
type SystemInfo struct {
|
2024-10-22 03:22:40 -07:00
|
|
|
base
|
|
|
|
|
2024-07-02 03:02:57 -07:00
|
|
|
runtime.SystemInfo
|
2024-08-05 05:59:34 -07:00
|
|
|
Precision int
|
2021-11-13 14:46:06 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
|
|
|
// Precision number of decimal places to show
|
2022-01-26 04:53:35 -08:00
|
|
|
Precision properties.Property = "precision"
|
2021-11-13 14:46:06 -08:00
|
|
|
)
|
|
|
|
|
2022-01-26 05:26:56 -08:00
|
|
|
func (s *SystemInfo) Template() string {
|
2022-02-01 05:07:58 -08:00
|
|
|
return " {{ round .PhysicalPercentUsed .Precision }} "
|
2022-01-23 12:37:51 -08:00
|
|
|
}
|
|
|
|
|
2022-01-26 05:26:56 -08:00
|
|
|
func (s *SystemInfo) Enabled() bool {
|
2022-01-26 04:09:21 -08:00
|
|
|
s.Precision = s.props.GetInt(Precision, 2)
|
2024-10-22 03:22:40 -07:00
|
|
|
|
|
|
|
sysInfo, err := s.env.SystemInfo()
|
2023-02-19 07:24:52 -08:00
|
|
|
if err != nil {
|
2024-10-22 03:22:40 -07:00
|
|
|
return false
|
2022-02-06 04:52:10 -08:00
|
|
|
}
|
2024-10-22 03:22:40 -07:00
|
|
|
|
2023-02-19 07:24:52 -08:00
|
|
|
s.SystemInfo = *sysInfo
|
2024-10-22 03:22:40 -07:00
|
|
|
|
|
|
|
if s.PhysicalPercentUsed == 0 && s.SwapPercentUsed == 0 {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
2021-11-13 14:46:06 -08:00
|
|
|
}
|