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 1 commit
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
Next Next commit
Add styled_underlines param to TerminalPane
  • Loading branch information
mike-lloyd03 committed Nov 7, 2023
commit 77769a8032d0b582ed58c72cf62f4e0f96dc0077
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
59 changes: 40 additions & 19 deletions zellij-server/src/panes/terminal_character.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,27 @@ impl CharacterStyles {
return None;
}

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

if new_styles.foreground == RESET_STYLES.foreground
&& new_styles.background == RESET_STYLES.background
&& new_styles.underline_color == RESET_STYLES.underline_color
&& new_styles.strike == RESET_STYLES.strike
&& new_styles.hidden == RESET_STYLES.hidden
&& new_styles.reverse == RESET_STYLES.reverse
&& new_styles.slow_blink == RESET_STYLES.slow_blink
&& new_styles.fast_blink == RESET_STYLES.fast_blink
&& new_styles.underline == RESET_STYLES.underline
&& new_styles.bold == RESET_STYLES.bold
&& new_styles.dim == RESET_STYLES.dim
&& new_styles.italic == RESET_STYLES.italic
&& new_styles.link_anchor == RESET_STYLES.link_anchor
{
*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 @@ -805,7 +823,7 @@ impl Cursor {
Cursor {
x,
y,
pending_styles: RESET_STYLES,
pending_styles: RESET_STYLES.enable_styled_underlines(true),
charsets: Default::default(),
shape: CursorShape::Initial,
}
Expand Down Expand Up @@ -846,13 +864,15 @@ pub fn render_first_run_banner(
rows: usize,
style: &Style,
run_command: Option<&RunCommand>,
enable_styled_underlines: bool,
) -> String {
let middle_row = rows / 2;
let middle_column = columns / 2;
let reset_styles = RESET_STYLES.enable_styled_underlines(enable_styled_underlines);
match run_command {
Some(run_command) => {
let bold_text = RESET_STYLES.bold(Some(AnsiCode::On));
let command_color_text = RESET_STYLES
let bold_text = reset_styles.bold(Some(AnsiCode::On));
let command_color_text = reset_styles
.foreground(Some(AnsiCode::from(style.colors.green)))
.bold(Some(AnsiCode::On));
let waiting_to_run_text = "Waiting to run: ";
Expand All @@ -867,7 +887,7 @@ pub fn render_first_run_banner(
waiting_to_run_text,
command_color_text,
command_text,
RESET_STYLES
reset_styles
);

let controls_bare_text_first_part = "<";
Expand All @@ -877,7 +897,8 @@ pub fn render_first_run_banner(
let controls_bare_text_third_part = "> drop to shell, <";
let ctrl_c_bare_text = "Ctrl-c";
let controls_bare_text_fourth_part = "> exit";
let controls_color = RESET_STYLES
let controls_color = reset_styles
.enable_styled_underlines(true)
.foreground(Some(AnsiCode::from(style.colors.orange)))
.bold(Some(AnsiCode::On));
let controls_line_length = controls_bare_text_first_part.len()
Expand All @@ -896,30 +917,30 @@ pub fn render_first_run_banner(
bold_text,
controls_color,
enter_bare_text,
RESET_STYLES,
reset_styles,
bold_text,
controls_color,
esc_bare_text,
RESET_STYLES,
reset_styles,
bold_text,
controls_color,
ctrl_c_bare_text,
RESET_STYLES,
reset_styles,
bold_text
);
format!(
"\u{1b}[?25l{}{}{}{}",
RESET_STYLES, waiting_to_run_line, controls_line, RESET_STYLES
reset_styles, waiting_to_run_line, controls_line, reset_styles
)
},
None => {
let bare_text = format!("Waiting to start...");
let bare_text_width = bare_text.width();
let column_start_postion = middle_column.saturating_sub(bare_text_width / 2);
let bold_text = RESET_STYLES.bold(Some(AnsiCode::On));
let bold_text = reset_styles.bold(Some(AnsiCode::On));
let waiting_to_run_line = format!(
"\u{1b}[?25l\u{1b}[{};{}H{}{}{}",
middle_row, column_start_postion, bold_text, bare_text, RESET_STYLES
middle_row, column_start_postion, bold_text, bare_text, reset_styles
);

let controls_bare_text_first_part = "<";
Expand All @@ -929,7 +950,7 @@ pub fn render_first_run_banner(
let controls_bare_text_third_part = "> drop to shell, <";
let ctrl_c_bare_text = "Ctrl-c";
let controls_bare_text_fourth_part = "> exit";
let controls_color = RESET_STYLES
let controls_color = reset_styles
.foreground(Some(AnsiCode::from(style.colors.orange)))
.bold(Some(AnsiCode::On));
let controls_line_length = controls_bare_text_first_part.len()
Expand All @@ -948,20 +969,20 @@ pub fn render_first_run_banner(
bold_text,
controls_color,
enter_bare_text,
RESET_STYLES,
reset_styles,
bold_text,
controls_color,
esc_bare_text,
RESET_STYLES,
reset_styles,
bold_text,
controls_color,
ctrl_c_bare_text,
RESET_STYLES,
reset_styles,
bold_text
);
format!(
"\u{1b}[?25l{}{}{}{}",
RESET_STYLES, waiting_to_run_line, controls_line, RESET_STYLES
reset_styles, waiting_to_run_line, controls_line, reset_styles
)
},
}
Expand Down
15 changes: 12 additions & 3 deletions zellij-server/src/panes/terminal_pane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ pub struct TerminalPane {
invoked_with: Option<Run>,
#[allow(dead_code)]
arrow_fonts: bool,
styled_underlines: bool,
}

impl Pane for TerminalPane {
Expand Down Expand Up @@ -789,6 +790,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 Down Expand Up @@ -828,6 +830,7 @@ impl TerminalPane {
pane_frame_color_override: None,
invoked_with,
arrow_fonts,
styled_underlines,
}
}
pub fn get_x(&self) -> usize {
Expand Down Expand Up @@ -879,10 +882,16 @@ impl TerminalPane {
let columns = self.get_content_columns();
let rows = self.get_content_rows();
let banner = match &self.is_held {
Some((_exit_status, _is_first_run, run_command)) => {
render_first_run_banner(columns, rows, &self.style, Some(run_command))
Some((_exit_status, _is_first_run, run_command)) => render_first_run_banner(
columns,
rows,
&self.style,
Some(run_command),
self.styled_underlines,
),
None => {
render_first_run_banner(columns, rows, &self.style, None, self.styled_underlines)
},
None => render_first_run_banner(columns, rows, &self.style, None),
};
self.banner = Some(banner.clone());
self.handle_pty_bytes(banner.as_bytes().to_vec());
Expand Down
2 changes: 2 additions & 0 deletions zellij-server/src/panes/unit/search_in_pane_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ fn create_pane() -> TerminalPane {
let terminal_emulator_color_codes = Rc::new(RefCell::new(HashMap::new()));
let debug = false;
let arrow_fonts = true;
let styled_underlines = true;
let mut terminal_pane = TerminalPane::new(
pid,
fake_win_size,
Expand All @@ -45,6 +46,7 @@ fn create_pane() -> TerminalPane {
None,
debug,
arrow_fonts,
styled_underlines,
); // 0 is the pane index
let content = read_fixture();
terminal_pane.handle_pty_bytes(content);
Expand Down
Loading