oh-my-posh/src/segments/sysinfo.go

43 lines
842 B
Go
Raw Normal View History

2022-01-26 06:54:36 -08:00
package segments
import (
"github.com/jandedobbeleer/oh-my-posh/src/platform"
"github.com/jandedobbeleer/oh-my-posh/src/properties"
)
2022-01-26 05:10:18 -08:00
type SystemInfo struct {
props properties.Properties
2022-11-09 11:27:54 -08:00
env platform.Environment
Precision int
platform.SystemInfo
}
const (
// Precision number of decimal places to show
Precision properties.Property = "precision"
)
func (s *SystemInfo) Template() string {
2022-02-01 05:07:58 -08:00
return " {{ round .PhysicalPercentUsed .Precision }} "
}
func (s *SystemInfo) Enabled() bool {
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) {
s.props = props
s.env = env
2022-01-26 04:09:21 -08:00
s.Precision = s.props.GetInt(Precision, 2)
sysInfo, err := env.SystemInfo()
if err != nil {
return
}
s.SystemInfo = *sysInfo
}