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

40 lines
684 B
Go
Raw Normal View History

2022-01-26 06:54:36 -08:00
package segments
import (
"github.com/jandedobbeleer/oh-my-posh/src/properties"
2024-07-02 03:02:57 -07:00
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
)
2022-01-26 05:10:18 -08:00
type SystemInfo struct {
base
2024-07-02 03:02:57 -07:00
runtime.SystemInfo
2024-08-05 05:59:34 -07:00
Precision int
}
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 {
2022-01-26 04:09:21 -08:00
s.Precision = s.props.GetInt(Precision, 2)
sysInfo, err := s.env.SystemInfo()
if err != nil {
return false
}
s.SystemInfo = *sysInfo
if s.PhysicalPercentUsed == 0 && s.SwapPercentUsed == 0 {
return false
}
return true
}