aboutsummaryrefslogtreecommitdiffstats
path: root/src/common/utils
diff options
context:
space:
mode:
authora-kenji <aks.kenji@protonmail.com>2021-05-03 18:26:45 +0200
committerGitHub <noreply@github.com>2021-05-03 18:26:45 +0200
commit2792a9009bfb91345dce9eb0562f4c6268ef33c4 (patch)
treeb451a9468d1afd83d04bfd83ea0ed7b5218eee8e /src/common/utils
parentMerge pull request #441 from a-kenji/fix-default-keybinds (diff)
parentMake Xrdb Loading More Forgiving (diff)
downloadsl0ppij-2792a9009bfb91345dce9eb0562f4c6268ef33c4.tar.gz
sl0ppij-2792a9009bfb91345dce9eb0562f4c6268ef33c4.tar.xz
sl0ppij-2792a9009bfb91345dce9eb0562f4c6268ef33c4.zip
Merge pull request #437 from a-kenji/xrdb-loading-fix
Make Xrdb Loading More Forgiving
Diffstat (limited to 'src/common/utils')
-rw-r--r--src/common/utils/shared.rs29
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;