From 0219e83d933a717a811ab3a6a3bdcac5d021dc76 Mon Sep 17 00:00:00 2001 From: Daniel Jankowski Date: Tue, 15 Oct 2024 19:15:22 +0200 Subject: [PATCH 01/13] feat(plugins): add transparent background for text and nested_list --- zellij-server/src/ui/components/mod.rs | 9 +++++++++ zellij-server/src/ui/components/nested_list.rs | 15 ++++++++++++--- zellij-server/src/ui/components/text.rs | 10 +++++++++- zellij-tile/src/ui_components/nested_list.rs | 4 ++++ zellij-tile/src/ui_components/text.rs | 18 +++++++++++++++--- 5 files changed, 49 insertions(+), 7 deletions(-) diff --git a/zellij-server/src/ui/components/mod.rs b/zellij-server/src/ui/components/mod.rs index 8fcfcc143f..e3a4791fdb 100644 --- a/zellij-server/src/ui/components/mod.rs +++ b/zellij-server/src/ui/components/mod.rs @@ -164,6 +164,15 @@ fn parse_selected(stringified: &mut String) -> bool { selected } +fn parse_transparent(stringified: &mut String) -> bool { + let mut transparent = false; + if stringified.chars().next() == Some('z') { + transparent = true; + stringified.remove(0); + } + transparent +} + fn parse_indices(stringified: &mut String) -> Vec> { stringified .chars() diff --git a/zellij-server/src/ui/components/nested_list.rs b/zellij-server/src/ui/components/nested_list.rs index 370131e514..7835cd97e1 100644 --- a/zellij-server/src/ui/components/nested_list.rs +++ b/zellij-server/src/ui/components/nested_list.rs @@ -1,5 +1,5 @@ use super::{ - is_too_high, parse_indices, parse_selected, parse_text, stringify_text, Coordinates, Text, + is_too_high, parse_indices, parse_selected, parse_transparent, parse_text, stringify_text, Coordinates, Text, }; use crate::panes::terminal_character::{AnsiCode, RESET_STYLES}; use zellij_utils::data::Style; @@ -35,7 +35,11 @@ pub fn nested_list( } else { "- " }; - let text_style = if line_item.text.selected { + let text_style = if line_item.text.transparent { + reset_styles_for_item + .bold(Some(AnsiCode::On)) + .foreground(Some(style.colors.white.into())) + } else if line_item.text.selected { reset_styles_for_item .bold(Some(AnsiCode::On)) .foreground(Some(style.colors.white.into())) @@ -65,7 +69,10 @@ pub fn nested_list( "".to_owned() } }); - let line_style = if line_item.text.selected { + let line_style = if line_item.text.transparent { + RESET_STYLES + .foreground(Some(style.colors.white.into())) + } else if line_item.text.selected { RESET_STYLES .foreground(Some(style.colors.white.into())) .background(Some(style.colors.bg.into())) @@ -89,10 +96,12 @@ pub fn parse_nested_list_items<'a>( .flat_map(|mut stringified| { let indentation_level = parse_indentation_level(&mut stringified); let selected = parse_selected(&mut stringified); + let transparent = parse_transparent(&mut stringified); let indices = parse_indices(&mut stringified); let text = parse_text(&mut stringified).map_err(|e| e.to_string())?; let text = Text { text, + transparent, selected, indices, }; diff --git a/zellij-server/src/ui/components/text.rs b/zellij-server/src/ui/components/text.rs index e546c10bc4..1b59f43d78 100644 --- a/zellij-server/src/ui/components/text.rs +++ b/zellij-server/src/ui/components/text.rs @@ -1,6 +1,6 @@ use super::{ emphasis_variants_for_ribbon, emphasis_variants_for_selected_ribbon, is_too_wide, - parse_indices, parse_selected, Coordinates, + parse_indices, parse_selected, parse_transparent, Coordinates, }; use crate::panes::terminal_character::{AnsiCode, CharacterStyles, RESET_STYLES}; use zellij_utils::{ @@ -16,6 +16,11 @@ pub fn text(content: Text, style: &Style, component_coordinates: Option(params_iter: impl Iterator) params_iter .flat_map(|mut stringified| { let selected = parse_selected(&mut stringified); + let transparent = parse_transparent(&mut stringified); let indices = parse_indices(&mut stringified); let text = parse_text(&mut stringified).map_err(|e| e.to_string())?; Ok::(Text { text, + transparent, selected, indices, }) @@ -115,6 +122,7 @@ pub fn parse_text_params<'a>(params_iter: impl Iterator) pub struct Text { pub text: String, pub selected: bool, + pub transparent: bool, pub indices: Vec>, } diff --git a/zellij-tile/src/ui_components/nested_list.rs b/zellij-tile/src/ui_components/nested_list.rs index 442c27fb66..779a12a929 100644 --- a/zellij-tile/src/ui_components/nested_list.rs +++ b/zellij-tile/src/ui_components/nested_list.rs @@ -26,6 +26,10 @@ impl NestedListItem { self.content = self.content.selected(); self } + pub fn transparent(mut self) -> Self { + self.content = self.content.transparent(); + self + } pub fn color_indices(mut self, index_level: usize, indices: Vec) -> Self { self.content = self.content.color_indices(index_level, indices); self diff --git a/zellij-tile/src/ui_components/text.rs b/zellij-tile/src/ui_components/text.rs index da934dd435..c936c4b7c3 100644 --- a/zellij-tile/src/ui_components/text.rs +++ b/zellij-tile/src/ui_components/text.rs @@ -5,6 +5,7 @@ use std::ops::RangeBounds; pub struct Text { text: String, selected: bool, + transparent: bool, indices: Vec>, } @@ -16,6 +17,7 @@ impl Text { Text { text: content.to_string(), selected: false, + transparent: false, indices: vec![], } } @@ -23,6 +25,10 @@ impl Text { self.selected = true; self } + pub fn transparent(mut self) -> Self { + self.transparent = true; + self + } pub fn color_indices(mut self, index_level: usize, mut indices: Vec) -> Self { self.pad_indices(index_level); self.indices @@ -75,11 +81,17 @@ impl Text { .join(",") )); } + + let mut prefix = "".to_owned(); if self.selected { - format!("x{}{}", indices, text) - } else { - format!("{}{}", indices, text) + prefix = format!("x{}", prefix); } + + if self.transparent { + prefix = format!("z{}", prefix); + } + + format!("{}{}{}", prefix, indices, text) } } From 995b41d7f1f94f2d24f123ab4baad26a337b7c79 Mon Sep 17 00:00:00 2001 From: Daniel Jankowski Date: Tue, 15 Oct 2024 19:27:11 +0200 Subject: [PATCH 02/13] chore: fix formatting issue --- zellij-server/src/ui/components/nested_list.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/zellij-server/src/ui/components/nested_list.rs b/zellij-server/src/ui/components/nested_list.rs index 7835cd97e1..bbdcd9f16b 100644 --- a/zellij-server/src/ui/components/nested_list.rs +++ b/zellij-server/src/ui/components/nested_list.rs @@ -1,5 +1,6 @@ use super::{ - is_too_high, parse_indices, parse_selected, parse_transparent, parse_text, stringify_text, Coordinates, Text, + is_too_high, parse_indices, parse_selected, parse_text, parse_transparent, stringify_text, + Coordinates, Text, }; use crate::panes::terminal_character::{AnsiCode, RESET_STYLES}; use zellij_utils::data::Style; @@ -70,8 +71,7 @@ pub fn nested_list( } }); let line_style = if line_item.text.transparent { - RESET_STYLES - .foreground(Some(style.colors.white.into())) + RESET_STYLES.foreground(Some(style.colors.white.into())) } else if line_item.text.selected { RESET_STYLES .foreground(Some(style.colors.white.into())) From f36822ceb5762770cac8ac11357f06a1d6cacb56 Mon Sep 17 00:00:00 2001 From: Daniel Jankowski Date: Fri, 18 Oct 2024 17:17:43 +0200 Subject: [PATCH 03/13] feat: invert flag behaviour --- zellij-server/src/ui/components/mod.rs | 8 +++---- .../src/ui/components/nested_list.rs | 22 +++++++++---------- zellij-server/src/ui/components/text.rs | 15 ++++++------- zellij-tile/src/ui_components/nested_list.rs | 4 ++-- zellij-tile/src/ui_components/text.rs | 10 ++++----- 5 files changed, 29 insertions(+), 30 deletions(-) diff --git a/zellij-server/src/ui/components/mod.rs b/zellij-server/src/ui/components/mod.rs index e3a4791fdb..f687b5f622 100644 --- a/zellij-server/src/ui/components/mod.rs +++ b/zellij-server/src/ui/components/mod.rs @@ -164,13 +164,13 @@ fn parse_selected(stringified: &mut String) -> bool { selected } -fn parse_transparent(stringified: &mut String) -> bool { - let mut transparent = false; +fn parse_bg_black(stringified: &mut String) -> bool { + let mut bg_black = false; if stringified.chars().next() == Some('z') { - transparent = true; + bg_black = true; stringified.remove(0); } - transparent + bg_black } fn parse_indices(stringified: &mut String) -> Vec> { diff --git a/zellij-server/src/ui/components/nested_list.rs b/zellij-server/src/ui/components/nested_list.rs index bbdcd9f16b..d5711c943d 100644 --- a/zellij-server/src/ui/components/nested_list.rs +++ b/zellij-server/src/ui/components/nested_list.rs @@ -1,5 +1,5 @@ use super::{ - is_too_high, parse_indices, parse_selected, parse_text, parse_transparent, stringify_text, + is_too_high, parse_bg_black, parse_indices, parse_selected, parse_text, stringify_text, Coordinates, Text, }; use crate::panes::terminal_character::{AnsiCode, RESET_STYLES}; @@ -36,20 +36,20 @@ pub fn nested_list( } else { "- " }; - let text_style = if line_item.text.transparent { + let text_style = if line_item.text.selected { reset_styles_for_item .bold(Some(AnsiCode::On)) .foreground(Some(style.colors.white.into())) - } else if line_item.text.selected { + .background(Some(style.colors.bg.into())) + } else if line_item.text.bg_black { reset_styles_for_item .bold(Some(AnsiCode::On)) .foreground(Some(style.colors.white.into())) - .background(Some(style.colors.bg.into())) + .background(Some(style.colors.black.into())) } else { reset_styles_for_item .bold(Some(AnsiCode::On)) .foreground(Some(style.colors.white.into())) - .background(Some(style.colors.black.into())) }; let (mut text, text_width) = stringify_text( &line_item.text, @@ -70,16 +70,16 @@ pub fn nested_list( "".to_owned() } }); - let line_style = if line_item.text.transparent { - RESET_STYLES.foreground(Some(style.colors.white.into())) - } else if line_item.text.selected { + let line_style = if line_item.text.selected { RESET_STYLES .foreground(Some(style.colors.white.into())) .background(Some(style.colors.bg.into())) - } else { + } else if line_item.text.bg_black { RESET_STYLES .foreground(Some(style.colors.white.into())) .background(Some(style.colors.black.into())) + } else { + RESET_STYLES.foreground(Some(style.colors.white.into())) }; stringified.push_str(&format!( "{}{}{}{:padding$}{bulletin}{}{text}{}", @@ -96,12 +96,12 @@ pub fn parse_nested_list_items<'a>( .flat_map(|mut stringified| { let indentation_level = parse_indentation_level(&mut stringified); let selected = parse_selected(&mut stringified); - let transparent = parse_transparent(&mut stringified); + let bg_black = parse_bg_black(&mut stringified); let indices = parse_indices(&mut stringified); let text = parse_text(&mut stringified).map_err(|e| e.to_string())?; let text = Text { text, - transparent, + bg_black, selected, indices, }; diff --git a/zellij-server/src/ui/components/text.rs b/zellij-server/src/ui/components/text.rs index 1b59f43d78..8d75cc38dc 100644 --- a/zellij-server/src/ui/components/text.rs +++ b/zellij-server/src/ui/components/text.rs @@ -1,6 +1,6 @@ use super::{ emphasis_variants_for_ribbon, emphasis_variants_for_selected_ribbon, is_too_wide, - parse_indices, parse_selected, parse_transparent, Coordinates, + parse_bg_black, parse_indices, parse_selected, Coordinates, }; use crate::panes::terminal_character::{AnsiCode, CharacterStyles, RESET_STYLES}; use zellij_utils::{ @@ -14,11 +14,10 @@ use zellij_utils::errors::prelude::*; pub fn text(content: Text, style: &Style, component_coordinates: Option) -> Vec { let mut text_style = RESET_STYLES .bold(Some(AnsiCode::On)) - .foreground(Some(style.colors.white.into())) - .background(Some(style.colors.black.into())); + .foreground(Some(style.colors.white.into())); - if content.transparent { - text_style = text_style.background(None); + if content.bg_black { + text_style = text_style.background(Some(style.colors.black.into())); } if content.selected { @@ -105,12 +104,12 @@ pub fn parse_text_params<'a>(params_iter: impl Iterator) params_iter .flat_map(|mut stringified| { let selected = parse_selected(&mut stringified); - let transparent = parse_transparent(&mut stringified); + let bg_black = parse_bg_black(&mut stringified); let indices = parse_indices(&mut stringified); let text = parse_text(&mut stringified).map_err(|e| e.to_string())?; Ok::(Text { text, - transparent, + bg_black, selected, indices, }) @@ -122,7 +121,7 @@ pub fn parse_text_params<'a>(params_iter: impl Iterator) pub struct Text { pub text: String, pub selected: bool, - pub transparent: bool, + pub bg_black: bool, pub indices: Vec>, } diff --git a/zellij-tile/src/ui_components/nested_list.rs b/zellij-tile/src/ui_components/nested_list.rs index 779a12a929..e0fbb55961 100644 --- a/zellij-tile/src/ui_components/nested_list.rs +++ b/zellij-tile/src/ui_components/nested_list.rs @@ -26,8 +26,8 @@ impl NestedListItem { self.content = self.content.selected(); self } - pub fn transparent(mut self) -> Self { - self.content = self.content.transparent(); + pub fn bg_black(mut self) -> Self { + self.content = self.content.bg_black(); self } pub fn color_indices(mut self, index_level: usize, indices: Vec) -> Self { diff --git a/zellij-tile/src/ui_components/text.rs b/zellij-tile/src/ui_components/text.rs index c936c4b7c3..64544147e1 100644 --- a/zellij-tile/src/ui_components/text.rs +++ b/zellij-tile/src/ui_components/text.rs @@ -5,7 +5,7 @@ use std::ops::RangeBounds; pub struct Text { text: String, selected: bool, - transparent: bool, + bg_black: bool, indices: Vec>, } @@ -17,7 +17,7 @@ impl Text { Text { text: content.to_string(), selected: false, - transparent: false, + bg_black: false, indices: vec![], } } @@ -25,8 +25,8 @@ impl Text { self.selected = true; self } - pub fn transparent(mut self) -> Self { - self.transparent = true; + pub fn bg_black(mut self) -> Self { + self.bg_black = true; self } pub fn color_indices(mut self, index_level: usize, mut indices: Vec) -> Self { @@ -87,7 +87,7 @@ impl Text { prefix = format!("x{}", prefix); } - if self.transparent { + if self.bg_black { prefix = format!("z{}", prefix); } From 731249f0dddbe01e8d80769a8e7b0c2a0f81c99a Mon Sep 17 00:00:00 2001 From: Daniel Jankowski Date: Fri, 18 Oct 2024 17:30:58 +0200 Subject: [PATCH 04/13] feat: implement bg_black handling for table cells --- zellij-server/src/ui/components/table.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/zellij-server/src/ui/components/table.rs b/zellij-server/src/ui/components/table.rs index 1974f2d916..4dc1b8914d 100644 --- a/zellij-server/src/ui/components/table.rs +++ b/zellij-server/src/ui/components/table.rs @@ -37,6 +37,9 @@ pub fn table( if cell.selected { reset_styles_for_item.background = None; text_style = text_style.background(Some(style.colors.bg.into())); + } else if cell.bg_black { + reset_styles_for_item.background = None; + text_style = text_style.background(Some(style.colors.black.into())); } // here we intentionally don't pass our coordinates even if we have them, because // these cells have already been padded and truncated From dc4b9d8b71e7e8edc837c643e8a4b13a70e79f9b Mon Sep 17 00:00:00 2001 From: Daniel Jankowski Date: Fri, 18 Oct 2024 18:18:06 +0200 Subject: [PATCH 05/13] fix: order of selected and bg_black in protocol --- zellij-tile/src/ui_components/text.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/zellij-tile/src/ui_components/text.rs b/zellij-tile/src/ui_components/text.rs index 64544147e1..8bf2f3f699 100644 --- a/zellij-tile/src/ui_components/text.rs +++ b/zellij-tile/src/ui_components/text.rs @@ -83,14 +83,15 @@ impl Text { } let mut prefix = "".to_owned(); - if self.selected { - prefix = format!("x{}", prefix); - } if self.bg_black { prefix = format!("z{}", prefix); } + if self.selected { + prefix = format!("x{}", prefix); + } + format!("{}{}{}", prefix, indices, text) } } From cc6b42231f3b44264e6e4bbb378384f1fdc95574 Mon Sep 17 00:00:00 2001 From: Daniel Jankowski Date: Wed, 23 Oct 2024 09:56:54 +0200 Subject: [PATCH 06/13] chore: rename from bg_black to opaque --- zellij-server/src/ui/components/mod.rs | 8 ++++---- zellij-server/src/ui/components/nested_list.rs | 10 +++++----- zellij-server/src/ui/components/table.rs | 2 +- zellij-server/src/ui/components/text.rs | 10 +++++----- zellij-tile/src/ui_components/nested_list.rs | 4 ++-- zellij-tile/src/ui_components/text.rs | 10 +++++----- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/zellij-server/src/ui/components/mod.rs b/zellij-server/src/ui/components/mod.rs index f687b5f622..260e2c2a60 100644 --- a/zellij-server/src/ui/components/mod.rs +++ b/zellij-server/src/ui/components/mod.rs @@ -164,13 +164,13 @@ fn parse_selected(stringified: &mut String) -> bool { selected } -fn parse_bg_black(stringified: &mut String) -> bool { - let mut bg_black = false; +fn parse_opaque(stringified: &mut String) -> bool { + let mut opaque = false; if stringified.chars().next() == Some('z') { - bg_black = true; + opaque = true; stringified.remove(0); } - bg_black + opaque } fn parse_indices(stringified: &mut String) -> Vec> { diff --git a/zellij-server/src/ui/components/nested_list.rs b/zellij-server/src/ui/components/nested_list.rs index d5711c943d..fa136761bd 100644 --- a/zellij-server/src/ui/components/nested_list.rs +++ b/zellij-server/src/ui/components/nested_list.rs @@ -1,5 +1,5 @@ use super::{ - is_too_high, parse_bg_black, parse_indices, parse_selected, parse_text, stringify_text, + is_too_high, parse_opaque, parse_indices, parse_selected, parse_text, stringify_text, Coordinates, Text, }; use crate::panes::terminal_character::{AnsiCode, RESET_STYLES}; @@ -41,7 +41,7 @@ pub fn nested_list( .bold(Some(AnsiCode::On)) .foreground(Some(style.colors.white.into())) .background(Some(style.colors.bg.into())) - } else if line_item.text.bg_black { + } else if line_item.text.opaque { reset_styles_for_item .bold(Some(AnsiCode::On)) .foreground(Some(style.colors.white.into())) @@ -74,7 +74,7 @@ pub fn nested_list( RESET_STYLES .foreground(Some(style.colors.white.into())) .background(Some(style.colors.bg.into())) - } else if line_item.text.bg_black { + } else if line_item.text.opaque { RESET_STYLES .foreground(Some(style.colors.white.into())) .background(Some(style.colors.black.into())) @@ -96,12 +96,12 @@ pub fn parse_nested_list_items<'a>( .flat_map(|mut stringified| { let indentation_level = parse_indentation_level(&mut stringified); let selected = parse_selected(&mut stringified); - let bg_black = parse_bg_black(&mut stringified); + let opaque = parse_opaque(&mut stringified); let indices = parse_indices(&mut stringified); let text = parse_text(&mut stringified).map_err(|e| e.to_string())?; let text = Text { text, - bg_black, + opaque, selected, indices, }; diff --git a/zellij-server/src/ui/components/table.rs b/zellij-server/src/ui/components/table.rs index 4dc1b8914d..cdb664556b 100644 --- a/zellij-server/src/ui/components/table.rs +++ b/zellij-server/src/ui/components/table.rs @@ -37,7 +37,7 @@ pub fn table( if cell.selected { reset_styles_for_item.background = None; text_style = text_style.background(Some(style.colors.bg.into())); - } else if cell.bg_black { + } else if cell.opaque { reset_styles_for_item.background = None; text_style = text_style.background(Some(style.colors.black.into())); } diff --git a/zellij-server/src/ui/components/text.rs b/zellij-server/src/ui/components/text.rs index 8d75cc38dc..9449f74d72 100644 --- a/zellij-server/src/ui/components/text.rs +++ b/zellij-server/src/ui/components/text.rs @@ -1,6 +1,6 @@ use super::{ emphasis_variants_for_ribbon, emphasis_variants_for_selected_ribbon, is_too_wide, - parse_bg_black, parse_indices, parse_selected, Coordinates, + parse_opaque, parse_indices, parse_selected, Coordinates, }; use crate::panes::terminal_character::{AnsiCode, CharacterStyles, RESET_STYLES}; use zellij_utils::{ @@ -16,7 +16,7 @@ pub fn text(content: Text, style: &Style, component_coordinates: Option(params_iter: impl Iterator) params_iter .flat_map(|mut stringified| { let selected = parse_selected(&mut stringified); - let bg_black = parse_bg_black(&mut stringified); + let opaque = parse_opaque(&mut stringified); let indices = parse_indices(&mut stringified); let text = parse_text(&mut stringified).map_err(|e| e.to_string())?; Ok::(Text { text, - bg_black, + opaque, selected, indices, }) @@ -121,7 +121,7 @@ pub fn parse_text_params<'a>(params_iter: impl Iterator) pub struct Text { pub text: String, pub selected: bool, - pub bg_black: bool, + pub opaque: bool, pub indices: Vec>, } diff --git a/zellij-tile/src/ui_components/nested_list.rs b/zellij-tile/src/ui_components/nested_list.rs index e0fbb55961..f9a31632b8 100644 --- a/zellij-tile/src/ui_components/nested_list.rs +++ b/zellij-tile/src/ui_components/nested_list.rs @@ -26,8 +26,8 @@ impl NestedListItem { self.content = self.content.selected(); self } - pub fn bg_black(mut self) -> Self { - self.content = self.content.bg_black(); + pub fn opaque(mut self) -> Self { + self.content = self.content.opaque(); self } pub fn color_indices(mut self, index_level: usize, indices: Vec) -> Self { diff --git a/zellij-tile/src/ui_components/text.rs b/zellij-tile/src/ui_components/text.rs index 8bf2f3f699..3bd7857efc 100644 --- a/zellij-tile/src/ui_components/text.rs +++ b/zellij-tile/src/ui_components/text.rs @@ -5,7 +5,7 @@ use std::ops::RangeBounds; pub struct Text { text: String, selected: bool, - bg_black: bool, + opaque: bool, indices: Vec>, } @@ -17,7 +17,7 @@ impl Text { Text { text: content.to_string(), selected: false, - bg_black: false, + opaque: false, indices: vec![], } } @@ -25,8 +25,8 @@ impl Text { self.selected = true; self } - pub fn bg_black(mut self) -> Self { - self.bg_black = true; + pub fn opaque(mut self) -> Self { + self.opaque = true; self } pub fn color_indices(mut self, index_level: usize, mut indices: Vec) -> Self { @@ -84,7 +84,7 @@ impl Text { let mut prefix = "".to_owned(); - if self.bg_black { + if self.opaque { prefix = format!("z{}", prefix); } From 954e4d4ab8428a705ccafd95451bdf71766aa894 Mon Sep 17 00:00:00 2001 From: Daniel Jankowski Date: Wed, 23 Oct 2024 10:00:25 +0200 Subject: [PATCH 07/13] fix: explicit selected, if opaque and selected for text --- zellij-server/src/ui/components/text.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/zellij-server/src/ui/components/text.rs b/zellij-server/src/ui/components/text.rs index 9449f74d72..a562248eca 100644 --- a/zellij-server/src/ui/components/text.rs +++ b/zellij-server/src/ui/components/text.rs @@ -16,12 +16,10 @@ pub fn text(content: Text, style: &Style, component_coordinates: Option Date: Wed, 23 Oct 2024 10:59:36 +0200 Subject: [PATCH 08/13] chore: fix formatting issues --- zellij-server/src/ui/components/nested_list.rs | 2 +- zellij-server/src/ui/components/text.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/zellij-server/src/ui/components/nested_list.rs b/zellij-server/src/ui/components/nested_list.rs index fa136761bd..4d32141441 100644 --- a/zellij-server/src/ui/components/nested_list.rs +++ b/zellij-server/src/ui/components/nested_list.rs @@ -1,5 +1,5 @@ use super::{ - is_too_high, parse_opaque, parse_indices, parse_selected, parse_text, stringify_text, + is_too_high, parse_indices, parse_opaque, parse_selected, parse_text, stringify_text, Coordinates, Text, }; use crate::panes::terminal_character::{AnsiCode, RESET_STYLES}; diff --git a/zellij-server/src/ui/components/text.rs b/zellij-server/src/ui/components/text.rs index a562248eca..b7f95aa036 100644 --- a/zellij-server/src/ui/components/text.rs +++ b/zellij-server/src/ui/components/text.rs @@ -1,6 +1,6 @@ use super::{ emphasis_variants_for_ribbon, emphasis_variants_for_selected_ribbon, is_too_wide, - parse_opaque, parse_indices, parse_selected, Coordinates, + parse_indices, parse_opaque, parse_selected, Coordinates, }; use crate::panes::terminal_character::{AnsiCode, CharacterStyles, RESET_STYLES}; use zellij_utils::{ From 2a85e2e1c8f840d6af1a38a765b5f7efef65c4c0 Mon Sep 17 00:00:00 2001 From: Daniel Jankowski Date: Wed, 23 Oct 2024 12:41:05 +0200 Subject: [PATCH 09/13] feat: opaque tab-bar --- default-plugins/tab-bar/src/line.rs | 18 +++++++++++++++--- default-plugins/tab-bar/src/main.rs | 11 +++++++---- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/default-plugins/tab-bar/src/line.rs b/default-plugins/tab-bar/src/line.rs index 349981f4d8..9384eaf18a 100644 --- a/default-plugins/tab-bar/src/line.rs +++ b/default-plugins/tab-bar/src/line.rs @@ -232,6 +232,7 @@ pub fn tab_line( tab_info: Option<&TabInfo>, mode_info: &ModeInfo, hide_swap_layout_indicator: bool, + background: &PaletteColor, ) -> Vec { let mut tabs_after_active = all_tabs.split_off(active_tab_index); let mut tabs_before_active = all_tabs; @@ -278,6 +279,14 @@ pub fn tab_line( capabilities, ); prefix.append(&mut tabs_to_render); + prefix.append(&mut vec![LinePart { + part: match background { + PaletteColor::Rgb((r, g, b)) => format!("\u{1b}[48;2;{};{};{}m\u{1b}[0K", r, g, b), + PaletteColor::EightBit(color) => format!("\u{1b}[48;5;{}m\u{1b}[0K", color), + }, + len: 0, + tab_index: None, + }]); if let Some(mut swap_layout_indicator) = swap_layout_indicator.take() { let remaining_space = cols @@ -382,9 +391,11 @@ pub fn style_key_with_modifier(keyvec: &[KeyWithModifier], color_index: Option self.mode_info.style.colors.black, + ThemeHue::Light => self.mode_info.style.colors.white, + }; + self.tab_line = tab_line( self.mode_info.session_name.as_deref(), all_tabs, @@ -135,6 +141,7 @@ impl ZellijPlugin for State { self.tabs.iter().find(|t| t.active), &self.mode_info, self.hide_swap_layout_indication, + &background, ); let output = self @@ -142,10 +149,6 @@ impl ZellijPlugin for State { .iter() .fold(String::new(), |output, part| output + &part.part); - let background = match self.mode_info.style.colors.theme_hue { - ThemeHue::Dark => self.mode_info.style.colors.black, - ThemeHue::Light => self.mode_info.style.colors.white, - }; match background { PaletteColor::Rgb((r, g, b)) => { print!("{}\u{1b}[48;2;{};{};{}m\u{1b}[0K", output, r, g, b); From 60116ead56bdfbf22a18c9a485ce49720b09bb8c Mon Sep 17 00:00:00 2001 From: Daniel Jankowski Date: Wed, 23 Oct 2024 13:37:36 +0200 Subject: [PATCH 10/13] feat: opaque session-manager bars --- default-plugins/session-manager/src/main.rs | 13 +++++++++- .../session-manager/src/ui/components.rs | 25 ++++++++++++++++--- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/default-plugins/session-manager/src/main.rs b/default-plugins/session-manager/src/main.rs index 9aebb6df52..3d4848af6d 100644 --- a/default-plugins/session-manager/src/main.rs +++ b/default-plugins/session-manager/src/main.rs @@ -122,10 +122,21 @@ impl ZellijPlugin for State { fn render(&mut self, rows: usize, cols: usize) { let (x, y, width, height) = self.main_menu_size(rows, cols); + let background = match self.colors.palette.theme_hue { + ThemeHue::Dark => self.colors.palette.black, + ThemeHue::Light => self.colors.palette.white, + }; + if self.is_welcome_screen { render_banner(x, 0, rows.saturating_sub(height), width); } - render_screen_toggle(self.active_screen, x, y, width.saturating_sub(2)); + render_screen_toggle( + self.active_screen, + x, + y, + width.saturating_sub(2), + &background, + ); match self.active_screen { ActiveScreen::NewSession => { diff --git a/default-plugins/session-manager/src/ui/components.rs b/default-plugins/session-manager/src/ui/components.rs index 5c265f5426..8bc09c2406 100644 --- a/default-plugins/session-manager/src/ui/components.rs +++ b/default-plugins/session-manager/src/ui/components.rs @@ -507,10 +507,22 @@ pub fn minimize_lines( pub fn render_prompt(search_term: &str, colors: Colors, x: usize, y: usize) { let prompt = colors.green(&format!("Search:")); let search_term = colors.bold(&format!("{}_", search_term)); - println!("\u{1b}[{};{}H{} {}\n", y + 1, x, prompt, search_term); + println!( + "\u{1b}[{};{}H\u{1b}[0m{} {}\n", + y + 1, + x, + prompt, + search_term + ); } -pub fn render_screen_toggle(active_screen: ActiveScreen, x: usize, y: usize, max_cols: usize) { +pub fn render_screen_toggle( + active_screen: ActiveScreen, + x: usize, + y: usize, + max_cols: usize, + background: &PaletteColor, +) { let key_indication_text = ""; let (new_session_text, running_sessions_text, exited_sessions_text) = if max_cols > 66 { ("New Session", "Attach to Session", "Resurrect Session") @@ -520,10 +532,12 @@ pub fn render_screen_toggle(active_screen: ActiveScreen, x: usize, y: usize, max let key_indication_len = key_indication_text.chars().count() + 1; let first_ribbon_length = new_session_text.chars().count() + 4; let second_ribbon_length = running_sessions_text.chars().count() + 4; + let third_ribbon_length = exited_sessions_text.chars().count() + 4; let key_indication_x = x; let first_ribbon_x = key_indication_x + key_indication_len; let second_ribbon_x = first_ribbon_x + first_ribbon_length; let third_ribbon_x = second_ribbon_x + second_ribbon_length; + let reset_x = third_ribbon_x + third_ribbon_length + 1; let mut new_session_text = Text::new(new_session_text); let mut running_sessions_text = Text::new(running_sessions_text); let mut exited_sessions_text = Text::new(exited_sessions_text); @@ -538,13 +552,18 @@ pub fn render_screen_toggle(active_screen: ActiveScreen, x: usize, y: usize, max exited_sessions_text = exited_sessions_text.selected(); }, } + let bg_color = match background { + PaletteColor::Rgb((r, g, b)) => format!("\u{1b}[48;2;{};{};{}m\u{1b}[0K", r, g, b), + PaletteColor::EightBit(color) => format!("\u{1b}[48;5;{}m\u{1b}[0K", color), + }; print_text_with_coordinates( - Text::new(key_indication_text).color_range(3, ..), + Text::new(key_indication_text).color_range(3, ..).opaque(), key_indication_x, y, None, None, ); + println!("\u{1b}[{};{}H{}", y + 1, first_ribbon_x, bg_color); print_ribbon_with_coordinates(new_session_text, first_ribbon_x, y, None, None); print_ribbon_with_coordinates(running_sessions_text, second_ribbon_x, y, None, None); print_ribbon_with_coordinates(exited_sessions_text, third_ribbon_x, y, None, None); From 2dd3eec3373d5069197df27c5e9012031b10533c Mon Sep 17 00:00:00 2001 From: Daniel Jankowski Date: Wed, 23 Oct 2024 14:13:32 +0200 Subject: [PATCH 11/13] feat: opaque ribbon in plugin manager --- default-plugins/plugin-manager/src/main.rs | 32 ++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/default-plugins/plugin-manager/src/main.rs b/default-plugins/plugin-manager/src/main.rs index 7cd5e5c4a2..92fa43694b 100644 --- a/default-plugins/plugin-manager/src/main.rs +++ b/default-plugins/plugin-manager/src/main.rs @@ -34,6 +34,7 @@ pub struct NewPluginScreen { selected_config_index: Option, request_ids: Vec, load_in_background: bool, + colors: Palette, } impl Default for NewPluginScreen { @@ -49,11 +50,19 @@ impl Default for NewPluginScreen { selected_config_index: None, request_ids: vec![], load_in_background: true, + colors: Palette::default(), } } } impl NewPluginScreen { + pub fn new(colors: Palette) -> Self { + Self { + colors, + ..Default::default() + } + } + pub fn render(&self, rows: usize, cols: usize) { self.render_title(cols); self.render_url_field(cols); @@ -246,12 +255,26 @@ impl NewPluginScreen { fn render_background_toggle(&self, y_coordinates: usize) { let key_shortcuts_text = format!("Ctrl l"); print_text_with_coordinates( - Text::new(&key_shortcuts_text).color_range(3, ..), + Text::new(&key_shortcuts_text).color_range(3, ..).opaque(), 0, y_coordinates, None, None, ); + let background = match self.colors.theme_hue { + ThemeHue::Dark => self.colors.black, + ThemeHue::Light => self.colors.white, + }; + let bg_color = match background { + PaletteColor::Rgb((r, g, b)) => format!("\u{1b}[48;2;{};{};{}m\u{1b}[0K", r, g, b), + PaletteColor::EightBit(color) => format!("\u{1b}[48;5;{}m\u{1b}[0K", color), + }; + println!( + "\u{1b}[{};{}H{}", + y_coordinates + 1, + key_shortcuts_text.chars().count() + 1, + bg_color + ); let load_in_background_text = format!("Load in Background"); let load_in_foreground_text = format!("Load in Foreground"); let (load_in_background_ribbon, load_in_foreground_ribbon) = if self.load_in_background { @@ -473,6 +496,7 @@ struct State { plugin_id_to_tab_position: HashMap, search_term: String, new_plugin_screen: Option, + colors: Palette, } register_plugin!(State); @@ -524,6 +548,10 @@ impl ZellijPlugin for State { fn update(&mut self, event: Event) -> bool { let mut should_render = false; match event { + Event::ModeUpdate(mode_info) => { + self.colors = mode_info.style.colors; + should_render = true; + }, Event::SessionUpdate(live_sessions, _dead_sessions) => { for session in live_sessions { if session.is_current_session { @@ -990,7 +1018,7 @@ impl State { self.reload_selected(); }, BareKey::Insert if key.has_no_modifiers() => { - self.new_plugin_screen = Some(Default::default()); + self.new_plugin_screen = Some(NewPluginScreen::new(self.colors)); should_render = true; }, BareKey::Delete if key.has_no_modifiers() => { From 7d6c1b674f0e4e6762418ba6adbd9bb8107c6101 Mon Sep 17 00:00:00 2001 From: Daniel Jankowski Date: Thu, 24 Oct 2024 10:37:58 +0200 Subject: [PATCH 12/13] feat: opaque one-line ui --- default-plugins/status-bar/src/main.rs | 19 ++++++++++++------- default-plugins/status-bar/src/one_line_ui.rs | 13 ++++++++----- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/default-plugins/status-bar/src/main.rs b/default-plugins/status-bar/src/main.rs index 7db9b09d97..939a923c60 100644 --- a/default-plugins/status-bar/src/main.rs +++ b/default-plugins/status-bar/src/main.rs @@ -253,17 +253,27 @@ impl ZellijPlugin for State { "" }; + let background = match self.mode_info.style.colors.theme_hue { + ThemeHue::Dark => self.mode_info.style.colors.black, + ThemeHue::Light => self.mode_info.style.colors.white, + }; + if rows == 1 && !self.classic_ui { + let fill_bg = match background { + PaletteColor::Rgb((r, g, b)) => format!("\u{1b}[48;2;{};{};{}m\u{1b}[0K", r, g, b), + PaletteColor::EightBit(color) => format!("\u{1b}[48;5;{}m\u{1b}[0K", color), + }; let active_tab = self.tabs.iter().find(|t| t.active); print!( - "{}", + "{}{}", one_line_ui( &self.mode_info, active_tab, cols, separator, self.base_mode_is_locked - ) + ), + fill_bg, ); return; } @@ -272,11 +282,6 @@ impl ZellijPlugin for State { let first_line = first_line(&self.mode_info, active_tab, cols, separator); let second_line = self.second_line(cols); - let background = match self.mode_info.style.colors.theme_hue { - ThemeHue::Dark => self.mode_info.style.colors.black, - ThemeHue::Light => self.mode_info.style.colors.white, - }; - // [48;5;238m is white background, [0K is so that it fills the rest of the line // [m is background reset, [0K is so that it clears the rest of the line match background { diff --git a/default-plugins/status-bar/src/one_line_ui.rs b/default-plugins/status-bar/src/one_line_ui.rs index 571cdfa69e..72d9f0b926 100644 --- a/default-plugins/status-bar/src/one_line_ui.rs +++ b/default-plugins/status-bar/src/one_line_ui.rs @@ -641,7 +641,7 @@ fn render_common_modifiers( line_part_to_render.part = format!( "{}{}{}", line_part_to_render.part, - serialize_text(&Text::new(&prefix_text)), + serialize_text(&Text::new(&prefix_text).opaque()), suffix_separator ); line_part_to_render.len += prefix_text.chars().count() + separator.chars().count(); @@ -899,7 +899,7 @@ fn secondary_keybinds(help: &ModeInfo, tab_info: Option<&TabInfo>, max_len: usiz } fn text_as_line_part_with_emphasis(text: String, emphases_index: usize) -> LinePart { - let part = serialize_text(&Text::new(&text).color_range(emphases_index, ..)); + let part = serialize_text(&Text::new(&text).color_range(emphases_index, ..).opaque()); LinePart { part, len: text.width(), @@ -1436,9 +1436,11 @@ fn style_key_with_modifier(keyvec: &[KeyWithModifier], color_index: Option Date: Thu, 24 Oct 2024 10:59:22 +0200 Subject: [PATCH 13/13] feat: opaque tab-bar in configuration plugin --- default-plugins/configuration/src/main.rs | 5 ++++- default-plugins/configuration/src/ui_components.rs | 13 +++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/default-plugins/configuration/src/main.rs b/default-plugins/configuration/src/main.rs index 67c7577be5..afc08bf533 100644 --- a/default-plugins/configuration/src/main.rs +++ b/default-plugins/configuration/src/main.rs @@ -71,6 +71,7 @@ struct State { ui_size: usize, current_screen: Screen, latest_mode_info: Option, + colors: Palette, } impl Default for State { @@ -81,6 +82,7 @@ impl Default for State { ui_size: UI_SIZE, current_screen: Screen::default(), latest_mode_info: None, + colors: Palette::default(), } } } @@ -114,6 +116,7 @@ impl ZellijPlugin for State { let mut should_render = false; match event { Event::ModeUpdate(mode_info) => { + self.colors = mode_info.style.colors; if self.latest_mode_info.as_ref().and_then(|l| l.base_mode) != mode_info.base_mode { // reset ui state self.current_screen.reset_state(self.is_setup_wizard); @@ -168,7 +171,7 @@ impl ZellijPlugin for State { fn render(&mut self, rows: usize, cols: usize) { let notification = self.notification.clone(); if self.is_in_main_screen() { - top_tab_menu(cols, &self.current_screen); + top_tab_menu(cols, &self.current_screen, &self.colors); } match &mut self.current_screen { Screen::RebindLeaders(rebind_leaders_screen) => { diff --git a/default-plugins/configuration/src/ui_components.rs b/default-plugins/configuration/src/ui_components.rs index 3cbdf76c16..d34488d44c 100644 --- a/default-plugins/configuration/src/ui_components.rs +++ b/default-plugins/configuration/src/ui_components.rs @@ -1,7 +1,15 @@ use crate::{Screen, WIDTH_BREAKPOINTS}; use zellij_tile::prelude::*; -pub fn top_tab_menu(cols: usize, current_screen: &Screen) { +pub fn top_tab_menu(cols: usize, current_screen: &Screen, colors: &Palette) { + let background = match colors.theme_hue { + ThemeHue::Dark => colors.black, + ThemeHue::Light => colors.white, + }; + let bg_color = match background { + PaletteColor::Rgb((r, g, b)) => format!("\u{1b}[48;2;{};{};{}m\u{1b}[0K", r, g, b), + PaletteColor::EightBit(color) => format!("\u{1b}[48;5;{}m\u{1b}[0K", color), + }; let first_ribbon_text_long = "Rebind leader keys"; let second_ribbon_text_long = "Change mode behavior"; let first_ribbon_text_short = "Rebind keys"; @@ -25,8 +33,9 @@ pub fn top_tab_menu(cols: usize, current_screen: &Screen) { if second_ribbon_is_selected { second_ribbon = second_ribbon.selected(); } - let switch_key = Text::new("").color_range(3, ..); + let switch_key = Text::new("").color_range(3, ..).opaque(); print_text_with_coordinates(switch_key, 0, 0, None, None); + print!("\u{1b}[{};{}H{}", 0, starting_positions.0 - 1, bg_color); print_ribbon_with_coordinates(first_ribbon, starting_positions.0, 0, None, None); print_ribbon_with_coordinates(second_ribbon, starting_positions.1, 0, None, None); }