diff options
author | Jackson Taylor <jtaylormuffins@gmail.com> | 2020-03-31 22:35:25 -0400 |
---|---|---|
committer | Jackson Taylor <jtaylormuffins@gmail.com> | 2020-03-31 22:35:25 -0400 |
commit | d70fe40f9de2a10ccd5892b7886a559b181748cc (patch) | |
tree | 7888b8c0275eb8e09b28b10059f169f652733e0b | |
parent | e7f0f1cb4d0f326327484cd10d3a36a5a31b161d (diff) |
Add initial files for status bar
Add main function loop
Add a battery module for laptops
Add a date module
-rw-r--r-- | batteryModule.go | 30 | ||||
-rw-r--r-- | dateModule.go | 16 | ||||
-rw-r--r-- | main.go | 61 |
3 files changed, 107 insertions, 0 deletions
diff --git a/batteryModule.go b/batteryModule.go new file mode 100644 index 0000000..81fdef0 --- /dev/null +++ b/batteryModule.go @@ -0,0 +1,30 @@ +package main + +import ( + "io/ioutil" +) + +// TODO: Move this to a central spot, like a config.h +const ( + batteryPath = "/sys/class/power_supply/BAT0/capacity" + identifier = "BAT" +) + +// BatteryModule is the module that controls finding out the battery +// percentage, mainly useful in laptops +type BatteryModule struct { +} + +func (_ BatteryModule) GetInfo() (string, error) { + return readBatteryLevel(batteryPath) +} + +func readBatteryLevel(path string) (string, error) { + dat, err := ioutil.ReadFile(path) + + if err != nil { + return "NULL", err + } + + return (string(dat[:len(dat)-1]) + "%"), nil +} diff --git a/dateModule.go b/dateModule.go new file mode 100644 index 0000000..baabe5a --- /dev/null +++ b/dateModule.go @@ -0,0 +1,16 @@ +package main + +import ( + "time" +) + +type DateModule struct { +} + +// getDate formats a string for the status bar +func (_ DateModule) GetInfo() (string, error) { + now := time.Now() + // return string([]rune(now.Weekday().String()[0:3])) + // return now.Format(time.Stamp) + return string([]rune(now.Month().String())) + " " + now.Format(time.Kitchen), nil +} @@ -0,0 +1,61 @@ +package main + +/* + Author: Jackson Taylor + Date: 3/28/2020 + Description: This is Jackson's Awesome Status Bar for suckless', very nice, dwm. +*/ + +import ( + "fmt" + // "os" + "os/exec" + // "time" +) + +// Bar is the struct that holds each of the modules and displays the data from them +type Bar struct { + Modules []Module +} + +type Module interface { + GetInfo() (string, error) +} + +var BarModules = []Module{ + DateModule{}, + BatteryModule{}, +} + +func main() { + + main := Bar{ + Modules: BarModules, + } + fmt.Println("Bar Started") + + var value string + + for { + value = "" + for _, b := range main.Modules { + p1, err := b.GetInfo() + if err != nil { + fmt.Println(err) + continue + } + value += "[" + p1 + "]" + } + + setBar(value) + } +} + +func getBattery() string { + return "100 %" +} + +func setBar(value string) (err error) { + err = exec.Command("xsetroot", "-name", value).Run() + return err +} |