diff options
| -rw-r--r-- | modules/home-manager/personal/gui/x/i3/bar/i3status.go | 67 |
1 files changed, 22 insertions, 45 deletions
diff --git a/modules/home-manager/personal/gui/x/i3/bar/i3status.go b/modules/home-manager/personal/gui/x/i3/bar/i3status.go index c26ae78..4e1b0f5 100644 --- a/modules/home-manager/personal/gui/x/i3/bar/i3status.go +++ b/modules/home-manager/personal/gui/x/i3/bar/i3status.go @@ -10,6 +10,7 @@ import ( "barista.run" "barista.run/bar" + "barista.run/base/click" "barista.run/colors" "barista.run/group" "barista.run/modules/battery" @@ -37,61 +38,37 @@ func main() { mdi.Load() // repo path will be inserted at build time // Display status of several services - updateSuccessIcon := pango.Icon("mdi-reload") - updatingIcon := pango.Icon("mdi-update") - updateFailIcon := pango.Icon("mdi-reload-alert") - garbageFullIcon := pango.Icon("mdi-delete") - garbageEmptyingIcon := pango.Icon("mdi-delete-restore") - garbageEmptyIcon := pango.Icon("mdi-delete-outline") - barista.Add(group.Simple(systemd.Service("nixos-upgrade").Output(func(i systemd.ServiceInfo) bar.Output { - state := i.UnitInfo.State - var colorScheme string - var output *pango.Node - switch { - case state == systemd.StateInactive: - colorScheme = "good" - output = updateSuccessIcon - case state == systemd.StateActivating: - colorScheme = "degraded" - output = updatingIcon - default: - colorScheme = "bad" - output = updateFailIcon - } - return outputs.Pango(output).Color(colors.Scheme(colorScheme)) - }), - systemd.Service("nix-gc").Output(func(i systemd.ServiceInfo) bar.Output { + outputServiceStatus := func(goodState systemd.State, degradedState systemd.State, goodIcon *pango.Node, degradedIcon *pango.Node, badIcon *pango.Node) func(systemd.ServiceInfo) bar.Output { + return func(i systemd.ServiceInfo) bar.Output { state := i.UnitInfo.State var colorScheme string var output *pango.Node switch { - case state == systemd.StateInactive: + case state == goodState: colorScheme = "good" - output = garbageEmptyIcon - case state == systemd.StateActivating: + output = goodIcon + case state == degradedState: colorScheme = "degraded" - output = garbageEmptyingIcon + output = degradedIcon default: colorScheme = "bad" - output = garbageFullIcon + output = badIcon } - return outputs.Pango(output).Color(colors.Scheme(colorScheme)) - }))) - emacsIcon := pango.Icon("mdi-alpha-e-circle") - barista.Add(systemd.UserService("emacs").Output(func(i systemd.ServiceInfo) bar.Output { - state := i.UnitInfo.State - var colorScheme string - switch { - case state == systemd.StateActive: - colorScheme = "good" - case state == systemd.StateActivating: - colorScheme = "degraded" - default: - colorScheme = "bad" + return outputs.Pango(output).Color(colors.Scheme(colorScheme)).OnClick(click.Right(func() { + i.Restart() + })) } - return outputs.Pango(emacsIcon).Color(colors.Scheme(colorScheme)) - })) - + } + updateSuccessIcon := pango.Icon("mdi-reload") + updatingIcon := pango.Icon("mdi-update") + updateFailIcon := pango.Icon("mdi-reload-alert") + garbageFullIcon := pango.Icon("mdi-delete") + garbageEmptyingIcon := pango.Icon("mdi-delete-restore") + garbageEmptyIcon := pango.Icon("mdi-delete-outline") + barista.Add(group.Simple(systemd.Service("nixos-upgrade").Output(outputServiceStatus(systemd.StateInactive, systemd.StateActivating, updateSuccessIcon, updatingIcon, updateFailIcon)), + systemd.Service("nix-gc").Output(outputServiceStatus(systemd.StateInactive, systemd.StateActivating, garbageEmptyIcon, garbageEmptyingIcon, garbageFullIcon)))) + emacsIcon := pango.Icon("mdi-alpha-e-circle") + barista.Add(systemd.UserService("emacs").Output(outputServiceStatus(systemd.StateActive, systemd.StateActivating, emacsIcon, emacsIcon, emacsIcon))) // Display space left on / storageIcon := pango.Icon("mdi-database") |
