Skip to content

Commit

Permalink
Add warning and ok thresholds to memory
Browse files Browse the repository at this point in the history
Signed-off-by: AKP <tom@tdpain.net>
  • Loading branch information
codemicro committed Mar 5, 2022
1 parent c1ba84f commit 313701f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cmd/bar/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func run() error {
providers.NewBattery("BAT0", 30, 15),
providers.NewDisk("/", 30, 10),
providers.NewCPU(20, 50),
providers.NewMemory(),
providers.NewMemory(7, 5),
providers.NewPulseaudioVolume(),
providers.NewDateTime(),
}
Expand Down
17 changes: 12 additions & 5 deletions internal/providers/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ import (
)

type Memory struct {
OkThreshold float32
OkThreshold float32
WarningThreshold float32
}

func NewMemory() i3bar.BlockGenerator {
return new(Memory)
func NewMemory(okThreshold, warningThreshold float32) i3bar.BlockGenerator {
return &Memory{
OkThreshold: okThreshold,
WarningThreshold: warningThreshold,
}
}

var (
Expand Down Expand Up @@ -60,6 +64,7 @@ func (g *Memory) Block(colors *i3bar.ColorSet) (*i3bar.Block, error) {
if err != nil {
return nil, err
}
avail := total - used

// TODO: Make the readout change between KB/MB/GB

Expand All @@ -69,9 +74,11 @@ func (g *Memory) Block(colors *i3bar.ColorSet) (*i3bar.Block, error) {
ShortText: fmt.Sprintf("M: %.1fGB", used),
}

if total - used < g.OkThreshold && g.OkThreshold != 0 {
if avail < g.WarningThreshold && g.WarningThreshold != 0 {
block.TextColor = colors.Bad
} else if avail < g.OkThreshold && g.OkThreshold != 0 {
block.TextColor = colors.Warning
}

return block, nil
}
}

0 comments on commit 313701f

Please sign in to comment.