Skip to content

Commit fa4b8fe

Browse files
committed
Resolve #85
1 parent 40af813 commit fa4b8fe

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

pkg/util/log/loading_text.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package log
22

33
import (
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

2123
func (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

7983
func (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(" "))

0 commit comments

Comments
 (0)