Actually Support Tags

This commit is contained in:
Brian Buller 2022-01-19 07:45:29 -06:00
parent 901015f211
commit 2ee6aea0b3
4 changed files with 107 additions and 96 deletions

15
go.mod
View File

@ -1,12 +1,19 @@
module git.bullercodeworks.com/brian/gime module git.bullercodeworks.com/brian/gime
go 1.16 go 1.17
replace git.bullercodeworks.com/brian/go-timertxt => /home/brbuller/Development/go/src/git.bullercodeworks.com/brian/go-timertxt
require ( require (
git.bullercodeworks.com/brian/go-timertxt v0.0.0-20210302170637-d35b67037e23 git.bullercodeworks.com/brian/go-timertxt v0.0.0-20210302170637-d35b67037e23
github.com/BurntSushi/toml v0.3.1 // indirect
github.com/br0xen/termbox-util v0.0.0-20200220160819-dc6d6950ba00 github.com/br0xen/termbox-util v0.0.0-20200220160819-dc6d6950ba00
github.com/br0xen/user-config v0.0.0-20170914134719-16e743ec93a2 github.com/br0xen/user-config v0.0.0-20170914134719-16e743ec93a2
github.com/casimir/xdg-go v0.0.0-20160329195404-372ccc2180da // indirect github.com/nsf/termbox-go v1.1.1
github.com/nsf/termbox-go v1.1.0 )
require (
github.com/BurntSushi/toml v1.0.0 // indirect
github.com/casimir/xdg-go v0.0.0-20160329195404-372ccc2180da // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
) )

15
go.sum
View File

@ -1,14 +1,15 @@
git.bullercodeworks.com/brian/go-timertxt v0.0.0-20210302170637-d35b67037e23 h1:/Tug0iB9QbhMagmU484YmnBZ4GzyWpK2hpulB+wmW0A= github.com/BurntSushi/toml v1.0.0 h1:dtDWrepsVPfW9H/4y7dDgFc2MBUSeJhlaDtK13CxFlU=
git.bullercodeworks.com/brian/go-timertxt v0.0.0-20210302170637-d35b67037e23/go.mod h1:y+bBvu2tRRBd6DpbrB/SlCITD7flInD5CYVYnaEZl3g= github.com/BurntSushi/toml v1.0.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/br0xen/termbox-util v0.0.0-20200220160819-dc6d6950ba00 h1:9AXfX20nYtpadSCppvKkZfFgU/htFHVhYqYdPNa4bm4= github.com/br0xen/termbox-util v0.0.0-20200220160819-dc6d6950ba00 h1:9AXfX20nYtpadSCppvKkZfFgU/htFHVhYqYdPNa4bm4=
github.com/br0xen/termbox-util v0.0.0-20200220160819-dc6d6950ba00/go.mod h1:x9wJlgOj74OFTOBwXOuO8pBguW37EgYNx51Dbjkfzo4= github.com/br0xen/termbox-util v0.0.0-20200220160819-dc6d6950ba00/go.mod h1:x9wJlgOj74OFTOBwXOuO8pBguW37EgYNx51Dbjkfzo4=
github.com/br0xen/user-config v0.0.0-20170914134719-16e743ec93a2 h1:H/prDPxUZBsK4DQC7ScP3ftSijMtWyetb6ab69DSKrs= github.com/br0xen/user-config v0.0.0-20170914134719-16e743ec93a2 h1:H/prDPxUZBsK4DQC7ScP3ftSijMtWyetb6ab69DSKrs=
github.com/br0xen/user-config v0.0.0-20170914134719-16e743ec93a2/go.mod h1:lMy7txIyYXt+I/1JgTGBZTdyTNJyNVDCX4Z+lHzNcSM= github.com/br0xen/user-config v0.0.0-20170914134719-16e743ec93a2/go.mod h1:lMy7txIyYXt+I/1JgTGBZTdyTNJyNVDCX4Z+lHzNcSM=
github.com/casimir/xdg-go v0.0.0-20160329195404-372ccc2180da h1:hjpZV7G49m1bly++F+Gho1Sbf2+eBW/eTLJWuRkH9Uc= github.com/casimir/xdg-go v0.0.0-20160329195404-372ccc2180da h1:hjpZV7G49m1bly++F+Gho1Sbf2+eBW/eTLJWuRkH9Uc=
github.com/casimir/xdg-go v0.0.0-20160329195404-372ccc2180da/go.mod h1:dywSSi3sMtJn2IjiYfJciP9tjVVeIVRa7AE7N5WLUBo= github.com/casimir/xdg-go v0.0.0-20160329195404-372ccc2180da/go.mod h1:dywSSi3sMtJn2IjiYfJciP9tjVVeIVRa7AE7N5WLUBo=
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/nsf/termbox-go v1.1.0 h1:R+GIXVMaDxDQ2VHem5vO5h0mI8ZxLECTUNw1ZzXODzI= github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
github.com/nsf/termbox-go v1.1.0/go.mod h1:T0cTdVuOwf7pHQNtfhnEbzHbcNyCEcVU4YPpouCbVxo= github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/nsf/termbox-go v1.1.1 h1:nksUPLCb73Q++DwbYUBEglYBRPZyoXJdrj5L+TkjyZY=
github.com/nsf/termbox-go v1.1.1/go.mod h1:T0cTdVuOwf7pHQNtfhnEbzHbcNyCEcVU4YPpouCbVxo=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=

