diff options
author | Denys Séguret <cano.petrole@gmail.com> | 2023-05-18 18:38:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-18 18:38:26 +0200 |
commit | 7d341561d8d528d8bd50d500c4cbea88c596cf71 (patch) | |
tree | 18d50075a968678d8f2caa9bf35aadde216107de | |
parent | dbb8e873cc09fc26176a5e8c7dd21224fecfdcdf (diff) |
Define disk space availability colors in skin (#707)
Allow definition of colors for the "good" to "bad" scale used to show cluttering of filesystems.
Fix #705
-rw-r--r-- | resources/default-conf/dark-blue-skin.hjson | 11 | ||||
-rw-r--r-- | resources/default-conf/dark-gruvbox.hjson | 10 | ||||
-rw-r--r-- | resources/default-conf/dark-orange-skin.hjson | 10 | ||||
-rw-r--r-- | resources/default-conf/solarized-dark.hjson | 10 | ||||
-rw-r--r-- | resources/default-conf/solarized-light.hjson | 10 | ||||
-rw-r--r-- | resources/default-conf/white-skin.hjson | 10 | ||||
-rw-r--r-- | src/filesystems/filesystems_state.rs | 2 | ||||
-rw-r--r-- | src/filesystems/mod.rs | 23 | ||||
-rw-r--r-- | src/filesystems/mount_space_display.rs | 3 | ||||
-rw-r--r-- | src/skin/skin_entry.rs | 20 | ||||
-rw-r--r-- | src/skin/style_map.rs | 28 | ||||
-rw-r--r-- | website/docs/img/20230517-fs.png | bin | 0 -> 53333 bytes | |||
-rw-r--r-- | website/docs/skins.md | 33 |
13 files changed, 137 insertions, 33 deletions
diff --git a/resources/default-conf/dark-blue-skin.hjson b/resources/default-conf/dark-blue-skin.hjson index 7e1507d..0ceb2b9 100644 --- a/resources/default-conf/dark-blue-skin.hjson +++ b/resources/default-conf/dark-blue-skin.hjson @@ -87,7 +87,16 @@ skin: { hex_non_ascii: ansi(167) None staging_area_title: gray(22) gray(2) / gray(20) gray(3) mode_command_mark: gray(5) ansi(204) bold - + good_to_bad_0: ansi(28) + good_to_bad_1: ansi(29) + good_to_bad_2: ansi(29) + good_to_bad_3: ansi(29) + good_to_bad_4: ansi(29) + good_to_bad_5: ansi(100) + good_to_bad_6: ansi(136) + good_to_bad_7: ansi(172) + good_to_bad_8: ansi(166) + good_to_bad_9: ansi(196) } ############################################################### diff --git a/resources/default-conf/dark-gruvbox.hjson b/resources/default-conf/dark-gruvbox.hjson index f5c2014..2804729 100644 --- a/resources/default-conf/dark-gruvbox.hjson +++ b/resources/default-conf/dark-gruvbox.hjson @@ -74,4 +74,14 @@ skin: { hex_non_ascii: rgb(214, 93, 14) None staging_area_title: rgb(235, 219, 178) rgb(40, 40, 40) / rgb(189, 174, 147) rgb(40, 40, 40) mode_command_mark: gray(5) ansi(204) Bold + good_to_bad_0: ansi(28) + good_to_bad_1: ansi(29) + good_to_bad_2: ansi(29) + good_to_bad_3: ansi(29) + good_to_bad_4: ansi(29) + good_to_bad_5: ansi(100) + good_to_bad_6: ansi(136) + good_to_bad_7: ansi(172) + good_to_bad_8: ansi(166) + good_to_bad_9: ansi(196) } diff --git a/resources/default-conf/dark-orange-skin.hjson b/resources/default-conf/dark-orange-skin.hjson index 2fe7a28..9fb0eee 100644 --- a/resources/default-conf/dark-orange-skin.hjson +++ b/resources/default-conf/dark-orange-skin.hjson @@ -81,6 +81,16 @@ skin: { hex_ascii_whitespace: ansi(143) None hex_ascii_other: ansi(215) None hex_non_ascii: ansi(167) None + good_to_bad_0: ansi(28) + good_to_bad_1: ansi(29) + good_to_bad_2: ansi(29) + good_to_bad_3: ansi(29) + good_to_bad_4: ansi(29) + good_to_bad_5: ansi(100) + good_to_bad_6: ansi(136) + good_to_bad_7: ansi(172) + good_to_bad_8: ansi(166) + good_to_bad_9: ansi(196) } diff --git a/resources/default-conf/solarized-dark.hjson b/resources/default-conf/solarized-dark.hjson index ded8b68..305469d 100644 --- a/resources/default-conf/solarized-dark.hjson +++ b/resources/default-conf/solarized-dark.hjson @@ -53,4 +53,14 @@ skin: { help_table_border: "none none" // default default preview_title: "gray(20) rgb(0, 43, 54)" staging_area_title: "gray(22) rgb(0, 43, 54)" + good_to_bad_0: ansi(28) // green + good_to_bad_1: ansi(29) + good_to_bad_2: ansi(29) + good_to_bad_3: ansi(29) + good_to_bad_4: ansi(29) + good_to_bad_5: ansi(100) + good_to_bad_6: ansi(136) + good_to_bad_7: ansi(172) + good_to_bad_8: ansi(166) + good_to_bad_9: ansi(196) // red } diff --git a/resources/default-conf/solarized-light.hjson b/resources/default-conf/solarized-light.hjson index ae3b53c..d83f3d5 100644 --- a/resources/default-conf/solarized-light.hjson +++ b/resources/default-conf/solarized-light.hjson @@ -100,4 +100,14 @@ skin: { preview_line_number: "rgb(147, 161, 161) rgb(238, 232, 213)" preview_match: "None ansi(29)" staging_area_title: "gray(22) rgb(253, 246, 227)" + good_to_bad_0: ansi(28) + good_to_bad_1: ansi(29) + good_to_bad_2: ansi(29) + good_to_bad_3: ansi(29) + good_to_bad_4: ansi(29) + good_to_bad_5: ansi(100) + good_to_bad_6: ansi(136) + good_to_bad_7: ansi(172) + good_to_bad_8: ansi(166) + good_to_bad_9: ansi(196) } diff --git a/resources/default-conf/white-skin.hjson b/resources/default-conf/white-skin.hjson index 0a6ddea..1e8d9b9 100644 --- a/resources/default-conf/white-skin.hjson +++ b/resources/default-conf/white-skin.hjson @@ -70,4 +70,14 @@ skin: { hex_non_ascii: ansi(167) None staging_area_title: gray(8) None / gray(13) None mode_command_mark: gray(15) ansi(204) Bold + good_to_bad_0: ansi(28) + good_to_bad_1: ansi(29) + good_to_bad_2: ansi(29) + good_to_bad_3: ansi(29) + good_to_bad_4: ansi(29) + good_to_bad_5: ansi(100) + good_to_bad_6: ansi(136) + good_to_bad_7: ansi(172) + good_to_bad_8: ansi(166) + good_to_bad_9: ansi(196) } diff --git a/src/filesystems/filesystems_state.rs b/src/filesystems/filesystems_state.rs index 0d7d555..41daadd 100644 --- a/src/filesystems/filesystems_state.rs +++ b/src/filesystems/filesystems_state.rs @@ -408,7 +408,7 @@ impl PanelState for FilesystemState { } // size, used, free if let Some(stats) = mount.stats().filter(|s| s.size() > 0) { - let share_color = super::share_color(stats.use_share()); + let share_color = styles.good_to_bad_color(stats.use_share()); // used if e_use { cw.queue_g_string(txt_style, format!("{:>4}", file_size::fit_4(stats.used())))?; diff --git a/src/filesystems/mod.rs b/src/filesystems/mod.rs index 0af4654..9708451 100644 --- a/src/filesystems/mod.rs +++ b/src/filesystems/mod.rs @@ -11,7 +11,6 @@ pub use { }; use { - crokey::crossterm::style::Color, once_cell::sync::Lazy, std::sync::Mutex, }; @@ -23,25 +22,3 @@ pub fn clear_cache() { mount_list.clear_cache(); } -static SHARE_COLORS: &[Color] = &[ - Color::AnsiValue(28), - Color::AnsiValue(29), - Color::AnsiValue(29), - Color::AnsiValue(29), - Color::AnsiValue(29), - Color::AnsiValue(100), - Color::AnsiValue(136), - Color::AnsiValue(172), - Color::AnsiValue(166), - Color::AnsiValue(196), -]; - -pub fn share_color(share: f64) -> Color { - debug_assert!((0.0..=1.0).contains(&share)); - let idx = (share * SHARE_COLORS.len() as f64) as usize; - if idx >= SHARE_COLORS.len() { - SHARE_COLORS[SHARE_COLORS.len() - 1] - } else { - SHARE_COLORS[idx] - } -} diff --git a/src/filesystems/mount_space_display.rs b/src/filesystems/mount_space_display.rs index 7563dc8..611de1e 100644 --- a/src/filesystems/mount_space_display.rs +++ b/src/filesystems/mount_space_display.rs @@ -2,7 +2,6 @@ use { crate::{ display::cond_bg, errors::ProgramError, - filesystems::share_color, skin::StyleMap, }, crokey::crossterm::{ @@ -60,7 +59,7 @@ impl<'m, 's> MountSpaceDisplay<'m, 's> { let mut e_bar = false; let w_percent = 4; let mut rem = self.available_width - w_percent; - let share_color = share_color(s.use_share()); + let share_color = self.skin.good_to_bad_color(s.use_share()); if rem > 1 { // left margin for readability rem -= 1; diff --git a/src/skin/skin_entry.rs b/src/skin/skin_entry.rs index 69b4937..8107c6d 100644 --- a/src/skin/skin_entry.rs +++ b/src/skin/skin_entry.rs @@ -90,21 +90,29 @@ fn parse_compound_style(s: &str) -> Result<CompoundStyle, InvalidSkinError> { ^ \s* (?P<fg>\w+(\([\d,\s]+\))?) - \s+ - (?P<bg>\w+(\([\d,\s]+\))?) - (?P<attributes>.*) + (?: + \s+ + (?P<bg>\w+(\([\d,\s]+\))?) + (?P<attributes>.*) + )? \s* $ " ); if let Some(c) = parts_rex.captures(&s) { let fg_color = colors::parse(c.name("fg").unwrap().as_str())?; - let bg_color = colors::parse(c.name("bg").unwrap().as_str())?; - let attrs = parse_attributes(c.name("attributes").unwrap().as_str())?; + let bg_color = match c.name("bg") { + Some(s) => colors::parse(s.as_str())?, + None => None, + }; + let attrs = match c.name("attributes") { + Some(s) => Attributes::from(parse_attributes(s.as_str())?.as_slice()), + None => Attributes::default(), + }; Ok(CompoundStyle::new( fg_color, bg_color, - Attributes::from(attrs.as_slice()), + attrs, )) } else { Err(InvalidSkinError::InvalidStyle { diff --git a/src/skin/style_map.rs b/src/skin/style_map.rs index 23f7970..20bb2ca 100644 --- a/src/skin/style_map.rs +++ b/src/skin/style_map.rs @@ -130,6 +130,24 @@ impl StyleMap { } Ok(()) } + pub fn good_to_bad_color(&self, value: f64) -> Color { + debug_assert!((0.0..=1.0).contains(&value)); + const N: usize = 10; + let idx = (value * N as f64) as usize; + let cs = match idx { + 0 => &self.good_to_bad_0, + 1 => &self.good_to_bad_1, + 2 => &self.good_to_bad_2, + 3 => &self.good_to_bad_3, + 4 => &self.good_to_bad_4, + 5 => &self.good_to_bad_5, + 6 => &self.good_to_bad_6, + 7 => &self.good_to_bad_7, + 8 => &self.good_to_bad_8, + _ => &self.good_to_bad_9, + }; + cs.object_style.foreground_color.unwrap_or(Color::Blue) + } } // Default styles defined as @@ -204,6 +222,16 @@ StyleMap! { hex_non_ascii: ansi(167), None, [] staging_area_title: gray(22), gray(2), [] / gray(20), gray(3), [] mode_command_mark: gray(5), ansi(204), [Bold] + good_to_bad_0: ansi(28), None, [] + good_to_bad_1: ansi(29), None, [] + good_to_bad_2: ansi(29), None, [] + good_to_bad_3: ansi(29), None, [] + good_to_bad_4: ansi(29), None, [] + good_to_bad_5: ansi(100), None, [] + good_to_bad_6: ansi(136), None, [] + good_to_bad_7: ansi(172), None, [] + good_to_bad_8: ansi(166), None, [] + good_to_bad_9: ansi(196), None, [] } impl fmt::Debug for StyleMap { diff --git a/website/docs/img/20230517-fs.png b/website/docs/img/20230517-fs.png Binary files differnew file mode 100644 index 0000000..42a61dd --- /dev/null +++ b/website/docs/img/20230517-fs.png diff --git a/website/docs/skins.md b/website/docs/skins.md index 604d7f2..c9c0054 100644 --- a/website/docs/skins.md +++ b/website/docs/skins.md @@ -82,6 +82,16 @@ skin: { hex_non_ascii: ansi(167) None staging_area_title: gray(22) None / gray(20) None mode_command_mark: gray(5) ansi(204) Bold + good_to_bad_0: ansi(28) + good_to_bad_1: ansi(29) + good_to_bad_2: ansi(29) + good_to_bad_3: ansi(29) + good_to_bad_4: ansi(29) + good_to_bad_5: ansi(100) + good_to_bad_6: ansi(136) + good_to_bad_7: ansi(172) + good_to_bad_8: ansi(166) + good_to_bad_9: ansi(196) } ``` ```toml @@ -149,6 +159,16 @@ hex_ascii_other = "ansi(215) None" hex_non_ascii = "ansi(167) None" staging_area_title = "gray(22) None / gray(20) None" mode_command_mark = "gray(5) ansi(204) Bold" +good_to_bad_0 = "ansi(28)" +good_to_bad_1 = "ansi(29)" +good_to_bad_2 = "ansi(29)" +good_to_bad_3 = "ansi(29)" +good_to_bad_4 = "ansi(29)" +good_to_bad_5 = "ansi(100)" +good_to_bad_6 = "ansi(136)" +good_to_bad_7 = "ansi(172)" +good_to_bad_8 = "ansi(166)" +good_to_bad_9 = "ansi(196)" ``` This would look like this: @@ -211,6 +231,19 @@ default = "gray(23) none / gray(20) none" ![transparent](img/20200529-transparent-broot.png) +## Good to Bad scale + +The `good_to_bad_0` to `good_to_bad_9` entries define a scale used to express the cluttering of filesystems: + +![fs](img/20230517-fs.png) + +Only the foreground color is used, so you may use the shortened definition, eg + +```hjson +good_to_bad_9: rgb(200, 15, 14) +``` + +There's no obligation to really use a green to red scale. You may even use only one color if you like. # Contribute your own skin |