Add highlighting rows only when you are on that widget, and tweaked table spacing.

This commit is contained in:
Clement Tsang 2020-01-02 19:07:53 -05:00
parent f018cb7542
commit 9ff3cb7a52

View File

@ -331,6 +331,8 @@ fn draw_cpu_legend<B: backend::Backend>(f: &mut Frame<B>, app_state: &mut app::A
let cpu_rows = stringified_cpu_data.iter().enumerate().map(|(itx, cpu_string_row)| { let cpu_rows = stringified_cpu_data.iter().enumerate().map(|(itx, cpu_string_row)| {
Row::StyledData( Row::StyledData(
cpu_string_row.iter(), cpu_string_row.iter(),
match app_state.current_application_position {
app::ApplicationPosition::Cpu => {
if cpu_row_counter == app_state.currently_selected_cpu_table_position - start_position { if cpu_row_counter == app_state.currently_selected_cpu_table_position - start_position {
cpu_row_counter = -1; cpu_row_counter = -1;
Style::default().fg(Color::Black).bg(Color::Cyan) Style::default().fg(Color::Black).bg(Color::Cyan)
@ -339,6 +341,9 @@ fn draw_cpu_legend<B: backend::Backend>(f: &mut Frame<B>, app_state: &mut app::A
cpu_row_counter += 1; cpu_row_counter += 1;
} }
Style::default().fg(COLOUR_LIST[itx % COLOUR_LIST.len()]) Style::default().fg(COLOUR_LIST[itx % COLOUR_LIST.len()])
}
}
_ => Style::default().fg(COLOUR_LIST[itx % COLOUR_LIST.len()]),
}, },
) )
}); });
@ -518,6 +523,8 @@ fn draw_temp_table<B: backend::Backend>(f: &mut Frame<B>, app_state: &mut app::A
let temperature_rows = sliced_vec.iter().map(|temp_row| { let temperature_rows = sliced_vec.iter().map(|temp_row| {
Row::StyledData( Row::StyledData(
temp_row.iter(), temp_row.iter(),
match app_state.current_application_position {
app::ApplicationPosition::Temp => {
if temp_row_counter == app_state.currently_selected_temperature_position - start_position { if temp_row_counter == app_state.currently_selected_temperature_position - start_position {
temp_row_counter = -1; temp_row_counter = -1;
Style::default().fg(Color::Black).bg(Color::Cyan) Style::default().fg(Color::Black).bg(Color::Cyan)
@ -526,11 +533,12 @@ fn draw_temp_table<B: backend::Backend>(f: &mut Frame<B>, app_state: &mut app::A
temp_row_counter += 1; temp_row_counter += 1;
} }
Style::default().fg(TEXT_COLOUR) Style::default().fg(TEXT_COLOUR)
}
}
_ => Style::default().fg(TEXT_COLOUR),
}, },
) )
}); });
let width = f64::from(draw_loc.width);
Table::new(["Sensor", "Temp"].iter(), temperature_rows) Table::new(["Sensor", "Temp"].iter(), temperature_rows)
.block( .block(
Block::default() Block::default()
@ -542,7 +550,7 @@ fn draw_temp_table<B: backend::Backend>(f: &mut Frame<B>, app_state: &mut app::A
}), }),
) )
.header_style(Style::default().fg(Color::LightBlue)) .header_style(Style::default().fg(Color::LightBlue))
.widths(&[Constraint::Length((width * 0.45) as u16), Constraint::Length((width * 0.4) as u16)]) .widths(&[Constraint::Percentage(50), Constraint::Percentage(50)])
.render(f, draw_loc); .render(f, draw_loc);
} }
@ -562,6 +570,8 @@ fn draw_disk_table<B: backend::Backend>(f: &mut Frame<B>, app_state: &mut app::A
let disk_rows = sliced_vec.iter().map(|disk| { let disk_rows = sliced_vec.iter().map(|disk| {
Row::StyledData( Row::StyledData(
disk.iter(), disk.iter(),
match app_state.current_application_position {
app::ApplicationPosition::Disk => {
if disk_counter == app_state.currently_selected_disk_position - start_position { if disk_counter == app_state.currently_selected_disk_position - start_position {
disk_counter = -1; disk_counter = -1;
Style::default().fg(Color::Black).bg(Color::Cyan) Style::default().fg(Color::Black).bg(Color::Cyan)
@ -570,12 +580,14 @@ fn draw_disk_table<B: backend::Backend>(f: &mut Frame<B>, app_state: &mut app::A
disk_counter += 1; disk_counter += 1;
} }
Style::default().fg(TEXT_COLOUR) Style::default().fg(TEXT_COLOUR)
}
}
_ => Style::default().fg(TEXT_COLOUR),
}, },
) )
}); });
// TODO: We may have to dynamically remove some of these table elements based on size... // TODO: We may have to dynamically remove some of these table elements based on size...
let width = f64::from(draw_loc.width);
Table::new(["Disk", "Mount", "Used", "Total", "Free", "R/s", "W/s"].iter(), disk_rows) Table::new(["Disk", "Mount", "Used", "Total", "Free", "R/s", "W/s"].iter(), disk_rows)
.block( .block(
Block::default() Block::default()
@ -588,20 +600,20 @@ fn draw_disk_table<B: backend::Backend>(f: &mut Frame<B>, app_state: &mut app::A
) )
.header_style(Style::default().fg(Color::LightBlue).modifier(Modifier::BOLD)) .header_style(Style::default().fg(Color::LightBlue).modifier(Modifier::BOLD))
.widths(&[ .widths(&[
Constraint::Length((width * 0.18).floor() as u16), Constraint::Percentage(18),
Constraint::Length((width * 0.14).floor() as u16), Constraint::Percentage(14),
Constraint::Length((width * 0.11).floor() as u16), Constraint::Percentage(11),
Constraint::Length((width * 0.11).floor() as u16), Constraint::Percentage(11),
Constraint::Length((width * 0.11).floor() as u16), Constraint::Percentage(11),
Constraint::Length((width * 0.11).floor() as u16), Constraint::Percentage(11),
Constraint::Length((width * 0.11).floor() as u16), Constraint::Percentage(11),
Constraint::Percentage(11),
]) ])
.render(f, draw_loc); .render(f, draw_loc);
} }
fn draw_processes_table<B: backend::Backend>(f: &mut Frame<B>, app_state: &mut app::App, draw_loc: Rect) { fn draw_processes_table<B: backend::Backend>(f: &mut Frame<B>, app_state: &mut app::App, draw_loc: Rect) {
let process_data: &[ConvertedProcessData] = &(app_state.canvas_data.process_data); let process_data: &[ConvertedProcessData] = &(app_state.canvas_data.process_data);
let width = f64::from(draw_loc.width);
// Admittedly this is kinda a hack... but we need to: // Admittedly this is kinda a hack... but we need to:
// * Scroll // * Scroll
@ -629,6 +641,8 @@ fn draw_processes_table<B: backend::Backend>(f: &mut Frame<B>, app_state: &mut a
]; ];
Row::StyledData( Row::StyledData(
stringified_process_vec.into_iter(), stringified_process_vec.into_iter(),
match app_state.current_application_position {
app::ApplicationPosition::Process => {
if process_counter == app_state.currently_selected_process_position - start_position { if process_counter == app_state.currently_selected_process_position - start_position {
process_counter = -1; process_counter = -1;
Style::default().fg(Color::Black).bg(Color::Cyan) Style::default().fg(Color::Black).bg(Color::Cyan)
@ -637,6 +651,9 @@ fn draw_processes_table<B: backend::Backend>(f: &mut Frame<B>, app_state: &mut a
process_counter += 1; process_counter += 1;
} }
Style::default().fg(TEXT_COLOUR) Style::default().fg(TEXT_COLOUR)
}
}
_ => Style::default().fg(TEXT_COLOUR),
}, },
) )
}); });
@ -673,10 +690,10 @@ fn draw_processes_table<B: backend::Backend>(f: &mut Frame<B>, app_state: &mut a
) )
.header_style(Style::default().fg(Color::LightBlue)) .header_style(Style::default().fg(Color::LightBlue))
.widths(&[ .widths(&[
Constraint::Length((width * 0.2) as u16), Constraint::Percentage(20),
Constraint::Length((width * 0.35) as u16), Constraint::Percentage(35),
Constraint::Length((width * 0.2) as u16), Constraint::Percentage(20),
Constraint::Length((width * 0.2) as u16), Constraint::Percentage(20),
]) ])
.render(f, draw_loc); .render(f, draw_loc);
} }