summaryrefslogtreecommitdiffstats
path: root/src/app
diff options
context:
space:
mode:
authorClement Tsang <34804052+ClementTsang@users.noreply.github.com>2021-02-15 14:12:43 -0500
committerGitHub <noreply@github.com>2021-02-15 14:12:43 -0500
commitfb7b1226fd610b53d1ba06e2c3d55f0100ebdb2f (patch)
tree408d75b599276271d14da889b6684fcad31cd162 /src/app
parentf2e6b9232d3bc741cac2acdf494fd0919fb414a9 (diff)
feature: add nord and nord-light colours (#406)
Adds colour schemes for Nord, along with a light variant.
Diffstat (limited to 'src/app')
-rw-r--r--src/app/layout_manager.rs22
-rw-r--r--src/app/process_killer.rs6
-rw-r--r--src/app/query.rs51
3 files changed, 43 insertions, 36 deletions
diff --git a/src/app/layout_manager.rs b/src/app/layout_manager.rs
index 05e73822..d4b9272d 100644
--- a/src/app/layout_manager.rs
+++ b/src/app/layout_manager.rs
@@ -12,20 +12,24 @@ pub struct BottomLayout {
pub total_row_height_ratio: u32,
}
-type WidgetMappings = (u32, BTreeMap<(u32, u32), u64>);
-type ColumnRowMappings = (u32, BTreeMap<(u32, u32), WidgetMappings>);
-type ColumnMappings = (u32, BTreeMap<(u32, u32), ColumnRowMappings>);
+// Represents a start and end coordinate in some dimension.
+type LineSegment = (u32, u32);
+
+type WidgetMappings = (u32, BTreeMap<LineSegment, u64>);
+type ColumnRowMappings = (u32, BTreeMap<LineSegment, WidgetMappings>);
+type ColumnMappings = (u32, BTreeMap<LineSegment, ColumnRowMappings>);
impl BottomLayout {
pub fn get_movement_mappings(&mut self) {
- fn is_intersecting(a: (u32, u32), b: (u32, u32)) -> bool {
+ #[allow(clippy::suspicious_operation_groupings)] // Have to enable this, clippy really doesn't like me doing this with tuples...
+ fn is_intersecting(a: LineSegment, b: LineSegment) -> bool {
a.0 >= b.0 && a.1 <= b.1
|| a.1 >= b.1 && a.0 <= b.0
|| a.0 <= b.0 && a.1 >= b.0
|| a.0 >= b.0 && a.0 < b.1 && a.1 >= b.1
}
- fn get_distance(target: (u32, u32), candidate: (u32, u32)) -> u32 {
+ fn get_distance(target: LineSegment, candidate: LineSegment) -> u32 {
if candidate.0 < target.0 {
candidate.1 - target.0
} else if candidate.1 < target.1 {
@@ -38,20 +42,20 @@ impl BottomLayout {
// Now we need to create the correct mapping for moving from a specific
// widget to another
- let mut layout_mapping: BTreeMap<(u32, u32), ColumnMappings> = BTreeMap::new();
+ let mut layout_mapping: BTreeMap<LineSegment, ColumnMappings> = BTreeMap::new();
let mut total_height = 0;
for row in &self.rows {
let mut row_width = 0;
- let mut row_mapping: BTreeMap<(u32, u32), ColumnRowMappings> = BTreeMap::new();
+ let mut row_mapping: BTreeMap<LineSegment, ColumnRowMappings> = BTreeMap::new();
let mut is_valid_row = false;
for col in &row.children {
let mut col_row_height = 0;
- let mut col_mapping: BTreeMap<(u32, u32), WidgetMappings> = BTreeMap::new();
+ let mut col_mapping: BTreeMap<LineSegment, WidgetMappings> = BTreeMap::new();
let mut is_valid_col = false;
for col_row in &col.children {
let mut widget_width = 0;
- let mut col_row_mapping: BTreeMap<(u32, u32), u64> = BTreeMap::new();
+ let mut col_row_mapping: BTreeMap<LineSegment, u64> = BTreeMap::new();
let mut is_valid_col_row = false;
for widget in &col_row.children {
match widget.widget_type {
diff --git a/src/app/process_killer.rs b/src/app/process_killer.rs
index 179965fb..9f38bc5d 100644
--- a/src/app/process_killer.rs
+++ b/src/app/process_killer.rs
@@ -27,7 +27,11 @@ impl Process {
}
fn kill(self) -> Result<(), String> {
- unsafe { TerminateProcess(self.0, 1) };
+ let result = unsafe { TerminateProcess(self.0, 1) };
+ if result == 0 {
+ return Err("Failed to kill process".to_string());
+ }
+
Ok(())
}
}
diff --git a/src/app/query.rs b/src/app/query.rs
index c61c5dad..79f61e73 100644
--- a/src/app/query.rs
+++ b/src/app/query.rs
@@ -625,34 +625,33 @@ impl Prefix {
is_ignoring_case,
is_searching_with_regex,
);
- } else if let Some((prefix_type, query_content)) = &mut self.regex_prefix {
- if let StringQuery::Value(regex_string) = query_content {
- match prefix_type {
- PrefixType::Pid | PrefixType::Name | PrefixType::State => {
- let escaped_regex: String;
- let final_regex_string = &format!(
- "{}{}{}{}",
- if is_searching_whole_word { "^" } else { "" },
- if is_ignoring_case { "(?i)" } else { "" },
- if !is_searching_with_regex {
- escaped_regex = regex::escape(regex_string);
- &escaped_regex
- } else {
- regex_string
- },
- if is_searching_whole_word { "$" } else { "" },
- );
-
- let taken_pwc = self.regex_prefix.take();
- if let Some((taken_pt, _)) = taken_pwc {
- self.regex_prefix = Some((
- taken_pt,
- StringQuery::Regex(regex::Regex::new(final_regex_string)?),
- ));
- }
+ } else if let Some((prefix_type, StringQuery::Value(regex_string))) = &mut self.regex_prefix
+ {
+ match prefix_type {
+ PrefixType::Pid | PrefixType::Name | PrefixType::State => {
+ let escaped_regex: String;
+ let final_regex_string = &format!(
+ "{}{}{}{}",
+ if is_searching_whole_word { "^" } else { "" },
+ if is_ignoring_case { "(?i)" } else { "" },
+ if !is_searching_with_regex {
+ escaped_regex = regex::escape(regex_string);
+ &escaped_regex
+ } else {
+ regex_string
+ },
+ if is_searching_whole_word { "$" } else { "" },
+ );
+
+ let taken_pwc = self.regex_prefix.take();
+ if let Some((taken_pt, _)) = taken_pwc {
+ self.regex_prefix = Some((
+ taken_pt,
+ StringQuery::Regex(regex::Regex::new(final_regex_string)?),
+ ));
}
- _ => {}
}
+ _ => {}
}
}