Skip to content

Commit

Permalink
remove unnecessary render and dependencies update
Browse files Browse the repository at this point in the history
  • Loading branch information
h1romas4 committed Apr 24, 2023
1 parent fa1b128 commit 65ce6ab
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 44 deletions.
30 changes: 15 additions & 15 deletions Cargo.lock

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

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "zellij-datetime"
version = "0.4.2"
version = "0.5.0"
authors = ["h1romas4 <[email protected]>"]
edition = "2021"

[dependencies]
zellij-tile = "^0.36.0"
zellij-tile-utils = "0.36.0"
ansi_term = "0.12"
chrono-wasi = "0.4.11"
zellij-tile = "^0.36"
zellij-tile-utils = "^0.36"
ansi_term = "^0.12"
chrono-wasi = "^0.4"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ zellij setup --dump-layout default > ~/.config/zellij/layouts/default.kdl
# deploy plugin .wasm
cd ~/.config/zellij/plugins/
# download datetime plugin
wget https://github.com/h1romas4/zellij-datetime/releases/download/v0.4.2/zellij-datetime.wasm
wget https://github.com/h1romas4/zellij-datetime/releases/download/v0.5.0/zellij-datetime.wasm
```

## Usage
Expand Down
39 changes: 16 additions & 23 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use zellij_tile_utils::style;

// FIXME: UTC+9
static TIMEZONE_OFFSET: i32 = 9;
// Dark gray
// FIXME: DateTime backgorund color
static DATETIME_BG_COLOR: (u8, u8, u8) = (32, 32, 32);

static ARROW_SEPARATOR_1: &str = "";
Expand Down Expand Up @@ -33,11 +33,7 @@ register_plugin!(State);
impl ZellijPlugin for State {
fn load(&mut self) {
set_selectable(false);
subscribe(&[
EventType::Timer,
EventType::Visible,
EventType::ModeUpdate,
]);
subscribe(&[EventType::Timer, EventType::Visible, EventType::ModeUpdate]);
self.before_now = u32::MAX;
}

Expand All @@ -55,8 +51,7 @@ impl ZellijPlugin for State {
// TODO: suport timezone or add plugin setting
// Timezone may not be obtained by WASI.
// let now = Local::now();
let now = Utc::now()
.with_timezone(&FixedOffset::east(TIMEZONE_OFFSET * 3600));
let now = Utc::now().with_timezone(&FixedOffset::east(TIMEZONE_OFFSET * 3600));
// render at 1 minute intervals.
let now_minute = now.minute();
if self.before_now != now_minute {
Expand All @@ -70,7 +65,6 @@ impl ZellijPlugin for State {
}
Event::ModeUpdate(mode_info) => {
if self.mode_info != mode_info {
render = true;
self.mode_update = true;
self.mode_info = mode_info;
}
Expand All @@ -88,24 +82,21 @@ impl ZellijPlugin for State {
self.pallet_fg = self.mode_info.style.colors.fg;
self.pallet_bg = self.mode_info.style.colors.bg;
self.datetime_bg_color = PaletteColor::Rgb(DATETIME_BG_COLOR);
// create line string
let bg1 = self.pallet_bg;
let bg2 = self.datetime_bg_color;
// create charctor
let arrow = &style!(bg2, bg2).bold().paint(ARROW_SPACE).to_string();
let sep_1 = &style!(bg2, bg1).bold().paint(ARROW_SEPARATOR_1).to_string();
let sep_2 = &style!(bg1, bg2).bold().paint(ARROW_SEPARATOR_2).to_string();
self.lp_1 = String::new();
self.lp_1
.push_str(&style!(bg2, bg1).bold().paint(ARROW_SEPARATOR_1).to_string());
self.lp_1
.push_str(&style!(bg2, bg2).bold().paint(ARROW_SPACE).to_string());
self.lp_1.push_str(sep_1);
self.lp_1.push_str(arrow);
self.lp_2 = String::new();
self.lp_2
.push_str(&style!(bg2, bg2).bold().paint(ARROW_SPACE).to_string());
self.lp_2
.push_str(&style!(bg1, bg2).bold().paint(ARROW_SEPARATOR_2).to_string());
self.lp_2
.push_str(&style!(bg2, bg2).bold().paint(ARROW_SPACE).to_string());
self.lp_2.push_str(arrow);
self.lp_2.push_str(sep_2);
self.lp_2.push_str(arrow);
self.lp_3 = String::new();
self.lp_3
.push_str(&style!(bg2, bg2).bold().paint(ARROW_SPACE).to_string());
self.lp_3.push_str(arrow);
self.mode_update = false;
}

Expand All @@ -131,7 +122,9 @@ impl ZellijPlugin for State {
if cols as isize - width as isize > 0 {
// only half width char
let padding = ARROW_SPACE.repeat(cols - width);
self.padding = style!(self.pallet_fg, self.pallet_bg).paint(padding).to_string();
self.padding = style!(self.pallet_fg, self.pallet_bg)
.paint(padding)
.to_string();
} else {
self.padding = String::new();
}
Expand Down

0 comments on commit 65ce6ab

Please sign in to comment.