65 lines
1.6 KiB
Go
65 lines
1.6 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 {
|
|
switch args[0] {
|
|
case "toggle":
|
|
toggleCmd.Run(cmd, []string{"-s"})
|
|
case "click":
|
|
if viper.GetBool("active") {
|
|
breakCmd.Run(cmd, []string{"-s"})
|
|
} else {
|
|
startCmd.Run(cmd, []string{"-s"})
|
|
}
|
|
case "status":
|
|
if viper.GetBool("active") {
|
|
fmt.Print("{\"text\":\"\uf04c\",\"state\":\"Good\"}")
|
|
} else {
|
|
fmt.Print("{\"text\":\"\uf04b\"}")
|
|
}
|
|
return
|
|
}
|
|
}
|
|
if viper.GetBool("active") {
|
|
lastBreak := viper.GetTime("lastbreak")
|
|
pomo := viper.GetDuration("pomodoro")
|
|
warnPct := viper.GetFloat64("warnpct") //0.75
|
|
warn := int(pomo.Seconds() * warnPct)
|
|
elapsed := int(time.Since(lastBreak).Seconds())
|
|
rem := time.Until(lastBreak.Add(pomo)).Round(time.Duration(time.Second))
|
|
if elapsed > int(pomo.Seconds()) {
|
|
state := "Critical"
|
|
if elapsed%2 == 1 {
|
|
state = "Warning"
|
|
}
|
|
fmt.Printf("{\"icon\":\"time\",\"state\":\"%s\", \"text\": \"BREAK!\"}", state)
|
|
} 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)
|
|
}
|