diff --git a/src/client/boundaries.rs b/src/client/boundaries.rs index 70671b6b..cd489be0 100644 --- a/src/client/boundaries.rs +++ b/src/client/boundaries.rs @@ -1,8 +1,8 @@ -use crate::common::{colors, Palette}; +use crate::common::colors; use crate::tab::Pane; use ansi_term::Colour::RGB; use std::collections::HashMap; -use zellij_tile::data::InputMode; +use zellij_tile::data::{InputMode, Palette}; use std::fmt::{Display, Error, Formatter}; pub mod boundary_type { diff --git a/src/client/tab.rs b/src/client/tab.rs index 9203d75b..33a25446 100644 --- a/src/client/tab.rs +++ b/src/client/tab.rs @@ -1,9 +1,7 @@ //! `Tab`s holds multiple panes. It tracks their coordinates (x/y) and size, //! as well as how they should be resized -use crate::common::{ - colors, input::handler::parse_keys, AppInstruction, Palette, SenderWithContext, -}; +use crate::common::{colors, input::handler::parse_keys, AppInstruction, SenderWithContext}; use crate::layout::Layout; use crate::panes::{PaneId, PositionAndSize, TerminalPane}; use crate::pty_bus::{PtyInstruction, VteEvent}; @@ -16,7 +14,7 @@ use std::{ collections::{BTreeMap, HashSet}, }; use std::{io::Write, sync::mpsc::channel}; -use zellij_tile::data::{Event, InputMode}; +use zellij_tile::data::{Event, InputMode, Palette}; const CURSOR_HEIGHT_WIDTH_RATIO: usize = 4; // this is not accurate and kind of a magic number, TODO: look into this const MIN_TERMINAL_HEIGHT: usize = 2; diff --git a/src/common/input/handler.rs b/src/common/input/handler.rs index 385c1453..163e5ddf 100644 --- a/src/common/input/handler.rs +++ b/src/common/input/handler.rs @@ -2,7 +2,7 @@ use super::actions::Action; use super::keybinds::get_default_keybinds; -use crate::common::{AppInstruction, Palette, SenderWithContext, OPENCALLS}; +use crate::common::{load_palette, AppInstruction, SenderWithContext, OPENCALLS}; use crate::errors::ContextType; use crate::os_input_output::OsApi; use crate::pty_bus::PtyInstruction; @@ -256,7 +256,7 @@ impl InputHandler { // TODO this should probably be automatically generated in some way pub fn get_mode_info(mode: InputMode) -> ModeInfo { let mut keybinds: Vec<(String, String)> = vec![]; - let mut palette = Palette::new(); + let mut palette = load_palette(); match mode { InputMode::Normal | InputMode::Locked => {} InputMode::Resize => { diff --git a/src/common/mod.rs b/src/common/mod.rs index dbfdf1f3..1d9345b8 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -39,7 +39,7 @@ use wasm_vm::{wasi_stdout, wasi_write_string, zellij_imports, PluginInstruction} use wasmer::{ChainableNamedResolver, Instance, Module, Store, Value}; use wasmer_wasi::{Pipe, WasiState}; use xrdb::Colors; -use zellij_tile::data::{EventType, InputMode}; +use zellij_tile::data::{EventType, InputMode, Palette}; #[derive(Serialize, Deserialize, Debug)] pub enum ApiCommand { @@ -126,73 +126,57 @@ pub mod colors { pub const BLACK: (u8, u8, u8) = (0, 0, 0); } -#[derive(Clone, Copy, Debug, Serialize, Deserialize)] -pub struct Palette { - pub fg: (u8, u8, u8), - pub bg: (u8, u8, u8), - pub black: (u8, u8, u8), - pub red: (u8, u8, u8), - pub green: (u8, u8, u8), - pub yellow: (u8, u8, u8), - pub blue: (u8, u8, u8), - pub magenta: (u8, u8, u8), - pub cyan: (u8, u8, u8), - pub white: (u8, u8, u8), -} - -impl Palette { - pub fn new() -> Self { - let palette = match Colors::new("xresources") { - Some(colors) => { - let fg = colors.fg.unwrap(); - let fg_imm = &fg; - let fg_hex: &str = &fg_imm; - let fg = Rgb::from_hex_str(fg_hex).unwrap().as_tuple(); - let fg = (fg.0 as u8, fg.1 as u8, fg.2 as u8); - let bg = colors.bg.unwrap(); - let bg_imm = &bg; - let bg_hex: &str = &bg_imm; - let bg = Rgb::from_hex_str(bg_hex).unwrap().as_tuple(); - let bg = (bg.0 as u8, bg.1 as u8, bg.2 as u8); - let colors: Vec<(u8, u8, u8)> = colors - .colors - .iter() - .map(|c| { - let c = c.clone(); - let imm_str = &c.unwrap(); - let hex_str: &str = &imm_str; - let rgb = Rgb::from_hex_str(hex_str).unwrap().as_tuple(); - (rgb.0 as u8, rgb.1 as u8, rgb.2 as u8) - }) - .collect(); - Self { - 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], - } +pub fn load_palette() -> Palette { + let palette = match Colors::new("xresources") { + Some(colors) => { + let fg = colors.fg.unwrap(); + let fg_imm = &fg; + let fg_hex: &str = &fg_imm; + let fg = Rgb::from_hex_str(fg_hex).unwrap().as_tuple(); + let fg = (fg.0 as u8, fg.1 as u8, fg.2 as u8); + let bg = colors.bg.unwrap(); + let bg_imm = &bg; + let bg_hex: &str = &bg_imm; + let bg = Rgb::from_hex_str(bg_hex).unwrap().as_tuple(); + let bg = (bg.0 as u8, bg.1 as u8, bg.2 as u8); + let colors: Vec<(u8, u8, u8)> = colors + .colors + .iter() + .map(|c| { + let c = c.clone(); + let imm_str = &c.unwrap(); + let hex_str: &str = &imm_str; + let rgb = Rgb::from_hex_str(hex_str).unwrap().as_tuple(); + (rgb.0 as u8, rgb.1 as u8, rgb.2 as u8) + }) + .collect(); + Palette { + 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], } - None => Self { - fg: colors::BRIGHT_GRAY, - bg: colors::BLACK, - black: colors::BLACK, - red: colors::RED, - green: colors::GREEN, - yellow: colors::GRAY, - blue: colors::GRAY, - magenta: colors::GRAY, - cyan: colors::GRAY, - white: colors::WHITE, - }, - }; - palette - } + } + None => Palette { + fg: colors::BRIGHT_GRAY, + bg: colors::BLACK, + black: colors::BLACK, + red: colors::RED, + green: colors::GREEN, + yellow: colors::GRAY, + blue: colors::GRAY, + magenta: colors::GRAY, + cyan: colors::GRAY, + white: colors::WHITE, + }, + }; + palette } /// Start Zellij with the specified [`OsApi`] and command-line arguments. @@ -326,7 +310,7 @@ pub fn start(mut os_input: Box, 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 = Palette::new(); + let colors = load_palette(); // debug_log_to_file(format!("{:?}", colors)); move || { let mut screen = Screen::new( diff --git a/src/common/screen.rs b/src/common/screen.rs index 999b6391..e11b734d 100644 --- a/src/common/screen.rs +++ b/src/common/screen.rs @@ -6,7 +6,6 @@ use std::str; use std::sync::mpsc::Receiver; use super::{AppInstruction, SenderWithContext}; -use crate::common::Palette; use crate::os_input_output::OsApi; use crate::panes::PositionAndSize; use crate::pty_bus::{PtyInstruction, VteEvent}; @@ -14,7 +13,7 @@ use crate::tab::Tab; use crate::{errors::ErrorContext, wasm_vm::PluginInstruction}; use crate::{layout::Layout, panes::PaneId}; -use zellij_tile::data::{Event, InputMode, TabInfo}; +use zellij_tile::data::{Event, InputMode, Palette, TabInfo}; /// Instructions that can be sent to the [`Screen`]. #[derive(Debug, Clone)]