diff options
| author | denis <denismaximov98@gmail.com> | 2021-03-25 18:05:16 +0200 |
|---|---|---|
| committer | denis <denismaximov98@gmail.com> | 2021-03-25 18:05:16 +0200 |
| commit | a35cade8dea3c6dff822c7fb04a439777433721a (patch) | |
| tree | 869f4f96ee972d4c61666e567e7e265410cab1d4 /src | |
| parent | fix(render): various rendering issues (#238) (diff) | |
| download | sl0ppij-a35cade8dea3c6dff822c7fb04a439777433721a.tar.gz sl0ppij-a35cade8dea3c6dff822c7fb04a439777433721a.tar.xz sl0ppij-a35cade8dea3c6dff822c7fb04a439777433721a.zip | |
wip: reading colors from xrdb
Diffstat (limited to 'src')
| -rw-r--r-- | src/client/boundaries.rs | 10 | ||||
| -rw-r--r-- | src/client/tab.rs | 7 | ||||
| -rw-r--r-- | src/common/mod.rs | 64 | ||||
| -rw-r--r-- | src/common/screen.rs | 7 |
4 files changed, 79 insertions, 9 deletions
diff --git a/src/client/boundaries.rs b/src/client/boundaries.rs index 19a1058d..6ad83bd8 100644 --- a/src/client/boundaries.rs +++ b/src/client/boundaries.rs @@ -1,4 +1,4 @@ -use crate::{common::input::handler::InputMode, tab::Pane}; +use crate::{common::{Palette, input::handler::InputMode}, tab::Pane}; use ansi_term::Colour; use std::collections::HashMap; @@ -763,11 +763,11 @@ impl Boundaries { boundary_characters: HashMap::new(), } } - pub fn add_rect(&mut self, rect: &dyn Pane, input_mode: InputMode, color: Option<Colour>) { - let color = match color.is_some() { + pub fn add_rect(&mut self, rect: &dyn Pane, input_mode: InputMode, palette: Option<Palette>) { + let color = match palette.is_some() { true => match input_mode { - InputMode::Normal | InputMode::Locked => Some(colors::GREEN), - _ => Some(colors::WHITE), + InputMode::Normal | InputMode::Locked => Some(palette.unwrap().green), + _ => Some(palette.unwrap().white), }, false => None, }; diff --git a/src/client/tab.rs b/src/client/tab.rs index 081194ed..9d6ae896 100644 --- a/src/client/tab.rs +++ b/src/client/tab.rs @@ -1,7 +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::{input::handler::InputMode, AppInstruction, SenderWithContext}; +use crate::common::{AppInstruction, Palette, SenderWithContext, input::handler::InputMode}; use crate::layout::Layout; use crate::panes::{PaneId, PositionAndSize, TerminalPane}; use crate::pty_bus::{PtyInstruction, VteEvent}; @@ -69,6 +69,7 @@ pub struct Tab { pub send_app_instructions: SenderWithContext<AppInstruction>, expansion_boundary: Option<PositionAndSize>, pub input_mode: InputMode, + pub colors: Palette } #[derive(Clone, Debug, Default, Serialize, Deserialize)] @@ -194,6 +195,7 @@ impl Tab { max_panes: Option<usize>, pane_id: Option<PaneId>, input_mode: InputMode, + colors: Palette ) -> Self { let panes = if let Some(PaneId::Terminal(pid)) = pane_id { let new_terminal = TerminalPane::new(pid, *full_screen_ws); @@ -224,6 +226,7 @@ impl Tab { send_plugin_instructions, expansion_boundary: None, input_mode, + colors } } @@ -653,7 +656,7 @@ impl Tab { if !self.panes_to_hide.contains(&terminal.pid()) { match self.active_terminal.unwrap() == terminal.pid() { true => { - boundaries.add_rect(terminal.as_ref(), self.input_mode, Some(colors::GREEN)) + boundaries.add_rect(terminal.as_ref(), self.input_mode, Some(self.colors)) } false => boundaries.add_rect(terminal.as_ref(), self.input_mode, None), } diff --git a/src/common/mod.rs b/src/common/mod.rs index 7e52dde7..b061c785 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -15,6 +15,9 @@ use std::sync::mpsc; use std::thread; use std::{cell::RefCell, sync::mpsc::TrySendError}; use std::{collections::HashMap, fs}; +use xrdb::Colors; +use colors_transform::{Rgb, Color}; +use ansi_term::Colour::RGB; use crate::panes::PaneId; use directories_next::ProjectDirs; @@ -148,6 +151,64 @@ pub enum AppInstruction { Error(String), } +pub mod colors { + use ansi_term::Colour::{self, Fixed}; + pub const WHITE: Colour = Fixed(255); + pub const GREEN: Colour = Fixed(154); + pub const GRAY: Colour = Fixed(238); +} + +#[derive(Clone, Copy)] +pub struct Palette { + pub black: ansi_term::Color, + pub red: ansi_term::Color, + pub green: ansi_term::Color, + pub yellow: ansi_term::Color, + pub blue: ansi_term::Color, + pub magenta: ansi_term::Color, + pub cyan: ansi_term::Color, + pub white: ansi_term::Color, +} + +impl Palette { + pub fn new() -> Self { + let palette = match Colors::new("xresources") { + Some(colors) => { + let colors: Vec<ansi_term::Color> = 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(rgb.0 as u8, rgb.1 as u8, rgb.2 as u8) + }).collect(); + Self { + 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 { + black: colors::GRAY, + red: colors::GRAY, + 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. // FIXME this should definitely be modularized and split into different functions. pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs) { @@ -280,7 +341,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 = Palette::new(); move || { let mut screen = Screen::new( receive_screen_instructions, @@ -291,6 +352,7 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs) { os_input, max_panes, InputMode::Normal, + colors ); loop { let (event, mut err_ctx) = screen diff --git a/src/common/screen.rs b/src/common/screen.rs index bb77ab85..92109435 100644 --- a/src/common/screen.rs +++ b/src/common/screen.rs @@ -5,7 +5,7 @@ use std::os::unix::io::RawFd; use std::str; use std::sync::mpsc::Receiver; -use super::{input::handler::InputMode, AppInstruction, SenderWithContext}; +use super::{AppInstruction, Palette, SenderWithContext, input::handler::InputMode}; use crate::os_input_output::OsApi; use crate::panes::PositionAndSize; use crate::pty_bus::{PtyInstruction, VteEvent}; @@ -74,6 +74,7 @@ pub struct Screen { os_api: Box<dyn OsApi>, tabname_buf: String, input_mode: InputMode, + colors: Palette } impl Screen { @@ -87,6 +88,7 @@ impl Screen { os_api: Box<dyn OsApi>, max_panes: Option<usize>, input_mode: InputMode, + colors: Palette ) -> Self { Screen { receiver: receive_screen_instructions, @@ -100,6 +102,7 @@ impl Screen { os_api, tabname_buf: String::new(), input_mode, + colors } } @@ -120,6 +123,7 @@ impl Screen { self.max_panes, Some(PaneId::Terminal(pane_id)), self.input_mode, + self.colors ); self.active_tab_index = Some(tab_index); self.tabs.insert(tab_index, tab); @@ -265,6 +269,7 @@ impl Screen { self.max_panes, None, self.input_mode, + self.colors ); tab.apply_layout(layout, new_pids); self.active_tab_index = Some(tab_index); |