View File

@ -149,7 +149,7 @@ var fuzzyFormats = []string{
} }
func timerToFriendlyString(t *timertxt.Timer) string { func timerToFriendlyString(t *timertxt.Timer) string {
var start, end, contexts, projects string var start, end, contexts, projects, tags string
start = t.StartDate.Format(friendlyFormatForTime(t.StartDate)) start = t.StartDate.Format(friendlyFormatForTime(t.StartDate))
if t.FinishDate.IsZero() { if t.FinishDate.IsZero() {
end = "**:**" end = "**:**"
@ -162,6 +162,9 @@ func timerToFriendlyString(t *timertxt.Timer) string {
for _, v := range t.Projects { for _, v := range t.Projects {
projects += "+" + v + " " projects += "+" + v + " "
} }
for k, v := range t.AdditionalTags {
tags = fmt.Sprintf("%s%s:%s ", tags, k, v)
}
var dur time.Duration var dur time.Duration
if t.FinishDate.IsZero() { if t.FinishDate.IsZero() {
dur = time.Now().Sub(t.StartDate) dur = time.Now().Sub(t.StartDate)
@ -169,7 +172,7 @@ func timerToFriendlyString(t *timertxt.Timer) string {
dur = t.FinishDate.Sub(t.StartDate) dur = t.FinishDate.Sub(t.StartDate)
} }
dur = dur.Round(GetRoundToDuration()) dur = dur.Round(GetRoundToDuration())
return fmt.Sprintf("% 2d. %s - %s [ %s] [ %s] %s ( %.2f )", t.Id, start, end, contexts, projects, t.Notes, DurationToDecimal(dur)) return fmt.Sprintf("% 2d. %s - %s [ %s] [ %s] [ %s] %s ( %.2f )", t.Id, start, end, contexts, projects, tags, t.Notes, DurationToDecimal(dur))
} }
func friendlyFormatForTime(t time.Time) string { func friendlyFormatForTime(t time.Time) string {

View File

@ -10,89 +10,6 @@ import (
timertxt "git.bullercodeworks.com/brian/go-timertxt" timertxt "git.bullercodeworks.com/brian/go-timertxt"
) )
func (a *AppState) opI3Status(args []string) int {
state := "Idle"
wrk, err := a.getMostRecentTimer()
if err != nil {
fmt.Print("{\"icon\":\"time\",\"state\":\"Critical\", \"text\": \"Error loading timer entry\"}")
return 0
}
var text string
if wrk.FinishDate.IsZero() {
wrkDur := wrk.Duration().Round(time.Minute * 15)
hrs := int(wrkDur.Hours())
mins := int(wrkDur.Minutes()) - hrs*60
if hrs > 0 {
text = fmt.Sprintf("%dh%dm", hrs, mins)
} else {
text = fmt.Sprintf("%dm", mins)
}
if !wrk.Finished {
// If the current time is before 7AM, after 5PM, or a weekend, use a Warning state
cTime := time.Now()
if cTime.Weekday() == time.Sunday || cTime.Weekday() == time.Saturday || cTime.Hour() < 7 || cTime.Hour() > 17 {
state = "Warning"
} else {
state = "Good"
}
}
for _, ctx := range wrk.Contexts {
text = fmt.Sprintf("%s @%s", text, ctx)
}
for _, prj := range wrk.Projects {
text = fmt.Sprintf("%s +%s", text, prj)
}
} else {
text = "("
for _, ctx := range wrk.Contexts {
text = fmt.Sprintf("%s@%s ", text, ctx)
}
for _, prj := range wrk.Projects {
text = fmt.Sprintf("%s+%s ", text, prj)
}
if text[len(text)-1] == ' ' {
text = text[:len(text)-1]
}
text = text + ")"
getListTotal := func(list *timertxt.TimerList) string {
var isActive bool
var total time.Duration
for _, v := range *list {
dur := v.FinishDate.Sub(v.StartDate)
if v.FinishDate.IsZero() {
dur = time.Now().Sub(v.StartDate)
isActive = true
}
total += dur
}
total = total.Round(GetRoundToDuration())
if isActive {
return fmt.Sprintf("%.2f+", DurationToDecimal(total))
} else {
return fmt.Sprintf("%.2f", DurationToDecimal(total))
}
}
dayList := a.getFilteredTimerList([]string{"--a", BeginningOfDay().Format("2006-01-02"), "@bcw"})
text = text + " d:" + getListTotal(dayList)
weekList := a.getFilteredTimerList([]string{"--a", BeginningOfWeek().Format("2006-01-02"), "@bcw"})
text = text + " w:" + getListTotal(weekList)
monthList := a.getFilteredTimerList([]string{"--a", BeginningOfMonth().Format("2006-01-02"), "@bcw"})
text = text + " m:" + getListTotal(monthList)
}
fmt.Printf("{\"icon\":\"time\",\"state\":\"%s\", \"text\": \"%s\"}", state, text)
return 0
}
func (a *AppState) opEditor(args []string) int {
editor := os.Getenv("EDITOR")
if editor == "" {
fmt.Println("No $EDITOR set")
return 1
}
fmt.Println(editor, a.directory+a.fileTimer)
return 0
}
func (a *AppState) opStatus(args []string) int { func (a *AppState) opStatus(args []string) int {
if len(*a.TimerList.GetActiveTimers()) == 0 { if len(*a.TimerList.GetActiveTimers()) == 0 {
fmt.Println("No timers running") fmt.Println("No timers running")
@ -576,3 +493,86 @@ func (a *AppState) opPrintUsage(args []string) int {
} }
return 0 return 0
} }
func (a *AppState) opI3Status(args []string) int {
state := "Idle"
wrk, err := a.getMostRecentTimer()
if err != nil {
fmt.Print("{\"icon\":\"time\",\"state\":\"Critical\", \"text\": \"Error loading timer entry\"}")
return 0
}
var text string
if wrk.FinishDate.IsZero() {
wrkDur := wrk.Duration().Round(time.Minute * 15)
hrs := int(wrkDur.Hours())
mins := int(wrkDur.Minutes()) - hrs*60
if hrs > 0 {
text = fmt.Sprintf("%dh%dm", hrs, mins)
} else {
text = fmt.Sprintf("%dm", mins)
}
if !wrk.Finished {
// If the current time is before 7AM, after 5PM, or a weekend, use a Warning state
cTime := time.Now()
if cTime.Weekday() == time.Sunday || cTime.Weekday() == time.Saturday || cTime.Hour() < 7 || cTime.Hour() > 17 {
state = "Warning"
} else {
state = "Good"
}
}
for _, ctx := range wrk.Contexts {
text = fmt.Sprintf("%s @%s", text, ctx)
}
for _, prj := range wrk.Projects {
text = fmt.Sprintf("%s +%s", text, prj)
}
} else {
text = "("
for _, ctx := range wrk.Contexts {
text = fmt.Sprintf("%s@%s ", text, ctx)
}
for _, prj := range wrk.Projects {
text = fmt.Sprintf("%s+%s ", text, prj)
}
if text[len(text)-1] == ' ' {
text = text[:len(text)-1]
}
text = text + ")"
getListTotal := func(list *timertxt.TimerList) string {
var isActive bool
var total time.Duration
for _, v := range *list {
dur := v.FinishDate.Sub(v.StartDate)
if v.FinishDate.IsZero() {
dur = time.Now().Sub(v.StartDate)
isActive = true
}
total += dur
}
total = total.Round(GetRoundToDuration())
if isActive {
return fmt.Sprintf("%.2f+", DurationToDecimal(total))
} else {
return fmt.Sprintf("%.2f", DurationToDecimal(total))
}
}
dayList := a.getFilteredTimerList([]string{"--a", BeginningOfDay().Format("2006-01-02"), "@bcw"})
text = text + " d:" + getListTotal(dayList)
weekList := a.getFilteredTimerList([]string{"--a", BeginningOfWeek().Format("2006-01-02"), "@bcw"})
text = text + " w:" + getListTotal(weekList)
monthList := a.getFilteredTimerList([]string{"--a", BeginningOfMonth().Format("2006-01-02"), "@bcw"})
text = text + " m:" + getListTotal(monthList)
}
fmt.Printf("{\"icon\":\"time\",\"state\":\"%s\", \"text\": \"%s\"}", state, text)
return 0
}
func (a *AppState) opEditor(args []string) int {
editor := os.Getenv("EDITOR")
if editor == "" {
fmt.Println("No $EDITOR set")
return 1
}
fmt.Println(editor, a.directory+a.fileTimer)
return 0
}