Skip to content

Commit edb2d42

Browse files
committed
fix: compensate for printing performance on Windows
Updating the screen takes a much longer time on Windows than it does on other platforms. This change adds a longer update delay on Windows to help to compensate for that. Signed-off-by: Donnie Adams <[email protected]>
1 parent d36cdf2 commit edb2d42

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

display.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
package tui
22

33
import (
4+
"runtime"
45
"strings"
56
"time"
67

78
"github.com/pterm/pterm"
89
)
910

1011
type display struct {
11-
area *pterm.AreaPrinter
12-
prompter *prompter
13-
last time.Time
14-
stopped bool
12+
area *pterm.AreaPrinter
13+
prompter *prompter
14+
last time.Time
15+
lastDuration int64
16+
stopped bool
1517
}
1618

1719
func newDisplay(tool string) (*display, error) {
@@ -87,17 +89,21 @@ func (a *display) Progress(text string) error {
8789
a.area = area
8890
a.stopped = false
8991
a.last = time.Time{}
92+
a.lastDuration = 0
9093
}
9194

9295
now := time.Now()
93-
if now.Sub(a.last).Milliseconds() > 50 {
94-
a.last = now
96+
if now.Sub(a.last).Milliseconds() > a.lastDuration+50 {
9597
lines := strings.Split(text, "\n")
9698
height := pterm.GetTerminalHeight()
9799
if len(lines) > height {
98100
lines = lines[len(lines)-height:]
99101
}
100102
a.area.Update(strings.Join(lines, "\n"))
103+
if !a.last.IsZero() && runtime.GOOS == "windows" {
104+
a.lastDuration = time.Now().Sub(a.last).Milliseconds()
105+
}
106+
a.last = now
101107
}
102108

103109
return nil

run.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,11 @@ func Run(ctx context.Context, tool string, opts ...RunOptions) error {
102102
var text string
103103

104104
for event := range run.Events() {
105-
text = render(input, run)
106-
if err := ui.Progress(text); err != nil {
107-
return err
105+
if event.Call != nil {
106+
text = render(input, run)
107+
if err := ui.Progress(text); err != nil {
108+
return err
109+
}
108110
}
109111

110112
if ok, err := confirm.HandlePrompt(ctx, event, ui.Ask); !ok || err != nil {

0 commit comments

Comments
 (0)