diff --git a/.gitignore b/.gitignore index c9a39d7aa324b454153515f7845685a0a38654b9..797456857f04bd20ab70400eb3d630342a27eafb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ .*.swp *~ - +/battery /bin diff --git a/bar/run.go b/bar/run.go index b970949ceb1f37f59ece133f1b05c4e68a205913..292cbbc7d9ca4b768e4b113b3e3a9133d18601f1 100644 --- a/bar/run.go +++ b/bar/run.go @@ -34,15 +34,15 @@ func Run(cmd *cobra.Command, args []string) { fmt.Printf(`{ "version": 1, "stop_signal": %d, "cont_signal": %d, "click_events": true }`+"\n", unix.SignalNum("SIGSTOP"), unix.SignalNum("SIGCONT")) - separator := "[" + fmt.Printf("[\n[{\"full_text\": \"Starting i3going-on...\"}]\n") + time.Sleep(2 * time.Second) for { - // Render the ststus line. + // Render the status line. line := make([]string, 0, 5) for _, module := range cfg.Modules { line = append(line, module.Render()) } - fmt.Printf("%s\n[%s]", separator, strings.Join(line, ",")) - separator = "," + fmt.Printf(",\n[%s]", strings.Join(line, ",")) // Wait for the refresh time, a click or a config file change. select { @@ -51,11 +51,11 @@ func Run(cmd *cobra.Command, args []string) { for _, module := range cfg.Modules { if click.Name == module.Name { found = true - fmt.Print(`,[{"full_text": "CLICK!"},{"name": "post", "full_text": "post", "color": "#11ff11"},{"name": "date", "full_text": "22-12-01 22:54"}]`) + fmt.Print(`,[{"full_text": "CLICK!"}]`) } } if !found { - fmt.Print(`,[{"full_text": "ERROR!"},{"name": "post", "full_text": "post", "color": "#11ff11"},{"name": "date", "full_text": "22-12-01 22:54"}]`) + fmt.Print(`,[{"full_text": "ERROR!"}]`) } time.Sleep(5 * time.Second) case configEvent := <-watcher.Events: diff --git a/doc/config.sample.yaml b/config/sample.yaml similarity index 100% rename from doc/config.sample.yaml rename to config/sample.yaml diff --git a/docs/protocol.md b/docs/protocol.md new file mode 100644 index 0000000000000000000000000000000000000000..2ef7d451fa43444eb7c0db88d693b40195f5e6ce --- /dev/null +++ b/docs/protocol.md @@ -0,0 +1,27 @@ +# JSON protocol for i3bar + +This program outputs a [json +protocol](https://i3wm.org/docs/i3bar-protocol.html) to describe what +goes in the bar. It receives input for the clicks on the bar. + +In both cases it's an infinite array. + +## Output protocol (bar status fields) + +The output protocol is an infinite array that starts with a header object +and then has an array of fields to display - emitted every few seconds. + +### Header + + * `version`: protocol version - currently `1`. + * `stop_signal`: i3bar will send this to stop the process. Set to + `SIGSTOP`. If it's a problem, set it to `0`. + * `cont_signal`: i3bar will send this to continue (unstop) the process. Set to + `SIGCONT`. + * `click_events`: Enables click events. Set to `true`. + +### Status element + +## Input protocol (clicks) + + diff --git a/go.mod b/go.mod index 0ace0ac577dbcb4c7650c5c54e65efec8715acd1..45c28deadb5acce234da0d355ff3d149c2e18224 100644 --- a/go.mod +++ b/go.mod @@ -4,10 +4,10 @@ go 1.19 require ( github.com/codegoalie/golibnotify v0.1.0 - github.com/distatus/battery v0.10.0 github.com/fsnotify/fsnotify v1.6.0 github.com/spf13/cobra v1.6.1 github.com/spf13/viper v1.14.0 + gitlab.com/lyda/battery v0.0.0-20230129170204-3ffa6d059f9b golang.org/x/sys v0.0.0-20220908164124-27713097b956 gopkg.in/yaml.v2 v2.4.0 gopkg.in/yaml.v3 v3.0.1 diff --git a/go.sum b/go.sum index 0a843e4e78bc3135b5647022c096d52bde42acd4..118f409d352854481af9f3dcb3574c45130564cd 100644 --- a/go.sum +++ b/go.sum @@ -52,8 +52,6 @@ github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/distatus/battery v0.10.0 h1:YbizvmV33mqqC1fPCAEaQGV3bBhfYOfM+2XmL+mvt5o= -github.com/distatus/battery v0.10.0/go.mod h1:STnSvFLX//eEpkaN7qWRxCWxrWOcssTDgnG4yqq9BRE= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= @@ -182,6 +180,8 @@ github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +gitlab.com/lyda/battery v0.0.0-20230129170204-3ffa6d059f9b h1:FfXFsSNxlmEKFce+bZhM+GVvZ4gl2EnAk7XZprdfyC8= +gitlab.com/lyda/battery v0.0.0-20230129170204-3ffa6d059f9b/go.mod h1:G8sRcYsOmeIwPo4CT/npwbxJ/XkPvkBT+DZJnBfDVco= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= @@ -287,7 +287,6 @@ golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190912141932-bc967efca4b8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/modules/battery.go b/modules/battery.go index ea760459871520bd3cbbd5571c4ba5741e602dc1..21ce8ac98a63ada64c55de43f13fae5124e4bef8 100644 --- a/modules/battery.go +++ b/modules/battery.go @@ -7,7 +7,7 @@ import ( "math" "time" - "github.com/distatus/battery" + "gitlab.com/lyda/battery" ) type battTS struct { diff --git a/util/battery/battery.go b/util/battery/battery.go new file mode 100644 index 0000000000000000000000000000000000000000..f9e613cc2774b10e2032122aa81c949ce9f95114 --- /dev/null +++ b/util/battery/battery.go @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + + "gitlab.com/lyda/battery" +) + +func main() { + batteries, err := battery.GetAll() + if err != nil { + fmt.Println("Could not get battery info!") + return + } + for i, battery := range batteries { + fmt.Printf("Bat%d: ", i) + fmt.Printf("state: %s, ", battery.State.String()) + fmt.Printf("current capacity: %f mWh, ", battery.Current) + fmt.Printf("last full capacity: %f mWh, ", battery.Full) + fmt.Printf("design capacity: %f mWh, ", battery.Design) + fmt.Printf("charge rate: %f mW, ", battery.ChargeRate) + fmt.Printf("voltage: %f V, ", battery.Voltage) + fmt.Printf("design voltage: %f V\n", battery.DesignVoltage) + } +}