Added help screen.

This commit is contained in:
ClementTsang 2019-10-09 22:00:10 -04:00
parent 2d20ec7f6f
commit 2900ae2acf
5 changed files with 455 additions and 402 deletions

View File

@ -45,15 +45,19 @@ Currently, I'm unable to really dev or test on MacOS, so I'm not sure how well t
#### General #### General
- `q`, `Esc`, or `Ctrl-C` to quit. - `q`, `Ctrl-C` to quit.
- `Up/k`, `Down/j`, `Left/h`, `Right/l` to navigate between panels. - `Up/k`, `Down/j`, `Left/h`, `Right/l` to navigate between panels.
- `Shift+Up` and `Shift+Down` scrolls through the list if the panel is a table (Temperature, Disks, Processes) - `Shift+Up` and `Shift+Down` scrolls through the list if the panel is a table (Temperature, Disks, Processes).
- `Esc` to close a dialog window (help or dd confirmation).
- `?` to get a help screen explaining the controls.
#### Processes Panel #### Processes Panel
- `dd` to kill the selected process (currently only on Linux) - **I would highly recommend you to be careful using this, lest you accidentally kill the wrong process**. - `dd` to kill the selected process - **I would highly recommend you to be careful using this, lest you accidentally kill the wrong process**.
- `c` to sort by CPU usage. Sorts in descending order by default. Press again to reverse sorting order. - `c` to sort by CPU usage. Sorts in descending order by default. Press again to reverse sorting order.

View File

