Fixed cursor blinking, added other cursor shape rendering

This commit is contained in:
Mikayla Maki 2022-08-18 11:28:18 -07:00
parent acce0042f9
commit 6652d41864
6 changed files with 70 additions and 65 deletions

View file

@ -645,54 +645,59 @@ impl Element for TerminalEl {
selection,
);
//Layout cursor
let cursor = {
if self.cursor_visible {
let cursor_point = DisplayCursor::from(cursor.point, display_offset);
let cursor_text = {
let str_trxt = cursor_text.to_string();
//Layout cursor. Rectangle is used for IME, so we should lay it out even
//if we don't end up showing it.
let cursor = if let alacritty_terminal::ansi::CursorShape::Hidden = cursor.shape {
None
} else {
let cursor_point = DisplayCursor::from(cursor.point, display_offset);
let cursor_text = {
let str_trxt = cursor_text.to_string();
let color = if self.focused {
terminal_theme.colors.background
} else {
terminal_theme.colors.foreground
};
cx.text_layout_cache.layout_str(
&str_trxt,
text_style.font_size,
&[(
str_trxt.len(),
RunStyle {
font_id: text_style.font_id,
color,
underline: Default::default(),
},
)],
)
let color = if self.focused {
terminal_theme.colors.background
} else {
terminal_theme.colors.foreground
};
TerminalEl::shape_cursor(cursor_point, dimensions, &cursor_text).map(
move |(cursor_position, block_width)| {
let shape = if self.focused {
CursorShape::Block
} else {
CursorShape::Hollow
};
Cursor::new(
cursor_position,
block_width,
dimensions.line_height,
terminal_theme.colors.cursor,
shape,
Some(cursor_text),
)
},
cx.text_layout_cache.layout_str(
&str_trxt,
text_style.font_size,
&[(
str_trxt.len(),
RunStyle {
font_id: text_style.font_id,
color,
underline: Default::default(),
},
)],
)
} else {
None
}
};
TerminalEl::shape_cursor(cursor_point, dimensions, &cursor_text).map(
move |(cursor_position, block_width)| {
let shape = match cursor.shape {
alacritty_terminal::ansi::CursorShape::Block if !self.focused => {
CursorShape::Hollow
}
alacritty_terminal::ansi::CursorShape::Block => CursorShape::Block,
alacritty_terminal::ansi::CursorShape::Underline => CursorShape::Underscore,
alacritty_terminal::ansi::CursorShape::Beam => CursorShape::Bar,
alacritty_terminal::ansi::CursorShape::HollowBlock => CursorShape::Hollow,
//This case is handled in the wrapping if
alacritty_terminal::ansi::CursorShape::Hidden => CursorShape::Block,
};
Cursor::new(
cursor_position,
block_width,
dimensions.line_height,
terminal_theme.colors.cursor,
shape,
Some(cursor_text),
)
},
)
};
//Done!
@ -783,10 +788,12 @@ impl Element for TerminalEl {
});
//Draw cursor
if let Some(cursor) = &layout.cursor {
cx.paint_layer(clip_bounds, |cx| {
cursor.paint(origin, cx);
})
if self.cursor_visible {
if let Some(cursor) = &layout.cursor {
cx.paint_layer(clip_bounds, |cx| {
cursor.paint(origin, cx);
})
}
}
});
}

View file

@ -141,13 +141,17 @@ impl ConnectedView {
}
fn show_character_palette(&mut self, _: &ShowCharacterPalette, cx: &mut ViewContext<Self>) {
if self
if !self
.terminal
.read(cx)
.last_mode
.contains(TermMode::ALT_SCREEN)
{
cx.show_character_palette();
} else {
self.terminal
.read(cx)
.try_keystroke(&Keystroke::parse("ctrl-cmd-space").unwrap());
}
}
@ -156,8 +160,6 @@ impl ConnectedView {
cx.notify();
}
//2 -> Character palette shows up! But it's incorrectly positioned
pub fn should_show_cursor(
&self,
focused: bool,
@ -187,9 +189,9 @@ impl ConnectedView {
match setting {
//If the user requested to never blink, don't blink it.
TerminalBlink::Never => true,
TerminalBlink::Off => true,
//If the terminal is controlling it, check terminal mode
TerminalBlink::TerminalControlled | TerminalBlink::Always => self.blink_state,
TerminalBlink::TerminalControlled | TerminalBlink::On => self.blink_state,
}
}

View file

@ -297,11 +297,8 @@ impl TerminalBuilder {
let mut term = Term::new(&config, &initial_size, ZedListener(events_tx.clone()));
//Start off blinking if we need to
match blink_settings {
None | Some(TerminalBlink::TerminalControlled) | Some(TerminalBlink::Always) => {
term.set_mode(alacritty_terminal::ansi::Mode::BlinkingCursor)
}
_ => {}
if let Some(TerminalBlink::On) = blink_settings {
term.set_mode(alacritty_terminal::ansi::Mode::BlinkingCursor)
}
let term = Arc::new(FairMutex::new(term));