Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
429 changes: 246 additions & 183 deletions crabport-core/src/keybind.rs

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions crabport-terminal/src/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1164,6 +1164,19 @@ impl TerminalSession {
self.kitty_keyboard.load(Ordering::SeqCst) != 0
}

/// Whether the running program has enabled DECCKM (`\x1b[?1h`), the
/// application-cursor-keys mode that vim/less/nano switch into. Arrow and
/// Home/End keys must then use the SS3 forms (`ESC O A`, `ESC O H`)
/// instead of the CSI forms.
///
/// Reads through a try-lock: a keypress that lands while the PTY thread
/// holds the term lock encodes the normal CSI form rather than stalling
/// input.
pub fn app_cursor_mode(&self) -> bool {
self.try_with_term_mut(|term| term.mode().contains(TermMode::APP_CURSOR))
.unwrap_or(false)
}

/// Scan a chunk of *program output* for kitty-keyboard negotiation
/// requests and react accordingly.
///
Expand Down
1 change: 1 addition & 0 deletions crabport-ui/i18n/en.toml
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,7 @@ action_terminal_reset_font = "Terminal: Reset Font Size"
action_terminal_search = "Terminal: Search"
action_split_vertical = "Terminal: Split Pane Vertically"
action_split_horizontal = "Terminal: Split Pane Horizontally"
action_close_pane = "Terminal: Close Pane"

[menu]
app_name = "CrabPort"
Expand Down
1 change: 1 addition & 0 deletions crabport-ui/i18n/zh-CN.toml
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ action_terminal_reset_font = "终端:重置字体"
action_terminal_search = "终端:搜索"
action_split_vertical = "终端:垂直分割面板"
action_split_horizontal = "终端:水平分割面板"
action_close_pane = "终端:关闭窗格"

[menu]
app_name = "CrabPort"
Expand Down
1 change: 1 addition & 0 deletions crabport-ui/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ actions!(
TerminalSearch,
SplitVertical,
SplitHorizontal,
ClosePane,
]
);

Expand Down
55 changes: 55 additions & 0 deletions crabport-ui/src/app/tabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,27 @@ impl CrabportApp {
self.focus_pane_next_frame(new_pane_id, cx);
}

/// The tab whose split tree contains `pane_id`, if any.
fn tab_id_for_pane(&self, pane_id: u64) -> Option<u64> {
self.split_trees
.iter()
.find(|(_, tree)| tree.root.find_pane(pane_id))
.map(|(tab_id, _)| *tab_id)
}

/// Close the pane that owns the keyboard focus in the active terminal
/// tab (⌘W, #89). [`Self::close_pane`] collapses the split, or closes
/// the whole tab when the pane was the last one. A no-op on tabs with
/// no split tree (Home, SFTP).
pub fn close_focused_pane(&mut self, cx: &mut Context<Self>) {
let tab_id = self.active_tab_id;
let Some(tree) = self.split_trees.get(&tab_id) else {
return;
};
let pane_id = tree.active_pane;
self.close_pane(tab_id, pane_id, cx);
}

/// Close a single pane by pane id. If it was the last pane in the tab,
/// the whole tab is closed (mirrors `close_tab`). Otherwise the split
/// tree collapses and the active pane is updated.
Expand Down Expand Up @@ -1163,6 +1184,28 @@ impl CrabportApp {
},
));

// Close Pane — collapses the split the right-clicked pane belongs
// to (#89). Only offered when the tab actually has more than one
// pane, so the item never appears where there is nothing to close:
// with a single pane, closing means closing the tab, and the tab
// bar already has a close button for that.
if let Some(pane_id) = real_pane_id
&& let Some(close_tab_id) = self.tab_id_for_pane(pane_id)
&& let Some(tree) = self.split_trees.get(&close_tab_id)
&& tree.root.find_pane(pane_id)
&& tree.root.pane_ids().len() > 1
{
let app_for_close = cx.entity().clone();
items.push(ContextMenuItem::new(
t!("terminal.close_pane").to_string(),
move |_w, cx| {
app_for_close.update(cx, |app, cx| {
app.close_pane(close_tab_id, pane_id, cx);
});
},
));
}

