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

@ -105,12 +105,12 @@
//Set the cursor blinking behavior in the terminal. //Set the cursor blinking behavior in the terminal.
//May take 4 values: //May take 4 values:
// 1. Never blink the cursor, ignoring the terminal mode // 1. Never blink the cursor, ignoring the terminal mode
// "blinking": "never", // "blinking": "off",
// 2. Default the cursor blink to on, but allow the terminal to // 2. Default the cursor blink to off, but allow the terminal to
// turn blinking off // set blinking
// "blinking": "terminal_controlled", // "blinking": "terminal_controlled",
// 3. Always blink the cursor, ignoring the terminal mode // 3. Always blink the cursor, ignoring the terminal mode
// "blinking": "always", // "blinking": "on",
"blinking": "terminal_controlled", "blinking": "terminal_controlled",
//Any key-value pairs added to this list will be added to the terminal's //Any key-value pairs added to this list will be added to the terminal's
//enviroment. Use `:` to seperate multiple values. //enviroment. Use `:` to seperate multiple values.

View file

@ -1159,7 +1159,6 @@ extern "C" fn first_rect_for_character_range(
let window = get_window_state(this).borrow().native_window; let window = get_window_state(this).borrow().native_window;
NSView::frame(window) NSView::frame(window)
}; };
with_input_handler(this, |input_handler| { with_input_handler(this, |input_handler| {
input_handler.rect_for_range(range.to_range()?) input_handler.rect_for_range(range.to_range()?)
}) })

View file

@ -89,9 +89,9 @@ pub struct TerminalSettings {
#[derive(Clone, Debug, Deserialize, PartialEq, Eq, JsonSchema)] #[derive(Clone, Debug, Deserialize, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
pub enum TerminalBlink { pub enum TerminalBlink {
Never, Off,
TerminalControlled, TerminalControlled,
Always, On,
} }
impl Default for TerminalBlink { impl Default for TerminalBlink {

View file

@ -645,9 +645,11 @@ impl Element for TerminalEl {
selection, selection,
); );
//Layout cursor //Layout cursor. Rectangle is used for IME, so we should lay it out even
let cursor = { //if we don't end up showing it.
if self.cursor_visible { let cursor = if let alacritty_terminal::ansi::CursorShape::Hidden = cursor.shape {
None
} else {
let cursor_point = DisplayCursor::from(cursor.point, display_offset); let cursor_point = DisplayCursor::from(cursor.point, display_offset);
let cursor_text = { let cursor_text = {
let str_trxt = cursor_text.to_string(); let str_trxt = cursor_text.to_string();
@ -674,10 +676,16 @@ impl Element for TerminalEl {
TerminalEl::shape_cursor(cursor_point, dimensions, &cursor_text).map( TerminalEl::shape_cursor(cursor_point, dimensions, &cursor_text).map(
move |(cursor_position, block_width)| { move |(cursor_position, block_width)| {
let shape = if self.focused { let shape = match cursor.shape {
CursorShape::Block alacritty_terminal::ansi::CursorShape::Block if !self.focused => {
} else {
CursorShape::Hollow 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::new(
@ -690,9 +698,6 @@ impl Element for TerminalEl {
) )
}, },
) )
} else {
None
}
}; };
//Done! //Done!
@ -783,11 +788,13 @@ impl Element for TerminalEl {
}); });
//Draw cursor //Draw cursor
if self.cursor_visible {
if let Some(cursor) = &layout.cursor { if let Some(cursor) = &layout.cursor {
cx.paint_layer(clip_bounds, |cx| { cx.paint_layer(clip_bounds, |cx| {
cursor.paint(origin, cx); cursor.paint(origin, cx);
}) })
} }
}
}); });
} }

View file

@ -141,13 +141,17 @@ impl ConnectedView {
} }
fn show_character_palette(&mut self, _: &ShowCharacterPalette, cx: &mut ViewContext<Self>) { fn show_character_palette(&mut self, _: &ShowCharacterPalette, cx: &mut ViewContext<Self>) {
if self if !self
.terminal .terminal
.read(cx) .read(cx)
.last_mode .last_mode
.contains(TermMode::ALT_SCREEN) .contains(TermMode::ALT_SCREEN)
{ {
cx.show_character_palette(); 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(); cx.notify();
} }
//2 -> Character palette shows up! But it's incorrectly positioned
pub fn should_show_cursor( pub fn should_show_cursor(
&self, &self,
focused: bool, focused: bool,
@ -187,9 +189,9 @@ impl ConnectedView {
match setting { match setting {
//If the user requested to never blink, don't blink it. //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 //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,12 +297,9 @@ impl TerminalBuilder {
let mut term = Term::new(&config, &initial_size, ZedListener(events_tx.clone())); let mut term = Term::new(&config, &initial_size, ZedListener(events_tx.clone()));
//Start off blinking if we need to //Start off blinking if we need to
match blink_settings { if let Some(TerminalBlink::On) = blink_settings {
None | Some(TerminalBlink::TerminalControlled) | Some(TerminalBlink::Always) => {
term.set_mode(alacritty_terminal::ansi::Mode::BlinkingCursor) term.set_mode(alacritty_terminal::ansi::Mode::BlinkingCursor)
} }
_ => {}
}
let term = Arc::new(FairMutex::new(term)); let term = Arc::new(FairMutex::new(term));