diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/batteryModule.go | 29 | ||||
-rw-r--r-- | modules/dateModule.go | 17 | ||||
-rw-r--r-- | modules/module.go | 6 | ||||
-rw-r--r-- | modules/timeModule.go | 10 |
4 files changed, 62 insertions, 0 deletions
diff --git a/modules/batteryModule.go b/modules/batteryModule.go new file mode 100644 index 0000000..d4593ff --- /dev/null +++ b/modules/batteryModule.go @@ -0,0 +1,29 @@ +package modules + +import ( + "io/ioutil" +) + +// TODO: Move this to a central spot, like a config.h +const ( + batteryPath = "/sys/class/power_supply/BAT0/capacity" +) + +// 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/modules/dateModule.go b/modules/dateModule.go new file mode 100644 index 0000000..9dec1dd --- /dev/null +++ b/modules/dateModule.go @@ -0,0 +1,17 @@ +package modules + +import ( + "fmt" + "strconv" + "time" +) + +type DateModule struct { +} + +// getDate formats a string for the status bar +func (_ DateModule) GetInfo() (string, error) { + now := time.Now() + // return now.Weekday().String() + " " + now.Month().String()[0:3] + " " + now.Year(), nil + return fmt.Sprintf("%s %s %s %s", now.Weekday(), now.Month().String()[0:3], strconv.Itoa(now.Day()), strconv.Itoa(now.Year())), nil +} diff --git a/modules/module.go b/modules/module.go new file mode 100644 index 0000000..69e8337 --- /dev/null +++ b/modules/module.go @@ -0,0 +1,6 @@ +package modules + +// Module is the interface for you to extend what your bar does. +type Module interface { + GetInfo() (string, error) +} diff --git a/modules/timeModule.go b/modules/timeModule.go new file mode 100644 index 0000000..501b2fe --- /dev/null +++ b/modules/timeModule.go @@ -0,0 +1,10 @@ +package modules + +import "time" + +type TimeModule struct { +} + +func (_ TimeModule) GetInfo() (string, error) { + return time.Now().Format(time.Kitchen), nil +} |