// Clear Screen — erases the visible terminal display but keeps
// scrollback. Equivalent to the `clear` shell command.
items.push(ContextMenuItem::new(
Expand Down Expand Up @@ -1210,6 +1253,7 @@ impl CrabportApp {
let app_handle = cx.entity().downgrade();
let app_handle2 = cx.entity().downgrade();
let app_handle3 = cx.entity().downgrade();
let app_handle4 = cx.entity().downgrade();
// Capture the view entity so the `on_focused` callback can resolve
// the real pane_id (the key in `pane_views`) by entity equality.
// The `pane_id` passed to the callback is `TerminalView::count`,
Expand Down Expand Up @@ -1253,6 +1297,17 @@ impl CrabportApp {
});
});
});
v.set_on_close_request(move |cx| {
// Defer like the split callback: close_pane touches
// pane_views / split_trees and other entities, which would
// re-enter the borrow held by the on_action handler.
let h = app_handle4.clone();
cx.defer(move |cx| {
let _ = h.update(cx, |app, cx| {
app.close_focused_pane(cx);
});
});
});
// Right-click inside the terminal pane surfaces a
// Copy/Paste/Select-All context menu. Resolve the real pane_id
// (the key in `pane_views`) by entity equality so the menu
Expand Down
4 changes: 4 additions & 0 deletions crabport-ui/src/keybinds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ pub fn catalog() -> Vec<CatalogEntry> {
"terminal_search" => crate::app::TerminalSearch, TERM, plat("cmd-f", "ctrl-f"), true;
"split_vertical" => crate::app::SplitVertical, TERM, plat("cmd-d", "ctrl-d"), true;
"split_horizontal" => crate::app::SplitHorizontal, TERM, plat("cmd-shift-d", "ctrl-shift-d"), true;
// ⌘W closes the focused pane, or the tab when it is the last one.
// Empty on other platforms: Ctrl+W is 0x17 (delete word) and must
// reach the shell.
"close_pane" => crate::app::ClosePane, TERM, plat("cmd-w", ""), true;
)
}

