diff options
| author | denis <denismaximov98@gmail.com> | 2021-03-26 16:42:38 +0200 |
|---|---|---|
| committer | denis <denismaximov98@gmail.com> | 2021-03-26 16:42:38 +0200 |
| commit | 2c402b0b1d6a21220dca65835335bacfe3fe43e6 (patch) | |
| tree | e1efc26e167e049f17f45d9b8a78193ee691d280 /src | |
| parent | wip: reading colors from xrdb (diff) | |
| download | sl0ppij-2c402b0b1d6a21220dca65835335bacfe3fe43e6.tar.gz sl0ppij-2c402b0b1d6a21220dca65835335bacfe3fe43e6.tar.xz sl0ppij-2c402b0b1d6a21220dca65835335bacfe3fe43e6.zip | |
wip: scary how messy it is, but it's a start
Diffstat (limited to 'src')
| -rw-r--r-- | src/client/boundaries.rs | 17 | ||||
| -rw-r--r-- | src/client/tab.rs | 4 | ||||
| -rw-r--r-- | src/common/input/handler.rs | 84 | ||||
| -rw-r--r-- | src/common/mod.rs | 61 |
4 files changed, 96 insertions, 70 deletions
diff --git a/src/client/boundaries.rs b/src/client/boundaries.rs index 6ad83bd8..e7c2cb03 100644 --- a/src/client/boundaries.rs +++ b/src/client/boundaries.rs @@ -1,5 +1,5 @@ -use crate::{common::{Palette, input::handler::InputMode}, tab::Pane}; -use ansi_term::Colour; +use crate::{common::{input::handler::Palette, colors, input::handler::InputMode}, tab::Pane}; +use ansi_term::Colour::RGB; use std::collections::HashMap; use std::fmt::{Display, Error, Formatter}; @@ -18,20 +18,13 @@ pub mod boundary_type { pub const CROSS: &str = "┼"; } -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); -} - pub type BoundaryType = &'static str; // easy way to refer to boundary_type above #[derive(Clone, Copy, Debug)] pub struct BoundarySymbol { boundary_type: BoundaryType, invisible: bool, - color: Option<Colour>, + color: Option<(u8, u8, u8)>, } impl BoundarySymbol { @@ -46,7 +39,7 @@ impl BoundarySymbol { self.invisible = true; self } - pub fn color(&mut self, color: Option<Colour>) -> Self { + pub fn color(&mut self, color: Option<(u8, u8, u8)>) -> Self { self.color = color; *self } @@ -57,7 +50,7 @@ impl Display for BoundarySymbol { match self.invisible { true => write!(f, " "), false => match self.color { - Some(color) => write!(f, "{}", color.paint(self.boundary_type)), + Some(color) => write!(f, "{}", RGB(color.0, color.1, color.2).paint(self.boundary_type)), None => write!(f, "{}", self.boundary_type), }, } diff --git a/src/client/tab.rs b/src/client/tab.rs index 9d6ae896..56970851 100644 --- a/src/client/tab.rs +++ b/src/client/tab.rs @@ -1,13 +1,13 @@ //! `Tab`s holds multiple panes. It tracks their coordinates (x/y) and size, //! as well as how they should be resized -use crate::common::{AppInstruction, Palette, SenderWithContext, input::handler::InputMode}; +use crate::common::{AppInstruction, SenderWithContext, input::handler::{Palette, InputMode}}; use crate::layout::Layout; use crate::panes::{PaneId, PositionAndSize, TerminalPane}; use crate::pty_bus::{PtyInstruction, VteEvent}; use crate::wasm_vm::{PluginInputType, PluginInstruction}; use crate::{ - boundaries::{colors, Boundaries}, + boundaries::Boundaries, panes::PluginPane, }; use crate::{os_input_output::OsApi, utils::shared::pad_to_size}; diff --git a/src/common/input/handler.rs b/src/common/input/handler.rs index 2d5e965f..4f77c0ae 100644 --- a/src/common/input/handler.rs +++ b/src/common/input/handler.rs @@ -9,6 +9,9 @@ use crate::pty_bus::PtyInstruction; use crate::screen::ScreenInstruction; use crate::wasm_vm::{EventType, PluginInputType, PluginInstruction}; use crate::CommandIsExecuting; +use xrdb::Colors; +use colors_transform::{Rgb, Color}; +use crate::common::utils::logging::debug_log_to_file; use serde::{Deserialize, Serialize}; use strum_macros::EnumIter; @@ -299,6 +302,7 @@ pub enum InputMode { pub struct Help { pub mode: InputMode, pub keybinds: Vec<(String, String)>, // <shortcut> => <shortcut description> + pub palette: Palette } impl Default for InputMode { @@ -307,11 +311,89 @@ impl Default for InputMode { } } +pub mod colors { + pub const WHITE: (u8, u8, u8) = (238, 238, 238); + pub const GREEN: (u8, u8, u8) = (175, 255, 0); + 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 BLACK: (u8, u8, u8) = (0, 0, 0); +} + +#[derive(Clone, Copy, Default, 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] + } + }, + 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 + } +} + + /// 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_help(mode: InputMode) -> Help { let mut keybinds: Vec<(String, String)> = vec![]; + let mut palette = Palette::new(); match mode { InputMode::Normal | InputMode::Locked => {} InputMode::Resize => { @@ -339,7 +421,7 @@ pub fn get_help(mode: InputMode) -> Help { keybinds.push(("Enter".to_string(), "when done".to_string())); } } - Help { mode, keybinds } + Help { mode, keybinds, palette } } /// Entry point to the module. Instantiates an [`InputHandler`] and starts diff --git a/src/common/mod.rs b/src/common/mod.rs index b061c785..2bbc18bd 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -30,13 +30,14 @@ use wasmer_wasi::{Pipe, WasiState}; use crate::cli::CliArgs; use crate::layout::Layout; +use crate::common::input::handler::Palette; use command_is_executing::CommandIsExecuting; use errors::{AppContext, ContextType, ErrorContext, PluginContext, PtyContext, ScreenContext}; use input::handler::input_loop; use os_input_output::OsApi; use pty_bus::{PtyBus, PtyInstruction}; use screen::{Screen, ScreenInstruction}; -use utils::consts::{ZELLIJ_IPC_PIPE, ZELLIJ_ROOT_PLUGIN_DIR}; +use utils::{consts::{ZELLIJ_IPC_PIPE, ZELLIJ_ROOT_PLUGIN_DIR}, logging::debug_log_to_file}; use wasm_vm::{ wasi_stdout, wasi_write_string, zellij_imports, EventType, PluginInputType, PluginInstruction, }; @@ -152,62 +153,11 @@ pub enum AppInstruction { } 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); + pub const WHITE: (u8, u8, u8) = (238, 238, 238); + pub const GREEN: (u8, u8, u8) = (175, 255, 0); + pub const GRAY: (u8, u8, u8) = (68, 68, 68); } -#[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. @@ -342,6 +292,7 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs) { let send_app_instructions = send_app_instructions.clone(); let max_panes = opts.max_panes; let colors = Palette::new(); + // debug_log_to_file(format!("{:?}", colors)); move || { let mut screen = Screen::new( receive_screen_instructions, |
