Skip to content

Commit

Permalink
fix error print
Browse files Browse the repository at this point in the history
Signed-off-by: Joana Hrotko <joana.hrotko@docker.com>
  • Loading branch information
jhrotko committed Mar 22, 2024
1 parent 80e8081 commit dccd075
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions cmd/formatter/shortcut.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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()
}
}

Expand Down

0 comments on commit dccd075

Please sign in to comment.