Expand Down
130 changes: 117 additions & 13 deletions crabport-ui/src/layouts/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,16 @@ pub fn render_content(
// If this tab has a split tree, render the panes recursively;
// otherwise fall back to the single terminal view.
let inner: AnyElement = if let Some(tree) = split_trees.get(&tab_id) {
render_split_node(&tree.root, tree.active_pane, tab_id, pane_views, handle)
.into_any_element()
let multi_pane = tree.root.pane_ids().len() > 1;
render_split_node(
&tree.root,
tree.active_pane,
multi_pane,
tab_id,
pane_views,
handle,
)
.into_any_element()
} else if let Some(terminal_entity) = terminal_views.get(&tab_id) {
div()
.size_full()
Expand Down Expand Up @@ -1039,15 +1047,22 @@ pub fn render_content(
fn render_split_node(
node: &SplitNode,
active_pane: u64,
multi_pane: bool,
tab_id: u64,
pane_views: &HashMap<u64, Entity<TerminalView>>,
handle: &Entity<CrabportApp>,
) -> AnyElement {
use gpui_component::resizable::{h_resizable, resizable_panel, v_resizable};
match node {
SplitNode::Pane(pane_id) => {
render_pane(*pane_id, active_pane, tab_id, pane_views, handle).into_any_element()
}
SplitNode::Pane(pane_id) => render_pane(
*pane_id,
active_pane,
multi_pane,
tab_id,
pane_views,
handle,
)
.into_any_element(),
SplitNode::Split { dir, a, b, .. } => {
let dir = *dir;
let group_id =
Expand All @@ -1058,8 +1073,10 @@ fn render_split_node(
};
// Render children. For a nested split child, wrap it in a
// `resizable_panel` so the inner group fills its allocated space.
let child_a = render_split_child(a, active_pane, tab_id, pane_views, handle);
let child_b = render_split_child(b, active_pane, tab_id, pane_views, handle);
let child_a =
render_split_child(a, active_pane, multi_pane, tab_id, pane_views, handle);
let child_b =
render_split_child(b, active_pane, multi_pane, tab_id, pane_views, handle);

let group = if axis == gpui::Axis::Horizontal {
h_resizable(group_id)
Expand All @@ -1079,32 +1096,44 @@ fn render_split_node(
fn render_split_child(
node: &SplitNode,
active_pane: u64,
multi_pane: bool,
tab_id: u64,
pane_views: &HashMap<u64, Entity<TerminalView>>,
handle: &Entity<CrabportApp>,
) -> AnyElement {
match node {
SplitNode::Pane(pane_id) => {
render_pane(*pane_id, active_pane, tab_id, pane_views, handle).into_any_element()
}
SplitNode::Pane(pane_id) => render_pane(
*pane_id,
active_pane,
multi_pane,
tab_id,
pane_views,
handle,
)
.into_any_element(),
SplitNode::Split { .. } => {
// Nested split: render as a group, which itself becomes the child.
render_split_node(node, active_pane, tab_id, pane_views, handle)
render_split_node(node, active_pane, multi_pane, tab_id, pane_views, handle)
}
}
}

/// Render a single terminal pane with click-to-focus + active highlight.
/// Render a single terminal pane with click-to-focus, and — when the tab
/// holds more than one pane — a focus ring on the pane that owns the
/// keyboard (#89): with identical-looking panes, the ring is what tells you
/// at a glance which terminal you're typing into.
fn render_pane(
pane_id: u64,
active_pane: u64,
multi_pane: bool,
tab_id: u64,
pane_views: &HashMap<u64, Entity<TerminalView>>,
handle: &Entity<CrabportApp>,
) -> impl IntoElement {
let is_active = pane_id == active_pane;
let view = pane_views.get(&pane_id).cloned();
let view_for_focus = view.clone();
let glow_id = ElementId::Name(format!("pane-glow-{}-{}", tab_id, pane_id).into());
let mut el = div()
.id(ElementId::Name(
format!("pane-{}-{}", tab_id, pane_id).into(),
Expand All @@ -1116,7 +1145,6 @@ fn render_pane(
// single click to fire `on_mouse_down` on *every* pane, re-focusing
// the wrong one.
.occlude()
.when(is_active, |el| el.bg(rgba((surface_hover() << 8) | 0x18)))
.on_mouse_down(MouseButton::Left, {
let handle = handle.clone();
move |_e, w, cx| {
Expand All @@ -1133,6 +1161,82 @@ fn render_pane(
if let Some(view) = view {
el = el.child(view);
}
// The glow paints *after* the view, because TerminalView fills itself
// with an opaque `term_bg` — the old active-pane tint sat on this
// container and was painted over, which is why the focused pane was
// impossible to pick out. The overlay has no listeners, so every click
// and drag passes through to the terminal beneath; the glow fades in on
// the pane that takes focus and out of the one that loses it.
if multi_pane {
let glow = input_border_focused();
// Same hue at both stops so the fade never drifts gray in Hsla.
let lit = rgba((glow << 8) | 0x38);
let clear = rgba((glow << 8) | 0x00);
// A tight rim: the wash reaches only ~12pt in from each edge, so
// the terminal keeps its plain background across the middle.
let glow_px = px(12.0);
// gpui 0.2 has two-stop linear gradients only, so the radial
// edge-to-centre wash is composed from one strip per side; the two
// neighbours overlap at each corner, pooling the light there.
let strip = |angle: f32| {
linear_gradient(
angle,
linear_color_stop(lit, 0.0),
linear_color_stop(clear, 1.0),
)
};
el = el.child(
div()
.id(glow_id.clone())
.absolute()
.inset_0()
// Pointer-events: none — the glow is purely visual.
.with_transition(glow_id)
.transition_when_else(
is_active,
duration_fast(),
EASE_STANDARD,
|el| el.opacity(1.0),
|el| el.opacity(0.0),
)
.child(
div()
.absolute()
.top_0()
.left_0()
.w_full()
.h(glow_px)
.bg(strip(180.0)),
)
.child(
div()
.absolute()
.bottom_0()
.left_0()
.w_full()
.h(glow_px)
.bg(strip(0.0)),
)
.child(
div()
.absolute()
.top_0()
.left_0()
.h_full()
.w(glow_px)
.bg(strip(90.0)),
)
.child(
div()
.absolute()
.top_0()
.right_0()
.h_full()
.w(glow_px)
.bg(strip(270.0)),
),
);
}
el
}

Expand Down
Loading
Loading