38 lines
911 B
Go
38 lines
911 B
Go
|
/*
|
||
|
Copyright © 2023 Brian Buller <brian@bullercodeworks.com>
|
||
|
|
||
|
*/
|
||
|
package cmd
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"time"
|
||
|
|
||
|
"github.com/spf13/cobra"
|
||
|
"github.com/spf13/viper"
|
||
|
)
|
||
|
|
||
|
// i3Cmd represents the i3 command
|
||
|
var i3Cmd = &cobra.Command{
|
||
|
Use: "i3",
|
||
|
Short: "Print state to stdout in i3 bar format",
|
||
|
Run: func(cmd *cobra.Command, args []string) {
|
||
|
lastBreak := viper.GetTime("lastbreak")
|
||
|
pomo := viper.GetDuration("pomodoro")
|
||
|
warnPct := viper.GetFloat64("warnpct") //0.75
|
||
|
warn := pomo * time.Duration(warnPct)
|
||
|
elapsed := time.Since(lastBreak)
|
||
|
if elapsed > pomo {
|
||
|
fmt.Print("{\"icon\":\"tomato\",\"state\":\"Critical\", \"text\": \"BREAK!\"}")
|
||
|
} else if elapsed > warn {
|
||
|
fmt.Printf("{\"icon\":\"tomato\",\"state\":\"Warning\", \"text\": \"%s\"}", elapsed)
|
||
|
} else {
|
||
|
fmt.Printf("{\"icon\":\"tomato\",\"state\":\"Good\", \"text\": \"%s\"}", elapsed)
|
||
|
}
|
||
|
},
|
||
|
}
|
||
|
|
||
|
func init() {
|
||
|
rootCmd.AddCommand(i3Cmd)
|
||
|
}
|