From 1a5d30d17d5b05f3a9c7372b78071d40363396aa Mon Sep 17 00:00:00 2001 From: denis Date: Sun, 7 Mar 2021 18:39:44 +0200 Subject: [PATCH 01/31] 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 3e10e345754e9b2759cf5240126de398921db691 Mon Sep 17 00:00:00 2001 From: Brooks J Rady Date: Tue, 9 Mar 2021 17:09:21 +0000 Subject: [PATCH 02/31] Rename init() to load() in plugin API + Bump deps --- Cargo.lock | 94 ++++++++++++++-------------- default-tiles/status-bar/src/main.rs | 2 +- default-tiles/strider/src/main.rs | 2 +- default-tiles/tab-bar/src/main.rs | 2 +- zellij-tile/src/lib.rs | 4 +- 5 files changed, 52 insertions(+), 52 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index eb1b291e..1a070709 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,9 +11,9 @@ dependencies = [ [[package]] name = "adler" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bedc89c5c7b5550ffb9372eb5c5ffc7f9f705cc3f4a128bd4669b9745f555093" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "ansi_term" @@ -214,9 +214,9 @@ checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" [[package]] name = "bitvec" -version = "0.19.4" +version = "0.19.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7ba35e9565969edb811639dbebfe34edc0368e472c5018474c8eb2543397f81" +checksum = "8942c8d352ae1838c9dda0b0ca2ab657696ef2232a20147cf1b30ae1a9cb4321" dependencies = [ "funty", "radium", @@ -527,9 +527,9 @@ checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" [[package]] name = "enumset" -version = "1.0.5" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c70e3089d60da62772627697a83dd166615072eebe1a52ac05f16bdbd0165dc3" +checksum = "fbd795df6708a599abf1ee10eacc72efd052b7a5f70fdf0715e4d5151a6db9c3" dependencies = [ "enumset_derive", ] @@ -798,9 +798,9 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "indexmap" -version = "1.6.1" +version = "1.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb1fa934250de4de8aef298d81c729a7d33d8c239daa3a7575e6b92bfc7313b" +checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3" dependencies = [ "autocfg", "hashbrown", @@ -809,9 +809,9 @@ dependencies = [ [[package]] name = "insta" -version = "1.6.3" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd354a2c8c8083d58414597a4ecada1984f9b82ea7e87eeabddc869eaf120992" +checksum = "e1b6cf41e31a7e7b78055b548826da45c7dc74e6a13a3fa6b897a17a01322f26" dependencies = [ "console", "lazy_static", @@ -833,16 +833,16 @@ dependencies = [ [[package]] name = "interprocess" -version = "1.1.0" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98969eda6bf33b8532e8a7b8f157afc43556188741fa0df8c92b8780f8654e52" +checksum = "1c58ec7fbda1df9a93f587b780659db3c99f61f4be27f9c82c9b37684ffd0366" dependencies = [ "blocking", "cfg-if 1.0.0", "futures", "intmap", - "lazy_static", "libc", + "once_cell", "spinning", "thiserror", "winapi", @@ -884,9 +884,9 @@ checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" [[package]] name = "js-sys" -version = "0.3.47" +version = "0.3.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cfb73131c35423a367daf8cbd24100af0d077668c8c2943f0e7dd775fef0f65" +checksum = "dc9f84f9b115ce7843d60706df1422a916680bfdfcbdb0447c5614ff9d7e4d78" dependencies = [ "wasm-bindgen", ] @@ -927,9 +927,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.86" +version = "0.2.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7282d924be3275cec7f6756ff4121987bc6481325397dde6ba3e7802b1a8b1c" +checksum = "03b07a082330a35e43f63177cc01689da34fbffa0105e1246cf0311472cac73a" [[package]] name = "libloading" @@ -1084,9 +1084,9 @@ checksum = "a9a7ab5d64814df0fe4a4b5ead45ed6c5f181ee3ff04ba344313a6c80446c5d4" [[package]] name = "once_cell" -version = "1.7.0" +version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10acf907b94fc1b1a152d08ef97e7759650268cf986bf127f387e602b02c7e5a" +checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3" [[package]] name = "parking" @@ -1096,9 +1096,9 @@ checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72" [[package]] name = "pin-project-lite" -version = "0.2.4" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "439697af366c49a6d0a010c56a0d97685bc140ce0d377b13a2ea2aa42d64a827" +checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905" [[package]] name = "pin-utils" @@ -1361,9 +1361,9 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "serde" -version = "1.0.123" +version = "1.0.124" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92d5161132722baa40d802cc70b15262b98258453e85e5d1d365c757c73869ae" +checksum = "bd761ff957cb2a45fbb9ab3da6512de9de55872866160b23c25f1a841e99d29f" dependencies = [ "serde_derive", ] @@ -1379,9 +1379,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.123" +version = "1.0.124" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9391c295d64fc0abb2c556bad848f33cb8296276b1ad2677d1ae1ace4f258f31" +checksum = "1800f7693e94e186f5e25a28291ae1570da908aff7d97a095dec1e56ff99069b" dependencies = [ "proc-macro2", "quote", @@ -1390,9 +1390,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43535db9747a4ba938c0ce0a98cc631a46ebf943c9e1d604e091df6007620bf6" +checksum = "799e97dc9fdae36a5c8b8f2cae9ce2ee9fdce2058c57a93e6099d919fd982f79" dependencies = [ "itoa", "ryu", @@ -1572,9 +1572,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.60" +version = "1.0.62" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c700597eca8a5a762beb35753ef6b94df201c81cca676604f547495a0d7f0081" +checksum = "123a78a3596b24fee53a6464ce52d8ecbf62241e6294c7e7fe12086cd161f512" dependencies = [ "proc-macro2", "quote", @@ -1879,9 +1879,9 @@ checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" [[package]] name = "wasm-bindgen" -version = "0.2.70" +version = "0.2.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55c0f7123de74f0dab9b7d00fd614e7b19349cd1e2f5252bbe9b1754b59433be" +checksum = "7ee1280240b7c461d6a0071313e08f34a60b0365f14260362e5a2b17d1d31aa7" dependencies = [ "cfg-if 1.0.0", "wasm-bindgen-macro", @@ -1889,9 +1889,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.70" +version = "0.2.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7bc45447f0d4573f3d65720f636bbcc3dd6ce920ed704670118650bcd47764c7" +checksum = "5b7d8b6942b8bb3a9b0e73fc79b98095a27de6fa247615e59d096754a3bc2aa8" dependencies = [ "bumpalo", "lazy_static", @@ -1904,9 +1904,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.20" +version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3de431a2910c86679c34283a33f66f4e4abd7e0aec27b6669060148872aadf94" +checksum = "8e67a5806118af01f0d9045915676b22aaebecf4178ae7021bc171dab0b897ab" dependencies = [ "cfg-if 1.0.0", "js-sys", @@ -1916,9 +1916,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.70" +version = "0.2.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b8853882eef39593ad4174dd26fc9865a64e84026d223f63bb2c42affcbba2c" +checksum = "e5ac38da8ef716661f0f36c0d8320b89028efe10c7c0afde65baffb496ce0d3b" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1926,9 +1926,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.70" +version = "0.2.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4133b5e7f2a531fa413b3a1695e925038a05a71cf67e87dafa295cb645a01385" +checksum = "cc053ec74d454df287b9374ee8abb36ffd5acb95ba87da3ba5b7d3fe20eb401e" dependencies = [ "proc-macro2", "quote", @@ -1939,9 +1939,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.70" +version = "0.2.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd4945e4943ae02d15c13962b38a5b1e81eadd4b71214eee75af64a4d6a4fd64" +checksum = "7d6f8ec44822dd71f5f221a5847fb34acd9060535c1211b70a05844c0f6383b1" [[package]] name = "wasmer" @@ -2145,27 +2145,27 @@ checksum = "87cc2fe6350834b4e528ba0901e7aa405d78b89dc1fa3145359eb4de0e323fcf" [[package]] name = "wast" -version = "34.0.0" +version = "35.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3de71ea922e46a60d0bde4b27ebf24ab7c4991006fd5de23ce9c58e129b3ab3c" +checksum = "db5ae96da18bb5926341516fd409b5a8ce4e4714da7f0a1063d3b20ac9f9a1e1" dependencies = [ "leb128", ] [[package]] name = "wat" -version = "1.0.35" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "474403335b9a90b21120ab8131dd888f0a8d041c2d365ab960feddfe5a73c4b6" +checksum = "0b0fa059022c5dabe129f02b429d67086400deb8277f89c975555dacc1dadbcc" dependencies = [ "wast", ] [[package]] name = "web-sys" -version = "0.3.47" +version = "0.3.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c40dc691fc48003eba817c38da7113c15698142da971298003cac3ef175680b3" +checksum = "ec600b26223b2948cedfde2a0aa6756dcf1fef616f43d7b3097aaf53a6c4d92b" dependencies = [ "js-sys", "wasm-bindgen", diff --git a/default-tiles/status-bar/src/main.rs b/default-tiles/status-bar/src/main.rs index 1b64a304..b34fa69b 100644 --- a/default-tiles/status-bar/src/main.rs +++ b/default-tiles/status-bar/src/main.rs @@ -230,7 +230,7 @@ fn keybinds(help: &Help, max_width: usize) -> LinePart { } impl ZellijTile for State { - fn init(&mut self) { + fn load(&mut self) { set_selectable(false); set_invisible_borders(true); set_max_height(1); diff --git a/default-tiles/strider/src/main.rs b/default-tiles/strider/src/main.rs index 3213b2af..415d5217 100644 --- a/default-tiles/strider/src/main.rs +++ b/default-tiles/strider/src/main.rs @@ -8,7 +8,7 @@ use zellij_tile::*; register_tile!(State); impl ZellijTile for State { - fn init(&mut self) { + fn load(&mut self) { refresh_directory(self); } diff --git a/default-tiles/tab-bar/src/main.rs b/default-tiles/tab-bar/src/main.rs index 9f1c10ea..4c49812f 100644 --- a/default-tiles/tab-bar/src/main.rs +++ b/default-tiles/tab-bar/src/main.rs @@ -38,7 +38,7 @@ static ARROW_SEPARATOR: &str = ""; register_tile!(State); impl ZellijTile for State { - fn init(&mut self) { + fn load(&mut self) { set_selectable(false); set_invisible_borders(true); set_max_height(1); diff --git a/zellij-tile/src/lib.rs b/zellij-tile/src/lib.rs index de87ee9c..51ec9680 100644 --- a/zellij-tile/src/lib.rs +++ b/zellij-tile/src/lib.rs @@ -3,7 +3,7 @@ mod shim; pub use shim::*; #[allow(unused_variables)] pub trait ZellijTile { - fn init(&mut self) {} + fn load(&mut self) {} fn draw(&mut self, rows: usize, cols: usize) {} fn handle_key(&mut self, key: Key) {} fn handle_global_key(&mut self, key: Key) {} @@ -20,7 +20,7 @@ macro_rules! register_tile { fn main() { STATE.with(|state| { - state.borrow_mut().init(); + state.borrow_mut().load(); }); } From 06bce9a1fd88651a2e85c120776bc07399206806 Mon Sep 17 00:00:00 2001 From: Brooks J Rady Date: Tue, 9 Mar 2021 19:39:42 +0000 Subject: [PATCH 03/31] Deduplicate the WASM interface structs --- Cargo.lock | 4 +- Cargo.toml | 4 +- default-tiles/status-bar/src/main.rs | 4 +- default-tiles/strider/src/main.rs | 2 +- default-tiles/tab-bar/src/main.rs | 2 +- src/client/tab.rs | 9 ---- src/common/input/actions.rs | 4 +- src/common/input/handler.rs | 39 +--------------- src/common/input/keybinds.rs | 2 +- src/common/mod.rs | 17 ++++--- src/common/screen.rs | 4 +- src/common/wasm_vm.rs | 2 +- zellij-tile/Cargo.toml | 4 +- zellij-tile/src/data.rs | 68 ++++++++++++++++++++++++++++ zellij-tile/src/lib.rs | 15 ++++-- zellij-tile/src/prelude.rs | 3 ++ zellij-tile/src/shim.rs | 58 +----------------------- 17 files changed, 111 insertions(+), 130 deletions(-) create mode 100644 zellij-tile/src/data.rs create mode 100644 zellij-tile/src/prelude.rs diff --git a/Cargo.lock b/Cargo.lock index 1a070709..6b20bdc9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2258,7 +2258,6 @@ dependencies = [ "strip-ansi-escapes", "structopt", "strum", - "strum_macros", "termion_temporary_zellij_fork", "termios", "toml", @@ -2268,6 +2267,7 @@ dependencies = [ "walkdir", "wasmer", "wasmer-wasi", + "zellij-tile", ] [[package]] @@ -2276,4 +2276,6 @@ version = "0.5.0" dependencies = [ "serde", "serde_json", + "strum", + "strum_macros", ] diff --git a/Cargo.toml b/Cargo.toml index 1d9ac68f..b5266a8c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,17 +27,17 @@ signal-hook = "0.1.10" strip-ansi-escapes = "0.1.0" structopt = "0.3" # termion = { git = "https://gitlab.com/TheLostLambda/termion.git", version = "1.6.0", features = ["serde"] } -termion = { package = "termion_temporary_zellij_fork" , version = "1.6.0", features = ["serde"]} +termion = { package = "termion_temporary_zellij_fork", version = "1.6.0", features = ["serde"]} termios = "0.3" unicode-truncate = "0.2.0" unicode-width = "0.1.8" vte = "0.8.0" strum = "0.20.0" -strum_macros = "0.20.0" lazy_static = "1.4.0" wasmer = "1.0.0" wasmer-wasi = "1.0.0" interprocess = "1.0.1" +zellij-tile = { path = "zellij-tile/", version = "0.5.0" } [dependencies.async-std] version = "1.3.0" diff --git a/default-tiles/status-bar/src/main.rs b/default-tiles/status-bar/src/main.rs index b34fa69b..68f56b7f 100644 --- a/default-tiles/status-bar/src/main.rs +++ b/default-tiles/status-bar/src/main.rs @@ -1,6 +1,6 @@ use colored::*; use std::fmt::{Display, Error, Formatter}; -use zellij_tile::*; +use zellij_tile::prelude::*; // for more of these, copy paste from: https://en.wikipedia.org/wiki/Box-drawing_character static ARROW_SEPARATOR: &str = " "; @@ -152,7 +152,7 @@ fn key_path(help: &Help) -> LinePart { len, ) } - InputMode::Normal | _ => { + InputMode::Normal => { let key_path = superkey_text.on_green(); let separator = ARROW_SEPARATOR.green().on_black(); ( diff --git a/default-tiles/strider/src/main.rs b/default-tiles/strider/src/main.rs index 415d5217..81a31ce1 100644 --- a/default-tiles/strider/src/main.rs +++ b/default-tiles/strider/src/main.rs @@ -3,7 +3,7 @@ mod state; use colored::*; use state::{FsEntry, State}; use std::{cmp::min, fs::read_dir}; -use zellij_tile::*; +use zellij_tile::prelude::*; register_tile!(State); diff --git a/default-tiles/tab-bar/src/main.rs b/default-tiles/tab-bar/src/main.rs index 4c49812f..5220509b 100644 --- a/default-tiles/tab-bar/src/main.rs +++ b/default-tiles/tab-bar/src/main.rs @@ -1,7 +1,7 @@ mod line; mod tab; -use zellij_tile::*; +use zellij_tile::prelude::*; use crate::line::tab_line; use crate::tab::tab_style; diff --git a/src/client/tab.rs b/src/client/tab.rs index 1ef0b720..8ee3775b 100644 --- a/src/client/tab.rs +++ b/src/client/tab.rs @@ -8,7 +8,6 @@ use crate::pty_bus::{PtyInstruction, VteEvent}; use crate::wasm_vm::{PluginInputType, PluginInstruction}; use crate::{boundaries::Boundaries, panes::PluginPane}; use crate::{os_input_output::OsApi, utils::shared::pad_to_size}; -use serde::{Deserialize, Serialize}; use std::os::unix::io::RawFd; use std::{ cmp::Reverse, @@ -67,14 +66,6 @@ pub struct Tab { expansion_boundary: Option, } -#[derive(Clone, Debug, Default, Serialize, Deserialize)] -pub struct TabData { - /* subset of fields to publish to plugins */ - pub position: usize, - pub name: String, - pub active: bool, -} - // FIXME: Use a struct that has a pane_type enum, to reduce all of the duplication pub trait Pane { fn x(&self) -> usize; diff --git a/src/common/input/actions.rs b/src/common/input/actions.rs index 88a7036f..059255d3 100644 --- a/src/common/input/actions.rs +++ b/src/common/input/actions.rs @@ -1,6 +1,6 @@ //! Definition of the actions that can be bound to keys. -use super::handler; +use zellij_tile::data::InputMode; /// The four directions (left, right, up, down). #[derive(Clone, Debug)] @@ -19,7 +19,7 @@ pub enum Action { /// Write to the terminal. Write(Vec), /// Switch to the specified input mode. - SwitchToMode(handler::InputMode), + SwitchToMode(InputMode), /// Resize focus pane in specified direction. Resize(Direction), /// Switch focus to next pane in specified direction. diff --git a/src/common/input/handler.rs b/src/common/input/handler.rs index 52db9b4f..e498fbb6 100644 --- a/src/common/input/handler.rs +++ b/src/common/input/handler.rs @@ -10,9 +10,8 @@ use crate::screen::ScreenInstruction; use crate::wasm_vm::{EventType, PluginInputType, PluginInstruction}; use crate::CommandIsExecuting; -use serde::{Deserialize, Serialize}; -use strum_macros::EnumIter; use termion::input::TermReadEventsAndRaw; +use zellij_tile::data::{Help, InputMode}; use super::keybinds::key_to_actions; @@ -269,42 +268,6 @@ impl InputHandler { } } -/// Describes the different input modes, which change the way that keystrokes will be interpreted. -#[derive(Debug, PartialEq, Eq, Hash, Copy, Clone, EnumIter, Serialize, Deserialize)] -pub enum InputMode { - /// In `Normal` mode, input is always written to the terminal, except for one special input that - /// triggers the switch to [`InputMode::Command`] mode. - Normal, - /// In `Command` mode, input is bound to actions (more precisely, sequences of actions). - /// `Command` mode gives access to the other modes non-`InputMode::Normal` modes. - /// etc. - Command, - /// `Resize` mode allows resizing the different existing panes. - Resize, - /// `Pane` mode allows creating and closing panes, as well as moving between them. - Pane, - /// `Tab` mode allows creating and closing tabs, as well as moving between them. - Tab, - /// `Scroll` mode allows scrolling up and down within a pane. - Scroll, - RenameTab, -} - -/// Represents the contents of the help message that is printed in the status bar, -/// which indicates the current [`InputMode`] and what the keybinds for that mode -/// are. Related to the default `status-bar` plugin. -#[derive(Default, Debug, Clone, Serialize, Deserialize)] -pub struct Help { - pub mode: InputMode, - pub keybinds: Vec<(String, String)>, // => -} - -impl Default for InputMode { - fn default() -> InputMode { - InputMode::Normal - } -} - /// Creates a [`Help`] struct indicating the current [`InputMode`] and its keybinds /// (as pairs of [`String`]s). // TODO this should probably be automatically generated in some way diff --git a/src/common/input/keybinds.rs b/src/common/input/keybinds.rs index 46abf4ab..da0f1c15 100644 --- a/src/common/input/keybinds.rs +++ b/src/common/input/keybinds.rs @@ -1,12 +1,12 @@ //! Mapping of inputs to sequences of actions. use super::actions::{Action, Direction}; -use super::handler::InputMode; use std::collections::HashMap; use strum::IntoEnumIterator; use termion::event::Key; +use zellij_tile::data::*; type Keybinds = HashMap; type ModeKeybinds = HashMap>; diff --git a/src/common/mod.rs b/src/common/mod.rs index 7b19bcef..9c41e131 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -16,27 +16,26 @@ use std::thread; use std::{cell::RefCell, sync::mpsc::TrySendError}; use std::{collections::HashMap, fs}; -use crate::panes::PaneId; -use directories_next::ProjectDirs; -use input::handler::InputMode; -use serde::{Deserialize, Serialize}; -use termion::input::TermRead; -use wasm_vm::PluginEnv; -use wasmer::{ChainableNamedResolver, Instance, Module, Store, Value}; -use wasmer_wasi::{Pipe, WasiState}; - use crate::cli::CliArgs; use crate::layout::Layout; +use crate::panes::PaneId; use command_is_executing::CommandIsExecuting; +use directories_next::ProjectDirs; use errors::{AppContext, ContextType, ErrorContext, PluginContext, PtyContext, ScreenContext}; use input::handler::input_loop; use os_input_output::OsApi; use pty_bus::{PtyBus, PtyInstruction}; use screen::{Screen, ScreenInstruction}; +use serde::{Deserialize, Serialize}; +use termion::input::TermRead; use utils::consts::{ZELLIJ_IPC_PIPE, ZELLIJ_ROOT_PLUGIN_DIR}; +use wasm_vm::PluginEnv; use wasm_vm::{ wasi_stdout, wasi_write_string, zellij_imports, EventType, PluginInputType, PluginInstruction, }; +use wasmer::{ChainableNamedResolver, Instance, Module, Store, Value}; +use wasmer_wasi::{Pipe, WasiState}; +use zellij_tile::data::InputMode; #[derive(Serialize, Deserialize, Debug)] pub enum ApiCommand { diff --git a/src/common/screen.rs b/src/common/screen.rs index 199a1223..b848cc49 100644 --- a/src/common/screen.rs +++ b/src/common/screen.rs @@ -9,10 +9,12 @@ use super::{AppInstruction, SenderWithContext}; use crate::os_input_output::OsApi; use crate::panes::PositionAndSize; use crate::pty_bus::{PtyInstruction, VteEvent}; -use crate::tab::{Tab, TabData}; +use crate::tab::Tab; use crate::{errors::ErrorContext, wasm_vm::PluginInstruction}; use crate::{layout::Layout, panes::PaneId}; +use zellij_tile::data::TabData; + /// Instructions that can be sent to the [`Screen`]. #[derive(Debug, Clone)] pub enum ScreenInstruction { diff --git a/src/common/wasm_vm.rs b/src/common/wasm_vm.rs index 15b920ad..24e8d2a6 100644 --- a/src/common/wasm_vm.rs +++ b/src/common/wasm_vm.rs @@ -1,4 +1,3 @@ -use crate::tab::TabData; use serde::{Deserialize, Serialize}; use std::{ path::PathBuf, @@ -6,6 +5,7 @@ use std::{ }; use wasmer::{imports, Function, ImportObject, Store, WasmerEnv}; use wasmer_wasi::WasiEnv; +use zellij_tile::data::TabData; use super::{ input::handler::get_help, pty_bus::PtyInstruction, screen::ScreenInstruction, AppInstruction, diff --git a/zellij-tile/Cargo.toml b/zellij-tile/Cargo.toml index bdabb175..eb9a2d59 100644 --- a/zellij-tile/Cargo.toml +++ b/zellij-tile/Cargo.toml @@ -8,4 +8,6 @@ license = "MIT" [dependencies] serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" \ No newline at end of file +serde_json = "1.0" +strum = "0.20.0" +strum_macros = "0.20.0" \ No newline at end of file diff --git a/zellij-tile/src/data.rs b/zellij-tile/src/data.rs new file mode 100644 index 00000000..b64f1e4e --- /dev/null +++ b/zellij-tile/src/data.rs @@ -0,0 +1,68 @@ +use serde::{Deserialize, Serialize}; +use strum_macros::EnumIter; + +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] +pub enum Key { + Backspace, + Left, + Right, + Up, + Down, + Home, + End, + PageUp, + PageDown, + BackTab, + Delete, + Insert, + F(u8), + Char(char), + Alt(char), + Ctrl(char), + Null, + Esc, +} + +/// Describes the different input modes, which change the way that keystrokes will be interpreted. +#[derive(Debug, PartialEq, Eq, Hash, Copy, Clone, EnumIter, Serialize, Deserialize)] +pub enum InputMode { + /// In `Normal` mode, input is always written to the terminal, except for one special input that + /// triggers the switch to [`InputMode::Command`] mode. + Normal, + /// In `Command` mode, input is bound to actions (more precisely, sequences of actions). + /// `Command` mode gives access to the other modes non-`InputMode::Normal` modes. + /// etc. + Command, + /// `Resize` mode allows resizing the different existing panes. + Resize, + /// `Pane` mode allows creating and closing panes, as well as moving between them. + Pane, + /// `Tab` mode allows creating and closing tabs, as well as moving between them. + Tab, + /// `Scroll` mode allows scrolling up and down within a pane. + Scroll, + RenameTab, +} + +impl Default for InputMode { + fn default() -> InputMode { + InputMode::Normal + } +} + +/// Represents the contents of the help message that is printed in the status bar, +/// which indicates the current [`InputMode`] and what the keybinds for that mode +/// are. Related to the default `status-bar` plugin. +#[derive(Default, Debug, Clone, Serialize, Deserialize)] +pub struct Help { + pub mode: InputMode, + pub keybinds: Vec<(String, String)>, // => +} + +#[derive(Debug, Clone, Deserialize, Serialize)] +pub struct TabData { + /* subset of fields to publish to plugins */ + pub position: usize, + pub name: String, + pub active: bool, +} diff --git a/zellij-tile/src/lib.rs b/zellij-tile/src/lib.rs index 51ec9680..ea38f6c9 100644 --- a/zellij-tile/src/lib.rs +++ b/zellij-tile/src/lib.rs @@ -1,6 +1,9 @@ -mod shim; +pub mod data; +pub mod prelude; +pub mod shim; + +use data::*; -pub use shim::*; #[allow(unused_variables)] pub trait ZellijTile { fn load(&mut self) {} @@ -34,14 +37,16 @@ macro_rules! register_tile { #[no_mangle] pub fn handle_key() { STATE.with(|state| { - state.borrow_mut().handle_key($crate::get_key()); + state.borrow_mut().handle_key($crate::shim::get_key()); }); } #[no_mangle] pub fn handle_global_key() { STATE.with(|state| { - state.borrow_mut().handle_global_key($crate::get_key()); + state + .borrow_mut() + .handle_global_key($crate::shim::get_key()); }); } @@ -57,7 +62,7 @@ macro_rules! register_tile { STATE.with(|state| { state .borrow_mut() - .handle_tab_rename_keypress($crate::get_key()); + .handle_tab_rename_keypress($crate::shim::get_key()); }) } }; diff --git a/zellij-tile/src/prelude.rs b/zellij-tile/src/prelude.rs new file mode 100644 index 00000000..2dd24a47 --- /dev/null +++ b/zellij-tile/src/prelude.rs @@ -0,0 +1,3 @@ +pub use crate::data::*; +pub use crate::shim::*; +pub use crate::*; diff --git a/zellij-tile/src/shim.rs b/zellij-tile/src/shim.rs index 20185c72..bb038e82 100644 --- a/zellij-tile/src/shim.rs +++ b/zellij-tile/src/shim.rs @@ -1,61 +1,7 @@ -use serde::{de::DeserializeOwned, Deserialize, Serialize}; +use serde::de::DeserializeOwned; use std::{io, path::Path}; -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] -pub enum Key { - Backspace, - Left, - Right, - Up, - Down, - Home, - End, - PageUp, - PageDown, - BackTab, - Delete, - Insert, - F(u8), - Char(char), - Alt(char), - Ctrl(char), - Null, - Esc, -} - -// TODO: use same struct from main crate? -#[derive(Default, Debug, Clone, Serialize, Deserialize)] -pub struct Help { - pub mode: InputMode, - pub keybinds: Vec<(String, String)>, -} - -// TODO: use same struct from main crate? -#[derive(Debug, Clone, Deserialize, Serialize)] -pub enum InputMode { - Normal, - Command, - Resize, - Pane, - Tab, - RenameTab, - Scroll, - Exiting, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct TabData { - /* subset of fields to publish to plugins */ - pub position: usize, - pub name: String, - pub active: bool, -} - -impl Default for InputMode { - fn default() -> InputMode { - InputMode::Normal - } -} +use crate::data::*; pub fn get_key() -> Key { deserialize_from_stdin().unwrap() From e9ab81850e61b9b5e9c1f25d79cafd8378bda600 Mon Sep 17 00:00:00 2001 From: Brooks J Rady Date: Tue, 9 Mar 2021 21:51:17 +0000 Subject: [PATCH 04/31] Add event subscription tracking --- build-all.sh | 18 +++++++--------- default-tiles/tab-bar/src/main.rs | 2 +- src/client/layout.rs | 4 ++-- src/common/errors.rs | 2 ++ src/common/input/handler.rs | 6 +++--- src/common/mod.rs | 24 ++++++++++++++------- src/common/screen.rs | 4 ++-- src/common/wasm_vm.rs | 35 +++++++++++++++++++++++-------- zellij-tile/src/data.rs | 16 +++++++++++--- zellij-tile/src/shim.rs | 14 ++++++++++++- 10 files changed, 85 insertions(+), 40 deletions(-) diff --git a/build-all.sh b/build-all.sh index df8e6978..f267b110 100755 --- a/build-all.sh +++ b/build-all.sh @@ -1,29 +1,25 @@ #!/bin/sh -total=6 +total=5 # This is temporary while https://github.com/rust-lang/cargo/issues/7004 is open -echo "Building zellij-tile (1/$total)..." -cd zellij-tile +echo "Building status-bar (1/$total)..." +cd default-tiles/status-bar cargo build --release --target-dir ../../target -echo "Building status-bar (2/$total)..." -cd ../default-tiles/status-bar -cargo build --release --target-dir ../../target - -echo "Building strider (3/$total)..." +echo "Building strider (2/$total)..." cd ../strider cargo build --release --target-dir ../../target -echo "Building tab-bar (4/$total)..." +echo "Building tab-bar (3/$total)..." cd ../tab-bar cargo build --release --target-dir ../../target -echo "Optimising WASM executables (5/$total)..." +echo "Optimising WASM executables (4/$total)..." cd ../.. wasm-opt -O target/wasm32-wasi/release/status-bar.wasm -o target/status-bar.wasm || cp target/wasm32-wasi/release/status-bar.wasm target/status-bar.wasm wasm-opt -O target/wasm32-wasi/release/strider.wasm -o target/strider.wasm || cp target/wasm32-wasi/release/strider.wasm target/strider.wasm wasm-opt -O target/wasm32-wasi/release/tab-bar.wasm -o target/tab-bar.wasm || cp target/wasm32-wasi/release/tab-bar.wasm target/tab-bar.wasm -echo "Building zellij (6/$total)..." +echo "Building zellij (5/$total)..." cargo build --target-dir target $@ diff --git a/default-tiles/tab-bar/src/main.rs b/default-tiles/tab-bar/src/main.rs index 5220509b..6c00cb79 100644 --- a/default-tiles/tab-bar/src/main.rs +++ b/default-tiles/tab-bar/src/main.rs @@ -28,7 +28,7 @@ impl Default for BarMode { struct State { active_tab_index: usize, num_tabs: usize, - tabs: Vec, + tabs: Vec, mode: BarMode, new_name: String, } diff --git a/src/client/layout.rs b/src/client/layout.rs index 1b383540..33df2a2f 100644 --- a/src/client/layout.rs +++ b/src/client/layout.rs @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize}; use std::path::{Path, PathBuf}; use std::{fs::File, io::prelude::*}; -use crate::common::wasm_vm::EventType; +use crate::common::wasm_vm::NaughtyEventType; use crate::panes::PositionAndSize; fn split_space_to_parts_vertically( @@ -182,7 +182,7 @@ pub struct Layout { #[serde(default)] pub expansion_boundary: bool, #[serde(default, skip_serializing_if = "Vec::is_empty")] - pub events: Vec, + pub events: Vec, } impl Layout { diff --git a/src/common/errors.rs b/src/common/errors.rs index df741629..48a92b76 100644 --- a/src/common/errors.rs +++ b/src/common/errors.rs @@ -164,6 +164,7 @@ impl Display for ContextType { } } +// FIXME: Just deriving EnumDiscriminants from strum will remove the need for any of this!!! /// Stack call representations corresponding to the different types of [`ScreenInstruction`]s. #[derive(Debug, Clone, Copy, PartialEq)] pub enum ScreenContext { @@ -201,6 +202,7 @@ pub enum ScreenContext { UpdateTabName, } +// FIXME: Just deriving EnumDiscriminants from strum will remove the need for any of this!!! impl From<&ScreenInstruction> for ScreenContext { fn from(screen_instruction: &ScreenInstruction) -> Self { match *screen_instruction { diff --git a/src/common/input/handler.rs b/src/common/input/handler.rs index e498fbb6..40d53d5d 100644 --- a/src/common/input/handler.rs +++ b/src/common/input/handler.rs @@ -7,7 +7,7 @@ use crate::errors::ContextType; use crate::os_input_output::OsApi; use crate::pty_bus::PtyInstruction; use crate::screen::ScreenInstruction; -use crate::wasm_vm::{EventType, PluginInputType, PluginInstruction}; +use crate::wasm_vm::{NaughtyEventType, PluginInputType, PluginInstruction}; use crate::CommandIsExecuting; use termion::input::TermReadEventsAndRaw; @@ -234,7 +234,7 @@ impl InputHandler { Action::TabNameInput(c) => { self.send_plugin_instructions .send(PluginInstruction::Input( - PluginInputType::Event(EventType::Tab), + PluginInputType::Event(NaughtyEventType::Tab), c.clone(), )) .unwrap(); @@ -245,7 +245,7 @@ impl InputHandler { Action::SaveTabName => { self.send_plugin_instructions .send(PluginInstruction::Input( - PluginInputType::Event(EventType::Tab), + PluginInputType::Event(NaughtyEventType::Tab), vec![b'\n'], )) .unwrap(); diff --git a/src/common/mod.rs b/src/common/mod.rs index 9c41e131..411269b6 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -9,12 +9,16 @@ pub mod screen; pub mod utils; pub mod wasm_vm; -use std::io::Write; use std::path::{Path, PathBuf}; use std::sync::mpsc; use std::thread; use std::{cell::RefCell, sync::mpsc::TrySendError}; use std::{collections::HashMap, fs}; +use std::{ + collections::HashSet, + io::Write, + sync::{Arc, Mutex}, +}; use crate::cli::CliArgs; use crate::layout::Layout; @@ -31,7 +35,8 @@ use termion::input::TermRead; use utils::consts::{ZELLIJ_IPC_PIPE, ZELLIJ_ROOT_PLUGIN_DIR}; use wasm_vm::PluginEnv; use wasm_vm::{ - wasi_stdout, wasi_write_string, zellij_imports, EventType, PluginInputType, PluginInstruction, + wasi_stdout, wasi_write_string, zellij_imports, NaughtyEventType, PluginInputType, + PluginInstruction, }; use wasmer::{ChainableNamedResolver, Instance, Module, Store, Value}; use wasmer_wasi::{Pipe, WasiState}; @@ -442,11 +447,13 @@ pub fn start(mut os_input: Box, opts: CliArgs) { let store = Store::default(); let mut plugin_id = 0; let mut plugin_map = HashMap::new(); - let handler_map: HashMap = - [(EventType::Tab, "handle_tab_rename_keypress".to_string())] - .iter() - .cloned() - .collect(); + let handler_map: HashMap = [( + NaughtyEventType::Tab, + "handle_tab_rename_keypress".to_string(), + )] + .iter() + .cloned() + .collect(); move || loop { let (event, mut err_ctx) = receive_plugin_instructions @@ -499,6 +506,7 @@ pub fn start(mut os_input: Box, opts: CliArgs) { send_screen_instructions: send_screen_instructions.clone(), send_app_instructions: send_app_instructions.clone(), wasi_env, + subscriptions: Arc::new(Mutex::new(HashSet::new())), events, }; @@ -526,7 +534,7 @@ pub fn start(mut os_input: Box, opts: CliArgs) { } PluginInstruction::UpdateTabs(mut tabs) => { for (instance, plugin_env) in plugin_map.values() { - if !plugin_env.events.contains(&EventType::Tab) { + if !plugin_env.events.contains(&NaughtyEventType::Tab) { continue; } let handler = instance.exports.get_function("update_tabs").unwrap(); diff --git a/src/common/screen.rs b/src/common/screen.rs index b848cc49..c4c4bdd7 100644 --- a/src/common/screen.rs +++ b/src/common/screen.rs @@ -13,7 +13,7 @@ use crate::tab::Tab; use crate::{errors::ErrorContext, wasm_vm::PluginInstruction}; use crate::{layout::Layout, panes::PaneId}; -use zellij_tile::data::TabData; +use zellij_tile::data::TabInfo; /// Instructions that can be sent to the [`Screen`]. #[derive(Debug, Clone)] @@ -272,7 +272,7 @@ impl Screen { let mut tab_data = vec![]; let active_tab_index = self.active_tab_index.unwrap(); for tab in self.tabs.values() { - tab_data.push(TabData { + tab_data.push(TabInfo { position: tab.position, name: tab.name.clone(), active: active_tab_index == tab.index, diff --git a/src/common/wasm_vm.rs b/src/common/wasm_vm.rs index 24e8d2a6..9c03ab8a 100644 --- a/src/common/wasm_vm.rs +++ b/src/common/wasm_vm.rs @@ -1,11 +1,15 @@ use serde::{Deserialize, Serialize}; use std::{ + collections::HashSet, path::PathBuf, - sync::mpsc::{channel, Sender}, + sync::{ + mpsc::{channel, Sender}, + Arc, Mutex, + }, }; use wasmer::{imports, Function, ImportObject, Store, WasmerEnv}; use wasmer_wasi::WasiEnv; -use zellij_tile::data::TabData; +use zellij_tile::data::{EventType, TabInfo}; use super::{ input::handler::get_help, pty_bus::PtyInstruction, screen::ScreenInstruction, AppInstruction, @@ -13,24 +17,24 @@ use super::{ }; #[derive(Clone, Debug, PartialEq, Hash, Eq, Serialize, Deserialize)] -pub enum EventType { +pub enum NaughtyEventType { Tab, } #[derive(Clone, Debug)] pub enum PluginInputType { Normal(u32), - Event(EventType), + Event(NaughtyEventType), } #[derive(Clone, Debug)] pub enum PluginInstruction { - Load(Sender, PathBuf, Vec), + Load(Sender, PathBuf, Vec), Draw(Sender, u32, usize, usize), // String buffer, plugin id, rows, cols Input(PluginInputType, Vec), // plugin id, input bytes GlobalInput(Vec), // input bytes Unload(u32), - UpdateTabs(Vec), // num tabs, active tab + UpdateTabs(Vec), // num tabs, active tab Quit, } @@ -41,7 +45,8 @@ pub struct PluginEnv { pub send_app_instructions: SenderWithContext, pub send_pty_instructions: SenderWithContext, // FIXME: This should be a big bundle of all of the channels pub wasi_env: WasiEnv, - pub events: Vec, + pub subscriptions: Arc>>, + pub events: Vec, // FIXME: Murder this very soon (should not survive into main) } // Plugin API --------------------------------------------------------------------------------------------------------- @@ -49,6 +54,8 @@ pub struct PluginEnv { pub fn zellij_imports(store: &Store, plugin_env: &PluginEnv) -> ImportObject { imports! { "zellij" => { + "host_subscribe" => Function::new_native_with_env(store, plugin_env.clone(), host_subscribe), + "host_unsubscribe" => Function::new_native_with_env(store, plugin_env.clone(), host_unsubscribe), "host_open_file" => Function::new_native_with_env(store, plugin_env.clone(), host_open_file), "host_set_invisible_borders" => Function::new_native_with_env(store, plugin_env.clone(), host_set_invisible_borders), "host_set_max_height" => Function::new_native_with_env(store, plugin_env.clone(), host_set_max_height), @@ -58,7 +65,18 @@ pub fn zellij_imports(store: &Store, plugin_env: &PluginEnv) -> ImportObject { } } -// FIXME: Bundle up all of the channels! Pair that with WasiEnv? +fn host_subscribe(plugin_env: &PluginEnv) { + let mut subscriptions = plugin_env.subscriptions.lock().unwrap(); + let new: HashSet = serde_json::from_str(&wasi_stdout(&plugin_env.wasi_env)).unwrap(); + subscriptions.extend(new); +} + +fn host_unsubscribe(plugin_env: &PluginEnv) { + let mut subscriptions = plugin_env.subscriptions.lock().unwrap(); + let old: HashSet = serde_json::from_str(&wasi_stdout(&plugin_env.wasi_env)).unwrap(); + subscriptions.retain(|k| !old.contains(k)); +} + fn host_open_file(plugin_env: &PluginEnv) { let path = PathBuf::from(wasi_stdout(&plugin_env.wasi_env).lines().next().unwrap()); plugin_env @@ -67,7 +85,6 @@ fn host_open_file(plugin_env: &PluginEnv) { .unwrap(); } -// FIXME: Think about these naming conventions – should everything be prefixed by 'host'? fn host_set_selectable(plugin_env: &PluginEnv, selectable: i32) { let selectable = selectable != 0; plugin_env diff --git a/zellij-tile/src/data.rs b/zellij-tile/src/data.rs index b64f1e4e..2979bece 100644 --- a/zellij-tile/src/data.rs +++ b/zellij-tile/src/data.rs @@ -1,5 +1,5 @@ use serde::{Deserialize, Serialize}; -use strum_macros::EnumIter; +use strum_macros::{EnumDiscriminants, EnumIter, ToString}; #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] pub enum Key { @@ -23,6 +23,15 @@ pub enum Key { Esc, } +#[derive(Debug, EnumDiscriminants, ToString, Serialize, Deserialize)] +#[strum_discriminants(derive(Hash, Serialize, Deserialize))] +#[strum_discriminants(name(EventType))] +pub enum Event { + ModeUpdate(Help), // FIXME: Rename the `Help` struct + TabUpdate(TabInfo), + KeyPress(Key), +} + /// Describes the different input modes, which change the way that keystrokes will be interpreted. #[derive(Debug, PartialEq, Eq, Hash, Copy, Clone, EnumIter, Serialize, Deserialize)] pub enum InputMode { @@ -56,11 +65,12 @@ impl Default for InputMode { #[derive(Default, Debug, Clone, Serialize, Deserialize)] pub struct Help { pub mode: InputMode, + // FIXME: This should probably return Keys and Actions, then sort out strings plugin-side pub keybinds: Vec<(String, String)>, // => } -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct TabData { +#[derive(Debug, Default, Clone, Deserialize, Serialize)] +pub struct TabInfo { /* subset of fields to publish to plugins */ pub position: usize, pub name: String, diff --git a/zellij-tile/src/shim.rs b/zellij-tile/src/shim.rs index bb038e82..3681e9ba 100644 --- a/zellij-tile/src/shim.rs +++ b/zellij-tile/src/shim.rs @@ -7,6 +7,16 @@ pub fn get_key() -> Key { deserialize_from_stdin().unwrap() } +pub fn subscribe(event_types: &[EventType]) { + println!("{}", serde_json::to_string(event_types).unwrap()); + unsafe { host_subscribe() }; +} + +pub fn unsubscribe(event_types: &[EventType]) { + println!("{}", serde_json::to_string(event_types).unwrap()); + unsafe { host_unsubscribe() }; +} + pub fn open_file(path: &Path) { println!("{}", path.to_string_lossy()); unsafe { host_open_file() }; @@ -31,7 +41,7 @@ pub fn get_help() -> Help { deserialize_from_stdin().unwrap_or_default() } -pub fn get_tabs() -> Vec { +pub fn get_tabs() -> Vec { deserialize_from_stdin().unwrap_or_default() } @@ -43,6 +53,8 @@ fn deserialize_from_stdin() -> Option { #[link(wasm_import_module = "zellij")] extern "C" { + fn host_subscribe(); + fn host_unsubscribe(); fn host_open_file(); fn host_set_max_height(max_height: i32); fn host_set_selectable(selectable: i32); From 1dd4045e23b0c92570e6c203c43f318ad01dbd2c Mon Sep 17 00:00:00 2001 From: Brooks J Rady Date: Tue, 9 Mar 2021 22:20:16 +0000 Subject: [PATCH 05/31] Clippy compels me to cull code --- default-tiles/strider/src/state.rs | 2 +- default-tiles/tab-bar/src/line.rs | 4 +-- default-tiles/tab-bar/src/main.rs | 4 --- src/client/panes/terminal_character.rs | 10 +++--- src/common/errors.rs | 4 +-- src/common/input/handler.rs | 15 ++++----- src/common/input/keybinds.rs | 6 ++-- src/common/ipc.rs | 8 ++--- src/common/mod.rs | 44 +++++++++++--------------- src/common/screen.rs | 13 +++----- 10 files changed, 47 insertions(+), 63 deletions(-) diff --git a/default-tiles/strider/src/state.rs b/default-tiles/strider/src/state.rs index 2a9230e8..0d96ae0b 100644 --- a/default-tiles/strider/src/state.rs +++ b/default-tiles/strider/src/state.rs @@ -58,6 +58,6 @@ impl FsEntry { } pub fn is_hidden_file(&self) -> bool { - self.name().chars().nth(0).unwrap() == '.'.into() + self.name().starts_with('.') } } diff --git a/default-tiles/tab-bar/src/line.rs b/default-tiles/tab-bar/src/line.rs index 306c0281..1f844642 100644 --- a/default-tiles/tab-bar/src/line.rs +++ b/default-tiles/tab-bar/src/line.rs @@ -56,7 +56,7 @@ fn left_more_message(tab_count_to_the_left: usize) -> LinePart { let more_text = if tab_count_to_the_left < 10000 { format!(" ← +{} ", tab_count_to_the_left) } else { - format!(" ← +many ") + " ← +many ".to_string() }; let more_styled_text = format!( "{}{}", @@ -79,7 +79,7 @@ fn right_more_message(tab_count_to_the_right: usize) -> LinePart { let more_text = if tab_count_to_the_right < 10000 { format!(" +{} → ", tab_count_to_the_right) } else { - format!(" +many → ") + " +many → ".to_string() }; let more_styled_text = format!( "{}{}{}", diff --git a/default-tiles/tab-bar/src/main.rs b/default-tiles/tab-bar/src/main.rs index 6c00cb79..f40a5c1f 100644 --- a/default-tiles/tab-bar/src/main.rs +++ b/default-tiles/tab-bar/src/main.rs @@ -26,8 +26,6 @@ impl Default for BarMode { #[derive(Default)] struct State { - active_tab_index: usize, - num_tabs: usize, tabs: Vec, mode: BarMode, new_name: String, @@ -42,8 +40,6 @@ impl ZellijTile for State { set_selectable(false); set_invisible_borders(true); set_max_height(1); - self.active_tab_index = 0; - self.num_tabs = 0; self.mode = BarMode::Normal; self.new_name = String::new(); } diff --git a/src/client/panes/terminal_character.rs b/src/client/panes/terminal_character.rs index 80c3162b..053ebd3f 100644 --- a/src/client/panes/terminal_character.rs +++ b/src/client/panes/terminal_character.rs @@ -23,7 +23,7 @@ pub enum AnsiCode { On, Reset, NamedColor(NamedColor), - RGBCode((u8, u8, u8)), + RgbCode((u8, u8, u8)), ColorIndex(u8), } @@ -336,7 +336,7 @@ impl CharacterStyles { [36, ..] => *self = self.foreground(Some(AnsiCode::NamedColor(NamedColor::Cyan))), [37, ..] => *self = self.foreground(Some(AnsiCode::NamedColor(NamedColor::White))), [38, 2, ..] => { - let ansi_code = AnsiCode::RGBCode(( + let ansi_code = AnsiCode::RgbCode(( *ansi_params.get(2).unwrap() as u8, *ansi_params.get(3).unwrap() as u8, *ansi_params.get(4).unwrap() as u8, @@ -364,7 +364,7 @@ impl CharacterStyles { [46, ..] => *self = self.background(Some(AnsiCode::NamedColor(NamedColor::Cyan))), [47, ..] => *self = self.background(Some(AnsiCode::NamedColor(NamedColor::White))), [48, 2, ..] => { - let ansi_code = AnsiCode::RGBCode(( + let ansi_code = AnsiCode::RgbCode(( *ansi_params.get(2).unwrap() as u8, *ansi_params.get(3).unwrap() as u8, *ansi_params.get(4).unwrap() as u8, @@ -416,7 +416,7 @@ impl Display for CharacterStyles { } if let Some(ansi_code) = self.foreground { match ansi_code { - AnsiCode::RGBCode((r, g, b)) => { + AnsiCode::RgbCode((r, g, b)) => { write!(f, "\u{1b}[38;2;{};{};{}m", r, g, b)?; } AnsiCode::ColorIndex(color_index) => { @@ -433,7 +433,7 @@ impl Display for CharacterStyles { }; if let Some(ansi_code) = self.background { match ansi_code { - AnsiCode::RGBCode((r, g, b)) => { + AnsiCode::RgbCode((r, g, b)) => { write!(f, "\u{1b}[48;2;{};{};{}m", r, g, b)?; } AnsiCode::ColorIndex(color_index) => { diff --git a/src/common/errors.rs b/src/common/errors.rs index 48a92b76..bd9907fa 100644 --- a/src/common/errors.rs +++ b/src/common/errors.rs @@ -133,7 +133,7 @@ pub enum ContextType { Plugin(PluginContext), /// An app-related call. App(AppContext), - IPCServer, + IpcServer, StdinHandler, AsyncTask, /// An empty, placeholder call. This should be thought of as representing no call at all. @@ -152,7 +152,7 @@ impl Display for ContextType { ContextType::Plugin(c) => write!(f, "{}plugin_thread: {}{:?}", purple, green, c), ContextType::App(c) => write!(f, "{}main_thread: {}{:?}", purple, green, c), - ContextType::IPCServer => write!(f, "{}ipc_server: {}AcceptInput", purple, green), + ContextType::IpcServer => write!(f, "{}ipc_server: {}AcceptInput", purple, green), ContextType::StdinHandler => { write!(f, "{}stdin_handler_thread: {}AcceptInput", purple, green) } diff --git a/src/common/input/handler.rs b/src/common/input/handler.rs index 40d53d5d..ed247830 100644 --- a/src/common/input/handler.rs +++ b/src/common/input/handler.rs @@ -73,15 +73,12 @@ impl InputHandler { // framework relies on it to not create dead threads that loop // and eat up CPUs. Do not remove until the test framework has // been revised. Sorry about this (@categorille) - if { - let mut should_break = false; - for action in - key_to_actions(&key, raw_bytes, &self.mode, &keybinds) - { - should_break |= self.dispatch_action(action); - } - should_break - } { + let mut should_break = false; + for action in key_to_actions(&key, raw_bytes, &self.mode, &keybinds) + { + should_break |= self.dispatch_action(action); + } + if should_break { break 'input_loop; } } diff --git a/src/common/input/keybinds.rs b/src/common/input/keybinds.rs index da0f1c15..b5dacd70 100644 --- a/src/common/input/keybinds.rs +++ b/src/common/input/keybinds.rs @@ -17,14 +17,14 @@ pub fn get_default_keybinds() -> Result { let mut defaults = Keybinds::new(); for mode in InputMode::iter() { - defaults.insert(mode, get_defaults_for_mode(&mode)?); + defaults.insert(mode, get_defaults_for_mode(&mode)); } Ok(defaults) } /// Returns the default keybinds for a givent [`InputMode`]. -fn get_defaults_for_mode(mode: &InputMode) -> Result { +fn get_defaults_for_mode(mode: &InputMode) -> ModeKeybinds { let mut defaults = ModeKeybinds::new(); match *mode { @@ -181,7 +181,7 @@ fn get_defaults_for_mode(mode: &InputMode) -> Result { } } - Ok(defaults) + defaults } /// Converts a [`Key`] terminal event to a sequence of [`Action`]s according to the current diff --git a/src/common/ipc.rs b/src/common/ipc.rs index 77d57df3..81576b86 100644 --- a/src/common/ipc.rs +++ b/src/common/ipc.rs @@ -3,12 +3,12 @@ use serde::{Deserialize, Serialize}; use std::collections::HashSet; -type SessionID = u64; +type SessionId = u64; #[derive(PartialEq, Eq, Serialize, Deserialize, Hash)] pub struct Session { // Unique ID for this session - id: SessionID, + id: SessionId, // Identifier for the underlying IPC primitive (socket, pipe) conn_name: String, // User configured alias for the session @@ -30,9 +30,9 @@ pub enum ClientToServerMsg { // Create a new session CreateSession, // Attach to a running session - AttachToSession(SessionID, ClientType), + AttachToSession(SessionId, ClientType), // Force detach - DetachSession(SessionID), + DetachSession(SessionId), // Disconnect from the session we're connected to DisconnectFromSession, } diff --git a/src/common/mod.rs b/src/common/mod.rs index 411269b6..f0babeaa 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -553,14 +553,12 @@ pub fn start(mut os_input: Box, opts: CliArgs) { let (instance, plugin_env) = plugin_map.get(&pid).unwrap(); let handle_key = instance.exports.get_function("handle_key").unwrap(); - for key in input_bytes.keys() { - if let Ok(key) = key { - wasi_write_string( - &plugin_env.wasi_env, - &serde_json::to_string(&key).unwrap(), - ); - handle_key.call(&[]).unwrap(); - } + for key in input_bytes.keys().flatten() { + wasi_write_string( + &plugin_env.wasi_env, + &serde_json::to_string(&key).unwrap(), + ); + handle_key.call(&[]).unwrap(); } } PluginInputType::Event(event) => { @@ -572,14 +570,12 @@ pub fn start(mut os_input: Box, opts: CliArgs) { .exports .get_function(handler_map.get(&event).unwrap()) .unwrap(); - for key in input_bytes.keys() { - if let Ok(key) = key { - wasi_write_string( - &plugin_env.wasi_env, - &serde_json::to_string(&key).unwrap(), - ); - handle_key.call(&[]).unwrap(); - } + for key in input_bytes.keys().flatten() { + wasi_write_string( + &plugin_env.wasi_env, + &serde_json::to_string(&key).unwrap(), + ); + handle_key.call(&[]).unwrap(); } } } @@ -591,14 +587,12 @@ pub fn start(mut os_input: Box, opts: CliArgs) { for (instance, plugin_env) in plugin_map.values() { let handler = instance.exports.get_function("handle_global_key").unwrap(); - for key in input_bytes.keys() { - if let Ok(key) = key { - wasi_write_string( - &plugin_env.wasi_env, - &serde_json::to_string(&key).unwrap(), - ); - handler.call(&[]).unwrap(); - } + for key in input_bytes.keys().flatten() { + wasi_write_string( + &plugin_env.wasi_env, + &serde_json::to_string(&key).unwrap(), + ); + handler.call(&[]).unwrap(); } } @@ -626,7 +620,7 @@ pub fn start(mut os_input: Box, opts: CliArgs) { let listener = std::os::unix::net::UnixListener::bind(ZELLIJ_IPC_PIPE) .expect("could not listen on ipc socket"); let mut err_ctx = OPENCALLS.with(|ctx| *ctx.borrow()); - err_ctx.add_call(ContextType::IPCServer); + err_ctx.add_call(ContextType::IpcServer); send_pty_instructions.update(err_ctx); send_screen_instructions.update(err_ctx); diff --git a/src/common/screen.rs b/src/common/screen.rs index c4c4bdd7..539eef9a 100644 --- a/src/common/screen.rs +++ b/src/common/screen.rs @@ -171,15 +171,12 @@ impl Screen { pub fn go_to_tab(&mut self, mut tab_index: usize) { tab_index -= 1; let active_tab = self.get_active_tab().unwrap(); - match self.tabs.values().find(|t| t.position == tab_index) { - Some(t) => { - if t.index != active_tab.index { - self.active_tab_index = Some(t.index); - self.update_tabs(); - self.render(); - } + if let Some(t) = self.tabs.values().find(|t| t.position == tab_index) { + if t.index != active_tab.index { + self.active_tab_index = Some(t.index); + self.update_tabs(); + self.render(); } - None => {} } } From a1fbb26818f71d4436dab47a1c4a8e39bfe4b684 Mon Sep 17 00:00:00 2001 From: Aram Drevekenin Date: Fri, 12 Mar 2021 10:11:47 +0100 Subject: [PATCH 06/31] fix(layout): add tab bar to strider layout --- assets/layouts/strider.yaml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/assets/layouts/strider.yaml b/assets/layouts/strider.yaml index 1667dd0b..cd972d20 100644 --- a/assets/layouts/strider.yaml +++ b/assets/layouts/strider.yaml @@ -1,6 +1,12 @@ --- direction: Horizontal parts: + - direction: Vertical + split_size: + Fixed: 1 + plugin: tab-bar + events: + - Tab - direction: Vertical parts: - direction: Horizontal @@ -11,5 +17,5 @@ parts: expansion_boundary: true - direction: Vertical split_size: - Fixed: 1 + Fixed: 2 plugin: status-bar From ac358d913c452ad66bb4fe4f76627e119604ea3e Mon Sep 17 00:00:00 2001 From: Aram Drevekenin Date: Fri, 12 Mar 2021 14:27:13 +0100 Subject: [PATCH 07/31] fix(performance): smaller allocations when rendering (#222) --- src/client/panes/terminal_pane.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/client/panes/terminal_pane.rs b/src/client/panes/terminal_pane.rs index fd83d571..4a0321af 100644 --- a/src/client/panes/terminal_pane.rs +++ b/src/client/panes/terminal_pane.rs @@ -205,12 +205,11 @@ impl Pane for TerminalPane { for line_index in 0..self.grid.height { let x = self.get_x(); let y = self.get_y(); - vte_output = format!( - "{}\u{1b}[{};{}H\u{1b}[m", - vte_output, + vte_output.push_str(&format!( + "\u{1b}[{};{}H\u{1b}[m", y + line_index + 1, x + 1 - ); // goto row/col and reset styles + )); // goto row/col and reset styles for _col_index in 0..self.grid.width { vte_output.push(EMPTY_TERMINAL_CHARACTER.character); } @@ -220,7 +219,7 @@ impl Pane for TerminalPane { for (row, line) in buffer_lines.iter().enumerate() { let x = self.get_x(); let y = self.get_y(); - vte_output = format!("{}\u{1b}[{};{}H\u{1b}[m", vte_output, y + row + 1, x + 1); // goto row/col and reset styles + vte_output.push_str(&format!("\u{1b}[{};{}H\u{1b}[m", y + row + 1, x + 1)); // goto row/col and reset styles for (col, t_character) in line.iter().enumerate() { if col < display_cols { // in some cases (eg. while resizing) some characters will spill over @@ -232,7 +231,7 @@ impl Pane for TerminalPane { // the terminal keeps the previous styles as long as we're in the same // line, so we only want to update the new styles here (this also // includes resetting previous styles as needed) - vte_output = format!("{}{}", vte_output, new_styles); + vte_output.push_str(&new_styles.to_string()); } vte_output.push(t_character.character); } From 0307b2de9e5d041dce1d70d0fd76cc34f7e006f7 Mon Sep 17 00:00:00 2001 From: Kunal Mohan Date: Sun, 14 Mar 2021 11:59:06 +0530 Subject: [PATCH 08/31] fix build directory for zellij-tile --- build-all.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-all.sh b/build-all.sh index df8e6978..cdb1d0cc 100755 --- a/build-all.sh +++ b/build-all.sh @@ -6,7 +6,7 @@ total=6 echo "Building zellij-tile (1/$total)..." cd zellij-tile -cargo build --release --target-dir ../../target +cargo build --release --target-dir ../target echo "Building status-bar (2/$total)..." cd ../default-tiles/status-bar From a17498999013bbc646201da0ab8bb9095b5320a4 Mon Sep 17 00:00:00 2001 From: Jonah Caplan Date: Mon, 15 Mar 2021 05:52:50 -0400 Subject: [PATCH 09/31] fix(tabs): delete characters when renaming tab (#226) --- default-tiles/tab-bar/src/main.rs | 3 +++ src/common/screen.rs | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/default-tiles/tab-bar/src/main.rs b/default-tiles/tab-bar/src/main.rs index 0dd739d8..8c025336 100644 --- a/default-tiles/tab-bar/src/main.rs +++ b/default-tiles/tab-bar/src/main.rs @@ -100,6 +100,9 @@ impl ZellijTile for State { self.new_name.clear(); } Key::Char(c) => self.new_name = format!("{}{}", self.new_name, c), + Key::Backspace | Key::Delete => { + self.new_name.pop(); + } _ => {} } } diff --git a/src/common/screen.rs b/src/common/screen.rs index 199a1223..57bb0e0f 100644 --- a/src/common/screen.rs +++ b/src/common/screen.rs @@ -294,6 +294,10 @@ impl Screen { self.update_tabs(); self.render(); } + "\u{007F}" | "\u{0008}" => { + //delete and backspace keys + self.tabname_buf.pop(); + } c => { self.tabname_buf.push_str(c); } From 922440a952792c5603dfca7f08ede45b887a294d Mon Sep 17 00:00:00 2001 From: denis Date: Mon, 15 Mar 2021 14:17:04 +0200 Subject: [PATCH 10/31] 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 46c9802f6fd7cf37dab6c775554a9b7b9aa39bfd Mon Sep 17 00:00:00 2001 From: Aram Drevekenin Date: Tue, 16 Mar 2021 16:54:07 +0100 Subject: [PATCH 11/31] Performance: only render panes that should be updated (#234) * fix(performance): bring back should_render * style(fmt): rustfmt --- src/client/panes/terminal_pane.rs | 20 ++------------------ src/client/tab.rs | 4 ---- src/tests/fakes.rs | 11 +++++++++-- src/tests/integration/expansion_boundary.rs | 11 +++++++++-- src/tests/integration/resize_down.rs | 16 +++++++++++++++- src/tests/integration/resize_left.rs | 15 ++++++++++++++- src/tests/integration/resize_right.rs | 15 ++++++++++++++- src/tests/integration/resize_up.rs | 15 ++++++++++++++- src/tests/utils.rs | 1 + 9 files changed, 78 insertions(+), 30 deletions(-) diff --git a/src/client/panes/terminal_pane.rs b/src/client/panes/terminal_pane.rs index 4a0321af..9fa70d11 100644 --- a/src/client/panes/terminal_pane.rs +++ b/src/client/panes/terminal_pane.rs @@ -70,13 +70,11 @@ impl Pane for TerminalPane { fn reset_size_and_position_override(&mut self) { self.position_and_size_override = None; self.reflow_lines(); - self.mark_for_rerender(); } fn change_pos_and_size(&mut self, position_and_size: &PositionAndSize) { self.position_and_size.columns = position_and_size.columns; self.position_and_size.rows = position_and_size.rows; self.reflow_lines(); - self.mark_for_rerender(); } fn override_size_and_position(&mut self, x: usize, y: usize, size: &PositionAndSize) { let position_and_size_override = PositionAndSize { @@ -87,7 +85,6 @@ impl Pane for TerminalPane { }; self.position_and_size_override = Some(position_and_size_override); self.reflow_lines(); - self.mark_for_rerender(); } fn handle_event(&mut self, event: VteEvent) { match event { @@ -191,12 +188,7 @@ impl Pane for TerminalPane { self.max_height } fn render(&mut self) -> Option { - // if self.should_render { - if true { - // while checking should_render rather than rendering each pane every time - // is more performant, it causes some problems when the pane to the left should be - // rendered and has wide characters (eg. Chinese characters or emoji) - // as a (hopefully) temporary hack, we render all panes until we find a better solution + if self.should_render || cfg!(test) { let mut vte_output = String::new(); let buffer_lines = &self.read_buffer_as_lines(); let display_cols = self.get_columns(); @@ -238,7 +230,7 @@ impl Pane for TerminalPane { } character_styles.clear(); } - self.mark_for_rerender(); + self.should_render = false; Some(vte_output) } else { None @@ -251,45 +243,37 @@ impl Pane for TerminalPane { self.position_and_size.y += count; self.position_and_size.rows -= count; self.reflow_lines(); - self.mark_for_rerender(); } fn increase_height_down(&mut self, count: usize) { self.position_and_size.rows += count; self.reflow_lines(); - self.mark_for_rerender(); } fn increase_height_up(&mut self, count: usize) { self.position_and_size.y -= count; self.position_and_size.rows += count; self.reflow_lines(); - self.mark_for_rerender(); } fn reduce_height_up(&mut self, count: usize) { self.position_and_size.rows -= count; self.reflow_lines(); - self.mark_for_rerender(); } fn reduce_width_right(&mut self, count: usize) { self.position_and_size.x += count; self.position_and_size.columns -= count; self.reflow_lines(); - self.mark_for_rerender(); } fn reduce_width_left(&mut self, count: usize) { self.position_and_size.columns -= count; self.reflow_lines(); - self.mark_for_rerender(); } fn increase_width_left(&mut self, count: usize) { self.position_and_size.x -= count; self.position_and_size.columns += count; self.reflow_lines(); - self.mark_for_rerender(); } fn increase_width_right(&mut self, count: usize) { self.position_and_size.columns += count; self.reflow_lines(); - self.mark_for_rerender(); } fn scroll_up(&mut self, count: usize) { self.grid.move_viewport_up(count); diff --git a/src/client/tab.rs b/src/client/tab.rs index 1ef0b720..520720c0 100644 --- a/src/client/tab.rs +++ b/src/client/tab.rs @@ -1679,7 +1679,6 @@ impl Tab { } else if self.can_reduce_pane_and_surroundings_right(&active_pane_id, count) { self.reduce_pane_and_surroundings_right(&active_pane_id, count); } - self.render(); } } pub fn resize_left(&mut self) { @@ -1691,7 +1690,6 @@ impl Tab { } else if self.can_reduce_pane_and_surroundings_left(&active_pane_id, count) { self.reduce_pane_and_surroundings_left(&active_pane_id, count); } - self.render(); } } pub fn resize_down(&mut self) { @@ -1703,7 +1701,6 @@ impl Tab { } else if self.can_reduce_pane_and_surroundings_down(&active_pane_id, count) { self.reduce_pane_and_surroundings_down(&active_pane_id, count); } - self.render(); } } pub fn resize_up(&mut self) { @@ -1715,7 +1712,6 @@ impl Tab { } else if self.can_reduce_pane_and_surroundings_up(&active_pane_id, count) { self.reduce_pane_and_surroundings_up(&active_pane_id, count); } - self.render(); } } pub fn move_focus(&mut self) { diff --git a/src/tests/fakes.rs b/src/tests/fakes.rs index fa9c6f0e..c800de97 100644 --- a/src/tests/fakes.rs +++ b/src/tests/fakes.rs @@ -10,6 +10,8 @@ use std::time::{Duration, Instant}; use crate::os_input_output::OsApi; use crate::tests::possible_tty_inputs::{get_possible_tty_inputs, Bytes}; +use crate::tests::utils::commands::SLEEP; + const MIN_TIME_BETWEEN_SNAPSHOTS: Duration = Duration::from_millis(50); #[derive(Clone)] @@ -189,11 +191,16 @@ impl OsApi for FakeInputOutput { ::std::thread::sleep(MIN_TIME_BETWEEN_SNAPSHOTS - last_snapshot_time.elapsed()); } } - self.stdin_commands + let command = self + .stdin_commands .lock() .unwrap() .pop_front() - .unwrap_or(vec![]) + .unwrap_or(vec![]); + if command == SLEEP { + std::thread::sleep(std::time::Duration::from_millis(200)); + } + command } fn get_stdout_writer(&self) -> Box { Box::new(self.stdout_writer.clone()) diff --git a/src/tests/integration/expansion_boundary.rs b/src/tests/integration/expansion_boundary.rs index 7cb0b0f7..c68c1d5a 100644 --- a/src/tests/integration/expansion_boundary.rs +++ b/src/tests/integration/expansion_boundary.rs @@ -4,7 +4,7 @@ use std::path::PathBuf; use crate::panes::PositionAndSize; use crate::tests::fakes::FakeInputOutput; use crate::tests::utils::commands::{ - PANE_MODE, QUIT, RESIZE_DOWN_IN_RESIZE_MODE, RESIZE_MODE, SPAWN_TERMINAL_IN_PANE_MODE, + PANE_MODE, QUIT, RESIZE_DOWN_IN_RESIZE_MODE, RESIZE_MODE, SLEEP, SPAWN_TERMINAL_IN_PANE_MODE, TOGGLE_ACTIVE_TERMINAL_FULLSCREEN_IN_PANE_MODE, }; use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots}; @@ -23,7 +23,12 @@ pub fn new_panes_are_open_inside_expansion_border() { y: 0, }; let mut fake_input_output = get_fake_os_input(&fake_win_size); - fake_input_output.add_terminal_input(&[&PANE_MODE, &SPAWN_TERMINAL_IN_PANE_MODE, &QUIT]); + fake_input_output.add_terminal_input(&[ + &PANE_MODE, + &SPAWN_TERMINAL_IN_PANE_MODE, + &SLEEP, + &QUIT, + ]); let mut opts = CliArgs::default(); opts.layout = Some(PathBuf::from( "src/tests/fixtures/layouts/expansion-boundary-in-the-middle.yaml", @@ -55,6 +60,7 @@ pub fn resize_pane_inside_expansion_border() { &SPAWN_TERMINAL_IN_PANE_MODE, &RESIZE_MODE, &RESIZE_DOWN_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); let mut opts = CliArgs::default(); @@ -87,6 +93,7 @@ pub fn toggling_fullcsreen_in_expansion_border_expands_only_until_border() { &PANE_MODE, &SPAWN_TERMINAL_IN_PANE_MODE, &TOGGLE_ACTIVE_TERMINAL_FULLSCREEN_IN_PANE_MODE, + &SLEEP, &QUIT, ]); let mut opts = CliArgs::default(); diff --git a/src/tests/integration/resize_down.rs b/src/tests/integration/resize_down.rs index 0171cea2..4957b33e 100644 --- a/src/tests/integration/resize_down.rs +++ b/src/tests/integration/resize_down.rs @@ -7,7 +7,8 @@ use crate::{start, CliArgs}; use crate::tests::utils::commands::{ MOVE_FOCUS_IN_PANE_MODE, PANE_MODE, QUIT, RESIZE_DOWN_IN_RESIZE_MODE, - RESIZE_LEFT_IN_RESIZE_MODE, RESIZE_MODE, SPLIT_DOWN_IN_PANE_MODE, SPLIT_RIGHT_IN_PANE_MODE, + RESIZE_LEFT_IN_RESIZE_MODE, RESIZE_MODE, SLEEP, SPLIT_DOWN_IN_PANE_MODE, + SPLIT_RIGHT_IN_PANE_MODE, }; fn get_fake_os_input(fake_win_size: &PositionAndSize) -> FakeInputOutput { @@ -37,6 +38,7 @@ pub fn resize_down_with_pane_above() { &SPLIT_DOWN_IN_PANE_MODE, &RESIZE_MODE, &RESIZE_DOWN_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); start(Box::new(fake_input_output.clone()), CliArgs::default()); @@ -75,6 +77,7 @@ pub fn resize_down_with_pane_below() { &MOVE_FOCUS_IN_PANE_MODE, &RESIZE_MODE, &RESIZE_DOWN_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); start(Box::new(fake_input_output.clone()), CliArgs::default()); @@ -118,6 +121,7 @@ pub fn resize_down_with_panes_above_and_below() { &MOVE_FOCUS_IN_PANE_MODE, &RESIZE_MODE, &RESIZE_DOWN_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); start(Box::new(fake_input_output.clone()), CliArgs::default()); @@ -160,6 +164,7 @@ pub fn resize_down_with_multiple_panes_above() { &MOVE_FOCUS_IN_PANE_MODE, &RESIZE_MODE, &RESIZE_DOWN_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); @@ -205,6 +210,7 @@ pub fn resize_down_with_panes_above_aligned_left_with_current_pane() { &MOVE_FOCUS_IN_PANE_MODE, &RESIZE_MODE, &RESIZE_DOWN_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); @@ -249,6 +255,7 @@ pub fn resize_down_with_panes_below_aligned_left_with_current_pane() { &MOVE_FOCUS_IN_PANE_MODE, &RESIZE_MODE, &RESIZE_DOWN_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); @@ -291,6 +298,7 @@ pub fn resize_down_with_panes_above_aligned_right_with_current_pane() { &SPLIT_DOWN_IN_PANE_MODE, &RESIZE_MODE, &RESIZE_DOWN_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); @@ -334,6 +342,7 @@ pub fn resize_down_with_panes_below_aligned_right_with_current_pane() { &MOVE_FOCUS_IN_PANE_MODE, &RESIZE_MODE, &RESIZE_DOWN_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); @@ -380,6 +389,7 @@ pub fn resize_down_with_panes_above_aligned_left_and_right_with_current_pane() { &SPLIT_DOWN_IN_PANE_MODE, &RESIZE_MODE, &RESIZE_DOWN_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); @@ -428,6 +438,7 @@ pub fn resize_down_with_panes_below_aligned_left_and_right_with_current_pane() { &MOVE_FOCUS_IN_PANE_MODE, &RESIZE_MODE, &RESIZE_DOWN_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); @@ -493,6 +504,7 @@ pub fn resize_down_with_panes_above_aligned_left_and_right_with_panes_to_the_lef &RESIZE_LEFT_IN_RESIZE_MODE, &RESIZE_LEFT_IN_RESIZE_MODE, &RESIZE_DOWN_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); @@ -560,6 +572,7 @@ pub fn resize_down_with_panes_below_aligned_left_and_right_with_to_the_left_and_ &RESIZE_LEFT_IN_RESIZE_MODE, &RESIZE_LEFT_IN_RESIZE_MODE, &RESIZE_DOWN_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); @@ -596,6 +609,7 @@ pub fn cannot_resize_down_when_pane_below_is_at_minimum_height() { &SPLIT_DOWN_IN_PANE_MODE, &RESIZE_MODE, &RESIZE_DOWN_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); start(Box::new(fake_input_output.clone()), CliArgs::default()); diff --git a/src/tests/integration/resize_left.rs b/src/tests/integration/resize_left.rs index 0d0d61a5..a9d229d9 100644 --- a/src/tests/integration/resize_left.rs +++ b/src/tests/integration/resize_left.rs @@ -7,7 +7,7 @@ use crate::{start, CliArgs}; use crate::tests::utils::commands::{ MOVE_FOCUS_IN_PANE_MODE, PANE_MODE, QUIT, RESIZE_LEFT_IN_RESIZE_MODE, RESIZE_MODE, - RESIZE_UP_IN_RESIZE_MODE, SPLIT_DOWN_IN_PANE_MODE, SPLIT_RIGHT_IN_PANE_MODE, + RESIZE_UP_IN_RESIZE_MODE, SLEEP, SPLIT_DOWN_IN_PANE_MODE, SPLIT_RIGHT_IN_PANE_MODE, }; fn get_fake_os_input(fake_win_size: &PositionAndSize) -> FakeInputOutput { @@ -34,6 +34,7 @@ pub fn resize_left_with_pane_to_the_left() { &SPLIT_RIGHT_IN_PANE_MODE, &RESIZE_MODE, &RESIZE_LEFT_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); start(Box::new(fake_input_output.clone()), CliArgs::default()); @@ -70,6 +71,7 @@ pub fn resize_left_with_pane_to_the_right() { &MOVE_FOCUS_IN_PANE_MODE, &RESIZE_MODE, &RESIZE_LEFT_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); start(Box::new(fake_input_output.clone()), CliArgs::default()); @@ -108,6 +110,7 @@ pub fn resize_left_with_panes_to_the_left_and_right() { &MOVE_FOCUS_IN_PANE_MODE, &RESIZE_MODE, &RESIZE_LEFT_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); start(Box::new(fake_input_output.clone()), CliArgs::default()); @@ -148,6 +151,7 @@ pub fn resize_left_with_multiple_panes_to_the_left() { &MOVE_FOCUS_IN_PANE_MODE, &RESIZE_MODE, &RESIZE_LEFT_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); @@ -191,6 +195,7 @@ pub fn resize_left_with_panes_to_the_left_aligned_top_with_current_pane() { &MOVE_FOCUS_IN_PANE_MODE, &RESIZE_MODE, &RESIZE_LEFT_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); @@ -231,6 +236,7 @@ pub fn resize_left_with_panes_to_the_right_aligned_top_with_current_pane() { &SPLIT_DOWN_IN_PANE_MODE, &RESIZE_MODE, &RESIZE_LEFT_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); @@ -273,6 +279,7 @@ pub fn resize_left_with_panes_to_the_left_aligned_bottom_with_current_pane() { &MOVE_FOCUS_IN_PANE_MODE, &RESIZE_MODE, &RESIZE_LEFT_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); @@ -314,6 +321,7 @@ pub fn resize_left_with_panes_to_the_right_aligned_bottom_with_current_pane() { &MOVE_FOCUS_IN_PANE_MODE, &RESIZE_MODE, &RESIZE_LEFT_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); @@ -360,6 +368,7 @@ pub fn resize_left_with_panes_to_the_left_aligned_top_and_bottom_with_current_pa &SPLIT_RIGHT_IN_PANE_MODE, &RESIZE_MODE, &RESIZE_LEFT_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); @@ -408,6 +417,7 @@ pub fn resize_left_with_panes_to_the_right_aligned_top_and_bottom_with_current_p &MOVE_FOCUS_IN_PANE_MODE, &RESIZE_MODE, &RESIZE_LEFT_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); @@ -473,6 +483,7 @@ pub fn resize_left_with_panes_to_the_left_aligned_top_and_bottom_with_panes_abov &RESIZE_UP_IN_RESIZE_MODE, &RESIZE_UP_IN_RESIZE_MODE, &RESIZE_LEFT_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); @@ -541,6 +552,7 @@ pub fn resize_left_with_panes_to_the_right_aligned_top_and_bottom_with_panes_abo &RESIZE_UP_IN_RESIZE_MODE, &RESIZE_UP_IN_RESIZE_MODE, &RESIZE_LEFT_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); @@ -577,6 +589,7 @@ pub fn cannot_resize_left_when_pane_to_the_left_is_at_minimum_width() { &SPLIT_RIGHT_IN_PANE_MODE, &RESIZE_MODE, &RESIZE_LEFT_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); start(Box::new(fake_input_output.clone()), CliArgs::default()); diff --git a/src/tests/integration/resize_right.rs b/src/tests/integration/resize_right.rs index 8f1928ee..fef33e84 100644 --- a/src/tests/integration/resize_right.rs +++ b/src/tests/integration/resize_right.rs @@ -7,7 +7,7 @@ use crate::{start, CliArgs}; use crate::tests::utils::commands::{ MOVE_FOCUS_IN_PANE_MODE, PANE_MODE, QUIT, RESIZE_MODE, RESIZE_RIGHT_IN_RESIZE_MODE, - RESIZE_UP_IN_RESIZE_MODE, SPLIT_DOWN_IN_PANE_MODE, SPLIT_RIGHT_IN_PANE_MODE, + RESIZE_UP_IN_RESIZE_MODE, SLEEP, SPLIT_DOWN_IN_PANE_MODE, SPLIT_RIGHT_IN_PANE_MODE, }; fn get_fake_os_input(fake_win_size: &PositionAndSize) -> FakeInputOutput { @@ -34,6 +34,7 @@ pub fn resize_right_with_pane_to_the_left() { &SPLIT_RIGHT_IN_PANE_MODE, &RESIZE_MODE, &RESIZE_RIGHT_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); start(Box::new(fake_input_output.clone()), CliArgs::default()); @@ -70,6 +71,7 @@ pub fn resize_right_with_pane_to_the_right() { &MOVE_FOCUS_IN_PANE_MODE, &RESIZE_MODE, &RESIZE_RIGHT_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); start(Box::new(fake_input_output.clone()), CliArgs::default()); @@ -108,6 +110,7 @@ pub fn resize_right_with_panes_to_the_left_and_right() { &MOVE_FOCUS_IN_PANE_MODE, &RESIZE_MODE, &RESIZE_RIGHT_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); start(Box::new(fake_input_output.clone()), CliArgs::default()); @@ -148,6 +151,7 @@ pub fn resize_right_with_multiple_panes_to_the_left() { &MOVE_FOCUS_IN_PANE_MODE, &RESIZE_MODE, &RESIZE_RIGHT_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); @@ -191,6 +195,7 @@ pub fn resize_right_with_panes_to_the_left_aligned_top_with_current_pane() { &MOVE_FOCUS_IN_PANE_MODE, &RESIZE_MODE, &RESIZE_RIGHT_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); @@ -231,6 +236,7 @@ pub fn resize_right_with_panes_to_the_right_aligned_top_with_current_pane() { &SPLIT_DOWN_IN_PANE_MODE, &RESIZE_MODE, &RESIZE_RIGHT_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); @@ -273,6 +279,7 @@ pub fn resize_right_with_panes_to_the_left_aligned_bottom_with_current_pane() { &MOVE_FOCUS_IN_PANE_MODE, &RESIZE_MODE, &RESIZE_RIGHT_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); @@ -314,6 +321,7 @@ pub fn resize_right_with_panes_to_the_right_aligned_bottom_with_current_pane() { &MOVE_FOCUS_IN_PANE_MODE, &RESIZE_MODE, &RESIZE_RIGHT_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); @@ -360,6 +368,7 @@ pub fn resize_right_with_panes_to_the_left_aligned_top_and_bottom_with_current_p &SPLIT_RIGHT_IN_PANE_MODE, &RESIZE_MODE, &RESIZE_RIGHT_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); @@ -408,6 +417,7 @@ pub fn resize_right_with_panes_to_the_right_aligned_top_and_bottom_with_current_ &MOVE_FOCUS_IN_PANE_MODE, &RESIZE_MODE, &RESIZE_RIGHT_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); @@ -473,6 +483,7 @@ pub fn resize_right_with_panes_to_the_left_aligned_top_and_bottom_with_panes_abo &RESIZE_UP_IN_RESIZE_MODE, &RESIZE_UP_IN_RESIZE_MODE, &RESIZE_RIGHT_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); @@ -540,6 +551,7 @@ pub fn resize_right_with_panes_to_the_right_aligned_top_and_bottom_with_panes_ab &RESIZE_UP_IN_RESIZE_MODE, &RESIZE_UP_IN_RESIZE_MODE, &RESIZE_RIGHT_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); @@ -576,6 +588,7 @@ pub fn cannot_resize_right_when_pane_to_the_left_is_at_minimum_width() { &SPLIT_RIGHT_IN_PANE_MODE, &RESIZE_MODE, &RESIZE_RIGHT_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); start(Box::new(fake_input_output.clone()), CliArgs::default()); diff --git a/src/tests/integration/resize_up.rs b/src/tests/integration/resize_up.rs index 2df6dfa7..9d4dd05a 100644 --- a/src/tests/integration/resize_up.rs +++ b/src/tests/integration/resize_up.rs @@ -7,7 +7,7 @@ use crate::{start, CliArgs}; use crate::tests::utils::commands::{ MOVE_FOCUS_IN_PANE_MODE, PANE_MODE, QUIT, RESIZE_LEFT_IN_RESIZE_MODE, RESIZE_MODE, - RESIZE_UP_IN_RESIZE_MODE, SPLIT_DOWN_IN_PANE_MODE, SPLIT_RIGHT_IN_PANE_MODE, + RESIZE_UP_IN_RESIZE_MODE, SLEEP, SPLIT_DOWN_IN_PANE_MODE, SPLIT_RIGHT_IN_PANE_MODE, }; fn get_fake_os_input(fake_win_size: &PositionAndSize) -> FakeInputOutput { @@ -36,6 +36,7 @@ pub fn resize_up_with_pane_above() { &SPLIT_DOWN_IN_PANE_MODE, &RESIZE_MODE, &RESIZE_UP_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); start(Box::new(fake_input_output.clone()), CliArgs::default()); @@ -74,6 +75,7 @@ pub fn resize_up_with_pane_below() { &MOVE_FOCUS_IN_PANE_MODE, &RESIZE_MODE, &RESIZE_UP_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); start(Box::new(fake_input_output.clone()), CliArgs::default()); @@ -117,6 +119,7 @@ pub fn resize_up_with_panes_above_and_below() { &MOVE_FOCUS_IN_PANE_MODE, &RESIZE_MODE, &RESIZE_UP_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); start(Box::new(fake_input_output.clone()), CliArgs::default()); @@ -158,6 +161,7 @@ pub fn resize_up_with_multiple_panes_above() { &MOVE_FOCUS_IN_PANE_MODE, &RESIZE_MODE, &RESIZE_UP_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); @@ -201,6 +205,7 @@ pub fn resize_up_with_panes_above_aligned_left_with_current_pane() { &MOVE_FOCUS_IN_PANE_MODE, &RESIZE_MODE, &RESIZE_UP_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); @@ -245,6 +250,7 @@ pub fn resize_up_with_panes_below_aligned_left_with_current_pane() { &MOVE_FOCUS_IN_PANE_MODE, &RESIZE_MODE, &RESIZE_UP_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); @@ -287,6 +293,7 @@ pub fn resize_up_with_panes_above_aligned_right_with_current_pane() { &SPLIT_DOWN_IN_PANE_MODE, &RESIZE_MODE, &RESIZE_UP_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); @@ -330,6 +337,7 @@ pub fn resize_up_with_panes_below_aligned_right_with_current_pane() { &MOVE_FOCUS_IN_PANE_MODE, &RESIZE_MODE, &RESIZE_UP_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); @@ -376,6 +384,7 @@ pub fn resize_up_with_panes_above_aligned_left_and_right_with_current_pane() { &SPLIT_DOWN_IN_PANE_MODE, &RESIZE_MODE, &RESIZE_UP_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); @@ -424,6 +433,7 @@ pub fn resize_up_with_panes_below_aligned_left_and_right_with_current_pane() { &MOVE_FOCUS_IN_PANE_MODE, &RESIZE_MODE, &RESIZE_UP_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); @@ -489,6 +499,7 @@ pub fn resize_up_with_panes_above_aligned_left_and_right_with_panes_to_the_left_ &RESIZE_LEFT_IN_RESIZE_MODE, &RESIZE_LEFT_IN_RESIZE_MODE, &RESIZE_UP_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); @@ -556,6 +567,7 @@ pub fn resize_up_with_panes_below_aligned_left_and_right_with_to_the_left_and_ri &RESIZE_LEFT_IN_RESIZE_MODE, &RESIZE_LEFT_IN_RESIZE_MODE, &RESIZE_UP_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); @@ -592,6 +604,7 @@ pub fn cannot_resize_up_when_pane_above_is_at_minimum_height() { &SPLIT_DOWN_IN_PANE_MODE, &RESIZE_MODE, &RESIZE_UP_IN_RESIZE_MODE, + &SLEEP, &QUIT, ]); start(Box::new(fake_input_output.clone()), CliArgs::default()); diff --git a/src/tests/utils.rs b/src/tests/utils.rs index 86973d74..14f4cfa0 100644 --- a/src/tests/utils.rs +++ b/src/tests/utils.rs @@ -76,4 +76,5 @@ pub mod commands { pub const SWITCH_NEXT_TAB_IN_TAB_MODE: [u8; 1] = [108]; // l pub const SWITCH_PREV_TAB_IN_TAB_MODE: [u8; 1] = [104]; // h pub const CLOSE_TAB_IN_TAB_MODE: [u8; 1] = [120]; // x + pub const SLEEP: [u8; 0] = []; } From 3dd776834a6b641466195394103c7d5a94653fb4 Mon Sep 17 00:00:00 2001 From: denis Date: Wed, 17 Mar 2021 11:16:02 +0200 Subject: [PATCH 12/31] 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 13/31] 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 14/31] 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 15/31] 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 16/31] 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 17/31] 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 18/31] 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 a1e6171031dbf6f3285a99a84555a13f7ce88127 Mon Sep 17 00:00:00 2001 From: Brooks J Rady Date: Tue, 23 Mar 2021 16:26:34 +0000 Subject: [PATCH 19/31] Rename references of 'draw' to 'render' for plugins --- default-tiles/status-bar/src/main.rs | 2 +- default-tiles/strider/src/main.rs | 2 +- default-tiles/tab-bar/src/main.rs | 2 +- src/client/panes/plugin_pane.rs | 2 +- src/common/errors.rs | 4 ++-- src/common/mod.rs | 7 ++++--- src/common/wasm_vm.rs | 6 +++--- zellij-tile/src/lib.rs | 7 ++++--- 8 files changed, 17 insertions(+), 15 deletions(-) diff --git a/default-tiles/status-bar/src/main.rs b/default-tiles/status-bar/src/main.rs index 68f56b7f..dc0af60e 100644 --- a/default-tiles/status-bar/src/main.rs +++ b/default-tiles/status-bar/src/main.rs @@ -236,7 +236,7 @@ impl ZellijTile for State { set_max_height(1); } - fn draw(&mut self, _rows: usize, cols: usize) { + fn render(&mut self, _rows: usize, cols: usize) { let help = get_help(); let line_prefix = prefix(&help); let key_path = key_path(&help); diff --git a/default-tiles/strider/src/main.rs b/default-tiles/strider/src/main.rs index 81a31ce1..08f44707 100644 --- a/default-tiles/strider/src/main.rs +++ b/default-tiles/strider/src/main.rs @@ -12,7 +12,7 @@ impl ZellijTile for State { refresh_directory(self); } - fn draw(&mut self, rows: usize, cols: usize) { + fn render(&mut self, rows: usize, cols: usize) { for i in 0..rows { if self.selected() < self.scroll() { *self.scroll_mut() = self.selected(); diff --git a/default-tiles/tab-bar/src/main.rs b/default-tiles/tab-bar/src/main.rs index f40a5c1f..e933420b 100644 --- a/default-tiles/tab-bar/src/main.rs +++ b/default-tiles/tab-bar/src/main.rs @@ -44,7 +44,7 @@ impl ZellijTile for State { self.new_name = String::new(); } - fn draw(&mut self, _rows: usize, cols: usize) { + fn render(&mut self, _rows: usize, cols: usize) { if self.tabs.is_empty() { return; } diff --git a/src/client/panes/plugin_pane.rs b/src/client/panes/plugin_pane.rs index 588cffd6..4cffff5f 100644 --- a/src/client/panes/plugin_pane.rs +++ b/src/client/panes/plugin_pane.rs @@ -120,7 +120,7 @@ impl Pane for PluginPane { let (buf_tx, buf_rx) = channel(); self.send_plugin_instructions - .send(PluginInstruction::Draw( + .send(PluginInstruction::Render( buf_tx, self.pid, self.rows(), diff --git a/src/common/errors.rs b/src/common/errors.rs index bd9907fa..b5b96342 100644 --- a/src/common/errors.rs +++ b/src/common/errors.rs @@ -278,7 +278,7 @@ use crate::wasm_vm::PluginInstruction; #[derive(Debug, Clone, Copy, PartialEq)] pub enum PluginContext { Load, - Draw, + Render, Input, GlobalInput, Unload, @@ -290,7 +290,7 @@ impl From<&PluginInstruction> for PluginContext { fn from(plugin_instruction: &PluginInstruction) -> Self { match *plugin_instruction { PluginInstruction::Load(..) => PluginContext::Load, - PluginInstruction::Draw(..) => PluginContext::Draw, + PluginInstruction::Render(..) => PluginContext::Render, PluginInstruction::Input(..) => PluginContext::Input, PluginInstruction::GlobalInput(_) => PluginContext::GlobalInput, PluginInstruction::Unload(_) => PluginContext::Unload, diff --git a/src/common/mod.rs b/src/common/mod.rs index f0babeaa..675fe828 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -522,12 +522,13 @@ pub fn start(mut os_input: Box, opts: CliArgs) { pid_tx.send(plugin_id).unwrap(); plugin_id += 1; } - PluginInstruction::Draw(buf_tx, pid, rows, cols) => { + PluginInstruction::Render(buf_tx, pid, rows, cols) => { let (instance, plugin_env) = plugin_map.get(&pid).unwrap(); - let draw = instance.exports.get_function("draw").unwrap(); + let render = instance.exports.get_function("render").unwrap(); - draw.call(&[Value::I32(rows as i32), Value::I32(cols as i32)]) + render + .call(&[Value::I32(rows as i32), Value::I32(cols as i32)]) .unwrap(); buf_tx.send(wasi_stdout(&plugin_env.wasi_env)).unwrap(); diff --git a/src/common/wasm_vm.rs b/src/common/wasm_vm.rs index 9c03ab8a..788219a4 100644 --- a/src/common/wasm_vm.rs +++ b/src/common/wasm_vm.rs @@ -30,9 +30,9 @@ pub enum PluginInputType { #[derive(Clone, Debug)] pub enum PluginInstruction { Load(Sender, PathBuf, Vec), - Draw(Sender, u32, usize, usize), // String buffer, plugin id, rows, cols - Input(PluginInputType, Vec), // plugin id, input bytes - GlobalInput(Vec), // input bytes + Render(Sender, u32, usize, usize), // String buffer, plugin id, rows, cols + Input(PluginInputType, Vec), // plugin id, input bytes + GlobalInput(Vec), // input bytes Unload(u32), UpdateTabs(Vec), // num tabs, active tab Quit, diff --git a/zellij-tile/src/lib.rs b/zellij-tile/src/lib.rs index ea38f6c9..6adc9f6d 100644 --- a/zellij-tile/src/lib.rs +++ b/zellij-tile/src/lib.rs @@ -7,7 +7,8 @@ use data::*; #[allow(unused_variables)] pub trait ZellijTile { fn load(&mut self) {} - fn draw(&mut self, rows: usize, cols: usize) {} + fn render(&mut self, rows: usize, cols: usize) {} + // FIXME: Everything below this line should be purged fn handle_key(&mut self, key: Key) {} fn handle_global_key(&mut self, key: Key) {} fn update_tabs(&mut self) {} @@ -28,9 +29,9 @@ macro_rules! register_tile { } #[no_mangle] - pub fn draw(rows: i32, cols: i32) { + pub fn render(rows: i32, cols: i32) { STATE.with(|state| { - state.borrow_mut().draw(rows as usize, cols as usize); + state.borrow_mut().render(rows as usize, cols as usize); }); } From ac55e590475fb68f29071fc06ded8f6d6bf5db22 Mon Sep 17 00:00:00 2001 From: Brooks J Rady Date: Tue, 23 Mar 2021 19:52:59 +0000 Subject: [PATCH 20/31] Initial implementation of the update callback + upstream termion --- Cargo.lock | 23 +++++++------------ Cargo.toml | 2 +- src/common/errors.rs | 2 ++ src/common/input/handler.rs | 36 +++++++++++++++++++++++++++++- src/common/input/keybinds.rs | 1 - src/common/mod.rs | 43 +++++++++++++++++++++++++++++++++++- src/common/wasm_vm.rs | 3 ++- zellij-tile/src/data.rs | 2 +- zellij-tile/src/lib.rs | 10 +++++++++ zellij-tile/src/shim.rs | 4 +++- 10 files changed, 104 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b618c1c3..bb23c131 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1269,12 +1269,6 @@ dependencies = [ "num_cpus", ] -[[package]] -name = "redox_syscall" -version = "0.1.57" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" - [[package]] name = "redox_syscall" version = "0.2.5" @@ -1290,7 +1284,7 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8440d8acb4fd3d277125b4bd01a6f38aee8d814b3b5fc09b3f2b825d37d3fe8f" dependencies = [ - "redox_syscall 0.2.5", + "redox_syscall", ] [[package]] @@ -1300,7 +1294,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "528532f3d801c87aec9def2add9ca802fe569e44a544afe633765267840abe64" dependencies = [ "getrandom", - "redox_syscall 0.2.5", + "redox_syscall", ] [[package]] @@ -1621,7 +1615,7 @@ dependencies = [ "cfg-if 1.0.0", "libc", "rand", - "redox_syscall 0.2.5", + "redox_syscall", "remove_dir_all", "winapi", ] @@ -1637,16 +1631,15 @@ dependencies = [ ] [[package]] -name = "termion_temporary_zellij_fork" -version = "1.6.0" +name = "termion" +version = "1.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65175afb01727f72d690bc8b2a2ac411c0243ec43988b7bd96d428301197bed0" +checksum = "077185e2eac69c3f8379a4298e1e07cd36beb962290d4a51199acf0fdc10607e" dependencies = [ "libc", "numtoa", - "redox_syscall 0.1.57", + "redox_syscall", "redox_termios", - "serde", ] [[package]] @@ -2269,7 +2262,7 @@ dependencies = [ "strip-ansi-escapes", "structopt", "strum", - "termion_temporary_zellij_fork", + "termion", "termios", "toml", "unicode-truncate", diff --git a/Cargo.toml b/Cargo.toml index b5266a8c..fec3c7b2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ signal-hook = "0.1.10" strip-ansi-escapes = "0.1.0" structopt = "0.3" # termion = { git = "https://gitlab.com/TheLostLambda/termion.git", version = "1.6.0", features = ["serde"] } -termion = { package = "termion_temporary_zellij_fork", version = "1.6.0", features = ["serde"]} +termion = "1.5.0" termios = "0.3" unicode-truncate = "0.2.0" unicode-width = "0.1.8" diff --git a/src/common/errors.rs b/src/common/errors.rs index b5b96342..11d13c7e 100644 --- a/src/common/errors.rs +++ b/src/common/errors.rs @@ -278,6 +278,7 @@ use crate::wasm_vm::PluginInstruction; #[derive(Debug, Clone, Copy, PartialEq)] pub enum PluginContext { Load, + Update, Render, Input, GlobalInput, @@ -290,6 +291,7 @@ impl From<&PluginInstruction> for PluginContext { fn from(plugin_instruction: &PluginInstruction) -> Self { match *plugin_instruction { PluginInstruction::Load(..) => PluginContext::Load, + PluginInstruction::Update(_) => PluginContext::Update, PluginInstruction::Render(..) => PluginContext::Render, PluginInstruction::Input(..) => PluginContext::Input, PluginInstruction::GlobalInput(_) => PluginContext::GlobalInput, diff --git a/src/common/input/handler.rs b/src/common/input/handler.rs index 29a504f5..90afb64c 100644 --- a/src/common/input/handler.rs +++ b/src/common/input/handler.rs @@ -11,7 +11,7 @@ use crate::wasm_vm::{NaughtyEventType, PluginInputType, PluginInstruction}; use crate::CommandIsExecuting; use termion::input::TermReadEventsAndRaw; -use zellij_tile::data::{Help, InputMode}; +use zellij_tile::data::{Event, Help, InputMode, Key}; use super::keybinds::key_to_actions; @@ -61,6 +61,7 @@ impl InputHandler { 'input_loop: loop { //@@@ I think this should actually just iterate over stdin directly let stdin_buffer = self.os_input.read_from_stdin(); + // FIXME: Kill me someday (soon) drop( self.send_plugin_instructions .send(PluginInstruction::GlobalInput(stdin_buffer.clone())), @@ -69,6 +70,11 @@ impl InputHandler { match key_result { Ok((event, raw_bytes)) => match event { termion::event::Event::Key(key) => { + let key = cast_termion_key(key); + drop( + self.send_plugin_instructions + .send(PluginInstruction::Update(Event::KeyPress(key))), + ); // FIXME this explicit break is needed because the current test // framework relies on it to not create dead threads that loop // and eat up CPUs. Do not remove until the test framework has @@ -320,3 +326,31 @@ pub fn input_loop( ) .handle_input(); } + +// FIXME: This is an absolutely cursed function that should be destroyed as soon +// as an alternative that doesn't touch zellij-tile can be developed... +fn cast_termion_key(event: termion::event::Key) -> Key { + match event { + termion::event::Key::Backspace => Key::Backspace, + termion::event::Key::Left => Key::Left, + termion::event::Key::Right => Key::Right, + termion::event::Key::Up => Key::Up, + termion::event::Key::Down => Key::Down, + termion::event::Key::Home => Key::Home, + termion::event::Key::End => Key::End, + termion::event::Key::PageUp => Key::PageUp, + termion::event::Key::PageDown => Key::PageDown, + termion::event::Key::BackTab => Key::BackTab, + termion::event::Key::Delete => Key::Delete, + termion::event::Key::Insert => Key::Insert, + termion::event::Key::F(n) => Key::F(n), + termion::event::Key::Char(c) => Key::Char(c), + termion::event::Key::Alt(c) => Key::Alt(c), + termion::event::Key::Ctrl(c) => Key::Ctrl(c), + termion::event::Key::Null => Key::Null, + termion::event::Key::Esc => Key::Esc, + _ => { + unimplemented!("Encountered an unknown key!") + } + } +} diff --git a/src/common/input/keybinds.rs b/src/common/input/keybinds.rs index 183b9a2c..e48d3115 100644 --- a/src/common/input/keybinds.rs +++ b/src/common/input/keybinds.rs @@ -5,7 +5,6 @@ use super::actions::{Action, Direction}; use std::collections::HashMap; use strum::IntoEnumIterator; -use termion::event::Key; use zellij_tile::data::*; type Keybinds = HashMap; diff --git a/src/common/mod.rs b/src/common/mod.rs index 675fe828..70edcea8 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -40,7 +40,7 @@ use wasm_vm::{ }; use wasmer::{ChainableNamedResolver, Instance, Module, Store, Value}; use wasmer_wasi::{Pipe, WasiState}; -use zellij_tile::data::InputMode; +use zellij_tile::data::{InputMode, Key}; #[derive(Serialize, Deserialize, Debug)] pub enum ApiCommand { @@ -456,6 +456,33 @@ pub fn start(mut os_input: Box, opts: CliArgs) { .collect(); move || loop { + // FIXME: This 100% *must* be destroyed before this makes in into main!!!!!!!!!!! + fn cast_termion_key(event: termion::event::Key) -> Key { + match event { + termion::event::Key::Backspace => Key::Backspace, + termion::event::Key::Left => Key::Left, + termion::event::Key::Right => Key::Right, + termion::event::Key::Up => Key::Up, + termion::event::Key::Down => Key::Down, + termion::event::Key::Home => Key::Home, + termion::event::Key::End => Key::End, + termion::event::Key::PageUp => Key::PageUp, + termion::event::Key::PageDown => Key::PageDown, + termion::event::Key::BackTab => Key::BackTab, + termion::event::Key::Delete => Key::Delete, + termion::event::Key::Insert => Key::Insert, + termion::event::Key::F(n) => Key::F(n), + termion::event::Key::Char(c) => Key::Char(c), + termion::event::Key::Alt(c) => Key::Alt(c), + termion::event::Key::Ctrl(c) => Key::Ctrl(c), + termion::event::Key::Null => Key::Null, + termion::event::Key::Esc => Key::Esc, + _ => { + unimplemented!("Encountered an unknown key!") + } + } + } + let (event, mut err_ctx) = receive_plugin_instructions .recv() .expect("failed to receive event on channel"); @@ -522,6 +549,17 @@ pub fn start(mut os_input: Box, opts: CliArgs) { pid_tx.send(plugin_id).unwrap(); plugin_id += 1; } + PluginInstruction::Update(event) => { + for (instance, plugin_env) in plugin_map.values() { + let update = instance.exports.get_function("update").unwrap(); + + wasi_write_string( + &plugin_env.wasi_env, + &serde_json::to_string(&event).unwrap(), + ); + update.call(&[]).unwrap(); + } + } PluginInstruction::Render(buf_tx, pid, rows, cols) => { let (instance, plugin_env) = plugin_map.get(&pid).unwrap(); @@ -555,6 +593,7 @@ pub fn start(mut os_input: Box, opts: CliArgs) { let handle_key = instance.exports.get_function("handle_key").unwrap(); for key in input_bytes.keys().flatten() { + let key = cast_termion_key(key); wasi_write_string( &plugin_env.wasi_env, &serde_json::to_string(&key).unwrap(), @@ -572,6 +611,7 @@ pub fn start(mut os_input: Box, opts: CliArgs) { .get_function(handler_map.get(&event).unwrap()) .unwrap(); for key in input_bytes.keys().flatten() { + let key = cast_termion_key(key); wasi_write_string( &plugin_env.wasi_env, &serde_json::to_string(&key).unwrap(), @@ -589,6 +629,7 @@ pub fn start(mut os_input: Box, opts: CliArgs) { let handler = instance.exports.get_function("handle_global_key").unwrap(); for key in input_bytes.keys().flatten() { + let key = cast_termion_key(key); wasi_write_string( &plugin_env.wasi_env, &serde_json::to_string(&key).unwrap(), diff --git a/src/common/wasm_vm.rs b/src/common/wasm_vm.rs index 788219a4..2f2a0cf6 100644 --- a/src/common/wasm_vm.rs +++ b/src/common/wasm_vm.rs @@ -9,7 +9,7 @@ use std::{ }; use wasmer::{imports, Function, ImportObject, Store, WasmerEnv}; use wasmer_wasi::WasiEnv; -use zellij_tile::data::{EventType, TabInfo}; +use zellij_tile::data::{Event, EventType, TabInfo}; use super::{ input::handler::get_help, pty_bus::PtyInstruction, screen::ScreenInstruction, AppInstruction, @@ -30,6 +30,7 @@ pub enum PluginInputType { #[derive(Clone, Debug)] pub enum PluginInstruction { Load(Sender, PathBuf, Vec), + Update(Event), Render(Sender, u32, usize, usize), // String buffer, plugin id, rows, cols Input(PluginInputType, Vec), // plugin id, input bytes GlobalInput(Vec), // input bytes diff --git a/zellij-tile/src/data.rs b/zellij-tile/src/data.rs index 2a03b94c..abca9994 100644 --- a/zellij-tile/src/data.rs +++ b/zellij-tile/src/data.rs @@ -23,7 +23,7 @@ pub enum Key { Esc, } -#[derive(Debug, EnumDiscriminants, ToString, Serialize, Deserialize)] +#[derive(Debug, Clone, EnumDiscriminants, ToString, Serialize, Deserialize)] #[strum_discriminants(derive(Hash, Serialize, Deserialize))] #[strum_discriminants(name(EventType))] pub enum Event { diff --git a/zellij-tile/src/lib.rs b/zellij-tile/src/lib.rs index 6adc9f6d..eb1b08fb 100644 --- a/zellij-tile/src/lib.rs +++ b/zellij-tile/src/lib.rs @@ -7,6 +7,7 @@ use data::*; #[allow(unused_variables)] pub trait ZellijTile { fn load(&mut self) {} + fn update(&mut self, event: Event) {} fn render(&mut self, rows: usize, cols: usize) {} // FIXME: Everything below this line should be purged fn handle_key(&mut self, key: Key) {} @@ -28,6 +29,15 @@ macro_rules! register_tile { }); } + #[no_mangle] + pub fn update() { + STATE.with(|state| { + state + .borrow_mut() + .update($crate::shim::deserialize_from_stdin().unwrap()); + }); + } + #[no_mangle] pub fn render(rows: i32, cols: i32) { STATE.with(|state| { diff --git a/zellij-tile/src/shim.rs b/zellij-tile/src/shim.rs index 3681e9ba..e0e65490 100644 --- a/zellij-tile/src/shim.rs +++ b/zellij-tile/src/shim.rs @@ -45,7 +45,9 @@ pub fn get_tabs() -> Vec { deserialize_from_stdin().unwrap_or_default() } -fn deserialize_from_stdin() -> Option { +#[doc(hidden)] +// FIXME: Make this just return T and do a .unwrap() at the end; also naming? +pub fn deserialize_from_stdin() -> Option { let mut json = String::new(); io::stdin().read_line(&mut json).unwrap(); serde_json::from_str(&json).ok() From 23df8e447a1e73b8e3536fbf9781f1aafcee2765 Mon Sep 17 00:00:00 2001 From: Brooks J Rady Date: Tue, 23 Mar 2021 23:57:18 +0000 Subject: [PATCH 21/31] Move most key handling to the update() + event system --- default-tiles/strider/src/main.rs | 67 ++++++++++++++------------- src/client/tab.rs | 16 +++---- src/common/errors.rs | 4 +- src/common/input/handler.rs | 18 ++++---- src/common/mod.rs | 76 ++++++++++--------------------- src/common/wasm_vm.rs | 5 +- zellij-tile/src/data.rs | 4 +- zellij-tile/src/lib.rs | 18 -------- 8 files changed, 82 insertions(+), 126 deletions(-) diff --git a/default-tiles/strider/src/main.rs b/default-tiles/strider/src/main.rs index 08f44707..c2867fe4 100644 --- a/default-tiles/strider/src/main.rs +++ b/default-tiles/strider/src/main.rs @@ -10,6 +10,41 @@ register_tile!(State); impl ZellijTile for State { fn load(&mut self) { refresh_directory(self); + subscribe(&[EventType::KeyPress]); + } + + fn update(&mut self, event: Event) { + if let Event::KeyPress(key) = event { + match key { + Key::Up | Key::Char('k') => { + *self.selected_mut() = self.selected().saturating_sub(1); + } + Key::Down | Key::Char('j') => { + let next = self.selected().saturating_add(1); + *self.selected_mut() = min(self.files.len() - 1, next); + } + Key::Right | Key::Char('\n') | Key::Char('l') => { + match self.files[self.selected()].clone() { + FsEntry::Dir(p, _) => { + self.path = p; + refresh_directory(self); + } + FsEntry::File(p, _) => open_file(&p), + } + } + Key::Left | Key::Char('h') => { + self.path.pop(); + refresh_directory(self); + } + + Key::Char('.') => { + self.toggle_hidden_files(); + refresh_directory(self); + } + + _ => (), + }; + } } fn render(&mut self, rows: usize, cols: usize) { @@ -38,38 +73,6 @@ impl ZellijTile for State { } } } - - fn handle_key(&mut self, key: Key) { - match key { - Key::Up | Key::Char('k') => { - *self.selected_mut() = self.selected().saturating_sub(1); - } - Key::Down | Key::Char('j') => { - let next = self.selected().saturating_add(1); - *self.selected_mut() = min(self.files.len() - 1, next); - } - Key::Right | Key::Char('\n') | Key::Char('l') => { - match self.files[self.selected()].clone() { - FsEntry::Dir(p, _) => { - self.path = p; - refresh_directory(self); - } - FsEntry::File(p, _) => open_file(&p), - } - } - Key::Left | Key::Char('h') => { - self.path.pop(); - refresh_directory(self); - } - - Key::Char('.') => { - self.toggle_hidden_files(); - refresh_directory(self); - } - - _ => (), - }; - } } fn refresh_directory(state: &mut State) { diff --git a/src/client/tab.rs b/src/client/tab.rs index 1818672b..1a3f411d 100644 --- a/src/client/tab.rs +++ b/src/client/tab.rs @@ -1,11 +1,11 @@ //! `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::parse_keys, AppInstruction, SenderWithContext}; use crate::layout::Layout; use crate::panes::{PaneId, PositionAndSize, TerminalPane}; use crate::pty_bus::{PtyInstruction, VteEvent}; -use crate::wasm_vm::{PluginInputType, PluginInstruction}; +use crate::wasm_vm::PluginInstruction; use crate::{boundaries::Boundaries, panes::PluginPane}; use crate::{os_input_output::OsApi, utils::shared::pad_to_size}; use std::os::unix::io::RawFd; @@ -14,6 +14,7 @@ use std::{ collections::{BTreeMap, HashSet}, }; use std::{io::Write, sync::mpsc::channel}; +use zellij_tile::data::Event; const CURSOR_HEIGHT_WIDTH_RATIO: usize = 4; // this is not accurate and kind of a magic number, TODO: look into this const MIN_TERMINAL_HEIGHT: usize = 2; @@ -553,12 +554,11 @@ impl Tab { .expect("failed to drain terminal"); } Some(PaneId::Plugin(pid)) => { - self.send_plugin_instructions - .send(PluginInstruction::Input( - PluginInputType::Normal(pid), - input_bytes, - )) - .unwrap(); + for key in parse_keys(&input_bytes) { + self.send_plugin_instructions + .send(PluginInstruction::Update(Some(pid), Event::KeyPress(key))) + .unwrap() + } } _ => {} } diff --git a/src/common/errors.rs b/src/common/errors.rs index 11d13c7e..b12a57a1 100644 --- a/src/common/errors.rs +++ b/src/common/errors.rs @@ -281,7 +281,6 @@ pub enum PluginContext { Update, Render, Input, - GlobalInput, Unload, Quit, Tabs, @@ -291,10 +290,9 @@ impl From<&PluginInstruction> for PluginContext { fn from(plugin_instruction: &PluginInstruction) -> Self { match *plugin_instruction { PluginInstruction::Load(..) => PluginContext::Load, - PluginInstruction::Update(_) => PluginContext::Update, + PluginInstruction::Update(..) => PluginContext::Update, PluginInstruction::Render(..) => PluginContext::Render, PluginInstruction::Input(..) => PluginContext::Input, - PluginInstruction::GlobalInput(_) => PluginContext::GlobalInput, PluginInstruction::Unload(_) => PluginContext::Unload, PluginInstruction::Quit => PluginContext::Quit, PluginInstruction::UpdateTabs(..) => PluginContext::Tabs, diff --git a/src/common/input/handler.rs b/src/common/input/handler.rs index 90afb64c..4b948cbf 100644 --- a/src/common/input/handler.rs +++ b/src/common/input/handler.rs @@ -10,8 +10,8 @@ use crate::screen::ScreenInstruction; use crate::wasm_vm::{NaughtyEventType, PluginInputType, PluginInstruction}; use crate::CommandIsExecuting; -use termion::input::TermReadEventsAndRaw; -use zellij_tile::data::{Event, Help, InputMode, Key}; +use termion::input::{TermRead, TermReadEventsAndRaw}; +use zellij_tile::data::{Help, InputMode, Key}; use super::keybinds::key_to_actions; @@ -61,19 +61,15 @@ impl InputHandler { 'input_loop: loop { //@@@ I think this should actually just iterate over stdin directly let stdin_buffer = self.os_input.read_from_stdin(); - // FIXME: Kill me someday (soon) - drop( - self.send_plugin_instructions - .send(PluginInstruction::GlobalInput(stdin_buffer.clone())), - ); for key_result in stdin_buffer.events_and_raw() { match key_result { Ok((event, raw_bytes)) => match event { termion::event::Event::Key(key) => { let key = cast_termion_key(key); + // FIXME: This is a bit of a hack to get resizing to work! drop( - self.send_plugin_instructions - .send(PluginInstruction::Update(Event::KeyPress(key))), + self.send_screen_instructions + .send(ScreenInstruction::Render), ); // FIXME this explicit break is needed because the current test // framework relies on it to not create dead threads that loop @@ -327,6 +323,10 @@ pub fn input_loop( .handle_input(); } +pub fn parse_keys(input_bytes: &[u8]) -> Vec { + input_bytes.keys().flatten().map(cast_termion_key).collect() +} + // FIXME: This is an absolutely cursed function that should be destroyed as soon // as an alternative that doesn't touch zellij-tile can be developed... fn cast_termion_key(event: termion::event::Key) -> Key { diff --git a/src/common/mod.rs b/src/common/mod.rs index 70edcea8..b8a4c671 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -17,6 +17,7 @@ use std::{collections::HashMap, fs}; use std::{ collections::HashSet, io::Write, + str::FromStr, sync::{Arc, Mutex}, }; @@ -40,7 +41,7 @@ use wasm_vm::{ }; use wasmer::{ChainableNamedResolver, Instance, Module, Store, Value}; use wasmer_wasi::{Pipe, WasiState}; -use zellij_tile::data::{InputMode, Key}; +use zellij_tile::data::{EventType, InputMode, Key}; #[derive(Serialize, Deserialize, Debug)] pub enum ApiCommand { @@ -549,16 +550,21 @@ pub fn start(mut os_input: Box, opts: CliArgs) { pid_tx.send(plugin_id).unwrap(); plugin_id += 1; } - PluginInstruction::Update(event) => { - for (instance, plugin_env) in plugin_map.values() { - let update = instance.exports.get_function("update").unwrap(); - - wasi_write_string( - &plugin_env.wasi_env, - &serde_json::to_string(&event).unwrap(), - ); - update.call(&[]).unwrap(); + PluginInstruction::Update(pid, event) => { + for (&i, (instance, plugin_env)) in &plugin_map { + let subs = plugin_env.subscriptions.lock().unwrap(); + // FIXME: This is very janky... Maybe I should write my own macro for Event -> EventType? + let event_type = EventType::from_str(&event.to_string()).unwrap(); + if pid.is_none() || pid == Some(i) && subs.contains(&event_type) { + let update = instance.exports.get_function("update").unwrap(); + wasi_write_string( + &plugin_env.wasi_env, + &serde_json::to_string(&event).unwrap(), + ); + update.call(&[]).unwrap(); + } } + drop(send_screen_instructions.send(ScreenInstruction::Render)); } PluginInstruction::Render(buf_tx, pid, rows, cols) => { let (instance, plugin_env) = plugin_map.get(&pid).unwrap(); @@ -587,11 +593,15 @@ pub fn start(mut os_input: Box, opts: CliArgs) { } // FIXME: Deduplicate this with the callback below! PluginInstruction::Input(input_type, input_bytes) => { - match input_type { - PluginInputType::Normal(pid) => { - let (instance, plugin_env) = plugin_map.get(&pid).unwrap(); - let handle_key = - instance.exports.get_function("handle_key").unwrap(); + if let PluginInputType::Event(event) = input_type { + for (instance, plugin_env) in plugin_map.values() { + if !plugin_env.events.contains(&event) { + continue; + } + let handle_key = instance + .exports + .get_function(handler_map.get(&event).unwrap()) + .unwrap(); for key in input_bytes.keys().flatten() { let key = cast_termion_key(key); wasi_write_string( @@ -601,45 +611,9 @@ pub fn start(mut os_input: Box, opts: CliArgs) { handle_key.call(&[]).unwrap(); } } - PluginInputType::Event(event) => { - for (instance, plugin_env) in plugin_map.values() { - if !plugin_env.events.contains(&event) { - continue; - } - let handle_key = instance - .exports - .get_function(handler_map.get(&event).unwrap()) - .unwrap(); - for key in input_bytes.keys().flatten() { - let key = cast_termion_key(key); - wasi_write_string( - &plugin_env.wasi_env, - &serde_json::to_string(&key).unwrap(), - ); - handle_key.call(&[]).unwrap(); - } - } - } } drop(send_screen_instructions.send(ScreenInstruction::Render)); } - PluginInstruction::GlobalInput(input_bytes) => { - // FIXME: Set up an event subscription system, and timed callbacks - for (instance, plugin_env) in plugin_map.values() { - let handler = - instance.exports.get_function("handle_global_key").unwrap(); - for key in input_bytes.keys().flatten() { - let key = cast_termion_key(key); - wasi_write_string( - &plugin_env.wasi_env, - &serde_json::to_string(&key).unwrap(), - ); - handler.call(&[]).unwrap(); - } - } - - drop(send_screen_instructions.send(ScreenInstruction::Render)); - } PluginInstruction::Unload(pid) => drop(plugin_map.remove(&pid)), PluginInstruction::Quit => break, } diff --git a/src/common/wasm_vm.rs b/src/common/wasm_vm.rs index 2f2a0cf6..24b947d6 100644 --- a/src/common/wasm_vm.rs +++ b/src/common/wasm_vm.rs @@ -30,10 +30,9 @@ pub enum PluginInputType { #[derive(Clone, Debug)] pub enum PluginInstruction { Load(Sender, PathBuf, Vec), - Update(Event), + Update(Option, Event), // Focused plugin / broadcast, event data Render(Sender, u32, usize, usize), // String buffer, plugin id, rows, cols - Input(PluginInputType, Vec), // plugin id, input bytes - GlobalInput(Vec), // input bytes + Input(PluginInputType, Vec), // plugin id, input bytes Unload(u32), UpdateTabs(Vec), // num tabs, active tab Quit, diff --git a/zellij-tile/src/data.rs b/zellij-tile/src/data.rs index abca9994..a6e07983 100644 --- a/zellij-tile/src/data.rs +++ b/zellij-tile/src/data.rs @@ -1,5 +1,5 @@ use serde::{Deserialize, Serialize}; -use strum_macros::{EnumDiscriminants, EnumIter, ToString}; +use strum_macros::{EnumDiscriminants, EnumIter, EnumString, ToString}; #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] pub enum Key { @@ -24,7 +24,7 @@ pub enum Key { } #[derive(Debug, Clone, EnumDiscriminants, ToString, Serialize, Deserialize)] -#[strum_discriminants(derive(Hash, Serialize, Deserialize))] +#[strum_discriminants(derive(EnumString, Hash, Serialize, Deserialize))] #[strum_discriminants(name(EventType))] pub enum Event { ModeUpdate(Help), // FIXME: Rename the `Help` struct diff --git a/zellij-tile/src/lib.rs b/zellij-tile/src/lib.rs index eb1b08fb..771edb2d 100644 --- a/zellij-tile/src/lib.rs +++ b/zellij-tile/src/lib.rs @@ -10,8 +10,6 @@ pub trait ZellijTile { fn update(&mut self, event: Event) {} fn render(&mut self, rows: usize, cols: usize) {} // FIXME: Everything below this line should be purged - fn handle_key(&mut self, key: Key) {} - fn handle_global_key(&mut self, key: Key) {} fn update_tabs(&mut self) {} fn handle_tab_rename_keypress(&mut self, key: Key) {} } @@ -45,22 +43,6 @@ macro_rules! register_tile { }); } - #[no_mangle] - pub fn handle_key() { - STATE.with(|state| { - state.borrow_mut().handle_key($crate::shim::get_key()); - }); - } - - #[no_mangle] - pub fn handle_global_key() { - STATE.with(|state| { - state - .borrow_mut() - .handle_global_key($crate::shim::get_key()); - }); - } - #[no_mangle] pub fn update_tabs() { STATE.with(|state| { From 91608dfe4ea3e75853d4966d7f464d85c022beef Mon Sep 17 00:00:00 2001 From: denis Date: Wed, 24 Mar 2021 07:50:47 +0200 Subject: [PATCH 22/31] 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 23/31] 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 24/31] 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(); From 81a517b264912f65fd9a216befd5dd788d93adf4 Mon Sep 17 00:00:00 2001 From: Brooks J Rady Date: Thu, 25 Mar 2021 14:13:59 +0000 Subject: [PATCH 25/31] Remove a dead input enum variant --- src/common/mod.rs | 34 +++++++++++++++++----------------- src/common/wasm_vm.rs | 1 - 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/common/mod.rs b/src/common/mod.rs index b8a4c671..add50d47 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -593,25 +593,25 @@ pub fn start(mut os_input: Box, opts: CliArgs) { } // FIXME: Deduplicate this with the callback below! PluginInstruction::Input(input_type, input_bytes) => { - if let PluginInputType::Event(event) = input_type { - for (instance, plugin_env) in plugin_map.values() { - if !plugin_env.events.contains(&event) { - continue; - } - let handle_key = instance - .exports - .get_function(handler_map.get(&event).unwrap()) - .unwrap(); - for key in input_bytes.keys().flatten() { - let key = cast_termion_key(key); - wasi_write_string( - &plugin_env.wasi_env, - &serde_json::to_string(&key).unwrap(), - ); - handle_key.call(&[]).unwrap(); - } + let PluginInputType::Event(event) = input_type; + for (instance, plugin_env) in plugin_map.values() { + if !plugin_env.events.contains(&event) { + continue; + } + let handle_key = instance + .exports + .get_function(handler_map.get(&event).unwrap()) + .unwrap(); + for key in input_bytes.keys().flatten() { + let key = cast_termion_key(key); + wasi_write_string( + &plugin_env.wasi_env, + &serde_json::to_string(&key).unwrap(), + ); + handle_key.call(&[]).unwrap(); } } + drop(send_screen_instructions.send(ScreenInstruction::Render)); } PluginInstruction::Unload(pid) => drop(plugin_map.remove(&pid)), diff --git a/src/common/wasm_vm.rs b/src/common/wasm_vm.rs index 24b947d6..19b3a197 100644 --- a/src/common/wasm_vm.rs +++ b/src/common/wasm_vm.rs @@ -23,7 +23,6 @@ pub enum NaughtyEventType { #[derive(Clone, Debug)] pub enum PluginInputType { - Normal(u32), Event(NaughtyEventType), } From 0ea8ce497d899e1a9faa241cfeaedcaa35f8e3f0 Mon Sep 17 00:00:00 2001 From: Brooks J Rady Date: Thu, 25 Mar 2021 14:30:31 +0000 Subject: [PATCH 26/31] Rename Help to ModeInfo --- default-tiles/status-bar/src/first_line.rs | 2 +- default-tiles/status-bar/src/second_line.rs | 8 ++++---- src/common/input/handler.rs | 6 +++--- zellij-tile/src/data.rs | 4 ++-- zellij-tile/src/shim.rs | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/default-tiles/status-bar/src/first_line.rs b/default-tiles/status-bar/src/first_line.rs index 00ff1543..20603df1 100644 --- a/default-tiles/status-bar/src/first_line.rs +++ b/default-tiles/status-bar/src/first_line.rs @@ -287,7 +287,7 @@ pub fn superkey() -> LinePart { } } -pub fn ctrl_keys(help: &Help, max_len: usize) -> LinePart { +pub fn ctrl_keys(help: &ModeInfo, max_len: usize) -> LinePart { match &help.mode { InputMode::Locked => key_indicators( max_len, diff --git a/default-tiles/status-bar/src/second_line.rs b/default-tiles/status-bar/src/second_line.rs index 743fba7f..322f4333 100644 --- a/default-tiles/status-bar/src/second_line.rs +++ b/default-tiles/status-bar/src/second_line.rs @@ -97,7 +97,7 @@ fn select_pane_shortcut(is_first_shortcut: bool) -> LinePart { } } -fn full_shortcut_list(help: &Help) -> LinePart { +fn full_shortcut_list(help: &ModeInfo) -> LinePart { match help.mode { InputMode::Normal => LinePart::default(), InputMode::Locked => locked_interface_indication(), @@ -116,7 +116,7 @@ fn full_shortcut_list(help: &Help) -> LinePart { } } -fn shortened_shortcut_list(help: &Help) -> LinePart { +fn shortened_shortcut_list(help: &ModeInfo) -> LinePart { match help.mode { InputMode::Normal => LinePart::default(), InputMode::Locked => locked_interface_indication(), @@ -135,7 +135,7 @@ fn shortened_shortcut_list(help: &Help) -> LinePart { } } -fn best_effort_shortcut_list(help: &Help, max_len: usize) -> LinePart { +fn best_effort_shortcut_list(help: &ModeInfo, max_len: usize) -> LinePart { match help.mode { InputMode::Normal => LinePart::default(), InputMode::Locked => { @@ -169,7 +169,7 @@ fn best_effort_shortcut_list(help: &Help, max_len: usize) -> LinePart { } } -pub fn keybinds(help: &Help, max_width: usize) -> LinePart { +pub fn keybinds(help: &ModeInfo, max_width: usize) -> LinePart { let full_shortcut_list = full_shortcut_list(help); if full_shortcut_list.len <= max_width { return full_shortcut_list; diff --git a/src/common/input/handler.rs b/src/common/input/handler.rs index f48ec7c9..857ebb5a 100644 --- a/src/common/input/handler.rs +++ b/src/common/input/handler.rs @@ -11,7 +11,7 @@ use crate::wasm_vm::{NaughtyEventType, PluginInputType, PluginInstruction}; use crate::CommandIsExecuting; use termion::input::{TermRead, TermReadEventsAndRaw}; -use zellij_tile::data::{Help, InputMode, Key}; +use zellij_tile::data::{InputMode, Key, ModeInfo}; use super::keybinds::key_to_actions; @@ -273,7 +273,7 @@ impl InputHandler { /// Creates a [`Help`] struct indicating the current [`InputMode`] and its keybinds /// (as pairs of [`String`]s). // TODO this should probably be automatically generated in some way -pub fn get_help(mode: InputMode) -> Help { +pub fn get_help(mode: InputMode) -> ModeInfo { let mut keybinds: Vec<(String, String)> = vec![]; match mode { InputMode::Normal | InputMode::Locked => {} @@ -302,7 +302,7 @@ pub fn get_help(mode: InputMode) -> Help { keybinds.push(("Enter".to_string(), "when done".to_string())); } } - Help { mode, keybinds } + ModeInfo { mode, keybinds } } /// Entry point to the module. Instantiates an [`InputHandler`] and starts diff --git a/zellij-tile/src/data.rs b/zellij-tile/src/data.rs index a6e07983..67bf0d74 100644 --- a/zellij-tile/src/data.rs +++ b/zellij-tile/src/data.rs @@ -27,7 +27,7 @@ pub enum Key { #[strum_discriminants(derive(EnumString, Hash, Serialize, Deserialize))] #[strum_discriminants(name(EventType))] pub enum Event { - ModeUpdate(Help), // FIXME: Rename the `Help` struct + ModeUpdate(ModeInfo), TabUpdate(TabInfo), KeyPress(Key), } @@ -62,7 +62,7 @@ impl Default for InputMode { /// which indicates the current [`InputMode`] and what the keybinds for that mode /// are. Related to the default `status-bar` plugin. #[derive(Default, Debug, Clone, Serialize, Deserialize)] -pub struct Help { +pub struct ModeInfo { pub mode: InputMode, // FIXME: This should probably return Keys and Actions, then sort out strings plugin-side pub keybinds: Vec<(String, String)>, // => diff --git a/zellij-tile/src/shim.rs b/zellij-tile/src/shim.rs index e0e65490..afb49f27 100644 --- a/zellij-tile/src/shim.rs +++ b/zellij-tile/src/shim.rs @@ -36,7 +36,7 @@ pub fn set_selectable(selectable: bool) { unsafe { host_set_selectable(selectable) }; } -pub fn get_help() -> Help { +pub fn get_help() -> ModeInfo { unsafe { host_get_help() }; deserialize_from_stdin().unwrap_or_default() } From 0371c111b795b8ff5ad852b22528f5caa3a2c7b0 Mon Sep 17 00:00:00 2001 From: Brooks J Rady Date: Thu, 25 Mar 2021 14:56:59 +0000 Subject: [PATCH 27/31] Removed AppState and the unneeded get_help() function --- default-tiles/status-bar/src/main.rs | 16 +++++++++--- src/common/errors.rs | 4 --- src/common/input/handler.rs | 17 +++++++----- src/common/mod.rs | 39 +--------------------------- src/common/wasm_vm.rs | 24 ++--------------- zellij-tile/src/shim.rs | 6 ----- 6 files changed, 25 insertions(+), 81 deletions(-) diff --git a/default-tiles/status-bar/src/main.rs b/default-tiles/status-bar/src/main.rs index 59065a81..8daa158e 100644 --- a/default-tiles/status-bar/src/main.rs +++ b/default-tiles/status-bar/src/main.rs @@ -23,7 +23,9 @@ static ARROW_SEPARATOR: &str = ""; static MORE_MSG: &str = " ... "; #[derive(Default)] -struct State {} +struct State { + mode_info: ModeInfo, +} register_tile!(State); @@ -44,15 +46,21 @@ impl ZellijTile for State { set_selectable(false); set_invisible_borders(true); set_max_height(2); + subscribe(&[EventType::ModeUpdate]); + } + + fn update(&mut self, event: Event) { + if let Event::ModeUpdate(mode_info) = event { + self.mode_info = mode_info; + } } fn render(&mut self, _rows: usize, cols: usize) { - let help = get_help(); let superkey = superkey(); - let ctrl_keys = ctrl_keys(&help, cols - superkey.len); + let ctrl_keys = ctrl_keys(&self.mode_info, cols - superkey.len); let first_line = format!("{}{}", superkey, ctrl_keys); - let second_line = keybinds(&help, cols); + let second_line = keybinds(&self.mode_info, cols); // [48;5;238m is gray background, [0K is so that it fills the rest of the line // [48;5;16m is black background, [0K is so that it fills the rest of the line diff --git a/src/common/errors.rs b/src/common/errors.rs index 9afa694f..7b194f5d 100644 --- a/src/common/errors.rs +++ b/src/common/errors.rs @@ -305,8 +305,6 @@ impl From<&PluginInstruction> for PluginContext { /// Stack call representations corresponding to the different types of [`AppInstruction`]s. #[derive(Debug, Clone, Copy, PartialEq)] pub enum AppContext { - GetState, - SetState, Exit, Error, } @@ -314,8 +312,6 @@ pub enum AppContext { impl From<&AppInstruction> for AppContext { fn from(app_instruction: &AppInstruction) -> Self { match *app_instruction { - AppInstruction::GetState(_) => AppContext::GetState, - AppInstruction::SetState(_) => AppContext::SetState, AppInstruction::Exit => AppContext::Exit, AppInstruction::Error(_) => AppContext::Error, } diff --git a/src/common/input/handler.rs b/src/common/input/handler.rs index 857ebb5a..3444471a 100644 --- a/src/common/input/handler.rs +++ b/src/common/input/handler.rs @@ -2,7 +2,7 @@ use super::actions::Action; use super::keybinds::get_default_keybinds; -use crate::common::{update_state, AppInstruction, AppState, SenderWithContext, OPENCALLS}; +use crate::common::{AppInstruction, SenderWithContext, OPENCALLS}; use crate::errors::ContextType; use crate::os_input_output::OsApi; use crate::pty_bus::PtyInstruction; @@ -11,7 +11,7 @@ use crate::wasm_vm::{NaughtyEventType, PluginInputType, PluginInstruction}; use crate::CommandIsExecuting; use termion::input::{TermRead, TermReadEventsAndRaw}; -use zellij_tile::data::{InputMode, Key, ModeInfo}; +use zellij_tile::data::{Event, InputMode, Key, ModeInfo}; use super::keybinds::key_to_actions; @@ -128,11 +128,14 @@ impl InputHandler { } Action::SwitchToMode(mode) => { self.mode = mode; - update_state(&self.send_app_instructions, |_| AppState { - input_mode: self.mode, - }); + self.send_plugin_instructions + .send(PluginInstruction::Update( + None, + Event::ModeUpdate(get_mode_info(mode)), + )) + .unwrap(); self.send_screen_instructions - .send(ScreenInstruction::ChangeInputMode(self.mode)) + .send(ScreenInstruction::ChangeInputMode(mode)) .unwrap(); self.send_screen_instructions .send(ScreenInstruction::Render) @@ -273,7 +276,7 @@ impl InputHandler { /// Creates a [`Help`] struct indicating the current [`InputMode`] and its keybinds /// (as pairs of [`String`]s). // TODO this should probably be automatically generated in some way -pub fn get_help(mode: InputMode) -> ModeInfo { +pub fn get_mode_info(mode: InputMode) -> ModeInfo { let mut keybinds: Vec<(String, String)> = vec![]; match mode { InputMode::Normal | InputMode::Locked => {} diff --git a/src/common/mod.rs b/src/common/mod.rs index d8957003..f291eb19 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -9,10 +9,10 @@ pub mod screen; pub mod utils; pub mod wasm_vm; +use std::cell::RefCell; use std::path::{Path, PathBuf}; use std::sync::mpsc; use std::thread; -use std::{cell::RefCell, sync::mpsc::TrySendError}; use std::{collections::HashMap, fs}; use std::{ collections::HashSet, @@ -50,25 +50,6 @@ pub enum ApiCommand { SplitVertically, MoveFocus, } -// FIXME: It would be good to add some more things to this over time -#[derive(Debug, Clone, Default)] -pub struct AppState { - pub input_mode: InputMode, -} - -// FIXME: Make this a method on the big `Communication` struct, so that app_tx can be extracted -// from self instead of being explicitly passed here -pub fn update_state( - app_tx: &SenderWithContext, - update_fn: impl FnOnce(AppState) -> AppState, -) { - let (state_tx, state_rx) = mpsc::channel(); - - drop(app_tx.send(AppInstruction::GetState(state_tx))); - let state = state_rx.recv().unwrap(); - - drop(app_tx.send(AppInstruction::SetState(update_fn(state)))) -} /// An [MPSC](mpsc) asynchronous channel with added error context. pub type ChannelWithContext = ( @@ -112,19 +93,6 @@ impl SenderWithContext { } } - /// Attempts to send an event on this sender's channel, terminating instead of blocking - /// if the event could not be sent (buffer full or connection closed). - /// - /// This can only be called on [`SyncSender`](SenderType::SyncSender)s, and will - /// panic if called on an asynchronous [`Sender`](SenderType::Sender). - pub fn try_send(&self, event: T) -> Result<(), TrySendError<(T, ErrorContext)>> { - if let SenderType::SyncSender(ref s) = self.sender { - s.try_send((event, self.err_ctx)) - } else { - panic!("try_send can only be called on SyncSenders!") - } - } - /// Updates this [`SenderWithContext`]'s [`ErrorContext`]. This is the way one adds /// a call to the error context. /// @@ -147,8 +115,6 @@ thread_local!( /// Instructions related to the entire application. #[derive(Clone)] pub enum AppInstruction { - GetState(mpsc::Sender), - SetState(AppState), Exit, Error(String), } @@ -162,7 +128,6 @@ pub fn start(mut os_input: Box, opts: CliArgs) { .get_stdout_writer() .write(take_snapshot.as_bytes()) .unwrap(); - let mut app_state = AppState::default(); let command_is_executing = CommandIsExecuting::new(); @@ -715,8 +680,6 @@ pub fn start(mut os_input: Box, opts: CliArgs) { send_screen_instructions.update(err_ctx); send_pty_instructions.update(err_ctx); match app_instruction { - AppInstruction::GetState(state_tx) => drop(state_tx.send(app_state.clone())), - AppInstruction::SetState(state) => app_state = state, AppInstruction::Exit => { break; } diff --git a/src/common/wasm_vm.rs b/src/common/wasm_vm.rs index 19b3a197..d6334e56 100644 --- a/src/common/wasm_vm.rs +++ b/src/common/wasm_vm.rs @@ -2,18 +2,14 @@ use serde::{Deserialize, Serialize}; use std::{ collections::HashSet, path::PathBuf, - sync::{ - mpsc::{channel, Sender}, - Arc, Mutex, - }, + sync::{mpsc::Sender, Arc, Mutex}, }; use wasmer::{imports, Function, ImportObject, Store, WasmerEnv}; use wasmer_wasi::WasiEnv; use zellij_tile::data::{Event, EventType, TabInfo}; use super::{ - input::handler::get_help, pty_bus::PtyInstruction, screen::ScreenInstruction, AppInstruction, - PaneId, SenderWithContext, + pty_bus::PtyInstruction, screen::ScreenInstruction, AppInstruction, PaneId, SenderWithContext, }; #[derive(Clone, Debug, PartialEq, Hash, Eq, Serialize, Deserialize)] @@ -59,7 +55,6 @@ pub fn zellij_imports(store: &Store, plugin_env: &PluginEnv) -> ImportObject { "host_set_invisible_borders" => Function::new_native_with_env(store, plugin_env.clone(), host_set_invisible_borders), "host_set_max_height" => Function::new_native_with_env(store, plugin_env.clone(), host_set_max_height), "host_set_selectable" => Function::new_native_with_env(store, plugin_env.clone(), host_set_selectable), - "host_get_help" => Function::new_native_with_env(store, plugin_env.clone(), host_get_help), } } } @@ -117,21 +112,6 @@ fn host_set_invisible_borders(plugin_env: &PluginEnv, invisible_borders: i32) { .unwrap() } -fn host_get_help(plugin_env: &PluginEnv) { - let (state_tx, state_rx) = channel(); - // FIXME: If I changed the application so that threads were sent the termination - // signal and joined one at a time, there would be an order to shutdown, so I - // could get rid of this .is_ok() check and the .try_send() - if plugin_env - .send_app_instructions - .try_send(AppInstruction::GetState(state_tx)) - .is_ok() - { - let help = get_help(state_rx.recv().unwrap().input_mode); - wasi_write_string(&plugin_env.wasi_env, &serde_json::to_string(&help).unwrap()); - } -} - // Helper Functions --------------------------------------------------------------------------------------------------- // FIXME: Unwrap city diff --git a/zellij-tile/src/shim.rs b/zellij-tile/src/shim.rs index afb49f27..bbdf5fcc 100644 --- a/zellij-tile/src/shim.rs +++ b/zellij-tile/src/shim.rs @@ -36,11 +36,6 @@ pub fn set_selectable(selectable: bool) { unsafe { host_set_selectable(selectable) }; } -pub fn get_help() -> ModeInfo { - unsafe { host_get_help() }; - deserialize_from_stdin().unwrap_or_default() -} - pub fn get_tabs() -> Vec { deserialize_from_stdin().unwrap_or_default() } @@ -61,5 +56,4 @@ extern "C" { fn host_set_max_height(max_height: i32); fn host_set_selectable(selectable: i32); fn host_set_invisible_borders(invisible_borders: i32); - fn host_get_help(); } From 84a5cf95d1168db47931f81774e1210e1f022a69 Mon Sep 17 00:00:00 2001 From: Brooks J Rady Date: Thu, 25 Mar 2021 15:51:39 +0000 Subject: [PATCH 28/31] Converted tab updates to the new generic update() function --- default-tiles/tab-bar/src/main.rs | 13 +++++++------ src/common/errors.rs | 2 -- src/common/mod.rs | 16 +--------------- src/common/screen.rs | 4 ++-- src/common/wasm_vm.rs | 3 +-- zellij-tile/src/data.rs | 2 +- zellij-tile/src/lib.rs | 8 -------- zellij-tile/src/shim.rs | 4 ---- 8 files changed, 12 insertions(+), 40 deletions(-) diff --git a/default-tiles/tab-bar/src/main.rs b/default-tiles/tab-bar/src/main.rs index a245dc1f..7f5e438d 100644 --- a/default-tiles/tab-bar/src/main.rs +++ b/default-tiles/tab-bar/src/main.rs @@ -51,8 +51,13 @@ impl ZellijTile for State { set_selectable(false); set_invisible_borders(true); set_max_height(1); - self.mode = BarMode::Normal; - self.new_name = String::new(); + subscribe(&[EventType::TabUpdate]); + } + + fn update(&mut self, event: Event) { + if let Event::TabUpdate(tabs) = event { + self.tabs = tabs; + } } fn render(&mut self, _rows: usize, cols: usize) { @@ -84,10 +89,6 @@ impl ZellijTile for State { println!("{}\u{1b}[48;5;238m\u{1b}[0K", s); } - fn update_tabs(&mut self) { - self.tabs = get_tabs(); - } - fn handle_tab_rename_keypress(&mut self, key: Key) { self.mode = BarMode::Rename; match key { diff --git a/src/common/errors.rs b/src/common/errors.rs index 7b194f5d..83860a59 100644 --- a/src/common/errors.rs +++ b/src/common/errors.rs @@ -285,7 +285,6 @@ pub enum PluginContext { Input, Unload, Quit, - Tabs, } impl From<&PluginInstruction> for PluginContext { @@ -297,7 +296,6 @@ impl From<&PluginInstruction> for PluginContext { PluginInstruction::Input(..) => PluginContext::Input, PluginInstruction::Unload(_) => PluginContext::Unload, PluginInstruction::Quit => PluginContext::Quit, - PluginInstruction::UpdateTabs(..) => PluginContext::Tabs, } } } diff --git a/src/common/mod.rs b/src/common/mod.rs index f291eb19..15a28d96 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -524,7 +524,7 @@ pub fn start(mut os_input: Box, opts: CliArgs) { let subs = plugin_env.subscriptions.lock().unwrap(); // FIXME: This is very janky... Maybe I should write my own macro for Event -> EventType? let event_type = EventType::from_str(&event.to_string()).unwrap(); - if pid.is_none() || pid == Some(i) && subs.contains(&event_type) { + if (pid.is_none() || pid == Some(i)) && subs.contains(&event_type) { let update = instance.exports.get_function("update").unwrap(); wasi_write_string( &plugin_env.wasi_env, @@ -546,20 +546,6 @@ pub fn start(mut os_input: Box, opts: CliArgs) { buf_tx.send(wasi_stdout(&plugin_env.wasi_env)).unwrap(); } - PluginInstruction::UpdateTabs(mut tabs) => { - for (instance, plugin_env) in plugin_map.values() { - if !plugin_env.events.contains(&NaughtyEventType::Tab) { - continue; - } - let handler = instance.exports.get_function("update_tabs").unwrap(); - tabs.sort_by(|a, b| a.position.cmp(&b.position)); - wasi_write_string( - &plugin_env.wasi_env, - &serde_json::to_string(&tabs).unwrap(), - ); - handler.call(&[]).unwrap(); - } - } // FIXME: Deduplicate this with the callback below! PluginInstruction::Input(input_type, input_bytes) => { let PluginInputType::Event(event) = input_type; diff --git a/src/common/screen.rs b/src/common/screen.rs index 89205f73..e902099c 100644 --- a/src/common/screen.rs +++ b/src/common/screen.rs @@ -13,7 +13,7 @@ use crate::tab::Tab; use crate::{errors::ErrorContext, wasm_vm::PluginInstruction}; use crate::{layout::Layout, panes::PaneId}; -use zellij_tile::data::{InputMode, TabInfo}; +use zellij_tile::data::{Event, InputMode, TabInfo}; /// Instructions that can be sent to the [`Screen`]. #[derive(Debug, Clone)] @@ -282,7 +282,7 @@ impl Screen { }); } self.send_plugin_instructions - .send(PluginInstruction::UpdateTabs(tab_data)) + .send(PluginInstruction::Update(None, Event::TabUpdate(tab_data))) .unwrap(); } diff --git a/src/common/wasm_vm.rs b/src/common/wasm_vm.rs index d6334e56..249ad9ca 100644 --- a/src/common/wasm_vm.rs +++ b/src/common/wasm_vm.rs @@ -6,7 +6,7 @@ use std::{ }; use wasmer::{imports, Function, ImportObject, Store, WasmerEnv}; use wasmer_wasi::WasiEnv; -use zellij_tile::data::{Event, EventType, TabInfo}; +use zellij_tile::data::{Event, EventType}; use super::{ pty_bus::PtyInstruction, screen::ScreenInstruction, AppInstruction, PaneId, SenderWithContext, @@ -29,7 +29,6 @@ pub enum PluginInstruction { Render(Sender, u32, usize, usize), // String buffer, plugin id, rows, cols Input(PluginInputType, Vec), // plugin id, input bytes Unload(u32), - UpdateTabs(Vec), // num tabs, active tab Quit, } diff --git a/zellij-tile/src/data.rs b/zellij-tile/src/data.rs index 67bf0d74..9576285a 100644 --- a/zellij-tile/src/data.rs +++ b/zellij-tile/src/data.rs @@ -28,7 +28,7 @@ pub enum Key { #[strum_discriminants(name(EventType))] pub enum Event { ModeUpdate(ModeInfo), - TabUpdate(TabInfo), + TabUpdate(Vec), KeyPress(Key), } diff --git a/zellij-tile/src/lib.rs b/zellij-tile/src/lib.rs index 771edb2d..cff3624d 100644 --- a/zellij-tile/src/lib.rs +++ b/zellij-tile/src/lib.rs @@ -10,7 +10,6 @@ pub trait ZellijTile { fn update(&mut self, event: Event) {} fn render(&mut self, rows: usize, cols: usize) {} // FIXME: Everything below this line should be purged - fn update_tabs(&mut self) {} fn handle_tab_rename_keypress(&mut self, key: Key) {} } @@ -43,13 +42,6 @@ macro_rules! register_tile { }); } - #[no_mangle] - pub fn update_tabs() { - STATE.with(|state| { - state.borrow_mut().update_tabs(); - }) - } - #[no_mangle] pub fn handle_tab_rename_keypress() { STATE.with(|state| { diff --git a/zellij-tile/src/shim.rs b/zellij-tile/src/shim.rs index bbdf5fcc..1bb8ccab 100644 --- a/zellij-tile/src/shim.rs +++ b/zellij-tile/src/shim.rs @@ -36,10 +36,6 @@ pub fn set_selectable(selectable: bool) { unsafe { host_set_selectable(selectable) }; } -pub fn get_tabs() -> Vec { - deserialize_from_stdin().unwrap_or_default() -} - #[doc(hidden)] // FIXME: Make this just return T and do a .unwrap() at the end; also naming? pub fn deserialize_from_stdin() -> Option { From b6f945da35065f0a0d3b384b4d0f167908c0140f Mon Sep 17 00:00:00 2001 From: Brooks J Rady Date: Thu, 25 Mar 2021 17:22:10 +0000 Subject: [PATCH 29/31] Wrap up the plugin system refactor, running everything through update() --- assets/layouts/default.yaml | 2 - assets/layouts/strider.yaml | 2 - default-tiles/tab-bar/src/main.rs | 44 ++------ src/client/layout.rs | 8 +- src/client/tab.rs | 169 ++++++++++++++---------------- src/common/errors.rs | 2 - src/common/input/actions.rs | 1 - src/common/input/handler.rs | 24 +---- src/common/input/keybinds.rs | 5 +- src/common/mod.rs | 80 +------------- src/common/os_input_output.rs | 13 +-- src/common/screen.rs | 17 +-- src/common/utils/consts.rs | 2 - src/common/wasm_vm.rs | 15 +-- zellij-tile/src/lib.rs | 15 +-- zellij-tile/src/shim.rs | 29 ++--- 16 files changed, 121 insertions(+), 307 deletions(-) diff --git a/assets/layouts/default.yaml b/assets/layouts/default.yaml index f46569b7..408f2f38 100644 --- a/assets/layouts/default.yaml +++ b/assets/layouts/default.yaml @@ -5,8 +5,6 @@ parts: split_size: Fixed: 1 plugin: tab-bar - events: - - Tab - direction: Vertical expansion_boundary: true - direction: Vertical diff --git a/assets/layouts/strider.yaml b/assets/layouts/strider.yaml index cd972d20..9d0f09b0 100644 --- a/assets/layouts/strider.yaml +++ b/assets/layouts/strider.yaml @@ -5,8 +5,6 @@ parts: split_size: Fixed: 1 plugin: tab-bar - events: - - Tab - direction: Vertical parts: - direction: Horizontal diff --git a/default-tiles/tab-bar/src/main.rs b/default-tiles/tab-bar/src/main.rs index 7f5e438d..4a1f2933 100644 --- a/default-tiles/tab-bar/src/main.rs +++ b/default-tiles/tab-bar/src/main.rs @@ -12,23 +12,10 @@ pub struct LinePart { len: usize, } -#[derive(PartialEq)] -enum BarMode { - Normal, - Rename, -} - -impl Default for BarMode { - fn default() -> Self { - BarMode::Normal - } -} - #[derive(Default)] struct State { tabs: Vec, - mode: BarMode, - new_name: String, + mode: InputMode, } static ARROW_SEPARATOR: &str = ""; @@ -51,12 +38,14 @@ impl ZellijTile for State { set_selectable(false); set_invisible_borders(true); set_max_height(1); - subscribe(&[EventType::TabUpdate]); + subscribe(&[EventType::TabUpdate, EventType::ModeUpdate]); } fn update(&mut self, event: Event) { - if let Event::TabUpdate(tabs) = event { - self.tabs = tabs; + match event { + Event::ModeUpdate(mode_info) => self.mode = mode_info.mode, + Event::TabUpdate(tabs) => self.tabs = tabs, + _ => unimplemented!(), // FIXME: This should be unreachable, but this could be cleaner } } @@ -68,11 +57,9 @@ impl ZellijTile for State { let mut active_tab_index = 0; for t in self.tabs.iter_mut() { let mut tabname = t.name.clone(); - if t.active && self.mode == BarMode::Rename { - if self.new_name.is_empty() { + if t.active && self.mode == InputMode::RenameTab { + if tabname.is_empty() { tabname = String::from("Enter name..."); - } else { - tabname = self.new_name.clone(); } active_tab_index = t.position; } else if t.active { @@ -88,19 +75,4 @@ impl ZellijTile for State { } println!("{}\u{1b}[48;5;238m\u{1b}[0K", s); } - - fn handle_tab_rename_keypress(&mut self, key: Key) { - self.mode = BarMode::Rename; - match key { - Key::Char('\n') | Key::Esc => { - self.mode = BarMode::Normal; - self.new_name.clear(); - } - Key::Char(c) => self.new_name = format!("{}{}", self.new_name, c), - Key::Backspace | Key::Delete => { - self.new_name.pop(); - } - _ => {} - } - } } diff --git a/src/client/layout.rs b/src/client/layout.rs index 33df2a2f..2d1daaf4 100644 --- a/src/client/layout.rs +++ b/src/client/layout.rs @@ -1,10 +1,8 @@ -use crate::utils::consts::ZELLIJ_ROOT_LAYOUT_DIR; use directories_next::ProjectDirs; use serde::{Deserialize, Serialize}; -use std::path::{Path, PathBuf}; +use std::path::PathBuf; use std::{fs::File, io::prelude::*}; -use crate::common::wasm_vm::NaughtyEventType; use crate::panes::PositionAndSize; fn split_space_to_parts_vertically( @@ -181,19 +179,15 @@ pub struct Layout { pub plugin: Option, #[serde(default)] pub expansion_boundary: bool, - #[serde(default, skip_serializing_if = "Vec::is_empty")] - pub events: Vec, } impl Layout { pub fn new(layout_path: PathBuf) -> Self { let project_dirs = ProjectDirs::from("org", "Zellij Contributors", "Zellij").unwrap(); let layout_dir = project_dirs.data_dir().join("layouts/"); - let root_layout_dir = Path::new(ZELLIJ_ROOT_LAYOUT_DIR); let mut layout_file = File::open(&layout_path) .or_else(|_| File::open(&layout_path.with_extension("yaml"))) .or_else(|_| File::open(&layout_dir.join(&layout_path).with_extension("yaml"))) - .or_else(|_| File::open(root_layout_dir.join(&layout_path).with_extension("yaml"))) .unwrap_or_else(|_| panic!("cannot find layout {}", &layout_path.display())); let mut layout = String::new(); diff --git a/src/client/tab.rs b/src/client/tab.rs index b74c2eb7..1e56fd8b 100644 --- a/src/client/tab.rs +++ b/src/client/tab.rs @@ -258,11 +258,7 @@ impl Tab { if let Some(plugin) = &layout.plugin { let (pid_tx, pid_rx) = channel(); self.send_plugin_instructions - .send(PluginInstruction::Load( - pid_tx, - plugin.clone(), - layout.events.clone(), - )) + .send(PluginInstruction::Load(pid_tx, plugin.clone())) .unwrap(); let pid = pid_rx.recv().unwrap(); let new_plugin = PluginPane::new( @@ -301,7 +297,6 @@ impl Tab { self.toggle_active_pane_fullscreen(); } if !self.has_panes() { - // FIXME: This could use a second look if let PaneId::Terminal(term_pid) = pid { let new_terminal = TerminalPane::new(term_pid, self.full_screen_ws); self.os_api.set_terminal_size_using_fd( @@ -352,7 +347,6 @@ impl Tab { if terminal_to_split.rows() * CURSOR_HEIGHT_WIDTH_RATIO > terminal_to_split.columns() && terminal_to_split.rows() > terminal_to_split.min_height() * 2 { - // FIXME: This could use a second look if let PaneId::Terminal(term_pid) = pid { let (top_winsize, bottom_winsize) = split_horizontally_with_gap(&terminal_ws); let new_terminal = TerminalPane::new(term_pid, bottom_winsize); @@ -373,7 +367,6 @@ impl Tab { self.active_terminal = Some(pid); } } else if terminal_to_split.columns() > terminal_to_split.min_width() * 2 { - // FIXME: This could use a second look if let PaneId::Terminal(term_pid) = pid { let (left_winsize, right_winsize) = split_vertically_with_gap(&terminal_ws); let new_terminal = TerminalPane::new(term_pid, right_winsize); @@ -403,7 +396,6 @@ impl Tab { self.toggle_active_pane_fullscreen(); } if !self.has_panes() { - // FIXME: This could use a second look if let PaneId::Terminal(term_pid) = pid { let new_terminal = TerminalPane::new(term_pid, self.full_screen_ws); self.os_api.set_terminal_size_using_fd( @@ -414,47 +406,44 @@ impl Tab { self.panes.insert(pid, Box::new(new_terminal)); self.active_terminal = Some(pid); } - } else { - // FIXME: This could use a second look - if let PaneId::Terminal(term_pid) = pid { - // TODO: check minimum size of active terminal - let active_pane_id = &self.get_active_pane_id().unwrap(); - let active_pane = self.panes.get_mut(active_pane_id).unwrap(); - if active_pane.rows() < MIN_TERMINAL_HEIGHT * 2 + 1 { - self.send_pty_instructions - .send(PtyInstruction::ClosePane(pid)) // we can't open this pane, close the pty - .unwrap(); - return; - } - let terminal_ws = PositionAndSize { - x: active_pane.x(), - y: active_pane.y(), - rows: active_pane.rows(), - columns: active_pane.columns(), - }; - let (top_winsize, bottom_winsize) = split_horizontally_with_gap(&terminal_ws); - - active_pane.change_pos_and_size(&top_winsize); - - let new_terminal = TerminalPane::new(term_pid, bottom_winsize); - self.os_api.set_terminal_size_using_fd( - new_terminal.pid, - bottom_winsize.columns as u16, - bottom_winsize.rows as u16, - ); - self.panes.insert(pid, Box::new(new_terminal)); - - if let PaneId::Terminal(active_terminal_pid) = active_pane_id { - self.os_api.set_terminal_size_using_fd( - *active_terminal_pid, - top_winsize.columns as u16, - top_winsize.rows as u16, - ); - } - - self.active_terminal = Some(pid); - self.render(); + } else if let PaneId::Terminal(term_pid) = pid { + // TODO: check minimum size of active terminal + let active_pane_id = &self.get_active_pane_id().unwrap(); + let active_pane = self.panes.get_mut(active_pane_id).unwrap(); + if active_pane.rows() < MIN_TERMINAL_HEIGHT * 2 + 1 { + self.send_pty_instructions + .send(PtyInstruction::ClosePane(pid)) // we can't open this pane, close the pty + .unwrap(); + return; } + let terminal_ws = PositionAndSize { + x: active_pane.x(), + y: active_pane.y(), + rows: active_pane.rows(), + columns: active_pane.columns(), + }; + let (top_winsize, bottom_winsize) = split_horizontally_with_gap(&terminal_ws); + + active_pane.change_pos_and_size(&top_winsize); + + let new_terminal = TerminalPane::new(term_pid, bottom_winsize); + self.os_api.set_terminal_size_using_fd( + new_terminal.pid, + bottom_winsize.columns as u16, + bottom_winsize.rows as u16, + ); + self.panes.insert(pid, Box::new(new_terminal)); + + if let PaneId::Terminal(active_terminal_pid) = active_pane_id { + self.os_api.set_terminal_size_using_fd( + *active_terminal_pid, + top_winsize.columns as u16, + top_winsize.rows as u16, + ); + } + + self.active_terminal = Some(pid); + self.render(); } } pub fn vertical_split(&mut self, pid: PaneId) { @@ -463,7 +452,6 @@ impl Tab { self.toggle_active_pane_fullscreen(); } if !self.has_panes() { - // FIXME: This could use a second look if let PaneId::Terminal(term_pid) = pid { let new_terminal = TerminalPane::new(term_pid, self.full_screen_ws); self.os_api.set_terminal_size_using_fd( @@ -474,47 +462,44 @@ impl Tab { self.panes.insert(pid, Box::new(new_terminal)); self.active_terminal = Some(pid); } - } else { - // FIXME: This could use a second look - if let PaneId::Terminal(term_pid) = pid { - // TODO: check minimum size of active terminal - let active_pane_id = &self.get_active_pane_id().unwrap(); - let active_pane = self.panes.get_mut(active_pane_id).unwrap(); - if active_pane.columns() < MIN_TERMINAL_WIDTH * 2 + 1 { - self.send_pty_instructions - .send(PtyInstruction::ClosePane(pid)) // we can't open this pane, close the pty - .unwrap(); - return; - } - let terminal_ws = PositionAndSize { - x: active_pane.x(), - y: active_pane.y(), - rows: active_pane.rows(), - columns: active_pane.columns(), - }; - let (left_winsize, right_winsize) = split_vertically_with_gap(&terminal_ws); - - active_pane.change_pos_and_size(&left_winsize); - - let new_terminal = TerminalPane::new(term_pid, right_winsize); - self.os_api.set_terminal_size_using_fd( - new_terminal.pid, - right_winsize.columns as u16, - right_winsize.rows as u16, - ); - self.panes.insert(pid, Box::new(new_terminal)); - - if let PaneId::Terminal(active_terminal_pid) = active_pane_id { - self.os_api.set_terminal_size_using_fd( - *active_terminal_pid, - left_winsize.columns as u16, - left_winsize.rows as u16, - ); - } - - self.active_terminal = Some(pid); - self.render(); + } else if let PaneId::Terminal(term_pid) = pid { + // TODO: check minimum size of active terminal + let active_pane_id = &self.get_active_pane_id().unwrap(); + let active_pane = self.panes.get_mut(active_pane_id).unwrap(); + if active_pane.columns() < MIN_TERMINAL_WIDTH * 2 + 1 { + self.send_pty_instructions + .send(PtyInstruction::ClosePane(pid)) // we can't open this pane, close the pty + .unwrap(); + return; } + let terminal_ws = PositionAndSize { + x: active_pane.x(), + y: active_pane.y(), + rows: active_pane.rows(), + columns: active_pane.columns(), + }; + let (left_winsize, right_winsize) = split_vertically_with_gap(&terminal_ws); + + active_pane.change_pos_and_size(&left_winsize); + + let new_terminal = TerminalPane::new(term_pid, right_winsize); + self.os_api.set_terminal_size_using_fd( + new_terminal.pid, + right_winsize.columns as u16, + right_winsize.rows as u16, + ); + self.panes.insert(pid, Box::new(new_terminal)); + + if let PaneId::Terminal(active_terminal_pid) = active_pane_id { + self.os_api.set_terminal_size_using_fd( + *active_terminal_pid, + left_winsize.columns as u16, + left_winsize.rows as u16, + ); + } + + self.active_terminal = Some(pid); + self.render(); } } pub fn get_active_pane(&self) -> Option<&dyn Pane> { @@ -1680,6 +1665,7 @@ impl Tab { self.reduce_pane_and_surroundings_right(&active_pane_id, count); } } + self.render(); } pub fn resize_left(&mut self) { // TODO: find out by how much we actually reduced and only reduce by that much @@ -1691,6 +1677,7 @@ impl Tab { self.reduce_pane_and_surroundings_left(&active_pane_id, count); } } + self.render(); } pub fn resize_down(&mut self) { // TODO: find out by how much we actually reduced and only reduce by that much @@ -1702,6 +1689,7 @@ impl Tab { self.reduce_pane_and_surroundings_down(&active_pane_id, count); } } + self.render(); } pub fn resize_up(&mut self) { // TODO: find out by how much we actually reduced and only reduce by that much @@ -1713,6 +1701,7 @@ impl Tab { self.reduce_pane_and_surroundings_up(&active_pane_id, count); } } + self.render(); } pub fn move_focus(&mut self) { if !self.has_selectable_panes() { diff --git a/src/common/errors.rs b/src/common/errors.rs index 83860a59..f5aeae85 100644 --- a/src/common/errors.rs +++ b/src/common/errors.rs @@ -282,7 +282,6 @@ pub enum PluginContext { Load, Update, Render, - Input, Unload, Quit, } @@ -293,7 +292,6 @@ impl From<&PluginInstruction> for PluginContext { PluginInstruction::Load(..) => PluginContext::Load, PluginInstruction::Update(..) => PluginContext::Update, PluginInstruction::Render(..) => PluginContext::Render, - PluginInstruction::Input(..) => PluginContext::Input, PluginInstruction::Unload(_) => PluginContext::Unload, PluginInstruction::Quit => PluginContext::Quit, } diff --git a/src/common/input/actions.rs b/src/common/input/actions.rs index 059255d3..f4226864 100644 --- a/src/common/input/actions.rs +++ b/src/common/input/actions.rs @@ -49,5 +49,4 @@ pub enum Action { CloseTab, GoToTab(u32), TabNameInput(Vec), - SaveTabName, } diff --git a/src/common/input/handler.rs b/src/common/input/handler.rs index 3444471a..33f4e5dc 100644 --- a/src/common/input/handler.rs +++ b/src/common/input/handler.rs @@ -7,7 +7,7 @@ use crate::errors::ContextType; use crate::os_input_output::OsApi; use crate::pty_bus::PtyInstruction; use crate::screen::ScreenInstruction; -use crate::wasm_vm::{NaughtyEventType, PluginInputType, PluginInstruction}; +use crate::wasm_vm::PluginInstruction; use crate::CommandIsExecuting; use termion::input::{TermRead, TermReadEventsAndRaw}; @@ -66,11 +66,6 @@ impl InputHandler { Ok((event, raw_bytes)) => match event { termion::event::Event::Key(key) => { let key = cast_termion_key(key); - // FIXME: This is a bit of a hack to get resizing to work! - drop( - self.send_screen_instructions - .send(ScreenInstruction::Render), - ); // FIXME this explicit break is needed because the current test // framework relies on it to not create dead threads that loop // and eat up CPUs. Do not remove until the test framework has @@ -237,27 +232,10 @@ impl InputHandler { .unwrap(); } Action::TabNameInput(c) => { - self.send_plugin_instructions - .send(PluginInstruction::Input( - PluginInputType::Event(NaughtyEventType::Tab), - c.clone(), - )) - .unwrap(); self.send_screen_instructions .send(ScreenInstruction::UpdateTabName(c)) .unwrap(); } - Action::SaveTabName => { - self.send_plugin_instructions - .send(PluginInstruction::Input( - PluginInputType::Event(NaughtyEventType::Tab), - vec![b'\n'], - )) - .unwrap(); - self.send_screen_instructions - .send(ScreenInstruction::UpdateTabName(vec![b'\n'])) - .unwrap(); - } Action::NoOp => {} } diff --git a/src/common/input/keybinds.rs b/src/common/input/keybinds.rs index e48d3115..7b1e8779 100644 --- a/src/common/input/keybinds.rs +++ b/src/common/input/keybinds.rs @@ -226,10 +226,7 @@ fn get_defaults_for_mode(mode: &InputMode) -> ModeKeybinds { defaults.insert(Key::Up, vec![Action::ScrollUp]); } InputMode::RenameTab => { - defaults.insert( - Key::Char('\n'), - vec![Action::SaveTabName, Action::SwitchToMode(InputMode::Tab)], - ); + defaults.insert(Key::Char('\n'), vec![Action::SwitchToMode(InputMode::Tab)]); defaults.insert( Key::Ctrl('g'), vec![Action::SwitchToMode(InputMode::Normal)], diff --git a/src/common/mod.rs b/src/common/mod.rs index 15a28d96..e895fcc0 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -10,7 +10,7 @@ pub mod utils; pub mod wasm_vm; use std::cell::RefCell; -use std::path::{Path, PathBuf}; +use std::path::PathBuf; use std::sync::mpsc; use std::thread; use std::{collections::HashMap, fs}; @@ -32,16 +32,12 @@ use os_input_output::OsApi; use pty_bus::{PtyBus, PtyInstruction}; use screen::{Screen, ScreenInstruction}; use serde::{Deserialize, Serialize}; -use termion::input::TermRead; -use utils::consts::{ZELLIJ_IPC_PIPE, ZELLIJ_ROOT_PLUGIN_DIR}; +use utils::consts::ZELLIJ_IPC_PIPE; use wasm_vm::PluginEnv; -use wasm_vm::{ - wasi_stdout, wasi_write_string, zellij_imports, NaughtyEventType, PluginInputType, - PluginInstruction, -}; +use wasm_vm::{wasi_stdout, wasi_write_string, zellij_imports, PluginInstruction}; use wasmer::{ChainableNamedResolver, Instance, Module, Store, Value}; use wasmer_wasi::{Pipe, WasiState}; -use zellij_tile::data::{EventType, InputMode, Key}; +use zellij_tile::data::{EventType, InputMode}; #[derive(Serialize, Deserialize, Debug)] pub enum ApiCommand { @@ -352,8 +348,6 @@ pub fn start(mut os_input: Box, opts: CliArgs) { .get_active_tab_mut() .unwrap() .set_pane_selectable(id, selectable); - // FIXME: Is this needed? - screen.render(); } ScreenInstruction::SetMaxHeight(id, max_height) => { screen @@ -417,42 +411,7 @@ pub fn start(mut os_input: Box, opts: CliArgs) { let store = Store::default(); let mut plugin_id = 0; let mut plugin_map = HashMap::new(); - let handler_map: HashMap = [( - NaughtyEventType::Tab, - "handle_tab_rename_keypress".to_string(), - )] - .iter() - .cloned() - .collect(); - move || loop { - // FIXME: This 100% *must* be destroyed before this makes in into main!!!!!!!!!!! - fn cast_termion_key(event: termion::event::Key) -> Key { - match event { - termion::event::Key::Backspace => Key::Backspace, - termion::event::Key::Left => Key::Left, - termion::event::Key::Right => Key::Right, - termion::event::Key::Up => Key::Up, - termion::event::Key::Down => Key::Down, - termion::event::Key::Home => Key::Home, - termion::event::Key::End => Key::End, - termion::event::Key::PageUp => Key::PageUp, - termion::event::Key::PageDown => Key::PageDown, - termion::event::Key::BackTab => Key::BackTab, - termion::event::Key::Delete => Key::Delete, - termion::event::Key::Insert => Key::Insert, - termion::event::Key::F(n) => Key::F(n), - termion::event::Key::Char(c) => Key::Char(c), - termion::event::Key::Alt(c) => Key::Alt(c), - termion::event::Key::Ctrl(c) => Key::Ctrl(c), - termion::event::Key::Null => Key::Null, - termion::event::Key::Esc => Key::Esc, - _ => { - unimplemented!("Encountered an unknown key!") - } - } - } - let (event, mut err_ctx) = receive_plugin_instructions .recv() .expect("failed to receive event on channel"); @@ -461,18 +420,13 @@ pub fn start(mut os_input: Box, opts: CliArgs) { send_pty_instructions.update(err_ctx); send_app_instructions.update(err_ctx); match event { - PluginInstruction::Load(pid_tx, path, events) => { + PluginInstruction::Load(pid_tx, path) => { let project_dirs = ProjectDirs::from("org", "Zellij Contributors", "Zellij").unwrap(); let plugin_dir = project_dirs.data_dir().join("plugins/"); - // FIXME: This really shouldn't need to exist anymore, let's get rid of it! - let root_plugin_dir = Path::new(ZELLIJ_ROOT_PLUGIN_DIR); let wasm_bytes = fs::read(&path) .or_else(|_| fs::read(&path.with_extension("wasm"))) .or_else(|_| fs::read(&plugin_dir.join(&path).with_extension("wasm"))) - .or_else(|_| { - fs::read(&root_plugin_dir.join(&path).with_extension("wasm")) - }) .unwrap_or_else(|_| panic!("cannot find plugin {}", &path.display())); // FIXME: Cache this compiled module on disk. I could use `(de)serialize_to_file()` for that @@ -504,7 +458,6 @@ pub fn start(mut os_input: Box, opts: CliArgs) { send_app_instructions: send_app_instructions.clone(), wasi_env, subscriptions: Arc::new(Mutex::new(HashSet::new())), - events, }; let zellij = zellij_imports(&store, &plugin_env); @@ -546,29 +499,6 @@ pub fn start(mut os_input: Box, opts: CliArgs) { buf_tx.send(wasi_stdout(&plugin_env.wasi_env)).unwrap(); } - // FIXME: Deduplicate this with the callback below! - PluginInstruction::Input(input_type, input_bytes) => { - let PluginInputType::Event(event) = input_type; - for (instance, plugin_env) in plugin_map.values() { - if !plugin_env.events.contains(&event) { - continue; - } - let handle_key = instance - .exports - .get_function(handler_map.get(&event).unwrap()) - .unwrap(); - for key in input_bytes.keys().flatten() { - let key = cast_termion_key(key); - wasi_write_string( - &plugin_env.wasi_env, - &serde_json::to_string(&key).unwrap(), - ); - handle_key.call(&[]).unwrap(); - } - } - - drop(send_screen_instructions.send(ScreenInstruction::Render)); - } PluginInstruction::Unload(pid) => drop(plugin_map.remove(&pid)), PluginInstruction::Quit => break, } diff --git a/src/common/os_input_output.rs b/src/common/os_input_output.rs index 26a7d497..043a9aea 100644 --- a/src/common/os_input_output.rs +++ b/src/common/os_input_output.rs @@ -82,15 +82,10 @@ fn handle_command_exit(mut child: Child) { } for signal in signals.pending() { - // FIXME: We need to handle more signals here! - #[allow(clippy::single_match)] - match signal { - signal_hook::SIGINT => { - child.kill().unwrap(); - child.wait().unwrap(); - break 'handle_exit; - } - _ => {} + if signal == signal_hook::SIGINT { + child.kill().unwrap(); + child.wait().unwrap(); + break 'handle_exit; } } } diff --git a/src/common/screen.rs b/src/common/screen.rs index e902099c..5208834a 100644 --- a/src/common/screen.rs +++ b/src/common/screen.rs @@ -74,7 +74,6 @@ pub struct Screen { active_tab_index: Option, /// The [`OsApi`] this [`Screen`] uses. os_api: Box, - tabname_buf: String, input_mode: InputMode, } @@ -100,7 +99,6 @@ impl Screen { active_tab_index: None, tabs: BTreeMap::new(), os_api, - tabname_buf: String::new(), input_mode, } } @@ -288,25 +286,20 @@ impl Screen { pub fn update_active_tab_name(&mut self, buf: Vec) { let s = str::from_utf8(&buf).unwrap(); + let active_tab = self.get_active_tab_mut().unwrap(); match s { "\0" => { - self.tabname_buf = String::new(); - } - "\n" => { - let new_name = self.tabname_buf.clone(); - let active_tab = self.get_active_tab_mut().unwrap(); - active_tab.name = new_name; - self.update_tabs(); - self.render(); + active_tab.name = String::new(); } "\u{007F}" | "\u{0008}" => { //delete and backspace keys - self.tabname_buf.pop(); + active_tab.name.pop(); } c => { - self.tabname_buf.push_str(c); + active_tab.name.push_str(c); } } + self.update_tabs(); } pub fn change_input_mode(&mut self, input_mode: InputMode) { self.input_mode = input_mode; diff --git a/src/common/utils/consts.rs b/src/common/utils/consts.rs index fa9eee0d..663a545d 100644 --- a/src/common/utils/consts.rs +++ b/src/common/utils/consts.rs @@ -4,5 +4,3 @@ pub const ZELLIJ_TMP_DIR: &str = "/tmp/zellij"; pub const ZELLIJ_TMP_LOG_DIR: &str = "/tmp/zellij/zellij-log"; pub const ZELLIJ_TMP_LOG_FILE: &str = "/tmp/zellij/zellij-log/log.txt"; pub const ZELLIJ_IPC_PIPE: &str = "/tmp/zellij/ipc"; -pub const ZELLIJ_ROOT_PLUGIN_DIR: &str = "/usr/share/zellij/plugins"; -pub const ZELLIJ_ROOT_LAYOUT_DIR: &str = "/usr/share/zellij/layouts"; diff --git a/src/common/wasm_vm.rs b/src/common/wasm_vm.rs index 249ad9ca..29b110ae 100644 --- a/src/common/wasm_vm.rs +++ b/src/common/wasm_vm.rs @@ -1,4 +1,3 @@ -use serde::{Deserialize, Serialize}; use std::{ collections::HashSet, path::PathBuf, @@ -12,22 +11,11 @@ use super::{ pty_bus::PtyInstruction, screen::ScreenInstruction, AppInstruction, PaneId, SenderWithContext, }; -#[derive(Clone, Debug, PartialEq, Hash, Eq, Serialize, Deserialize)] -pub enum NaughtyEventType { - Tab, -} - -#[derive(Clone, Debug)] -pub enum PluginInputType { - Event(NaughtyEventType), -} - #[derive(Clone, Debug)] pub enum PluginInstruction { - Load(Sender, PathBuf, Vec), + Load(Sender, PathBuf), Update(Option, Event), // Focused plugin / broadcast, event data Render(Sender, u32, usize, usize), // String buffer, plugin id, rows, cols - Input(PluginInputType, Vec), // plugin id, input bytes Unload(u32), Quit, } @@ -40,7 +28,6 @@ pub struct PluginEnv { pub send_pty_instructions: SenderWithContext, // FIXME: This should be a big bundle of all of the channels pub wasi_env: WasiEnv, pub subscriptions: Arc>>, - pub events: Vec, // FIXME: Murder this very soon (should not survive into main) } // Plugin API --------------------------------------------------------------------------------------------------------- diff --git a/zellij-tile/src/lib.rs b/zellij-tile/src/lib.rs index cff3624d..72211764 100644 --- a/zellij-tile/src/lib.rs +++ b/zellij-tile/src/lib.rs @@ -9,8 +9,6 @@ pub trait ZellijTile { fn load(&mut self) {} fn update(&mut self, event: Event) {} fn render(&mut self, rows: usize, cols: usize) {} - // FIXME: Everything below this line should be purged - fn handle_tab_rename_keypress(&mut self, key: Key) {} } #[macro_export] @@ -29,9 +27,7 @@ macro_rules! register_tile { #[no_mangle] pub fn update() { STATE.with(|state| { - state - .borrow_mut() - .update($crate::shim::deserialize_from_stdin().unwrap()); + state.borrow_mut().update($crate::shim::object_from_stdin()); }); } @@ -41,14 +37,5 @@ macro_rules! register_tile { state.borrow_mut().render(rows as usize, cols as usize); }); } - - #[no_mangle] - pub fn handle_tab_rename_keypress() { - STATE.with(|state| { - state - .borrow_mut() - .handle_tab_rename_keypress($crate::shim::get_key()); - }) - } }; } diff --git a/zellij-tile/src/shim.rs b/zellij-tile/src/shim.rs index 1bb8ccab..42a646a1 100644 --- a/zellij-tile/src/shim.rs +++ b/zellij-tile/src/shim.rs @@ -3,9 +3,7 @@ use std::{io, path::Path}; use crate::data::*; -pub fn get_key() -> Key { - deserialize_from_stdin().unwrap() -} +// Subscription Handling pub fn subscribe(event_types: &[EventType]) { println!("{}", serde_json::to_string(event_types).unwrap()); @@ -17,31 +15,34 @@ pub fn unsubscribe(event_types: &[EventType]) { unsafe { host_unsubscribe() }; } -pub fn open_file(path: &Path) { - println!("{}", path.to_string_lossy()); - unsafe { host_open_file() }; -} +// Plugin Settings pub fn set_max_height(max_height: i32) { unsafe { host_set_max_height(max_height) }; } pub fn set_invisible_borders(invisible_borders: bool) { - let invisible_borders = if invisible_borders { 1 } else { 0 }; - unsafe { host_set_invisible_borders(invisible_borders) }; + unsafe { host_set_invisible_borders(if invisible_borders { 1 } else { 0 }) }; } pub fn set_selectable(selectable: bool) { - let selectable = if selectable { 1 } else { 0 }; - unsafe { host_set_selectable(selectable) }; + unsafe { host_set_selectable(if selectable { 1 } else { 0 }) }; } +// Host Functions + +pub fn open_file(path: &Path) { + println!("{}", path.to_string_lossy()); + unsafe { host_open_file() }; +} + +// Internal Functions + #[doc(hidden)] -// FIXME: Make this just return T and do a .unwrap() at the end; also naming? -pub fn deserialize_from_stdin() -> Option { +pub fn object_from_stdin() -> T { let mut json = String::new(); io::stdin().read_line(&mut json).unwrap(); - serde_json::from_str(&json).ok() + serde_json::from_str(&json).unwrap() } #[link(wasm_import_module = "zellij")] From 6316763b0e0fab4753e781bf612f228fb43428a9 Mon Sep 17 00:00:00 2001 From: Brooks J Rady Date: Thu, 25 Mar 2021 17:41:02 +0000 Subject: [PATCH 30/31] Fixing a load of clippy lints in status-bar --- default-tiles/status-bar/src/first_line.rs | 116 +++++++------------- default-tiles/status-bar/src/second_line.rs | 8 +- default-tiles/tab-bar/src/line.rs | 2 +- 3 files changed, 45 insertions(+), 81 deletions(-) diff --git a/default-tiles/status-bar/src/first_line.rs b/default-tiles/status-bar/src/first_line.rs index 20603df1..41fe5729 100644 --- a/default-tiles/status-bar/src/first_line.rs +++ b/default-tiles/status-bar/src/first_line.rs @@ -70,90 +70,64 @@ fn unselected_mode_shortcut(letter: char, text: &str) -> LinePart { .fg(BLACK) .on(BRIGHT_GRAY) .bold() - .paint(format!(" <")); + .paint(" <"); let char_shortcut = Style::new() .bold() .fg(RED) .on(BRIGHT_GRAY) .bold() - .paint(format!("{}", letter)); + .paint(letter.to_string()); let char_right_separator = Style::new() .bold() .fg(BLACK) .on(BRIGHT_GRAY) .bold() - .paint(format!(">")); - let styled_text = Style::new() - .fg(BLACK) - .on(BRIGHT_GRAY) - .bold() - .paint(format!("{} ", text)); + .paint(">"); + let styled_text = Style::new().fg(BLACK).on(BRIGHT_GRAY).bold().paint(text); let suffix_separator = Style::new().fg(BRIGHT_GRAY).on(GRAY).paint(ARROW_SEPARATOR); LinePart { - part: format!( - "{}", - ANSIStrings(&[ - prefix_separator, - char_left_separator, - char_shortcut, - char_right_separator, - styled_text, - suffix_separator - ]) - ), + part: ANSIStrings(&[ + prefix_separator, + char_left_separator, + char_shortcut, + char_right_separator, + styled_text, + suffix_separator, + ]) + .to_string(), len: text.chars().count() + 6, // 2 for the arrows, 3 for the char separators, 1 for the character } } fn selected_mode_shortcut(letter: char, text: &str) -> LinePart { let prefix_separator = Style::new().fg(GRAY).on(GREEN).paint(ARROW_SEPARATOR); - let char_left_separator = Style::new() - .bold() - .fg(BLACK) - .on(GREEN) - .bold() - .paint(format!(" <")); + let char_left_separator = Style::new().bold().fg(BLACK).on(GREEN).bold().paint(" <"); let char_shortcut = Style::new() .bold() .fg(RED) .on(GREEN) .bold() - .paint(format!("{}", letter)); - let char_right_separator = Style::new() - .bold() - .fg(BLACK) - .on(GREEN) - .bold() - .paint(format!(">")); - let styled_text = Style::new() - .fg(BLACK) - .on(GREEN) - .bold() - .paint(format!("{} ", text)); + .paint(letter.to_string()); + let char_right_separator = Style::new().bold().fg(BLACK).on(GREEN).bold().paint(">"); + let styled_text = Style::new().fg(BLACK).on(GREEN).bold().paint(text); let suffix_separator = Style::new().fg(GREEN).on(GRAY).paint(ARROW_SEPARATOR); LinePart { - part: format!( - "{}", - ANSIStrings(&[ - prefix_separator, - char_left_separator, - char_shortcut, - char_right_separator, - styled_text, - suffix_separator - ]) - ), + part: ANSIStrings(&[ + prefix_separator, + char_left_separator, + char_shortcut, + char_right_separator, + styled_text, + suffix_separator, + ]) + .to_string(), len: text.chars().count() + 6, // 2 for the arrows, 3 for the char separators, 1 for the character } } fn disabled_mode_shortcut(text: &str) -> LinePart { let prefix_separator = Style::new().fg(GRAY).on(BRIGHT_GRAY).paint(ARROW_SEPARATOR); - let styled_text = Style::new() - .fg(GRAY) - .on(BRIGHT_GRAY) - .dimmed() - .paint(format!("{} ", text)); + let styled_text = Style::new().fg(GRAY).on(BRIGHT_GRAY).dimmed().paint(text); let suffix_separator = Style::new().fg(BRIGHT_GRAY).on(GRAY).paint(ARROW_SEPARATOR); LinePart { part: format!("{}{}{}", prefix_separator, styled_text, suffix_separator), @@ -162,7 +136,7 @@ fn disabled_mode_shortcut(text: &str) -> LinePart { } fn selected_mode_shortcut_single_letter(letter: char) -> LinePart { - let char_shortcut_text = format!(" {} ", letter); + let char_shortcut_text = letter.to_string(); let len = char_shortcut_text.chars().count() + 4; // 2 for the arrows, 2 for the padding let prefix_separator = Style::new().fg(GRAY).on(GREEN).paint(ARROW_SEPARATOR); let char_shortcut = Style::new() @@ -173,16 +147,13 @@ fn selected_mode_shortcut_single_letter(letter: char) -> LinePart { .paint(char_shortcut_text); let suffix_separator = Style::new().fg(GREEN).on(GRAY).paint(ARROW_SEPARATOR); LinePart { - part: format!( - "{}", - ANSIStrings(&[prefix_separator, char_shortcut, suffix_separator]) - ), + part: ANSIStrings(&[prefix_separator, char_shortcut, suffix_separator]).to_string(), len, } } fn unselected_mode_shortcut_single_letter(letter: char) -> LinePart { - let char_shortcut_text = format!(" {} ", letter); + let char_shortcut_text = letter.to_string(); let len = char_shortcut_text.chars().count() + 4; // 2 for the arrows, 2 for the padding let prefix_separator = Style::new().fg(GRAY).on(BRIGHT_GRAY).paint(ARROW_SEPARATOR); let char_shortcut = Style::new() @@ -193,10 +164,7 @@ fn unselected_mode_shortcut_single_letter(letter: char) -> LinePart { .paint(char_shortcut_text); let suffix_separator = Style::new().fg(BRIGHT_GRAY).on(GRAY).paint(ARROW_SEPARATOR); LinePart { - part: format!( - "{}", - ANSIStrings(&[prefix_separator, char_shortcut, suffix_separator]) - ), + part: ANSIStrings(&[prefix_separator, char_shortcut, suffix_separator]).to_string(), len, } } @@ -225,12 +193,8 @@ fn shortened_ctrl_key(key: &CtrlKeyShortcut) -> LinePart { _ => shortened_text, }; match key.mode { - CtrlKeyMode::Unselected => { - unselected_mode_shortcut(letter_shortcut, &format!("{}", shortened_text)) - } - CtrlKeyMode::Selected => { - selected_mode_shortcut(letter_shortcut, &format!("{}", shortened_text)) - } + CtrlKeyMode::Unselected => unselected_mode_shortcut(letter_shortcut, &shortened_text), + CtrlKeyMode::Selected => selected_mode_shortcut(letter_shortcut, &shortened_text), CtrlKeyMode::Disabled => { disabled_mode_shortcut(&format!(" <{}>{}", letter_shortcut, shortened_text)) } @@ -282,7 +246,7 @@ pub fn superkey() -> LinePart { let prefix_text = " Ctrl + "; let prefix = Style::new().fg(WHITE).on(GRAY).bold().paint(prefix_text); LinePart { - part: format!("{}", prefix), + part: prefix.to_string(), len: prefix_text.chars().count(), } } @@ -291,7 +255,7 @@ pub fn ctrl_keys(help: &ModeInfo, max_len: usize) -> LinePart { match &help.mode { InputMode::Locked => key_indicators( max_len, - &vec![ + &[ CtrlKeyShortcut::new(CtrlKeyMode::Selected, CtrlKeyAction::Lock), CtrlKeyShortcut::new(CtrlKeyMode::Disabled, CtrlKeyAction::Pane), CtrlKeyShortcut::new(CtrlKeyMode::Disabled, CtrlKeyAction::Tab), @@ -302,7 +266,7 @@ pub fn ctrl_keys(help: &ModeInfo, max_len: usize) -> LinePart { ), InputMode::Resize => key_indicators( max_len, - &vec![ + &[ CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Lock), CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Pane), CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Tab), @@ -313,7 +277,7 @@ pub fn ctrl_keys(help: &ModeInfo, max_len: usize) -> LinePart { ), InputMode::Pane => key_indicators( max_len, - &vec![ + &[ CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Lock), CtrlKeyShortcut::new(CtrlKeyMode::Selected, CtrlKeyAction::Pane), CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Tab), @@ -324,7 +288,7 @@ pub fn ctrl_keys(help: &ModeInfo, max_len: usize) -> LinePart { ), InputMode::Tab | InputMode::RenameTab => key_indicators( max_len, - &vec![ + &[ CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Lock), CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Pane), CtrlKeyShortcut::new(CtrlKeyMode::Selected, CtrlKeyAction::Tab), @@ -335,7 +299,7 @@ pub fn ctrl_keys(help: &ModeInfo, max_len: usize) -> LinePart { ), InputMode::Scroll => key_indicators( max_len, - &vec![ + &[ CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Lock), CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Pane), CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Tab), @@ -346,7 +310,7 @@ pub fn ctrl_keys(help: &ModeInfo, max_len: usize) -> LinePart { ), InputMode::Normal => key_indicators( max_len, - &vec![ + &[ CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Lock), CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Pane), CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Tab), diff --git a/default-tiles/status-bar/src/second_line.rs b/default-tiles/status-bar/src/second_line.rs index 322f4333..ebcb93dd 100644 --- a/default-tiles/status-bar/src/second_line.rs +++ b/default-tiles/status-bar/src/second_line.rs @@ -108,7 +108,7 @@ fn full_shortcut_list(help: &ModeInfo) -> LinePart { line_part.len += shortcut.len; line_part.part = format!("{}{}", line_part.part, shortcut,); } - let select_pane_shortcut = select_pane_shortcut(help.keybinds.len() == 0); + let select_pane_shortcut = select_pane_shortcut(help.keybinds.is_empty()); line_part.len += select_pane_shortcut.len; line_part.part = format!("{}{}", line_part.part, select_pane_shortcut,); line_part @@ -127,7 +127,7 @@ fn shortened_shortcut_list(help: &ModeInfo) -> LinePart { line_part.len += shortcut.len; line_part.part = format!("{}{}", line_part.part, shortcut,); } - let select_pane_shortcut = select_pane_shortcut(help.keybinds.len() == 0); + let select_pane_shortcut = select_pane_shortcut(help.keybinds.is_empty()); line_part.len += select_pane_shortcut.len; line_part.part = format!("{}{}", line_part.part, select_pane_shortcut,); line_part @@ -159,7 +159,7 @@ fn best_effort_shortcut_list(help: &ModeInfo, max_len: usize) -> LinePart { line_part.len += shortcut.len; line_part.part = format!("{}{}", line_part.part, shortcut,); } - let select_pane_shortcut = select_pane_shortcut(help.keybinds.len() == 0); + let select_pane_shortcut = select_pane_shortcut(help.keybinds.is_empty()); if line_part.len + select_pane_shortcut.len <= max_len { line_part.len += select_pane_shortcut.len; line_part.part = format!("{}{}", line_part.part, select_pane_shortcut,); @@ -178,5 +178,5 @@ pub fn keybinds(help: &ModeInfo, max_width: usize) -> LinePart { if shortened_shortcut_list.len <= max_width { return shortened_shortcut_list; } - return best_effort_shortcut_list(help, max_width); + best_effort_shortcut_list(help, max_width) } diff --git a/default-tiles/tab-bar/src/line.rs b/default-tiles/tab-bar/src/line.rs index 124eab67..1d1c33ec 100644 --- a/default-tiles/tab-bar/src/line.rs +++ b/default-tiles/tab-bar/src/line.rs @@ -130,7 +130,7 @@ fn add_next_tabs_msg( } fn tab_line_prefix() -> LinePart { - let prefix_text = format!(" Zellij "); + let prefix_text = " Zellij ".to_string(); let prefix_text_len = prefix_text.chars().count(); let prefix_styled_text = Style::new().fg(WHITE).on(GRAY).bold().paint(prefix_text); LinePart { From c71252f77eed82140765a370fabb206a9960c092 Mon Sep 17 00:00:00 2001 From: Brooks J Rady Date: Fri, 26 Mar 2021 13:02:31 +0000 Subject: [PATCH 31/31] Fix some overzealous format!() removals and a stray comment --- Cargo.toml | 1 - default-tiles/status-bar/src/first_line.rs | 22 +++++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d83100ff..776eb3e9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,6 @@ serde_yaml = "0.8" signal-hook = "0.1.10" strip-ansi-escapes = "0.1.0" structopt = "0.3" -# termion = { git = "https://gitlab.com/TheLostLambda/termion.git", version = "1.6.0", features = ["serde"] } termion = "1.5.0" termios = "0.3" unicode-truncate = "0.2.0" diff --git a/default-tiles/status-bar/src/first_line.rs b/default-tiles/status-bar/src/first_line.rs index 41fe5729..0e4ec53b 100644 --- a/default-tiles/status-bar/src/first_line.rs +++ b/default-tiles/status-bar/src/first_line.rs @@ -83,7 +83,11 @@ fn unselected_mode_shortcut(letter: char, text: &str) -> LinePart { .on(BRIGHT_GRAY) .bold() .paint(">"); - let styled_text = Style::new().fg(BLACK).on(BRIGHT_GRAY).bold().paint(text); + let styled_text = Style::new() + .fg(BLACK) + .on(BRIGHT_GRAY) + .bold() + .paint(format!("{} ", text)); let suffix_separator = Style::new().fg(BRIGHT_GRAY).on(GRAY).paint(ARROW_SEPARATOR); LinePart { part: ANSIStrings(&[ @@ -109,7 +113,11 @@ fn selected_mode_shortcut(letter: char, text: &str) -> LinePart { .bold() .paint(letter.to_string()); let char_right_separator = Style::new().bold().fg(BLACK).on(GREEN).bold().paint(">"); - let styled_text = Style::new().fg(BLACK).on(GREEN).bold().paint(text); + let styled_text = Style::new() + .fg(BLACK) + .on(GREEN) + .bold() + .paint(format!("{} ", text)); let suffix_separator = Style::new().fg(GREEN).on(GRAY).paint(ARROW_SEPARATOR); LinePart { part: ANSIStrings(&[ @@ -127,7 +135,11 @@ fn selected_mode_shortcut(letter: char, text: &str) -> LinePart { fn disabled_mode_shortcut(text: &str) -> LinePart { let prefix_separator = Style::new().fg(GRAY).on(BRIGHT_GRAY).paint(ARROW_SEPARATOR); - let styled_text = Style::new().fg(GRAY).on(BRIGHT_GRAY).dimmed().paint(text); + let styled_text = Style::new() + .fg(GRAY) + .on(BRIGHT_GRAY) + .dimmed() + .paint(format!("{} ", text)); let suffix_separator = Style::new().fg(BRIGHT_GRAY).on(GRAY).paint(ARROW_SEPARATOR); LinePart { part: format!("{}{}{}", prefix_separator, styled_text, suffix_separator), @@ -136,7 +148,7 @@ fn disabled_mode_shortcut(text: &str) -> LinePart { } fn selected_mode_shortcut_single_letter(letter: char) -> LinePart { - let char_shortcut_text = letter.to_string(); + let char_shortcut_text = format!(" {} ", letter); let len = char_shortcut_text.chars().count() + 4; // 2 for the arrows, 2 for the padding let prefix_separator = Style::new().fg(GRAY).on(GREEN).paint(ARROW_SEPARATOR); let char_shortcut = Style::new() @@ -153,7 +165,7 @@ fn selected_mode_shortcut_single_letter(letter: char) -> LinePart { } fn unselected_mode_shortcut_single_letter(letter: char) -> LinePart { - let char_shortcut_text = letter.to_string(); + let char_shortcut_text = format!(" {} ", letter); let len = char_shortcut_text.chars().count() + 4; // 2 for the arrows, 2 for the padding let prefix_separator = Style::new().fg(GRAY).on(BRIGHT_GRAY).paint(ARROW_SEPARATOR); let char_shortcut = Style::new()