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
- `q`, `Esc`, or `Ctrl-C` to quit.
- `q`, `Ctrl-C` to quit.
- `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
- `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.

View File

@ -21,7 +21,6 @@ pub enum ScrollDirection {
}
pub struct App {
pub should_quit : bool,
pub process_sorting_type : processes::ProcessSorting,
pub process_sorting_reverse : bool,
pub to_be_resorted : bool,
@ -40,13 +39,13 @@ pub struct App {
pub previous_process_position : i64,
awaiting_second_d : bool,
pub use_dot : bool,
pub show_help : bool,
}
impl App {
pub fn new(show_average_cpu : bool, temperature_type : temperature::TemperatureType, update_rate_in_milliseconds : u64, use_dot : bool) -> App {
App {
process_sorting_type : processes::ProcessSorting::CPU,
should_quit : false,
process_sorting_reverse : true,
to_be_resorted : false,
currently_selected_process_position : 0,
@ -64,12 +63,23 @@ impl App {
previous_temp_position : 0,
awaiting_second_d : false,
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) {
if !self.show_help {
match c {
'q' => self.should_quit = true,
'd' => {
if self.awaiting_second_d {
self.awaiting_second_d = false;
@ -124,6 +134,9 @@ impl App {
self.to_be_resorted = true;
self.currently_selected_process_position = 0;
}
'?' => {
self.show_help = true;
}
_ => {}
}
@ -131,6 +144,7 @@ impl App {
self.awaiting_second_d = false;
}
}
}
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);

View File

@ -1,8 +1,8 @@
use tui_temp_fork::{
backend,
layout::{Constraint, Direction, Layout},
layout::{Alignment, Constraint, Direction, Layout},
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,
};
@ -43,6 +43,44 @@ pub fn draw_data<B : backend::Backend>(terminal : &mut Terminal<B>, app_state :
terminal.autoresize()?;
terminal.draw(|mut f| {
//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()
.direction(Direction::Vertical)
.margin(1)
@ -202,7 +240,6 @@ pub fn draw_data<B : backend::Backend>(terminal : &mut Terminal<B>, app_state :
Row::StyledData(
disk.iter(),
if disk_counter == app_state.currently_selected_temperature_position - start_position {
// TODO: This is what controls the highlighting!
disk_counter = -1;
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(
disk.iter(),
if disk_counter == app_state.currently_selected_disk_position - start_position {
// TODO: This is what controls the highlighting!
disk_counter = -1;
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(
process.iter(),
if process_counter == app_state.currently_selected_process_position - start_position {
// TODO: This is what controls the highlighting!
process_counter = -1;
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]);
}
}
}
})?;
//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!
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 DEFAULT_REFRESH_RATE_IN_MILLISECONDS : u128 = 1000;

View File

@ -183,14 +183,16 @@ fn main() -> error::Result<()> {
Event::KeyInput(event) => {
// debug!("Keyboard event fired!");
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('l') | KeyEvent::Right => app.on_right(),
KeyEvent::Char('k') | KeyEvent::Up => app.on_up(),
KeyEvent::Char('j') | KeyEvent::Down => app.on_down(),
KeyEvent::ShiftUp => app.decrement_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.");
}
}
if app.should_quit {
break;
}
}
// Draw!
if let Err(err) = canvas::draw_data(&mut terminal, &mut app, &canvas_data) {