diff --git a/cmd/formatter/logs.go b/cmd/formatter/logs.go index 7f41cf7ec4f..97297afb0d8 100644 --- a/cmd/formatter/logs.go +++ b/cmd/formatter/logs.go @@ -108,7 +108,7 @@ func (l *logConsumer) write(w io.Writer, container, message string) { if l.ctx.Err() != nil { return } - print := func() { + printFn := func() { p := l.getPresenter(container) timestamp := time.Now().Format(jsonmessage.RFC3339NanoFixed) for _, line := range strings.Split(message, "\n") { @@ -120,9 +120,9 @@ func (l *logConsumer) write(w io.Writer, container, message string) { } } if KeyboardManager != nil { - KeyboardManager.PrintKeyboardInfo(print) + KeyboardManager.PrintKeyboardInfo(printFn) } else { - print() + printFn() } } diff --git a/cmd/formatter/shortcut.go b/cmd/formatter/shortcut.go index 0e8e33ef7a9..1aa9bc952f7 100644 --- a/cmd/formatter/shortcut.go +++ b/cmd/formatter/shortcut.go @@ -18,6 +18,7 @@ package formatter import ( "context" + "errors" "fmt" "math" "os" @@ -62,7 +63,7 @@ func (ke *KeyboardError) addError(prefix string, err error) { prefix = ansiColor("1;36", fmt.Sprintf("%s →", prefix)) errorString := fmt.Sprintf("%s %s", prefix, err.Error()) - ke.err = fmt.Errorf(errorString) + ke.err = errors.New(errorString) } func (ke *KeyboardError) error() string { @@ -113,7 +114,14 @@ type LogKeyboard struct { var KeyboardManager *LogKeyboard var eg multierror.Group -func NewKeyboardManager(isDockerDesktopActive, isWatchConfigured bool, sc chan<- os.Signal, watchFn func(ctx context.Context, project *types.Project, services []string, options api.WatchOptions) error) { +func NewKeyboardManager(isDockerDesktopActive, isWatchConfigured bool, + sc chan<- os.Signal, + watchFn func(ctx context.Context, + project *types.Project, + services []string, + options api.WatchOptions, + ) error, +) { km := LogKeyboard{} km.IsDockerDesktopActive = isDockerDesktopActive km.IsWatchConfigured = isWatchConfigured @@ -134,9 +142,9 @@ func NewKeyboardManager(isDockerDesktopActive, isWatchConfigured bool, sc chan<- HideCursor() } -func (lk *LogKeyboard) PrintKeyboardInfo(print func()) { +func (lk *LogKeyboard) PrintKeyboardInfo(printFn func()) { lk.clearNavigationMenu() - print() + printFn() if lk.logLevel == INFO { lk.createBuffer(0) @@ -151,13 +159,13 @@ func (lk *LogKeyboard) createBuffer(lines int) { if lk.kError.shoudlDisplay() { extraLines := linesOffset(lk.kError.error()) + 1 allocateSpace(extraLines) - lines = lines + extraLines + lines += extraLines } infoMessage := lk.navigationMenu() extraLines := linesOffset(infoMessage) + 1 allocateSpace(extraLines) - lines = lines + extraLines + lines += extraLines if lines > 0 { MoveCursorUp(lines) @@ -259,6 +267,10 @@ func (lk *LogKeyboard) StartWatch(ctx context.Context, project *types.Project, o } } +func (lk *LogKeyboard) KeyboardClose() { + _ = keyboard.Close() +} + func (lk *LogKeyboard) HandleKeyEvents(event keyboard.KeyEvent, ctx context.Context, project *types.Project, options api.UpOptions) { switch kRune := event.Rune; kRune { case 'V': @@ -269,7 +281,7 @@ func (lk *LogKeyboard) HandleKeyEvents(event keyboard.KeyEvent, ctx context.Cont } switch key := event.Key; key { case keyboard.KeyCtrlC: - keyboard.Close() + lk.KeyboardClose() lk.clearNavigationMenu() ShowCursor() @@ -281,7 +293,7 @@ func (lk *LogKeyboard) HandleKeyEvents(event keyboard.KeyEvent, ctx context.Cont } go func() { // Send telemetry - tracing.SpanWrapFunc("navigation_menu", tracing.KeyboardOptions(lk.metrics), + _ = tracing.SpanWrapFunc("navigation_menu", tracing.KeyboardOptions(lk.metrics), func(ctx context.Context) error { return nil })(ctx) diff --git a/pkg/compose/up.go b/pkg/compose/up.go index cb470c26299..e69452251c6 100644 --- a/pkg/compose/up.go +++ b/pkg/compose/up.go @@ -99,7 +99,7 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options if options.Start.Watch { formatter.KeyboardManager.StartWatch(ctx, project, options) } - defer keyboard.Close() + defer formatter.KeyboardManager.KeyboardClose() } for { select { diff --git a/pkg/compose/watch.go b/pkg/compose/watch.go index 065df748235..45bae583316 100644 --- a/pkg/compose/watch.go +++ b/pkg/compose/watch.go @@ -175,7 +175,6 @@ func (s *composeService) Watch(ctx context.Context, project *types.Project, serv }) } if !watching { - // options.LogTo.Err(api.WatchLogger, "FAILED") return fmt.Errorf("none of the selected services is configured for watch, consider setting an 'develop' section") } options.LogTo.Log(api.WatchLogger, "Watch started")