@@ -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,9 @@ 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
+ if ontty {
212
+ displayStatusMsg (ontty , "DONE" , "QEMU instance terminated" , termMaxWidth )
213
+ }
205
214
return nil
206
215
207
216
// monitor the machine state events from console/serial logs
@@ -232,17 +241,17 @@ func runDevShellSSH(ctx context.Context, builder *platform.QemuBuilder, conf *co
232
241
statusMsg = "QEMU guest is booting"
233
242
}
234
243
}
235
- displayStatusMsg (fmt .Sprintf ("EVENT | %s" , statusMsg ), lastMsg , termMaxWidth )
244
+ displayStatusMsg (ontty , fmt .Sprintf ("EVENT | %s" , statusMsg ), lastMsg , termMaxWidth )
236
245
237
246
// monitor the SSH connection
238
247
case err := <- sc .errChan :
239
248
if err == nil {
240
249
sc .controlChan <- sshNotReady
241
- displayStatusMsg ("SESSION" , "Clean exit from SSH, terminating instance" , termMaxWidth )
250
+ displayStatusMsg (ontty , "SESSION" , "Clean exit from SSH, terminating instance" , termMaxWidth )
242
251
return nil
243
252
} else if sshCommand != "" {
244
253
sc .controlChan <- sshNotReady
245
- displayStatusMsg ("SESSION" , "SSH command exited, terminating instance" , termMaxWidth )
254
+ displayStatusMsg (ontty , "SESSION" , "SSH command exited, terminating instance" , termMaxWidth )
246
255
return err
247
256
}
248
257
if ready {
@@ -455,6 +464,7 @@ type sshClient struct {
455
464
port string
456
465
agent string
457
466
cmd string
467
+ ontty bool
458
468
controlChan chan sshControlMessage
459
469
errChan chan error
460
470
sshCmd * exec.Cmd
@@ -511,8 +521,10 @@ func (sc *sshClient) start() {
511
521
if sc .cmd != "" {
512
522
sshArgs = append (sshArgs , "--" , sc .cmd )
513
523
}
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
524
+ if sc .ontty {
525
+ fmt .Printf ("\033 [2K\r " ) // clear serial console line
526
+ fmt .Printf ("[SESSION] Starting SSH\r " ) // and stage a status msg which will be erased
527
+ }
516
528
sshCmd := exec .Command (sshArgs [0 ], sshArgs [1 :]... )
517
529
sshCmd .Stdin = os .Stdin
518
530
sshCmd .Stdout = os .Stdout
@@ -531,7 +543,7 @@ func (sc *sshClient) start() {
531
543
for scanner .Scan () {
532
544
msg := scanner .Text ()
533
545
if strings .Contains (msg , "Connection to 127.0.0.1 closed" ) {
534
- displayStatusMsg ("SSH" , "connection closed" , 0 )
546
+ displayStatusMsg (sc . ontty , "SSH" , "connection closed" , 0 )
535
547
}
536
548
}
537
549
}()
0 commit comments