aboutsummaryrefslogtreecommitdiffstats
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
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
-rw-r--r--Cargo.lock3
-rw-r--r--Cargo.toml1
-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
-rw-r--r--zellij-tile/Cargo.toml4
-rw-r--r--zellij-tile/src/data.rs98
9 files changed, 108 insertions, 96 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 78ef1848..78536f80 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2305,6 +2305,7 @@ dependencies = [
"walkdir",
"wasmer",
"wasmer-wasi",
+ "xrdb",
"zellij-tile",
]
@@ -2312,10 +2313,8 @@ dependencies = [
name = "zellij-tile"
version = "0.5.0"
dependencies = [
- "colors-transform",
"serde",
"serde_json",
"strum",
"strum_macros",
- "xrdb",
]
diff --git a/Cargo.toml b/Cargo.toml
index 9d5696ec..94ebc472 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -37,6 +37,7 @@ lazy_static = "1.4.0"
wasmer = "1.0.0"
wasmer-wasi = "1.0.0"
interprocess = "1.0.1"
+xrdb = "0.1.1"
colors-transform = "0.2.5"
zellij-tile = { path = "zellij-tile/", version = "0.5.0" }
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)]
diff --git a/zellij-tile/Cargo.toml b/zellij-tile/Cargo.toml
index aa0fe088..eb9a2d59 100644
--- a/zellij-tile/Cargo.toml
+++ b/zellij-tile/Cargo.toml
@@ -10,6 +10,4 @@ license = "MIT"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
strum = "0.20.0"
-strum_macros = "0.20.0"
-xrdb = "0.1.1"
-colors-transform = "0.2.5" \ No newline at end of file
+strum_macros = "0.20.0" \ No newline at end of file
diff --git a/zellij-tile/src/data.rs b/zellij-tile/src/data.rs
index 315bc091..16f02531 100644
--- a/zellij-tile/src/data.rs
+++ b/zellij-tile/src/data.rs
@@ -1,89 +1,5 @@
-use colors_transform::{Color, Rgb};
use serde::{Deserialize, Serialize};
use strum_macros::{EnumDiscriminants, EnumIter, EnumString, ToString};
-use xrdb::Colors;
-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
- }
-}
-impl Default for Palette {
- fn default() -> Palette {
- Palette::new()
- }
-}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum Key {
@@ -142,6 +58,20 @@ impl Default for InputMode {
}
}
+#[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),
+}
+
/// Represents the contents of the help message that is printed in the status bar,
/// which indicates the current [`InputMode`] and what the keybinds for that mode
/// are. Related to the default `status-bar` plugin.