@@ -27,6 +27,7 @@ pub enum Focus {
2727
2828pub enum Dialog {
2929 ConfirmCancelJob ( String ) ,
30+ CancelJobError ( String ) ,
3031}
3132
3233#[ derive( Clone , Copy ) ]
@@ -139,20 +140,32 @@ impl App {
139140 match dialog {
140141 Dialog :: ConfirmCancelJob ( id) => match key. code {
141142 KeyCode :: Enter | KeyCode :: Char ( 'y' ) => {
142- let _ = Command :: new ( "scancel" )
143+ let output = Command :: new ( "scancel" )
143144 . arg ( id)
144145 . stdout ( Stdio :: null ( ) )
145- . stderr ( Stdio :: null ( ) )
146+ . stderr ( Stdio :: piped ( ) )
146147 . spawn ( )
147148 . expect ( "failed to execute scancel" )
148- . wait ( ) ;
149- self . dialog = None ;
149+ . wait_with_output ( )
150+ . expect ( "failed to execute scancel" ) ;
151+ // check for error
152+ if output. status . success ( ) {
153+ self . dialog = None ;
154+ } else {
155+ let err_string = String :: from_utf8_lossy ( & output. stderr ) . to_string ( ) ;
156+ self . dialog = Some ( Dialog :: CancelJobError (
157+ err_string
158+ ) ) ;
159+ } ;
150160 }
151161 KeyCode :: Esc => {
152162 self . dialog = None ;
153163 }
154164 _ => { }
155165 } ,
166+ Dialog :: CancelJobError ( _error) => {
167+ self . dialog = None ;
168+ } ,
156169 } ;
157170 } else {
158171 match key. code {
@@ -510,10 +523,28 @@ impl App {
510523 . style ( Style :: default ( ) . fg ( Color :: Green ) ) ,
511524 ) ;
512525
526+ let area = centered_lines ( 75 , 3 , f. size ( ) ) ;
527+ f. render_widget ( Clear , area) ;
528+ f. render_widget ( dialog, area) ;
529+ } ,
530+ Dialog :: CancelJobError ( error) => {
531+ let dialog = Paragraph :: new ( Line :: from ( vec ! [
532+ Span :: styled( error, Style :: default ( ) . add_modifier( Modifier :: BOLD ) ) ,
533+ ] ) )
534+ . style ( Style :: default ( ) . fg ( Color :: White ) )
535+ . wrap ( Wrap { trim : true } )
536+ . block (
537+ Block :: default ( )
538+ . title ( "Error" )
539+ . borders ( Borders :: ALL )
540+ . style ( Style :: default ( ) . fg ( Color :: Red ) ) ,
541+ ) ;
542+
513543 let area = centered_lines ( 75 , 3 , f. size ( ) ) ;
514544 f. render_widget ( Clear , area) ;
515545 f. render_widget ( dialog, area) ;
516546 }
547+
517548 }
518549 }
519550 }
0 commit comments