agent: Improve terminal tool card design (#29712)

To-dos:

- [x] Expose the command to defend against cases where that's just super
long
- [x] Tackle the vertical scroll conflict with panel scroll
- [x] Reduce default font-size

Release Notes:

- N/A

---------

Co-authored-by: Ben Brandt <benjamin.j.brandt@gmail.com>
Co-authored-by: Mikayla Maki <mikayla.c.maki@gmail.com>
Co-authored-by: Agus Zubiaga <hi@aguz.me>
This commit is contained in:
Danilo Leal 2025-05-05 15:50:53 -03:00 committed by GitHub
parent e64f5ff358
commit 7dfbe0b908
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 174 additions and 145 deletions

View file

@ -261,6 +261,7 @@ async fn deserialize_pane_group(
workspace.clone(),
Some(workspace_id),
project.downgrade(),
false,
window,
cx,
)

View file

@ -1,9 +1,9 @@
use editor::{CursorLayout, HighlightedRange, HighlightedRangeLine};
use gpui::{
AnyElement, App, AvailableSpace, Bounds, ContentMask, Context, DispatchPhase, Element,
ElementId, Entity, FocusHandle, Font, FontStyle, FontWeight, GlobalElementId, HighlightStyle,
Hitbox, Hsla, InputHandler, InteractiveElement, Interactivity, IntoElement, LayoutId,
ModifiersChangedEvent, MouseButton, MouseMoveEvent, Pixels, Point, ShapedLine,
ElementId, Entity, FocusHandle, Focusable, Font, FontStyle, FontWeight, GlobalElementId,
HighlightStyle, Hitbox, Hsla, InputHandler, InteractiveElement, Interactivity, IntoElement,
LayoutId, ModifiersChangedEvent, MouseButton, MouseMoveEvent, Pixels, Point, ShapedLine,
StatefulInteractiveElement, StrikethroughStyle, Styled, TextRun, TextStyle, UTF16Selection,
UnderlineStyle, WeakEntity, WhiteSpace, Window, WindowTextSystem, div, fill, point, px,
relative, size,
@ -158,6 +158,7 @@ pub struct TerminalElement {
focused: bool,
cursor_visible: bool,
interactivity: Interactivity,
embedded: bool,
block_below_cursor: Option<Rc<BlockProperties>>,
}
@ -178,6 +179,7 @@ impl TerminalElement {
focused: bool,
cursor_visible: bool,
block_below_cursor: Option<Rc<BlockProperties>>,
embedded: bool,
) -> TerminalElement {
TerminalElement {
terminal,
@ -187,6 +189,7 @@ impl TerminalElement {
focus: focus.clone(),
cursor_visible,
block_below_cursor,
embedded,
interactivity: Default::default(),
}
.track_focus(&focus)
@ -503,11 +506,15 @@ impl TerminalElement {
);
self.interactivity.on_scroll_wheel({
let terminal_view = self.terminal_view.downgrade();
move |e, _, cx| {
move |e, window, cx| {
terminal_view
.update(cx, |terminal_view, cx| {
terminal_view.scroll_wheel(e, cx);
cx.notify();
if !terminal_view.embedded
|| terminal_view.focus_handle(cx).is_focused(window)
{
terminal_view.scroll_wheel(e, cx);
cx.notify();
}
})
.ok();
}
@ -580,6 +587,16 @@ impl Element for TerminalElement {
window: &mut Window,
cx: &mut App,
) -> (LayoutId, Self::RequestLayoutState) {
if self.embedded {
let scrollable = {
let term = self.terminal.read(cx);
!term.scrolled_to_top() && !term.scrolled_to_bottom() && self.focused
};
if scrollable {
self.interactivity.occlude_mouse();
}
}
let layout_id =
self.interactivity
.request_layout(global_id, window, cx, |mut style, window, cx| {
@ -636,10 +653,14 @@ impl Element for TerminalElement {
let font_weight = terminal_settings.font_weight.unwrap_or_default();
let line_height = terminal_settings.line_height.value();
let font_size = terminal_settings.font_size;
let font_size =
font_size.map_or(buffer_font_size, |size| theme::adjusted_font_size(size, cx));
let font_size = if self.embedded {
window.text_style().font_size.to_pixels(window.rem_size())
} else {
terminal_settings
.font_size
.map_or(buffer_font_size, |size| theme::adjusted_font_size(size, cx))
};
let theme = cx.theme().clone();

View file

@ -437,6 +437,7 @@ impl TerminalPanel {
weak_workspace.clone(),
database_id,
project.downgrade(),
false,
window,
cx,
)
@ -674,6 +675,7 @@ impl TerminalPanel {
workspace.weak_handle(),
workspace.database_id(),
workspace.project().downgrade(),
false,
window,
cx,
)
@ -714,6 +716,7 @@ impl TerminalPanel {
workspace.weak_handle(),
workspace.database_id(),
workspace.project().downgrade(),
false,
window,
cx,
)

View file

@ -111,6 +111,7 @@ pub struct TerminalView {
context_menu: Option<(Entity<ContextMenu>, gpui::Point<Pixels>, Subscription)>,
cursor_shape: CursorShape,
blink_state: bool,
embedded: bool,
blinking_terminal_enabled: bool,
cwd_serialized: bool,
blinking_paused: bool,
@ -162,6 +163,7 @@ impl TerminalView {
workspace: WeakEntity<Workspace>,
workspace_id: Option<WorkspaceId>,
project: WeakEntity<Project>,
embedded: bool,
window: &mut Window,
cx: &mut Context<Self>,
) -> Self {
@ -200,6 +202,7 @@ impl TerminalView {
blink_epoch: 0,
hover_target_tooltip: None,
hover_tooltip_update: Task::ready(()),
embedded,
workspace_id,
show_breadcrumbs: TerminalSettings::get_global(cx).toolbar.breadcrumbs,
block_below_cursor: None,
@ -381,7 +384,6 @@ impl TerminalView {
return;
}
}
self.terminal.update(cx, |term, _| term.scroll_wheel(event));
}
@ -1377,6 +1379,7 @@ impl Render for TerminalView {
focused,
self.should_show_cursor(focused, cx),
self.block_below_cursor.clone(),
self.embedded,
))
.when_some(self.render_scrollbar(cx), |div, scrollbar| {
div.child(scrollbar)
@ -1502,6 +1505,7 @@ impl Item for TerminalView {
self.workspace.clone(),
workspace_id,
self.project.clone(),
false,
window,
cx,
)
@ -1659,6 +1663,7 @@ impl SerializableItem for TerminalView {
workspace,
Some(workspace_id),
project.downgrade(),
false,
window,
cx,
)