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>
76 lines
2 KiB
Go
76 lines
2 KiB
Go
package tui
|
|
|
|
import (
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
|
|
"vcom/internal/tui/modal"
|
|
"vcom/internal/tui/notify"
|
|
)
|
|
|
|
// sortMenu is S: sort key, reverse order, directories first. The choice
|
|
// applies to both panels and is saved to the config (one line each, like
|
|
// the theme).
|
|
func (a *App) sortMenu() tea.Cmd {
|
|
b := a.deps.Config.Browser
|
|
onOff := func(v bool) string {
|
|
if v {
|
|
return "on"
|
|
}
|
|
return "off"
|
|
}
|
|
cur := b.Sort.By
|
|
mark := func(by string) string {
|
|
if by == cur {
|
|
return "●"
|
|
}
|
|
return ""
|
|
}
|
|
items := []modal.Item{
|
|
{Label: "Sort by", Header: true},
|
|
{Label: "Name", Detail: mark("name"), Value: "name"},
|
|
{Label: "Size", Detail: mark("size"), Value: "size"},
|
|
{Label: "Modified", Detail: mark("modified"), Value: "modified"},
|
|
{Label: "Extension", Detail: mark("extension"), Value: "extension"},
|
|
{Label: "Options", Header: true},
|
|
{Label: "Reverse order", Detail: onOff(b.Sort.Reverse), Value: "reverse"},
|
|
{Label: "Directories first", Detail: onOff(b.DirsFirst), Value: "dirsfirst"},
|
|
}
|
|
a.openModal(modal.NewList("Sort", items, cur), func(o modal.Outcome) tea.Cmd {
|
|
if o.Cancelled {
|
|
return nil
|
|
}
|
|
c := &a.deps.Config.Browser
|
|
var section, key string
|
|
var value any
|
|
switch v := o.Value.(string); v {
|
|
case "reverse":
|
|
c.Sort.Reverse = !c.Sort.Reverse
|
|
section, key, value = "browser.sort", "reverse", c.Sort.Reverse
|
|
case "dirsfirst":
|
|
c.DirsFirst = !c.DirsFirst
|
|
section, key, value = "browser", "dirs_first", c.DirsFirst
|
|
default:
|
|
c.Sort.By = v
|
|
section, key, value = "browser.sort", "by", v
|
|
}
|
|
opts := a.panelOptions()
|
|
for _, p := range a.panels {
|
|
p.SetOptions(opts)
|
|
}
|
|
set, path := a.deps.SetConfigKey, a.deps.ConfigPath
|
|
save := func() tea.Msg {
|
|
if _, err := set(path, section, key, value); err != nil {
|
|
return sortSavedMsg{err}
|
|
}
|
|
return nil
|
|
}
|
|
return tea.Batch(save, a.selectionChanged())
|
|
})
|
|
return nil
|
|
}
|
|
|
|
type sortSavedMsg struct{ err error }
|
|
|
|
func (a *App) onSortSaved(m sortSavedMsg) tea.Cmd {
|
|
return a.notify(notify.Error, "Sort order not saved: "+m.err.Error())
|
|
}
|