@@ -22,6 +22,7 @@ import (
2222 "fmt"
2323 "math"
2424 "os"
25+ "strings"
2526 "syscall"
2627 "time"
2728
@@ -90,6 +91,7 @@ const (
9091type LogKeyboard struct {
9192 kError KeyboardError
9293 Watch * KeyboardWatch
94+ Detach func ()
9395 IsDockerDesktopActive bool
9496 logLevel KEYBOARD_LOG_LEVEL
9597 signalChannel chan <- os.Signal
@@ -161,29 +163,23 @@ func (lk *LogKeyboard) printNavigationMenu() {
161163}
162164
163165func (lk * LogKeyboard ) navigationMenu () string {
164- var openDDInfo string
166+ var items [] string
165167 if lk .IsDockerDesktopActive {
166- openDDInfo = shortcutKeyColor ("v" ) + navColor (" View in Docker Desktop" )
168+ items = append ( items , shortcutKeyColor ("v" )+ navColor (" View in Docker Desktop" ) )
167169 }
168170
169- var openDDUI string
170- if openDDInfo != "" {
171- openDDUI = navColor (" " )
172- }
173171 if lk .IsDockerDesktopActive {
174- openDDUI = openDDUI + shortcutKeyColor ("o" ) + navColor (" View Config" )
172+ items = append ( items , shortcutKeyColor ("o" )+ navColor (" View Config" ) )
175173 }
176174
177- var watchInfo string
178- if openDDInfo != "" || openDDUI != "" {
179- watchInfo = navColor (" " )
180- }
181175 isEnabled := " Enable"
182176 if lk .Watch != nil && lk .Watch .Watching {
183177 isEnabled = " Disable"
184178 }
185- watchInfo = watchInfo + shortcutKeyColor ("w" ) + navColor (isEnabled + " Watch" )
186- return openDDInfo + openDDUI + watchInfo
179+ items = append (items , shortcutKeyColor ("w" )+ navColor (isEnabled + " Watch" ))
180+ items = append (items , shortcutKeyColor ("d" )+ navColor (" Detach" ))
181+
182+ return strings .Join (items , " " )
187183}
188184
189185func (lk * LogKeyboard ) clearNavigationMenu () {
@@ -290,6 +286,9 @@ func (lk *LogKeyboard) ToggleWatch(ctx context.Context, options api.UpOptions) {
290286
291287func (lk * LogKeyboard ) HandleKeyEvents (ctx context.Context , event keyboard.KeyEvent , project * types.Project , options api.UpOptions ) {
292288 switch kRune := event .Rune ; kRune {
289+ case 'd' :
290+ lk .clearNavigationMenu ()
291+ lk .Detach ()
293292 case 'v' :
294293 lk .openDockerDesktop (ctx , project )
295294 case 'w' :
@@ -336,6 +335,10 @@ func (lk *LogKeyboard) EnableWatch(enabled bool, watcher Feature) {
336335 }
337336}
338337
338+ func (lk * LogKeyboard ) EnableDetach (detach func ()) {
339+ lk .Detach = detach
340+ }
341+
339342func allocateSpace (lines int ) {
340343 for i := 0 ; i < lines ; i ++ {
341344 clearLine ()
0 commit comments