Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow sorting by any column #183

Merged
merged 8 commits into from
Aug 16, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix for basic mode
  • Loading branch information
ClementTsang committed Aug 14, 2020
commit 3fb950fd7a7bfbaf9b412447994483cd8636cbe0
70 changes: 59 additions & 11 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -891,11 +891,17 @@ impl App {
// more obvious that we are separating dialog logic and normal logic IMO.
// This is even more so as most logic already checks for dialog state.
match caught_char {
'1' => self.help_scroll_to_or_max(self.help_dialog_state.index_shortcuts[1]),
'2' => self.help_scroll_to_or_max(self.help_dialog_state.index_shortcuts[2]),
'3' => self.help_scroll_to_or_max(self.help_dialog_state.index_shortcuts[3]),
'4' => self.help_scroll_to_or_max(self.help_dialog_state.index_shortcuts[4]),
'5' => self.help_scroll_to_or_max(self.help_dialog_state.index_shortcuts[5]),
'1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' => {
let potential_index = caught_char.to_digit(10);
if let Some(potential_index) = potential_index {
if (potential_index as usize) < self.help_dialog_state.index_shortcuts.len()
{
self.help_scroll_to_or_max(
self.help_dialog_state.index_shortcuts[potential_index as usize],
);
}
}
}
'j' | 'k' | 'g' | 'G' => self.handle_char(caught_char),
_ => {}
}
Expand Down Expand Up @@ -1151,19 +1157,40 @@ impl App {
BottomWidgetType::Temp
| BottomWidgetType::Proc
| BottomWidgetType::ProcSearch
| BottomWidgetType::ProcSort
| BottomWidgetType::Disk
| BottomWidgetType::Battery
if self.basic_table_widget_state.is_some() =>
{
// Gotta do this for the sort widget
if let BottomWidgetType::ProcSort = new_widget.widget_type {
if let Some(proc_widget_state) =
self.proc_state.widget_states.get(&(new_widget_id - 2))
{
if proc_widget_state.is_sort_open {
self.current_widget = new_widget.clone();
} else if let Some(next_new_widget_id) =
new_widget.left_neighbour
{
if let Some(next_new_widget) =
self.widget_map.get(&next_new_widget_id)
{
self.current_widget = next_new_widget.clone();
}
}
}
} else {
self.current_widget = new_widget.clone();
}

if let Some(basic_table_widget_state) =
&mut self.basic_table_widget_state
{
basic_table_widget_state.currently_displayed_widget_id =
new_widget_id;
self.current_widget.widget_id;
basic_table_widget_state.currently_displayed_widget_type =
new_widget.widget_type.clone();
self.current_widget.widget_type.clone();
}
self.current_widget = new_widget.clone();
}
BottomWidgetType::CpuLegend => {
if let Some(cpu_widget_state) =
Expand Down Expand Up @@ -1280,20 +1307,41 @@ impl App {
match new_widget.widget_type {
BottomWidgetType::Temp
| BottomWidgetType::Proc
| BottomWidgetType::ProcSort
| BottomWidgetType::ProcSearch
| BottomWidgetType::Disk
| BottomWidgetType::Battery
if self.basic_table_widget_state.is_some() =>
{
// Required for sort widget.
if let BottomWidgetType::ProcSort = new_widget.widget_type {
if let Some(proc_widget_state) =
self.proc_state.widget_states.get(&(new_widget_id - 2))
{
if proc_widget_state.is_sort_open {
self.current_widget = new_widget.clone();
} else if let Some(next_new_widget_id) =
new_widget.right_neighbour
{
if let Some(next_new_widget) =
self.widget_map.get(&next_new_widget_id)
{
self.current_widget = next_new_widget.clone();
}
}
}
} else {
self.current_widget = new_widget.clone();
}

if let Some(basic_table_widget_state) =
&mut self.basic_table_widget_state
{
basic_table_widget_state.currently_displayed_widget_id =
new_widget_id;
self.current_widget.widget_id;
basic_table_widget_state.currently_displayed_widget_type =
new_widget.widget_type.clone();
self.current_widget.widget_type.clone();
}
self.current_widget = new_widget.clone();
}
BottomWidgetType::CpuLegend => {
if let Some(cpu_widget_state) =
Expand Down
31 changes: 21 additions & 10 deletions src/app/layout_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ impl BottomLayout {
.widget_id(4)
.up_neighbour(Some(100))
.left_neighbour(Some(7))
.right_neighbour(Some(DEFAULT_WIDGET_ID))
.right_neighbour(Some(DEFAULT_WIDGET_ID + 2))
.build()])
.build()])
.build(),
Expand All @@ -634,15 +634,26 @@ impl BottomLayout {
.children(vec![
BottomColRow::builder()
.canvas_handle_height(true)
.children(vec![BottomWidget::builder()
.canvas_handle_width(true)
.widget_type(BottomWidgetType::Proc)
.widget_id(DEFAULT_WIDGET_ID)
.up_neighbour(Some(100))
.down_neighbour(Some(DEFAULT_WIDGET_ID + 1))
.left_neighbour(Some(4))
.right_neighbour(Some(7))
.build()])
.children(vec![
BottomWidget::builder()
.canvas_handle_width(true)
.widget_type(BottomWidgetType::ProcSort)
.widget_id(DEFAULT_WIDGET_ID + 2)
.up_neighbour(Some(100))
.down_neighbour(Some(DEFAULT_WIDGET_ID + 1))
.left_neighbour(Some(4))
.right_neighbour(Some(DEFAULT_WIDGET_ID))
.build(),
BottomWidget::builder()
.canvas_handle_width(true)
.widget_type(BottomWidgetType::Proc)
.widget_id(DEFAULT_WIDGET_ID)
.up_neighbour(Some(100))
.down_neighbour(Some(DEFAULT_WIDGET_ID + 1))
.left_neighbour(Some(DEFAULT_WIDGET_ID + 2))
.right_neighbour(Some(7))
.build(),
])
.build(),
BottomColRow::builder()
.canvas_handle_height(true)
Expand Down
21 changes: 14 additions & 7 deletions src/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,13 +426,20 @@ impl Painter {
false,
widget_id,
),
Proc => self.draw_process_features(
&mut f,
app_state,
vertical_chunks[4],
false,
widget_id,
),
Proc | ProcSort => {
let wid = widget_id
- match basic_table_widget_state.currently_displayed_widget_type {
ProcSort => 2,
_ => 0,
};
self.draw_process_features(
&mut f,
app_state,
vertical_chunks[4],
false,
wid,
);
}
Temp => self.draw_temp_table(
&mut f,
app_state,
Expand Down
2 changes: 1 addition & 1 deletion src/canvas/dialogs/help_dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl HelpDialog for Painter {

app_state.help_dialog_state.scroll_state.max_scroll_index =
(self.styled_help_text.len() as u16
+ (constants::HELP_TEXT.len() as u16 - 3)
+ (constants::HELP_TEXT.len() as u16 - 4)
+ overflow_buffer)
.saturating_sub(draw_loc.height);

Expand Down
43 changes: 41 additions & 2 deletions src/canvas/widgets/basic_table_arrows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ impl BasicTableArrows for Painter {
fn draw_basic_table_arrows<B: Backend>(
&self, f: &mut Frame<'_, B>, app_state: &App, draw_loc: Rect, current_table: &BottomWidget,
) {
let current_table = if let BottomWidgetType::ProcSort = current_table.widget_type {
current_table
.right_neighbour
.map(|id| app_state.widget_map.get(&id).unwrap())
.unwrap()
} else {
current_table
};

// Effectively a paragraph with a ton of spacing
let (left_table, right_table) = (
{
Expand All @@ -33,7 +42,21 @@ impl BasicTableArrows for Painter {
app_state
.widget_map
.get(&left_widget_id)
.map(|left_widget| &left_widget.widget_type)
.map(|left_widget| {
if left_widget.widget_type == BottomWidgetType::ProcSort {
left_widget
.left_neighbour
.map(|left_left_widget_id| {
app_state.widget_map.get(&left_left_widget_id).map(
|left_left_widget| &left_left_widget.widget_type,
)
})
.unwrap_or_else(|| Some(&BottomWidgetType::Temp))
.unwrap_or_else(|| &BottomWidgetType::Temp)
} else {
&left_widget.widget_type
}
})
.unwrap_or_else(|| &BottomWidgetType::Temp)
})
.unwrap_or_else(|| &BottomWidgetType::Temp)
Expand All @@ -45,7 +68,23 @@ impl BasicTableArrows for Painter {
app_state
.widget_map
.get(&right_widget_id)
.map(|right_widget| &right_widget.widget_type)
.map(|right_widget| {
if right_widget.widget_type == BottomWidgetType::ProcSort {
right_widget
.left_neighbour
.map(|right_right_widget_id| {
app_state.widget_map.get(&right_right_widget_id).map(
|right_right_widget| {
&right_right_widget.widget_type
},
)
})
.unwrap_or_else(|| Some(&BottomWidgetType::Disk))
.unwrap_or_else(|| &BottomWidgetType::Disk)
} else {
&right_widget.widget_type
}
})
.unwrap_or_else(|| &BottomWidgetType::Disk)
})
.unwrap_or_else(|| &BottomWidgetType::Disk)
Expand Down
4 changes: 2 additions & 2 deletions src/canvas/widgets/process_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl ProcessTableWidget for Painter {
if is_sort_open {
let processes_chunk = Layout::default()
.direction(Direction::Horizontal)
.constraints([Constraint::Length(header_len + 3), Constraint::Min(0)].as_ref())
.constraints([Constraint::Length(header_len + 4), Constraint::Min(0)].as_ref())
.split(proc_draw_loc);
proc_draw_loc = processes_chunk[1];

Expand Down Expand Up @@ -564,7 +564,7 @@ impl ProcessTableWidget for Painter {

let margined_draw_loc = Layout::default()
.constraints([Constraint::Percentage(100)].as_ref())
.margin(if is_on_widget || draw_border { 0 } else { 1 })
.horizontal_margin(if is_on_widget || draw_border { 0 } else { 1 })
.direction(Direction::Horizontal)
.split(draw_loc);

Expand Down
21 changes: 17 additions & 4 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ lazy_static! {
}

// Help text
pub const HELP_CONTENTS_TEXT: [&str; 6] = [
pub const HELP_CONTENTS_TEXT: [&str; 7] = [
"Press the corresponding numbers to jump to the section, or scroll:",
"1 - General",
"2 - CPU widget",
"3 - Process widget",
"4 - Process search widget",
"5 - Battery widget",
"5 - Process sort widget",
"6 - Battery widget",
];

pub const GENERAL_HELP_TEXT: [&str; 29] = [
Expand Down Expand Up @@ -88,7 +89,7 @@ pub const CPU_HELP_TEXT: [&str; 2] = [
"Mouse scroll Scrolling over an CPU core/average shows only that entry on the chart",
];

pub const PROCESS_HELP_TEXT: [&str; 9] = [
pub const PROCESS_HELP_TEXT: [&str; 11] = [
"3 - Process widget",
"dd Kill the selected process",
"c Sort by CPU usage, press again to reverse sorting order",
Expand All @@ -98,6 +99,8 @@ pub const PROCESS_HELP_TEXT: [&str; 9] = [
"Tab Group/un-group processes with the same name",
"Ctrl-f, / Open process search widget",
"P Toggle between showing the full path or just the process name",
"s, F6 Manage column to sort by",
"I Invert current sorting",
];

pub const SEARCH_HELP_TEXT: [&str; 43] = [
Expand Down Expand Up @@ -146,8 +149,17 @@ pub const SEARCH_HELP_TEXT: [&str; 43] = [
"TiB ex: read > 1 tib",
];

pub const SORT_HELP_TEXT: [&str; 6] = [
"5 - Sort widget",
"Up Scroll up in list",
"Down Scroll down in list",
"Mouse scroll Scroll through sort widget",
"Esc Close the sort widget",
"Enter Sort by current selected column",
];

pub const BATTERY_HELP_TEXT: [&str; 3] = [
"5 - Battery widget",
"6 - Battery widget",
"Left Go to previous battery",
"Right Go to next battery",
];
Expand All @@ -159,6 +171,7 @@ lazy_static! {
CPU_HELP_TEXT.to_vec(),
PROCESS_HELP_TEXT.to_vec(),
SEARCH_HELP_TEXT.to_vec(),
SORT_HELP_TEXT.to_vec(),
BATTERY_HELP_TEXT.to_vec(),
];
}
Expand Down