diff options
author | Brooks Rady <b.j.rady@gmail.com> | 2022-03-22 14:58:16 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-22 14:58:16 +0000 |
commit | 9bfafde12348623e2a5d1513ba0928e15d441efd (patch) | |
tree | eced3310a2b8102189ae55e984104a94bed8a510 /zellij-server/src/ui | |
parent | 2d55a3e274f1fc13d7adf8a1574188498efae82c (diff) |
feat(ui): round frame corners (#1227)
* feat(ui): round frame corners
* Allow rounded_corners to be set without a palette
* Revert "Allow rounded_corners to be set without a palette"
This reverts commit 9271a4b5452f2e59e0ebd55136343f0fbfabaa13.
* fix(style): remove redundant code
* fix(style): clippy lints that somehow got missed
* feat(config): add ui config section
Diffstat (limited to 'zellij-server/src/ui')
-rw-r--r-- | zellij-server/src/ui/boundaries.rs | 4 | ||||
-rw-r--r-- | zellij-server/src/ui/pane_boundaries_frame.rs | 76 | ||||
-rw-r--r-- | zellij-server/src/ui/pane_contents_and_ui.rs | 23 |
3 files changed, 73 insertions, 30 deletions
diff --git a/zellij-server/src/ui/boundaries.rs b/zellij-server/src/ui/boundaries.rs index 649437415..b78d631cf 100644 --- a/zellij-server/src/ui/boundaries.rs +++ b/zellij-server/src/ui/boundaries.rs @@ -11,11 +11,15 @@ use zellij_utils::shared::colors; use std::fmt::{Display, Error, Formatter}; pub mod boundary_type { pub const TOP_RIGHT: &str = "┐"; + pub const TOP_RIGHT_ROUND: &str = "╮"; pub const VERTICAL: &str = "│"; pub const HORIZONTAL: &str = "─"; pub const TOP_LEFT: &str = "┌"; + pub const TOP_LEFT_ROUND: &str = "╭"; pub const BOTTOM_RIGHT: &str = "┘"; + pub const BOTTOM_RIGHT_ROUND: &str = "╯"; pub const BOTTOM_LEFT: &str = "└"; + pub const BOTTOM_LEFT_ROUND: &str = "╰"; pub const VERTICAL_LEFT: &str = "┤"; pub const VERTICAL_RIGHT: &str = "├"; pub const HORIZONTAL_DOWN: &str = "┬"; diff --git a/zellij-server/src/ui/pane_boundaries_frame.rs b/zellij-server/src/ui/pane_boundaries_frame.rs index 28f6112bb..22812cb3a 100644 --- a/zellij-server/src/ui/pane_boundaries_frame.rs +++ b/zellij-server/src/ui/pane_boundaries_frame.rs @@ -2,8 +2,9 @@ use crate::output::CharacterChunk; use crate::panes::{AnsiCode, CharacterStyles, TerminalCharacter, EMPTY_TERMINAL_CHARACTER}; use crate::ui::boundaries::boundary_type; use crate::ClientId; +use zellij_tile::prelude::Style; use zellij_utils::pane_size::Viewport; -use zellij_utils::zellij_tile::prelude::{client_id_to_colors, Palette, PaletteColor}; +use zellij_utils::zellij_tile::prelude::{client_id_to_colors, PaletteColor}; use unicode_width::{UnicodeWidthChar, UnicodeWidthStr}; @@ -65,7 +66,7 @@ pub struct FrameParams { pub focused_client: Option<ClientId>, pub is_main_client: bool, pub other_focused_clients: Vec<ClientId>, - pub colors: Palette, + pub style: Style, pub color: Option<PaletteColor>, pub other_cursors_exist_in_session: bool, } @@ -75,7 +76,7 @@ pub struct PaneFrame { pub geom: Viewport, pub title: String, pub scroll_position: (usize, usize), // (position, length) - pub colors: Palette, + pub style: Style, pub color: Option<PaletteColor>, pub focused_client: Option<ClientId>, pub is_main_client: bool, @@ -94,7 +95,7 @@ impl PaneFrame { geom, title: main_title, scroll_position, - colors: frame_params.colors, + style: frame_params.style, color: frame_params.color, focused_client: frame_params.focused_client, is_main_client: frame_params.is_main_client, @@ -103,9 +104,22 @@ impl PaneFrame { } } fn client_cursor(&self, client_id: ClientId) -> Vec<TerminalCharacter> { - let color = client_id_to_colors(client_id, self.colors); + let color = client_id_to_colors(client_id, self.style.colors); background_color(" ", color.map(|c| c.0)) } + fn get_corner(&self, corner: &'static str) -> &'static str { + if self.style.rounded_corners { + match corner { + boundary_type::TOP_RIGHT => boundary_type::TOP_RIGHT_ROUND, + boundary_type::TOP_LEFT => boundary_type::TOP_LEFT_ROUND, + boundary_type::BOTTOM_RIGHT => boundary_type::BOTTOM_RIGHT_ROUND, + boundary_type::BOTTOM_LEFT => boundary_type::BOTTOM_LEFT_ROUND, + _ => corner, + } + } else { + corner + } + } fn render_title_right_side( &self, max_length: usize, @@ -364,9 +378,15 @@ impl PaneFrame { let mut col = self.geom.x; loop { if col == self.geom.x { - title_line.append(&mut foreground_color(boundary_type::TOP_LEFT, self.color)); + title_line.append(&mut foreground_color( + self.get_corner(boundary_type::TOP_LEFT), + self.color, + )); } else if col == self.geom.x + self.geom.cols - 1 { - title_line.append(&mut foreground_color(boundary_type::TOP_RIGHT, self.color)); + title_line.append(&mut foreground_color( + self.get_corner(boundary_type::TOP_RIGHT), + self.color, + )); } else if col == left_side_start_position { title_line.append(&mut left_side); col += left_side_len; @@ -404,9 +424,15 @@ impl PaneFrame { let mut col = self.geom.x; loop { if col == self.geom.x { - title_line.append(&mut foreground_color(boundary_type::TOP_LEFT, self.color)); + title_line.append(&mut foreground_color( + self.get_corner(boundary_type::TOP_LEFT), + self.color, + )); } else if col == self.geom.x + self.geom.cols - 1 { - title_line.append(&mut foreground_color(boundary_type::TOP_RIGHT, self.color)); + title_line.append(&mut foreground_color( + self.get_corner(boundary_type::TOP_RIGHT), + self.color, + )); } else if col == left_side_start_position { title_line.append(&mut left_side); col += *left_side_len; @@ -437,9 +463,15 @@ impl PaneFrame { let mut col = self.geom.x; loop { if col == self.geom.x { - title_line.append(&mut foreground_color(boundary_type::TOP_LEFT, self.color)); + title_line.append(&mut foreground_color( + self.get_corner(boundary_type::TOP_LEFT), + self.color, + )); } else if col == self.geom.x + self.geom.cols - 1 { - title_line.append(&mut foreground_color(boundary_type::TOP_RIGHT, self.color)); + title_line.append(&mut foreground_color( + self.get_corner(boundary_type::TOP_RIGHT), + self.color, + )); } else if col == middle_start_position { title_line.append(&mut middle); col += *middle_len; @@ -461,8 +493,10 @@ impl PaneFrame { mut right_side: Vec<TerminalCharacter>, right_side_len: &usize, ) -> Vec<TerminalCharacter> { - let mut left_boundary = foreground_color(boundary_type::TOP_LEFT, self.color); - let mut right_boundary = foreground_color(boundary_type::TOP_RIGHT, self.color); + let mut left_boundary = + foreground_color(self.get_corner(boundary_type::TOP_LEFT), self.color); + let mut right_boundary = + foreground_color(self.get_corner(boundary_type::TOP_RIGHT), self.color); let total_title_length = self.geom.cols.saturating_sub(2); // 2 for the left and right corners let mut middle = String::new(); for _ in (left_side_len + right_side_len)..total_title_length { @@ -481,8 +515,10 @@ impl PaneFrame { mut left_side: Vec<TerminalCharacter>, left_side_len: &usize, ) -> Vec<TerminalCharacter> { - let mut left_boundary = foreground_color(boundary_type::TOP_LEFT, self.color); - let mut right_boundary = foreground_color(boundary_type::TOP_RIGHT, self.color); + let mut left_boundary = + foreground_color(self.get_corner(boundary_type::TOP_LEFT), self.color); + let mut right_boundary = + foreground_color(self.get_corner(boundary_type::TOP_RIGHT), self.color); let total_title_length = self.geom.cols.saturating_sub(2); // 2 for the left and right corners let mut middle_padding = String::new(); for _ in *left_side_len..total_title_length { @@ -496,8 +532,10 @@ impl PaneFrame { ret } fn empty_title_line(&self) -> Vec<TerminalCharacter> { - let mut left_boundary = foreground_color(boundary_type::TOP_LEFT, self.color); - let mut right_boundary = foreground_color(boundary_type::TOP_RIGHT, self.color); + let mut left_boundary = + foreground_color(self.get_corner(boundary_type::TOP_LEFT), self.color); + let mut right_boundary = + foreground_color(self.get_corner(boundary_type::TOP_RIGHT), self.color); let total_title_length = self.geom.cols.saturating_sub(2); // 2 for the left and right corners let mut middle_padding = String::new(); for _ in 0..total_title_length { @@ -575,10 +613,10 @@ impl PaneFrame { for col in 0..self.geom.cols { let boundary = if col == 0 { // bottom left corner - boundary_type::BOTTOM_LEFT + self.get_corner(boundary_type::BOTTOM_LEFT) } else if col == self.geom.cols - 1 { // bottom right corner - boundary_type::BOTTOM_RIGHT + self.get_corner(boundary_type::BOTTOM_RIGHT) } else { boundary_type::HORIZONTAL }; diff --git a/zellij-server/src/ui/pane_contents_and_ui.rs b/zellij-server/src/ui/pane_contents_and_ui.rs index 61b0e3544..4a39da8ff 100644 --- a/zellij-server/src/ui/pane_contents_and_ui.rs +++ b/zellij-server/src/ui/pane_contents_and_ui.rs @@ -5,13 +5,14 @@ use crate::ui::boundaries::Boundaries; use crate::ui::pane_boundaries_frame::FrameParams; use crate::ClientId; use std::collections::HashMap; -use zellij_tile::data::{ - client_id_to_colors, single_client_color, InputMode, Palette, PaletteColor, +use zellij_tile::{ + data::{client_id_to_colors, single_client_color, InputMode, PaletteColor}, + prelude::Style, }; pub struct PaneContentsAndUi<'a> { pane: &'a mut Box<dyn Pane>, output: &'a mut Output, - colors: Palette, + style: Style, focused_clients: Vec<ClientId>, multiple_users_exist_in_session: bool, z_index: Option<usize>, @@ -21,7 +22,7 @@ impl<'a> PaneContentsAndUi<'a> { pub fn new( pane: &'a mut Box<dyn Pane>, output: &'a mut Output, - colors: Palette, + style: Style, active_panes: &HashMap<ClientId, PaneId>, multiple_users_exist_in_session: bool, z_index: Option<usize>, @@ -34,7 +35,7 @@ impl<'a> PaneContentsAndUi<'a> { PaneContentsAndUi { pane, output, - colors, + style, focused_clients, multiple_users_exist_in_session, z_index, @@ -95,7 +96,7 @@ impl<'a> PaneContentsAndUi<'a> { .iter() .find(|&&c_id| c_id != client_id) .unwrap(); - if let Some(colors) = client_id_to_colors(*fake_cursor_client_id, self.colors) { + if let Some(colors) = client_id_to_colors(*fake_cursor_client_id, self.style.colors) { if let Some(vte_output) = self.pane.render_fake_cursor(colors.0, colors.1) { self.output.add_post_vte_instruction_to_client( client_id, @@ -146,7 +147,7 @@ impl<'a> PaneContentsAndUi<'a> { focused_client, is_main_client: pane_focused_for_client_id, other_focused_clients: vec![], - colors: self.colors, + style: self.style, color: frame_color, other_cursors_exist_in_session: false, } @@ -155,7 +156,7 @@ impl<'a> PaneContentsAndUi<'a> { focused_client, is_main_client: pane_focused_for_client_id, other_focused_clients, - colors: self.colors, + style: self.style, color: frame_color, other_cursors_exist_in_session: self.multiple_users_exist_in_session, } @@ -195,14 +196,14 @@ impl<'a> PaneContentsAndUi<'a> { match mode { InputMode::Normal | InputMode::Locked => { if session_is_mirrored || !self.multiple_users_exist_in_session { - let colors = single_client_color(self.colors); // mirrored sessions only have one focused color + let colors = single_client_color(self.style.colors); // mirrored sessions only have one focused color Some(colors.0) } else { - let colors = client_id_to_colors(client_id, self.colors); + let colors = client_id_to_colors(client_id, self.style.colors); colors.map(|colors| colors.0) } } - _ => Some(self.colors.orange), + _ => Some(self.style.colors.orange), } } else { None |