Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 834a857227 | |||
| 729084ae74 | |||
| b30d663eb1 |
4
.tmuxrc
Normal file
4
.tmuxrc
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
rename-window dev
|
||||||
|
neww -n build
|
||||||
|
neww -n run
|
||||||
|
select-window -t 0:0
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright © 2022 Brian Buller <brian@bullercodeworks.com>
|
Copyright © 2022 Brian Buller <brian@bullercodeworks.com>
|
||||||
|
|
||||||
*/
|
*/
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
@@ -74,6 +73,7 @@ func opListTimers(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
filter := util.BuildFilterFromArgs(args)
|
filter := util.BuildFilterFromArgs(args)
|
||||||
list = list.Filter(filter)
|
list = list.Filter(filter)
|
||||||
|
list.Sort(timertxt.SortFinishDateAsc)
|
||||||
|
|
||||||
dayTotals := make(map[string]time.Duration)
|
dayTotals := make(map[string]time.Duration)
|
||||||
for _, v := range list.GetTimerSlice() {
|
for _, v := range list.GetTimerSlice() {
|
||||||
|
|||||||
43
cmd/time.go
43
cmd/time.go
@@ -1,6 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright © 2022 Brian Buller <brian@bullercodeworks.com>
|
Copyright © 2022 Brian Buller <brian@bullercodeworks.com>
|
||||||
|
|
||||||
*/
|
*/
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
@@ -10,37 +9,71 @@ import (
|
|||||||
|
|
||||||
"git.bullercodeworks.com/brian/gime/cli"
|
"git.bullercodeworks.com/brian/gime/cli"
|
||||||
"git.bullercodeworks.com/brian/gime/util"
|
"git.bullercodeworks.com/brian/gime/util"
|
||||||
|
"git.bullercodeworks.com/brian/go-timertxt"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
// timeCmd represents the time command
|
// timeCmd represents the time command
|
||||||
var timeCmd = &cobra.Command{
|
var timeCmd = &cobra.Command{
|
||||||
Use: "time",
|
Use: "time",
|
||||||
Short: "A brief description of your command",
|
Short: "Output the total time for the given contexts/projects",
|
||||||
RunE: opShowTimers,
|
RunE: opShowTimers,
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(timeCmd)
|
rootCmd.AddCommand(timeCmd)
|
||||||
|
|
||||||
|
// Local Flags
|
||||||
|
timeCmd.Flags().BoolP("all", "a", false, "Include done.txt timers")
|
||||||
|
timeCmd.Flags().BoolP("done", "d", false, "Only done.txt timers")
|
||||||
}
|
}
|
||||||
|
|
||||||
func opShowTimers(cmd *cobra.Command, args []string) error {
|
func opShowTimers(cmd *cobra.Command, args []string) error {
|
||||||
var err error
|
var err error
|
||||||
|
var includeArchive bool
|
||||||
|
var onlyArchive bool
|
||||||
|
if onlyArchive, err = cmd.Flags().GetBool("done"); err != nil {
|
||||||
|
return err
|
||||||
|
} else if includeArchive, err = cmd.Flags().GetBool("all"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
p := cli.Program{}
|
p := cli.Program{}
|
||||||
err = p.Initialize()
|
err = p.Initialize()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if !onlyArchive {
|
||||||
if err := p.LoadTimerList(); err != nil {
|
if err := p.LoadTimerList(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
list := p.GetFilteredTimerList(args)
|
}
|
||||||
|
if includeArchive || onlyArchive {
|
||||||
|
if err := p.LoadDoneList(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
list := timertxt.NewTimerList()
|
||||||
|
if !onlyArchive {
|
||||||
|
list = p.TimerList
|
||||||
|
if includeArchive {
|
||||||
|
for _, tmr := range p.DoneList.GetTimerSlice() {
|
||||||
|
list.AddTimer(tmr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
list = p.DoneList
|
||||||
|
}
|
||||||
|
filter := util.BuildFilterFromArgs(args)
|
||||||
|
list = list.Filter(filter)
|
||||||
|
list.Sort(timertxt.SortFinishDateAsc)
|
||||||
|
|
||||||
var isActive bool
|
var isActive bool
|
||||||
var total time.Duration
|
var total time.Duration
|
||||||
for _, v := range list.GetTimerSlice() {
|
for _, v := range list.GetTimerSlice() {
|
||||||
dur := v.FinishDate.Sub(v.StartDate)
|
dur := util.Round(v.FinishDate.Sub(v.StartDate))
|
||||||
if v.FinishDate.IsZero() {
|
if v.FinishDate.IsZero() {
|
||||||
dur = time.Now().Sub(v.StartDate)
|
dur = util.Round(time.Now().Sub(v.StartDate))
|
||||||
isActive = true
|
isActive = true
|
||||||
}
|
}
|
||||||
total += dur
|
total += dur
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -9,7 +9,7 @@ replace git.bullercodeworks.com/brian/wandle => /home/brbuller/Development/go/sr
|
|||||||
replace git.bullercodeworks.com/brian/widdles => /home/brbuller/Development/go/src/git.bullercodeworks.com/brian/widdles
|
replace git.bullercodeworks.com/brian/widdles => /home/brbuller/Development/go/src/git.bullercodeworks.com/brian/widdles
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.bullercodeworks.com/brian/go-timertxt v0.0.0-20210302170637-d35b67037e23
|
git.bullercodeworks.com/brian/go-timertxt v1.5.0
|
||||||
git.bullercodeworks.com/brian/wandle v1.0.3
|
git.bullercodeworks.com/brian/wandle v1.0.3
|
||||||
git.bullercodeworks.com/brian/widdles v0.0.0-00010101000000-000000000000
|
git.bullercodeworks.com/brian/widdles v0.0.0-00010101000000-000000000000
|
||||||
github.com/br0xen/termbox-util v0.0.0-20200220160819-dc6d6950ba00
|
github.com/br0xen/termbox-util v0.0.0-20200220160819-dc6d6950ba00
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
*/
|
*/
|
||||||
type PromptForTagWiddle struct {
|
type PromptForTagWiddle struct {
|
||||||
active bool
|
active bool
|
||||||
|
visible bool
|
||||||
x, y, w, h int
|
x, y, w, h int
|
||||||
|
|
||||||
origKey, origVal string
|
origKey, origVal string
|
||||||
@@ -36,8 +37,8 @@ func NewPromptForTagWiddle(x, y, w, h int, key, val string) *PromptForTagWiddle
|
|||||||
origKey: key, origVal: val,
|
origKey: key, origVal: val,
|
||||||
keyInput: keyInp,
|
keyInput: keyInp,
|
||||||
valInput: widdles.NewToggleField("Value", val, 0, 0, 0, 0),
|
valInput: widdles.NewToggleField("Value", val, 0, 0, 0, 0),
|
||||||
cancelButton: widdles.NewButton("Cancel", 0, 0, 0, 0),
|
cancelButton: widdles.NewButton("Cancel"),
|
||||||
doneButton: widdles.NewButton("Done", 0, 0, 0, 0),
|
doneButton: widdles.NewButton("Done"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,6 +87,8 @@ func (w *PromptForTagWiddle) View(style wandle.Style) {
|
|||||||
wandle.Print(w.x+1, w.y+w.h-2, style, w.msg)
|
wandle.Print(w.x+1, w.y+w.h-2, style, w.msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *PromptForTagWiddle) SetVisible(v bool) { w.visible = v }
|
||||||
|
func (w *PromptForTagWiddle) IsVisible() bool { return w.visible }
|
||||||
func (w *PromptForTagWiddle) IsActive() bool { return w.active }
|
func (w *PromptForTagWiddle) IsActive() bool { return w.active }
|
||||||
func (w *PromptForTagWiddle) SetActive(b bool) { w.active = b }
|
func (w *PromptForTagWiddle) SetActive(b bool) { w.active = b }
|
||||||
func (w *PromptForTagWiddle) Focusable() bool { return true }
|
func (w *PromptForTagWiddle) Focusable() bool { return true }
|
||||||
|
|||||||
@@ -102,9 +102,11 @@ func DurationToDecimal(dur time.Duration) float64 {
|
|||||||
mins := dur.Minutes() - (dur.Hours() * 60)
|
mins := dur.Minutes() - (dur.Hours() * 60)
|
||||||
return dur.Hours() + (mins / 60)
|
return dur.Hours() + (mins / 60)
|
||||||
}
|
}
|
||||||
|
|
||||||
func AddDurations(dur1, dur2 time.Duration) time.Duration {
|
func AddDurations(dur1, dur2 time.Duration) time.Duration {
|
||||||
return time.Duration(int64(dur1) + int64(dur2))
|
return time.Duration(int64(dur1) + int64(dur2))
|
||||||
}
|
}
|
||||||
|
|
||||||
func SubDurations(dur1, dur2 time.Duration) time.Duration {
|
func SubDurations(dur1, dur2 time.Duration) time.Duration {
|
||||||
return time.Duration(int64(dur1) - int64(dur2))
|
return time.Duration(int64(dur1) - int64(dur2))
|
||||||
}
|
}
|
||||||
@@ -167,6 +169,23 @@ func ParseFuzzyTime(t string) (time.Time, error) {
|
|||||||
return ret, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Check for some custom string values
|
||||||
|
now := time.Now()
|
||||||
|
y, m, d := now.Date()
|
||||||
|
switch t {
|
||||||
|
case "today", "today-start", "day", "day-start":
|
||||||
|
return time.Date(y, m, d, 0, 0, 0, 0, now.Location()), nil
|
||||||
|
case "today-end", "day-end":
|
||||||
|
return time.Date(y, m, d, 23, 59, 59, 0, now.Location()).Add(-time.Duration(time.Nanosecond)), nil
|
||||||
|
case "month", "month-start":
|
||||||
|
return time.Date(y, m, 1, 0, 0, 0, 0, now.Location()), nil
|
||||||
|
case "month-end":
|
||||||
|
return time.Date(y, m+1, 1, 0, 0, 0, 0, now.Location()).Add(-time.Duration(time.Nanosecond)), nil
|
||||||
|
case "year", "year-start":
|
||||||
|
return time.Date(y, 1, 1, 0, 0, 0, 0, now.Location()), nil
|
||||||
|
case "year-end":
|
||||||
|
return time.Date(y+1, 1, 1, 0, 0, 0, 0, now.Location()).Add(-time.Duration(time.Nanosecond)), nil
|
||||||
|
}
|
||||||
return time.Time{}, errors.New("Unable to parse time: " + t)
|
return time.Time{}, errors.New("Unable to parse time: " + t)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -359,24 +378,40 @@ func BuildFilterFromArgs(args []string) func(*timertxt.Timer) bool {
|
|||||||
end := time.Now()
|
end := time.Now()
|
||||||
var contextFilters []string
|
var contextFilters []string
|
||||||
var projectFilters []string
|
var projectFilters []string
|
||||||
|
var tagFilters []string
|
||||||
var allFilters []func(timertxt.Timer) bool
|
var allFilters []func(timertxt.Timer) bool
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
contextFilters, args = GetContextsFromSlice(args)
|
contextFilters, args = GetContextsFromSlice(args)
|
||||||
projectFilters, args = GetProjectsFromSlice(args)
|
projectFilters, args = GetProjectsFromSlice(args)
|
||||||
|
tagFilters, args = GetAdditionalTagsFromSlice(args)
|
||||||
}
|
}
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
|
// Bounded by time. Parse the start time.
|
||||||
|
if args[0] == "today" || args[0] == "day" || args[0] == "month" || args[0] == "year" {
|
||||||
|
args[0] = fmt.Sprintf("%s-start", args[0])
|
||||||
|
if len(args) == 1 {
|
||||||
|
args = append(args, fmt.Sprintf("%s-end", args[0]))
|
||||||
|
}
|
||||||
|
}
|
||||||
var err error
|
var err error
|
||||||
if start, err = ParseFuzzyTime(args[0]); err != nil {
|
if start, err = ParseFuzzyTime(args[0]); err != nil {
|
||||||
|
// Error parsing start date
|
||||||
y, m, d := time.Now().Date()
|
y, m, d := time.Now().Date()
|
||||||
start = time.Date(y, m, d, 0, 0, 0, 0, time.Now().Location())
|
start = time.Date(y, m, d, 0, 0, 0, 0, time.Now().Location())
|
||||||
} else {
|
} else {
|
||||||
|
// Not sure what this arg is, discard it.
|
||||||
args = args[1:]
|
args = args[1:]
|
||||||
}
|
}
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
|
if args[0] == "today" || args[0] == "day" || args[0] == "month" || args[0] == "year" {
|
||||||
|
args[0] = fmt.Sprintf("%s-end", args[0])
|
||||||
|
}
|
||||||
|
// Parse the end time
|
||||||
if end, err = ParseFuzzyTime(args[0]); err != nil {
|
if end, err = ParseFuzzyTime(args[0]); err != nil {
|
||||||
y, m, d := time.Now().Date()
|
y, m, d := time.Now().Date()
|
||||||
end = time.Date(y, m, d, 23, 59, 59, 0, time.Now().Location())
|
end = time.Date(y, m, d, 23, 59, 59, 0, time.Now().Location())
|
||||||
} else {
|
} else {
|
||||||
|
// Not sure what this arg is, discard it.
|
||||||
args = args[1:]
|
args = args[1:]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -412,6 +447,20 @@ func BuildFilterFromArgs(args []string) func(*timertxt.Timer) bool {
|
|||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
if len(tagFilters) > 0 {
|
||||||
|
allFilters = append(allFilters, func(t timertxt.Timer) bool {
|
||||||
|
for _, v := range tagFilters {
|
||||||
|
pts := strings.Split(v, ":")
|
||||||
|
if len(pts) < 2 || !t.HasTag(pts[0]) || t.GetTag(pts[0]) != pts[1] {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
//if len(pts) == 2 && t.HasTag(pts[0]) && t.GetTag(pts[0]) == pts[1] {
|
||||||
|
// return true
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
}
|
||||||
doFilters := func(t *timertxt.Timer) bool {
|
doFilters := func(t *timertxt.Timer) bool {
|
||||||
for _, v := range allFilters {
|
for _, v := range allFilters {
|
||||||
if !v(*t) {
|
if !v(*t) {
|
||||||
@@ -441,6 +490,7 @@ func StringSliceContains(sl []string, val string) bool {
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func AppendStringIfDistinct(sl []string, val string) []string {
|
func AppendStringIfDistinct(sl []string, val string) []string {
|
||||||
if !StringSliceContains(sl, val) {
|
if !StringSliceContains(sl, val) {
|
||||||
return append(sl, val)
|
return append(sl, val)
|
||||||
|
|||||||
Reference in New Issue
Block a user