vcom/internal/tui/yank_path.go
vrubelroman 066d3494c2 feat(tui): Enter dispatch, external programs, remote edit, mirror, sort, session (6.6)
Enter on a file (archives still go to 6.5): an executable opens a Run /
Edit / View menu and never runs by itself (U-P1-3, N-P0-2; Run pauses for
Enter afterwards); text goes to $VISUAL/$EDITOR (parsed with quotes);
other files go to xdg-open, reaped in the background (no zombies:
U-P1-15). A file on SSH (or in an archive) is downloaded to the run dir;
edits are uploaded back via WriteAtomic only if the copy changed, and if
the server file changed meanwhile the user chooses overwrite / save a copy
beside / keep the local copy (U-P1-12). p mirrors with a reference per
mount (U-P1-14, N-P1-12); S sorts (saved to the config); y copies paths.
The session goes through internal/state: restored at start (remote and
archive panels as their local place), saved every 30 s when changed, on
SIGHUP (tui.Signal) and in main's teardown (App.Shutdown).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 14:10:52 +03:00

42 lines
1 KiB
Go

package tui
import (
"fmt"
"strings"
tea "github.com/charmbracelet/bubbletea"
"vcom/internal/tui/notify"
"vcom/internal/vfs"
)
type yankedMsg struct {
n int
err error
}
// yankPath is y: copy the full path(s) of the targets (or of the current
// directory) to the clipboard. Remote paths carry their host label.
func (a *App) yankPath() tea.Cmd {
p := a.Active()
es, _ := p.Targets()
var lines []string
for _, e := range es {
lines = append(lines, displayPath(vfs.Location{FS: p.FS(), Path: p.FS().Paths().Join(p.Path(), e.Name)}))
}
if len(lines) == 0 {
lines = []string{displayPath(p.Location())}
}
clip, text := a.deps.Clipboard, strings.Join(lines, "\n")
return func() tea.Msg { return yankedMsg{n: len(lines), err: clip(text)} }
}
func (a *App) onYanked(m yankedMsg) tea.Cmd {
if m.err != nil {
return a.notify(notify.Error, "Clipboard: "+m.err.Error())
}
if m.n == 1 {
return a.notify(notify.Info, "Path copied to the clipboard")
}
return a.notify(notify.Info, fmt.Sprintf("%d paths copied to the clipboard", m.n))
}