mirror of
https://github.com/Luzifer/worktime.git
synced 2024-12-22 22:11:16 +00:00
During track display tracked time
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
6249d99e0a
commit
68b120c623
1 changed files with 18 additions and 5 deletions
23
cmd/track.go
23
cmd/track.go
|
@ -8,8 +8,9 @@ import (
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Luzifer/worktime/schema"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
"github.com/Luzifer/worktime/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
// trackCmd represents the track command
|
// trackCmd represents the track command
|
||||||
|
@ -17,13 +18,25 @@ var trackCmd = &cobra.Command{
|
||||||
Use: "track [tag [tag]]",
|
Use: "track [tag [tag]]",
|
||||||
Short: "Track a time frame from the command start until interruption",
|
Short: "Track a time frame from the command start until interruption",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
start := time.Now()
|
var (
|
||||||
|
c = make(chan os.Signal, 1)
|
||||||
|
start = time.Now()
|
||||||
|
run = true
|
||||||
|
)
|
||||||
|
|
||||||
|
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||||
fmt.Println("Press Ctrl+C to stop time tracking...")
|
fmt.Println("Press Ctrl+C to stop time tracking...")
|
||||||
|
|
||||||
c := make(chan os.Signal, 1)
|
for run {
|
||||||
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
select {
|
||||||
<-c // Blocks until a signal arrives
|
case <-c: // Blocks until a signal arrives
|
||||||
|
run = false
|
||||||
|
|
||||||
|
case <-time.Tick(time.Second):
|
||||||
|
fmt.Printf("\r\x1b[K")
|
||||||
|
fmt.Printf("Tracking since %s (%s)...", start.Format(time.RFC1123), time.Since(start))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
end := time.Now()
|
end := time.Now()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue