@@ -50,7 +50,10 @@ func stripControlCharacters(s string) string {
50
50
}, s )
51
51
}
52
52
53
- func displayStatusMsg (status , msg string , termMaxWidth int ) {
53
+ func displayStatusMsg (ontty bool , status , msg string , termMaxWidth int ) {
54
+ if ! ontty {
55
+ return
56
+ }
54
57
s := strings .TrimSpace (msg )
55
58
if s == "" {
56
59
return
@@ -63,8 +66,11 @@ func displayStatusMsg(status, msg string, termMaxWidth int) {
63
66
}
64
67
65
68
func runDevShellSSH (ctx context.Context , builder * platform.QemuBuilder , conf * conf.Conf , sshCommand string ) error {
66
- if ! term .IsTerminal (0 ) {
67
- return fmt .Errorf ("stdin is not a tty" )
69
+ ontty := term .IsTerminal (0 )
70
+ if sshCommand == "" {
71
+ if ! ontty {
72
+ return fmt .Errorf ("stdin is not a tty" )
73
+ }
68
74
}
69
75
termMaxWidth , _ , err := term .GetSize (0 )
70
76
if err != nil {
@@ -170,6 +176,7 @@ func runDevShellSSH(ctx context.Context, builder *platform.QemuBuilder, conf *co
170
176
171
177
// Start the SSH client
172
178
sc := newSshClient (ip , agent .Socket , sshCommand )
179
+ sc .ontty = ontty
173
180
go sc .controlStartStop ()
174
181
175
182
ready := false
@@ -187,7 +194,7 @@ func runDevShellSSH(ctx context.Context, builder *platform.QemuBuilder, conf *co
187
194
// a status message on the console.
188
195
case serialMsg := <- serialChan :
189
196
if ! ready {
190
- displayStatusMsg (statusMsg , serialMsg , termMaxWidth )
197
+ displayStatusMsg (ontty , statusMsg , serialMsg , termMaxWidth )
191
198
}
192
199
lastMsg = serialMsg
193
200
// monitor the err channel
@@ -201,7 +208,7 @@ func runDevShellSSH(ctx context.Context, builder *platform.QemuBuilder, conf *co
201
208
202
209
// monitor the instance state
203
210
case <- qemuWaitChan :
204
- displayStatusMsg ("DONE" , "QEMU instance terminated" , termMaxWidth )
211
+ displayStatusMsg (ontty , "DONE" , "QEMU instance terminated" , termMaxWidth )
205
212
return nil
206
213
207
214
// monitor the machine state events from console/serial logs
@@ -232,17 +239,17 @@ func runDevShellSSH(ctx context.Context, builder *platform.QemuBuilder, conf *co
232
239
statusMsg = "QEMU guest is booting"
233
240
}
234
241
}
235
- displayStatusMsg (fmt .Sprintf ("EVENT | %s" , statusMsg ), lastMsg , termMaxWidth )
242
+ displayStatusMsg (ontty , fmt .Sprintf ("EVENT | %s" , statusMsg ), lastMsg , termMaxWidth )
236
243
237
244
// monitor the SSH connection
238
245
case err := <- sc .errChan :
239
246
if err == nil {
240
247
sc .controlChan <- sshNotReady
241
- displayStatusMsg ("SESSION" , "Clean exit from SSH, terminating instance" , termMaxWidth )
248
+ displayStatusMsg (ontty , "SESSION" , "Clean exit from SSH, terminating instance" , termMaxWidth )
242
249
return nil
243
250
} else if sshCommand != "" {
244
251
sc .controlChan <- sshNotReady
245
- displayStatusMsg ("SESSION" , "SSH command exited, terminating instance" , termMaxWidth )
252
+ displayStatusMsg (ontty , "SESSION" , "SSH command exited, terminating instance" , termMaxWidth )
246
253
return err
247
254
}
248
255
if ready {
@@ -455,6 +462,7 @@ type sshClient struct {
455
462
port string
456
463
agent string
457
464
cmd string
465
+ ontty bool
458
466
controlChan chan sshControlMessage
459
467
errChan chan error
460
468
sshCmd * exec.Cmd
@@ -511,8 +519,10 @@ func (sc *sshClient) start() {
511
519
if sc .cmd != "" {
512
520
sshArgs = append (sshArgs , "--" , sc .cmd )
513
521
}
514
- fmt .Printf ("\033 [2K\r " ) // clear serial console line
515
- fmt .Printf ("[SESSION] Starting SSH\r " ) // and stage a status msg which will be erased
522
+ if sc .ontty {
523
+ fmt .Printf ("\033 [2K\r " ) // clear serial console line
524
+ fmt .Printf ("[SESSION] Starting SSH\r " ) // and stage a status msg which will be erased
525
+ }
516
526
sshCmd := exec .Command (sshArgs [0 ], sshArgs [1 :]... )
517
527
sshCmd .Stdin = os .Stdin
518
528
sshCmd .Stdout = os .Stdout
@@ -531,7 +541,7 @@ func (sc *sshClient) start() {
531
541
for scanner .Scan () {
532
542
msg := scanner .Text ()
533
543
if strings .Contains (msg , "Connection to 127.0.0.1 closed" ) {
534
- displayStatusMsg ("SSH" , "connection closed" , 0 )
544
+ displayStatusMsg (sc . ontty , "SSH" , "connection closed" , 0 )
535
545
}
536
546
}
537
547
}()
0 commit comments