@@ -64,8 +64,11 @@ func displayStatusMsg(status, msg string, termMaxWidth int) {
64
64
}
65
65
66
66
func runDevShellSSH (ctx context.Context , builder * platform.QemuBuilder , conf * conf.Conf , sshCommand string ) error {
67
- if ! term .IsTerminal (0 ) {
68
- return fmt .Errorf ("stdin is not a tty" )
67
+ ontty := term .IsTerminal (0 )
68
+ if sshCommand == "" {
69
+ if ! ontty {
70
+ return fmt .Errorf ("stdin is not a tty" )
71
+ }
69
72
}
70
73
termMaxWidth , _ , err := term .GetSize (0 )
71
74
if err != nil {
@@ -171,6 +174,7 @@ func runDevShellSSH(ctx context.Context, builder *platform.QemuBuilder, conf *co
171
174
172
175
// Start the SSH client
173
176
sc := newSshClient (ip , agent .Socket , sshCommand )
177
+ sc .ontty = ontty
174
178
go sc .controlStartStop ()
175
179
176
180
ready := false
@@ -187,8 +191,10 @@ func runDevShellSSH(ctx context.Context, builder *platform.QemuBuilder, conf *co
187
191
// handle console messages. If SSH is not ready, then display a
188
192
// a status message on the console.
189
193
case serialMsg := <- serialChan :
190
- if ! ready {
191
- displayStatusMsg (statusMsg , serialMsg , termMaxWidth )
194
+ if ontty {
195
+ if ! ready {
196
+ displayStatusMsg (statusMsg , serialMsg , termMaxWidth )
197
+ }
192
198
}
193
199
lastMsg = serialMsg
194
200
// monitor the err channel
@@ -202,7 +208,9 @@ func runDevShellSSH(ctx context.Context, builder *platform.QemuBuilder, conf *co
202
208
203
209
// monitor the instance state
204
210
case <- qemuWaitChan :
205
- displayStatusMsg ("DONE" , "QEMU instance terminated" , termMaxWidth )
211
+ if ontty {
212
+ displayStatusMsg ("DONE" , "QEMU instance terminated" , termMaxWidth )
213
+ }
206
214
return nil
207
215
208
216
// monitor the machine state events from console/serial logs
@@ -233,17 +241,23 @@ func runDevShellSSH(ctx context.Context, builder *platform.QemuBuilder, conf *co
233
241
statusMsg = "QEMU guest is booting"
234
242
}
235
243
}
236
- displayStatusMsg (fmt .Sprintf ("EVENT | %s" , statusMsg ), lastMsg , termMaxWidth )
244
+ if ontty {
245
+ displayStatusMsg (fmt .Sprintf ("EVENT | %s" , statusMsg ), lastMsg , termMaxWidth )
246
+ }
237
247
238
248
// monitor the SSH connection
239
249
case err := <- sc .errChan :
240
250
if err == nil {
241
251
sc .controlChan <- sshNotReady
242
- displayStatusMsg ("SESSION" , "Clean exit from SSH, terminating instance" , termMaxWidth )
252
+ if ontty {
253
+ displayStatusMsg ("SESSION" , "Clean exit from SSH, terminating instance" , termMaxWidth )
254
+ }
243
255
return nil
244
256
} else if sshCommand != "" {
245
257
sc .controlChan <- sshNotReady
246
- displayStatusMsg ("SESSION" , "SSH command exited, terminating instance" , termMaxWidth )
258
+ if ontty {
259
+ displayStatusMsg ("SESSION" , "SSH command exited, terminating instance" , termMaxWidth )
260
+ }
247
261
return err
248
262
}
249
263
if ready {
@@ -456,6 +470,7 @@ type sshClient struct {
456
470
port string
457
471
agent string
458
472
cmd string
473
+ ontty bool
459
474
controlChan chan sshControlMessage
460
475
errChan chan error
461
476
sshCmd * exec.Cmd
@@ -512,8 +527,10 @@ func (sc *sshClient) start() {
512
527
if sc .cmd != "" {
513
528
sshArgs = append (sshArgs , "--" , sc .cmd )
514
529
}
515
- fmt .Printf ("\033 [2K\r " ) // clear serial console line
516
- fmt .Printf ("[SESSION] Starting SSH\r " ) // and stage a status msg which will be erased
530
+ if sc .ontty {
531
+ fmt .Printf ("\033 [2K\r " ) // clear serial console line
532
+ fmt .Printf ("[SESSION] Starting SSH\r " ) // and stage a status msg which will be erased
533
+ }
517
534
sshCmd := exec .Command (sshArgs [0 ], sshArgs [1 :]... )
518
535
sshCmd .Stdin = os .Stdin
519
536
sshCmd .Stdout = os .Stdout
@@ -532,7 +549,9 @@ func (sc *sshClient) start() {
532
549
for scanner .Scan () {
533
550
msg := scanner .Text ()
534
551
if strings .Contains (msg , "Connection to 127.0.0.1 closed" ) {
535
- displayStatusMsg ("SSH" , "connection closed" , 0 )
552
+ if sc .ontty {
553
+ displayStatusMsg ("SSH" , "connection closed" , 0 )
554
+ }
536
555
}
537
556
}
538
557
}()
0 commit comments