mirror of
https://github.com/l0ng-ai/tty7.git
synced 2026-11-06 00:15:06 +00:00
refactor: drop what the new sidebar left unused, and two clippy findings
- `TerminalView::native_ssh_cwd` and its helper existed for the sidebar's old folder grouping of native SSH panes; an SSH tab now groups by host, and nothing else read it. - The file tree's context menu takes `cx` instead of `danger` and the new groups flag, back to the argument count it had on main. - A title test builds its workspace in the initializer.
This commit is contained in:
@@ -263,23 +263,6 @@ fn cwd_is_on_host(pane_runs_remotely: bool, host_is_local: bool) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
/// The cwd a native SSH pane's remote shell reported, for the few readers that
|
||||
/// only need a name for it and not a host to act on it.
|
||||
///
|
||||
/// Such a pane belongs to this machine's daemon, so [`cwd_is_on_host`] rightly
|
||||
/// turns its paths away from every `Host` call — there is no host to hand them
|
||||
/// to. But the shell on the far end states them itself (OSC 7), unlike a shell
|
||||
/// that ssh'd onward from a local prompt, whose directory is only ever a guess.
|
||||
/// Only an absolute POSIX path counts: that is what a remote sshd's shell
|
||||
/// reports, and anything else is not a directory worth naming.
|
||||
fn native_ssh_cwd(
|
||||
remote: Option<&RemoteContext>,
|
||||
cwd: Option<std::path::PathBuf>,
|
||||
) -> Option<std::path::PathBuf> {
|
||||
remote.filter(|r| r.kind == crate::daemon::protocol::RemoteKind::NativeSsh)?;
|
||||
cwd.filter(|c| c.to_string_lossy().starts_with('/'))
|
||||
}
|
||||
|
||||
/// Which path dialect a pane's output is written in.
|
||||
///
|
||||
/// A pane running on this machine spells paths the way this OS does, and that
|
||||
@@ -1996,12 +1979,6 @@ impl TerminalView {
|
||||
self.git_status_cwd.as_deref()
|
||||
}
|
||||
|
||||
/// See [`native_ssh_cwd`]. `None` for every pane that is not a native SSH
|
||||
/// one — those either have a `git_status_cwd` or have no cwd to name.
|
||||
pub fn native_ssh_cwd(&self) -> Option<std::path::PathBuf> {
|
||||
native_ssh_cwd(self.remote_context().as_ref(), self.cwd())
|
||||
}
|
||||
|
||||
/// Plant the cwd the git-status poll would have found. For tests that
|
||||
/// need a pane to look like it is sitting somewhere known — a real poll
|
||||
/// needs a live shell reporting a directory, which a quiet test pane has
|
||||
@@ -10019,37 +9996,6 @@ mod tests {
|
||||
assert!(!cwd_is_on_host(false, false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn only_a_native_ssh_pane_names_its_remote_cwd() {
|
||||
use super::{RemoteContext, native_ssh_cwd};
|
||||
use std::path::PathBuf;
|
||||
let native = RemoteContext {
|
||||
kind: RemoteKind::NativeSsh,
|
||||
argv: Vec::new(),
|
||||
target: "ubuntu@box".into(),
|
||||
};
|
||||
let home = || Some(PathBuf::from("/home/ubuntu"));
|
||||
assert_eq!(native_ssh_cwd(Some(&native), home()), home());
|
||||
|
||||
// `ssh` typed at a local prompt: the directory is a guess, not a
|
||||
// report from the far end.
|
||||
let typed = RemoteContext {
|
||||
kind: RemoteKind::Ssh,
|
||||
..native.clone()
|
||||
};
|
||||
assert_eq!(native_ssh_cwd(Some(&typed), home()), None);
|
||||
assert_eq!(native_ssh_cwd(Some(&wsl_context("Ubuntu")), home()), None);
|
||||
// A local pane has its own path through `git_status_cwd`.
|
||||
assert_eq!(native_ssh_cwd(None, home()), None);
|
||||
|
||||
assert_eq!(native_ssh_cwd(Some(&native), None), None);
|
||||
assert_eq!(
|
||||
native_ssh_cwd(Some(&native), Some(PathBuf::from("~"))),
|
||||
None,
|
||||
"only an absolute path names a directory"
|
||||
);
|
||||
}
|
||||
|
||||
/// Which machine's spelling a pane's paths are read in. Ungated on
|
||||
/// purpose: the bug this settles was a Windows-only one that hid behind a
|
||||
/// `#[cfg(unix)]` on the test that covered it.
|
||||
|
||||
+9
-12
@@ -1962,11 +1962,6 @@ impl Tty7App {
|
||||
let show_hidden = self.file_tree.show_hidden;
|
||||
let paths_are_local = self.spawn_host(cx).is_local();
|
||||
move |menu, _window, cx| {
|
||||
let danger = cx.theme().danger;
|
||||
// A group is something the sidebar draws; with the tabs
|
||||
// along the top there is nowhere to show one.
|
||||
let groups_shown = cx.global::<crate::core::config::Config>().tab_bar_position
|
||||
== crate::core::config::TabBarPosition::Left;
|
||||
Self::tree_row_context_menu(
|
||||
menu,
|
||||
&path,
|
||||
@@ -1974,9 +1969,8 @@ impl Tty7App {
|
||||
is_root,
|
||||
show_hidden,
|
||||
paths_are_local,
|
||||
groups_shown,
|
||||
danger,
|
||||
&app,
|
||||
cx,
|
||||
)
|
||||
}
|
||||
});
|
||||
@@ -2017,13 +2011,16 @@ impl Tty7App {
|
||||
// here — silently opening nothing, or the wrong thing if a local path
|
||||
// happens to collide.
|
||||
paths_are_local: bool,
|
||||
// Whether "Pin as Group" has a sidebar to put the group in. Offered
|
||||
// on a remote workspace too, unlike the file manager above: the tree
|
||||
// and a pinned folder are both on the workspace's own host.
|
||||
groups_shown: bool,
|
||||
danger: gpui::Hsla,
|
||||
app: &gpui::WeakEntity<Self>,
|
||||
cx: &App,
|
||||
) -> PopupMenu {
|
||||
let danger = cx.theme().danger;
|
||||
// Whether "Pin as Group" has a sidebar to put the group in: with the
|
||||
// tabs along the top there is nowhere to show one. Offered on a remote
|
||||
// workspace too, unlike the file manager above — the tree and a pinned
|
||||
// folder are both on the workspace's own host.
|
||||
let groups_shown = cx.global::<crate::core::config::Config>().tab_bar_position
|
||||
== crate::core::config::TabBarPosition::Left;
|
||||
let mut menu = menu.min_w(px(200.));
|
||||
let p = path.to_path_buf();
|
||||
|
||||
|
||||
@@ -1147,8 +1147,10 @@ mod tests {
|
||||
/// A pinned folder outranks any number of repo hints.
|
||||
#[test]
|
||||
fn a_pinned_folder_outranks_the_repo_majority() {
|
||||
let mut ws = Workspace::default();
|
||||
ws.tabs = vec![leaf_tab(1), leaf_tab(2), leaf_tab(3)];
|
||||
let mut ws = Workspace {
|
||||
tabs: vec![leaf_tab(1), leaf_tab(2), leaf_tab(3)],
|
||||
..Default::default()
|
||||
};
|
||||
for t in &mut ws.tabs {
|
||||
t.last_auto = Some(AutoKey::Repo("/repo/tty7".into()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user