Skip to content

Commit

Permalink
feat: invert flag behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
dj95 committed Oct 18, 2024
1 parent 995b41d commit f36822c
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 30 deletions.
8 changes: 4 additions & 4 deletions zellij-server/src/ui/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<usize>> {
Expand Down
22 changes: 11 additions & 11 deletions zellij-server/src/ui/components/nested_list.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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,
Expand All @@ -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}{}",
Expand All @@ -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,
};
Expand Down
15 changes: 7 additions & 8 deletions zellij-server/src/ui/components/text.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand All @@ -14,11 +14,10 @@ use zellij_utils::errors::prelude::*;
pub fn text(content: Text, style: &Style, component_coordinates: Option<Coordinates>) -> Vec<u8> {
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 {
Expand Down Expand Up @@ -105,12 +104,12 @@ pub fn parse_text_params<'a>(params_iter: impl Iterator<Item = &'a mut String>)
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, String>(Text {
text,
transparent,
bg_black,
selected,
indices,
})
Expand All @@ -122,7 +121,7 @@ pub fn parse_text_params<'a>(params_iter: impl Iterator<Item = &'a mut String>)
pub struct Text {
pub text: String,
pub selected: bool,
pub transparent: bool,
pub bg_black: bool,
pub indices: Vec<Vec<usize>>,
}

Expand Down
4 changes: 2 additions & 2 deletions zellij-tile/src/ui_components/nested_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<usize>) -> Self {
Expand Down
10 changes: 5 additions & 5 deletions zellij-tile/src/ui_components/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::ops::RangeBounds;
pub struct Text {
text: String,
selected: bool,
transparent: bool,
bg_black: bool,
indices: Vec<Vec<usize>>,
}

Expand All @@ -17,16 +17,16 @@ impl Text {
Text {
text: content.to_string(),
selected: false,
transparent: false,
bg_black: false,
indices: vec![],
}
}
pub fn selected(mut self) -> Self {
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<usize>) -> Self {
Expand Down Expand Up @@ -87,7 +87,7 @@ impl Text {
prefix = format!("x{}", prefix);
}

if self.transparent {
if self.bg_black {
prefix = format!("z{}", prefix);
}

Expand Down

0 comments on commit f36822c

Please sign in to comment.