@@ -18,6 +18,7 @@ package formatter
18
18
19
19
import (
20
20
"context"
21
+ "errors"
21
22
"fmt"
22
23
"math"
23
24
"os"
@@ -62,7 +63,7 @@ func (ke *KeyboardError) addError(prefix string, err error) {
62
63
prefix = ansiColor ("1;36" , fmt .Sprintf ("%s →" , prefix ))
63
64
errorString := fmt .Sprintf ("%s %s" , prefix , err .Error ())
64
65
65
- ke .err = fmt . Errorf (errorString )
66
+ ke .err = errors . New (errorString )
66
67
}
67
68
68
69
func (ke * KeyboardError ) error () string {
@@ -113,7 +114,14 @@ type LogKeyboard struct {
113
114
var KeyboardManager * LogKeyboard
114
115
var eg multierror.Group
115
116
116
- func NewKeyboardManager (isDockerDesktopActive , isWatchConfigured bool , sc chan <- os.Signal , watchFn func (ctx context.Context , project * types.Project , services []string , options api.WatchOptions ) error ) {
117
+ func NewKeyboardManager (isDockerDesktopActive , isWatchConfigured bool ,
118
+ sc chan <- os.Signal ,
119
+ watchFn func (ctx context.Context ,
120
+ project * types.Project ,
121
+ services []string ,
122
+ options api.WatchOptions ,
123
+ ) error ,
124
+ ) {
117
125
km := LogKeyboard {}
118
126
km .IsDockerDesktopActive = isDockerDesktopActive
119
127
km .IsWatchConfigured = isWatchConfigured
@@ -134,9 +142,9 @@ func NewKeyboardManager(isDockerDesktopActive, isWatchConfigured bool, sc chan<-
134
142
HideCursor ()
135
143
}
136
144
137
- func (lk * LogKeyboard ) PrintKeyboardInfo (print func ()) {
145
+ func (lk * LogKeyboard ) PrintKeyboardInfo (printFn func ()) {
138
146
lk .clearNavigationMenu ()
139
- print ()
147
+ printFn ()
140
148
141
149
if lk .logLevel == INFO {
142
150
lk .createBuffer (0 )
@@ -151,13 +159,13 @@ func (lk *LogKeyboard) createBuffer(lines int) {
151
159
if lk .kError .shoudlDisplay () {
152
160
extraLines := linesOffset (lk .kError .error ()) + 1
153
161
allocateSpace (extraLines )
154
- lines = lines + extraLines
162
+ lines += extraLines
155
163
}
156
164
157
165
infoMessage := lk .navigationMenu ()
158
166
extraLines := linesOffset (infoMessage ) + 1
159
167
allocateSpace (extraLines )
160
- lines = lines + extraLines
168
+ lines += extraLines
161
169
162
170
if lines > 0 {
163
171
MoveCursorUp (lines )
@@ -259,6 +267,10 @@ func (lk *LogKeyboard) StartWatch(ctx context.Context, project *types.Project, o
259
267
}
260
268
}
261
269
270
+ func (lk * LogKeyboard ) KeyboardClose () {
271
+ _ = keyboard .Close ()
272
+ }
273
+
262
274
func (lk * LogKeyboard ) HandleKeyEvents (event keyboard.KeyEvent , ctx context.Context , project * types.Project , options api.UpOptions ) {
263
275
switch kRune := event .Rune ; kRune {
264
276
case 'V' :
@@ -269,7 +281,7 @@ func (lk *LogKeyboard) HandleKeyEvents(event keyboard.KeyEvent, ctx context.Cont
269
281
}
270
282
switch key := event .Key ; key {
271
283
case keyboard .KeyCtrlC :
272
- keyboard . Close ()
284
+ lk . KeyboardClose ()
273
285
274
286
lk .clearNavigationMenu ()
275
287
ShowCursor ()
@@ -281,7 +293,7 @@ func (lk *LogKeyboard) HandleKeyEvents(event keyboard.KeyEvent, ctx context.Cont
281
293
}
282
294
go func () {
283
295
// Send telemetry
284
- tracing .SpanWrapFunc ("navigation_menu" , tracing .KeyboardOptions (lk .metrics ),
296
+ _ = tracing .SpanWrapFunc ("navigation_menu" , tracing .KeyboardOptions (lk .metrics ),
285
297
func (ctx context.Context ) error {
286
298
return nil
287
299
})(ctx )
0 commit comments