Skip to content

Commit ecff25e

Browse files
committed
add verbosity on cancel
1 parent 37187a9 commit ecff25e

2 files changed

Lines changed: 37 additions & 5 deletions

File tree

src/app.rs

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub enum Focus {
2727

2828
pub 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
}

src/job.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ impl Job {
5959
let name = field_values.get("name").unwrap().clone();
6060
let state = field_values.get("state").unwrap().clone();
6161
let state_compact = field_values.get("statecompact").unwrap().clone();
62-
let reason = Some(field_values.get("reason").unwrap().clone());
62+
let reason = field_values.get("reason")
63+
.filter(|&value| value != "None").cloned();
6364
let user = field_values.get("username").unwrap().clone();
6465
let time = field_values.get("timeused").unwrap().clone();
6566
let cpu_tres = field_values.get("tres-alloc").unwrap();

0 commit comments

Comments
 (0)