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
Next Next commit
refactor: rename and prepare for adding process sorting...
  • Loading branch information
ClementTsang committed Aug 13, 2020
commit cca3b01cdc17c39d64f599781e83f7fe42fdaf71
82 changes: 52 additions & 30 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ impl App {
proc_widget_state
.process_search_state
.search_state
.cursor_direction = CursorDirection::LEFT;
.cursor_direction = CursorDirection::Left;

proc_widget_state.update_query();
self.proc_state.force_update = Some(self.current_widget.widget_id - 1);
Expand Down Expand Up @@ -502,6 +502,11 @@ impl App {
{
proc_widget_state.current_column_index =
proc_widget_state.current_column_index.saturating_sub(1);

debug!(
"Current column index <: {}",
proc_widget_state.current_column_index
);
}
}
BottomWidgetType::ProcSearch => {
Expand All @@ -527,7 +532,7 @@ impl App {
proc_widget_state
.process_search_state
.search_state
.cursor_direction = CursorDirection::LEFT;
.cursor_direction = CursorDirection::Left;
}
}
}
Expand Down Expand Up @@ -562,6 +567,10 @@ impl App {
if proc_widget_state.current_column_index < proc_widget_state.num_columns {
proc_widget_state.current_column_index += 1;
}
debug!(
"Current column index >: {}",
proc_widget_state.current_column_index
);
}
}
BottomWidgetType::ProcSearch => {
Expand All @@ -587,7 +596,7 @@ impl App {
proc_widget_state
.process_search_state
.search_state
.cursor_direction = CursorDirection::RIGHT;
.cursor_direction = CursorDirection::Right;
}
}
}
Expand Down Expand Up @@ -643,7 +652,7 @@ impl App {
proc_widget_state
.process_search_state
.search_state
.cursor_direction = CursorDirection::LEFT;
.cursor_direction = CursorDirection::Left;
}
}
}
Expand Down Expand Up @@ -689,7 +698,7 @@ impl App {
proc_widget_state
.process_search_state
.search_state
.cursor_direction = CursorDirection::RIGHT;
.cursor_direction = CursorDirection::Right;
}
}
}
Expand Down Expand Up @@ -815,7 +824,7 @@ impl App {
proc_widget_state
.process_search_state
.search_state
.cursor_direction = CursorDirection::RIGHT;
.cursor_direction = CursorDirection::Right;

return;
}
Expand Down Expand Up @@ -900,13 +909,13 @@ impl App {
.get_mut_widget_state(self.current_widget.widget_id)
{
match proc_widget_state.process_sorting_type {
processes::ProcessSorting::CPU => {
processes::ProcessSorting::Cpu => {
proc_widget_state.process_sorting_reverse =
!proc_widget_state.process_sorting_reverse
}
_ => {
proc_widget_state.process_sorting_type =
processes::ProcessSorting::CPU;
processes::ProcessSorting::Cpu;
proc_widget_state.process_sorting_reverse = true;
}
}
Expand All @@ -923,13 +932,13 @@ impl App {
.get_mut_widget_state(self.current_widget.widget_id)
{
match proc_widget_state.process_sorting_type {
processes::ProcessSorting::MEM => {
processes::ProcessSorting::Mem => {
proc_widget_state.process_sorting_reverse =
!proc_widget_state.process_sorting_reverse
}
_ => {
proc_widget_state.process_sorting_type =
processes::ProcessSorting::MEM;
processes::ProcessSorting::Mem;
proc_widget_state.process_sorting_reverse = true;
}
}
Expand All @@ -947,13 +956,13 @@ impl App {
// Skip if grouped
if !proc_widget_state.is_grouped {
match proc_widget_state.process_sorting_type {
processes::ProcessSorting::PID => {
processes::ProcessSorting::Pid => {
proc_widget_state.process_sorting_reverse =
!proc_widget_state.process_sorting_reverse
}
_ => {
proc_widget_state.process_sorting_type =
processes::ProcessSorting::PID;
processes::ProcessSorting::Pid;
proc_widget_state.process_sorting_reverse = false;
}
}
Expand Down Expand Up @@ -982,13 +991,13 @@ impl App {
.get_mut_widget_state(self.current_widget.widget_id)
{
match proc_widget_state.process_sorting_type {
processes::ProcessSorting::IDENTIFIER => {
processes::ProcessSorting::Identifier => {
proc_widget_state.process_sorting_reverse =
!proc_widget_state.process_sorting_reverse
}
_ => {
proc_widget_state.process_sorting_type =
processes::ProcessSorting::IDENTIFIER;
processes::ProcessSorting::Identifier;
proc_widget_state.process_sorting_reverse = false;
}
}
Expand All @@ -1010,6 +1019,19 @@ impl App {
'-' => self.zoom_out(),
'=' => self.reset_zoom(),
'e' => self.expand_widget(),
's' => {
if let BottomWidgetType::Proc = self.current_widget.widget_type {
if let Some(proc_widget_state) = self
.proc_state
.get_mut_widget_state(self.current_widget.widget_id)
{
// Open up sorting dialog for that specific proc widget.
// TODO: It might be a decent idea to allow sorting ALL? I dunno.

proc_widget_state.is_sort_open = !proc_widget_state.is_sort_open;
}
}
}
_ => {}
}

Expand Down Expand Up @@ -1413,7 +1435,7 @@ impl App {
.get_mut_widget_state(self.current_widget.widget_id)
{
proc_widget_state.scroll_state.current_scroll_position = 0;
proc_widget_state.scroll_state.scroll_direction = ScrollDirection::UP;
proc_widget_state.scroll_state.scroll_direction = ScrollDirection::Up;
}
}
BottomWidgetType::Temp => {
Expand All @@ -1422,7 +1444,7 @@ impl App {
.get_mut_widget_state(self.current_widget.widget_id)
{
temp_widget_state.scroll_state.current_scroll_position = 0;
temp_widget_state.scroll_state.scroll_direction = ScrollDirection::UP;
temp_widget_state.scroll_state.scroll_direction = ScrollDirection::Up;
}
}
BottomWidgetType::Disk => {
Expand All @@ -1431,7 +1453,7 @@ impl App {
.get_mut_widget_state(self.current_widget.widget_id)
{
disk_widget_state.scroll_state.current_scroll_position = 0;
disk_widget_state.scroll_state.scroll_direction = ScrollDirection::UP;
disk_widget_state.scroll_state.scroll_direction = ScrollDirection::Up;
}
}
BottomWidgetType::CpuLegend => {
Expand All @@ -1440,7 +1462,7 @@ impl App {
.get_mut_widget_state(self.current_widget.widget_id - 1)
{
cpu_widget_state.scroll_state.current_scroll_position = 0;
cpu_widget_state.scroll_state.scroll_direction = ScrollDirection::UP;
cpu_widget_state.scroll_state.scroll_direction = ScrollDirection::Up;
}
}

Expand Down Expand Up @@ -1469,7 +1491,7 @@ impl App {
proc_widget_state.scroll_state.current_scroll_position =
finalized_process_data.len() - 1;
proc_widget_state.scroll_state.scroll_direction =
ScrollDirection::DOWN;
ScrollDirection::Down;
}
}
}
Expand All @@ -1482,7 +1504,7 @@ impl App {
if !self.canvas_data.temp_sensor_data.is_empty() {
temp_widget_state.scroll_state.current_scroll_position =
self.canvas_data.temp_sensor_data.len() - 1;
temp_widget_state.scroll_state.scroll_direction = ScrollDirection::DOWN;
temp_widget_state.scroll_state.scroll_direction = ScrollDirection::Down;
}
}
}
Expand All @@ -1494,7 +1516,7 @@ impl App {
if !self.canvas_data.disk_data.is_empty() {
disk_widget_state.scroll_state.current_scroll_position =
self.canvas_data.disk_data.len() - 1;
disk_widget_state.scroll_state.scroll_direction = ScrollDirection::DOWN;
disk_widget_state.scroll_state.scroll_direction = ScrollDirection::Down;
}
}
}
Expand All @@ -1506,7 +1528,7 @@ impl App {
let cap = self.canvas_data.cpu_data.len();
if cap > 0 {
cpu_widget_state.scroll_state.current_scroll_position = cap - 1;
cpu_widget_state.scroll_state.scroll_direction = ScrollDirection::DOWN;
cpu_widget_state.scroll_state.scroll_direction = ScrollDirection::Down;
}
}
}
Expand Down Expand Up @@ -1563,9 +1585,9 @@ impl App {
}

if num_to_change_by < 0 {
cpu_widget_state.scroll_state.scroll_direction = ScrollDirection::UP;
cpu_widget_state.scroll_state.scroll_direction = ScrollDirection::Up;
} else {
cpu_widget_state.scroll_state.scroll_direction = ScrollDirection::DOWN;
cpu_widget_state.scroll_state.scroll_direction = ScrollDirection::Down;
}
}
}
Expand All @@ -1591,9 +1613,9 @@ impl App {
}

if num_to_change_by < 0 {
proc_widget_state.scroll_state.scroll_direction = ScrollDirection::UP;
proc_widget_state.scroll_state.scroll_direction = ScrollDirection::Up;
} else {
proc_widget_state.scroll_state.scroll_direction = ScrollDirection::DOWN;
proc_widget_state.scroll_state.scroll_direction = ScrollDirection::Down;
}
}
}
Expand All @@ -1615,9 +1637,9 @@ impl App {
}

if num_to_change_by < 0 {
temp_widget_state.scroll_state.scroll_direction = ScrollDirection::UP;
temp_widget_state.scroll_state.scroll_direction = ScrollDirection::Up;
} else {
temp_widget_state.scroll_state.scroll_direction = ScrollDirection::DOWN;
temp_widget_state.scroll_state.scroll_direction = ScrollDirection::Down;
}
}
}
Expand All @@ -1638,9 +1660,9 @@ impl App {
}

if num_to_change_by < 0 {
disk_widget_state.scroll_state.scroll_direction = ScrollDirection::UP;
disk_widget_state.scroll_state.scroll_direction = ScrollDirection::Up;
} else {
disk_widget_state.scroll_state.scroll_direction = ScrollDirection::DOWN;
disk_widget_state.scroll_state.scroll_direction = ScrollDirection::Down;
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/app/data_farmer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub struct DataCollection {
pub network_harvest: network::NetworkHarvest,
pub memory_harvest: mem::MemHarvest,
pub swap_harvest: mem::MemHarvest,
pub cpu_harvest: cpu::CPUHarvest,
pub cpu_harvest: cpu::CpuHarvest,
pub process_harvest: Vec<processes::ProcessHarvest>,
pub disk_harvest: Vec<disks::DiskHarvest>,
pub io_harvest: disks::IOHarvest,
Expand All @@ -67,7 +67,7 @@ impl Default for DataCollection {
network_harvest: network::NetworkHarvest::default(),
memory_harvest: mem::MemHarvest::default(),
swap_harvest: mem::MemHarvest::default(),
cpu_harvest: cpu::CPUHarvest::default(),
cpu_harvest: cpu::CpuHarvest::default(),
process_harvest: Vec::default(),
disk_harvest: Vec::default(),
io_harvest: disks::IOHarvest::default(),
Expand All @@ -84,7 +84,7 @@ impl DataCollection {
self.network_harvest = network::NetworkHarvest::default();
self.memory_harvest = mem::MemHarvest::default();
self.swap_harvest = mem::MemHarvest::default();
self.cpu_harvest = cpu::CPUHarvest::default();
self.cpu_harvest = cpu::CpuHarvest::default();
self.process_harvest = Vec::default();
self.disk_harvest = Vec::default();
self.io_harvest = disks::IOHarvest::default();
Expand Down Expand Up @@ -205,7 +205,7 @@ impl DataCollection {
self.network_harvest = network.clone();
}

fn eat_cpu(&mut self, cpu: &[cpu::CPUData], new_entry: &mut TimedData) {
fn eat_cpu(&mut self, cpu: &[cpu::CpuData], new_entry: &mut TimedData) {
// Note this only pre-calculates the data points - the names will be
// within the local copy of cpu_harvest. Since it's all sequential
// it probably doesn't matter anyways.
Expand Down
2 changes: 1 addition & 1 deletion src/app/data_harvester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub mod temperature;
#[derive(Clone, Debug)]
pub struct Data {
pub last_collection_time: Instant,
pub cpu: Option<cpu::CPUHarvest>,
pub cpu: Option<cpu::CpuHarvest>,
pub memory: Option<mem::MemHarvest>,
pub swap: Option<mem::MemHarvest>,
pub temperature_sensors: Option<Vec<temperature::TempHarvest>>,
Expand Down
10 changes: 5 additions & 5 deletions src/app/data_harvester/cpu.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
use sysinfo::{ProcessorExt, System, SystemExt};

#[derive(Default, Debug, Clone)]
pub struct CPUData {
pub struct CpuData {
pub cpu_name: String,
pub cpu_usage: f64,
}

pub type CPUHarvest = Vec<CPUData>;
pub type CpuHarvest = Vec<CpuData>;

pub fn get_cpu_data_list(sys: &System, show_average_cpu: bool) -> CPUHarvest {
pub fn get_cpu_data_list(sys: &System, show_average_cpu: bool) -> CpuHarvest {
let cpu_data = sys.get_processors();
let avg_cpu_usage = sys.get_global_processor_info().get_cpu_usage();
let mut cpu_vec = vec![];

if show_average_cpu {
cpu_vec.push(CPUData {
cpu_vec.push(CpuData {
cpu_name: "AVG".to_string(),
cpu_usage: avg_cpu_usage as f64,
});
}

for (itx, cpu) in cpu_data.iter().enumerate() {
cpu_vec.push(CPUData {
cpu_vec.push(CpuData {
cpu_name: format!("CPU{}", itx),
cpu_usage: f64::from(cpu.get_cpu_usage()),
});
Expand Down
15 changes: 10 additions & 5 deletions src/app/data_harvester/processes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,20 @@ use sysinfo::{ProcessExt, ProcessorExt, System, SystemExt};

#[derive(Clone)]
pub enum ProcessSorting {
CPU,
MEM,
PID,
IDENTIFIER,
Cpu,
Mem,
Pid,
Identifier,
Read,
Write,
TotalRead,
TotalWrite,
State, // This one is just alphabetical
}

impl Default for ProcessSorting {
fn default() -> Self {
ProcessSorting::CPU
ProcessSorting::Cpu
}
}

Expand Down
Loading