3 Commits
v1 ... main

Author SHA1 Message Date
1ef19ca9c7 Make 'Break' more annoying 2023-11-28 08:13:06 -06:00
004ca7ab5b v1.1 2023-04-03 10:37:40 -05:00
4f8927d0d3 Click _after_ break 2023-03-31 12:56:12 -05:00
8 changed files with 73 additions and 31 deletions

View File

@@ -14,5 +14,8 @@ LDFLAGS=-ldflags "-w -s -X cmd.Version=${VERSION} -X cmd.Build=${BUILD}"
breaktime: breaktime:
go build ${LDFLAGS} -o build/${BINARY} go build ${LDFLAGS} -o build/${BINARY}
install:
mv build/${BINARY} ${GOPATH}/bin
clean: clean:
rm build/* rm build/*

View File

@@ -16,12 +16,9 @@ var breakCmd = &cobra.Command{
Use: "break", Use: "break",
Short: "Start a break", Short: "Start a break",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
length := viper.GetDuration("breaklength") viper.Set("lastbreak", time.Now())
viper.Set("lastbreak", time.Now().Add(length))
viper.WriteConfig() viper.WriteConfig()
}, },
} }
func init() { func init() { rootCmd.AddCommand(breakCmd) }
rootCmd.AddCommand(breakCmd)
}

View File

@@ -23,9 +23,7 @@ var configCmd = &cobra.Command{
RunE: opConfig, RunE: opConfig,
} }
func init() { func init() { rootCmd.AddCommand(configCmd) }
rootCmd.AddCommand(configCmd)
}
func opConfig(cmd *cobra.Command, args []string) error { func opConfig(cmd *cobra.Command, args []string) error {
updConfig := make(map[string]string) updConfig := make(map[string]string)

View File

@@ -1,6 +1,5 @@
/* /*
Copyright © 2023 Brian Buller <brian@bullercodeworks.com> Copyright © 2023 Brian Buller <brian@bullercodeworks.com>
*/ */
package cmd package cmd
@@ -17,23 +16,38 @@ var i3Cmd = &cobra.Command{
Use: "i3", Use: "i3",
Short: "Print state to stdout in i3 bar format", Short: "Print state to stdout in i3 bar format",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
if len(args) == 1 && args[0] == "click" { if len(args) == 1 {
if viper.GetBool("active") { switch args[0] {
breakCmd.Run(cmd, []string{}) case "toggle":
} else { toggleCmd.Run(cmd, []string{"-s"})
startCmd.Run(cmd, []string{}) 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
} }
return
} }
if viper.GetBool("active") { if viper.GetBool("active") {
lastBreak := viper.GetTime("lastbreak") lastBreak := viper.GetTime("lastbreak")
pomo := viper.GetDuration("pomodoro") pomo := viper.GetDuration("pomodoro")
warnPct := viper.GetFloat64("warnpct") //0.75 warnPct := viper.GetFloat64("warnpct") //0.75
warn := float64(pomo.Seconds() * warnPct) warn := int(pomo.Seconds() * warnPct)
elapsed := time.Since(lastBreak).Seconds() elapsed := int(time.Since(lastBreak).Seconds())
rem := time.Until(lastBreak.Add(pomo)).Round(time.Duration(time.Second)) rem := time.Until(lastBreak.Add(pomo)).Round(time.Duration(time.Second))
if elapsed > pomo.Seconds() { if elapsed > int(pomo.Seconds()) {
fmt.Print("{\"icon\":\"time\",\"state\":\"Critical\", \"text\": \"BREAK!\"}") state := "Critical"
if elapsed%2 == 1 {
state = "Warning"
}
fmt.Printf("{\"icon\":\"time\",\"state\":\"%s\", \"text\": \"BREAK!\"}", state)
} else if elapsed > warn { } else if elapsed > warn {
fmt.Printf("{\"icon\":\"time\",\"state\":\"Warning\", \"text\": \"%s\"}", rem) fmt.Printf("{\"icon\":\"time\",\"state\":\"Warning\", \"text\": \"%s\"}", rem)
} else { } else {

View File

@@ -43,8 +43,6 @@ func init() {
cobra.OnInitialize(initConfig) cobra.OnInitialize(initConfig)
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.breaktime.yaml)") rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.breaktime.yaml)")
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
} }
// initConfig reads in config file and ENV variables if set. // initConfig reads in config file and ENV variables if set.
@@ -104,6 +102,13 @@ func initConfig() {
} }
} }
func runRootCmd(cmd *cobra.Command, args []string) error { func runRootCmd(cmd *cobra.Command, args []string) error { return nil }
return nil
func hasArg(arg string, args []string) bool {
for i := range args {
if args[i] == arg {
return true
}
}
return false
} }

View File

@@ -18,10 +18,10 @@ var startCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
viper.Set("active", true) viper.Set("active", true)
viper.WriteConfig() viper.WriteConfig()
fmt.Println("Timer Started.") if !hasArg("-s", args) {
fmt.Println("Timer Started.")
}
}, },
} }
func init() { func init() { rootCmd.AddCommand(startCmd) }
rootCmd.AddCommand(startCmd)
}

View File

@@ -18,10 +18,10 @@ var stopCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
viper.Set("active", false) viper.Set("active", false)
viper.WriteConfig() viper.WriteConfig()
fmt.Println("Timer Stopped.") if !hasArg("-s", args) {
fmt.Println("Timer Stopped.")
}
}, },
} }
func init() { func init() { rootCmd.AddCommand(stopCmd) }
rootCmd.AddCommand(stopCmd)
}

25
cmd/toggle.go Normal file
View File

@@ -0,0 +1,25 @@
/*
Copyright © 2023 Brian Buller <brian@bullercodeworks.com>
*/
package cmd
import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
// toggleCmd represents the toggle command
var toggleCmd = &cobra.Command{
Use: "toggle",
Short: "Toggle timer off/on",
Run: func(cmd *cobra.Command, args []string) {
if viper.GetBool("active") {
stopCmd.Run(cmd, args)
} else {
startCmd.Run(cmd, args)
}
},
}
func init() { rootCmd.AddCommand(toggleCmd) }