ctrl+k goes to any screen or Manage action by name
Thirty-odd places spread over a sidebar, a Manage list and Maintenance tabs are hard to find by browsing. Type a few letters of one and enter goes there, the way the menu would: a running deploy or a server not installed yet stops it with the same message, and an action that changes the server waits for a second enter. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3cace1ae84
commit
ac89cb058e
8 files changed
+249
-27
No files matched your search
+21
-8
@@ -6,6 +6,7 @@ import (
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/charmbracelet/bubbles/textinput"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
zone "github.com/lrstanley/bubblezone"
|
||||
@@ -56,13 +57,16 @@ type App struct {
|
||||
layout string // auto, compact or wide (layout.go)
|
||||
menuOpen bool // the compact layout shows the menu
|
||||
sheetOpen bool // the compact layout lists every key (⋯)
|
||||
menuTop int // how far the compact menu is scrolled
|
||||
sideFocus bool // the wide layout's keys are on the sidebar (menukeys.go)
|
||||
menuSel string // the menu entry selected from the keyboard
|
||||
menuKeys bool // the selection is shown: the menu was reached by key
|
||||
menuCols int // tiles across in the compact menu, as last drawn
|
||||
menuFollow bool // scroll the compact menu to the selection
|
||||
menuFocusLine int // the selection's line in the compact menu, or -1
|
||||
gotoOpen bool // ctrl+k's go-to box is up (goto.go)
|
||||
gotoIn textinput.Model
|
||||
gotoSel int
|
||||
menuTop int // how far the compact menu is scrolled
|
||||
sideFocus bool // the wide layout's keys are on the sidebar (menukeys.go)
|
||||
menuSel string // the menu entry selected from the keyboard
|
||||
menuKeys bool // the selection is shown: the menu was reached by key
|
||||
menuCols int // tiles across in the compact menu, as last drawn
|
||||
menuFollow bool // scroll the compact menu to the selection
|
||||
menuFocusLine int // the selection's line in the compact menu, or -1
|
||||
|
||||
health *deploy.Health // the header's dot (health.go)
|
||||
healthGen int
|
||||
@@ -203,6 +207,13 @@ func (a *App) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
return a, tea.Batch(cmd, func() tea.Msg { return startDeployMsg{m.opts} })
|
||||
case tea.KeyMsg:
|
||||
a.status = ""
|
||||
if a.gotoOpen {
|
||||
return a.gotoKey(m)
|
||||
}
|
||||
if m.String() == "ctrl+k" {
|
||||
a.openGoto()
|
||||
return a, nil
|
||||
}
|
||||
if a.sheetOpen {
|
||||
a.sheetOpen = false
|
||||
if m.String() == "esc" || m.String() == "q" {
|
||||
@@ -347,7 +358,9 @@ func (a *App) View() (out string) {
|
||||
title := sTitle.Render(a.cur().title())
|
||||
contentH := max(3, bodyH-2*padY-2)
|
||||
var content string
|
||||
if a.sheetOpen {
|
||||
if a.gotoOpen {
|
||||
title, content = sTitle.Render("Go to")+sMuted.Render(" enter goes · esc closes"), a.gotoView(inner, contentH)
|
||||
} else if a.sheetOpen {
|
||||
title, content = sTitle.Render("Keys")+sMuted.Render(" any key closes this"), a.sheetView(inner, contentH)
|
||||
} else {
|
||||
content = a.screenView(inner, contentH)
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/charmbracelet/bubbles/textinput"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
|
||||
"interzone/internal/config"
|
||||
)
|
||||
|
||||
// ── Go to ──────────────────────────────────────────────────────────
|
||||
//
|
||||
// ctrl+k, from anywhere: type a few letters of a screen or a Manage
|
||||
// action, and enter goes there. It goes the way the menu does (sideClick),
|
||||
// so a running deploy and a server not installed yet stop it the same way.
|
||||
|
||||
type gotoEntry struct {
|
||||
label string
|
||||
id string // a menu id
|
||||
act string // or a Manage action
|
||||
}
|
||||
|
||||
func (a *App) openGoto() {
|
||||
in := textinput.New()
|
||||
in.Prompt = sAccent.Render("› ")
|
||||
in.Placeholder = "a screen or an action, e.g. backup"
|
||||
in.PlaceholderStyle = lipgloss.NewStyle().Foreground(cFaint)
|
||||
in.TextStyle = lipgloss.NewStyle().Foreground(cText)
|
||||
in.Focus()
|
||||
a.gotoIn, a.gotoSel, a.gotoOpen = in, 0, true
|
||||
a.menuOpen, a.sheetOpen, a.sideFocus = false, false, false
|
||||
}
|
||||
|
||||
func (a *App) gotoEntries() []gotoEntry {
|
||||
var es []gotoEntry
|
||||
for i, s := range a.wizard() {
|
||||
if s.name() != "Deploy" {
|
||||
es = append(es, gotoEntry{label: "Setup › " + s.name(), id: "side:step:" + strconv.Itoa(i+1)})
|
||||
}
|
||||
}
|
||||
for _, m := range manageMenu {
|
||||
if (m.screen == "Users" || m.screen == "Rooms") && a.cfg.Homeserver != "synapse" || m.screen == "Tokens" && !a.cfg.UsesMAS() {
|
||||
continue
|
||||
}
|
||||
es = append(es, gotoEntry{label: "Manage › " + m.label, id: "side:manage:" + m.screen})
|
||||
}
|
||||
if a.cfg.Installed() {
|
||||
ms := a.screens[a.index("Manage")].(*manageScreen)
|
||||
ms.cfg = a.cfg
|
||||
for _, act := range ms.actions() {
|
||||
if act.disabled == "" {
|
||||
es = append(es, gotoEntry{label: "Manage › " + act.title, act: act.id})
|
||||
}
|
||||
}
|
||||
}
|
||||
for i, t := range mirrorsTabs {
|
||||
es = append(es, gotoEntry{label: "Mirrors › " + t, id: "side:mirrors:" + strconv.Itoa(i)})
|
||||
}
|
||||
es = append(es, gotoEntry{label: "Test servers", id: "side:test:"})
|
||||
for _, p := range config.Profiles() {
|
||||
if p.Name != config.Active() {
|
||||
es = append(es, gotoEntry{label: "Servers › switch to " + p.Name, id: "side:server:" + p.Name})
|
||||
}
|
||||
}
|
||||
return es
|
||||
}
|
||||
|
||||
// gotoMatches are the entries holding every word typed, in any order.
|
||||
func (a *App) gotoMatches() []gotoEntry {
|
||||
words := strings.Fields(strings.ToLower(a.gotoIn.Value()))
|
||||
var out []gotoEntry
|
||||
next:
|
||||
for _, e := range a.gotoEntries() {
|
||||
for _, w := range words {
|
||||
if !strings.Contains(strings.ToLower(e.label), w) {
|
||||
continue next
|
||||
}
|
||||
}
|
||||
out = append(out, e)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (a *App) gotoKey(m tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
ms := a.gotoMatches()
|
||||
switch m.String() {
|
||||
case "esc", "ctrl+k", "ctrl+c":
|
||||
a.gotoOpen = false
|
||||
return a, nil
|
||||
case "up", "ctrl+p", "shift+tab":
|
||||
a.gotoSel = max(0, a.gotoSel-1)
|
||||
return a, nil
|
||||
case "down", "ctrl+n", "tab":
|
||||
a.gotoSel = min(len(ms)-1, a.gotoSel+1)
|
||||
return a, nil
|
||||
case "enter":
|
||||
if len(ms) == 0 {
|
||||
return a, nil
|
||||
}
|
||||
a.gotoOpen = false
|
||||
e := ms[min(a.gotoSel, len(ms)-1)]
|
||||
if e.act == "" {
|
||||
return a, a.sideClick(e.id)
|
||||
}
|
||||
cmd := a.sideClick("side:manage:Manage")
|
||||
mg, ok := a.cur().(*manageScreen)
|
||||
if !ok {
|
||||
return a, cmd // busy, or not installed: sideClick said why
|
||||
}
|
||||
for i, act := range mg.actions() {
|
||||
if act.id != e.act {
|
||||
continue
|
||||
}
|
||||
mg.cursor = i
|
||||
if runsAtOnce[act.id] { // changes the server: a second enter runs it
|
||||
mg.armed, mg.armedKey = true, "enter"
|
||||
return a, cmd
|
||||
}
|
||||
return a, tea.Batch(cmd, mg.choose(act.id))
|
||||
}
|
||||
return a, cmd
|
||||
}
|
||||
var cmd tea.Cmd
|
||||
a.gotoIn, cmd = a.gotoIn.Update(m)
|
||||
a.gotoSel = 0
|
||||
return a, cmd
|
||||
}
|
||||
|
||||
func (a *App) gotoView(w, h int) string {
|
||||
a.gotoIn.Width = max(10, min(w, maxFormWidth)-4)
|
||||
lines := []string{a.gotoIn.View(), ""}
|
||||
ms := a.gotoMatches()
|
||||
if len(ms) == 0 {
|
||||
lines = append(lines, sMuted.Render(" nothing called that"))
|
||||
}
|
||||
room := max(1, h-len(lines))
|
||||
top := max(0, min(a.gotoSel-room+1, len(ms)-room))
|
||||
for i := top; i < min(len(ms), top+room); i++ {
|
||||
row := " " + sTitle.Render(truncate(ms[i].label, w-2))
|
||||
if i == a.gotoSel {
|
||||
row = sAccent.Render("▌ ") + sFocus.Render(truncate(ms[i].label, w-2))
|
||||
}
|
||||
lines = append(lines, markRow("goto:"+strconv.Itoa(i), row, w))
|
||||
}
|
||||
return strings.Join(lines, "\n")
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
func gotoType(a *App, s string) {
|
||||
a.Update(tea.KeyMsg{Type: tea.KeyCtrlK})
|
||||
a.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune(s)})
|
||||
a.Update(tea.KeyMsg{Type: tea.KeyEnter})
|
||||
}
|
||||
|
||||
// ctrl+k goes to a screen, or to a Manage action; one that changes the
|
||||
// server waits for a second enter.
|
||||
func TestGoto(t *testing.T) {
|
||||
a := demoApp(t, 120, 36)
|
||||
if a.cfg.Installed() {
|
||||
t.Fatal("the demo shouldn't be installed")
|
||||
}
|
||||
gotoType(a, "manage backups")
|
||||
if a.gotoOpen || a.cur().name() == "Backups" || a.status == "" {
|
||||
t.Errorf("an action on a server not installed should say why, at %s", a.cur().name())
|
||||
}
|
||||
a.cfg.PlaybookDir = t.TempDir()
|
||||
vars := filepath.Join(a.cfg.PlaybookDir, "inventory", "host_vars", a.cfg.HostName(), "vars.yml")
|
||||
os.MkdirAll(filepath.Dir(vars), 0o755)
|
||||
os.WriteFile(vars, nil, 0o600)
|
||||
gotoType(a, "fine tune")
|
||||
if a.gotoOpen || a.cur().name() != "Tuning" {
|
||||
t.Fatalf("ctrl+k fine tune went to %s", a.cur().name())
|
||||
}
|
||||
gotoType(a, "back up the")
|
||||
ms, ok := a.cur().(*manageScreen)
|
||||
if !ok || !ms.armed || ms.actions()[ms.cursor].id != "backup" {
|
||||
t.Fatalf("ctrl+k back up should arm the backup on Manage, at %s", a.cur().name())
|
||||
}
|
||||
gotoType(a, "zzz")
|
||||
if !a.gotoOpen {
|
||||
t.Error("enter with nothing matching closed the box")
|
||||
}
|
||||
a.Update(tea.KeyMsg{Type: tea.KeyEsc})
|
||||
if a.gotoOpen || a.cur().name() != "Manage" {
|
||||
t.Error("esc should close the box and stay put")
|
||||
}
|
||||
}
|
||||
@@ -118,6 +118,8 @@ func (a *App) compactView() string {
|
||||
switch {
|
||||
case a.menuOpen:
|
||||
content = a.menuScrolled(a.menuTiles(inner)+"\n"+a.menuLink("app:layout", "◫", a.layoutName(), "")+" "+a.menuLink("app:theme", "◐", themeName, ""), bodyH)
|
||||
case a.gotoOpen:
|
||||
content = sTitle.Render("Go to") + "\n\n" + a.gotoView(inner, bodyH-2)
|
||||
case a.sheetOpen:
|
||||
content = a.sheetView(inner, bodyH)
|
||||
default:
|
||||
@@ -189,6 +191,8 @@ func (a *App) compactHeader(w int) string {
|
||||
switch {
|
||||
case a.menuOpen:
|
||||
where = sAccent.Render("Menu")
|
||||
case a.gotoOpen:
|
||||
where = sAccent.Render("Go to")
|
||||
case a.sheetOpen:
|
||||
where = sAccent.Render("Keys")
|
||||
case a.step == 0:
|
||||
@@ -245,7 +249,7 @@ type barButton struct {
|
||||
func (a *App) compactBar(w int) string {
|
||||
var bs []barButton
|
||||
switch {
|
||||
case a.menuOpen || a.sheetOpen:
|
||||
case a.menuOpen || a.sheetOpen || a.gotoOpen:
|
||||
bs = append(bs, barButton{"key:esc", "✕ close", false})
|
||||
default:
|
||||
if a.step > 0 {
|
||||
@@ -347,7 +351,7 @@ func (a *App) sheetLines(inner int) ([]string, int) {
|
||||
}
|
||||
mine := len(lines)
|
||||
lines = append(lines, "", sSection.Render("Anywhere"))
|
||||
anywhere := [][2]string{{"ctrl+b", "the menu"}, {"esc", "back"}, {"?", "these keys"}, {"ctrl+s", "save answers"},
|
||||
anywhere := [][2]string{{"ctrl+k", "go to a screen or action"}, {"ctrl+b", "the menu"}, {"esc", "back"}, {"?", "these keys"}, {"ctrl+s", "save answers"},
|
||||
{"ctrl+l", "layout: " + a.layoutName()}, {"ctrl+y", "theme: " + themeName}, {"q", "quit, when not typing"}, {"ctrl+c", "quit"}}
|
||||
if a.compact() {
|
||||
anywhere = slices.DeleteFunc(anywhere, func(k [2]string) bool { return k[0] == "esc" || k[0] == "?" })
|
||||
|
||||
@@ -207,6 +207,13 @@ func (a *App) tap(ids []string) (tea.Model, tea.Cmd) {
|
||||
cycleTheme()
|
||||
return a, nil
|
||||
}
|
||||
if n, ok := strings.CutPrefix(id, "goto:"); ok && a.gotoOpen {
|
||||
a.gotoSel, _ = strconv.Atoi(n)
|
||||
return a.gotoKey(tea.KeyMsg{Type: tea.KeyEnter})
|
||||
}
|
||||
if a.gotoOpen && !strings.HasPrefix(id, "key:") {
|
||||
continue
|
||||
}
|
||||
if (a.menuOpen || a.sheetOpen) && !strings.HasPrefix(id, "side:") && !strings.HasPrefix(id, "key:") {
|
||||
continue // the screen under the menu isn't shown
|
||||
}
|
||||
|
||||
+14
-14
@@ -3,19 +3,19 @@
|
||||
│ ▸ Setup ││ │
|
||||
│ ││ Keys any key closes this │
|
||||
│ ▾ Manage example.org ││ │
|
||||
│ ▌ ⌂ Overview ││ On this screen P Upgrade Postgres │
|
||||
│ @ Users ││ ↑↓ select C Compress Synapse's state │
|
||||
│ # Rooms ││ enter run d Server dashboard │
|
||||
│ ▦ Dashboard ││ a–z shortcuts l View logs │
|
||||
│ ↻ Updates ││ u Update the server f Fine-tune the roles │
|
||||
│ ◷ Backups ││ c Check services $ Database shell │
|
||||
│ ⚑ Alerts ││ r Restart all services x Run playbook tags │
|
||||
│ ↺ Restore ││ n See what an update brings w Change the setup │
|
||||
│ ↶ Rollback ││ i Check container images v Move to another server │
|
||||
│ ✎ Fine-tune ││ A Alerts o Other servers │
|
||||
│ ⚒ Maintenance ││ p Start, stop or reinstall serv… X Uninstall everything │
|
||||
│ ⇢ Move server ││ U Update interzone │
|
||||
│ ▤ Servers ││ a Add a user Anywhere │
|
||||
│ ▌ ⌂ Overview ││ On this screen C Compress Synapse's state │
|
||||
│ @ Users ││ ↑↓ select d Server dashboard │
|
||||
│ # Rooms ││ enter run l View logs │
|
||||
│ ▦ Dashboard ││ a–z shortcuts f Fine-tune the roles │
|
||||
│ ↻ Updates ││ u Update the server $ Database shell │
|
||||
│ ◷ Backups ││ c Check services x Run playbook tags │
|
||||
│ ⚑ Alerts ││ r Restart all services w Change the setup │
|
||||
│ ↺ Restore ││ n See what an update brings v Move to another server │
|
||||
│ ↶ Rollback ││ i Check container images o Other servers │
|
||||
│ ✎ Fine-tune ││ A Alerts X Uninstall everything │
|
||||
│ ⚒ Maintenance ││ p Start, stop or reinstall serv… │
|
||||
│ ⇢ Move server ││ U Update interzone Anywhere │
|
||||
│ ▤ Servers ││ a Add a user ctrl+k go to a screen or action │
|
||||
│ ││ m Manage users ctrl+b the menu │
|
||||
│ ▸ Mirrors ││ R Manage rooms esc back │
|
||||
│ ││ b Back up the database ? these keys │
|
||||
@@ -24,7 +24,7 @@
|
||||
│ ▾ Servers ││ z Roll back ctrl+y theme: interzone │
|
||||
│ ● example.org ││ D Disk space q quit, when not typing │
|
||||
│ ││ V Vacuum the database ctrl+c quit │
|
||||
│ ││ │
|
||||
│ ││ P Upgrade Postgres │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
|
||||
+2
-2
@@ -6,6 +6,8 @@
|
||||
|
||||
|
||||
Anywhere
|
||||
ctrl+k go to a screen or action
|
||||
|
||||
ctrl+b the menu
|
||||
|
||||
ctrl+s save answers
|
||||
@@ -35,6 +37,4 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
✕ close
|
||||
+1
-1
@@ -4,6 +4,7 @@
|
||||
a–z shortcuts
|
||||
|
||||
Anywhere
|
||||
ctrl+k go to a screen or action
|
||||
ctrl+b the menu
|
||||
ctrl+s save answers
|
||||
ctrl+l layout: auto (compact)
|
||||
@@ -16,5 +17,4 @@
|
||||
|
||||
|
||||
|
||||
|
||||
✕ close
|
||||
Reference in new issue
Block a user