Mostly functional

This commit is contained in:
Brian Buller 2019-03-01 08:35:52 -06:00
parent 655c4f199e
commit 6b1cc0866f
3 changed files with 54 additions and 3 deletions

View File

@ -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 {

View File

@ -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
}

View File

@ -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 {