Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix styled underlines in editors #2918

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/tests/e2e/remote_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ fn read_from_channel(
let sixel_image_store = Rc::new(RefCell::new(SixelImageStore::default()));
let debug = false;
let arrow_fonts = true;
let styled_underlines = true;
let mut terminal_output = TerminalPane::new(
0,
pane_geom,
Expand All @@ -251,6 +252,7 @@ fn read_from_channel(
None,
debug,
arrow_fonts,
styled_underlines,
); // 0 is the pane index
loop {
if !should_keep_running.load(Ordering::SeqCst) {
Expand Down
15 changes: 10 additions & 5 deletions zellij-server/src/panes/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ pub struct Grid {
style: Style,
debug: bool,
arrow_fonts: bool,
styled_underlines: bool,
}

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -464,6 +465,7 @@ impl Grid {
style: Style, // TODO: consolidate this with terminal_emulator_colors
debug: bool,
arrow_fonts: bool,
styled_underlines: bool,
) -> Self {
let sixel_grid = SixelGrid::new(character_cell_size.clone(), sixel_image_store);
// make sure this is initialized as it is used internally
Expand All @@ -476,7 +478,7 @@ impl Grid {
viewport: vec![Row::new().canonical()],
lines_below: vec![],
horizontal_tabstops: create_horizontal_tabstops(columns),
cursor: Cursor::new(0, 0),
cursor: Cursor::new(0, 0, styled_underlines),
cursor_is_hidden: false,
saved_cursor_position: None,
scroll_region: None,
Expand Down Expand Up @@ -517,6 +519,7 @@ impl Grid {
style,
debug,
arrow_fonts,
styled_underlines,
}
}
pub fn render_full_viewport(&mut self) {
Expand Down Expand Up @@ -1688,7 +1691,7 @@ impl Grid {
self.cursor_key_mode = false;
self.scroll_region = None;
self.clear_viewport_before_rendering = true;
self.cursor = Cursor::new(0, 0);
self.cursor = Cursor::new(0, 0, self.styled_underlines);
self.saved_cursor_position = None;
self.active_charset = Default::default();
self.erasure_mode = false;
Expand Down Expand Up @@ -2132,7 +2135,7 @@ impl Grid {
self.lines_below.clear();
}
pub fn reset_cursor_position(&mut self) {
self.cursor = Cursor::new(0, 0);
self.cursor = Cursor::new(0, 0, self.styled_underlines);
}
}

Expand Down Expand Up @@ -2614,8 +2617,10 @@ impl Perform for Grid {
std::mem::replace(&mut self.lines_above, VecDeque::new());
let current_viewport =
std::mem::replace(&mut self.viewport, vec![Row::new().canonical()]);
let current_cursor =
std::mem::replace(&mut self.cursor, Cursor::new(0, 0));
let current_cursor = std::mem::replace(
&mut self.cursor,
Cursor::new(0, 0, self.styled_underlines),
);
let sixel_image_store = self.sixel_grid.sixel_image_store.clone();
let alternate_sixelgrid = std::mem::replace(
&mut self.sixel_grid,
Expand Down
4 changes: 4 additions & 0 deletions zellij-server/src/panes/plugin_pane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ macro_rules! get_or_create_grid {
$self.style.clone(),
$self.debug,
$self.arrow_fonts,
$self.styled_underlines,
);
grid.hide_cursor();
grid
Expand Down Expand Up @@ -88,6 +89,7 @@ pub(crate) struct PluginPane {
requesting_permissions: Option<PluginPermission>,
debug: bool,
arrow_fonts: bool,
styled_underlines: bool,
}

impl PluginPane {
Expand All @@ -107,6 +109,7 @@ impl PluginPane {
invoked_with: Option<Run>,
debug: bool,
arrow_fonts: bool,
styled_underlines: bool,
) -> Self {
let loading_indication = LoadingIndication::new(title.clone()).with_colors(style.colors);
let initial_loading_message = loading_indication.to_string();
Expand Down Expand Up @@ -139,6 +142,7 @@ impl PluginPane {
requesting_permissions: None,
debug,
arrow_fonts,
styled_underlines,
};
for client_id in currently_connected_clients {
plugin.handle_plugin_bytes(client_id, initial_loading_message.as_bytes().to_vec());
Expand Down
28 changes: 23 additions & 5 deletions zellij-server/src/panes/terminal_character.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl NamedColor {
}
}

#[derive(Clone, Copy, Debug, PartialEq, Default)]
#[derive(Clone, Copy, Debug, Default)]
pub struct CharacterStyles {
pub foreground: Option<AnsiCode>,
pub background: Option<AnsiCode>,
Expand All @@ -147,6 +147,24 @@ pub struct CharacterStyles {
pub styled_underlines_enabled: bool,
}

impl PartialEq for CharacterStyles {
fn eq(&self, other: &Self) -> bool {
self.foreground == other.foreground
&& self.background == other.background
&& self.underline_color == other.underline_color
&& self.strike == other.strike
&& self.hidden == other.hidden
&& self.reverse == other.reverse
&& self.slow_blink == other.slow_blink
&& self.fast_blink == other.fast_blink
&& self.underline == other.underline
&& self.bold == other.bold
&& self.dim == other.dim
&& self.italic == other.italic
&& self.link_anchor == other.link_anchor
}
}

impl CharacterStyles {
pub fn new() -> Self {
Self::default()
Expand Down Expand Up @@ -232,8 +250,8 @@ impl CharacterStyles {
}

if *new_styles == RESET_STYLES {
*self = RESET_STYLES;
return Some(RESET_STYLES);
*self = RESET_STYLES.enable_styled_underlines(self.styled_underlines_enabled);
return Some(RESET_STYLES.enable_styled_underlines(self.styled_underlines_enabled));
}

// create diff from all changed styles
Expand Down Expand Up @@ -801,11 +819,11 @@ pub struct Cursor {
}

impl Cursor {
pub fn new(x: usize, y: usize) -> Self {
pub fn new(x: usize, y: usize, styled_underlines: bool) -> Self {
Cursor {
x,
y,
pending_styles: RESET_STYLES,
pending_styles: RESET_STYLES.enable_styled_underlines(styled_underlines),
charsets: Default::default(),
shape: CursorShape::Initial,
}
Expand Down
2 changes: 2 additions & 0 deletions zellij-server/src/panes/terminal_pane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,7 @@ impl TerminalPane {
invoked_with: Option<Run>,
debug: bool,
arrow_fonts: bool,
styled_underlines: bool,
) -> TerminalPane {
let initial_pane_title =
initial_pane_title.unwrap_or_else(|| format!("Pane #{}", pane_index));
Expand All @@ -803,6 +804,7 @@ impl TerminalPane {
style.clone(),
debug,
arrow_fonts,
styled_underlines,
);
TerminalPane {
frame: HashMap::new(),
Expand Down
Loading