diff options
| author | Stefan Majewsky <majewsky@gmx.net> | 2017-11-15 22:44:32 +0100 |
|---|---|---|
| committer | Stefan Majewsky <majewsky@gmx.net> | 2017-11-15 22:44:32 +0100 |
| commit | beb2b07ff1d682253932cb0bd5fcaaa8a5ad542f (patch) | |
| tree | 73f24f4e12e2c7445de7debe83eecbc27f38f741 /pkg/i3status/main.go | |
| parent | d47c8f45f11b283b5648eef5f15e15ff7ce27d4b (diff) | |
| download | gofu-beb2b07ff1d682253932cb0bd5fcaaa8a5ad542f.tar.gz | |
i3status: add battery block
Diffstat (limited to 'pkg/i3status/main.go')
| -rw-r--r-- | pkg/i3status/main.go | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/pkg/i3status/main.go b/pkg/i3status/main.go index 1b16f21..a0c4342 100644 --- a/pkg/i3status/main.go +++ b/pkg/i3status/main.go @@ -43,22 +43,26 @@ func Exec(args []string) int { //prepare clock (this is inline instead of split into a separate function //because the wallclock also drives the main loop's clock, see below) now := time.Now() - currentBlocks["clock"] = []Block{ - { - Name: "clock", - Instance: "date", - Position: PositionClock, - FullText: now.Format("2006-01-02"), - ShortText: " ", - Color: "#AAAAAA", + currentBlocks["clock"] = section( + Block{ + Name: "clock", + Instance: "date", + Position: PositionClock, + FullText: now.Format("2006-01-02"), + ShortText: " ", + Color: "#AAAAAA", + SeparatorBlockWidth: 6, }, - { + Block{ Name: "clock", Instance: "time", Position: PositionClock, FullText: now.Format("15:04:05"), }, - } + ) + + //prepare other blocks + currentBlocks["battery"] = getBatteryStatus() //put blocks in rendering order var allBlocks []Block @@ -133,5 +137,18 @@ type Position int //Acceptable values for Position, from left to right. const ( PositionNone Position = iota + PositionBattery PositionClock ) + +//Order the given blocks byPositionAndInstance, then add a separator to the last one. +func section(blocks ...Block) []Block { + if len(blocks) == 0 { + return nil + } + sort.Sort(byPositionAndInstance(blocks)) + last := len(blocks) - 1 + blocks[last].Separator = true + blocks[last].SeparatorBlockWidth = 15 + return blocks +} |
