1
0
Fork 0
mirror of https://github.com/Luzifer/worktime.git synced 2024-12-22 14:01:17 +00:00

During track display tracked time

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2019-07-30 14:01:04 +02:00
parent 6249d99e0a
commit 68b120c623
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E

View file

@ -8,8 +8,9 @@ import (
"syscall"
"time"
"github.com/Luzifer/worktime/schema"
"github.com/spf13/cobra"
"github.com/Luzifer/worktime/schema"
)
// trackCmd represents the track command
@ -17,13 +18,25 @@ var trackCmd = &cobra.Command{
Use: "track [tag [tag]]",
Short: "Track a time frame from the command start until interruption",
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...")
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
<-c // Blocks until a signal arrives
for run {
select {
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()