Mostly functional
This commit is contained in:
parent
655c4f199e
commit
6b1cc0866f
44
helpers.go
44
helpers.go
@ -9,6 +9,41 @@ import (
|
|||||||
timertxt "github.com/br0xen/go-timertxt"
|
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 {
|
func GetRoundToDuration() time.Duration {
|
||||||
var dur time.Duration
|
var dur time.Duration
|
||||||
var err error
|
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) {
|
func splitSlice(args []string, predicate func(string) bool) ([]string, []string) {
|
||||||
var rem1, rem2 []string
|
var rem1, rem2 []string
|
||||||
for _, v := range args {
|
for _, v := range args {
|
||||||
|
12
timer_ops.go
12
timer_ops.go
@ -137,28 +137,34 @@ func (a *AppState) opListTimers(args []string) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *AppState) opStartTimer(args []string) int {
|
func (a *AppState) opStartTimer(args []string) int {
|
||||||
var contexts, projects []string
|
var contexts, projects, strTags []string
|
||||||
t := timertxt.NewTimer()
|
t := timertxt.NewTimer()
|
||||||
contexts, args = getContextsFromSlice(args)
|
|
||||||
projects, args = getProjectsFromSlice(args)
|
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
if start, err := parseFuzzyTime(args[0]); err == nil {
|
if start, err := parseFuzzyTime(args[0]); err == nil {
|
||||||
t.StartDate = start
|
t.StartDate = start
|
||||||
args = args[1:]
|
args = args[1:]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
contexts, args = getContextsFromSlice(args)
|
||||||
|
projects, args = getProjectsFromSlice(args)
|
||||||
|
strTags, args = getAdditionalTagsFromSlice(args)
|
||||||
for _, v := range contexts {
|
for _, v := range contexts {
|
||||||
t.Contexts = append(t.Contexts, strings.TrimPrefix(v, "@"))
|
t.Contexts = append(t.Contexts, strings.TrimPrefix(v, "@"))
|
||||||
}
|
}
|
||||||
for _, v := range projects {
|
for _, v := range projects {
|
||||||
t.Projects = append(t.Projects, strings.TrimPrefix(v, "+"))
|
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)
|
a.TimerList.AddTimer(t)
|
||||||
if err := a.WriteList(); err != nil {
|
if err := a.WriteList(); err != nil {
|
||||||
fmt.Println(err.Error())
|
fmt.Println(err.Error())
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
fmt.Println("Started: ", TimerToString(t))
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ func uiLoop() int {
|
|||||||
app.layoutAndDrawScreen(displayScreen)
|
app.layoutAndDrawScreen(displayScreen)
|
||||||
eventChan := make(chan termbox.Event)
|
eventChan := make(chan termbox.Event)
|
||||||
go readUserInput(eventChan)
|
go readUserInput(eventChan)
|
||||||
|
go checkForUpdate(eventChan)
|
||||||
for {
|
for {
|
||||||
event := <-eventChan
|
event := <-eventChan
|
||||||
if event.Type == termbox.EventKey {
|
if event.Type == termbox.EventKey {
|
||||||
|
Loading…
Reference in New Issue
Block a user