diff options
author | Canop <cano.petrole@gmail.com> | 2022-07-04 15:47:20 +0200 |
---|---|---|
committer | Canop <cano.petrole@gmail.com> | 2022-07-04 15:47:20 +0200 |
commit | c688a083b46628f1a9c7a23d1765016177514be4 (patch) | |
tree | 6756a98706d339e60bf8a958d7b02d7b2713e3d9 /src/display | |
parent | 8e2cacc24bfa393269ec77ad512752b77d044e4b (diff) |
conf files can import other conf files
A condition on terminal's light can be set
Diffstat (limited to 'src/display')
-rw-r--r-- | src/display/luma.rs | 52 | ||||
-rw-r--r-- | src/display/mod.rs | 8 |
2 files changed, 57 insertions, 3 deletions
diff --git a/src/display/luma.rs b/src/display/luma.rs new file mode 100644 index 0000000..27bf877 --- /dev/null +++ b/src/display/luma.rs @@ -0,0 +1,52 @@ +pub use { + once_cell::sync::Lazy, + serde::Deserialize, +}; + +#[derive(Debug, Clone, Copy, Deserialize, PartialEq)] +#[serde(rename_all = "lowercase")] +pub enum Luma { + Light, + Unknown, + Dark, +} + +/// Return the light of the terminal background, which is a value +/// between 0 (black) and 1 (white). +pub fn luma() -> &'static Result<f32, terminal_light::TlError> { + static LUMA: Lazy<Result<f32, terminal_light::TlError>> = Lazy::new(|| { + let luma = time!(Debug, terminal_light::luma()); + info!("terminal's luma: {:?}", &luma); + luma + }); + &*LUMA +} + +impl Luma { + pub fn read() -> Self { + match luma() { + Ok(luma) if *luma > 0.6 => Self::Light, + Ok(_) => Self::Dark, + _ => Self::Unknown, + } + } +} + +#[derive(Clone, Debug, Deserialize)] +#[serde(untagged)] +pub enum LumaCondition { + Simple(Luma), + Array(Vec<Luma>), +} + +impl LumaCondition { + pub fn is_verified(&self) -> bool { + self.includes(Luma::read()) + } + pub fn includes(&self, other: Luma) -> bool { + match self { + Self::Simple(luma) => other == *luma, + Self::Array(arr) => arr.contains(&other), + } + } +} diff --git a/src/display/mod.rs b/src/display/mod.rs index 702aa90..a9eceff 100644 --- a/src/display/mod.rs +++ b/src/display/mod.rs @@ -22,15 +22,16 @@ macro_rules! cond_bg { } mod areas; +mod cell_size; mod col; mod displayable_tree; -mod git_status_display; pub mod flags_display; -pub mod status_line; +mod git_status_display; +mod luma; mod matched_string; mod num_format; mod screen; -mod cell_size; +pub mod status_line; #[cfg(not(any(target_family="windows",target_os="android")))] mod permissions; @@ -41,6 +42,7 @@ pub use { cond_bg, displayable_tree::DisplayableTree, git_status_display::GitStatusDisplay, + luma::*, matched_string::MatchedString, screen::Screen, cell_size::*, |