diff --git a/Cargo.lock b/Cargo.lock index c60f4f9..ef850ce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2859,7 +2859,7 @@ dependencies = [ [[package]] name = "zellij-datetime" -version = "0.17.1" +version = "0.18.0" dependencies = [ "ansi_term", "chrono-wasi", @@ -2871,9 +2871,9 @@ dependencies = [ [[package]] name = "zellij-tile" -version = "0.38.0" +version = "0.38.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "077ea8d82d4d6f9dc24b672999004c32a72a5350d50f0f37397594f3d168bca1" +checksum = "68b51700a828e8a2bf2eb82d62b260932576fa1882494c2af8395f5f4794a15f" dependencies = [ "clap", "serde", @@ -2885,18 +2885,18 @@ dependencies = [ [[package]] name = "zellij-tile-utils" -version = "0.38.0" +version = "0.38.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe4262cd639250b356f809ae295ba73d5aaaec1e31d392d056d106fc3c64c3ae" +checksum = "de124f0c269a7d4433a60e6d5cface9b4684d5be819b6ea7dacdbedb6e636693" dependencies = [ "ansi_term", ] [[package]] name = "zellij-utils" -version = "0.38.0" +version = "0.38.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46d5d4651c2f87e59795582339eb5acaebe164cb5ec984a5702e1577657b5142" +checksum = "60c68881b9892c36e90031e7deb36a4fc8e11f6f95c468e19e900f54b6ed94de" dependencies = [ "anyhow", "async-channel", diff --git a/Cargo.toml b/Cargo.toml index dd4517b..d9b39b9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "zellij-datetime" -version = "0.17.1" +version = "0.18.0" authors = ["h1romas4 "] edition = "2021" [dependencies] -zellij-tile = "0.38.0" -zellij-tile-utils = "0.38.0" +zellij-tile = "0.38.1" +zellij-tile-utils = "0.38.1" ansi_term = "^0.12" chrono-wasi = "^0.4" linked-hash-map = "^0.5" diff --git a/plugin.kdl b/plugin.kdl index e4cf2d5..5a75d5f 100644 --- a/plugin.kdl +++ b/plugin.kdl @@ -1,20 +1,35 @@ layout { pane size=1 borderless=true { plugin location="file:./target/wasm32-wasi/debug/zellij-datetime.wasm" { + // Testing multiple timezone settings timezone1 "PDT/-9" timezone2 "UTC/0" timezone3 "CEST/+2" timezone4 "JST/+9" + // Testing that it will be in the specified timezone instead of timezone1 default_timezone "JST" + // Testing the Color Parser background_color "#0080a0" foreground_color "#ffffff" pane_color "#1e1e1e" + // Testing Plug-in Permissions + // To be tested at the first interactive query and at the automatic configuration cache. enable_right_click true + // Debugging options (not yet used) + enable_debug true } } + // Testing the Default Option pane size=1 borderless=true { plugin location="file:./target/wasm32-wasi/debug/zellij-datetime.wasm" } + pane size=1 borderless=true { + plugin location="file:./target/wasm32-wasi/debug/zellij-datetime.wasm" { + // Testing that the optional keys are sorted + timezone4 "JST/+9" + timezone3 "CEST/+2" + } + } pane size=1 borderless=true { plugin location="zellij:tab-bar" } diff --git a/src/config.rs b/src/config.rs index a9c58ce..3dc5281 100644 --- a/src/config.rs +++ b/src/config.rs @@ -11,10 +11,11 @@ static DEFAULT_PANE_COLOR: &str = "#1e1e1e"; pub struct Config { timezone: LinkedHashMap, default_timezone: String, - backgound_color: Option<(u8, u8, u8)>, - foreground_color: Option<(u8, u8, u8)>, - pane_color: Option<(u8, u8, u8)>, + backgound_color: (u8, u8, u8), + foreground_color: (u8, u8, u8), + pane_color: (u8, u8, u8), enable_right_click: bool, + enable_debug: bool, } impl Default for Config { @@ -25,10 +26,11 @@ impl Default for Config { Config { timezone, default_timezone: default_timezone.to_string(), - backgound_color: Some(parse_color(DEFAULT_BACKGROUND_COLOR).unwrap()), - foreground_color: Some(parse_color(DEFAULT_FOREGROUND_COLOR).unwrap()), - pane_color: Some(parse_color(DEFAULT_PANE_COLOR).unwrap()), + backgound_color: parse_color(DEFAULT_BACKGROUND_COLOR).unwrap(), + foreground_color: parse_color(DEFAULT_FOREGROUND_COLOR).unwrap(), + pane_color: parse_color(DEFAULT_PANE_COLOR).unwrap(), enable_right_click: false, + enable_debug: false, } } } @@ -75,15 +77,15 @@ impl Config { } } - pub fn get_backgound_color(&self) -> Option<(u8, u8, u8)> { + pub fn get_backgound_color(&self) -> (u8, u8, u8) { self.backgound_color } - pub fn get_foreground_color(&self) -> Option<(u8, u8, u8)> { + pub fn get_foreground_color(&self) -> (u8, u8, u8) { self.foreground_color } - pub fn get_pane_color(&self) -> Option<(u8, u8, u8)> { + pub fn get_pane_color(&self) -> (u8, u8, u8) { self.pane_color } @@ -91,12 +93,18 @@ impl Config { self.enable_right_click } + #[allow(unused)] + pub fn get_enable_debug(&self) -> bool { + self.enable_debug + } + pub fn configuration(&mut self, configuration: &BTreeMap) { let mut timezone: LinkedHashMap = LinkedHashMap::new(); let mut default_timezone: Option = None; for (key, value) in configuration { match key.as_str() { + // Option key BTreeMap is sorted "timezone1" | "timezone2" | "timezone3" | "timezone4" | "timezone5" | "timezone6" | "timezone7" | "timezone8" | "timezone9" => { let value: Vec<&str> = value.split('/').collect(); @@ -111,22 +119,25 @@ impl Config { } "background_color" => { if let Ok(color) = parse_color(value) { - self.backgound_color = Some((color.0, color.1, color.2)); + self.backgound_color = (color.0, color.1, color.2); } } "foreground_color" => { if let Ok(color) = parse_color(value) { - self.foreground_color = Some((color.0, color.1, color.2)); + self.foreground_color = (color.0, color.1, color.2); } } "pane_color" => { if let Ok(color) = parse_color(value) { - self.pane_color = Some((color.0, color.1, color.2)); + self.pane_color = (color.0, color.1, color.2); } } "enable_right_click" => { self.enable_right_click = value.trim().parse().unwrap_or(false); } + "enable_debug" => { + self.enable_debug = value.trim().parse().unwrap_or(false); + } _ => {} } } diff --git a/src/line.rs b/src/line.rs index ad96b69..042b6ad 100644 --- a/src/line.rs +++ b/src/line.rs @@ -16,20 +16,14 @@ pub struct Line { impl Line { pub fn update_style( &mut self, - backgound_color: Option<(u8, u8, u8)>, - foreground_color: Option<(u8, u8, u8)>, - pane_color: Option<(u8, u8, u8)>, + backgound_color: (u8, u8, u8), + foreground_color: (u8, u8, u8), + pane_color: (u8, u8, u8), ) { // set color - if let Some(bg_color) = backgound_color { - self.backgound_color = PaletteColor::Rgb(bg_color); - } - if let Some(fg_color) = foreground_color { - self.foreground_color = PaletteColor::Rgb(fg_color); - } - if let Some(pane_color) = pane_color { - self.pane_color = PaletteColor::Rgb(pane_color); - } + self.backgound_color = PaletteColor::Rgb(backgound_color); + self.foreground_color = PaletteColor::Rgb(foreground_color); + self.pane_color = PaletteColor::Rgb(pane_color); // create charctor let bg_1 = self.pane_color; let bg_2 = self.backgound_color; diff --git a/src/main.rs b/src/main.rs index 70ef9b9..3ddd267 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,30 +25,33 @@ register_plugin!(State); impl ZellijPlugin for State { fn load(&mut self, configuration: BTreeMap) { - // setting from plugin config in layout self.config.configuration(&configuration); - // reset default timezone self.reset_default_timezone(); - // create line sytle self.line.update_style( self.config.get_backgound_color(), self.config.get_foreground_color(), self.config.get_pane_color(), ); - // for making minute comparisons + + // Determine the elapse of one minute self.before_minute = u32::MAX; - // zellij plunin setting + subscribe(&[ EventType::PermissionRequestResult, EventType::Timer, EventType::Visible, EventType::Mouse, ]); - // request permission + self.permission_granted = false; + let mut permission = vec![]; if self.config.get_enable_right_click() { - request_permission(&[PermissionType::WriteToStdin]); + permission.push(PermissionType::WriteToStdin); + } + if !permission.is_empty() { + request_permission(&permission); } else { + // Unselectable if no permission query set_selectable(false); } }