@ -21,7 +21,6 @@ pub enum ScrollDirection {
} }
pub struct App { pub struct App {
pub should_quit : bool,
pub process_sorting_type : processes::ProcessSorting, pub process_sorting_type : processes::ProcessSorting,
pub process_sorting_reverse : bool, pub process_sorting_reverse : bool,
pub to_be_resorted : bool, pub to_be_resorted : bool,
@ -40,13 +39,13 @@ pub struct App {
pub previous_process_position : i64, pub previous_process_position : i64,
awaiting_second_d : bool, awaiting_second_d : bool,
pub use_dot : bool, pub use_dot : bool,
pub show_help : bool,
} }
impl App { impl App {
pub fn new(show_average_cpu : bool, temperature_type : temperature::TemperatureType, update_rate_in_milliseconds : u64, use_dot : bool) -> App { pub fn new(show_average_cpu : bool, temperature_type : temperature::TemperatureType, update_rate_in_milliseconds : u64, use_dot : bool) -> App {
App { App {
process_sorting_type : processes::ProcessSorting::CPU, process_sorting_type : processes::ProcessSorting::CPU,
should_quit : false,
process_sorting_reverse : true, process_sorting_reverse : true,
to_be_resorted : false, to_be_resorted : false,
currently_selected_process_position : 0, currently_selected_process_position : 0,
@ -64,12 +63,23 @@ impl App {
previous_temp_position : 0, previous_temp_position : 0,
awaiting_second_d : false, awaiting_second_d : false,
use_dot, use_dot,
show_help : false,
} }
} }
pub fn on_enter(&mut self) {
}
pub fn on_esc(&mut self) {
if self.show_help {
self.show_help = false;
}
}
// TODO: How should we make it for process panel specific hotkeys? Only if we're on process panel? Or what?
pub fn on_key(&mut self, c : char) { pub fn on_key(&mut self, c : char) {
if !self.show_help {
match c { match c {
'q' => self.should_quit = true,
'd' => { 'd' => {
if self.awaiting_second_d { if self.awaiting_second_d {
self.awaiting_second_d = false; self.awaiting_second_d = false;
@ -124,6 +134,9 @@ impl App {
self.to_be_resorted = true; self.to_be_resorted = true;
self.currently_selected_process_position = 0; self.currently_selected_process_position = 0;
} }
'?' => {
self.show_help = true;
}
_ => {} _ => {}
} }
@ -131,6 +144,7 @@ impl App {
self.awaiting_second_d = false; self.awaiting_second_d = false;
} }
} }
}
fn kill_highlighted_process(&self) -> crate::utils::error::Result<()> { fn kill_highlighted_process(&self) -> crate::utils::error::Result<()> {
let current_pid = u64::from(self.data.list_of_processes[self.currently_selected_process_position as usize].pid); let current_pid = u64::from(self.data.list_of_processes[self.currently_selected_process_position as usize].pid);

View File

@ -1,8 +1,8 @@
use tui_temp_fork::{ use tui_temp_fork::{
backend, backend,
layout::{Constraint, Direction, Layout}, layout::{Alignment, Constraint, Direction, Layout},
style::{Color, Modifier, Style}, style::{Color, Modifier, Style},
widgets::{Axis, Block, Borders, Chart, Dataset, Marker, Row, Table, Widget}, widgets::{Axis, Block, Borders, Chart, Dataset, Marker, Paragraph, Row, Table, Text, Widget},
Terminal, Terminal,
}; };
@ -43,6 +43,44 @@ pub fn draw_data<B : backend::Backend>(terminal : &mut Terminal<B>, app_state :
terminal.autoresize()?; terminal.autoresize()?;
terminal.draw(|mut f| { terminal.draw(|mut f| {
//debug!("Drawing!"); //debug!("Drawing!");
// Only for the "help" and "are you sure" menus
let vertical_dialog_chunk = Layout::default()
.direction(Direction::Vertical)
.margin(1)
.constraints([Constraint::Percentage(32), Constraint::Percentage(40), Constraint::Percentage(28)].as_ref())
.split(f.size());
let middle_dialog_chunk = Layout::default()
.direction(Direction::Horizontal)
.margin(0)
.constraints([Constraint::Percentage(30), Constraint::Percentage(40), Constraint::Percentage(30)].as_ref())
.split(vertical_dialog_chunk[1]);
if app_state.show_help {
let text = [
Text::raw("\nGeneral Keybinds\n"),
Text::raw("q, Ctrl-C to quit.\n"),
Text::raw("Up/k, Down/j, Left/h, Right/l to navigate between panels.\n"),
Text::raw("Shift+Up and Shift+Down scrolls through the list.\n"),
Text::raw("Esc to close a dialog window (help or dd confirmation).\n"),
Text::raw("? to get this help screen.\n"),
Text::raw("\nProcess Panel Keybinds\n"),
Text::raw("dd to kill the selected process.\n"),
Text::raw("c to sort by CPU usage.\n"),
Text::raw("m to sort by memory usage.\n"),
Text::raw("p to sort by PID.\n"),
Text::raw("n to sort by process name.\n"),
];
Paragraph::new(text.iter())
.block(Block::default().title("Help").borders(Borders::ALL))
.style(Style::default().fg(Color::Gray))
.alignment(Alignment::Left)
.wrap(true)
.render(&mut f, middle_dialog_chunk[1]);
}
else {
let vertical_chunks = Layout::default() let vertical_chunks = Layout::default()
.direction(Direction::Vertical) .direction(Direction::Vertical)
.margin(1) .margin(1)
@ -202,7 +240,6 @@ pub fn draw_data<B : backend::Backend>(terminal : &mut Terminal<B>, app_state :
Row::StyledData( Row::StyledData(
disk.iter(), disk.iter(),
if disk_counter == app_state.currently_selected_temperature_position - start_position { if disk_counter == app_state.currently_selected_temperature_position - start_position {
// TODO: This is what controls the highlighting!
disk_counter = -1; disk_counter = -1;
Style::default().fg(Color::Black).bg(Color::Cyan) Style::default().fg(Color::Black).bg(Color::Cyan)
} }
@ -248,7 +285,6 @@ pub fn draw_data<B : backend::Backend>(terminal : &mut Terminal<B>, app_state :
Row::StyledData( Row::StyledData(
disk.iter(), disk.iter(),
if disk_counter == app_state.currently_selected_disk_position - start_position { if disk_counter == app_state.currently_selected_disk_position - start_position {
// TODO: This is what controls the highlighting!
disk_counter = -1; disk_counter = -1;
Style::default().fg(Color::Black).bg(Color::Cyan) Style::default().fg(Color::Black).bg(Color::Cyan)
} }
@ -350,7 +386,6 @@ pub fn draw_data<B : backend::Backend>(terminal : &mut Terminal<B>, app_state :
Row::StyledData( Row::StyledData(
process.iter(), process.iter(),
if process_counter == app_state.currently_selected_process_position - start_position { if process_counter == app_state.currently_selected_process_position - start_position {
// TODO: This is what controls the highlighting!
process_counter = -1; process_counter = -1;
Style::default().fg(Color::Black).bg(Color::Cyan) Style::default().fg(Color::Black).bg(Color::Cyan)
} }
@ -399,6 +434,7 @@ pub fn draw_data<B : backend::Backend>(terminal : &mut Terminal<B>, app_state :
.render(&mut f, bottom_chunks[1]); .render(&mut f, bottom_chunks[1]);
} }
} }
}
})?; })?;
//debug!("Finished drawing."); //debug!("Finished drawing.");

View File

@ -1,5 +1,5 @@
// TODO: Store like three minutes of data, then change how much is shown based on scaling! // TODO: Store like three minutes of data, then change how much is shown based on scaling!
pub const STALE_MAX_MILLISECONDS : u64 = 60 * 1000; // We wish to store at most 60 seconds worth of data. This may change in the future, or be configurable. pub const STALE_MAX_MILLISECONDS : u64 = 60 * 1000; // We wish to store at most 60 seconds worth of data. This may change in the future, or be configurable.
pub const _TIME_STARTS_FROM : u64 = 60 * 1000; pub const _TIME_STARTS_FROM : u64 = 60 * 1000; // TODO: Fix this
pub const TICK_RATE_IN_MILLISECONDS : u64 = 200; // We use this as it's a good value to work with. pub const TICK_RATE_IN_MILLISECONDS : u64 = 200; // We use this as it's a good value to work with.
pub const DEFAULT_REFRESH_RATE_IN_MILLISECONDS : u128 = 1000; pub const DEFAULT_REFRESH_RATE_IN_MILLISECONDS : u128 = 1000;

View File

@ -183,14 +183,16 @@ fn main() -> error::Result<()> {
Event::KeyInput(event) => { Event::KeyInput(event) => {
// debug!("Keyboard event fired!"); // debug!("Keyboard event fired!");
match event { match event {
KeyEvent::Ctrl('c') | KeyEvent::Esc => break, KeyEvent::Ctrl('c') | KeyEvent::Char('q') => break,
KeyEvent::Char('h') | KeyEvent::Left => app.on_left(), KeyEvent::Char('h') | KeyEvent::Left => app.on_left(),
KeyEvent::Char('l') | KeyEvent::Right => app.on_right(), KeyEvent::Char('l') | KeyEvent::Right => app.on_right(),
KeyEvent::Char('k') | KeyEvent::Up => app.on_up(), KeyEvent::Char('k') | KeyEvent::Up => app.on_up(),
KeyEvent::Char('j') | KeyEvent::Down => app.on_down(), KeyEvent::Char('j') | KeyEvent::Down => app.on_down(),
KeyEvent::ShiftUp => app.decrement_position_count(), KeyEvent::ShiftUp => app.decrement_position_count(),
KeyEvent::ShiftDown => app.increment_position_count(), KeyEvent::ShiftDown => app.increment_position_count(),
KeyEvent::Char(c) => app.on_key(c), // TODO: We can remove the 'q' event and just move it to the quit? KeyEvent::Char(c) => app.on_key(c),
KeyEvent::Enter => app.on_enter(),
KeyEvent::Esc => app.on_esc(),
_ => {} _ => {}
} }
@ -248,9 +250,6 @@ fn main() -> error::Result<()> {
debug!("Update event complete."); debug!("Update event complete.");
} }
} }
if app.should_quit {
break;
}
} }
// Draw! // Draw!
if let Err(err) = canvas::draw_data(&mut terminal, &mut app, &canvas_data) { if let Err(err) = canvas::draw_data(&mut terminal, &mut app, &canvas_data) {