wip: replace the impl with a fn load_palette instead

This commit is contained in:
denis 2021-03-28 10:51:15 +03:00
parent 6e276ae386
commit 42890d4e64
5 changed files with 59 additions and 78 deletions

View file

@ -1,8 +1,8 @@
use crate::common::{colors, Palette}; use crate::common::colors;
use crate::tab::Pane; use crate::tab::Pane;
use ansi_term::Colour::RGB; use ansi_term::Colour::RGB;
use std::collections::HashMap; use std::collections::HashMap;
use zellij_tile::data::InputMode; use zellij_tile::data::{InputMode, Palette};
use std::fmt::{Display, Error, Formatter}; use std::fmt::{Display, Error, Formatter};
pub mod boundary_type { pub mod boundary_type {

View file

@ -1,9 +1,7 @@
//! `Tab`s holds multiple panes. It tracks their coordinates (x/y) and size, //! `Tab`s holds multiple panes. It tracks their coordinates (x/y) and size,
//! as well as how they should be resized //! as well as how they should be resized
use crate::common::{ use crate::common::{colors, input::handler::parse_keys, AppInstruction, SenderWithContext};
colors, input::handler::parse_keys, AppInstruction, Palette, SenderWithContext,
};
use crate::layout::Layout; use crate::layout::Layout;
use crate::panes::{PaneId, PositionAndSize, TerminalPane}; use crate::panes::{PaneId, PositionAndSize, TerminalPane};
use crate::pty_bus::{PtyInstruction, VteEvent}; use crate::pty_bus::{PtyInstruction, VteEvent};
@ -16,7 +14,7 @@ use std::{
collections::{BTreeMap, HashSet}, collections::{BTreeMap, HashSet},
}; };
use std::{io::Write, sync::mpsc::channel}; 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 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; const MIN_TERMINAL_HEIGHT: usize = 2;

View file

@ -2,7 +2,7 @@
use super::actions::Action; use super::actions::Action;
use super::keybinds::get_default_keybinds; 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::errors::ContextType;
use crate::os_input_output::OsApi; use crate::os_input_output::OsApi;
use crate::pty_bus::PtyInstruction; use crate::pty_bus::PtyInstruction;
@ -256,7 +256,7 @@ impl InputHandler {
// TODO this should probably be automatically generated in some way // TODO this should probably be automatically generated in some way
pub fn get_mode_info(mode: InputMode) -> ModeInfo { pub fn get_mode_info(mode: InputMode) -> ModeInfo {
let mut keybinds: Vec<(String, String)> = vec![]; let mut keybinds: Vec<(String, String)> = vec![];
let mut palette = Palette::new(); let mut palette = load_palette();
match mode { match mode {
InputMode::Normal | InputMode::Locked => {} InputMode::Normal | InputMode::Locked => {}
InputMode::Resize => { InputMode::Resize => {

View file

@ -39,7 +39,7 @@ use wasm_vm::{wasi_stdout, wasi_write_string, zellij_imports, PluginInstruction}
use wasmer::{ChainableNamedResolver, Instance, Module, Store, Value}; use wasmer::{ChainableNamedResolver, Instance, Module, Store, Value};
use wasmer_wasi::{Pipe, WasiState}; use wasmer_wasi::{Pipe, WasiState};
use xrdb::Colors; use xrdb::Colors;
use zellij_tile::data::{EventType, InputMode}; use zellij_tile::data::{EventType, InputMode, Palette};
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub enum ApiCommand { pub enum ApiCommand {
@ -126,22 +126,7 @@ pub mod colors {
pub const BLACK: (u8, u8, u8) = (0, 0, 0); pub const BLACK: (u8, u8, u8) = (0, 0, 0);
} }
#[derive(Clone, Copy, Debug, Serialize, Deserialize)] pub fn load_palette() -> Palette {
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") { let palette = match Colors::new("xresources") {
Some(colors) => { Some(colors) => {
let fg = colors.fg.unwrap(); let fg = colors.fg.unwrap();
@ -165,7 +150,7 @@ impl Palette {
(rgb.0 as u8, rgb.1 as u8, rgb.2 as u8) (rgb.0 as u8, rgb.1 as u8, rgb.2 as u8)
}) })
.collect(); .collect();
Self { Palette {
fg, fg,
bg, bg,
black: colors[0], black: colors[0],
@ -178,7 +163,7 @@ impl Palette {
white: colors[7], white: colors[7],
} }
} }
None => Self { None => Palette {
fg: colors::BRIGHT_GRAY, fg: colors::BRIGHT_GRAY,
bg: colors::BLACK, bg: colors::BLACK,
black: colors::BLACK, black: colors::BLACK,
@ -192,7 +177,6 @@ impl Palette {
}, },
}; };
palette palette
}
} }
/// Start Zellij with the specified [`OsApi`] and command-line arguments. /// Start Zellij with the specified [`OsApi`] and command-line arguments.
@ -326,7 +310,7 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs) {
let send_plugin_instructions = send_plugin_instructions.clone(); let send_plugin_instructions = send_plugin_instructions.clone();
let send_app_instructions = send_app_instructions.clone(); let send_app_instructions = send_app_instructions.clone();
let max_panes = opts.max_panes; let max_panes = opts.max_panes;
let colors = Palette::new(); let colors = load_palette();
// debug_log_to_file(format!("{:?}", colors)); // debug_log_to_file(format!("{:?}", colors));
move || { move || {
let mut screen = Screen::new( let mut screen = Screen::new(

View file

@ -6,7 +6,6 @@ use std::str;
use std::sync::mpsc::Receiver; use std::sync::mpsc::Receiver;
use super::{AppInstruction, SenderWithContext}; use super::{AppInstruction, SenderWithContext};
use crate::common::Palette;
use crate::os_input_output::OsApi; use crate::os_input_output::OsApi;
use crate::panes::PositionAndSize; use crate::panes::PositionAndSize;
use crate::pty_bus::{PtyInstruction, VteEvent}; use crate::pty_bus::{PtyInstruction, VteEvent};
@ -14,7 +13,7 @@ use crate::tab::Tab;
use crate::{errors::ErrorContext, wasm_vm::PluginInstruction}; use crate::{errors::ErrorContext, wasm_vm::PluginInstruction};
use crate::{layout::Layout, panes::PaneId}; 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`]. /// Instructions that can be sent to the [`Screen`].
#[derive(Debug, Clone)] #[derive(Debug, Clone)]