aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authordenis <denismaximov98@gmail.com>2021-03-27 15:30:53 +0200
committerdenis <denismaximov98@gmail.com>2021-03-27 15:30:53 +0200
commit6e276ae386f0f7e9dd3a4e1095d26e17f6c6401e (patch)
treee93c0e2c241e336baddbc2f124d8f09a54b3cd7f /src
parentwip: latest plugin system merge in (diff)
downloadsl0ppij-6e276ae386f0f7e9dd3a4e1095d26e17f6c6401e.tar.gz
sl0ppij-6e276ae386f0f7e9dd3a4e1095d26e17f6c6401e.tar.xz
sl0ppij-6e276ae386f0f7e9dd3a4e1095d26e17f6c6401e.zip
wip: move Palette out of zellij-tile
Diffstat (limited to 'src')
-rw-r--r--src/client/boundaries.rs3
-rw-r--r--src/client/tab.rs6
-rw-r--r--src/common/input/handler.rs4
-rw-r--r--src/common/mod.rs82
-rw-r--r--src/common/screen.rs3
5 files changed, 91 insertions, 7 deletions
diff --git a/src/client/boundaries.rs b/src/client/boundaries.rs
index eb1a5a21..70671b6b 100644
--- a/src/client/boundaries.rs
+++ b/src/client/boundaries.rs
@@ -1,7 +1,8 @@
+use crate::common::{colors, Palette};
use crate::tab::Pane;
use ansi_term::Colour::RGB;
use std::collections::HashMap;
-use zellij_tile::data::{colors, InputMode, Palette};
+use zellij_tile::data::InputMode;
use std::fmt::{Display, Error, Formatter};
pub mod boundary_type {
diff --git a/src/client/tab.rs b/src/client/tab.rs
index d5a190f4..9203d75b 100644
--- a/src/client/tab.rs
+++ b/src/client/tab.rs
@@ -1,7 +1,9 @@
//! `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::parse_keys, AppInstruction, SenderWithContext};
+use crate::common::{
+ colors, input::handler::parse_keys, AppInstruction, Palette, SenderWithContext,
+};
use crate::layout::Layout;
use crate::panes::{PaneId, PositionAndSize, TerminalPane};
use crate::pty_bus::{PtyInstruction, VteEvent};
@@ -14,7 +16,7 @@ use std::{
collections::{BTreeMap, HashSet},
};
use std::{io::Write, sync::mpsc::channel};
-use zellij_tile::data::{colors, Event, InputMode, Palette};
+use zellij_tile::data::{Event, InputMode};
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 b135ea16..385c1453 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, SenderWithContext, OPENCALLS};
+use crate::common::{AppInstruction, Palette, SenderWithContext, OPENCALLS};
use crate::errors::ContextType;
use crate::os_input_output::OsApi;
use crate::pty_bus::PtyInstruction;
@@ -11,7 +11,7 @@ use crate::wasm_vm::PluginInstruction;
use crate::CommandIsExecuting;
use termion::input::{TermRead, TermReadEventsAndRaw};
-use zellij_tile::data::{Event, InputMode, Key, ModeInfo, Palette};
+use zellij_tile::data::{Event, InputMode, Key, ModeInfo};
use super::keybinds::key_to_actions;
diff --git a/src/common/mod.rs b/src/common/mod.rs
index 6732619e..dbfdf1f3 100644
--- a/src/common/mod.rs
+++ b/src/common/mod.rs
@@ -24,6 +24,7 @@ use std::{
use crate::cli::CliArgs;
use crate::layout::Layout;
use crate::panes::PaneId;
+use colors_transform::{Color, Rgb};
use command_is_executing::CommandIsExecuting;
use directories_next::ProjectDirs;
use errors::{AppContext, ContextType, ErrorContext, PluginContext, PtyContext, ScreenContext};
@@ -37,7 +38,8 @@ use wasm_vm::PluginEnv;
use wasm_vm::{wasi_stdout, wasi_write_string, zellij_imports, PluginInstruction};
use wasmer::{ChainableNamedResolver, Instance, Module, Store, Value};
use wasmer_wasi::{Pipe, WasiState};
-use zellij_tile::data::{EventType, InputMode, Palette};
+use xrdb::Colors;
+use zellij_tile::data::{EventType, InputMode};
#[derive(Serialize, Deserialize, Debug)]
pub enum ApiCommand {
@@ -115,6 +117,84 @@ pub enum AppInstruction {
Error(String),
}
+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, 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
+ }
+}
+
/// 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) {
diff --git a/src/common/screen.rs b/src/common/screen.rs
index e11b734d..999b6391 100644
--- a/src/common/screen.rs
+++ b/src/common/screen.rs
@@ -6,6 +6,7 @@ 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};
@@ -13,7 +14,7 @@ use crate::tab::Tab;
use crate::{errors::ErrorContext, wasm_vm::PluginInstruction};
use crate::{layout::Layout, panes::PaneId};
-use zellij_tile::data::{Event, InputMode, Palette, TabInfo};
+use zellij_tile::data::{Event, InputMode, TabInfo};
/// Instructions that can be sent to the [`Screen`].
#[derive(Debug, Clone)]