8000 feat(terminal): show file links in the file panel by Sparky579 · Pull Request #402 · t8y2/motty · GitHub
[go: up one dir, main page]

Skip to content

feat(terminal): show file links in the file panel - #402

Open
Sparky579 wants to merge 1 commit into
t8y2:mainfrom
Sparky579:feat/terminal-file-links
Open

Sparky579 wants to merge 1 commit into
t8y2:mainfrom
Sparky579:feat/terminal-file-links

Conversation

@Sparky579
Copy link
Copy Markdown
Contributor

Closes #401.

What it does

Coding agents point at the files they write with an OSC 8 link, as file:///home/me/notes/a.md or an editor's vscode://file/<path>:<line>. app.OpenURL refuses both. In an SSH session the file is on the server anyway, so a Control+click on one only left "Could not open link" in the status bar. An agent that thinks the terminal has no hyperlinks underlines the name instead, and Motty saw nothing at all to click.

  • Control+click (Command+click on macOS) on a file link opens the file panel at the file's folder with the file selected.
    • It opens the panel when it is closed. When the panel shows this computer's files, it switches back to the server first.
    • Schemes: file://, vscode, vscode-insiders, vscodium, cursor and windsurf (<scheme>://file/<path>), and a target that is already an absolute path. :line and :line:column are dropped.
    • On a server, file://host/... is a file on that server whatever the host says. A local terminal only takes this computer's host (localDirectoryHost).
    • Other links still go to the system opener, as before.
  • Underlined file names work the same way, on Control+click only.
    • term.UnderlinedTextAt reads the underlined run of one colour around a cell. The run may hold spaces and wide characters, and it follows soft wraps, including a row that wrapped early before a wide character.
    • The run counts when it is an absolute path, or a name with an extension.
    • A bare name is joined to the shell's reported folder (OSC 7). If it is not in that folder, the folder's subfolders are searched for it with the SFTP:筛选支持包含子文件夹(按文件名递归搜索) #323 search.
    • A plain click never takes it, even with plain-click links turned on, because underlined text often means nothing of the kind.
  • Terminal menu
    • A file link or underlined file name offers Show in Files, Download and Copy. A web link offers Open in browser and Copy.
    • The existing absolute-path detection gains Download.
    • Download selects the file and then runs the panel's own downloadSFTP, so the download folder setting and the save dialog behave as they do in the panel. It is offered on servers only.
  • When the folder does not have the file, the status line says "x is not in this folder".

How it works

  • terminal_file_link.go:
    • fileLinkTarget parses a link target into a path for the machine the session runs on.
    • underlinedFileTarget does the same for underlined text.
    • openSessionLink replaces openTerminalLink as the terminal's openLink. It is now a closure over the session ID, so a click knows whose files to show.
  • The reveal from search results (SFTP:筛选支持包含子文件夹(按文件名递归搜索) #323) is generalized:
    • revealSFTPEntry clears the filter, sets folder.reveal and navigates. Search results and showInFiles share it.
    • sftpReveal carries download and search. applyReveal reports whether the listing was the reveal's folder and whether the entry was in it.
    • settleReveal is deferred in both listing paths, so it runs after the listing has written the status. It shows the not-found message, starts the subfolder search, or starts the download. The download therefore never runs from inside half-applied listing state, and its "queued" status is not overwritten.
  • showInFiles takes a sftpReveal. It clears followPath so the terminal-follow cannot pull the panel back to the shell's folder, and it selects the entry instead of only opening its folder. A path ending in a slash still opens that folder.
    • It also fixes an old slip: a server panel that was showing local files used to navigate the local side to the server path.

Testing

  • term: UnderlinedTextAt with spaces, wide characters, an early soft wrap, a colour change and plain text.
  • workbench/terminal_file_link_test.go:
    • Link parsing: file:// with a host and %20, editor links with :line:col, refused schemes, control characters, a local terminal refusing another host, and a Windows file:///C:/... link.
    • Control+click on a file:// link selects the file and does not reach the system opener. A plain click does nothing.
    • A vscode://file/...:3 link opens a closed panel that was on local files, back on the server, with the file selected.
    • Underlined names: a name with spaces and CJK in the shell's folder is selected. A name that is not there turns into the subfolder search with its result. A plain underlined word does nothing.
    • Menu on a file link: S 8000 how, Download and Copy, then Download writes the file into the download folder.
    • The not-found status, and a trailing-slash path opening its folder.
  • terminal_action_test.go: absolute paths now also offer Download.
  • gofmt, go vet ./..., go vet -tags dev ./internal/workbench and GOOS=linux go vet for the touched packages are clean.
  • go test passes for term, i18n and sftpclient. workbench has one unrelated failure on this Windows machine, TestLocalListShowsApplicationBundlesWithTheirSystemIcon, which also fails on a clean main here.

🤖 Generated with Claude Code

Coding agents link the files they write as file:// URLs or an editor's
vscode://file/<path>:<line> link. The system opener refuses both, and in
an SSH session the file is on the server anyway, so a Control+click
(Command+click on macOS) on one only left an error in the status bar.

- A Control+click on a file link now opens the file panel at the file's
  folder with the file selected, opening the panel or switching it to
  the server first. file:// on a server names a file on that server; a
  local terminal takes only this computer's host. :line is dropped.
- An agent that thinks the terminal has no hyperlinks underlines the
  name instead. term.UnderlinedTextAt reads that run (one colour, across
  soft wraps, with spaces and wide characters), and a Control+click on
  one that reads as a file name works the same way. A bare name is taken
  from the shell's reported folder; when it is not there, the folder's
  subfolders are searched for it. A plain click never takes it.
- The terminal menu offers Show in Files, Download and Copy for a file
  link, an underlined file name or an absolute path, and Open in browser
  for a web link. Download selects the file and runs the panel's own
  download, so the download folder setting applies. Show in Files now
  selects the file rather than only opening its folder.
- A file that is not in its folder says so in the status line.
- docs: file links, in the terminal page.

Closes t8y2#401

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

终端:Ctrl+点击文件链接时在文件面板中定位,并可下载

1 participant

0