Skip to content

Commit

Permalink
fix status bar
Browse files Browse the repository at this point in the history
  • Loading branch information
Kqzz committed Nov 17, 2023
1 parent 876c6bf commit 803099c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ upx:
- enabled: false
compress: best
lzma: false
brute: true
brute: false
# The lines beneath this are called `modelines`. See `:help modeline`
# Feel free to remove those if you don't want/use them.
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
Expand Down
19 changes: 11 additions & 8 deletions cmd/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,12 @@ func isFlagPassed(names ...string) bool {
}

func statusBar(startTime time.Time) {
fmt.Print("\x1B7") // Save the cursor position
// fmt.Print("\x1B[2K") // Erase the entire line - breaks smth else so idk
fmt.Print("\x1B[0J") // Erase from cursor to end of screen
fmt.Print("\x1B[?47h") // Save screen
fmt.Print("\x1B[1J") // Erase from cursor to beginning of screen
fmt.Print("\x1B[?47l") // Restore screen
defer fmt.Print("\x1B8") // Restore the cursor position util new size is calculated
fmt.Print("\x1B7") // Save the cursor position
fmt.Print("\x1B[2K") // Erase the entire line - breaks smth else so idk
fmt.Print("\x1B[0J") // Erase from cursor to end of screen
fmt.Print("\x1B[?47h") // Save screen
// fmt.Print("\x1B[1J") // Erase from cursor to beginning of screen
fmt.Print("\x1B[?47l") // Restore screen

fmt.Printf("\x1B[%d;%dH", 0, 0) // move cursor to row #, col #

Expand All @@ -56,6 +55,7 @@ func statusBar(startTime time.Time) {
requestsPerSecond := float64(claimer.Stats.Total) / elapsed

fmt.Printf("[RPS: %.2f | DUPLICATE: %d | NOT_ALLOWED: %d | TOO_MANY_REQUESTS: %d] ", requestsPerSecond, claimer.Stats.Duplicate, claimer.Stats.NotAllowed, claimer.Stats.TooManyRequests)
fmt.Print("\x1B8") // Restore the cursor position util new size is calculated
}

func main() {
Expand Down Expand Up @@ -120,7 +120,10 @@ func main() {
time.Sleep(time.Until(dropRange.Start))
}

start := time.Now()
start := dropRange.Start
if start.Before(time.Now()) {
start = time.Now()
}

for {
statusBar(start)
Expand Down

0 comments on commit 803099c

Please sign in to comment.