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/platform"
|
|
|
|
"github.com/jandedobbeleer/oh-my-posh/src/properties"
|
2021-11-13 14:46:06 -08:00
|
|
|
)
|
|
|
|
|
2022-01-26 05:10:18 -08:00
|
|
|
type SystemInfo struct {
|
2022-01-26 04:53:35 -08:00
|
|
|
props properties.Properties
|
2022-11-09 11:27:54 -08:00
|
|
|
env platform.Environment
|
2022-01-26 04:53:35 -08:00
|
|
|
|
2021-11-13 14:46:06 -08:00
|
|
|
Precision int
|
2023-02-19 07:24:52 -08:00
|
|
|
|
|
|
|
platform.SystemInfo
|
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 {
|
2021-11-13 14:46:06 -08:00
|
|
|
if s.PhysicalPercentUsed == 0 && s.SwapPercentUsed == 0 {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2022-11-09 11:27:54 -08:00
|
|
|
func (s *SystemInfo) Init(props properties.Properties, env platform.Environment) {
|
2021-11-13 14:46:06 -08:00
|
|
|
s.props = props
|
|
|
|
s.env = env
|
2022-01-26 04:09:21 -08:00
|
|
|
s.Precision = s.props.GetInt(Precision, 2)
|
2023-02-19 07:24:52 -08:00
|
|
|
sysInfo, err := env.SystemInfo()
|
|
|
|
if err != nil {
|
|
|
|
return
|
2022-02-06 04:52:10 -08:00
|
|
|
}
|
2023-02-19 07:24:52 -08:00
|
|
|
s.SystemInfo = *sysInfo
|
2021-11-13 14:46:06 -08:00
|
|
|
}
|