From 1a5d30d17d5b05f3a9c7372b78071d40363396aa Mon Sep 17 00:00:00 2001 From: denis Date: Sun, 7 Mar 2021 18:39:44 +0200 Subject: [PATCH 01/12] wip: visually marking the focused pane --- Cargo.lock | 12 ++- Cargo.toml | 1 + src/client/boundaries.rs | 189 +++++++++++++++++++++++++++++++++++---- src/client/tab.rs | 5 +- 4 files changed, 187 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index eb1b291e..4bfc89cb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -24,6 +24,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "ansi_term" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" +dependencies = [ + "winapi", +] + [[package]] name = "arrayvec" version = "0.5.2" @@ -280,7 +289,7 @@ version = "2.33.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" dependencies = [ - "ansi_term", + "ansi_term 0.11.0", "atty", "bitflags", "strsim 0.8.0", @@ -2240,6 +2249,7 @@ dependencies = [ name = "zellij" version = "0.2.1" dependencies = [ + "ansi_term 0.12.1", "async-std", "backtrace", "bincode", diff --git a/Cargo.toml b/Cargo.toml index 1d9ac68f..a811c5a1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ publish = [] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +ansi_term = "0.12.1" backtrace = "0.3.55" bincode = "1.3.1" directories-next = "2.0" diff --git a/src/client/boundaries.rs b/src/client/boundaries.rs index 67733c12..70159f9b 100644 --- a/src/client/boundaries.rs +++ b/src/client/boundaries.rs @@ -1,5 +1,7 @@ use crate::tab::Pane; use std::collections::HashMap; +use ansi_term::Colour::*; +use super::super::utils::logging::debug_log_to_file; use std::fmt::{Display, Error, Formatter}; @@ -23,27 +25,43 @@ pub type BoundaryType = &'static str; // easy way to refer to boundary_type abov pub struct BoundarySymbol { boundary_type: BoundaryType, invisible: bool, + should_be_colored: bool, + color: ansi_term::Colour } impl BoundarySymbol { - pub fn new(boundary_type: BoundaryType) -> Self { + pub fn new(boundary_type: BoundaryType, should_be_colored: bool) -> Self { BoundarySymbol { boundary_type, invisible: false, + should_be_colored, + color: match should_be_colored { + true => ansi_term::Colour::Red, + false => ansi_term::Colour::White + } } } pub fn invisible(mut self) -> Self { self.invisible = true; self } + pub fn color(mut self, color: ansi_term::Colour) -> Self { + self.color = color; + self.should_be_colored = true; + 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.should_be_colored { + true => write!(f, "{}", self.color.paint(self.boundary_type)), + false => write!(f, "{}", self.boundary_type) + } + } } } } @@ -53,6 +71,8 @@ fn combine_symbols( next_symbol: BoundarySymbol, ) -> Option { let invisible = current_symbol.invisible || next_symbol.invisible; + let should_be_colored = current_symbol.should_be_colored || next_symbol.should_be_colored; + let 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 +82,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::TOP_RIGHT, boundary_type::VERTICAL) => { @@ -70,6 +92,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::TOP_RIGHT, boundary_type::HORIZONTAL) => { @@ -78,6 +102,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::TOP_RIGHT, boundary_type::TOP_LEFT) => { @@ -86,6 +112,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::TOP_RIGHT, boundary_type::BOTTOM_RIGHT) => { @@ -94,6 +122,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::TOP_RIGHT, boundary_type::BOTTOM_LEFT) => { @@ -102,6 +132,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::TOP_RIGHT, boundary_type::VERTICAL_LEFT) => { @@ -110,6 +142,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::TOP_RIGHT, boundary_type::VERTICAL_RIGHT) => { @@ -118,6 +152,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::TOP_RIGHT, boundary_type::HORIZONTAL_DOWN) => { @@ -126,6 +162,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::TOP_RIGHT, boundary_type::HORIZONTAL_UP) => { @@ -134,6 +172,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::TOP_RIGHT, boundary_type::CROSS) => { @@ -142,6 +182,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::HORIZONTAL, boundary_type::HORIZONTAL) => { @@ -150,6 +192,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::HORIZONTAL, boundary_type::VERTICAL) => { @@ -158,6 +202,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::HORIZONTAL, boundary_type::TOP_LEFT) => { @@ -166,6 +212,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::HORIZONTAL, boundary_type::BOTTOM_RIGHT) => { @@ -174,6 +222,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::HORIZONTAL, boundary_type::BOTTOM_LEFT) => { @@ -182,6 +232,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::HORIZONTAL, boundary_type::VERTICAL_LEFT) => { @@ -190,6 +242,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::HORIZONTAL, boundary_type::VERTICAL_RIGHT) => { @@ -198,6 +252,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::HORIZONTAL, boundary_type::HORIZONTAL_DOWN) => { @@ -206,6 +262,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::HORIZONTAL, boundary_type::HORIZONTAL_UP) => { @@ -214,6 +272,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::HORIZONTAL, boundary_type::CROSS) => { @@ -222,6 +282,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::VERTICAL, boundary_type::VERTICAL) => { @@ -230,6 +292,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::VERTICAL, boundary_type::TOP_LEFT) => { @@ -238,6 +302,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::VERTICAL, boundary_type::BOTTOM_RIGHT) => { @@ -246,6 +312,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::VERTICAL, boundary_type::BOTTOM_LEFT) => { @@ -254,6 +322,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::VERTICAL, boundary_type::VERTICAL_LEFT) => { @@ -262,6 +332,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::VERTICAL, boundary_type::VERTICAL_RIGHT) => { @@ -270,6 +342,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::VERTICAL, boundary_type::HORIZONTAL_DOWN) => { @@ -278,6 +352,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::VERTICAL, boundary_type::HORIZONTAL_UP) => { @@ -286,6 +362,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::VERTICAL, boundary_type::CROSS) => { @@ -294,6 +372,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::TOP_LEFT, boundary_type::TOP_LEFT) => { @@ -302,6 +382,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::TOP_LEFT, boundary_type::BOTTOM_RIGHT) => { @@ -310,6 +392,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::TOP_LEFT, boundary_type::BOTTOM_LEFT) => { @@ -318,6 +402,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::TOP_LEFT, boundary_type::VERTICAL_LEFT) => { @@ -326,6 +412,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::TOP_LEFT, boundary_type::VERTICAL_RIGHT) => { @@ -334,6 +422,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::TOP_LEFT, boundary_type::HORIZONTAL_DOWN) => { @@ -342,6 +432,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::TOP_LEFT, boundary_type::HORIZONTAL_UP) => { @@ -350,6 +442,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::TOP_LEFT, boundary_type::CROSS) => { @@ -358,6 +452,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::BOTTOM_RIGHT, boundary_type::BOTTOM_RIGHT) => { @@ -366,6 +462,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::BOTTOM_RIGHT, boundary_type::BOTTOM_LEFT) => { @@ -374,6 +472,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::BOTTOM_RIGHT, boundary_type::VERTICAL_LEFT) => { @@ -382,6 +482,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::BOTTOM_RIGHT, boundary_type::VERTICAL_RIGHT) => { @@ -390,6 +492,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::BOTTOM_RIGHT, boundary_type::HORIZONTAL_DOWN) => { @@ -398,6 +502,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::BOTTOM_RIGHT, boundary_type::HORIZONTAL_UP) => { @@ -406,6 +512,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::BOTTOM_RIGHT, boundary_type::CROSS) => { @@ -414,6 +522,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::BOTTOM_LEFT, boundary_type::BOTTOM_LEFT) => { @@ -422,6 +532,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::BOTTOM_LEFT, boundary_type::VERTICAL_LEFT) => { @@ -430,6 +542,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::BOTTOM_LEFT, boundary_type::VERTICAL_RIGHT) => { @@ -438,6 +552,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::BOTTOM_LEFT, boundary_type::HORIZONTAL_DOWN) => { @@ -446,6 +562,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::BOTTOM_LEFT, boundary_type::HORIZONTAL_UP) => { @@ -454,6 +572,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::BOTTOM_LEFT, boundary_type::CROSS) => { @@ -462,6 +582,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::VERTICAL_LEFT, boundary_type::VERTICAL_LEFT) => { @@ -470,6 +592,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::VERTICAL_LEFT, boundary_type::VERTICAL_RIGHT) => { @@ -478,6 +602,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::VERTICAL_LEFT, boundary_type::HORIZONTAL_DOWN) => { @@ -486,6 +612,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::VERTICAL_LEFT, boundary_type::HORIZONTAL_UP) => { @@ -494,6 +622,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::VERTICAL_LEFT, boundary_type::CROSS) => { @@ -502,6 +632,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::VERTICAL_RIGHT, boundary_type::VERTICAL_RIGHT) => { @@ -510,6 +642,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::VERTICAL_RIGHT, boundary_type::HORIZONTAL_DOWN) => { @@ -518,6 +652,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::VERTICAL_RIGHT, boundary_type::HORIZONTAL_UP) => { @@ -526,6 +662,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::VERTICAL_RIGHT, boundary_type::CROSS) => { @@ -534,6 +672,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::HORIZONTAL_DOWN, boundary_type::HORIZONTAL_DOWN) => { @@ -542,6 +682,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::HORIZONTAL_DOWN, boundary_type::HORIZONTAL_UP) => { @@ -550,6 +692,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::HORIZONTAL_DOWN, boundary_type::CROSS) => { @@ -558,6 +702,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::HORIZONTAL_UP, boundary_type::HORIZONTAL_UP) => { @@ -566,6 +712,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::HORIZONTAL_UP, boundary_type::CROSS) => { @@ -574,6 +722,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (boundary_type::CROSS, boundary_type::CROSS) => { @@ -582,6 +732,8 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, + should_be_colored, + color }) } (_, _) => None, @@ -677,7 +829,8 @@ impl Boundaries { boundary_characters: HashMap::new(), } } - pub fn add_rect(&mut self, rect: &dyn Pane) { + pub fn add_rect(&mut self, rect: &dyn Pane, should_be_colored: bool) { + debug_log_to_file(format!("colored? {}", should_be_colored)); if rect.x() > 0 { let boundary_x_coords = rect.x() - 1; let first_row_coordinates = self.rect_right_boundary_row_start(rect); @@ -685,11 +838,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, should_be_colored) } else if row == last_row_coordinates - 1 && row != self.rows - 1 { - BoundarySymbol::new(boundary_type::BOTTOM_LEFT) + BoundarySymbol::new(boundary_type::BOTTOM_LEFT, should_be_colored) } else { - BoundarySymbol::new(boundary_type::VERTICAL) + BoundarySymbol::new(boundary_type::VERTICAL, should_be_colored) }; if rect.invisible_borders() { symbol_to_add = symbol_to_add.invisible(); @@ -709,11 +862,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, should_be_colored) } else if col == last_col_coordinates - 1 && col != self.columns - 1 { - BoundarySymbol::new(boundary_type::TOP_RIGHT) + BoundarySymbol::new(boundary_type::TOP_RIGHT, should_be_colored) } else { - BoundarySymbol::new(boundary_type::HORIZONTAL) + BoundarySymbol::new(boundary_type::HORIZONTAL, should_be_colored) }; if rect.invisible_borders() { symbol_to_add = symbol_to_add.invisible(); @@ -734,11 +887,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, should_be_colored) } else if row == last_row_coordinates - 1 && row != self.rows - 1 { - BoundarySymbol::new(boundary_type::BOTTOM_RIGHT) + BoundarySymbol::new(boundary_type::BOTTOM_RIGHT, should_be_colored) } else { - BoundarySymbol::new(boundary_type::VERTICAL) + BoundarySymbol::new(boundary_type::VERTICAL, should_be_colored) }; if rect.invisible_borders() { symbol_to_add = symbol_to_add.invisible(); @@ -758,11 +911,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, should_be_colored) } else if col == last_col_coordinates - 1 && col != self.columns - 1 { - BoundarySymbol::new(boundary_type::BOTTOM_RIGHT) + BoundarySymbol::new(boundary_type::BOTTOM_RIGHT, should_be_colored) } else { - BoundarySymbol::new(boundary_type::HORIZONTAL) + BoundarySymbol::new(boundary_type::HORIZONTAL, should_be_colored) }; if rect.invisible_borders() { symbol_to_add = symbol_to_add.invisible(); diff --git a/src/client/tab.rs b/src/client/tab.rs index bf096367..d5c7f896 100644 --- a/src/client/tab.rs +++ b/src/client/tab.rs @@ -625,7 +625,10 @@ 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(), true), + false => boundaries.add_rect(terminal.as_ref(), false) + } if let Some(vte_output) = terminal.render() { let vte_output = if let PaneId::Terminal(_) = kind { vte_output From 922440a952792c5603dfca7f08ede45b887a294d Mon Sep 17 00:00:00 2001 From: denis Date: Mon, 15 Mar 2021 14:17:04 +0200 Subject: [PATCH 02/12] wip: need to debug somehow --- src/client/boundaries.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/client/boundaries.rs b/src/client/boundaries.rs index 70159f9b..4c9c95fa 100644 --- a/src/client/boundaries.rs +++ b/src/client/boundaries.rs @@ -72,7 +72,6 @@ fn combine_symbols( ) -> Option { let invisible = current_symbol.invisible || next_symbol.invisible; let should_be_colored = current_symbol.should_be_colored || next_symbol.should_be_colored; - let color = next_symbol.color; let current_symbol = current_symbol.boundary_type; let next_symbol = next_symbol.boundary_type; match (current_symbol, next_symbol) { @@ -887,11 +886,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, should_be_colored) + BoundarySymbol::new(boundary_type::TOP_RIGHT, false) } else if row == last_row_coordinates - 1 && row != self.rows - 1 { - BoundarySymbol::new(boundary_type::BOTTOM_RIGHT, should_be_colored) + BoundarySymbol::new(boundary_type::BOTTOM_RIGHT, false) } else { - BoundarySymbol::new(boundary_type::VERTICAL, should_be_colored) + BoundarySymbol::new(boundary_type::VERTICAL, false) }; if rect.invisible_borders() { symbol_to_add = symbol_to_add.invisible(); @@ -911,11 +910,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, should_be_colored) + BoundarySymbol::new(boundary_type::BOTTOM_LEFT, false) } else if col == last_col_coordinates - 1 && col != self.columns - 1 { - BoundarySymbol::new(boundary_type::BOTTOM_RIGHT, should_be_colored) + BoundarySymbol::new(boundary_type::BOTTOM_RIGHT, false) } else { - BoundarySymbol::new(boundary_type::HORIZONTAL, should_be_colored) + BoundarySymbol::new(boundary_type::HORIZONTAL, false) }; if rect.invisible_borders() { symbol_to_add = symbol_to_add.invisible(); From 3dd776834a6b641466195394103c7d5a94653fb4 Mon Sep 17 00:00:00 2001 From: denis Date: Wed, 17 Mar 2021 11:16:02 +0200 Subject: [PATCH 03/12] wip: the borders are colored correctly now, need to change the color according to the mode selected next and do some cleaning up --- src/client/boundaries.rs | 183 +++++++++++++++++--------------- src/client/panes/plugin_pane.rs | 5 + src/client/tab.rs | 5 +- 3 files changed, 105 insertions(+), 88 deletions(-) diff --git a/src/client/boundaries.rs b/src/client/boundaries.rs index 4c9c95fa..550a8f3d 100644 --- a/src/client/boundaries.rs +++ b/src/client/boundaries.rs @@ -1,7 +1,6 @@ use crate::tab::Pane; +use ansi_term::Colour::{self, Fixed}; use std::collections::HashMap; -use ansi_term::Colour::*; -use super::super::utils::logging::debug_log_to_file; use std::fmt::{Display, Error, Formatter}; @@ -26,7 +25,7 @@ pub struct BoundarySymbol { boundary_type: BoundaryType, invisible: bool, should_be_colored: bool, - color: ansi_term::Colour + color: Colour, } impl BoundarySymbol { @@ -35,17 +34,14 @@ impl BoundarySymbol { boundary_type, invisible: false, should_be_colored, - color: match should_be_colored { - true => ansi_term::Colour::Red, - false => ansi_term::Colour::White - } + color: Fixed(245), } } pub fn invisible(mut self) -> Self { self.invisible = true; self } - pub fn color(mut self, color: ansi_term::Colour) -> Self { + pub fn color(mut self, color: Colour) -> Self { self.color = color; self.should_be_colored = true; self @@ -56,12 +52,10 @@ impl Display for BoundarySymbol { fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { match self.invisible { true => write!(f, " "), - false => { - match self.should_be_colored { - true => write!(f, "{}", self.color.paint(self.boundary_type)), - false => write!(f, "{}", self.boundary_type) - } - } + false => match self.should_be_colored { + true => write!(f, "{}", self.color.paint(self.boundary_type)), + false => write!(f, "{}", self.boundary_type), + }, } } } @@ -74,6 +68,10 @@ fn combine_symbols( let should_be_colored = current_symbol.should_be_colored || next_symbol.should_be_colored; let current_symbol = current_symbol.boundary_type; let next_symbol = next_symbol.boundary_type; + let color = match should_be_colored { + true => Fixed(154), + false => Fixed(245), + }; match (current_symbol, next_symbol) { (boundary_type::TOP_RIGHT, boundary_type::TOP_RIGHT) => { // (┐, ┐) => Some(┐) @@ -82,7 +80,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::TOP_RIGHT, boundary_type::VERTICAL) => { @@ -92,7 +90,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::TOP_RIGHT, boundary_type::HORIZONTAL) => { @@ -102,7 +100,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::TOP_RIGHT, boundary_type::TOP_LEFT) => { @@ -112,7 +110,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::TOP_RIGHT, boundary_type::BOTTOM_RIGHT) => { @@ -122,7 +120,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::TOP_RIGHT, boundary_type::BOTTOM_LEFT) => { @@ -132,7 +130,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::TOP_RIGHT, boundary_type::VERTICAL_LEFT) => { @@ -142,7 +140,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::TOP_RIGHT, boundary_type::VERTICAL_RIGHT) => { @@ -152,7 +150,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::TOP_RIGHT, boundary_type::HORIZONTAL_DOWN) => { @@ -162,7 +160,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::TOP_RIGHT, boundary_type::HORIZONTAL_UP) => { @@ -172,7 +170,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::TOP_RIGHT, boundary_type::CROSS) => { @@ -182,7 +180,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::HORIZONTAL, boundary_type::HORIZONTAL) => { @@ -192,7 +190,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::HORIZONTAL, boundary_type::VERTICAL) => { @@ -202,7 +200,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::HORIZONTAL, boundary_type::TOP_LEFT) => { @@ -212,7 +210,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::HORIZONTAL, boundary_type::BOTTOM_RIGHT) => { @@ -222,7 +220,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::HORIZONTAL, boundary_type::BOTTOM_LEFT) => { @@ -232,7 +230,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::HORIZONTAL, boundary_type::VERTICAL_LEFT) => { @@ -242,7 +240,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::HORIZONTAL, boundary_type::VERTICAL_RIGHT) => { @@ -252,7 +250,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::HORIZONTAL, boundary_type::HORIZONTAL_DOWN) => { @@ -262,7 +260,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::HORIZONTAL, boundary_type::HORIZONTAL_UP) => { @@ -272,7 +270,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::HORIZONTAL, boundary_type::CROSS) => { @@ -282,7 +280,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::VERTICAL, boundary_type::VERTICAL) => { @@ -292,7 +290,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::VERTICAL, boundary_type::TOP_LEFT) => { @@ -302,7 +300,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::VERTICAL, boundary_type::BOTTOM_RIGHT) => { @@ -312,7 +310,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::VERTICAL, boundary_type::BOTTOM_LEFT) => { @@ -322,7 +320,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::VERTICAL, boundary_type::VERTICAL_LEFT) => { @@ -332,7 +330,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::VERTICAL, boundary_type::VERTICAL_RIGHT) => { @@ -342,7 +340,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::VERTICAL, boundary_type::HORIZONTAL_DOWN) => { @@ -352,7 +350,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::VERTICAL, boundary_type::HORIZONTAL_UP) => { @@ -362,7 +360,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::VERTICAL, boundary_type::CROSS) => { @@ -372,7 +370,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::TOP_LEFT, boundary_type::TOP_LEFT) => { @@ -382,7 +380,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::TOP_LEFT, boundary_type::BOTTOM_RIGHT) => { @@ -392,7 +390,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::TOP_LEFT, boundary_type::BOTTOM_LEFT) => { @@ -402,7 +400,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::TOP_LEFT, boundary_type::VERTICAL_LEFT) => { @@ -412,7 +410,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::TOP_LEFT, boundary_type::VERTICAL_RIGHT) => { @@ -422,7 +420,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::TOP_LEFT, boundary_type::HORIZONTAL_DOWN) => { @@ -432,7 +430,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::TOP_LEFT, boundary_type::HORIZONTAL_UP) => { @@ -442,7 +440,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::TOP_LEFT, boundary_type::CROSS) => { @@ -452,7 +450,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::BOTTOM_RIGHT, boundary_type::BOTTOM_RIGHT) => { @@ -462,7 +460,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::BOTTOM_RIGHT, boundary_type::BOTTOM_LEFT) => { @@ -472,7 +470,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::BOTTOM_RIGHT, boundary_type::VERTICAL_LEFT) => { @@ -482,7 +480,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::BOTTOM_RIGHT, boundary_type::VERTICAL_RIGHT) => { @@ -492,7 +490,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::BOTTOM_RIGHT, boundary_type::HORIZONTAL_DOWN) => { @@ -502,7 +500,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::BOTTOM_RIGHT, boundary_type::HORIZONTAL_UP) => { @@ -512,7 +510,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::BOTTOM_RIGHT, boundary_type::CROSS) => { @@ -522,7 +520,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::BOTTOM_LEFT, boundary_type::BOTTOM_LEFT) => { @@ -532,7 +530,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::BOTTOM_LEFT, boundary_type::VERTICAL_LEFT) => { @@ -542,7 +540,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::BOTTOM_LEFT, boundary_type::VERTICAL_RIGHT) => { @@ -552,7 +550,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::BOTTOM_LEFT, boundary_type::HORIZONTAL_DOWN) => { @@ -562,7 +560,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::BOTTOM_LEFT, boundary_type::HORIZONTAL_UP) => { @@ -572,7 +570,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::BOTTOM_LEFT, boundary_type::CROSS) => { @@ -582,7 +580,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::VERTICAL_LEFT, boundary_type::VERTICAL_LEFT) => { @@ -592,7 +590,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::VERTICAL_LEFT, boundary_type::VERTICAL_RIGHT) => { @@ -602,7 +600,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::VERTICAL_LEFT, boundary_type::HORIZONTAL_DOWN) => { @@ -612,7 +610,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::VERTICAL_LEFT, boundary_type::HORIZONTAL_UP) => { @@ -622,7 +620,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::VERTICAL_LEFT, boundary_type::CROSS) => { @@ -632,7 +630,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::VERTICAL_RIGHT, boundary_type::VERTICAL_RIGHT) => { @@ -642,7 +640,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::VERTICAL_RIGHT, boundary_type::HORIZONTAL_DOWN) => { @@ -652,7 +650,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::VERTICAL_RIGHT, boundary_type::HORIZONTAL_UP) => { @@ -662,7 +660,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::VERTICAL_RIGHT, boundary_type::CROSS) => { @@ -672,7 +670,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::HORIZONTAL_DOWN, boundary_type::HORIZONTAL_DOWN) => { @@ -682,7 +680,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::HORIZONTAL_DOWN, boundary_type::HORIZONTAL_UP) => { @@ -692,7 +690,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::HORIZONTAL_DOWN, boundary_type::CROSS) => { @@ -702,7 +700,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::HORIZONTAL_UP, boundary_type::HORIZONTAL_UP) => { @@ -712,7 +710,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::HORIZONTAL_UP, boundary_type::CROSS) => { @@ -722,7 +720,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (boundary_type::CROSS, boundary_type::CROSS) => { @@ -732,7 +730,7 @@ fn combine_symbols( boundary_type, invisible, should_be_colored, - color + color, }) } (_, _) => None, @@ -829,7 +827,6 @@ impl Boundaries { } } pub fn add_rect(&mut self, rect: &dyn Pane, should_be_colored: bool) { - debug_log_to_file(format!("colored? {}", should_be_colored)); if rect.x() > 0 { let boundary_x_coords = rect.x() - 1; let first_row_coordinates = self.rect_right_boundary_row_start(rect); @@ -846,6 +843,9 @@ impl Boundaries { if rect.invisible_borders() { symbol_to_add = symbol_to_add.invisible(); } + if rect.colored_borders() { + symbol_to_add = symbol_to_add.color(Fixed(154)); + } let next_symbol = self .boundary_characters .remove(&coordinates) @@ -870,6 +870,9 @@ impl Boundaries { if rect.invisible_borders() { symbol_to_add = symbol_to_add.invisible(); } + if rect.colored_borders() { + symbol_to_add = symbol_to_add.color(Fixed(154)); + } let next_symbol = self .boundary_characters .remove(&coordinates) @@ -886,15 +889,18 @@ 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, false) + BoundarySymbol::new(boundary_type::TOP_RIGHT, should_be_colored) } else if row == last_row_coordinates - 1 && row != self.rows - 1 { - BoundarySymbol::new(boundary_type::BOTTOM_RIGHT, false) + BoundarySymbol::new(boundary_type::BOTTOM_RIGHT, should_be_colored) } else { - BoundarySymbol::new(boundary_type::VERTICAL, false) + BoundarySymbol::new(boundary_type::VERTICAL, should_be_colored) }; if rect.invisible_borders() { symbol_to_add = symbol_to_add.invisible(); } + if rect.colored_borders() { + symbol_to_add = symbol_to_add.color(Fixed(154)); + } let next_symbol = self .boundary_characters .remove(&coordinates) @@ -910,15 +916,18 @@ 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, false) + BoundarySymbol::new(boundary_type::BOTTOM_LEFT, should_be_colored) } else if col == last_col_coordinates - 1 && col != self.columns - 1 { - BoundarySymbol::new(boundary_type::BOTTOM_RIGHT, false) + BoundarySymbol::new(boundary_type::BOTTOM_RIGHT, should_be_colored) } else { - BoundarySymbol::new(boundary_type::HORIZONTAL, false) + BoundarySymbol::new(boundary_type::HORIZONTAL, should_be_colored) }; if rect.invisible_borders() { symbol_to_add = symbol_to_add.invisible(); } + if rect.colored_borders() { + symbol_to_add = symbol_to_add.color(Fixed(154)); + } let next_symbol = self .boundary_characters .remove(&coordinates) diff --git a/src/client/panes/plugin_pane.rs b/src/client/panes/plugin_pane.rs index 588cffd6..52e4c560 100644 --- a/src/client/panes/plugin_pane.rs +++ b/src/client/panes/plugin_pane.rs @@ -11,6 +11,7 @@ pub struct PluginPane { pub should_render: bool, pub selectable: bool, pub invisible_borders: bool, + pub colored_borders: bool, pub position_and_size: PositionAndSize, pub position_and_size_override: Option, pub send_plugin_instructions: SenderWithContext, @@ -28,6 +29,7 @@ impl PluginPane { should_render: true, selectable: true, invisible_borders: false, + colored_borders: false, position_and_size, position_and_size_override: None, send_plugin_instructions, @@ -188,4 +190,7 @@ impl Pane for PluginPane { fn invisible_borders(&self) -> bool { self.invisible_borders } + fn colored_borders(&self) -> bool { + self.colored_borders + } } diff --git a/src/client/tab.rs b/src/client/tab.rs index b7c43cf4..c8f9209d 100644 --- a/src/client/tab.rs +++ b/src/client/tab.rs @@ -174,6 +174,9 @@ pub trait Pane { fn invisible_borders(&self) -> bool { false } + fn colored_borders(&self) -> bool { + false + } } impl Tab { @@ -647,7 +650,7 @@ impl Tab { if !self.panes_to_hide.contains(&terminal.pid()) { match self.active_terminal.unwrap() == terminal.pid() { true => boundaries.add_rect(terminal.as_ref(), true), - false => boundaries.add_rect(terminal.as_ref(), false) + false => boundaries.add_rect(terminal.as_ref(), false), } if let Some(vte_output) = terminal.render() { let vte_output = if let PaneId::Terminal(_) = kind { From 59d2da54ca1f504af4271d96ba069b2d7a75ac2e Mon Sep 17 00:00:00 2001 From: denis Date: Fri, 19 Mar 2021 16:11:45 +0200 Subject: [PATCH 04/12] wip: active pane color, able to type / not able to type inside a pane distinction --- src/client/boundaries.rs | 65 +++++++++++++++++++++++----------------- src/client/tab.rs | 15 ++++++++-- 2 files changed, 49 insertions(+), 31 deletions(-) diff --git a/src/client/boundaries.rs b/src/client/boundaries.rs index 550a8f3d..1a8174e3 100644 --- a/src/client/boundaries.rs +++ b/src/client/boundaries.rs @@ -1,4 +1,5 @@ -use crate::tab::Pane; +use crate::common::utils::logging::debug_log_to_file; +use crate::{common::input::handler::InputMode, tab::Pane}; use ansi_term::Colour::{self, Fixed}; use std::collections::HashMap; @@ -18,6 +19,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)] @@ -34,18 +42,13 @@ impl BoundarySymbol { boundary_type, invisible: false, should_be_colored, - color: Fixed(245), + color: colors::GRAY, } } pub fn invisible(mut self) -> Self { self.invisible = true; self } - pub fn color(mut self, color: Colour) -> Self { - self.color = color; - self.should_be_colored = true; - self - } } impl Display for BoundarySymbol { @@ -63,14 +66,23 @@ impl Display for BoundarySymbol { fn combine_symbols( current_symbol: BoundarySymbol, next_symbol: BoundarySymbol, + input_mode: InputMode, ) -> Option { let invisible = current_symbol.invisible || next_symbol.invisible; let should_be_colored = current_symbol.should_be_colored || next_symbol.should_be_colored; let current_symbol = current_symbol.boundary_type; let next_symbol = next_symbol.boundary_type; let color = match should_be_colored { - true => Fixed(154), - false => Fixed(245), + true => match input_mode { + InputMode::Normal => colors::GREEN, + InputMode::Locked => colors::GREEN, + InputMode::Pane => colors::WHITE, + InputMode::RenameTab => colors::WHITE, + InputMode::Resize => colors::WHITE, + InputMode::Scroll => colors::WHITE, + InputMode::Tab => colors::WHITE, + }, + false => colors::WHITE, }; match (current_symbol, next_symbol) { (boundary_type::TOP_RIGHT, boundary_type::TOP_RIGHT) => { @@ -740,11 +752,12 @@ fn combine_symbols( fn find_next_symbol( first_symbol: BoundarySymbol, second_symbol: BoundarySymbol, + input_mode: InputMode, ) -> Option { - if let Some(symbol) = combine_symbols(first_symbol, second_symbol) { + if let Some(symbol) = combine_symbols(first_symbol, second_symbol, input_mode) { Some(symbol) } else { - combine_symbols(second_symbol, first_symbol) + combine_symbols(second_symbol, first_symbol, input_mode) } } @@ -826,7 +839,7 @@ impl Boundaries { boundary_characters: HashMap::new(), } } - pub fn add_rect(&mut self, rect: &dyn Pane, should_be_colored: bool) { + pub fn add_rect(&mut self, rect: &dyn Pane, should_be_colored: bool, input_mode: InputMode) { if rect.x() > 0 { let boundary_x_coords = rect.x() - 1; let first_row_coordinates = self.rect_right_boundary_row_start(rect); @@ -843,13 +856,12 @@ impl Boundaries { if rect.invisible_borders() { symbol_to_add = symbol_to_add.invisible(); } - if rect.colored_borders() { - symbol_to_add = symbol_to_add.color(Fixed(154)); - } let next_symbol = self .boundary_characters .remove(&coordinates) - .and_then(|current_symbol| find_next_symbol(current_symbol, symbol_to_add)) + .and_then(|current_symbol| { + find_next_symbol(current_symbol, symbol_to_add, input_mode) + }) .unwrap_or(symbol_to_add); self.boundary_characters.insert(coordinates, next_symbol); } @@ -870,13 +882,12 @@ impl Boundaries { if rect.invisible_borders() { symbol_to_add = symbol_to_add.invisible(); } - if rect.colored_borders() { - symbol_to_add = symbol_to_add.color(Fixed(154)); - } let next_symbol = self .boundary_characters .remove(&coordinates) - .and_then(|current_symbol| find_next_symbol(current_symbol, symbol_to_add)) + .and_then(|current_symbol| { + find_next_symbol(current_symbol, symbol_to_add, input_mode) + }) .unwrap_or(symbol_to_add); self.boundary_characters.insert(coordinates, next_symbol); } @@ -898,13 +909,12 @@ impl Boundaries { if rect.invisible_borders() { symbol_to_add = symbol_to_add.invisible(); } - if rect.colored_borders() { - symbol_to_add = symbol_to_add.color(Fixed(154)); - } let next_symbol = self .boundary_characters .remove(&coordinates) - .and_then(|current_symbol| find_next_symbol(current_symbol, symbol_to_add)) + .and_then(|current_symbol| { + find_next_symbol(current_symbol, symbol_to_add, input_mode) + }) .unwrap_or(symbol_to_add); self.boundary_characters.insert(coordinates, next_symbol); } @@ -925,13 +935,12 @@ impl Boundaries { if rect.invisible_borders() { symbol_to_add = symbol_to_add.invisible(); } - if rect.colored_borders() { - symbol_to_add = symbol_to_add.color(Fixed(154)); - } let next_symbol = self .boundary_characters .remove(&coordinates) - .and_then(|current_symbol| find_next_symbol(current_symbol, symbol_to_add)) + .and_then(|current_symbol| { + find_next_symbol(current_symbol, symbol_to_add, input_mode) + }) .unwrap_or(symbol_to_add); self.boundary_characters.insert(coordinates, next_symbol); } diff --git a/src/client/tab.rs b/src/client/tab.rs index c8f9209d..ecb94eb2 100644 --- a/src/client/tab.rs +++ b/src/client/tab.rs @@ -1,7 +1,8 @@ //! `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::common::input::handler::get_help; +use crate::common::{input::handler::InputMode, AppInstruction, AppState, SenderWithContext}; use crate::layout::Layout; use crate::panes::{PaneId, PositionAndSize, TerminalPane}; use crate::pty_bus::{PtyInstruction, VteEvent}; @@ -21,7 +22,13 @@ const MIN_TERMINAL_HEIGHT: usize = 2; const MIN_TERMINAL_WIDTH: usize = 4; type BorderAndPaneIds = (usize, Vec); +fn get_state(app_tx: &SenderWithContext) -> InputMode { + let (state_tx, state_rx) = channel(); + drop(app_tx.send(AppInstruction::GetState(state_tx))); + let state = state_rx.recv().unwrap(); + state.input_mode +} fn split_vertically_with_gap(rect: &PositionAndSize) -> (PositionAndSize, PositionAndSize) { let width_of_each_half = (rect.columns - 1) / 2; let mut first_rect = *rect; @@ -631,6 +638,7 @@ impl Tab { pub fn toggle_fullscreen_is_active(&mut self) { self.fullscreen_is_active = !self.fullscreen_is_active; } + pub fn render(&mut self) { if self.active_terminal.is_none() { // we might not have an active terminal if we closed the last pane @@ -643,14 +651,15 @@ impl Tab { self.full_screen_ws.rows as u16, ); let hide_cursor = "\u{1b}[?25l"; + let input_mode = get_state(&self.send_app_instructions); stdout .write_all(&hide_cursor.as_bytes()) .expect("cannot write to stdout"); for (kind, terminal) in self.panes.iter_mut() { if !self.panes_to_hide.contains(&terminal.pid()) { match self.active_terminal.unwrap() == terminal.pid() { - true => boundaries.add_rect(terminal.as_ref(), true), - false => boundaries.add_rect(terminal.as_ref(), false), + true => boundaries.add_rect(terminal.as_ref(), true, input_mode), + false => boundaries.add_rect(terminal.as_ref(), false, input_mode), } if let Some(vte_output) = terminal.render() { let vte_output = if let PaneId::Terminal(_) = kind { From 021c8608c8d8a0cd43328d9c0bede5259bd14261 Mon Sep 17 00:00:00 2001 From: denis Date: Sat, 20 Mar 2021 16:54:18 +0200 Subject: [PATCH 05/12] wip: not sure about updating the input_mode and tab switches for now --- src/client/boundaries.rs | 1 - src/client/tab.rs | 25 +++++++++++++++---------- src/common/errors.rs | 2 ++ src/common/input/handler.rs | 3 +++ src/common/mod.rs | 6 ++++++ src/common/screen.rs | 16 +++++++++++++++- 6 files changed, 41 insertions(+), 12 deletions(-) diff --git a/src/client/boundaries.rs b/src/client/boundaries.rs index 1a8174e3..a5f5965b 100644 --- a/src/client/boundaries.rs +++ b/src/client/boundaries.rs @@ -1,4 +1,3 @@ -use crate::common::utils::logging::debug_log_to_file; use crate::{common::input::handler::InputMode, tab::Pane}; use ansi_term::Colour::{self, Fixed}; use std::collections::HashMap; diff --git a/src/client/tab.rs b/src/client/tab.rs index ecb94eb2..dad75e30 100644 --- a/src/client/tab.rs +++ b/src/client/tab.rs @@ -22,13 +22,7 @@ const MIN_TERMINAL_HEIGHT: usize = 2; const MIN_TERMINAL_WIDTH: usize = 4; type BorderAndPaneIds = (usize, Vec); -fn get_state(app_tx: &SenderWithContext) -> InputMode { - let (state_tx, state_rx) = channel(); - drop(app_tx.send(AppInstruction::GetState(state_tx))); - let state = state_rx.recv().unwrap(); - state.input_mode -} fn split_vertically_with_gap(rect: &PositionAndSize) -> (PositionAndSize, PositionAndSize) { let width_of_each_half = (rect.columns - 1) / 2; let mut first_rect = *rect; @@ -72,6 +66,7 @@ pub struct Tab { pub send_plugin_instructions: SenderWithContext, pub send_app_instructions: SenderWithContext, expansion_boundary: Option, + pub input_mode: InputMode } #[derive(Clone, Debug, Default, Serialize, Deserialize)] @@ -80,6 +75,7 @@ pub struct TabData { 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 @@ -199,6 +195,7 @@ impl Tab { send_app_instructions: SenderWithContext, max_panes: Option, pane_id: Option, + input_mode: InputMode ) -> Self { let panes = if let Some(PaneId::Terminal(pid)) = pane_id { let new_terminal = TerminalPane::new(pid, *full_screen_ws); @@ -228,6 +225,7 @@ impl Tab { send_pty_instructions, send_plugin_instructions, expansion_boundary: None, + input_mode } } @@ -638,7 +636,6 @@ impl Tab { pub fn toggle_fullscreen_is_active(&mut self) { self.fullscreen_is_active = !self.fullscreen_is_active; } - pub fn render(&mut self) { if self.active_terminal.is_none() { // we might not have an active terminal if we closed the last pane @@ -651,15 +648,23 @@ impl Tab { self.full_screen_ws.rows as u16, ); let hide_cursor = "\u{1b}[?25l"; - let input_mode = get_state(&self.send_app_instructions); + //let input_mode = self.get_state(&self.send_app_instructions); stdout .write_all(&hide_cursor.as_bytes()) .expect("cannot write to stdout"); for (kind, terminal) in self.panes.iter_mut() { if !self.panes_to_hide.contains(&terminal.pid()) { match self.active_terminal.unwrap() == terminal.pid() { - true => boundaries.add_rect(terminal.as_ref(), true, input_mode), - false => boundaries.add_rect(terminal.as_ref(), false, input_mode), + true => boundaries.add_rect( + terminal.as_ref(), + true, + self.input_mode + ), + false => boundaries.add_rect( + terminal.as_ref(), + false, + self.input_mode + ), } if let Some(vte_output) = terminal.render() { let vte_output = if let PaneId::Terminal(_) = kind { diff --git a/src/common/errors.rs b/src/common/errors.rs index df741629..a2e05e30 100644 --- a/src/common/errors.rs +++ b/src/common/errors.rs @@ -199,6 +199,7 @@ pub enum ScreenContext { CloseTab, GoToTab, UpdateTabName, + ChangeInputMode } impl From<&ScreenInstruction> for ScreenContext { @@ -238,6 +239,7 @@ impl From<&ScreenInstruction> for ScreenContext { ScreenInstruction::CloseTab => ScreenContext::CloseTab, ScreenInstruction::GoToTab(_) => ScreenContext::GoToTab, ScreenInstruction::UpdateTabName(_) => ScreenContext::UpdateTabName, + ScreenInstruction::ChangeInputMode(_) => ScreenContext::ChangeInputMode } } } diff --git a/src/common/input/handler.rs b/src/common/input/handler.rs index 57bb46fb..2d5e965f 100644 --- a/src/common/input/handler.rs +++ b/src/common/input/handler.rs @@ -133,6 +133,9 @@ impl InputHandler { update_state(&self.send_app_instructions, |_| AppState { input_mode: self.mode, }); + self.send_screen_instructions + .send(ScreenInstruction::ChangeInputMode(self.mode)) + .unwrap(); self.send_screen_instructions .send(ScreenInstruction::Render) .unwrap(); diff --git a/src/common/mod.rs b/src/common/mod.rs index 7b19bcef..87f56567 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -37,6 +37,7 @@ use utils::consts::{ZELLIJ_IPC_PIPE, ZELLIJ_ROOT_PLUGIN_DIR}; use wasm_vm::{ wasi_stdout, wasi_write_string, zellij_imports, EventType, PluginInputType, PluginInstruction, }; +use crate::common::utils::logging::debug_log_to_file; #[derive(Serialize, Deserialize, Debug)] pub enum ApiCommand { @@ -290,6 +291,7 @@ pub fn start(mut os_input: Box, opts: CliArgs) { &full_screen_ws, os_input, max_panes, + InputMode::Normal ); loop { let (event, mut err_ctx) = screen @@ -424,6 +426,10 @@ pub fn start(mut os_input: Box, opts: CliArgs) { ScreenInstruction::UpdateTabName(c) => { screen.update_active_tab_name(c); } + ScreenInstruction::ChangeInputMode(input_mode) => { + debug_log_to_file(format!("{} {:?}", "switched mode to: ".to_string(), input_mode)); + screen.change_input_mode(input_mode); + } ScreenInstruction::Quit => { break; } diff --git a/src/common/screen.rs b/src/common/screen.rs index 57bb0e0f..a675ee07 100644 --- a/src/common/screen.rs +++ b/src/common/screen.rs @@ -5,7 +5,9 @@ use std::os::unix::io::RawFd; use std::str; use std::sync::mpsc::Receiver; -use super::{AppInstruction, SenderWithContext}; +use wasmer::wasmparser::WasmFuncType; + +use super::{AppInstruction, SenderWithContext, input::handler::InputMode}; use crate::os_input_output::OsApi; use crate::panes::PositionAndSize; use crate::pty_bus::{PtyInstruction, VteEvent}; @@ -48,6 +50,7 @@ pub enum ScreenInstruction { CloseTab, GoToTab(u32), UpdateTabName(Vec), + ChangeInputMode(InputMode) } /// A [`Screen`] holds multiple [`Tab`]s, each one holding multiple [`panes`](crate::client::panes). @@ -72,6 +75,7 @@ pub struct Screen { /// The [`OsApi`] this [`Screen`] uses. os_api: Box, tabname_buf: String, + input_mode: InputMode } impl Screen { @@ -84,6 +88,7 @@ impl Screen { full_screen_ws: &PositionAndSize, os_api: Box, max_panes: Option, + input_mode: InputMode ) -> Self { Screen { receiver: receive_screen_instructions, @@ -96,6 +101,7 @@ impl Screen { tabs: BTreeMap::new(), os_api, tabname_buf: String::new(), + input_mode } } @@ -115,6 +121,7 @@ impl Screen { self.send_app_instructions.clone(), self.max_panes, Some(PaneId::Terminal(pane_id)), + self.input_mode ); self.active_tab_index = Some(tab_index); self.tabs.insert(tab_index, tab); @@ -259,6 +266,7 @@ impl Screen { self.send_app_instructions.clone(), self.max_panes, None, + self.input_mode ); tab.apply_layout(layout, new_pids); self.active_tab_index = Some(tab_index); @@ -274,6 +282,7 @@ impl Screen { position: tab.position, name: tab.name.clone(), active: active_tab_index == tab.index, + input_mode: self.input_mode }); } self.send_plugin_instructions @@ -303,4 +312,9 @@ impl Screen { } } } + pub fn change_input_mode(&mut self, input_mode: InputMode) { + self.input_mode = input_mode; + self.get_active_tab_mut().unwrap().input_mode = self.input_mode; + self.render(); + } } From 9016253a51a8c6aeae766d09b7e8447fd5855231 Mon Sep 17 00:00:00 2001 From: denis Date: Sat, 20 Mar 2021 17:52:45 +0200 Subject: [PATCH 06/12] wip: cleanup --- src/client/boundaries.rs | 2 +- src/client/tab.rs | 3 +-- src/common/mod.rs | 1 - src/common/screen.rs | 2 -- 4 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/client/boundaries.rs b/src/client/boundaries.rs index a5f5965b..2109d4b4 100644 --- a/src/client/boundaries.rs +++ b/src/client/boundaries.rs @@ -1,5 +1,5 @@ use crate::{common::input::handler::InputMode, tab::Pane}; -use ansi_term::Colour::{self, Fixed}; +use ansi_term::Colour; use std::collections::HashMap; use std::fmt::{Display, Error, Formatter}; diff --git a/src/client/tab.rs b/src/client/tab.rs index dad75e30..67c4540b 100644 --- a/src/client/tab.rs +++ b/src/client/tab.rs @@ -1,8 +1,7 @@ //! `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::get_help; -use crate::common::{input::handler::InputMode, AppInstruction, AppState, SenderWithContext}; +use crate::common::{input::handler::InputMode, AppInstruction, SenderWithContext}; use crate::layout::Layout; use crate::panes::{PaneId, PositionAndSize, TerminalPane}; use crate::pty_bus::{PtyInstruction, VteEvent}; diff --git a/src/common/mod.rs b/src/common/mod.rs index 87f56567..3b596f42 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -427,7 +427,6 @@ pub fn start(mut os_input: Box, opts: CliArgs) { screen.update_active_tab_name(c); } ScreenInstruction::ChangeInputMode(input_mode) => { - debug_log_to_file(format!("{} {:?}", "switched mode to: ".to_string(), input_mode)); screen.change_input_mode(input_mode); } ScreenInstruction::Quit => { diff --git a/src/common/screen.rs b/src/common/screen.rs index a675ee07..eb8e3eb2 100644 --- a/src/common/screen.rs +++ b/src/common/screen.rs @@ -5,8 +5,6 @@ use std::os::unix::io::RawFd; use std::str; use std::sync::mpsc::Receiver; -use wasmer::wasmparser::WasmFuncType; - use super::{AppInstruction, SenderWithContext, input::handler::InputMode}; use crate::os_input_output::OsApi; use crate::panes::PositionAndSize; From 99c578ea1d23f12e2b13f43b562406ccd4120802 Mon Sep 17 00:00:00 2001 From: denis Date: Sun, 21 Mar 2021 10:48:21 +0200 Subject: [PATCH 07/12] chore: formatting --- src/client/tab.rs | 20 ++++++-------------- src/common/errors.rs | 4 ++-- src/common/mod.rs | 4 ++-- src/common/screen.rs | 16 ++++++++-------- 4 files changed, 18 insertions(+), 26 deletions(-) diff --git a/src/client/tab.rs b/src/client/tab.rs index 67c4540b..8a515279 100644 --- a/src/client/tab.rs +++ b/src/client/tab.rs @@ -65,7 +65,7 @@ pub struct Tab { pub send_plugin_instructions: SenderWithContext, pub send_app_instructions: SenderWithContext, expansion_boundary: Option, - pub input_mode: InputMode + pub input_mode: InputMode, } #[derive(Clone, Debug, Default, Serialize, Deserialize)] @@ -74,7 +74,7 @@ pub struct TabData { pub position: usize, pub name: String, pub active: bool, - pub input_mode: InputMode + pub input_mode: InputMode, } // FIXME: Use a struct that has a pane_type enum, to reduce all of the duplication @@ -194,7 +194,7 @@ impl Tab { send_app_instructions: SenderWithContext, max_panes: Option, pane_id: Option, - input_mode: InputMode + input_mode: InputMode, ) -> Self { let panes = if let Some(PaneId::Terminal(pid)) = pane_id { let new_terminal = TerminalPane::new(pid, *full_screen_ws); @@ -224,7 +224,7 @@ impl Tab { send_pty_instructions, send_plugin_instructions, expansion_boundary: None, - input_mode + input_mode, } } @@ -654,16 +654,8 @@ impl Tab { for (kind, terminal) in self.panes.iter_mut() { if !self.panes_to_hide.contains(&terminal.pid()) { match self.active_terminal.unwrap() == terminal.pid() { - true => boundaries.add_rect( - terminal.as_ref(), - true, - self.input_mode - ), - false => boundaries.add_rect( - terminal.as_ref(), - false, - self.input_mode - ), + true => boundaries.add_rect(terminal.as_ref(), true, self.input_mode), + false => boundaries.add_rect(terminal.as_ref(), false, self.input_mode), } if let Some(vte_output) = terminal.render() { let vte_output = if let PaneId::Terminal(_) = kind { diff --git a/src/common/errors.rs b/src/common/errors.rs index a2e05e30..eeebf93f 100644 --- a/src/common/errors.rs +++ b/src/common/errors.rs @@ -199,7 +199,7 @@ pub enum ScreenContext { CloseTab, GoToTab, UpdateTabName, - ChangeInputMode + ChangeInputMode, } impl From<&ScreenInstruction> for ScreenContext { @@ -239,7 +239,7 @@ impl From<&ScreenInstruction> for ScreenContext { ScreenInstruction::CloseTab => ScreenContext::CloseTab, ScreenInstruction::GoToTab(_) => ScreenContext::GoToTab, ScreenInstruction::UpdateTabName(_) => ScreenContext::UpdateTabName, - ScreenInstruction::ChangeInputMode(_) => ScreenContext::ChangeInputMode + ScreenInstruction::ChangeInputMode(_) => ScreenContext::ChangeInputMode, } } } diff --git a/src/common/mod.rs b/src/common/mod.rs index 3b596f42..d52b5a4c 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -26,6 +26,7 @@ use wasmer::{ChainableNamedResolver, Instance, Module, Store, Value}; use wasmer_wasi::{Pipe, WasiState}; use crate::cli::CliArgs; +use crate::common::utils::logging::debug_log_to_file; use crate::layout::Layout; use command_is_executing::CommandIsExecuting; use errors::{AppContext, ContextType, ErrorContext, PluginContext, PtyContext, ScreenContext}; @@ -37,7 +38,6 @@ use utils::consts::{ZELLIJ_IPC_PIPE, ZELLIJ_ROOT_PLUGIN_DIR}; use wasm_vm::{ wasi_stdout, wasi_write_string, zellij_imports, EventType, PluginInputType, PluginInstruction, }; -use crate::common::utils::logging::debug_log_to_file; #[derive(Serialize, Deserialize, Debug)] pub enum ApiCommand { @@ -291,7 +291,7 @@ pub fn start(mut os_input: Box, opts: CliArgs) { &full_screen_ws, os_input, max_panes, - InputMode::Normal + InputMode::Normal, ); loop { let (event, mut err_ctx) = screen diff --git a/src/common/screen.rs b/src/common/screen.rs index eb8e3eb2..d40a80c6 100644 --- a/src/common/screen.rs +++ b/src/common/screen.rs @@ -5,7 +5,7 @@ use std::os::unix::io::RawFd; use std::str; use std::sync::mpsc::Receiver; -use super::{AppInstruction, SenderWithContext, input::handler::InputMode}; +use super::{input::handler::InputMode, AppInstruction, SenderWithContext}; use crate::os_input_output::OsApi; use crate::panes::PositionAndSize; use crate::pty_bus::{PtyInstruction, VteEvent}; @@ -48,7 +48,7 @@ pub enum ScreenInstruction { CloseTab, GoToTab(u32), UpdateTabName(Vec), - ChangeInputMode(InputMode) + ChangeInputMode(InputMode), } /// A [`Screen`] holds multiple [`Tab`]s, each one holding multiple [`panes`](crate::client::panes). @@ -73,7 +73,7 @@ pub struct Screen { /// The [`OsApi`] this [`Screen`] uses. os_api: Box, tabname_buf: String, - input_mode: InputMode + input_mode: InputMode, } impl Screen { @@ -86,7 +86,7 @@ impl Screen { full_screen_ws: &PositionAndSize, os_api: Box, max_panes: Option, - input_mode: InputMode + input_mode: InputMode, ) -> Self { Screen { receiver: receive_screen_instructions, @@ -99,7 +99,7 @@ impl Screen { tabs: BTreeMap::new(), os_api, tabname_buf: String::new(), - input_mode + input_mode, } } @@ -119,7 +119,7 @@ impl Screen { self.send_app_instructions.clone(), self.max_panes, Some(PaneId::Terminal(pane_id)), - self.input_mode + self.input_mode, ); self.active_tab_index = Some(tab_index); self.tabs.insert(tab_index, tab); @@ -264,7 +264,7 @@ impl Screen { self.send_app_instructions.clone(), self.max_panes, None, - self.input_mode + self.input_mode, ); tab.apply_layout(layout, new_pids); self.active_tab_index = Some(tab_index); @@ -280,7 +280,7 @@ impl Screen { position: tab.position, name: tab.name.clone(), active: active_tab_index == tab.index, - input_mode: self.input_mode + input_mode: self.input_mode, }); } self.send_plugin_instructions From 2bc40e5402c8710ec6916ecace28ce50a1a80ca1 Mon Sep 17 00:00:00 2001 From: denis Date: Tue, 23 Mar 2021 08:47:20 +0200 Subject: [PATCH 08/12] wip: using Some(Color) in the BoundarySymbol now --- src/client/boundaries.rs | 255 ++++++++++++++------------------------- src/client/tab.rs | 12 +- src/common/screen.rs | 5 +- 3 files changed, 104 insertions(+), 168 deletions(-) diff --git a/src/client/boundaries.rs b/src/client/boundaries.rs index 2109d4b4..74859b0f 100644 --- a/src/client/boundaries.rs +++ b/src/client/boundaries.rs @@ -31,32 +31,34 @@ pub type BoundaryType = &'static str; // easy way to refer to boundary_type abov pub struct BoundarySymbol { boundary_type: BoundaryType, invisible: bool, - should_be_colored: bool, - color: Colour, + color: Option, } impl BoundarySymbol { - pub fn new(boundary_type: BoundaryType, should_be_colored: bool) -> Self { + pub fn new(boundary_type: BoundaryType) -> Self { BoundarySymbol { boundary_type, invisible: false, - should_be_colored, - color: colors::GRAY, + color: Some(colors::GRAY), } } pub fn invisible(mut self) -> Self { self.invisible = true; self } + pub fn color(&mut self, color: Option) -> Self { + self.color = color; + *self + } } impl Display for BoundarySymbol { fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { match self.invisible { true => write!(f, " "), - false => match self.should_be_colored { - true => write!(f, "{}", self.color.paint(self.boundary_type)), - false => write!(f, "{}", self.boundary_type), + false => match self.color { + Some(color) => write!(f, "{}", self.color.unwrap().paint(self.boundary_type)), + None => write!(f, "{}", self.boundary_type), }, } } @@ -68,20 +70,15 @@ fn combine_symbols( input_mode: InputMode, ) -> Option { let invisible = current_symbol.invisible || next_symbol.invisible; - let should_be_colored = current_symbol.should_be_colored || next_symbol.should_be_colored; + let should_be_colored = current_symbol.color.is_some() || next_symbol.color.is_some(); let current_symbol = current_symbol.boundary_type; let next_symbol = next_symbol.boundary_type; let color = match should_be_colored { true => match input_mode { - InputMode::Normal => colors::GREEN, - InputMode::Locked => colors::GREEN, - InputMode::Pane => colors::WHITE, - InputMode::RenameTab => colors::WHITE, - InputMode::Resize => colors::WHITE, - InputMode::Scroll => colors::WHITE, - InputMode::Tab => colors::WHITE, + InputMode::Normal | InputMode::Locked => Some(colors::GREEN), + _ => Some(colors::WHITE), }, - false => colors::WHITE, + false => None, }; match (current_symbol, next_symbol) { (boundary_type::TOP_RIGHT, boundary_type::TOP_RIGHT) => { @@ -90,8 +87,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::TOP_RIGHT, boundary_type::VERTICAL) => { @@ -100,8 +96,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::TOP_RIGHT, boundary_type::HORIZONTAL) => { @@ -110,8 +105,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::TOP_RIGHT, boundary_type::TOP_LEFT) => { @@ -120,8 +114,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::TOP_RIGHT, boundary_type::BOTTOM_RIGHT) => { @@ -130,8 +123,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::TOP_RIGHT, boundary_type::BOTTOM_LEFT) => { @@ -140,8 +132,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::TOP_RIGHT, boundary_type::VERTICAL_LEFT) => { @@ -150,8 +141,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::TOP_RIGHT, boundary_type::VERTICAL_RIGHT) => { @@ -160,8 +150,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::TOP_RIGHT, boundary_type::HORIZONTAL_DOWN) => { @@ -170,8 +159,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::TOP_RIGHT, boundary_type::HORIZONTAL_UP) => { @@ -180,8 +168,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::TOP_RIGHT, boundary_type::CROSS) => { @@ -190,8 +177,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::HORIZONTAL, boundary_type::HORIZONTAL) => { @@ -200,8 +186,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::HORIZONTAL, boundary_type::VERTICAL) => { @@ -210,8 +195,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::HORIZONTAL, boundary_type::TOP_LEFT) => { @@ -220,8 +204,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::HORIZONTAL, boundary_type::BOTTOM_RIGHT) => { @@ -230,8 +213,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::HORIZONTAL, boundary_type::BOTTOM_LEFT) => { @@ -240,8 +222,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::HORIZONTAL, boundary_type::VERTICAL_LEFT) => { @@ -250,8 +231,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::HORIZONTAL, boundary_type::VERTICAL_RIGHT) => { @@ -260,8 +240,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::HORIZONTAL, boundary_type::HORIZONTAL_DOWN) => { @@ -270,8 +249,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::HORIZONTAL, boundary_type::HORIZONTAL_UP) => { @@ -280,8 +258,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::HORIZONTAL, boundary_type::CROSS) => { @@ -290,8 +267,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::VERTICAL, boundary_type::VERTICAL) => { @@ -300,8 +276,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::VERTICAL, boundary_type::TOP_LEFT) => { @@ -310,8 +285,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::VERTICAL, boundary_type::BOTTOM_RIGHT) => { @@ -320,8 +294,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::VERTICAL, boundary_type::BOTTOM_LEFT) => { @@ -330,8 +303,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::VERTICAL, boundary_type::VERTICAL_LEFT) => { @@ -340,8 +312,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::VERTICAL, boundary_type::VERTICAL_RIGHT) => { @@ -350,8 +321,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::VERTICAL, boundary_type::HORIZONTAL_DOWN) => { @@ -360,8 +330,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::VERTICAL, boundary_type::HORIZONTAL_UP) => { @@ -370,8 +339,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::VERTICAL, boundary_type::CROSS) => { @@ -380,8 +348,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::TOP_LEFT, boundary_type::TOP_LEFT) => { @@ -390,8 +357,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::TOP_LEFT, boundary_type::BOTTOM_RIGHT) => { @@ -400,8 +366,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::TOP_LEFT, boundary_type::BOTTOM_LEFT) => { @@ -410,8 +375,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::TOP_LEFT, boundary_type::VERTICAL_LEFT) => { @@ -420,8 +384,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::TOP_LEFT, boundary_type::VERTICAL_RIGHT) => { @@ -430,8 +393,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::TOP_LEFT, boundary_type::HORIZONTAL_DOWN) => { @@ -440,8 +402,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::TOP_LEFT, boundary_type::HORIZONTAL_UP) => { @@ -450,8 +411,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::TOP_LEFT, boundary_type::CROSS) => { @@ -460,8 +420,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::BOTTOM_RIGHT, boundary_type::BOTTOM_RIGHT) => { @@ -470,8 +429,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::BOTTOM_RIGHT, boundary_type::BOTTOM_LEFT) => { @@ -480,8 +438,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::BOTTOM_RIGHT, boundary_type::VERTICAL_LEFT) => { @@ -490,8 +447,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::BOTTOM_RIGHT, boundary_type::VERTICAL_RIGHT) => { @@ -500,8 +456,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::BOTTOM_RIGHT, boundary_type::HORIZONTAL_DOWN) => { @@ -510,8 +465,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::BOTTOM_RIGHT, boundary_type::HORIZONTAL_UP) => { @@ -520,8 +474,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::BOTTOM_RIGHT, boundary_type::CROSS) => { @@ -530,8 +483,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::BOTTOM_LEFT, boundary_type::BOTTOM_LEFT) => { @@ -540,8 +492,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::BOTTOM_LEFT, boundary_type::VERTICAL_LEFT) => { @@ -550,8 +501,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::BOTTOM_LEFT, boundary_type::VERTICAL_RIGHT) => { @@ -560,8 +510,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::BOTTOM_LEFT, boundary_type::HORIZONTAL_DOWN) => { @@ -570,8 +519,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::BOTTOM_LEFT, boundary_type::HORIZONTAL_UP) => { @@ -580,8 +528,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::BOTTOM_LEFT, boundary_type::CROSS) => { @@ -590,8 +537,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::VERTICAL_LEFT, boundary_type::VERTICAL_LEFT) => { @@ -600,8 +546,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::VERTICAL_LEFT, boundary_type::VERTICAL_RIGHT) => { @@ -610,8 +555,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::VERTICAL_LEFT, boundary_type::HORIZONTAL_DOWN) => { @@ -620,8 +564,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::VERTICAL_LEFT, boundary_type::HORIZONTAL_UP) => { @@ -630,8 +573,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::VERTICAL_LEFT, boundary_type::CROSS) => { @@ -640,8 +582,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::VERTICAL_RIGHT, boundary_type::VERTICAL_RIGHT) => { @@ -650,8 +591,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::VERTICAL_RIGHT, boundary_type::HORIZONTAL_DOWN) => { @@ -660,8 +600,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::VERTICAL_RIGHT, boundary_type::HORIZONTAL_UP) => { @@ -670,8 +609,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::VERTICAL_RIGHT, boundary_type::CROSS) => { @@ -680,8 +618,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::HORIZONTAL_DOWN, boundary_type::HORIZONTAL_DOWN) => { @@ -690,8 +627,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::HORIZONTAL_DOWN, boundary_type::HORIZONTAL_UP) => { @@ -700,8 +636,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::HORIZONTAL_DOWN, boundary_type::CROSS) => { @@ -710,8 +645,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::HORIZONTAL_UP, boundary_type::HORIZONTAL_UP) => { @@ -720,8 +654,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::HORIZONTAL_UP, boundary_type::CROSS) => { @@ -730,8 +663,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (boundary_type::CROSS, boundary_type::CROSS) => { @@ -740,8 +672,7 @@ fn combine_symbols( Some(BoundarySymbol { boundary_type, invisible, - should_be_colored, - color, + color: color, }) } (_, _) => None, @@ -838,7 +769,7 @@ impl Boundaries { boundary_characters: HashMap::new(), } } - pub fn add_rect(&mut self, rect: &dyn Pane, should_be_colored: bool, input_mode: InputMode) { + pub fn add_rect(&mut self, rect: &dyn Pane, input_mode: InputMode, color: Option) { if rect.x() > 0 { let boundary_x_coords = rect.x() - 1; let first_row_coordinates = self.rect_right_boundary_row_start(rect); @@ -846,11 +777,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, should_be_colored) + 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, should_be_colored) + BoundarySymbol::new(boundary_type::BOTTOM_LEFT).color(color) } else { - BoundarySymbol::new(boundary_type::VERTICAL, should_be_colored) + BoundarySymbol::new(boundary_type::VERTICAL).color(color) }; if rect.invisible_borders() { symbol_to_add = symbol_to_add.invisible(); @@ -872,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, should_be_colored) + 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, should_be_colored) + BoundarySymbol::new(boundary_type::TOP_RIGHT).color(color) } else { - BoundarySymbol::new(boundary_type::HORIZONTAL, should_be_colored) + BoundarySymbol::new(boundary_type::HORIZONTAL).color(color) }; if rect.invisible_borders() { symbol_to_add = symbol_to_add.invisible(); @@ -899,11 +830,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, should_be_colored) + 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, should_be_colored) + BoundarySymbol::new(boundary_type::BOTTOM_RIGHT).color(color) } else { - BoundarySymbol::new(boundary_type::VERTICAL, should_be_colored) + BoundarySymbol::new(boundary_type::VERTICAL).color(color) }; if rect.invisible_borders() { symbol_to_add = symbol_to_add.invisible(); @@ -925,11 +856,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, should_be_colored) + 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, should_be_colored) + BoundarySymbol::new(boundary_type::BOTTOM_RIGHT).color(color) } else { - BoundarySymbol::new(boundary_type::HORIZONTAL, should_be_colored) + BoundarySymbol::new(boundary_type::HORIZONTAL).color(color) }; if rect.invisible_borders() { symbol_to_add = symbol_to_add.invisible(); diff --git a/src/client/tab.rs b/src/client/tab.rs index 8a515279..6370daf0 100644 --- a/src/client/tab.rs +++ b/src/client/tab.rs @@ -6,7 +6,10 @@ 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::Boundaries, panes::PluginPane}; +use crate::{ + boundaries::{colors, Boundaries}, + panes::PluginPane, +}; use crate::{os_input_output::OsApi, utils::shared::pad_to_size}; use serde::{Deserialize, Serialize}; use std::os::unix::io::RawFd; @@ -647,15 +650,16 @@ impl Tab { self.full_screen_ws.rows as u16, ); let hide_cursor = "\u{1b}[?25l"; - //let input_mode = self.get_state(&self.send_app_instructions); stdout .write_all(&hide_cursor.as_bytes()) .expect("cannot write to stdout"); for (kind, terminal) in self.panes.iter_mut() { if !self.panes_to_hide.contains(&terminal.pid()) { match self.active_terminal.unwrap() == terminal.pid() { - true => boundaries.add_rect(terminal.as_ref(), true, self.input_mode), - false => boundaries.add_rect(terminal.as_ref(), false, self.input_mode), + 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 { diff --git a/src/common/screen.rs b/src/common/screen.rs index d40a80c6..a074b300 100644 --- a/src/common/screen.rs +++ b/src/common/screen.rs @@ -312,7 +312,8 @@ impl Screen { } pub fn change_input_mode(&mut self, input_mode: InputMode) { self.input_mode = input_mode; - self.get_active_tab_mut().unwrap().input_mode = self.input_mode; - self.render(); + for tab in self.tabs.values_mut() { + tab.input_mode = self.input_mode; + } } } From 2913286d9e9cba3ea015ed168c1c44aeca29ca3f Mon Sep 17 00:00:00 2001 From: denis Date: Tue, 23 Mar 2021 10:01:36 +0200 Subject: [PATCH 09/12] wip: remove colored_borders --- src/client/boundaries.rs | 2 +- src/client/panes/plugin_pane.rs | 5 ----- src/client/tab.rs | 3 --- src/common/mod.rs | 1 - 4 files changed, 1 insertion(+), 10 deletions(-) diff --git a/src/client/boundaries.rs b/src/client/boundaries.rs index 74859b0f..85dfaa23 100644 --- a/src/client/boundaries.rs +++ b/src/client/boundaries.rs @@ -57,7 +57,7 @@ impl Display for BoundarySymbol { match self.invisible { true => write!(f, " "), false => match self.color { - Some(color) => write!(f, "{}", self.color.unwrap().paint(self.boundary_type)), + Some(_) => write!(f, "{}", self.color.unwrap().paint(self.boundary_type)), None => write!(f, "{}", self.boundary_type), }, } diff --git a/src/client/panes/plugin_pane.rs b/src/client/panes/plugin_pane.rs index 52e4c560..588cffd6 100644 --- a/src/client/panes/plugin_pane.rs +++ b/src/client/panes/plugin_pane.rs @@ -11,7 +11,6 @@ pub struct PluginPane { pub should_render: bool, pub selectable: bool, pub invisible_borders: bool, - pub colored_borders: bool, pub position_and_size: PositionAndSize, pub position_and_size_override: Option, pub send_plugin_instructions: SenderWithContext, @@ -29,7 +28,6 @@ impl PluginPane { should_render: true, selectable: true, invisible_borders: false, - colored_borders: false, position_and_size, position_and_size_override: None, send_plugin_instructions, @@ -190,7 +188,4 @@ impl Pane for PluginPane { fn invisible_borders(&self) -> bool { self.invisible_borders } - fn colored_borders(&self) -> bool { - self.colored_borders - } } diff --git a/src/client/tab.rs b/src/client/tab.rs index 6370daf0..5cb0fdce 100644 --- a/src/client/tab.rs +++ b/src/client/tab.rs @@ -179,9 +179,6 @@ pub trait Pane { fn invisible_borders(&self) -> bool { false } - fn colored_borders(&self) -> bool { - false - } } impl Tab { diff --git a/src/common/mod.rs b/src/common/mod.rs index d52b5a4c..7e52dde7 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -26,7 +26,6 @@ use wasmer::{ChainableNamedResolver, Instance, Module, Store, Value}; use wasmer_wasi::{Pipe, WasiState}; use crate::cli::CliArgs; -use crate::common::utils::logging::debug_log_to_file; use crate::layout::Layout; use command_is_executing::CommandIsExecuting; use errors::{AppContext, ContextType, ErrorContext, PluginContext, PtyContext, ScreenContext}; From 91608dfe4ea3e75853d4966d7f464d85c022beef Mon Sep 17 00:00:00 2001 From: denis Date: Wed, 24 Mar 2021 07:50:47 +0200 Subject: [PATCH 10/12] wip: cleanup the TabData, get rid of input_mode in tab, pass through render instead --- src/client/boundaries.rs | 15 ++++++++++----- src/client/tab.rs | 36 +++++++++++++++--------------------- src/common/screen.rs | 9 ++------- 3 files changed, 27 insertions(+), 33 deletions(-) diff --git a/src/client/boundaries.rs b/src/client/boundaries.rs index 85dfaa23..36fe17c5 100644 --- a/src/client/boundaries.rs +++ b/src/client/boundaries.rs @@ -57,7 +57,7 @@ impl Display for BoundarySymbol { match self.invisible { true => write!(f, " "), false => match self.color { - Some(_) => write!(f, "{}", self.color.unwrap().paint(self.boundary_type)), + Some(color) => write!(f, "{}", color.paint(self.boundary_type)), None => write!(f, "{}", self.boundary_type), }, } @@ -67,7 +67,7 @@ impl Display for BoundarySymbol { fn combine_symbols( current_symbol: BoundarySymbol, next_symbol: BoundarySymbol, - input_mode: InputMode, + input_mode: Option, ) -> Option { let invisible = current_symbol.invisible || next_symbol.invisible; let should_be_colored = current_symbol.color.is_some() || next_symbol.color.is_some(); @@ -75,7 +75,7 @@ fn combine_symbols( let next_symbol = next_symbol.boundary_type; let color = match should_be_colored { true => match input_mode { - InputMode::Normal | InputMode::Locked => Some(colors::GREEN), + Some(InputMode::Normal) | Some(InputMode::Locked) => Some(colors::GREEN), _ => Some(colors::WHITE), }, false => None, @@ -682,7 +682,7 @@ fn combine_symbols( fn find_next_symbol( first_symbol: BoundarySymbol, second_symbol: BoundarySymbol, - input_mode: InputMode, + input_mode: Option, ) -> Option { if let Some(symbol) = combine_symbols(first_symbol, second_symbol, input_mode) { Some(symbol) @@ -769,7 +769,12 @@ impl Boundaries { boundary_characters: HashMap::new(), } } - pub fn add_rect(&mut self, rect: &dyn Pane, input_mode: InputMode, color: Option) { + pub fn add_rect( + &mut self, + rect: &dyn Pane, + input_mode: Option, + color: Option, + ) { if rect.x() > 0 { let boundary_x_coords = rect.x() - 1; let first_row_coordinates = self.rect_right_boundary_row_start(rect); diff --git a/src/client/tab.rs b/src/client/tab.rs index 5cb0fdce..b58cc591 100644 --- a/src/client/tab.rs +++ b/src/client/tab.rs @@ -68,7 +68,6 @@ pub struct Tab { pub send_plugin_instructions: SenderWithContext, pub send_app_instructions: SenderWithContext, expansion_boundary: Option, - pub input_mode: InputMode, } #[derive(Clone, Debug, Default, Serialize, Deserialize)] @@ -77,7 +76,6 @@ pub struct TabData { 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 @@ -194,7 +192,6 @@ impl Tab { send_app_instructions: SenderWithContext, max_panes: Option, pane_id: Option, - input_mode: InputMode, ) -> Self { let panes = if let Some(PaneId::Terminal(pid)) = pane_id { let new_terminal = TerminalPane::new(pid, *full_screen_ws); @@ -224,7 +221,6 @@ impl Tab { send_pty_instructions, send_plugin_instructions, expansion_boundary: None, - input_mode, } } @@ -304,7 +300,7 @@ impl Tab { .unwrap(); } self.active_terminal = self.panes.iter().map(|(id, _)| id.to_owned()).next(); - self.render(); + self.render(None); } pub fn new_pane(&mut self, pid: PaneId) { self.close_down_to_max_terminals(); @@ -405,7 +401,7 @@ impl Tab { } } self.active_terminal = Some(pid); - self.render(); + self.render(None); } } pub fn horizontal_split(&mut self, pid: PaneId) { @@ -464,7 +460,7 @@ impl Tab { } self.active_terminal = Some(pid); - self.render(); + self.render(None); } } } @@ -524,7 +520,7 @@ impl Tab { } self.active_terminal = Some(pid); - self.render(); + self.render(None); } } } @@ -628,14 +624,14 @@ impl Tab { active_terminal.rows() as u16, ); } - self.render(); + self.render(None); self.toggle_fullscreen_is_active(); } } pub fn toggle_fullscreen_is_active(&mut self) { self.fullscreen_is_active = !self.fullscreen_is_active; } - pub fn render(&mut self) { + pub fn render(&mut self, input_mode: Option) { if self.active_terminal.is_none() { // we might not have an active terminal if we closed the last pane // in that case, we should not render as the app is exiting @@ -653,10 +649,8 @@ impl Tab { for (kind, terminal) in self.panes.iter_mut() { if !self.panes_to_hide.contains(&terminal.pid()) { 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), + true => boundaries.add_rect(terminal.as_ref(), input_mode, Some(colors::GREEN)), + false => boundaries.add_rect(terminal.as_ref(), input_mode, None), } if let Some(vte_output) = terminal.render() { let vte_output = if let PaneId::Terminal(_) = kind { @@ -1745,7 +1739,7 @@ impl Tab { } else { self.active_terminal = Some(*first_terminal); } - self.render(); + self.render(None); } pub fn move_focus_left(&mut self) { if !self.has_selectable_panes() { @@ -1775,7 +1769,7 @@ impl Tab { } else { self.active_terminal = Some(active_terminal.unwrap().pid()); } - self.render(); + self.render(None); } pub fn move_focus_down(&mut self) { if !self.has_selectable_panes() { @@ -1805,7 +1799,7 @@ impl Tab { } else { self.active_terminal = Some(active_terminal.unwrap().pid()); } - self.render(); + self.render(None); } pub fn move_focus_up(&mut self) { if !self.has_selectable_panes() { @@ -1835,7 +1829,7 @@ impl Tab { } else { self.active_terminal = Some(active_terminal.unwrap().pid()); } - self.render(); + self.render(None); } pub fn move_focus_right(&mut self) { if !self.has_selectable_panes() { @@ -1865,7 +1859,7 @@ impl Tab { } else { self.active_terminal = Some(active_terminal.unwrap().pid()); } - self.render(); + self.render(None); } fn horizontal_borders(&self, terminals: &[PaneId]) -> HashSet { terminals.iter().fold(HashSet::new(), |mut borders, t| { @@ -2072,7 +2066,7 @@ impl Tab { .get_mut(&PaneId::Terminal(active_terminal_id)) .unwrap(); active_terminal.scroll_up(1); - self.render(); + self.render(None); } } pub fn scroll_active_terminal_down(&mut self) { @@ -2082,7 +2076,7 @@ impl Tab { .get_mut(&PaneId::Terminal(active_terminal_id)) .unwrap(); active_terminal.scroll_down(1); - self.render(); + self.render(None); } } pub fn clear_active_terminal_scroll(&mut self) { diff --git a/src/common/screen.rs b/src/common/screen.rs index a074b300..1decb739 100644 --- a/src/common/screen.rs +++ b/src/common/screen.rs @@ -119,7 +119,6 @@ impl Screen { self.send_app_instructions.clone(), self.max_panes, Some(PaneId::Terminal(pane_id)), - self.input_mode, ); self.active_tab_index = Some(tab_index); self.tabs.insert(tab_index, tab); @@ -218,9 +217,10 @@ impl Screen { /// Renders this [`Screen`], which amounts to rendering its active [`Tab`]. pub fn render(&mut self) { + let input_mode = self.input_mode; if let Some(active_tab) = self.get_active_tab_mut() { if active_tab.get_active_pane().is_some() { - active_tab.render(); + active_tab.render(Some(input_mode)); } else { self.close_tab(); } @@ -264,7 +264,6 @@ impl Screen { self.send_app_instructions.clone(), self.max_panes, None, - self.input_mode, ); tab.apply_layout(layout, new_pids); self.active_tab_index = Some(tab_index); @@ -280,7 +279,6 @@ impl Screen { position: tab.position, name: tab.name.clone(), active: active_tab_index == tab.index, - input_mode: self.input_mode, }); } self.send_plugin_instructions @@ -312,8 +310,5 @@ impl Screen { } pub fn change_input_mode(&mut self, input_mode: InputMode) { self.input_mode = input_mode; - for tab in self.tabs.values_mut() { - tab.input_mode = self.input_mode; - } } } From 57e1f476f2323c4aff0d501d8905752dd6112ebe Mon Sep 17 00:00:00 2001 From: denis Date: Wed, 24 Mar 2021 11:23:03 +0200 Subject: [PATCH 11/12] wip: input_mode back in tab, not passing stuff around anymore --- src/client/boundaries.rs | 48 +++++++++++++++------------------------- src/client/tab.rs | 35 ++++++++++++++++------------- src/common/screen.rs | 8 +++++-- 3 files changed, 44 insertions(+), 47 deletions(-) diff --git a/src/client/boundaries.rs b/src/client/boundaries.rs index 36fe17c5..19a1058d 100644 --- a/src/client/boundaries.rs +++ b/src/client/boundaries.rs @@ -67,19 +67,14 @@ impl Display for BoundarySymbol { fn combine_symbols( current_symbol: BoundarySymbol, next_symbol: BoundarySymbol, - input_mode: Option, ) -> Option { let invisible = current_symbol.invisible || next_symbol.invisible; - let should_be_colored = current_symbol.color.is_some() || next_symbol.color.is_some(); + 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; - let color = match should_be_colored { - true => match input_mode { - Some(InputMode::Normal) | Some(InputMode::Locked) => Some(colors::GREEN), - _ => Some(colors::WHITE), - }, - false => None, - }; match (current_symbol, next_symbol) { (boundary_type::TOP_RIGHT, boundary_type::TOP_RIGHT) => { // (┐, ┐) => Some(┐) @@ -682,12 +677,11 @@ fn combine_symbols( fn find_next_symbol( first_symbol: BoundarySymbol, second_symbol: BoundarySymbol, - input_mode: Option, ) -> Option { - if let Some(symbol) = combine_symbols(first_symbol, second_symbol, input_mode) { + if let Some(symbol) = combine_symbols(first_symbol, second_symbol) { Some(symbol) } else { - combine_symbols(second_symbol, first_symbol, input_mode) + combine_symbols(second_symbol, first_symbol) } } @@ -769,12 +763,14 @@ impl Boundaries { boundary_characters: HashMap::new(), } } - pub fn add_rect( - &mut self, - rect: &dyn Pane, - input_mode: Option, - color: Option, - ) { + pub fn add_rect(&mut self, rect: &dyn Pane, input_mode: InputMode, color: Option) { + 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); @@ -794,9 +790,7 @@ impl Boundaries { let next_symbol = self .boundary_characters .remove(&coordinates) - .and_then(|current_symbol| { - find_next_symbol(current_symbol, symbol_to_add, input_mode) - }) + .and_then(|current_symbol| find_next_symbol(current_symbol, symbol_to_add)) .unwrap_or(symbol_to_add); self.boundary_characters.insert(coordinates, next_symbol); } @@ -820,9 +814,7 @@ impl Boundaries { let next_symbol = self .boundary_characters .remove(&coordinates) - .and_then(|current_symbol| { - find_next_symbol(current_symbol, symbol_to_add, input_mode) - }) + .and_then(|current_symbol| find_next_symbol(current_symbol, symbol_to_add)) .unwrap_or(symbol_to_add); self.boundary_characters.insert(coordinates, next_symbol); } @@ -847,9 +839,7 @@ impl Boundaries { let next_symbol = self .boundary_characters .remove(&coordinates) - .and_then(|current_symbol| { - find_next_symbol(current_symbol, symbol_to_add, input_mode) - }) + .and_then(|current_symbol| find_next_symbol(current_symbol, symbol_to_add)) .unwrap_or(symbol_to_add); self.boundary_characters.insert(coordinates, next_symbol); } @@ -873,9 +863,7 @@ impl Boundaries { let next_symbol = self .boundary_characters .remove(&coordinates) - .and_then(|current_symbol| { - find_next_symbol(current_symbol, symbol_to_add, input_mode) - }) + .and_then(|current_symbol| find_next_symbol(current_symbol, symbol_to_add)) .unwrap_or(symbol_to_add); self.boundary_characters.insert(coordinates, next_symbol); } diff --git a/src/client/tab.rs b/src/client/tab.rs index b58cc591..081194ed 100644 --- a/src/client/tab.rs +++ b/src/client/tab.rs @@ -68,6 +68,7 @@ pub struct Tab { pub send_plugin_instructions: SenderWithContext, pub send_app_instructions: SenderWithContext, expansion_boundary: Option, + pub input_mode: InputMode, } #[derive(Clone, Debug, Default, Serialize, Deserialize)] @@ -192,6 +193,7 @@ impl Tab { send_app_instructions: SenderWithContext, max_panes: Option, pane_id: Option, + input_mode: InputMode, ) -> Self { let panes = if let Some(PaneId::Terminal(pid)) = pane_id { let new_terminal = TerminalPane::new(pid, *full_screen_ws); @@ -221,6 +223,7 @@ impl Tab { send_pty_instructions, send_plugin_instructions, expansion_boundary: None, + input_mode, } } @@ -300,7 +303,7 @@ impl Tab { .unwrap(); } self.active_terminal = self.panes.iter().map(|(id, _)| id.to_owned()).next(); - self.render(None); + self.render(); } pub fn new_pane(&mut self, pid: PaneId) { self.close_down_to_max_terminals(); @@ -401,7 +404,7 @@ impl Tab { } } self.active_terminal = Some(pid); - self.render(None); + self.render(); } } pub fn horizontal_split(&mut self, pid: PaneId) { @@ -460,7 +463,7 @@ impl Tab { } self.active_terminal = Some(pid); - self.render(None); + self.render(); } } } @@ -520,7 +523,7 @@ impl Tab { } self.active_terminal = Some(pid); - self.render(None); + self.render(); } } } @@ -624,14 +627,14 @@ impl Tab { active_terminal.rows() as u16, ); } - self.render(None); + self.render(); self.toggle_fullscreen_is_active(); } } pub fn toggle_fullscreen_is_active(&mut self) { self.fullscreen_is_active = !self.fullscreen_is_active; } - pub fn render(&mut self, input_mode: Option) { + pub fn render(&mut self) { if self.active_terminal.is_none() { // we might not have an active terminal if we closed the last pane // in that case, we should not render as the app is exiting @@ -649,8 +652,10 @@ impl Tab { for (kind, terminal) in self.panes.iter_mut() { if !self.panes_to_hide.contains(&terminal.pid()) { match self.active_terminal.unwrap() == terminal.pid() { - true => boundaries.add_rect(terminal.as_ref(), input_mode, Some(colors::GREEN)), - false => boundaries.add_rect(terminal.as_ref(), input_mode, None), + 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 { @@ -1739,7 +1744,7 @@ impl Tab { } else { self.active_terminal = Some(*first_terminal); } - self.render(None); + self.render(); } pub fn move_focus_left(&mut self) { if !self.has_selectable_panes() { @@ -1769,7 +1774,7 @@ impl Tab { } else { self.active_terminal = Some(active_terminal.unwrap().pid()); } - self.render(None); + self.render(); } pub fn move_focus_down(&mut self) { if !self.has_selectable_panes() { @@ -1799,7 +1804,7 @@ impl Tab { } else { self.active_terminal = Some(active_terminal.unwrap().pid()); } - self.render(None); + self.render(); } pub fn move_focus_up(&mut self) { if !self.has_selectable_panes() { @@ -1829,7 +1834,7 @@ impl Tab { } else { self.active_terminal = Some(active_terminal.unwrap().pid()); } - self.render(None); + self.render(); } pub fn move_focus_right(&mut self) { if !self.has_selectable_panes() { @@ -1859,7 +1864,7 @@ impl Tab { } else { self.active_terminal = Some(active_terminal.unwrap().pid()); } - self.render(None); + self.render(); } fn horizontal_borders(&self, terminals: &[PaneId]) -> HashSet { terminals.iter().fold(HashSet::new(), |mut borders, t| { @@ -2066,7 +2071,7 @@ impl Tab { .get_mut(&PaneId::Terminal(active_terminal_id)) .unwrap(); active_terminal.scroll_up(1); - self.render(None); + self.render(); } } pub fn scroll_active_terminal_down(&mut self) { @@ -2076,7 +2081,7 @@ impl Tab { .get_mut(&PaneId::Terminal(active_terminal_id)) .unwrap(); active_terminal.scroll_down(1); - self.render(None); + self.render(); } } pub fn clear_active_terminal_scroll(&mut self) { diff --git a/src/common/screen.rs b/src/common/screen.rs index 1decb739..bb77ab85 100644 --- a/src/common/screen.rs +++ b/src/common/screen.rs @@ -119,6 +119,7 @@ impl Screen { self.send_app_instructions.clone(), self.max_panes, Some(PaneId::Terminal(pane_id)), + self.input_mode, ); self.active_tab_index = Some(tab_index); self.tabs.insert(tab_index, tab); @@ -217,10 +218,9 @@ impl Screen { /// Renders this [`Screen`], which amounts to rendering its active [`Tab`]. pub fn render(&mut self) { - let input_mode = self.input_mode; if let Some(active_tab) = self.get_active_tab_mut() { if active_tab.get_active_pane().is_some() { - active_tab.render(Some(input_mode)); + active_tab.render(); } else { self.close_tab(); } @@ -264,6 +264,7 @@ impl Screen { self.send_app_instructions.clone(), self.max_panes, None, + self.input_mode, ); tab.apply_layout(layout, new_pids); self.active_tab_index = Some(tab_index); @@ -310,5 +311,8 @@ impl Screen { } pub fn change_input_mode(&mut self, input_mode: InputMode) { self.input_mode = input_mode; + for tab in self.tabs.values_mut() { + tab.input_mode = self.input_mode; + } } } From e1e1f2104353ca021fe9b5261314ab6248c3b77c Mon Sep 17 00:00:00 2001 From: Aram Drevekenin Date: Wed, 24 Mar 2021 10:58:50 +0100 Subject: [PATCH 12/12] fix(render): various rendering issues (#238) --- src/client/panes/terminal_pane.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/client/panes/terminal_pane.rs b/src/client/panes/terminal_pane.rs index 9fa70d11..f0b15e50 100644 --- a/src/client/panes/terminal_pane.rs +++ b/src/client/panes/terminal_pane.rs @@ -188,7 +188,14 @@ impl Pane for TerminalPane { self.max_height } fn render(&mut self) -> Option { - if self.should_render || cfg!(test) { + // 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 { let mut vte_output = String::new(); let buffer_lines = &self.read_buffer_as_lines(); let display_cols = self.get_columns();