summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock1
-rw-r--r--default-plugins/status-bar/src/main.rs13
-rw-r--r--default-plugins/status-bar/src/second_line.rs20
-rw-r--r--default-plugins/tab-bar/src/line.rs12
-rw-r--r--default-plugins/tab-bar/src/main.rs2
-rw-r--r--default-plugins/tab-bar/src/tab.rs12
-rw-r--r--src/common/input/handler.rs15
-rw-r--r--src/common/mod.rs4
-rw-r--r--src/common/os_input_output.rs46
-rw-r--r--src/common/utils/shared.rs47
-rw-r--r--src/tests/fakes.rs37
-rw-r--r--zellij-tile/Cargo.toml1
-rw-r--r--zellij-tile/src/data.rs12
-rw-r--r--zellij-tile/src/lib.rs16
14 files changed, 140 insertions, 98 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 4058fad7d..0b18bd6bb 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2254,6 +2254,7 @@ dependencies = [
name = "zellij-tile"
version = "1.1.0"
dependencies = [
+ "ansi_term 0.12.1",
"serde",
"serde_json",
"strum",
diff --git a/default-plugins/status-bar/src/main.rs b/default-plugins/status-bar/src/main.rs
index efa193985..4914efdb0 100644
--- a/default-plugins/status-bar/src/main.rs
+++ b/default-plugins/status-bar/src/main.rs
@@ -119,19 +119,6 @@ impl ColoredElements {
}
}
-macro_rules! rgb {
- ($a:expr) => {
- RGB($a.0, $a.1, $a.2)
- };
-}
-macro_rules! style {
- ($a:expr, $b:expr) => {
- Style::new()
- .fg(RGB($a.0, $a.1, $a.2))
- .on(RGB($b.0, $b.1, $b.2))
- };
-}
-
// I really hate this, but I can't come up with a good solution for this,
// we need different colors from palette for the default theme
// plus here we can add new sources in the future, like Theme
diff --git a/default-plugins/status-bar/src/second_line.rs b/default-plugins/status-bar/src/second_line.rs
index 73c4d7650..6982c4103 100644
--- a/default-plugins/status-bar/src/second_line.rs
+++ b/default-plugins/status-bar/src/second_line.rs
@@ -223,13 +223,25 @@ fn quicknav_short(palette: Palette) -> LinePart {
part: format!(
"{}{}{}{}{}{}{}{}",
text_first_part,
- Style::new().fg(RGB(palette.orange.0, palette.orange.1, palette.orange.2)).bold().paint(alt),
+ Style::new()
+ .fg(RGB(palette.orange.0, palette.orange.1, palette.orange.2))
+ .bold()
+ .paint(alt),
text_second_part,
- Style::new().fg(RGB(palette.green.0, palette.green.1, palette.green.2)).bold().paint(new_pane_shortcut),
+ Style::new()
+ .fg(RGB(palette.green.0, palette.green.1, palette.green.2))
+ .bold()
+ .paint(new_pane_shortcut),
text_third_part,
- Style::new().fg(RGB(palette.green.0, palette.green.1, palette.green.2)).bold().paint(brackets_navigation),
+ Style::new()
+ .fg(RGB(palette.green.0, palette.green.1, palette.green.2))
+ .bold()
+ .paint(brackets_navigation),
text_fifth_part,
- Style::new().fg(RGB(palette.green.0, palette.green.1, palette.green.2)).bold().paint(hjkl_navigation),
+ Style::new()
+ .fg(RGB(palette.green.0, palette.green.1, palette.green.2))
+ .bold()
+ .paint(hjkl_navigation),
),
len,
}
diff --git a/default-plugins/tab-bar/src/line.rs b/default-plugins/tab-bar/src/line.rs
index 5976f12f5..ae287d2e8 100644
--- a/default-plugins/tab-bar/src/line.rs
+++ b/default-plugins/tab-bar/src/line.rs
@@ -1,15 +1,7 @@
-use ansi_term::{ANSIStrings, Color::RGB, Style};
+use ansi_term::ANSIStrings;
use crate::{LinePart, ARROW_SEPARATOR};
-use zellij_tile::data::{colors::*, Palette};
-
-macro_rules! style {
- ($a:expr, $b:expr) => {
- Style::new()
- .fg(RGB($a.0, $a.1, $a.2))
- .on(RGB($b.0, $b.1, $b.2))
- };
-}
+use zellij_tile::prelude::*;
fn get_current_title_len(current_title: &[LinePart]) -> usize {
current_title
diff --git a/default-plugins/tab-bar/src/main.rs b/default-plugins/tab-bar/src/main.rs
index 7c6a22209..1c6d584e3 100644
--- a/default-plugins/tab-bar/src/main.rs
+++ b/default-plugins/tab-bar/src/main.rs
@@ -59,7 +59,7 @@ impl ZellijPlugin for State {
t.active,
t.position,
t.is_sync_panes_active,
- self.mode_info.palette
+ self.mode_info.palette,
);
all_tabs.push(tab);
}
diff --git a/default-plugins/tab-bar/src/tab.rs b/default-plugins/tab-bar/src/tab.rs
index 3e3408103..27b4ad94e 100644
--- a/default-plugins/tab-bar/src/tab.rs
+++ b/default-plugins/tab-bar/src/tab.rs
@@ -1,14 +1,6 @@
use crate::{LinePart, ARROW_SEPARATOR};
use ansi_term::{ANSIStrings, Color::RGB, Style};
-use zellij_tile::data::Palette;
-
-macro_rules! style {
- ($a:expr, $b:expr) => {
- Style::new()
- .fg(RGB($a.0, $a.1, $a.2))
- .on(RGB($b.0, $b.1, $b.2))
- };
-}
+use zellij_tile::prelude::*;
pub fn active_tab(text: String, palette: Palette) -> LinePart {
let left_separator = style!(palette.bg, palette.green).paint(ARROW_SEPARATOR);
@@ -49,7 +41,7 @@ pub fn tab_style(
is_active_tab: bool,
position: usize,
is_sync_panes_active: bool,
- palette: Palette
+ palette: Palette,
) -> LinePart {
let mut tab_text = if text.is_empty() {
format!("Tab #{}", position + 1)
diff --git a/src/common/input/handler.rs b/src/common/input/handler.rs
index eda71eea6..b5f6008ab 100644
--- a/src/common/input/handler.rs
+++ b/src/common/input/handler.rs
@@ -2,7 +2,7 @@
use super::actions::Action;
use super::keybinds::Keybinds;
-use crate::common::input::config::Config;
+use crate::common::{input::config::Config};
use crate::common::{AppInstruction, SenderWithContext, OPENCALLS};
use crate::errors::ContextType;
use crate::os_input_output::OsApi;
@@ -11,9 +11,8 @@ use crate::screen::ScreenInstruction;
use crate::wasm_vm::PluginInstruction;
use crate::CommandIsExecuting;
-use crate::common::utils::shared::load_palette;
use termion::input::{TermRead, TermReadEventsAndRaw};
-use zellij_tile::data::{Event, InputMode, Key, ModeInfo};
+use zellij_tile::data::{Event, InputMode, Key, ModeInfo, Palette};
/// Handles the dispatching of [`Action`]s according to the current
/// [`InputMode`], and keep tracks of the current [`InputMode`].
@@ -132,11 +131,14 @@ impl InputHandler {
self.send_plugin_instructions
.send(PluginInstruction::Update(
None,
- Event::ModeUpdate(get_mode_info(mode)),
+ Event::ModeUpdate(get_mode_info(mode, self.os_input.load_palette())),
))
.unwrap();
self.send_screen_instructions
- .send(ScreenInstruction::ChangeMode(get_mode_info(mode)))
+ .send(ScreenInstruction::ChangeMode(get_mode_info(
+ mode,
+ self.os_input.load_palette(),
+ )))
.unwrap();
self.send_screen_instructions
.send(ScreenInstruction::Render)
@@ -285,9 +287,8 @@ impl InputHandler {
/// Creates a [`Help`] struct indicating the current [`InputMode`] and its keybinds
/// (as pairs of [`String`]s).
// TODO this should probably be automatically generated in some way
-pub fn get_mode_info(mode: InputMode) -> ModeInfo {
+pub fn get_mode_info(mode: InputMode, palette: Palette) -> ModeInfo {
let mut keybinds: Vec<(String, String)> = vec![];
- let palette = load_palette();
match mode {
InputMode::Normal | InputMode::Locked => {}
InputMode::Resize => {
diff --git a/src/common/mod.rs b/src/common/mod.rs
index 71824e269..c9b8e0e26 100644
--- a/src/common/mod.rs
+++ b/src/common/mod.rs
@@ -39,7 +39,7 @@ use os_input_output::OsApi;
use pty_bus::{PtyBus, PtyInstruction};
use screen::{Screen, ScreenInstruction};
use serde::{Deserialize, Serialize};
-use utils::{consts::ZELLIJ_IPC_PIPE, shared::load_palette};
+use utils::consts::ZELLIJ_IPC_PIPE;
use wasm_vm::{wasi_read_string, wasi_write_object, zellij_exports, PluginEnv, PluginInstruction};
use wasmer::{ChainableNamedResolver, Instance, Module, Store, Value};
use wasmer_wasi::{Pipe, WasiState};
@@ -267,7 +267,7 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs) {
let send_plugin_instructions = send_plugin_instructions.clone();
let send_app_instructions = send_app_instructions.clone();
let max_panes = opts.max_panes;
- let colors = load_palette();
+ let colors = os_input.load_palette();
// debug_log_to_file(format!("{:?}", colors));
move || {
let mut screen = Screen::new(
diff --git a/src/common/os_input_output.rs b/src/common/os_input_output.rs
index 35d77fddf..41a4bfe47 100644
--- a/src/common/os_input_output.rs
+++ b/src/common/os_input_output.rs
@@ -1,4 +1,5 @@
use crate::panes::PositionAndSize;
+use crate::utils::shared::{colors, detect_theme, hex_to_rgb};
use nix::fcntl::{fcntl, FcntlArg, OFlag};
use nix::pty::{forkpty, Winsize};
use nix::sys::signal::{kill, Signal};
@@ -12,6 +13,8 @@ use std::os::unix::io::RawFd;
use std::path::PathBuf;
use std::process::{Child, Command};
use std::sync::{Arc, Mutex};
+use xrdb::Colors;
+use zellij_tile::data::{Palette, PaletteSource, Theme};
use signal_hook::{consts::signal::*, iterator::Signals};
@@ -191,6 +194,7 @@ pub trait OsApi: Send + Sync {
/// Returns a [`Box`] pointer to this [`OsApi`] struct.
fn box_clone(&self) -> Box<dyn OsApi>;
fn receive_sigwinch(&self, cb: Box<dyn Fn()>);
+ fn load_palette(&self) -> Palette;
}
impl OsApi for OsInputOutput {
@@ -261,6 +265,48 @@ impl OsApi for OsInputOutput {
}
}
}
+ fn load_palette(&self) -> Palette {
+ let palette = match Colors::new("xresources") {
+ Some(palette) => {
+ let fg = hex_to_rgb(&palette.fg);
+ let bg = hex_to_rgb(&palette.bg);
+ let colors: Vec<(u8, u8, u8)> =
+ palette.colors.iter().map(|c| hex_to_rgb(c)).collect();
+ let theme = detect_theme(bg);
+ Palette {
+ source: PaletteSource::Xresources,
+ theme,
+ fg,
+ bg,
+ black: colors[0],
+ red: colors[1],
+ green: colors[2],
+ yellow: colors[3],
+ blue: colors[4],
+ magenta: colors[5],
+ cyan: colors[6],
+ white: colors[7],
+ orange: colors[9],
+ }
+ }
+ None => Palette {
+ source: PaletteSource::Default,
+ theme: Theme::Dark,
+ fg: colors::BRIGHT_GRAY,
+ bg: colors::GRAY,
+ black: colors::BLACK,
+ red: colors::RED,
+ green: colors::GREEN,
+ yellow: colors::GRAY,
+ blue: colors::GRAY,
+ magenta: colors::GRAY,
+ cyan: colors::GRAY,
+ white: colors::WHITE,
+ orange: colors::ORANGE,
+ },
+ };
+ palette
+ }
}
impl Clone for Box<dyn OsApi> {
diff --git a/src/common/utils/shared.rs b/src/common/utils/shared.rs
index 2decc9056..c72b2e85a 100644
--- a/src/common/utils/shared.rs
+++ b/src/common/utils/shared.rs
@@ -5,8 +5,7 @@ use std::{iter, str::from_utf8};
use strip_ansi_escapes::strip;
use colors_transform::{Color, Rgb};
-use xrdb::Colors;
-use zellij_tile::data::{Palette, PaletteSource, Theme};
+use zellij_tile::data::{Theme};
fn ansi_len(s: &str) -> usize {
from_utf8(&strip(s.as_bytes()).unwrap())
@@ -40,7 +39,7 @@ pub mod colors {
pub const GRAY: (u8, u8, u8) = (68, 68, 68);
pub const BRIGHT_GRAY: (u8, u8, u8) = (138, 138, 138);
pub const RED: (u8, u8, u8) = (135, 0, 0);
- pub const ORANGE: (u8, u8, u8) = (215,95,0);
+ pub const ORANGE: (u8, u8, u8) = (215, 95, 0);
pub const BLACK: (u8, u8, u8) = (0, 0, 0);
}
@@ -65,45 +64,3 @@ pub fn detect_theme(bg: (u8, u8, u8)) -> Theme {
false => Theme::Dark,
}
}
-
-pub fn load_palette() -> Palette {
- let palette = match Colors::new("xresources") {
- Some(palette) => {
- let fg = hex_to_rgb(&palette.fg);
- let bg = hex_to_rgb(&palette.bg);
- let colors: Vec<(u8, u8, u8)> = palette.colors.iter().map(|c| hex_to_rgb(c)).collect();
- let theme = detect_theme(bg);
- Palette {
- source: PaletteSource::Xresources,
- theme,
- fg,
- bg,
- black: colors[0],
- red: colors[1],
- green: colors[2],
- yellow: colors[3],
- blue: colors[4],
- magenta: colors[5],
- cyan: colors[6],
- white: colors[7],
- orange: colors[9]
- }
- }
- None => Palette {
- source: PaletteSource::Default,
- theme: Theme::Dark,
- fg: colors::BRIGHT_GRAY,
- bg: colors::GRAY,
- black: colors::BLACK,
- red: colors::RED,
- green: colors::GREEN,
- yellow: colors::GRAY,
- blue: colors::GRAY,
- magenta: colors::GRAY,
- cyan: colors::GRAY,
- white: colors::WHITE,
- orange: colors::ORANGE
- },
- };
- palette
-}
diff --git a/src/tests/fakes.rs b/src/tests/fakes.rs
index c9504a984..e00de017c 100644
--- a/src/tests/fakes.rs
+++ b/src/tests/fakes.rs
@@ -8,6 +8,8 @@ use std::time::{Duration, Instant};
use crate::os_input_output::OsApi;
use crate::tests::possible_tty_inputs::{get_possible_tty_inputs, Bytes};
+use crate::utils::shared::colors;
+use zellij_tile::data::{Palette, PaletteSource, Theme};
use crate::tests::utils::commands::{QUIT, SLEEP};
@@ -73,6 +75,7 @@ pub struct FakeInputOutput {
last_snapshot_time: Arc<Mutex<Instant>>,
should_trigger_sigwinch: Arc<(Mutex<bool>, Condvar)>,
sigwinch_event: Option<PositionAndSize>,
+ palette: Arc<Mutex<Palette>>,
}
impl FakeInputOutput {
@@ -81,6 +84,21 @@ impl FakeInputOutput {
let last_snapshot_time = Arc::new(Mutex::new(Instant::now()));
let stdout_writer = FakeStdoutWriter::new(last_snapshot_time.clone());
win_sizes.insert(0, winsize); // 0 is the current terminal
+ let palette: Palette = Palette {
+ source: PaletteSource::Default,
+ theme: Theme::Dark,
+ fg: colors::BRIGHT_GRAY,
+ bg: colors::GRAY,
+ black: colors::BLACK,
+ red: colors::RED,
+ green: colors::GREEN,
+ yellow: colors::GRAY,
+ blue: colors::GRAY,
+ magenta: colors::GRAY,
+ cyan: colors::GRAY,
+ white: colors::WHITE,
+ orange: colors::ORANGE,
+ };
FakeInputOutput {
read_buffers: Arc::new(Mutex::new(HashMap::new())),
stdin_writes: Arc::new(Mutex::new(HashMap::new())),
@@ -93,6 +111,7 @@ impl FakeInputOutput {
possible_tty_inputs: get_possible_tty_inputs(),
should_trigger_sigwinch: Arc::new((Mutex::new(false), Condvar::new())),
sigwinch_event: None,
+ palette: Arc::new(Mutex::new(palette)),
}
}
pub fn with_tty_inputs(mut self, tty_inputs: HashMap<u16, Bytes>) -> Self {
@@ -235,4 +254,22 @@ impl OsApi for FakeInputOutput {
cb();
}
}
+ fn load_palette(&self) -> Palette {
+ let palette: Palette = Palette {
+ source: PaletteSource::Default,
+ theme: Theme::Dark,
+ fg: colors::BRIGHT_GRAY,
+ bg: colors::GRAY,
+ black: colors::BLACK,
+ red: colors::RED,
+ green: colors::GREEN,
+ yellow: colors::GRAY,
+ blue: colors::GRAY,
+ magenta: colors::GRAY,
+ cyan: colors::GRAY,
+ white: colors::WHITE,
+ orange: colors::ORANGE,
+ };
+ palette
+ }
}
diff --git a/zellij-tile/Cargo.toml b/zellij-tile/Cargo.toml
index f59cf7b3e..7a3933103 100644
--- a/zellij-tile/Cargo.toml
+++ b/zellij-tile/Cargo.toml
@@ -7,6 +7,7 @@ description = "A small client-side library for writing Zellij plugins"
license = "MIT"
[dependencies]
+ansi_term = "0.12.1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
strum = "0.20.0"
diff --git a/zellij-tile/src/data.rs b/zellij-tile/src/data.rs
index 3b53ed136..845385ca5 100644
--- a/zellij-tile/src/data.rs
+++ b/zellij-tile/src/data.rs
@@ -67,13 +67,13 @@ impl Default for InputMode {
}
}
-#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
+#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub enum Theme {
Light,
Dark,
}
-#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
+#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub enum PaletteSource {
Default,
Xresources,
@@ -84,11 +84,11 @@ pub mod colors {
pub const GRAY: (u8, u8, u8) = (68, 68, 68);
pub const BRIGHT_GRAY: (u8, u8, u8) = (138, 138, 138);
pub const RED: (u8, u8, u8) = (135, 0, 0);
- pub const ORANGE: (u8, u8, u8) = (215,95,0);
+ pub const ORANGE: (u8, u8, u8) = (215, 95, 0);
pub const BLACK: (u8, u8, u8) = (0, 0, 0);
}
-#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
+#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct Palette {
pub source: PaletteSource,
pub theme: Theme,
@@ -102,7 +102,7 @@ pub struct Palette {
pub magenta: (u8, u8, u8),
pub cyan: (u8, u8, u8),
pub white: (u8, u8, u8),
- pub orange: (u8, u8, u8)
+ pub orange: (u8, u8, u8),
}
impl Default for Palette {
@@ -120,7 +120,7 @@ impl Default for Palette {
magenta: colors::GRAY,
cyan: colors::GRAY,
white: colors::WHITE,
- orange: colors::ORANGE
+ orange: colors::ORANGE,
}
}
}
diff --git a/zellij-tile/src/lib.rs b/zellij-tile/src/lib.rs
index af7d8ca12..3ab490613 100644
--- a/zellij-tile/src/lib.rs
+++ b/zellij-tile/src/lib.rs
@@ -39,3 +39,19 @@ macro_rules! register_plugin {
}
};
}
+
+#[macro_export]
+macro_rules! rgb {
+ ($a:expr) => {
+ ansi_term::Color::RGB($a.0, $a.1, $a.2)
+ };
+}
+
+#[macro_export]
+macro_rules! style {
+ ($a:expr, $b:expr) => {
+ ansi_term::Style::new()
+ .fg(ansi_term::Color::RGB($a.0, $a.1, $a.2))
+ .on(ansi_term::Color::RGB($b.0, $b.1, $b.2))
+ };
+}