diff --git a/crates/terminal/src/connected_el.rs b/crates/terminal/src/connected_el.rs index ab08efc1b3b8e9070275e8e6e3b817e58bcca791..5f917c7f4eba18545111345241d35ea91bef1f6f 100644 --- a/crates/terminal/src/connected_el.rs +++ b/crates/terminal/src/connected_el.rs @@ -200,6 +200,7 @@ pub struct TerminalEl { terminal: WeakModelHandle, view: WeakViewHandle, modal: bool, + focused: bool, } impl TerminalEl { @@ -207,11 +208,13 @@ impl TerminalEl { view: WeakViewHandle, terminal: WeakModelHandle, modal: bool, + focused: bool, ) -> TerminalEl { TerminalEl { view, terminal, modal, + focused, } } @@ -660,12 +663,18 @@ impl Element for TerminalEl { TerminalEl::shape_cursor(cursor_point, dimensions, &cursor_text).map( move |(cursor_position, block_width)| { + let (shape, color) = if self.focused { + (CursorShape::Block, terminal_theme.colors.cursor) + } else { + (CursorShape::Underscore, terminal_theme.colors.foreground) + }; + Cursor::new( cursor_position, block_width, dimensions.line_height, - terminal_theme.colors.cursor, - CursorShape::Block, + color, + shape, Some(cursor_text), ) }, diff --git a/crates/terminal/src/connected_view.rs b/crates/terminal/src/connected_view.rs index 1da8aad610ec342de3fb67dc88aba9da91024626..9e909d5bccfb7ca6f5f4bd801f1808232374e250 100644 --- a/crates/terminal/src/connected_view.rs +++ b/crates/terminal/src/connected_view.rs @@ -181,9 +181,15 @@ impl View for ConnectedView { fn render(&mut self, cx: &mut gpui::RenderContext<'_, Self>) -> ElementBox { let terminal_handle = self.terminal.clone().downgrade(); + let self_id = cx.view_id(); + let focused = cx + .focused_view_id(cx.window_id()) + .filter(|view_id| *view_id == self_id) + .is_some(); + Stack::new() .with_child( - TerminalEl::new(cx.handle(), terminal_handle, self.modal) + TerminalEl::new(cx.handle(), terminal_handle, self.modal, focused) .contained() .boxed(), ) @@ -191,8 +197,15 @@ impl View for ConnectedView { .boxed() } - fn on_focus_in(&mut self, _: AnyViewHandle, _cx: &mut ViewContext) { + fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext) { self.has_new_content = false; + self.terminal.read(cx).focus_in(); + cx.notify(); + } + + fn on_focus_out(&mut self, _: AnyViewHandle, cx: &mut ViewContext) { + self.terminal.read(cx).focus_out(); + cx.notify(); } fn selected_text_range(&self, cx: &AppContext) -> Option> { diff --git a/crates/terminal/src/terminal.rs b/crates/terminal/src/terminal.rs index f31c07423efac4d5c5e84f849af2a5c81b6977c3..af1c763f5230b3ec75a4f1c92a09ad2b81ba222f 100644 --- a/crates/terminal/src/terminal.rs +++ b/crates/terminal/src/terminal.rs @@ -601,18 +601,23 @@ impl Terminal { f(content, cursor_text) } - // fn estimate_utilization(last_processed: usize) -> f32 { - // let buffer_utilization = (last_processed as f32 / (READ_BUFFER_SIZE as f32)).clamp(0., 1.); - - // //Scale result to bias low, then high - // buffer_utilization * buffer_utilization - // } - ///Scroll the terminal pub fn scroll(&mut self, scroll: Scroll) { self.events.push(InternalEvent::Scroll(scroll)); } + pub fn focus_in(&self) { + if self.last_mode.contains(TermMode::FOCUS_IN_OUT) { + self.notify_pty("\x1b[I".to_string()); + } + } + + pub fn focus_out(&self) { + if self.last_mode.contains(TermMode::FOCUS_IN_OUT) { + self.notify_pty("\x1b[O".to_string()); + } + } + pub fn click(&mut self, point: Point, side: Direction, clicks: usize) { let selection_type = match clicks { 0 => return, //This is a release