Skip to content

Commit

Permalink
feat: show state and reason in details panel
Browse files Browse the repository at this point in the history
  • Loading branch information
kabouzeid committed Mar 28, 2023
1 parent 78487bb commit a77d4a3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
26 changes: 19 additions & 7 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::io;
use tui::{
backend::Backend,
layout::{Constraint, Direction, Layout},
style::{Color, Style},
style::{Color, Modifier, Style},
text::{Span, Spans, Text},
widgets::{Block, Borders, List, ListItem, ListState, Paragraph, Wrap},
Frame, Terminal,
Expand All @@ -40,6 +40,8 @@ pub struct Job {
pub id: String,
pub name: String,
pub state: String,
pub state_compact: String,
pub reason: Option<String>,
pub user: String,
pub time: String,
pub tres: String,
Expand Down Expand Up @@ -167,7 +169,7 @@ impl App {

let job_detail_log = Layout::default()
.direction(Direction::Vertical)
.constraints([Constraint::Length(6), Constraint::Min(3)].as_ref())
.constraints([Constraint::Length(7), Constraint::Min(3)].as_ref())
.split(master_detail[1]);

// Help
Expand Down Expand Up @@ -244,23 +246,34 @@ impl App {
.and_then(|i| self.jobs.get(i));

let job_detail = job_detail.map(|j| {
let state = Spans::from(vec![
Span::styled("State ", Style::default().fg(Color::Yellow)),
Span::raw(" "),
Span::raw(&j.state),
if let Some(s) = j.reason.as_deref() {
Span::styled(
format!(" ({s})"),
Style::default().add_modifier(Modifier::DIM),
)
} else {
Span::raw("")
},
]);

let command = Spans::from(vec![
Span::styled("Command", Style::default().fg(Color::Yellow)),
Span::raw(" "),
Span::raw(&j.command),
Span::raw(" "),
]);
let nodes = Spans::from(vec![
Span::styled("Nodes ", Style::default().fg(Color::Yellow)),
Span::raw(" "),
Span::raw(&j.nodelist),
Span::raw(" "),
]);
let tres = Spans::from(vec![
Span::styled("TRES ", Style::default().fg(Color::Yellow)),
Span::raw(" "),
Span::raw(&j.tres),
Span::raw(" "),
]);
let stdout = Spans::from(vec![
Span::styled("stdout ", Style::default().fg(Color::Yellow)),
Expand All @@ -271,10 +284,9 @@ impl App {
.map(|p| p.to_str().unwrap_or_default())
.unwrap_or_default(),
),
Span::raw(" "),
]);

Text::from(vec![command, nodes, tres, stdout])
Text::from(vec![state, command, nodes, tres, stdout])
});
let job_detail = Paragraph::new(job_detail.unwrap_or_default())
.block(Block::default().title("Details").borders(Borders::ALL));
Expand Down
18 changes: 14 additions & 4 deletions src/job_watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ impl JobWatcher {
"nodelist",
"stdout",
"command",
"statecompact",
"reason",
"ArrayJobID", // %A
"ArrayTaskID", // %a
"NodeList", // %N
Expand Down Expand Up @@ -72,16 +74,24 @@ impl JobWatcher {
let nodelist = parts[7];
let stdout = parts[8];
let command = parts[9];
let state_compact = parts[10];
let reason = parts[11];

let array_job_id = parts[10];
let array_task_id = parts[11];
let node_list = parts[12];
let working_dir = parts[13];
let array_job_id = parts[12];
let array_task_id = parts[13];
let node_list = parts[14];
let working_dir = parts[15];

Some(Job {
id: id.to_owned(),
name: name.to_owned(),
state: state.to_owned(),
state_compact: state_compact.to_owned(),
reason: if reason == "None" {
None
} else {
Some(reason.to_owned())
},
user: user.to_owned(),
time: time.to_owned(),
tres: tres.to_owned(),
Expand Down

0 comments on commit a77d4a3

Please sign in to comment.