use crate::tab::Pane;
use crate::utils::shared::colors;
use ansi_term::Colour::{Fixed, RGB};
use std::collections::HashMap;
use zellij_tile::data::{InputMode, Palette, PaletteColor};
use std::fmt::{Display, Error, Formatter};
pub mod boundary_type {
pub const TOP_RIGHT: &str = "┐";
pub const VERTICAL: &str = "│";
pub const HORIZONTAL: &str = "─";
pub const TOP_LEFT: &str = "┌";
pub const BOTTOM_RIGHT: &str = "┘";
pub const BOTTOM_LEFT: &str = "└";
pub const VERTICAL_LEFT: &str = "┤";
pub const VERTICAL_RIGHT: &str = "├";
pub const HORIZONTAL_DOWN: &str = "┬";
pub const HORIZONTAL_UP: &str = "┴";
pub const CROSS: &str = "┼";
}
pub type BoundaryType = &'static str; // easy way to refer to boundary_type above
#[derive(Clone, Copy, Debug)]
pub struct BoundarySymbol {
boundary_type: BoundaryType,
invisible: bool,
color: Option<PaletteColor>,
}
impl BoundarySymbol {
pub fn new(boundary_type: BoundaryType) -> Self {
BoundarySymbol {
boundary_type,
invisible: false,
color: Some(PaletteColor::EightBit(colors::GRAY)),
}
}
pub fn invisible(mut self) -> Self {
self.invisible = true;
self
}
pub fn color(&mut self, color: Option<PaletteColor>) -> 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.color {
Some(color) => match color {
PaletteColor::Rgb((r, g, b)) => {
write!(f, "{}", RGB(r, g, b).paint(self.boundary_type))
}
PaletteColor::EightBit(color) => {
write!(f, "{}", Fixed(color).paint(self.boundary_type))
}
},
None => write!(f, "{}", self.boundary_type),
},
}
}
}
fn combine_symbols(
current_symbol: BoundarySymbol,
next_symbol: BoundarySymbol,
) -> Option<BoundarySymbol> {
use boundary_type::*;
let invisible = current_symbol.invisible || next_symbol.invisible;
let color = current_symbol.color.or(next_symbol.color);
match (current_symbol.boundary_type, next_symbol.boundary_type) {
(CROSS, _) | (_, CROSS) => {
// (┼, *) or (*, ┼) => Some(┼)
let boundary_type = CROSS;
Some(BoundarySymbol {
boundary_type,
invisible,
color,
})
}
(TOP_RIGHT, TOP_RIGHT) => {
// (┐, ┐) => Some(┐)
let boundary_type = TOP_RIGHT;
Some(BoundarySymbol {
boundary_type,
invisible,
color,
})
}
(TOP_RIGHT, VERTICAL) | (TOP_RIGHT, BOTTOM_RIGHT) | (TOP_RIGHT, VERTICAL_LEFT) => {
// (┐, │) => Some(┤)
// (┐, ┘) => Some(┤)
// (─, ┤) => Some(┤)
let boundary_