6
6
"time"
7
7
8
8
"atomicgo.dev/cursor"
9
+ "github.com/pterm/pterm"
9
10
)
10
11
11
12
var (
@@ -23,6 +24,7 @@ type display struct {
23
24
displayState
24
25
prompter * prompter
25
26
contentLock sync.Mutex
27
+ paintLock sync.Mutex
26
28
closer func ()
27
29
}
28
30
@@ -49,6 +51,8 @@ func newDisplay(tool string) (*display, error) {
49
51
50
52
func (a * display ) readline (f func () (string , bool )) (string , bool ) {
51
53
a .paint ()
54
+ a .paintLock .Lock ()
55
+ defer a .paintLock .Unlock ()
52
56
cursor .Show ()
53
57
defer cursor .Hide ()
54
58
return f ()
@@ -68,7 +72,7 @@ func (a *display) setMultiLinePrompt(text string) {
68
72
if len (lines ) > 1 {
69
73
a .contentLock .Lock ()
70
74
defer a .contentLock .Unlock ()
71
- a .content = a .area . content + "\n " + strings .Join (lines [:len (lines )- 1 ], "\n " ) + "\n "
75
+ a .content = a .content + "\n " + strings .Join (lines [:len (lines )- 1 ], "\n " ) + "\n "
72
76
}
73
77
}
74
78
@@ -104,10 +108,12 @@ func (a *display) Prompt(text string) (string, bool) {
104
108
}
105
109
106
110
func (a * display ) paint () {
111
+ a .paintLock .Lock ()
112
+ defer a .paintLock .Unlock ()
113
+
107
114
a .contentLock .Lock ()
108
115
if a .finish {
109
116
a .area .Update (a .content )
110
- cursor .Show ()
111
117
a .displayState = displayState {}
112
118
a .contentLock .Unlock ()
113
119
return
@@ -120,7 +126,12 @@ func (a *display) paint() {
120
126
return
121
127
}
122
128
123
- a .area .Update (newContent )
129
+ lines := strings .Split (newContent , "\n " )
130
+ height := pterm .GetTerminalHeight ()
131
+ if len (lines ) > height {
132
+ lines = lines [len (lines )- height :]
133
+ }
134
+ a .area .Update (strings .Join (lines , "\n " ))
124
135
a .lastPrint = newContent
125
136
}
126
137
0 commit comments