File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package log
22
33import (
4+ "fmt"
45 "io"
56 "time"
67
@@ -13,13 +14,15 @@ type loadingText struct {
1314 Stream io.Writer
1415 Message string
1516
16- loadingRune int
17- isShown bool
18- stopChan chan bool
17+ startTimestamp int64
18+ loadingRune int
19+ isShown bool
20+ stopChan chan bool
1921}
2022
2123func (l * loadingText ) Start () {
2224 l .isShown = false
25+ l .startTimestamp = time .Now ().UnixNano ()
2326
2427 if l .stopChan == nil {
2528 l .stopChan = make (chan bool )
@@ -73,14 +76,15 @@ func (l *loadingText) render() {
7376 l .Stream .Write ([]byte ("[WAIT] " ))
7477 ct .ResetColor ()
7578
76- l .Stream .Write ([]byte (l .getLoadingChar () + " " + l .Message ))
79+ timeElapsed := fmt .Sprintf ("%d" , (time .Now ().UnixNano ()- l .startTimestamp )/ int64 (time .Second ))
80+ l .Stream .Write ([]byte (l .getLoadingChar () + " " + l .Message + " (" + timeElapsed + "s)" ))
7781}
7882
7983func (l * loadingText ) Stop () {
8084 l .stopChan <- true
8185 l .Stream .Write ([]byte ("\r " ))
8286
83- messageLength := len (l .Message ) + 9
87+ messageLength := len (l .Message ) + 20
8488
8589 for i := 0 ; i < messageLength ; i ++ {
8690 l .Stream .Write ([]byte (" " ))
You can’t perform that action at this time.
0 commit comments