diff options
| author | a-kenji <aks.kenji@protonmail.com> | 2021-05-02 19:19:52 +0200 |
|---|---|---|
| committer | a-kenji <aks.kenji@protonmail.com> | 2021-05-03 18:10:02 +0200 |
| commit | f97c3ae3a10e34b650c3993f7b29dea8407b804f (patch) | |
| tree | 3ef508d35f3b7ee0a5c808edbefb0a7a152a2fea /src/common/utils | |
| parent | docs(changelog): Add theme support through xrdb #239 (diff) | |
| download | sl0ppij-f97c3ae3a10e34b650c3993f7b29dea8407b804f.tar.gz sl0ppij-f97c3ae3a10e34b650c3993f7b29dea8407b804f.tar.xz sl0ppij-f97c3ae3a10e34b650c3993f7b29dea8407b804f.zip | |
Make Xrdb Loading More Forgiving
Attempt at fixing #434.
The `hex_to_rgb` function propagates the Option now.
If it is None, it tries to load the default Palette now.
Diffstat (limited to 'src/common/utils')
| -rw-r--r-- | src/common/utils/shared.rs | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/src/common/utils/shared.rs b/src/common/utils/shared.rs index 3f336f7b..c705ed0d 100644 --- a/src/common/utils/shared.rs +++ b/src/common/utils/shared.rs @@ -5,7 +5,7 @@ use std::{iter, str::from_utf8}; use strip_ansi_escapes::strip; use colors_transform::{Color, Rgb}; -use zellij_tile::data::Theme; +use zellij_tile::data::{Palette, PaletteSource, Theme}; fn ansi_len(s: &str) -> usize { from_utf8(&strip(s.as_bytes()).unwrap()) @@ -43,14 +43,31 @@ pub mod colors { pub const BLACK: (u8, u8, u8) = (0, 0, 0); } -pub fn hex_to_rgb(hex: &Option<String>) -> (u8, u8, u8) { - let c = hex.clone(); - let imm_str = &c.unwrap(); - let hex_str: &str = &imm_str; - let rgb = Rgb::from_hex_str(hex_str).unwrap().as_tuple(); +pub fn hex_to_rgb(hex: &str) -> (u8, u8, u8) { + let rgb = Rgb::from_hex_str(hex) + .expect("The passed argument must be a valid hex color") + .as_tuple(); (rgb.0 as u8, rgb.1 as u8, rgb.2 as u8) } +pub fn default_palette() -> Palette { + Palette { + source: PaletteSource::Default, + theme: Theme::Dark, + fg: colors::BRIGHT_GRAY, + bg: colors::GRAY, + black: colors::BLACK, + red: colors::RED, + green: colors::GREEN, + yellow: colors::GRAY, + blue: colors::GRAY, + magenta: colors::GRAY, + cyan: colors::GRAY, + white: colors::WHITE, + orange: colors::ORANGE, + } +} + // Dark magic pub fn detect_theme(bg: (u8, u8, u8)) -> Theme { let (r, g, b) = bg; |
