Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 36 additions & 3 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub enum Focus {

pub enum Dialog {
ConfirmCancelJob(String),
CancelJobError(String),
}

#[derive(Clone, Copy)]
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}

}
}
}
Expand Down