Skip to content
This repository has been archived by the owner on Aug 17, 2020. It is now read-only.

#118 Only use termbox if tty available #171

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 39 additions & 32 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,25 +294,28 @@ func start(test *types.TestConfig, sigChan chan os.Signal) result.LambdaResults
}
launchingOn := fmt.Sprintf("Launching on %s... (be patient)", platform)

termbox.Init()
defer termbox.Close()
termbox.Sync()
renderString(0, 0, launchingOn, coldef, coldef)
renderLogo()
termbox.Flush()

_, h := termbox.Size()
renderString(0, h-1, "Press ctrl-c to interrupt", coldef, coldef)
termbox.Flush()

go func() {
for {
event := termbox.PollEvent()
if event.Key == 3 {
sigChan <- syscall.SIGINT
var render bool
err := termbox.Init()
if err == nil {
render = true
defer termbox.Close()
termbox.Sync()
renderString(0, 0, launchingOn, coldef, coldef)
renderLogo()
termbox.Flush()

_, h := termbox.Size()
renderString(0, h-1, "Press ctrl-c to interrupt", coldef, coldef)
termbox.Flush()
go func() {
for {
event := termbox.PollEvent()
if event.Key == 3 {
sigChan <- syscall.SIGINT
}
}
}
}()
}()
}

startTime := time.Now()
firstTime := true
Expand All @@ -324,30 +327,34 @@ outer:
break outer
}
currentResult = *result
if firstTime {
if firstTime && render {
clearLogo()
firstTime = false
}

y := 3
totalReqs := 0
regionsData := currentResult.RegionsData()
for _, region := range currentResult.Regions() {
totalReqs += regionsData[region].TotalReqs
y = renderRegion(regionsData[region], y)
y++
if render {
for _, region := range currentResult.Regions() {
totalReqs += regionsData[region].TotalReqs
y = renderRegion(regionsData[region], y)
y++
}
}

y = 0
var percentDone float64
if test.Requests > 0 {
percentDone = float64(totalReqs) / float64(test.Requests)
} else {
percentDone = math.Min(float64(time.Since(startTime).Seconds())/float64(test.Timelimit), 1.0)
if render {
y = 0
var percentDone float64
if test.Requests > 0 {
percentDone = float64(totalReqs) / float64(test.Requests)
} else {
percentDone = math.Min(float64(time.Since(startTime).Seconds())/float64(test.Timelimit), 1.0)
}
drawProgressBar(percentDone, y)

termbox.Flush()
}
drawProgressBar(percentDone, y)

termbox.Flush()

case <-sigChan:
break outer
Expand Down