51 lines
1.3 KiB
Go
51 lines
1.3 KiB
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) {
|
|
if len(args) == 1 && args[0] == "click" {
|
|
if viper.GetBool("active") {
|
|
breakCmd.Run(cmd, []string{})
|
|
} else {
|
|
startCmd.Run(cmd, []string{})
|
|
}
|
|
return
|
|
}
|
|
if viper.GetBool("active") {
|
|
lastBreak := viper.GetTime("lastbreak")
|
|
pomo := viper.GetDuration("pomodoro")
|
|
warnPct := viper.GetFloat64("warnpct") //0.75
|
|
warn := float64(pomo.Seconds() * warnPct)
|
|
elapsed := time.Since(lastBreak).Seconds()
|
|
rem := time.Until(lastBreak.Add(pomo)).Round(time.Duration(time.Second))
|
|
if elapsed > pomo.Seconds() {
|
|
fmt.Print("{\"icon\":\"time\",\"state\":\"Critical\", \"text\": \"BREAK!\"}")
|
|
} else if elapsed > warn {
|
|
fmt.Printf("{\"icon\":\"time\",\"state\":\"Warning\", \"text\": \"%s\"}", rem)
|
|
} else {
|
|
fmt.Printf("{\"icon\":\"time\",\"state\":\"Good\", \"text\": \"%s\"}", rem)
|
|
}
|
|
} else {
|
|
fmt.Print("{\"icon\":\"time\", \"text\": \"Stopped\"}")
|
|
}
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
rootCmd.AddCommand(i3Cmd)
|
|
}
|