diff --git a/src/app.rs b/src/app.rs index e5b20bb..3d960f7 100644 --- a/src/app.rs +++ b/src/app.rs @@ -26,6 +26,7 @@ pub enum Focus { pub enum Dialog { ConfirmCancelJob(String), + CancelJobError(String), } #[derive(Clone, Copy)] @@ -165,19 +166,32 @@ impl App { match dialog { Dialog::ConfirmCancelJob(id) => match key.code { KeyCode::Enter | KeyCode::Char('y') => { - Command::new("scancel") + let output = Command::new("scancel") .arg(id) .stdout(Stdio::null()) - .stderr(Stdio::null()) + .stderr(Stdio::piped()) .spawn() + .expect("failed to execute scancel") + .wait_with_output() .expect("failed to execute scancel"); - self.dialog = None; + // check for error + if output.status.success() { + self.dialog = None; + } else { + let err_string = String::from_utf8_lossy(&output.stderr).to_string(); + self.dialog = Some(Dialog::CancelJobError( + err_string + )); + }; } KeyCode::Esc => { self.dialog = None; } _ => {} }, + Dialog::CancelJobError(_error) => { + self.dialog = None; + }, }; } else { match key.code { @@ -535,10 +549,29 @@ impl App { .style(Style::default().fg(Color::Green)), ); + let area = centered_lines(75, 3, f.size()); + f.render_widget(Clear, area); + f.render_widget(dialog, area); + }, + // TODO: We should be able to remove this repeated code + Dialog::CancelJobError(error) => { + let dialog = Paragraph::new(Line::from(vec![ + Span::styled(error, Style::default().add_modifier(Modifier::BOLD)), + ])) + .style(Style::default().fg(Color::White)) + .wrap(Wrap { trim: true }) + .block( + Block::default() + .title("Error") + .borders(Borders::ALL) + .style(Style::default().fg(Color::Red)), + ); + let area = centered_lines(75, 3, f.size()); f.render_widget(Clear, area); f.render_widget(dialog, area); } + } } }