From 72a3de98c28de5ca6d4509410b424616243248d0 Mon Sep 17 00:00:00 2001
From: ClementTsang <clementjhtsang@gmail.com>
Date: Fri, 4 Oct 2019 23:22:16 -0400
Subject: [PATCH] Added arrows to indicate process sorting direction

---
 Cargo.toml    |  2 +-
 TODO.md       |  4 ----
 src/canvas.rs | 48 +++++++++++++++++++++++++++++++++++-------------
 3 files changed, 36 insertions(+), 18 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml
index 6d3ac010..38ef6168 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -30,7 +30,7 @@ tokio = "0.2.0-alpha.4"
 winapi = "0.3.8"
 
 [dependencies.tui-temp-fork]
-#git = "https://github.com/ClementTsang/tui-rs"
+git = "https://github.com/ClementTsang/tui-rs"
 #path = "../tui-rs"
 version = "0.6.4"
 default-features = false
diff --git a/TODO.md b/TODO.md
index 993170f6..207d9db4 100644
--- a/TODO.md
+++ b/TODO.md
@@ -4,8 +4,6 @@ Note this will probably migrate to GitHub's native Issues; this was mostly for p
 
 - Rebalance cpu usage in process by using current value (it's currently just summing to 100%)
 
-- Scrolling support for temp/disk
-
 - Travis
 
 - Refactoring! Please.
@@ -18,8 +16,6 @@ Note this will probably migrate to GitHub's native Issues; this was mostly for p
 
 - Mouse + key events conflict? Make it so that some events don't clog up the loop if they are not valid keys!
 
-- Header should be clear on current sorting direction!
-
 - It would be maybe a good idea to see if we can run the process calculation across ALL cpus...? Might be more accurate.
 
 - ~~Add custom error because it's really messy~~ Done, but need to implement across rest of app!
diff --git a/src/canvas.rs b/src/canvas.rs
index 3d76535d..c15782ae 100644
--- a/src/canvas.rs
+++ b/src/canvas.rs
@@ -358,19 +358,41 @@ pub fn draw_data<B : backend::Backend>(terminal : &mut Terminal<B>, app_state :
 				)
 			});
 
-			Table::new(["PID", "Name", "CPU%", "Mem%"].iter(), process_rows)
-				.block(
-					Block::default()
-						.title("Processes")
-						.borders(Borders::ALL)
-						.border_style(match app_state.current_application_position {
-							app::ApplicationPosition::PROCESS => highlighted_border_style,
-							_ => border_style,
-						}),
-				)
-				.header_style(Style::default().fg(Color::LightBlue))
-				.widths(&[(width * 0.2) as u16, (width * 0.35) as u16, (width * 0.2) as u16, (width * 0.2) as u16])
-				.render(&mut f, bottom_chunks[1]);
+			{
+				use app::data_collection::processes::ProcessSorting;
+				let mut pid = "PID".to_string();
+				let mut name = "Name".to_string();
+				let mut cpu = "CPU%".to_string();
+				let mut mem = "Mem%".to_string();
+
+				let direction_val = if app_state.process_sorting_reverse {
+					" ⯆".to_string()
+				}
+				else {
+					" ⯅".to_string()
+				};
+
+				match app_state.process_sorting_type {
+					ProcessSorting::CPU => cpu += &direction_val,
+					ProcessSorting::MEM => mem += &direction_val,
+					ProcessSorting::PID => pid += &direction_val,
+					ProcessSorting::NAME => name += &direction_val,
+				};
+
+				Table::new([pid, name, cpu, mem].iter(), process_rows)
+					.block(
+						Block::default()
+							.title("Processes")
+							.borders(Borders::ALL)
+							.border_style(match app_state.current_application_position {
+								app::ApplicationPosition::PROCESS => highlighted_border_style,
+								_ => border_style,
+							}),
+					)
+					.header_style(Style::default().fg(Color::LightBlue))
+					.widths(&[(width * 0.2) as u16, (width * 0.35) as u16, (width * 0.2) as u16, (width * 0.2) as u16])
+					.render(&mut f, bottom_chunks[1]);
+			}
 		}
 	})?;