diff --git a/cmd/formatter/shortcut.go b/cmd/formatter/shortcut.go index 3fdac477a7f..feb3eb95fce 100644 --- a/cmd/formatter/shortcut.go +++ b/cmd/formatter/shortcut.go @@ -137,11 +137,9 @@ func NewKeyboardManager(ctx context.Context, isDockerDesktopActive, isWatchConfi } func (lk *LogKeyboard) PrintKeyboardInfo(printFn func()) { - lk.clearNavigationMenu() printFn() if lk.logLevel == INFO { - lk.createBuffer(0) lk.printNavigationMenu() } } @@ -167,6 +165,9 @@ func (lk *LogKeyboard) createBuffer(lines int) { } func (lk *LogKeyboard) printNavigationMenu() { + lk.clearNavigationMenu() + lk.createBuffer(0) + if lk.logLevel == INFO { height := goterm.Height() menu := lk.navigationMenu() @@ -214,19 +215,6 @@ func (lk *LogKeyboard) clearNavigationMenu() { RestoreCursor() } -func (lk *LogKeyboard) PrintEnter() { - lk.clearNavigationMenu() - lk.printNavigationMenu() -} - -func (lk *LogKeyboard) CleanTerminal() { - height := goterm.Height() - for i := 0; i < height; i++ { - NewLine() - ClearLine() - } -} - func (lk *LogKeyboard) openDockerDesktop(ctx context.Context, project *types.Project) { if !lk.IsDockerDesktopActive { return @@ -237,19 +225,30 @@ func (lk *LogKeyboard) openDockerDesktop(ctx context.Context, project *types.Pro err := open.Run(link) if err != nil { err = fmt.Errorf("Could not open Docker Desktop") - lk.kError.addError("View", err) + lk.keyboardError("View", err) } return err }), ) } +func (lk *LogKeyboard) keyboardError(prefix string, err error) { + lk.kError.addError(prefix, err) + + lk.printNavigationMenu() + timer1 := time.NewTimer((DISPLAY_ERROR_TIME + 1) * time.Second) + go func() { + <-timer1.C + lk.printNavigationMenu() + }() +} + func (lk *LogKeyboard) StartWatch(ctx context.Context, project *types.Project, options api.UpOptions) { if !lk.IsWatchConfigured { eg.Go(tracing.EventWrapFuncForErrGroup(ctx, "menu/watch", tracing.SpanOptions{}, func(ctx context.Context) error { err := fmt.Errorf("Watch is not yet configured. Learn more: %s", ansiColor(CYAN, "https://docs.docker.com/compose/file-watch/")) - lk.kError.addError("Watch", err) + lk.keyboardError("Watch", err) return err })) return @@ -297,9 +296,7 @@ func (lk *LogKeyboard) HandleKeyEvents(event keyboard.KeyEvent, ctx context.Cont // will notify main thread to kill and will handle gracefully lk.signalChannel <- syscall.SIGINT case keyboard.KeyEnter: - lk.PrintEnter() - case keyboard.KeyCtrlL: - lk.CleanTerminal() + lk.printNavigationMenu() } }