Cleanup confirms and refreshes; projects switch sessions in place; explain verify.sh, headroom and Mouse-1
This commit is contained in:
@@ -6,6 +6,7 @@ package main
|
||||
// to a command with a name, not a keystroke.
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
@@ -49,8 +50,11 @@ type projectModel struct {
|
||||
err error
|
||||
readAt time.Time
|
||||
|
||||
tab int
|
||||
scroll int
|
||||
tab int
|
||||
scroll int
|
||||
regAt int
|
||||
regs []registryRow
|
||||
confirmSwitch bool
|
||||
|
||||
showHelp bool
|
||||
width, height int
|
||||
@@ -145,6 +149,29 @@ func (m projectModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
return m, tea.Batch(m.load(), tickEvery(10*time.Second))
|
||||
|
||||
case tea.KeyMsg:
|
||||
if m.confirmSwitch {
|
||||
switch msg.String() {
|
||||
case "y":
|
||||
m.confirmSwitch = false
|
||||
if m.regAt < len(m.regs) {
|
||||
r := m.regs[m.regAt]
|
||||
params := map[string]any{"name": r.session}
|
||||
me, _ := os.Hostname()
|
||||
if r.host != "" && r.host != me && r.host != strings.Split(me, ".")[0] {
|
||||
params["host"] = r.host
|
||||
}
|
||||
body, _ := json.Marshal(params)
|
||||
out, err := exec.Command("tuios", "call", "switch-session", string(body)).CombinedOutput()
|
||||
if err != nil {
|
||||
m.err = fmt.Errorf("could not switch to %q: %v %s", r.session, err, strings.TrimSpace(string(out)))
|
||||
}
|
||||
}
|
||||
return m, nil
|
||||
case "esc", "n", "q":
|
||||
m.confirmSwitch = false
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
if m.showHelp {
|
||||
m.showHelp = false
|
||||
return m, nil
|
||||
@@ -163,6 +190,14 @@ func (m projectModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
return m, nil
|
||||
}
|
||||
return m, tea.Quit
|
||||
case "enter":
|
||||
if m.tab == 4 {
|
||||
m.regs = readRegistry()
|
||||
if len(m.regs) > 0 && m.regAt < len(m.regs) {
|
||||
m.confirmSwitch = true
|
||||
}
|
||||
}
|
||||
return m, nil
|
||||
case "(", "[", "h":
|
||||
if m.tab > 0 {
|
||||
m.tab--
|
||||
@@ -176,9 +211,15 @@ func (m projectModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
}
|
||||
return m, nil
|
||||
case "up", "k":
|
||||
if m.tab == 4 && m.regAt > 0 {
|
||||
m.regAt--
|
||||
}
|
||||
m.scroll--
|
||||
return m, nil
|
||||
case "down", "j":
|
||||
if m.tab == 4 && m.regAt < len(m.regs)-1 {
|
||||
m.regAt++
|
||||
}
|
||||
m.scroll++
|
||||
return m, nil
|
||||
case "esc":
|
||||
@@ -186,6 +227,8 @@ func (m projectModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
}
|
||||
|
||||
case projectMsg:
|
||||
m.regs = readRegistry()
|
||||
m.regAt = min(m.regAt, max(0, len(m.regs)-1))
|
||||
m.dash = msg.dash
|
||||
m.project = msg.project
|
||||
m.cfg = msg.cfg
|
||||
@@ -207,6 +250,17 @@ func (m projectModel) View() string {
|
||||
fmt.Sprintf("This workspace needs 80 × 24.\nThis panel is %d × %d.", m.width, m.height))
|
||||
}
|
||||
|
||||
if m.confirmSwitch && m.regAt < len(m.regs) {
|
||||
r := m.regs[m.regAt]
|
||||
return helpOverlay("switch to "+r.session+"?", [][2]string{
|
||||
{"what happens", "your TUIOS client moves to that session"},
|
||||
{"session", r.session},
|
||||
{"machine", r.host},
|
||||
{"folder", r.folder},
|
||||
{"y", "switch"},
|
||||
{"esc or n", "stay here"},
|
||||
}, m.width, m.height)
|
||||
}
|
||||
if m.showHelp {
|
||||
return helpOverlay("the project", [][2]string{
|
||||
{"[ ] h l", "facts, costs, settings"},
|
||||
@@ -497,7 +551,7 @@ func (m projectModel) projectListLines(width int) []string {
|
||||
rows := readRegistry()
|
||||
out := []string{"", dimStyle().Render(fmt.Sprintf(" %-26s %-12s %-14s %s", "project", "machine", "session", "folder"))}
|
||||
me, _ := os.Hostname()
|
||||
for _, r := range rows {
|
||||
for i, r := range rows {
|
||||
here := ""
|
||||
if r.host == me || r.host == strings.Split(me, ".")[0] {
|
||||
here = " (this machine)"
|
||||
@@ -505,13 +559,18 @@ func (m projectModel) projectListLines(width int) []string {
|
||||
line := fmt.Sprintf(" %-26s %-12s %-14s %s%s",
|
||||
truncateVisible(r.name, 26), r.host, truncateVisible(r.session, 14),
|
||||
truncateVisible(r.folder, max(10, width-60)), here)
|
||||
if i == m.regAt {
|
||||
out = append(out, selectedStyle2().Render(padTo("▸"+line[1:], width)))
|
||||
continue
|
||||
}
|
||||
out = append(out, line)
|
||||
}
|
||||
if len(rows) == 0 {
|
||||
out = append(out, " "+mutedStyle2().Render("none adopted yet: bin/office <folder> adds one"))
|
||||
}
|
||||
out = append(out, "")
|
||||
out = append(out, dimStyle().Render(" a project on another machine can be listed here but not opened from this one."))
|
||||
out = append(out, dimStyle().Render(" to open one: attach to its session, or run bin/office <folder> there."))
|
||||
out = append(out, dimStyle().Render(" enter switches your TUIOS client to that project's session."))
|
||||
out = append(out, dimStyle().Render(" a session on another machine switches only when that machine is in your"))
|
||||
out = append(out, dimStyle().Render(" ~/.config/tuios hosts table; otherwise attach to it by hand."))
|
||||
return out
|
||||
}
|
||||
|
||||
@@ -345,6 +345,24 @@ func (m repairModel) View() string {
|
||||
fmt.Sprintf("This workspace needs 80 × 24.\nThis panel is %d × %d.", m.width, m.height))
|
||||
}
|
||||
|
||||
if m.confirmKill {
|
||||
var names []string
|
||||
for name := range m.ticked {
|
||||
names = append(names, name)
|
||||
}
|
||||
sort.Strings(names)
|
||||
entries := [][2]string{
|
||||
{"what happens", "these TUIOS sessions are closed and their panes end"},
|
||||
{"", "nothing in ~/.pi/paperclips is deleted; that is your Pi history"},
|
||||
{"", "this project's session and attached sessions are never touched"},
|
||||
{"y", "close them"},
|
||||
{"esc or n", "do nothing"},
|
||||
}
|
||||
for _, n := range names {
|
||||
entries = append(entries, [2]string{"", n})
|
||||
}
|
||||
return helpOverlay(fmt.Sprintf("close %s?", fmtCount(len(names), "session", "sessions")), entries, m.width, m.height)
|
||||
}
|
||||
if m.showHelp {
|
||||
return helpOverlay("repair", [][2]string{
|
||||
{"[ ] h l", "health, layout, rebuild log"},
|
||||
|
||||
Reference in New Issue
Block a user