Skip to content

Commit

Permalink
Merge commit 'e0e23a12265ba89c776802c088ff9d98cfd2c090'
Browse files Browse the repository at this point in the history
  • Loading branch information
h1romas4 committed Sep 4, 2023
2 parents 717b89a + e0e23a1 commit 17438f5
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 41 deletions.
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "zellij-datetime"
version = "0.17.1"
version = "0.18.0"
authors = ["h1romas4 <h1romas4@gmail.com>"]
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"
Expand Down
15 changes: 15 additions & 0 deletions plugin.kdl
Original file line number Diff line number Diff line change
@@ -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"
}
Expand Down
35 changes: 23 additions & 12 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ static DEFAULT_PANE_COLOR: &str = "#1e1e1e";
pub struct Config {
timezone: LinkedHashMap<String, i32>,
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 {
Expand All @@ -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,
}
}
}
Expand Down Expand Up @@ -75,28 +77,34 @@ 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
}

pub fn get_enable_right_click(&self) -> bool {
self.enable_right_click
}

#[allow(unused)]
pub fn get_enable_debug(&self) -> bool {
self.enable_debug
}

pub fn configuration(&mut self, configuration: &BTreeMap<String, String>) {
let mut timezone: LinkedHashMap<String, i32> = LinkedHashMap::new();
let mut default_timezone: Option<String> = 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();
Expand All @@ -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);
}
_ => {}
}
}
Expand Down
18 changes: 6 additions & 12 deletions src/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 10 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,33 @@ register_plugin!(State);

impl ZellijPlugin for State {
fn load(&mut self, configuration: BTreeMap<String, String>) {
// 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);
}
}
Expand Down

0 comments on commit 17438f5

Please sign in to comment.