From b073e717c521ddb7978181d98e34bdec6d9f6ff8 Mon Sep 17 00:00:00 2001 From: h1romas4 Date: Mon, 4 Sep 2023 09:56:26 +0900 Subject: [PATCH 1/4] bump version --- Cargo.lock | 14 +++++++------- Cargo.toml | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) 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" From b5f26f3680336d83d3c72d9307e7a0fa72d91cfc Mon Sep 17 00:00:00 2001 From: h1romas4 Date: Mon, 4 Sep 2023 10:14:47 +0900 Subject: [PATCH 2/4] prep enable debug --- plugin.kdl | 1 + src/config.rs | 10 ++++++++++ src/main.rs | 6 +++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/plugin.kdl b/plugin.kdl index e4cf2d5..27d86ba 100644 --- a/plugin.kdl +++ b/plugin.kdl @@ -10,6 +10,7 @@ layout { foreground_color "#ffffff" pane_color "#1e1e1e" enable_right_click true + enable_debug true } } pane size=1 borderless=true { diff --git a/src/config.rs b/src/config.rs index a9c58ce..3f0eb46 100644 --- a/src/config.rs +++ b/src/config.rs @@ -15,6 +15,7 @@ pub struct Config { foreground_color: Option<(u8, u8, u8)>, pane_color: Option<(u8, u8, u8)>, enable_right_click: bool, + enable_debug: bool, } impl Default for Config { @@ -29,6 +30,7 @@ impl Default for Config { foreground_color: Some(parse_color(DEFAULT_FOREGROUND_COLOR).unwrap()), pane_color: Some(parse_color(DEFAULT_PANE_COLOR).unwrap()), enable_right_click: false, + enable_debug: false, } } } @@ -91,6 +93,11 @@ 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; @@ -127,6 +134,9 @@ impl Config { "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/main.rs b/src/main.rs index 70ef9b9..00c747c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -46,8 +46,12 @@ impl ZellijPlugin for State { ]); // 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 { set_selectable(false); } From a61183c56cc44381ab13f896b9cc919ab86b1bed Mon Sep 17 00:00:00 2001 From: h1romas4 Date: Mon, 4 Sep 2023 11:20:11 +0900 Subject: [PATCH 3/4] remove optional in config color --- src/config.rs | 24 ++++++++++++------------ src/line.rs | 18 ++++++------------ 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/src/config.rs b/src/config.rs index 3f0eb46..1ad862f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -11,9 +11,9 @@ 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, } @@ -26,9 +26,9 @@ 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, } @@ -77,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 } @@ -118,17 +118,17 @@ 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" => { 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; From e0e23a12265ba89c776802c088ff9d98cfd2c090 Mon Sep 17 00:00:00 2001 From: h1romas4 Date: Mon, 4 Sep 2023 11:34:48 +0900 Subject: [PATCH 4/4] fix comments --- plugin.kdl | 14 ++++++++++++++ src/config.rs | 1 + src/main.rs | 11 +++++------ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/plugin.kdl b/plugin.kdl index 27d86ba..5a75d5f 100644 --- a/plugin.kdl +++ b/plugin.kdl @@ -1,21 +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 1ad862f..3dc5281 100644 --- a/src/config.rs +++ b/src/config.rs @@ -104,6 +104,7 @@ impl Config { 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(); diff --git a/src/main.rs b/src/main.rs index 00c747c..3ddd267 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,26 +25,24 @@ 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() { @@ -53,6 +51,7 @@ impl ZellijPlugin for State { if !permission.is_empty() { request_permission(&permission); } else { + // Unselectable if no permission query set_selectable(false); } }