diff --git a/helpers.go b/helpers.go index bf697b9..571628c 100644 --- a/helpers.go +++ b/helpers.go @@ -9,6 +9,41 @@ import ( timertxt "github.com/br0xen/go-timertxt" ) +// TimerToString takes a TimeEntry and gives a nicely formatted string +func TimerToString(t *timertxt.Timer) string { + var ret string + var end string + if t.StartsToday() { + ret = t.StartDate.Format("15:04 - ") + end = "**:**" + } else { + ret = t.StartDate.Format("2006/01/02 15:04:05 - ") + end = "**:**:**" + } + if !t.FinishDate.IsZero() { + if t.EndsToday() { + end = t.FinishDate.Format("15:04") + } else { + end = t.FinishDate.Format("2006/01/02 15:04:05") + } + } + ret += end + if len(t.Contexts) > 0 { + ret += " " + fmt.Sprint(t.Contexts) + } + if len(t.Projects) > 0 { + ret += " " + fmt.Sprint(t.Projects) + } + if len(t.AdditionalTags) > 0 { + ret += " [ " + for k, v := range t.AdditionalTags { + ret += k + ":" + v + " " + } + ret += "]" + } + return ret +} + func GetRoundToDuration() time.Duration { var dur time.Duration var err error @@ -42,6 +77,15 @@ func getProjectsFromSlice(args []string) ([]string, []string) { }) } +// getAdditionalTagsFromSlice pulls all '*:*' (tags) out of the +// string slice and returns those projects and the remaining +// strings from the slice +func getAdditionalTagsFromSlice(args []string) ([]string, []string) { + return splitSlice(args, func(v string) bool { + return strings.Contains(v, ":") + }) +} + func splitSlice(args []string, predicate func(string) bool) ([]string, []string) { var rem1, rem2 []string for _, v := range args { diff --git a/timer_ops.go b/timer_ops.go index 1131e32..3bbf869 100644 --- a/timer_ops.go +++ b/timer_ops.go @@ -137,28 +137,34 @@ func (a *AppState) opListTimers(args []string) int { } func (a *AppState) opStartTimer(args []string) int { - var contexts, projects []string + var contexts, projects, strTags []string t := timertxt.NewTimer() - contexts, args = getContextsFromSlice(args) - projects, args = getProjectsFromSlice(args) if len(args) > 0 { if start, err := parseFuzzyTime(args[0]); err == nil { t.StartDate = start args = args[1:] } } + contexts, args = getContextsFromSlice(args) + projects, args = getProjectsFromSlice(args) + strTags, args = getAdditionalTagsFromSlice(args) for _, v := range contexts { t.Contexts = append(t.Contexts, strings.TrimPrefix(v, "@")) } for _, v := range projects { t.Projects = append(t.Projects, strings.TrimPrefix(v, "+")) } + for _, v := range strTags { + tgPts := strings.Split(v, ":") + t.AdditionalTags[tgPts[0]] = tgPts[1] + } a.TimerList.AddTimer(t) if err := a.WriteList(); err != nil { fmt.Println(err.Error()) return 1 } + fmt.Println("Started: ", TimerToString(t)) return 0 } diff --git a/ui_loop.go b/ui_loop.go index 8cd7ce7..1c2a106 100644 --- a/ui_loop.go +++ b/ui_loop.go @@ -24,6 +24,7 @@ func uiLoop() int { app.layoutAndDrawScreen(displayScreen) eventChan := make(chan termbox.Event) go readUserInput(eventChan) + go checkForUpdate(eventChan) for { event := <-eventChan if event.Type == termbox.EventKey {