summaryrefslogtreecommitdiffstats
path: root/src/utils/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/mod.rs')
-rw-r--r--src/utils/mod.rs20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/utils/mod.rs b/src/utils/mod.rs
index fa26dcf..699f8a0 100644
--- a/src/utils/mod.rs
+++ b/src/utils/mod.rs
@@ -1,5 +1,3 @@
-#[cfg(not(target_os = "windows"))]
-pub(crate) mod termbg;
mod tiktoken;
use self::tiktoken::cl100k_base;
@@ -45,3 +43,21 @@ pub fn split_text(text: &str) -> Result<Vec<String>, anyhow::Error> {
let data: Result<Vec<String>, _> = tokens.into_iter().map(|v| bpe.decode(&[v])).collect();
data
}
+
+pub fn light_theme_from_colorfgbg(colorfgbg: &str) -> Option<bool> {
+ let parts: Vec<_> = colorfgbg.split(';').collect();
+ let bg = match parts.len() {
+ 2 => &parts[1],
+ 3 => &parts[2],
+ _ => {
+ return None;
+ }
+ };
+ let bg = bg.parse::<u8>().ok()?;
+ let (r, g, b) = ansi_colours::rgb_from_ansi256(bg);
+
+ let v = 0.2126 * r as f32 + 0.7152 * g as f32 + 0.0722 * b as f32;
+
+ let light = v > 128.0;
+ Some(light)
+}