diff options
| author | a-kenji <aks.kenji@protonmail.com> | 2021-03-26 23:33:36 +0100 |
|---|---|---|
| committer | a-kenji <aks.kenji@protonmail.com> | 2021-03-26 23:33:36 +0100 |
| commit | 84488a35aa2cef3505e9b40f7f0345cff73d62c8 (patch) | |
| tree | 880d5019c40675177ea0402a186f6826d2bffa6f /src/client | |
| parent | Config: Fix README (diff) | |
| parent | feat(plugin): refactored to a new and more general plugin API (diff) | |
| download | sl0ppij-84488a35aa2cef3505e9b40f7f0345cff73d62c8.tar.gz sl0ppij-84488a35aa2cef3505e9b40f7f0345cff73d62c8.tar.xz sl0ppij-84488a35aa2cef3505e9b40f7f0345cff73d62c8.zip | |
Merge branch 'main' of https://github.com/zellij-org/zellij into config-file
Diffstat (limited to 'src/client')
| -rw-r--r-- | src/client/boundaries.rs | 128 | ||||
| -rw-r--r-- | src/client/layout.rs | 8 | ||||
| -rw-r--r-- | src/client/panes/plugin_pane.rs | 2 | ||||
| -rw-r--r-- | src/client/panes/terminal_character.rs | 10 | ||||
| -rw-r--r-- | src/client/panes/terminal_pane.rs | 36 | ||||
| -rw-r--r-- | src/client/tab.rs | 193 |
6 files changed, 220 insertions, 157 deletions
diff --git a/src/client/boundaries.rs b/src/client/boundaries.rs index 67733c12..e498da89 100644 --- a/src/client/boundaries.rs +++ b/src/client/boundaries.rs @@ -1,5 +1,7 @@ use crate::tab::Pane; +use ansi_term::Colour; use std::collections::HashMap; +use zellij_tile::data::InputMode; use std::fmt::{Display, Error, Formatter}; @@ -17,12 +19,20 @@ 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>, } impl BoundarySymbol { @@ -30,20 +40,27 @@ impl BoundarySymbol { BoundarySymbol { boundary_type, invisible: false, + color: Some(colors::GRAY), } } pub fn invisible(mut self) -> Self { self.invisible = true; self } + pub fn color(&mut self, color: Option<Colour>) -> Self { + self.color = color; + *self + } } impl Display for BoundarySymbol { fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { - if self.invisible { - write!(f, " ") - } else { - write!(f, "{}", self.boundary_type) + match self.invisible { + true => write!(f, " "), + false => match self.color { + Some(color) => write!(f, "{}", color.paint(self.boundary_type)), + None => write!(f, "{}", self.boundary_type), + }, } } } @@ -53,6 +70,10 @@ fn combine_symbols( next_symbol: BoundarySymbol, ) -> Option<BoundarySymbol> { let invisible = current_symbol.invisible || next_symbol.invisible; + let color = match (current_symbol.color.is_some(), next_symbol.color.is_some()) { + (true, _) => current_symbol.color, + _ => next_symbol.color, + }; let current_symbol = current_symbol.boundary_type; let next_symbol = next_symbol.boundary_type; match (current_symbol, next_symbol) { @@ -62,6 +83,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::TOP_RIGHT, boundary_type::VERTICAL) => { @@ -70,6 +92,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::TOP_RIGHT, boundary_type::HORIZONTAL) => { @@ -78,6 +101,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::TOP_RIGHT, boundary_type::TOP_LEFT) => { @@ -86,6 +110,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::TOP_RIGHT, boundary_type::BOTTOM_RIGHT) => { @@ -94,6 +119,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::TOP_RIGHT, boundary_type::BOTTOM_LEFT) => { @@ -102,6 +128,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::TOP_RIGHT, boundary_type::VERTICAL_LEFT) => { @@ -110,6 +137,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::TOP_RIGHT, boundary_type::VERTICAL_RIGHT) => { @@ -118,6 +146,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::TOP_RIGHT, boundary_type::HORIZONTAL_DOWN) => { @@ -126,6 +155,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::TOP_RIGHT, boundary_type::HORIZONTAL_UP) => { @@ -134,6 +164,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::TOP_RIGHT, boundary_type::CROSS) => { @@ -142,6 +173,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::HORIZONTAL, boundary_type::HORIZONTAL) => { @@ -150,6 +182,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::HORIZONTAL, boundary_type::VERTICAL) => { @@ -158,6 +191,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::HORIZONTAL, boundary_type::TOP_LEFT) => { @@ -166,6 +200,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::HORIZONTAL, boundary_type::BOTTOM_RIGHT) => { @@ -174,6 +209,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::HORIZONTAL, boundary_type::BOTTOM_LEFT) => { @@ -182,6 +218,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::HORIZONTAL, boundary_type::VERTICAL_LEFT) => { @@ -190,6 +227,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::HORIZONTAL, boundary_type::VERTICAL_RIGHT) => { @@ -198,6 +236,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::HORIZONTAL, boundary_type::HORIZONTAL_DOWN) => { @@ -206,6 +245,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::HORIZONTAL, boundary_type::HORIZONTAL_UP) => { @@ -214,6 +254,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::HORIZONTAL, boundary_type::CROSS) => { @@ -222,6 +263,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::VERTICAL, boundary_type::VERTICAL) => { @@ -230,6 +272,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::VERTICAL, boundary_type::TOP_LEFT) => { @@ -238,6 +281,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::VERTICAL, boundary_type::BOTTOM_RIGHT) => { @@ -246,6 +290,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::VERTICAL, boundary_type::BOTTOM_LEFT) => { @@ -254,6 +299,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::VERTICAL, boundary_type::VERTICAL_LEFT) => { @@ -262,6 +308,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::VERTICAL, boundary_type::VERTICAL_RIGHT) => { @@ -270,6 +317,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::VERTICAL, boundary_type::HORIZONTAL_DOWN) => { @@ -278,6 +326,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::VERTICAL, boundary_type::HORIZONTAL_UP) => { @@ -286,6 +335,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::VERTICAL, boundary_type::CROSS) => { @@ -294,6 +344,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::TOP_LEFT, boundary_type::TOP_LEFT) => { @@ -302,6 +353,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::TOP_LEFT, boundary_type::BOTTOM_RIGHT) => { @@ -310,6 +362,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::TOP_LEFT, boundary_type::BOTTOM_LEFT) => { @@ -318,6 +371,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::TOP_LEFT, boundary_type::VERTICAL_LEFT) => { @@ -326,6 +380,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::TOP_LEFT, boundary_type::VERTICAL_RIGHT) => { @@ -334,6 +389,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::TOP_LEFT, boundary_type::HORIZONTAL_DOWN) => { @@ -342,6 +398,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::TOP_LEFT, boundary_type::HORIZONTAL_UP) => { @@ -350,6 +407,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::TOP_LEFT, boundary_type::CROSS) => { @@ -358,6 +416,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::BOTTOM_RIGHT, boundary_type::BOTTOM_RIGHT) => { @@ -366,6 +425,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::BOTTOM_RIGHT, boundary_type::BOTTOM_LEFT) => { @@ -374,6 +434,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::BOTTOM_RIGHT, boundary_type::VERTICAL_LEFT) => { @@ -382,6 +443,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::BOTTOM_RIGHT, boundary_type::VERTICAL_RIGHT) => { @@ -390,6 +452,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::BOTTOM_RIGHT, boundary_type::HORIZONTAL_DOWN) => { @@ -398,6 +461,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::BOTTOM_RIGHT, boundary_type::HORIZONTAL_UP) => { @@ -406,6 +470,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::BOTTOM_RIGHT, boundary_type::CROSS) => { @@ -414,6 +479,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::BOTTOM_LEFT, boundary_type::BOTTOM_LEFT) => { @@ -422,6 +488,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::BOTTOM_LEFT, boundary_type::VERTICAL_LEFT) => { @@ -430,6 +497,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::BOTTOM_LEFT, boundary_type::VERTICAL_RIGHT) => { @@ -438,6 +506,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::BOTTOM_LEFT, boundary_type::HORIZONTAL_DOWN) => { @@ -446,6 +515,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::BOTTOM_LEFT, boundary_type::HORIZONTAL_UP) => { @@ -454,6 +524,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::BOTTOM_LEFT, boundary_type::CROSS) => { @@ -462,6 +533,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::VERTICAL_LEFT, boundary_type::VERTICAL_LEFT) => { @@ -470,6 +542,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::VERTICAL_LEFT, boundary_type::VERTICAL_RIGHT) => { @@ -478,6 +551,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::VERTICAL_LEFT, boundary_type::HORIZONTAL_DOWN) => { @@ -486,6 +560,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::VERTICAL_LEFT, boundary_type::HORIZONTAL_UP) => { @@ -494,6 +569,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::VERTICAL_LEFT, boundary_type::CROSS) => { @@ -502,6 +578,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::VERTICAL_RIGHT, boundary_type::VERTICAL_RIGHT) => { @@ -510,6 +587,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::VERTICAL_RIGHT, boundary_type::HORIZONTAL_DOWN) => { @@ -518,6 +596,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::VERTICAL_RIGHT, boundary_type::HORIZONTAL_UP) => { @@ -526,6 +605,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::VERTICAL_RIGHT, boundary_type::CROSS) => { @@ -534,6 +614,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::HORIZONTAL_DOWN, boundary_type::HORIZONTAL_DOWN) => { @@ -542,6 +623,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::HORIZONTAL_DOWN, boundary_type::HORIZONTAL_UP) => { @@ -550,6 +632,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::HORIZONTAL_DOWN, boundary_type::CROSS) => { @@ -558,6 +641,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::HORIZONTAL_UP, boundary_type::HORIZONTAL_UP) => { @@ -566,6 +650,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::HORIZONTAL_UP, boundary_type::CROSS) => { @@ -574,6 +659,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (boundary_type::CROSS, boundary_type::CROSS) => { @@ -582,6 +668,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + color, }) } (_, _) => None, @@ -677,7 +764,14 @@ impl Boundaries { boundary_characters: HashMap::new(), } } - pub fn add_rect(&mut self, rect: &dyn Pane) { + pub fn add_rect(&mut self, rect: &dyn Pane, input_mode: InputMode, color: Option<Colour>) { + let color = match color.is_some() { + true => match input_mode { + InputMode::Normal | InputMode::Locked => Some(colors::GREEN), + _ => Some(colors::WHITE), + }, + false => None, + }; if rect.x() > 0 { let boundary_x_coords = rect.x() - 1; let first_row_coordinates = self.rect_right_boundary_row_start(rect); @@ -685,11 +779,11 @@ impl Boundaries { for row in first_row_coordinates..last_row_coordinates { let coordinates = Coordinates::new(boundary_x_coords, row); let mut symbol_to_add = if row == first_row_coordinates && row != 0 { - BoundarySymbol::new(boundary_type::TOP_LEFT) + BoundarySymbol::new(boundary_type::TOP_LEFT).color(color) } else if row == last_row_coordinates - 1 && row != self.rows - 1 { - BoundarySymbol::new(boundary_type::BOTTOM_LEFT) + BoundarySymbol::new(boundary_type::BOTTOM_LEFT).color(color) } else { - BoundarySymbol::new(boundary_type::VERTICAL) + BoundarySymbol::new(boundary_type::VERTICAL).color(color) }; if rect.invisible_borders() { symbol_to_add = symbol_to_add.invisible(); @@ -709,11 +803,11 @@ impl Boundaries { for col in first_col_coordinates..last_col_coordinates { let coordinates = Coordinates::new(col, boundary_y_coords); let mut symbol_to_add = if col == first_col_coordinates && col != 0 { - BoundarySymbol::new(boundary_type::TOP_LEFT) + BoundarySymbol::new(boundary_type::TOP_LEFT).color(color) } else if col == last_col_coordinates - 1 && col != self.columns - 1 { - BoundarySymbol::new(boundary_type::TOP_RIGHT) + BoundarySymbol::new(boundary_type::TOP_RIGHT).color(color) } else { - BoundarySymbol::new(boundary_type::HORIZONTAL) + BoundarySymbol::new(boundary_type::HORIZONTAL).color(color) }; if rect.invisible_borders() { symbol_to_add = symbol_to_add.invisible(); @@ -734,11 +828,11 @@ impl Boundaries { for row in first_row_coordinates..last_row_coordinates { let coordinates = Coordinates::new(boundary_x_coords, row); let mut symbol_to_add = if row == first_row_coordinates && row != 0 { - BoundarySymbol::new(boundary_type::TOP_RIGHT) + BoundarySymbol::new(boundary_type::TOP_RIGHT).color(color) } else if row == last_row_coordinates - 1 && row != self.rows - 1 { - BoundarySymbol::new(boundary_type::BOTTOM_RIGHT) + BoundarySymbol::new(boundary_type::BOTTOM_RIGHT).color(color) } else { - BoundarySymbol::new(boundary_type::VERTICAL) + BoundarySymbol::new(boundary_type::VERTICAL).color(color) }; if rect.invisible_borders() { symbol_to_add = symbol_to_add.invisible(); @@ -758,11 +852,11 @@ impl Boundaries { for col in first_col_coordinates..last_col_coordinates { let coordinates = Coordinates::new(col, boundary_y_coords); let mut symbol_to_add = if col == first_col_coordinates && col != 0 { - BoundarySymbol::new(boundary_type::BOTTOM_LEFT) + BoundarySymbol::new(boundary_type::BOTTOM_LEFT).color(color) } else if col == last_col_coordinates - 1 && col != self.columns - 1 { - BoundarySymbol::new(boundary_type::BOTTOM_RIGHT) + BoundarySymbol::new(boundary_type::BOTTOM_RIGHT).color(color) } else { - BoundarySymbol::new(boundary_type::HORIZONTAL) + BoundarySymbol::new(boundary_type::HORIZONTAL).color(color) }; if rect.invisible_borders() { symbol_to_add = symbol_to_add.invisible(); diff --git a/src/client/layout.rs b/src/client/layout.rs index 1b383540..2d1daaf4 100644 --- a/src/client/layout.rs +++ b/src/client/layout.rs @@ -1,10 +1,8 @@ -use crate::utils::consts::ZELLIJ_ROOT_LAYOUT_DIR; use directories_next::ProjectDirs; use serde::{Deserialize, Serialize}; -use std::path::{Path, PathBuf}; +use std::path::PathBuf; use std::{fs::File, io::prelude::*}; -use crate::common::wasm_vm::EventType; use crate::panes::PositionAndSize; fn split_space_to_parts_vertically( @@ -181,19 +179,15 @@ pub struct Layout { pub plugin: Option<PathBuf>, #[serde(default)] pub expansion_boundary: bool, - #[serde(default, skip_serializing_if = "Vec::is_empty")] - pub events: Vec<EventType>, } impl Layout { pub fn new(layout_path: PathBuf) -> Self { let project_dirs = ProjectDirs::from("org", "Zellij Contributors", "Zellij").unwrap(); let layout_dir = project_dirs.data_dir().join("layouts/"); - let root_layout_dir = Path::new(ZELLIJ_ROOT_LAYOUT_DIR); let mut layout_file = File::open(&layout_path) .or_else(|_| File::open(&layout_path.with_extension("yaml"))) .or_else(|_| File::open(&layout_dir.join(&layout_path).with_extension("yaml"))) - .or_else(|_| File::open(root_layout_dir.join(&layout_path).with_extension("yaml"))) .unwrap_or_else(|_| panic!("cannot find layout {}", &layout_path.display())); let mut layout = String::new(); diff --git a/src/client/panes/plugin_pane.rs b/src/client/panes/plugin_pane.rs index 588cffd6..4cffff5f 100644 --- a/src/client/panes/plugin_pane.rs +++ b/src/client/panes/plugin_pane.rs @@ -120,7 +120,7 @@ impl Pane for PluginPane { let (buf_tx, buf_rx) = channel(); self.send_plugin_instructions - .send(PluginInstruction::Draw( + .send(PluginInstruction::Render( buf_tx, self.pid, self.rows(), diff --git a/src/client/panes/terminal_character.rs b/src/client/panes/terminal_character.rs index 80c3162b..053ebd3f 100644 --- a/src/client/panes/terminal_character.rs +++ b/src/client/panes/terminal_character.rs @@ -23,7 +23,7 @@ pub enum AnsiCode { On, Reset, NamedColor(NamedColor), - RGBCode((u8, u8, u8)), + RgbCode((u8, u8, u8)), ColorIndex(u8), } @@ -336,7 +336,7 @@ impl CharacterStyles { [36, ..] => *self = self.foreground(Some(AnsiCode::NamedColor(NamedColor::Cyan))), [37, ..] => *self = self.foreground(Some(AnsiCode::NamedColor(NamedColor::White))), [38, 2, ..] => { - let ansi_code = AnsiCode::RGBCode(( + let ansi_code = AnsiCode::RgbCode(( *ansi_params.get(2).unwrap() as u8, *ansi_params.get(3).unwrap() as u8, *ansi_params.get(4).unwrap() as u8, @@ -364,7 +364,7 @@ impl CharacterStyles { [46, ..] => *self = self.background(Some(AnsiCode::NamedColor(NamedColor::Cyan))), [47, ..] => *self = self.background(Some(AnsiCode::NamedColor(NamedColor::White))), [48, 2, ..] => { - let ansi_code = AnsiCode::RGBCode(( + let ansi_code = AnsiCode::RgbCode(( *ansi_params.get(2).unwrap() as u8, *ansi_params.get(3).unwrap() as u8, *ansi_params.get(4).unwrap() as u8, @@ -416,7 +416,7 @@ impl Display for CharacterStyles { } if let Some(ansi_code) = self.foreground { match ansi_code { - AnsiCode::RGBCode((r, g, b)) => { + AnsiCode::RgbCode((r, g, b)) => { write!(f, "\u{1b}[38;2;{};{};{}m", r, g, b)?; } AnsiCode::ColorIndex(color_index) => { @@ -433,7 +433,7 @@ impl Display for CharacterStyles { }; if let Some(ansi_code) = self.background { match ansi_code { - AnsiCode::RGBCode((r, g, b)) => { + AnsiCode::RgbCode((r, g, b)) => { write!(f, "\u{1b}[48;2;{};{};{}m", r, g, b)?; } AnsiCode::ColorIndex(color_index) => { diff --git a/src/client/panes/terminal_pane.rs b/src/client/panes/terminal_pane.rs index fd83d571..f0b15e50 100644 --- a/src/client/panes/terminal_pane.rs +++ b/src/client/panes/terminal_pane.rs @@ -70,13 +70,11 @@ impl Pane for TerminalPane { fn reset_size_and_position_override(&mut self) { self.position_and_size_override = None; self.reflow_lines(); - self.mark_for_rerender(); } fn change_pos_and_size(&mut self, position_and_size: &PositionAndSize) { self.position_and_size.columns = position_and_size.columns; self.position_and_size.rows = position_and_size.rows; self.reflow_lines(); - self.mark_for_rerender(); } fn override_size_and_position(&mut self, x: usize, y: usize, size: &PositionAndSize) { let position_and_size_override = PositionAndSize { @@ -87,7 +85,6 @@ impl Pane for TerminalPane { }; self.position_and_size_override = Some(position_and_size_override); self.reflow_lines(); - self.mark_for_rerender(); } fn handle_event(&mut self, event: VteEvent) { match event { @@ -191,12 +188,14 @@ impl Pane for TerminalPane { self.max_height } fn render(&mut self) -> Option<String> { - // if self.should_render { + // FIXME: + // the below conditional is commented out because it causes several bugs: + // 1. When panes are resized or tabs are switched the previous contents of the screen stick + // around + // 2. When there are wide characters in a pane, since we don't yet handle them properly, + // the spill over to the pane to the right + // if self.should_render || cfg!(test) { if true { - // while checking should_render rather than rendering each pane every time - // is more performant, it causes some problems when the pane to the left should be - // rendered and has wide characters (eg. Chinese characters or emoji) - // as a (hopefully) temporary hack, we render all panes until we find a better solution let mut vte_output = String::new(); let buffer_lines = &self.read_buffer_as_lines(); let display_cols = self.get_columns(); @@ -205,12 +204,11 @@ impl Pane for TerminalPane { for line_index in 0..self.grid.height { let x = self.get_x(); let y = self.get_y(); - vte_output = format!( - "{}\u{1b}[{};{}H\u{1b}[m", - vte_output, + vte_output.push_str(&format!( + "\u{1b}[{};{}H\u{1b}[m", y + line_index + 1, x + 1 - ); // goto row/col and reset styles + )); // goto row/col and reset styles for _col_index in 0..self.grid.width { vte_output.push(EMPTY_TERMINAL_CHARACTER.character); } @@ -220,7 +218,7 @@ impl Pane for TerminalPane { for (row, line) in buffer_lines.iter().enumerate() { let x = self.get_x(); let y = self.get_y(); - vte_output = format!("{}\u{1b}[{};{}H\u{1b}[m", vte_output, y + row + 1, x + 1); // goto row/col and reset styles + vte_output.push_str(&format!("\u{1b}[{};{}H\u{1b}[m", y + row + 1, x + 1)); // goto row/col and reset styles for (col, t_character) in line.iter().enumerate() { if col < display_cols { // in some cases (eg. while resizing) some characters will spill over @@ -232,14 +230,14 @@ impl Pane for TerminalPane { // the terminal keeps the previous styles as long as we're in the same // line, so we only want to update the new styles here (this also // includes resetting previous styles as needed) - vte_output = format!("{}{}", vte_output, new_styles); + vte_output.push_str(&new_styles.to_string()); } vte_output.push(t_character.character); } } character_styles.clear(); } - self.mark_for_rerender(); + self.should_render = false; Some(vte_output) } else { None @@ -252,45 +250,37 @@ impl Pane for TerminalPane { self.position_and_size.y += count; self.position_and_size.rows -= count; self.reflow_lines(); - self.mark_for_rerender(); } fn increase_height_down(&mut self, count: usize) { self.position_and_size.rows += count; self.reflow_lines(); - self.mark_for_rerender(); } fn increase_height_up(&mut self, count: usize) { self.position_and_size.y -= count; self.position_and_size.rows += count; self.reflow_lines(); - self.mark_for_rerender(); } fn reduce_height_up(&mut self, count: usize) { self.position_and_size.rows -= count; self.reflow_lines(); - self.mark_for_rerender(); } fn reduce_width_right(&mut self, count: usize) { self.position_and_size.x += count; self.position_and_size.columns -= count; self.reflow_lines(); - self.mark_for_rerender(); } fn reduce_width_left(&mut self, count: usize) { self.position_and_size.columns -= count; self.reflow_lines(); - self.mark_for_rerender(); } fn increase_width_left(&mut self, count: usize) { self.position_and_size.x -= count; self.position_and_size.columns += count; self.reflow_lines(); - self.mark_for_rerender(); } fn increase_width_right(&mut self, count: usize) { self.position_and_size.columns += count; self.reflow_lines(); - self.mark_for_rerender(); } fn scroll_up(&mut self, count: usize) { self.grid.move_viewport_up(count); diff --git a/src/client/tab.rs b/src/client/tab.rs index 1ef0b720..1e56fd8b 100644 --- a/src/client/tab.rs +++ b/src/client/tab.rs @@ -1,20 +1,21 @@ //! `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, SenderWithContext}; +use crate::boundaries::colors; +use crate::common::{input::handler::parse_keys, AppInstruction, SenderWithContext}; use crate::layout::Layout; use crate::panes::{PaneId, PositionAndSize, TerminalPane}; use crate::pty_bus::{PtyInstruction, VteEvent}; -use crate::wasm_vm::{PluginInputType, PluginInstruction}; +use crate::wasm_vm::PluginInstruction; use crate::{boundaries::Boundaries, panes::PluginPane}; use crate::{os_input_output::OsApi, utils::shared::pad_to_size}; -use serde::{Deserialize, Serialize}; use std::os::unix::io::RawFd; use std::{ cmp::Reverse, collections::{BTreeMap, HashSet}, }; use std::{io::Write, sync::mpsc::channel}; +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; @@ -65,14 +66,7 @@ pub struct Tab { pub send_plugin_instructions: SenderWithContext<PluginInstruction>, pub send_app_instructions: SenderWithContext<AppInstruction>, expansion_boundary: Option<PositionAndSize>, -} - -#[derive(Clone, Debug, Default, Serialize, Deserialize)] -pub struct TabData { - /* subset of fields to publish to plugins */ - pub position: usize, - pub name: String, - pub active: bool, + pub input_mode: InputMode, } // FIXME: Use a struct that has a pane_type enum, to reduce all of the duplication @@ -189,6 +183,7 @@ impl Tab { send_app_instructions: SenderWithContext<AppInstruction>, max_panes: Option<usize>, pane_id: Option<PaneId>, + input_mode: InputMode, ) -> Self { let panes = if let Some(PaneId::Terminal(pid)) = pane_id { let new_terminal = TerminalPane::new(pid, *full_screen_ws); @@ -218,6 +213,7 @@ impl Tab { send_pty_instructions, send_plugin_instructions, expansion_boundary: None, + input_mode, } } @@ -262,11 +258,7 @@ impl Tab { if let Some(plugin) = &layout.plugin { let (pid_tx, pid_rx) = channel(); self.send_plugin_instructions - .send(PluginInstruction::Load( - pid_tx, - plugin.clone(), - layout.events.clone(), - )) + .send(PluginInstruction::Load(pid_tx, plugin.clone())) .unwrap(); let pid = pid_rx.recv().unwrap(); let new_plugin = PluginPane::new( @@ -305,7 +297,6 @@ impl Tab { self.toggle_active_pane_fullscreen(); } if !self.has_panes() { - // FIXME: This could use a second look if let PaneId::Terminal(term_pid) = pid { let new_terminal = TerminalPane::new(term_pid, self.full_screen_ws); self.os_api.set_terminal_size_using_fd( @@ -356,7 +347,6 @@ impl Tab { if terminal_to_split.rows() * CURSOR_HEIGHT_WIDTH_RATIO > terminal_to_split.columns() && terminal_to_split.rows() > terminal_to_split.min_height() * 2 { - // FIXME: This could use a second look if let PaneId::Terminal(term_pid) = pid { let (top_winsize, bottom_winsize) = split_horizontally_with_gap(&terminal_ws); let new_terminal = TerminalPane::new(term_pid, bottom_winsize); @@ -377,7 +367,6 @@ impl Tab { self.active_terminal = Some(pid); } } else if terminal_to_split.columns() > terminal_to_split.min_width() * 2 { - // FIXME: This could use a second look if let PaneId::Terminal(term_pid) = pid { let (left_winsize, right_winsize) = split_vertically_with_gap(&terminal_ws); let new_terminal = TerminalPane::new(term_pid, right_winsize); @@ -407,7 +396,6 @@ impl Tab { self.toggle_active_pane_fullscreen(); } if !self.has_panes() { - // FIXME: This could use a second look if let PaneId::Terminal(term_pid) = pid { let new_terminal = TerminalPane::new(term_pid, self.full_screen_ws); self.os_api.set_terminal_size_using_fd( @@ -418,47 +406,44 @@ impl Tab { self.panes.insert(pid, Box::new(new_terminal)); self.active_terminal = Some(pid); } - } else { - // FIXME: This could use a second look - if let PaneId::Terminal(term_pid) = pid { - // TODO: check minimum size of active terminal - let active_pane_id = &self.get_active_pane_id().unwrap(); - let active_pane = self.panes.get_mut(active_pane_id).unwrap(); - if active_pane.rows() < MIN_TERMINAL_HEIGHT * 2 + 1 { - self.send_pty_instructions - .send(PtyInstruction::ClosePane(pid)) // we can't open this pane, close the pty - .unwrap(); - return; - } - let terminal_ws = PositionAndSize { - x: active_pane.x(), - y: active_pane.y(), - rows: active_pane.rows(), - columns: active_pane.columns(), - }; - let (top_winsize, bottom_winsize) = split_horizontally_with_gap(&terminal_ws); + } else if let PaneId::Terminal(term_pid) = pid { + // TODO: check minimum size of active terminal + let active_pane_id = &self.get_active_pane_id().unwrap(); + let active_pane = self.panes.get_mut(active_pane_id).unwrap(); + if active_pane.rows() < MIN_TERMINAL_HEIGHT * 2 + 1 { + self.send_pty_instructions + .send(PtyInstruction::ClosePane(pid)) // we can't open this pane, close the pty + .unwrap(); + return; + } + let terminal_ws = PositionAndSize { + x: active_pane.x(), + y: active_pane.y(), + rows: active_pane.rows(), + columns: active_pane.columns(), + }; + let (top_winsize, bottom_winsize) = split_horizontally_with_gap(&terminal_ws); + + active_pane.change_pos_and_size(&top_winsize); - active_pane.change_pos_and_size(&top_winsize); + let new_terminal = TerminalPane::new(term_pid, bottom_winsize); + self.os_api.set_terminal_size_using_fd( + new_terminal.pid, + bottom_winsize.columns as u16, + bottom_winsize.rows as u16, + ); + self.panes.insert(pid, Box::new(new_terminal)); - let new_terminal = TerminalPane::new(term_pid, bottom_winsize); + if let PaneId::Terminal(active_terminal_pid) = active_pane_id { self.os_api.set_terminal_size_using_fd( - new_terminal.pid, - bottom_winsize.columns as u16, - bottom_winsize.rows as u16, + *active_terminal_pid, + top_winsize.columns as u16, + top_winsize.rows as u16, ); - self.panes.insert(pid, Box::new(new_terminal)); - - if let PaneId::Terminal(active_terminal_pid) = active_pane_id { - self.os_api.set_terminal_size_using_fd( - *active_terminal_pid, - top_winsize.columns as u16, - top_winsize.rows as u16, - ); - } - - self.active_terminal = Some(pid); - self.render(); } + + self.active_terminal = Some(pid); + self.render(); } } pub fn vertical_split(&mut self, pid: PaneId) { @@ -467,7 +452,6 @@ impl Tab { self.toggle_active_pane_fullscreen(); } if !self.has_panes() { - // FIXME: This could use a second look if let PaneId::Terminal(term_pid) = pid { let new_terminal = TerminalPane::new(term_pid, self.full_screen_ws); self.os_api.set_terminal_size_using_fd( @@ -478,47 +462,44 @@ impl Tab { self.panes.insert(pid, Box::new(new_terminal)); self.active_terminal = Some(pid); } - } else { - // FIXME: This could use a second look - if let PaneId::Terminal(term_pid) = pid { - // TODO: check minimum size of active terminal - let active_pane_id = &self.get_active_pane_id().unwrap(); - let active_pane = self.panes.get_mut(active_pane_id).unwrap(); - if active_pane.columns() < MIN_TERMINAL_WIDTH * 2 + 1 { - self.send_pty_instructions - .send(PtyInstruction::ClosePane(pid)) // we can't open this pane, close the pty - .unwrap(); - return; - } - let terminal_ws = PositionAndSize { - x: active_pane.x(), - y: active_pane.y(), - rows: active_pane.rows(), - columns: active_pane.columns(), - }; - let (left_winsize, right_winsize) = split_vertically_with_gap(&terminal_ws); + } else if let PaneId::Terminal(term_pid) = pid { + // TODO: check minimum size of active terminal + let active_pane_id = &self.get_active_pane_id().unwrap(); + let active_pane = self.panes.get_mut(active_pane_id).unwrap(); + if active_pane.columns() < MIN_TERMINAL_WIDTH * 2 + 1 { + self.send_pty_instructions + .send(PtyInstruction::ClosePane(pid)) // we can't open this pane, close the pty + .unwrap(); + return; + } + let terminal_ws = PositionAndSize { + x: active_pane.x(), + y: active_pane.y(), + rows: active_pane.rows(), + columns: active_pane.columns(), + }; + let (left_winsize, right_winsize) = split_vertically_with_gap(&terminal_ws); - active_pane.change_pos_and_size(&left_winsize); + active_pane.change_pos_and_size(&left_winsize); + + let new_terminal = TerminalPane::new(term_pid, right_winsize); + self.os_api.set_terminal_size_using_fd( + new_terminal.pid, + right_winsize.columns as u16, + right_winsize.rows as u16, + ); + self.panes.insert(pid, Box::new(new_terminal)); - let new_terminal = TerminalPane::new(term_pid, right_winsize); + if let PaneId::Terminal(active_terminal_pid) = active_pane_id { self.os_api.set_terminal_size_using_fd( - new_terminal.pid, - right_winsize.columns as u16, - right_winsize.rows as u16, + *active_terminal_pid, + left_winsize.columns as u16, + left_winsize.rows as u16, ); - self.panes.insert(pid, Box::new(new_terminal)); - - if let PaneId::Terminal(active_terminal_pid) = active_pane_id { - self.os_api.set_terminal_size_using_fd( - *active_terminal_pid, - left_winsize.columns as u16, - left_winsize.rows as u16, - ); - } - - self.active_terminal = Some(pid); - self.render(); } + + self.active_terminal = Some(pid); + self.render(); } } pub fn get_active_pane(&self) -> Option<&dyn Pane> { @@ -562,12 +543,11 @@ impl Tab { .expect("failed to drain terminal"); } Some(PaneId::Plugin(pid)) => { - self.send_plugin_instructions - .send(PluginInstruction::Input( - PluginInputType::Normal(pid), - input_bytes, - )) - .unwrap(); + for key in parse_keys(&input_bytes) { + self.send_plugin_instructions + .send(PluginInstruction::Update(Some(pid), Event::KeyPress(key))) + .unwrap() + } } _ => {} } @@ -645,7 +625,12 @@ impl Tab { .expect("cannot write to stdout"); for (kind, terminal) in self.panes.iter_mut() { if !self.panes_to_hide.contains(&terminal.pid()) { - boundaries.add_rect(terminal.as_ref()); + match self.active_terminal.unwrap() == terminal.pid() { + true => { + boundaries.add_rect(terminal.as_ref(), self.input_mode, Some(colors::GREEN)) + } + false => boundaries.add_rect(terminal.as_ref(), self.input_mode, None), + } if let Some(vte_output) = terminal.render() { let vte_output = if let PaneId::Terminal(_) = kind { vte_output @@ -1679,8 +1664,8 @@ impl Tab { } else if self.can_reduce_pane_and_surroundings_right(&active_pane_id, count) { self.reduce_pane_and_surroundings_right(&active_pane_id, count); } - self.render(); } + self.render(); } pub fn resize_left(&mut self) { // TODO: find out by how much we actually reduced and only reduce by that much @@ -1691,8 +1676,8 @@ impl Tab { } else if self.can_reduce_pane_and_surroundings_left(&active_pane_id, count) { self.reduce_pane_and_surroundings_left(&active_pane_id, count); } - self.render(); } + self.render(); } pub fn resize_down(&mut self) { // TODO: find out by how much we actually reduced and only reduce by that much @@ -1703,8 +1688,8 @@ impl Tab { } else if self.can_reduce_pane_and_surroundings_down(&active_pane_id, count) { self.reduce_pane_and_surroundings_down(&active_pane_id, count); } - self.render(); } + self.render(); } pub fn resize_up(&mut self) { // TODO: find out by how much we actually reduced and only reduce by that much @@ -1715,8 +1700,8 @@ impl Tab { } else if self.can_reduce_pane_and_surroundings_up(&active_pane_id, count) { self.reduce_pane_and_surroundings_up(&active_pane_id, count); } - self.render(); } + self.render(); } pub fn move_focus(&mut self) { if !self.has_selectable_panes() { |
