Merge in changes from main and fix clippy lints

This commit is contained in:
Brooks J Rady 2021-03-25 14:24:11 +00:00
commit f2f7758384
9 changed files with 154 additions and 21 deletions

1
Cargo.lock generated
View file

@ -2244,6 +2244,7 @@ dependencies = [
name = "zellij" name = "zellij"
version = "0.2.1" version = "0.2.1"
dependencies = [ dependencies = [
"ansi_term 0.12.1",
"async-std", "async-std",
"backtrace", "backtrace",
"bincode", "bincode",

View file

@ -13,6 +13,7 @@ publish = []
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
ansi_term = "0.12.1"
backtrace = "0.3.55" backtrace = "0.3.55"
bincode = "1.3.1" bincode = "1.3.1"
directories-next = "2.0" directories-next = "2.0"

View file

@ -1,5 +1,7 @@
use crate::tab::Pane; use crate::tab::Pane;
use ansi_term::Colour;
use std::collections::HashMap; use std::collections::HashMap;
use zellij_tile::data::InputMode;
use std::fmt::{Display, Error, Formatter}; use std::fmt::{Display, Error, Formatter};
@ -17,12 +19,20 @@ pub mod boundary_type {
pub const CROSS: &str = ""; 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 pub type BoundaryType = &'static str; // easy way to refer to boundary_type above
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub struct BoundarySymbol { pub struct BoundarySymbol {
boundary_type: BoundaryType, boundary_type: BoundaryType,
invisible: bool, invisible: bool,
color: Option<Colour>,
} }
impl BoundarySymbol { impl BoundarySymbol {
@ -30,20 +40,27 @@ impl BoundarySymbol {
BoundarySymbol { BoundarySymbol {
boundary_type, boundary_type,
invisible: false, invisible: false,
color: Some(colors::GRAY),
} }
} }
pub fn invisible(mut self) -> Self { pub fn invisible(mut self) -> Self {
self.invisible = true; self.invisible = true;
self self
} }
pub fn color(&mut self, color: Option<Colour>) -> Self {
self.color = color;
*self
}
} }
impl Display for BoundarySymbol { impl Display for BoundarySymbol {
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
if self.invisible { match self.invisible {
write!(f, " ") true => write!(f, " "),
} else { false => match self.color {
write!(f, "{}", self.boundary_type) Some(color) => write!(f, "{}", color.paint(self.boundary_type)),
None => write!(f, "{}", self.boundary_type),
},
} }
} }
} }
@ -53,6 +70,10 @@ fn combine_symbols(
next_symbol: BoundarySymbol, next_symbol: BoundarySymbol,
) -> Option<BoundarySymbol> { ) -> Option<BoundarySymbol> {
let invisible = current_symbol.invisible || next_symbol.invisible; let invisible = current_symbol.invisible || next_symbol.invisible;
let color = match (current_symbol.color.is_some(), next_symbol.color.is_some()) {
(true, _) => current_symbol.color,
_ => next_symbol.color,
};
let current_symbol = current_symbol.boundary_type; let current_symbol = current_symbol.boundary_type;
let next_symbol = next_symbol.boundary_type; let next_symbol = next_symbol.boundary_type;
match (current_symbol, next_symbol) { match (current_symbol, next_symbol) {
@ -62,6 +83,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::TOP_RIGHT, boundary_type::VERTICAL) => { (boundary_type::TOP_RIGHT, boundary_type::VERTICAL) => {
@ -70,6 +92,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::TOP_RIGHT, boundary_type::HORIZONTAL) => { (boundary_type::TOP_RIGHT, boundary_type::HORIZONTAL) => {
@ -78,6 +101,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::TOP_RIGHT, boundary_type::TOP_LEFT) => { (boundary_type::TOP_RIGHT, boundary_type::TOP_LEFT) => {
@ -86,6 +110,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::TOP_RIGHT, boundary_type::BOTTOM_RIGHT) => { (boundary_type::TOP_RIGHT, boundary_type::BOTTOM_RIGHT) => {
@ -94,6 +119,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::TOP_RIGHT, boundary_type::BOTTOM_LEFT) => { (boundary_type::TOP_RIGHT, boundary_type::BOTTOM_LEFT) => {
@ -102,6 +128,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::TOP_RIGHT, boundary_type::VERTICAL_LEFT) => { (boundary_type::TOP_RIGHT, boundary_type::VERTICAL_LEFT) => {
@ -110,6 +137,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::TOP_RIGHT, boundary_type::VERTICAL_RIGHT) => { (boundary_type::TOP_RIGHT, boundary_type::VERTICAL_RIGHT) => {
@ -118,6 +146,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::TOP_RIGHT, boundary_type::HORIZONTAL_DOWN) => { (boundary_type::TOP_RIGHT, boundary_type::HORIZONTAL_DOWN) => {
@ -126,6 +155,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::TOP_RIGHT, boundary_type::HORIZONTAL_UP) => { (boundary_type::TOP_RIGHT, boundary_type::HORIZONTAL_UP) => {
@ -134,6 +164,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::TOP_RIGHT, boundary_type::CROSS) => { (boundary_type::TOP_RIGHT, boundary_type::CROSS) => {
@ -142,6 +173,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::HORIZONTAL, boundary_type::HORIZONTAL) => { (boundary_type::HORIZONTAL, boundary_type::HORIZONTAL) => {
@ -150,6 +182,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::HORIZONTAL, boundary_type::VERTICAL) => { (boundary_type::HORIZONTAL, boundary_type::VERTICAL) => {
@ -158,6 +191,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::HORIZONTAL, boundary_type::TOP_LEFT) => { (boundary_type::HORIZONTAL, boundary_type::TOP_LEFT) => {
@ -166,6 +200,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::HORIZONTAL, boundary_type::BOTTOM_RIGHT) => { (boundary_type::HORIZONTAL, boundary_type::BOTTOM_RIGHT) => {
@ -174,6 +209,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::HORIZONTAL, boundary_type::BOTTOM_LEFT) => { (boundary_type::HORIZONTAL, boundary_type::BOTTOM_LEFT) => {
@ -182,6 +218,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::HORIZONTAL, boundary_type::VERTICAL_LEFT) => { (boundary_type::HORIZONTAL, boundary_type::VERTICAL_LEFT) => {
@ -190,6 +227,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::HORIZONTAL, boundary_type::VERTICAL_RIGHT) => { (boundary_type::HORIZONTAL, boundary_type::VERTICAL_RIGHT) => {
@ -198,6 +236,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::HORIZONTAL, boundary_type::HORIZONTAL_DOWN) => { (boundary_type::HORIZONTAL, boundary_type::HORIZONTAL_DOWN) => {
@ -206,6 +245,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::HORIZONTAL, boundary_type::HORIZONTAL_UP) => { (boundary_type::HORIZONTAL, boundary_type::HORIZONTAL_UP) => {
@ -214,6 +254,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::HORIZONTAL, boundary_type::CROSS) => { (boundary_type::HORIZONTAL, boundary_type::CROSS) => {
@ -222,6 +263,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::VERTICAL, boundary_type::VERTICAL) => { (boundary_type::VERTICAL, boundary_type::VERTICAL) => {
@ -230,6 +272,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::VERTICAL, boundary_type::TOP_LEFT) => { (boundary_type::VERTICAL, boundary_type::TOP_LEFT) => {
@ -238,6 +281,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::VERTICAL, boundary_type::BOTTOM_RIGHT) => { (boundary_type::VERTICAL, boundary_type::BOTTOM_RIGHT) => {
@ -246,6 +290,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::VERTICAL, boundary_type::BOTTOM_LEFT) => { (boundary_type::VERTICAL, boundary_type::BOTTOM_LEFT) => {
@ -254,6 +299,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::VERTICAL, boundary_type::VERTICAL_LEFT) => { (boundary_type::VERTICAL, boundary_type::VERTICAL_LEFT) => {
@ -262,6 +308,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::VERTICAL, boundary_type::VERTICAL_RIGHT) => { (boundary_type::VERTICAL, boundary_type::VERTICAL_RIGHT) => {
@ -270,6 +317,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::VERTICAL, boundary_type::HORIZONTAL_DOWN) => { (boundary_type::VERTICAL, boundary_type::HORIZONTAL_DOWN) => {
@ -278,6 +326,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::VERTICAL, boundary_type::HORIZONTAL_UP) => { (boundary_type::VERTICAL, boundary_type::HORIZONTAL_UP) => {
@ -286,6 +335,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::VERTICAL, boundary_type::CROSS) => { (boundary_type::VERTICAL, boundary_type::CROSS) => {
@ -294,6 +344,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::TOP_LEFT, boundary_type::TOP_LEFT) => { (boundary_type::TOP_LEFT, boundary_type::TOP_LEFT) => {
@ -302,6 +353,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::TOP_LEFT, boundary_type::BOTTOM_RIGHT) => { (boundary_type::TOP_LEFT, boundary_type::BOTTOM_RIGHT) => {
@ -310,6 +362,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::TOP_LEFT, boundary_type::BOTTOM_LEFT) => { (boundary_type::TOP_LEFT, boundary_type::BOTTOM_LEFT) => {
@ -318,6 +371,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::TOP_LEFT, boundary_type::VERTICAL_LEFT) => { (boundary_type::TOP_LEFT, boundary_type::VERTICAL_LEFT) => {
@ -326,6 +380,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::TOP_LEFT, boundary_type::VERTICAL_RIGHT) => { (boundary_type::TOP_LEFT, boundary_type::VERTICAL_RIGHT) => {
@ -334,6 +389,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::TOP_LEFT, boundary_type::HORIZONTAL_DOWN) => { (boundary_type::TOP_LEFT, boundary_type::HORIZONTAL_DOWN) => {
@ -342,6 +398,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::TOP_LEFT, boundary_type::HORIZONTAL_UP) => { (boundary_type::TOP_LEFT, boundary_type::HORIZONTAL_UP) => {
@ -350,6 +407,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::TOP_LEFT, boundary_type::CROSS) => { (boundary_type::TOP_LEFT, boundary_type::CROSS) => {
@ -358,6 +416,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::BOTTOM_RIGHT, boundary_type::BOTTOM_RIGHT) => { (boundary_type::BOTTOM_RIGHT, boundary_type::BOTTOM_RIGHT) => {
@ -366,6 +425,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::BOTTOM_RIGHT, boundary_type::BOTTOM_LEFT) => { (boundary_type::BOTTOM_RIGHT, boundary_type::BOTTOM_LEFT) => {
@ -374,6 +434,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::BOTTOM_RIGHT, boundary_type::VERTICAL_LEFT) => { (boundary_type::BOTTOM_RIGHT, boundary_type::VERTICAL_LEFT) => {
@ -382,6 +443,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::BOTTOM_RIGHT, boundary_type::VERTICAL_RIGHT) => { (boundary_type::BOTTOM_RIGHT, boundary_type::VERTICAL_RIGHT) => {
@ -390,6 +452,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::BOTTOM_RIGHT, boundary_type::HORIZONTAL_DOWN) => { (boundary_type::BOTTOM_RIGHT, boundary_type::HORIZONTAL_DOWN) => {
@ -398,6 +461,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::BOTTOM_RIGHT, boundary_type::HORIZONTAL_UP) => { (boundary_type::BOTTOM_RIGHT, boundary_type::HORIZONTAL_UP) => {
@ -406,6 +470,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::BOTTOM_RIGHT, boundary_type::CROSS) => { (boundary_type::BOTTOM_RIGHT, boundary_type::CROSS) => {
@ -414,6 +479,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::BOTTOM_LEFT, boundary_type::BOTTOM_LEFT) => { (boundary_type::BOTTOM_LEFT, boundary_type::BOTTOM_LEFT) => {
@ -422,6 +488,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::BOTTOM_LEFT, boundary_type::VERTICAL_LEFT) => { (boundary_type::BOTTOM_LEFT, boundary_type::VERTICAL_LEFT) => {
@ -430,6 +497,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::BOTTOM_LEFT, boundary_type::VERTICAL_RIGHT) => { (boundary_type::BOTTOM_LEFT, boundary_type::VERTICAL_RIGHT) => {
@ -438,6 +506,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::BOTTOM_LEFT, boundary_type::HORIZONTAL_DOWN) => { (boundary_type::BOTTOM_LEFT, boundary_type::HORIZONTAL_DOWN) => {
@ -446,6 +515,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::BOTTOM_LEFT, boundary_type::HORIZONTAL_UP) => { (boundary_type::BOTTOM_LEFT, boundary_type::HORIZONTAL_UP) => {
@ -454,6 +524,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::BOTTOM_LEFT, boundary_type::CROSS) => { (boundary_type::BOTTOM_LEFT, boundary_type::CROSS) => {
@ -462,6 +533,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::VERTICAL_LEFT, boundary_type::VERTICAL_LEFT) => { (boundary_type::VERTICAL_LEFT, boundary_type::VERTICAL_LEFT) => {
@ -470,6 +542,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::VERTICAL_LEFT, boundary_type::VERTICAL_RIGHT) => { (boundary_type::VERTICAL_LEFT, boundary_type::VERTICAL_RIGHT) => {
@ -478,6 +551,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::VERTICAL_LEFT, boundary_type::HORIZONTAL_DOWN) => { (boundary_type::VERTICAL_LEFT, boundary_type::HORIZONTAL_DOWN) => {
@ -486,6 +560,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::VERTICAL_LEFT, boundary_type::HORIZONTAL_UP) => { (boundary_type::VERTICAL_LEFT, boundary_type::HORIZONTAL_UP) => {
@ -494,6 +569,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::VERTICAL_LEFT, boundary_type::CROSS) => { (boundary_type::VERTICAL_LEFT, boundary_type::CROSS) => {
@ -502,6 +578,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::VERTICAL_RIGHT, boundary_type::VERTICAL_RIGHT) => { (boundary_type::VERTICAL_RIGHT, boundary_type::VERTICAL_RIGHT) => {
@ -510,6 +587,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::VERTICAL_RIGHT, boundary_type::HORIZONTAL_DOWN) => { (boundary_type::VERTICAL_RIGHT, boundary_type::HORIZONTAL_DOWN) => {
@ -518,6 +596,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::VERTICAL_RIGHT, boundary_type::HORIZONTAL_UP) => { (boundary_type::VERTICAL_RIGHT, boundary_type::HORIZONTAL_UP) => {
@ -526,6 +605,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::VERTICAL_RIGHT, boundary_type::CROSS) => { (boundary_type::VERTICAL_RIGHT, boundary_type::CROSS) => {
@ -534,6 +614,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::HORIZONTAL_DOWN, boundary_type::HORIZONTAL_DOWN) => { (boundary_type::HORIZONTAL_DOWN, boundary_type::HORIZONTAL_DOWN) => {
@ -542,6 +623,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::HORIZONTAL_DOWN, boundary_type::HORIZONTAL_UP) => { (boundary_type::HORIZONTAL_DOWN, boundary_type::HORIZONTAL_UP) => {
@ -550,6 +632,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::HORIZONTAL_DOWN, boundary_type::CROSS) => { (boundary_type::HORIZONTAL_DOWN, boundary_type::CROSS) => {
@ -558,6 +641,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::HORIZONTAL_UP, boundary_type::HORIZONTAL_UP) => { (boundary_type::HORIZONTAL_UP, boundary_type::HORIZONTAL_UP) => {
@ -566,6 +650,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::HORIZONTAL_UP, boundary_type::CROSS) => { (boundary_type::HORIZONTAL_UP, boundary_type::CROSS) => {
@ -574,6 +659,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(boundary_type::CROSS, boundary_type::CROSS) => { (boundary_type::CROSS, boundary_type::CROSS) => {
@ -582,6 +668,7 @@ fn combine_symbols(
Some(BoundarySymbol { Some(BoundarySymbol {
boundary_type, boundary_type,
invisible, invisible,
color,
}) })
} }
(_, _) => None, (_, _) => None,
@ -677,7 +764,14 @@ impl Boundaries {
boundary_characters: HashMap::new(), boundary_characters: HashMap::new(),
} }
} }
pub fn add_rect(&mut self, rect: &dyn Pane) { pub fn add_rect(&mut self, rect: &dyn Pane, input_mode: InputMode, color: Option<Colour>) {
let color = match color.is_some() {
true => match input_mode {
InputMode::Normal | InputMode::Locked => Some(colors::GREEN),
_ => Some(colors::WHITE),
},
false => None,
};
if rect.x() > 0 { if rect.x() > 0 {
let boundary_x_coords = rect.x() - 1; let boundary_x_coords = rect.x() - 1;
let first_row_coordinates = self.rect_right_boundary_row_start(rect); let first_row_coordinates = self.rect_right_boundary_row_start(rect);
@ -685,11 +779,11 @@ impl Boundaries {
for row in first_row_coordinates..last_row_coordinates { for row in first_row_coordinates..last_row_coordinates {
let coordinates = Coordinates::new(boundary_x_coords, row); let coordinates = Coordinates::new(boundary_x_coords, row);
let mut symbol_to_add = if row == first_row_coordinates && row != 0 { let mut symbol_to_add = if row == first_row_coordinates && row != 0 {
BoundarySymbol::new(boundary_type::TOP_LEFT) BoundarySymbol::new(boundary_type::TOP_LEFT).color(color)
} else if row == last_row_coordinates - 1 && row != self.rows - 1 { } else if row == last_row_coordinates - 1 && row != self.rows - 1 {
BoundarySymbol::new(boundary_type::BOTTOM_LEFT) BoundarySymbol::new(boundary_type::BOTTOM_LEFT).color(color)
} else { } else {
BoundarySymbol::new(boundary_type::VERTICAL) BoundarySymbol::new(boundary_type::VERTICAL).color(color)
}; };
if rect.invisible_borders() { if rect.invisible_borders() {
symbol_to_add = symbol_to_add.invisible(); symbol_to_add = symbol_to_add.invisible();
@ -709,11 +803,11 @@ impl Boundaries {
for col in first_col_coordinates..last_col_coordinates { for col in first_col_coordinates..last_col_coordinates {
let coordinates = Coordinates::new(col, boundary_y_coords); let coordinates = Coordinates::new(col, boundary_y_coords);
let mut symbol_to_add = if col == first_col_coordinates && col != 0 { let mut symbol_to_add = if col == first_col_coordinates && col != 0 {
BoundarySymbol::new(boundary_type::TOP_LEFT) BoundarySymbol::new(boundary_type::TOP_LEFT).color(color)
} else if col == last_col_coordinates - 1 && col != self.columns - 1 { } else if col == last_col_coordinates - 1 && col != self.columns - 1 {
BoundarySymbol::new(boundary_type::TOP_RIGHT) BoundarySymbol::new(boundary_type::TOP_RIGHT).color(color)
} else { } else {
BoundarySymbol::new(boundary_type::HORIZONTAL) BoundarySymbol::new(boundary_type::HORIZONTAL).color(color)
}; };
if rect.invisible_borders() { if rect.invisible_borders() {
symbol_to_add = symbol_to_add.invisible(); symbol_to_add = symbol_to_add.invisible();
@ -734,11 +828,11 @@ impl Boundaries {
for row in first_row_coordinates..last_row_coordinates { for row in first_row_coordinates..last_row_coordinates {
let coordinates = Coordinates::new(boundary_x_coords, row); let coordinates = Coordinates::new(boundary_x_coords, row);
let mut symbol_to_add = if row == first_row_coordinates && row != 0 { let mut symbol_to_add = if row == first_row_coordinates && row != 0 {
BoundarySymbol::new(boundary_type::TOP_RIGHT) BoundarySymbol::new(boundary_type::TOP_RIGHT).color(color)
} else if row == last_row_coordinates - 1 && row != self.rows - 1 { } else if row == last_row_coordinates - 1 && row != self.rows - 1 {
BoundarySymbol::new(boundary_type::BOTTOM_RIGHT) BoundarySymbol::new(boundary_type::BOTTOM_RIGHT).color(color)
} else { } else {
BoundarySymbol::new(boundary_type::VERTICAL) BoundarySymbol::new(boundary_type::VERTICAL).color(color)
}; };
if rect.invisible_borders() { if rect.invisible_borders() {
symbol_to_add = symbol_to_add.invisible(); symbol_to_add = symbol_to_add.invisible();
@ -758,11 +852,11 @@ impl Boundaries {
for col in first_col_coordinates..last_col_coordinates { for col in first_col_coordinates..last_col_coordinates {
let coordinates = Coordinates::new(col, boundary_y_coords); let coordinates = Coordinates::new(col, boundary_y_coords);
let mut symbol_to_add = if col == first_col_coordinates && col != 0 { let mut symbol_to_add = if col == first_col_coordinates && col != 0 {
BoundarySymbol::new(boundary_type::BOTTOM_LEFT) BoundarySymbol::new(boundary_type::BOTTOM_LEFT).color(color)
} else if col == last_col_coordinates - 1 && col != self.columns - 1 { } else if col == last_col_coordinates - 1 && col != self.columns - 1 {
BoundarySymbol::new(boundary_type::BOTTOM_RIGHT) BoundarySymbol::new(boundary_type::BOTTOM_RIGHT).color(color)
} else { } else {
BoundarySymbol::new(boundary_type::HORIZONTAL) BoundarySymbol::new(boundary_type::HORIZONTAL).color(color)
}; };
if rect.invisible_borders() { if rect.invisible_borders() {
symbol_to_add = symbol_to_add.invisible(); symbol_to_add = symbol_to_add.invisible();

View file

@ -188,7 +188,14 @@ impl Pane for TerminalPane {
self.max_height self.max_height
} }
fn render(&mut self) -> Option<String> { fn render(&mut self) -> Option<String> {
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 mut vte_output = String::new();
let buffer_lines = &self.read_buffer_as_lines(); let buffer_lines = &self.read_buffer_as_lines();
let display_cols = self.get_columns(); let display_cols = self.get_columns();

View file

@ -1,6 +1,7 @@
//! `Tab`s holds multiple panes. It tracks their coordinates (x/y) and size, //! `Tab`s holds multiple panes. It tracks their coordinates (x/y) and size,
//! as well as how they should be resized //! as well as how they should be resized
use crate::boundaries::colors;
use crate::common::{input::handler::parse_keys, AppInstruction, SenderWithContext}; use crate::common::{input::handler::parse_keys, AppInstruction, SenderWithContext};
use crate::layout::Layout; use crate::layout::Layout;
use crate::panes::{PaneId, PositionAndSize, TerminalPane}; use crate::panes::{PaneId, PositionAndSize, TerminalPane};
@ -14,7 +15,7 @@ use std::{
collections::{BTreeMap, HashSet}, collections::{BTreeMap, HashSet},
}; };
use std::{io::Write, sync::mpsc::channel}; use std::{io::Write, sync::mpsc::channel};
use zellij_tile::data::Event; use zellij_tile::data::{Event, InputMode};
const CURSOR_HEIGHT_WIDTH_RATIO: usize = 4; // this is not accurate and kind of a magic number, TODO: look into this const CURSOR_HEIGHT_WIDTH_RATIO: usize = 4; // this is not accurate and kind of a magic number, TODO: look into this
const MIN_TERMINAL_HEIGHT: usize = 2; const MIN_TERMINAL_HEIGHT: usize = 2;
@ -65,6 +66,7 @@ pub struct Tab {
pub send_plugin_instructions: SenderWithContext<PluginInstruction>, pub send_plugin_instructions: SenderWithContext<PluginInstruction>,
pub send_app_instructions: SenderWithContext<AppInstruction>, pub send_app_instructions: SenderWithContext<AppInstruction>,
expansion_boundary: Option<PositionAndSize>, expansion_boundary: Option<PositionAndSize>,
pub input_mode: InputMode,
} }
// FIXME: Use a struct that has a pane_type enum, to reduce all of the duplication // FIXME: Use a struct that has a pane_type enum, to reduce all of the duplication
@ -181,6 +183,7 @@ impl Tab {
send_app_instructions: SenderWithContext<AppInstruction>, send_app_instructions: SenderWithContext<AppInstruction>,
max_panes: Option<usize>, max_panes: Option<usize>,
pane_id: Option<PaneId>, pane_id: Option<PaneId>,
input_mode: InputMode,
) -> Self { ) -> Self {
let panes = if let Some(PaneId::Terminal(pid)) = pane_id { let panes = if let Some(PaneId::Terminal(pid)) = pane_id {
let new_terminal = TerminalPane::new(pid, *full_screen_ws); let new_terminal = TerminalPane::new(pid, *full_screen_ws);
@ -210,6 +213,7 @@ impl Tab {
send_pty_instructions, send_pty_instructions,
send_plugin_instructions, send_plugin_instructions,
expansion_boundary: None, expansion_boundary: None,
input_mode,
} }
} }
@ -636,7 +640,12 @@ impl Tab {
.expect("cannot write to stdout"); .expect("cannot write to stdout");
for (kind, terminal) in self.panes.iter_mut() { for (kind, terminal) in self.panes.iter_mut() {
if !self.panes_to_hide.contains(&terminal.pid()) { if !self.panes_to_hide.contains(&terminal.pid()) {
boundaries.add_rect(terminal.as_ref()); match self.active_terminal.unwrap() == terminal.pid() {
true => {
boundaries.add_rect(terminal.as_ref(), self.input_mode, Some(colors::GREEN))
}
false => boundaries.add_rect(terminal.as_ref(), self.input_mode, None),
}
if let Some(vte_output) = terminal.render() { if let Some(vte_output) = terminal.render() {
let vte_output = if let PaneId::Terminal(_) = kind { let vte_output = if let PaneId::Terminal(_) = kind {
vte_output vte_output

View file

@ -200,6 +200,7 @@ pub enum ScreenContext {
CloseTab, CloseTab,
GoToTab, GoToTab,
UpdateTabName, UpdateTabName,
ChangeInputMode,
} }
// FIXME: Just deriving EnumDiscriminants from strum will remove the need for any of this!!! // FIXME: Just deriving EnumDiscriminants from strum will remove the need for any of this!!!
@ -240,6 +241,7 @@ impl From<&ScreenInstruction> for ScreenContext {
ScreenInstruction::CloseTab => ScreenContext::CloseTab, ScreenInstruction::CloseTab => ScreenContext::CloseTab,
ScreenInstruction::GoToTab(_) => ScreenContext::GoToTab, ScreenInstruction::GoToTab(_) => ScreenContext::GoToTab,
ScreenInstruction::UpdateTabName(_) => ScreenContext::UpdateTabName, ScreenInstruction::UpdateTabName(_) => ScreenContext::UpdateTabName,
ScreenInstruction::ChangeInputMode(_) => ScreenContext::ChangeInputMode,
} }
} }
} }

View file

@ -131,6 +131,9 @@ impl InputHandler {
update_state(&self.send_app_instructions, |_| AppState { update_state(&self.send_app_instructions, |_| AppState {
input_mode: self.mode, input_mode: self.mode,
}); });
self.send_screen_instructions
.send(ScreenInstruction::ChangeInputMode(self.mode))
.unwrap();
self.send_screen_instructions self.send_screen_instructions
.send(ScreenInstruction::Render) .send(ScreenInstruction::Render)
.unwrap(); .unwrap();

View file

@ -295,6 +295,7 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs) {
&full_screen_ws, &full_screen_ws,
os_input, os_input,
max_panes, max_panes,
InputMode::Normal,
); );
loop { loop {
let (event, mut err_ctx) = screen let (event, mut err_ctx) = screen
@ -429,6 +430,9 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs) {
ScreenInstruction::UpdateTabName(c) => { ScreenInstruction::UpdateTabName(c) => {
screen.update_active_tab_name(c); screen.update_active_tab_name(c);
} }
ScreenInstruction::ChangeInputMode(input_mode) => {
screen.change_input_mode(input_mode);
}
ScreenInstruction::Quit => { ScreenInstruction::Quit => {
break; break;
} }

View file

@ -13,7 +13,7 @@ use crate::tab::Tab;
use crate::{errors::ErrorContext, wasm_vm::PluginInstruction}; use crate::{errors::ErrorContext, wasm_vm::PluginInstruction};
use crate::{layout::Layout, panes::PaneId}; use crate::{layout::Layout, panes::PaneId};
use zellij_tile::data::TabInfo; use zellij_tile::data::{InputMode, TabInfo};
/// Instructions that can be sent to the [`Screen`]. /// Instructions that can be sent to the [`Screen`].
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@ -50,6 +50,7 @@ pub enum ScreenInstruction {
CloseTab, CloseTab,
GoToTab(u32), GoToTab(u32),
UpdateTabName(Vec<u8>), UpdateTabName(Vec<u8>),
ChangeInputMode(InputMode),
} }
/// A [`Screen`] holds multiple [`Tab`]s, each one holding multiple [`panes`](crate::client::panes). /// A [`Screen`] holds multiple [`Tab`]s, each one holding multiple [`panes`](crate::client::panes).
@ -74,6 +75,7 @@ pub struct Screen {
/// The [`OsApi`] this [`Screen`] uses. /// The [`OsApi`] this [`Screen`] uses.
os_api: Box<dyn OsApi>, os_api: Box<dyn OsApi>,
tabname_buf: String, tabname_buf: String,
input_mode: InputMode,
} }
impl Screen { impl Screen {
@ -86,6 +88,7 @@ impl Screen {
full_screen_ws: &PositionAndSize, full_screen_ws: &PositionAndSize,
os_api: Box<dyn OsApi>, os_api: Box<dyn OsApi>,
max_panes: Option<usize>, max_panes: Option<usize>,
input_mode: InputMode,
) -> Self { ) -> Self {
Screen { Screen {
receiver: receive_screen_instructions, receiver: receive_screen_instructions,
@ -98,6 +101,7 @@ impl Screen {
tabs: BTreeMap::new(), tabs: BTreeMap::new(),
os_api, os_api,
tabname_buf: String::new(), tabname_buf: String::new(),
input_mode,
} }
} }
@ -117,6 +121,7 @@ impl Screen {
self.send_app_instructions.clone(), self.send_app_instructions.clone(),
self.max_panes, self.max_panes,
Some(PaneId::Terminal(pane_id)), Some(PaneId::Terminal(pane_id)),
self.input_mode,
); );
self.active_tab_index = Some(tab_index); self.active_tab_index = Some(tab_index);
self.tabs.insert(tab_index, tab); self.tabs.insert(tab_index, tab);
@ -258,6 +263,7 @@ impl Screen {
self.send_app_instructions.clone(), self.send_app_instructions.clone(),
self.max_panes, self.max_panes,
None, None,
self.input_mode,
); );
tab.apply_layout(layout, new_pids); tab.apply_layout(layout, new_pids);
self.active_tab_index = Some(tab_index); self.active_tab_index = Some(tab_index);
@ -302,4 +308,10 @@ 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;
}
}
} }