@@ -3,7 +3,6 @@ package formatter
3
3
import (
4
4
"context"
5
5
"fmt"
6
- "strings"
7
6
"time"
8
7
9
8
"github.com/buger/goterm"
@@ -39,12 +38,12 @@ var KeyboardManager *LogKeyboard
39
38
40
39
var errorColor = "\x1b [1;33m"
41
40
42
- func NewKeyboardManager (isDockerDesktopActive , IsWatchConfigured bool , watchFn func (ctx context.Context , project * types.Project , services []string , options api.WatchOptions ) error ) {
41
+ func NewKeyboardManager (isDockerDesktopActive , isWatchConfigured bool , watchFn func (ctx context.Context , project * types.Project , services []string , options api.WatchOptions ) error ) {
43
42
km := LogKeyboard {}
44
43
KeyboardManager = & km
45
44
KeyboardManager .Watch .Watching = true
46
- KeyboardManager .IsDockerDesktopActive = true
47
- KeyboardManager .IsWatchConfigured = true
45
+ KeyboardManager .IsDockerDesktopActive = isDockerDesktopActive
46
+ KeyboardManager .IsWatchConfigured = isWatchConfigured
48
47
KeyboardManager .Watch .WatchFn = watchFn
49
48
}
50
49
@@ -62,9 +61,9 @@ func (lk *LogKeyboard) PrintKeyboardInfo(print func()) {
62
61
lk .printInfo ()
63
62
}
64
63
65
- func (lk * LogKeyboard ) Error (err error ) {
64
+ func (lk * LogKeyboard ) Error (prefix string , err error ) {
66
65
lk .ErrorHandle .errStart = time .Now ()
67
- lk .ErrorHandle .err = err
66
+ lk .ErrorHandle .err = fmt . Errorf ( "[%s] %s" , prefix , err . Error ())
68
67
}
69
68
70
69
// This avoids incorrect printing at the end of the terminal
@@ -77,7 +76,7 @@ func (lk *LogKeyboard) createBuffer() {
77
76
func (lk * LogKeyboard ) printError (height int ) {
78
77
if lk .ErrorHandle .err != nil && int (time .Since (lk .ErrorHandle .errStart ).Seconds ()) < DISPLAY_ERROR_TIME {
79
78
fmt .Printf ("\033 [%d;0H" , height - 1 ) // Move to before last line
80
- fmt .Printf ("\033 [K" + errorColor + "[Error] " + lk .ErrorHandle .err .Error ())
79
+ fmt .Printf ("\033 [K" + errorColor + lk .ErrorHandle .err .Error ())
81
80
}
82
81
}
83
82
@@ -93,15 +92,16 @@ func (lk *LogKeyboard) printInfo() {
93
92
94
93
func (lk * LogKeyboard ) infoMessage () {
95
94
options := navColor (" Options: " )
95
+ var openDDInfo string
96
96
if lk .IsDockerDesktopActive {
97
- options = options + keyColor ("^V" ) + navColor ("iew containers in Docker Desktop" )
97
+ openDDInfo = keyColor ("^V" ) + navColor ("iew containers in Docker Desktop" )
98
98
}
99
- if lk .IsWatchConfigured {
100
- if strings .Contains (options , "Docker Desktop" ) {
101
- options = options + navColor (", " )
102
- }
103
- options = options + navColor ("Enable " ) + keyColor ("^W" ) + navColor ("atch Mode" )
99
+ var watchInfo string
100
+ if openDDInfo != "" {
101
+ watchInfo = navColor (", " )
104
102
}
103
+ watchInfo = watchInfo + navColor ("Enable " ) + keyColor ("^W" ) + navColor ("atch Mode" )
104
+ options = options + openDDInfo + watchInfo
105
105
106
106
fmt .Print ("\033 [K" + options )
107
107
}
@@ -143,13 +143,18 @@ func (lk *LogKeyboard) openDockerDesktop(project *types.Project) {
143
143
link := fmt .Sprintf ("docker-desktop://dashboard/apps/%s" , project .Name )
144
144
err := open .Run (link )
145
145
if err != nil {
146
- lk .Error (fmt .Errorf ("could not open Docker Desktop" ))
146
+ lk .Error ("View" , fmt .Errorf ("could not open Docker Desktop" ))
147
147
} else {
148
- lk .Error (nil )
148
+ lk .Error ("" , nil )
149
149
}
150
150
}
151
151
}
152
+
152
153
func (lk * LogKeyboard ) StartWatch (ctx context.Context , project * types.Project , options api.UpOptions ) {
154
+ if ! lk .IsWatchConfigured {
155
+ lk .Error ("Watch" , fmt .Errorf ("Watch is not yet configured. Learn more: https://docs.docker.com/compose/file-watch/" ))
156
+ return
157
+ }
153
158
lk .switchWatching ()
154
159
if lk .isWatching () {
155
160
fmt .Println ("watching shortcut" )
@@ -166,7 +171,7 @@ func (lk *LogKeyboard) StartWatch(ctx context.Context, project *types.Project, o
166
171
})
167
172
errW <- err
168
173
}()
169
- lk .Error (<- errW )
174
+ lk .Error ("Watch" , <- errW )
170
175
}
171
176
}
172
177
0 commit comments