Make the whole UI clickable

Menu entries, form fields, options, checkboxes, list rows, tabs and the key
hints all take clicks; the wheel scrolls. -no-mouse leaves the mouse to the
terminal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
vvvomitandClaude Opus 5.5 committed 2026-10-25 04:44:45 +03:30
1 parent 5eb27065b2
commit 8a760b50ae
15 files changed
+608 -72

No files matched your search

+7
View File
@@ -152,6 +152,7 @@ install itself from a PyPI mirror).
```sh
./interzone # start the wizard (or the Manage menu, once installed)
./interzone --reset # forget saved answers
./interzone -no-mouse # leave the mouse to the terminal
```
The menu on the left shows where you are: the setup steps, the Manage
@@ -170,6 +171,12 @@ rail.
| `ctrl+b` | fold or unfold the menu on the left |
| `esc` | back |
Everything also works with the mouse: click a menu entry, a field, an option,
a checkbox or a key in the bar at the bottom. In lists, the first click selects
a row and a second click opens it. The wheel scrolls. While interzone has the
mouse, hold `shift` to select text in most terminals, or start it with
`-no-mouse`.
On the Review screen, `enter` deploys and `s` only writes the files and prints
the `ansible-playbook` command to run later.
+2 -1
View File
@@ -22,6 +22,7 @@ require (
github.com/clipperhouse/stringish v0.1.1 // indirect
github.com/clipperhouse/uax29/v2 v2.5.0 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/lrstanley/bubblezone v1.0.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.19 // indirect
@@ -31,5 +32,5 @@ require (
github.com/rivo/uniseg v0.4.7 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
golang.org/x/sys v0.38.0 // indirect
golang.org/x/text v0.3.8 // indirect
golang.org/x/text v0.24.0 // indirect
)
+4
View File
@@ -30,6 +30,8 @@ github.com/clipperhouse/uax29/v2 v2.5.0 h1:x7T0T4eTHDONxFJsL94uKNKPHrclyFI0lm7+w
github.com/clipperhouse/uax29/v2 v2.5.0/go.mod h1:Wn1g7MK6OoeDT0vL+Q0SQLDz/KpfsVRgg6W7ihQeh4g=
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
github.com/lrstanley/bubblezone v1.0.0 h1:bIpUaBilD42rAQwlg/4u5aTqVAt6DSRKYZuSdmkr8UA=
github.com/lrstanley/bubblezone v1.0.0/go.mod h1:kcTekA8HE/0Ll2bWzqHlhA2c513KDNLW7uDfDP4Mly8=
github.com/lucasb-eyer/go-colorful v1.3.0 h1:2/yBRLdWBZKrf7gB40FoiKfAWYQ0lqNcbuQwVHXptag=
github.com/lucasb-eyer/go-colorful v1.3.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
@@ -56,6 +58,8 @@ golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=
golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY=
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0=
golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
+17 -4
View File
@@ -7,6 +7,7 @@ import (
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
zone "github.com/lrstanley/bubblezone"
"interzone/internal/config"
)
@@ -47,6 +48,7 @@ type App struct {
}
func New(cfg *config.Config, loaded bool) *App {
zone.NewGlobal()
a := &App{cfg: cfg, loaded: loaded, sideCollapsed: loadSidebarCollapsed()}
a.screens = []screen{
&welcomeScreen{loaded: loaded},
@@ -113,6 +115,8 @@ func (a *App) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch m := msg.(type) {
case tea.WindowSizeMsg:
a.w, a.h = m.Width, m.Height
case tea.MouseMsg:
return a.mouse(m)
case navMsg:
return a, a.go_(int(m))
case formDoneMsg:
@@ -205,6 +209,7 @@ func (a *App) View() string {
if a.w == 0 {
return ""
}
marked = marked[:0]
header := a.header(a.w)
footer := a.footer(a.w)
// With the menu open, it shows the steps; the stepper line is only
@@ -244,7 +249,7 @@ func (a *App) View() string {
if stepper != "" {
parts = append(parts, stepper)
}
return lipgloss.JoinVertical(lipgloss.Left, append(parts, body, footer)...)
return zone.Scan(lipgloss.JoinVertical(lipgloss.Left, append(parts, body, footer)...))
}
func (a *App) header(w int) string {
@@ -302,12 +307,12 @@ func (a *App) stepper(w int) string {
func (a *App) footer(w int) string {
var parts []string
for _, k := range a.cur().keys() {
parts = append(parts, sKey.Render(k[0])+" "+sMuted.Render(k[1]))
parts = append(parts, hint(k[0], k[1]))
}
if a.step > 0 {
parts = append(parts, sKey.Render("esc")+" "+sMuted.Render("back"))
parts = append(parts, hint("esc", "back"))
}
parts = append(parts, sKey.Render("ctrl+c")+" "+sMuted.Render("quit"))
parts = append(parts, hint("ctrl+c", "quit"))
line := " " + strings.Join(parts, sFaint.Render(" · "))
if lipgloss.Width(line) > w {
line = " " + strings.Join(parts, sFaint.Render(" · "))
@@ -318,6 +323,14 @@ func (a *App) footer(w int) string {
return truncateANSI(line, w)
}
// hint is a footer key hint; a one-key hint is clickable as a whole.
func hint(key, desc string) string {
if _, ok := keyMsg(key); ok {
return mark("key:"+key, sKey.Render(key)+" "+sMuted.Render(desc))
}
return keyLink(key) + " " + sMuted.Render(desc)
}
func truncateANSI(s string, w int) string {
if lipgloss.Width(s) <= w {
return s
+60 -8
View File
@@ -1,6 +1,7 @@
package ui
import (
"strconv"
"strings"
"github.com/charmbracelet/bubbles/textarea"
@@ -115,10 +116,14 @@ type form struct {
focus int
reveal bool
width int
id string // prefix of its click zones
}
var formCount int
func newForm(fields ...*field) *form {
f := &form{fields: fields}
formCount++
f := &form{fields: fields, id: "form" + strconv.Itoa(formCount) + ":"}
f.focus = -1
f.move(1)
return f
@@ -295,7 +300,7 @@ func (f *form) View(width, height int) string {
lines = append(lines, "")
}
first = false
lines = append(lines, strings.Split(f.renderField(fl, i == f.focus, width), "\n")...)
lines = append(lines, strings.Split(markLines(f.id+"f"+strconv.Itoa(i), f.renderField(fl, i, i == f.focus, width)), "\n")...)
if i == f.focus {
focusStart, focusEnd = start, len(lines)
}
@@ -313,10 +318,10 @@ func (f *form) View(width, height int) string {
top = max(0, min(top, len(lines)-height))
view := lines[top : top+height]
if top > 0 {
view[0] = sFaint.Render(" ▲ more above")
view[0] = mark(f.id+"up", sFaint.Render(" ▲ more above"))
}
if top+height < len(lines) {
view[len(view)-1] = sFaint.Render(" ▼ more below")
view[len(view)-1] = mark(f.id+"down", sFaint.Render(" ▼ more below"))
}
return strings.Join(view, "\n")
}
@@ -331,7 +336,7 @@ func sectionHeading(title string, width int) string {
return head + " " + sFaint.Render(strings.Repeat("─", rule))
}
func (f *form) renderField(fl *field, focused bool, width int) string {
func (f *form) renderField(fl *field, idx int, focused bool, width int) string {
bar := " "
label := sMuted.Render(fl.label)
prompt := sFaint.Render("› ")
@@ -363,11 +368,11 @@ func (f *form) renderField(fl *field, focused bool, width int) string {
if fl.labels != nil {
name = fl.labels[i]
}
opt := sMuted.Padding(0, 2).Render(name)
if i == fl.choice {
parts = append(parts, lipgloss.NewStyle().Foreground(lipgloss.Color("#111018")).Background(cPurple).Bold(true).Padding(0, 2).Render(name))
} else {
parts = append(parts, sMuted.Padding(0, 2).Render(name))
opt = lipgloss.NewStyle().Foreground(lipgloss.Color("#111018")).Background(cPurple).Bold(true).Padding(0, 2).Render(name)
}
parts = append(parts, mark(f.id+"c"+strconv.Itoa(idx)+"."+strconv.Itoa(i), opt))
}
body = strings.Join(parts, " ")
case fArea:
@@ -396,3 +401,50 @@ func helpLine(fl *field, focused bool, bar string, width int) string {
help := lipgloss.NewStyle().Foreground(cMuted).Italic(true).Width(max(20, width)).Render(fl.help)
return "\n" + bar + strings.ReplaceAll(help, "\n", "\n"+bar)
}
// focusOn moves the focus to field i.
func (f *form) focusOn(i int) {
if i == f.focus || i < 0 || i >= len(f.fields) || !f.fields[i].visible() {
return
}
f.focus = i - 1
if !f.move(1) {
f.focus = i
}
}
// click handles a click on one of the form's zones: a field takes the
// focus (a toggle also flips), a choice option is picked.
func (f *form) click(id string) (tea.Cmd, bool) {
rest, ok := strings.CutPrefix(id, f.id)
if !ok {
return nil, false
}
switch {
case rest == "up":
f.move(-1)
case rest == "down":
f.move(1)
case strings.HasPrefix(rest, "c"):
a, b, _ := strings.Cut(rest[1:], ".")
i, err1 := strconv.Atoi(a)
j, err2 := strconv.Atoi(b)
if err1 != nil || err2 != nil || i >= len(f.fields) || j >= len(f.fields[i].choices) {
return nil, false
}
f.focusOn(i)
f.fields[i].choice = j
case strings.HasPrefix(rest, "f"):
i, err := strconv.Atoi(rest[1:])
if err != nil || i >= len(f.fields) {
return nil, false
}
f.focusOn(i)
if fl := f.fields[i]; fl.kind == fToggle {
fl.on = !fl.on
}
default:
return nil, false
}
return nil, true
}
+257
View File
@@ -0,0 +1,257 @@
package ui
import (
"sort"
"strconv"
"strings"
tea "github.com/charmbracelet/bubbletea"
zone "github.com/lrstanley/bubblezone"
"interzone/internal/config"
)
// ── Mouse ──────────────────────────────────────────────────────────
//
// Clickable parts of the view are wrapped with mark(id, text). The final
// frame is scanned for the markers, and a click is resolved to the ids
// under the pointer, smallest zone first:
//
// key:<name> a key hint; clicking presses the key
// side:… the menu on the left (sidebar.go)
// anything else handled by the screen's click method, or its form
//
// The wheel scrolls by sending ↑ and ↓ to the screen.
// clicker is a screen with clickable parts of its own.
type clicker interface {
// click handles a click on id and reports whether it did.
click(id string) (tea.Cmd, bool)
}
// formHolder is a screen showing a form that should take clicks.
type formHolder interface{ activeForm() *form }
// marked lists the zone ids of the frame being drawn. A mark's zone id
// gets the occurrence number appended, so the same id can be marked more
// than once in a frame (a key in the footer and in a dialog).
var marked []string
func mark(id, s string) string {
if s == "" {
return s
}
zid := id + "#" + strconv.Itoa(len(marked))
marked = append(marked, zid)
return zone.Mark(zid, s)
}
// markLines marks every line of s separately with id, so a block that
// is later cut into lines (scrolling) still resolves.
func markLines(id, s string) string {
lines := strings.Split(s, "\n")
for i, l := range lines {
lines[i] = mark(id, l)
}
return strings.Join(lines, "\n")
}
// hits returns the ids under the pointer, smallest zone first.
func hits(m tea.MouseMsg) []string {
type hit struct {
id string
area int
}
var hs []hit
for _, zid := range marked {
z := zone.Get(zid)
if !z.InBounds(m) {
continue
}
id := zid[:strings.LastIndex(zid, "#")]
hs = append(hs, hit{id, (z.EndX - z.StartX + 1) * (z.EndY - z.StartY + 1)})
}
sort.SliceStable(hs, func(i, j int) bool { return hs[i].area < hs[j].area })
var out []string
seen := map[string]bool{}
for _, h := range hs {
if !seen[h.id] {
seen[h.id] = true
out = append(out, h.id)
}
}
return out
}
// keyMsg turns a key name as the hints spell it into a key press, or
// reports false for names that aren't one key ("↑↓", "type").
func keyMsg(name string) (tea.KeyMsg, bool) {
named := map[string]tea.KeyType{
"enter": tea.KeyEnter, "esc": tea.KeyEsc, "tab": tea.KeyTab, "shift+tab": tea.KeyShiftTab,
"del": tea.KeyDelete, "delete": tea.KeyDelete, "backspace": tea.KeyBackspace,
"up": tea.KeyUp, "down": tea.KeyDown, "left": tea.KeyLeft, "right": tea.KeyRight,
"↑": tea.KeyUp, "↓": tea.KeyDown, "←": tea.KeyLeft, "→": tea.KeyRight,
"home": tea.KeyHome, "end": tea.KeyEnd, "pgup": tea.KeyPgUp, "pgdown": tea.KeyPgDown,
}
if t, ok := named[name]; ok {
return tea.KeyMsg{Type: t}, true
}
if name == "space" {
return tea.KeyMsg{Type: tea.KeySpace, Runes: []rune{' '}}, true
}
if c, ok := strings.CutPrefix(name, "ctrl+"); ok && len(c) == 1 && c[0] >= 'a' && c[0] <= 'z' {
return tea.KeyMsg{Type: tea.KeyType(c[0] - 'a' + 1)}, true
}
if r := []rune(name); len(r) == 1 {
return tea.KeyMsg{Type: tea.KeyRunes, Runes: r}, true
}
return tea.KeyMsg{}, false
}
// keyLink renders a key name as a clickable hint. Combined hints are
// split into their keys: "↑↓" → ↑ and ↓, "tab/↑↓" → tab, ↑ and ↓.
func keyLink(name string) string {
if strings.Contains(name, "/") && len(name) > 1 {
parts := strings.Split(name, "/")
for i, p := range parts {
parts[i] = keyLink(p)
}
return strings.Join(parts, sKey.Render("/"))
}
if r := []rune(name); len(r) == 2 && strings.ContainsRune("↑←", r[0]) {
return keyLink(string(r[0])) + keyLink(string(r[1]))
}
if _, ok := keyMsg(name); !ok {
return sKey.Render(name)
}
return mark("key:"+name, sKey.Render(name))
}
// rowClick handles a click on a list row id "<prefix><n>": the first click
// selects the row, a click on the selected row activates it.
func rowClick(id, prefix string, cursor *int, n int) (row int, activate, ok bool) {
rest, found := strings.CutPrefix(id, prefix)
if !found {
return 0, false, false
}
i, err := strconv.Atoi(rest)
if err != nil || i < 0 || i >= n {
return 0, false, false
}
activate = *cursor == i
*cursor = i
return i, activate, true
}
func (a *App) mouse(m tea.MouseMsg) (tea.Model, tea.Cmd) {
ids := hits(m)
onSide := false
for _, id := range ids {
onSide = onSide || strings.HasPrefix(id, "side:")
}
switch {
case m.Action != tea.MouseActionPress:
return a, nil
case m.Button == tea.MouseButtonWheelUp || m.Button == tea.MouseButtonWheelDown:
if onSide || a.cur().typing() && !a.wheelOK() {
return a, nil
}
k := tea.KeyMsg{Type: tea.KeyDown}
if m.Button == tea.MouseButtonWheelUp {
k.Type = tea.KeyUp
}
return a, a.cur().update(k)
case m.Button != tea.MouseButtonLeft:
return a, nil
}
for _, id := range ids {
if name, ok := strings.CutPrefix(id, "key:"); ok {
if k, ok := keyMsg(name); ok {
return a.Update(k)
}
}
if strings.HasPrefix(id, "side:") {
return a, a.sideClick(id)
}
if c, ok := a.cur().(clicker); ok {
if cmd, done := c.click(id); done {
return a, cmd
}
}
if fh, ok := a.cur().(formHolder); ok {
if f := fh.activeForm(); f != nil {
if cmd, done := f.click(id); done {
return a, cmd
}
}
}
}
return a, nil
}
// wheelOK reports whether ↑↓ only move around on the current screen even
// while it takes typing (a form's text field), so the wheel can send them.
func (a *App) wheelOK() bool {
if fh, ok := a.cur().(formHolder); ok {
if f := fh.activeForm(); f != nil {
c := f.current()
return c == nil || c.kind != fArea
}
}
return false
}
// busy reports whether a deploy runs, during which the menu can't leave.
func (a *App) busy() bool {
ds, ok := a.cur().(*deployScreen)
return ok && ds.running
}
func (a *App) sideClick(id string) tea.Cmd {
if id == "side:fold" {
a.toggleSidebar()
return nil
}
if a.busy() {
a.status = sWarn.Render("! wait for the run to finish, or press ctrl+c to stop it")
return nil
}
rest := strings.TrimPrefix(id, "side:")
kind, arg, _ := strings.Cut(rest, ":")
switch kind {
case "step":
n, err := strconv.Atoi(arg)
if err != nil || a.screens[n].name() == "Deploy" {
return nil // a deploy starts from Review
}
return a.jump(n)
case "manage":
if !a.cfg.Installed() && arg != "Servers" {
a.status = sWarn.Render("! set up and deploy the server first; Manage works on an installed server")
return nil
}
return a.jump(a.index(arg))
case "server":
if arg == config.Active() {
return a.jump(a.index("Servers"))
}
c, err := config.LoadFile(config.ProfilePath(arg))
if err != nil {
a.status = sBad.Render("✗ " + err.Error())
return nil
}
return a.switchServer(switchServerMsg{name: arg, cfg: c})
case "head":
switch arg {
case "setup":
if a.section() != sideSetup {
return a.jump(a.index("Network"))
}
case "manage":
return a.sideClick("side:manage:Manage")
case "servers":
return a.jump(a.index("Servers"))
}
}
return nil
}
+187
View File
@@ -0,0 +1,187 @@
package ui
import (
"strconv"
"strings"
tea "github.com/charmbracelet/bubbletea"
"interzone/internal/catalog"
)
// Click handling of each screen (see mouse.go). Lists work the same way
// everywhere: a click selects a row, a click on the selected row opens it
// as enter would.
var enterKey = tea.KeyMsg{Type: tea.KeyEnter}
// listClick handles a click on a listRows row of a screen whose enter acts
// on the cursor row.
func listClick(id string, cursor *int, n int, update func(tea.Msg) tea.Cmd) (tea.Cmd, bool) {
_, activate, ok := rowClick(id, "row:", cursor, n)
if !ok {
return nil, false
}
if activate {
return update(enterKey), true
}
return nil, true
}
// The forms each screen shows.
func (s *networkScreen) activeForm() *form { return s.form }
func (s *serverScreen) activeForm() *form { return s.form }
func (s *sslScreen) activeForm() *form { return s.form }
func (s *settingsScreen) activeForm() *form { return s.form }
func (s *backupsScreen) activeForm() *form { return s.form }
func (s *serversScreen) activeForm() *form { return s.form }
func (s *migrateScreen) activeForm() *form {
if s.confirm {
return nil
}
return s.form
}
func (s *manageScreen) activeForm() *form {
if s.mode != modeUser {
return nil
}
return s.userForm
}
func (s *usersScreen) activeForm() *form {
if s.mode != usersLogin && s.mode != usersNew {
return nil
}
return s.form
}
func (s *welcomeScreen) click(id string) (tea.Cmd, bool) {
if _, _, ok := rowClick(id, "welcome:", &s.choice, 2); ok {
return s.update(enterKey), true // two big options: one click picks
}
return nil, false
}
func (s *homeserverScreen) click(id string) (tea.Cmd, bool) {
_, activate, ok := rowClick(id, "hs:", &s.sel, len(catalog.Homeservers))
if ok && activate {
return nav(1), true
}
return nil, ok
}
func (s *componentsScreen) click(id string) (tea.Cmd, bool) {
items := s.items()
toggle := func(i int) {
if it := items[i]; s.available(it) {
s.selected[it.ID] = !s.selected[it.ID]
}
}
if i, _, ok := rowClick(id, "compbox:", &s.cursor, len(items)); ok {
toggle(i)
return nil, true
}
if i, activate, ok := rowClick(id, "comp:", &s.cursor, len(items)); ok {
if activate {
toggle(i)
}
return nil, true
}
if rest, ok := strings.CutPrefix(id, "cat:"); ok {
i, err := strconv.Atoi(rest)
if err != nil || i >= len(catalog.Categories) {
return nil, false
}
s.filtering = false
s.filter.SetValue("")
s.filter.Blur()
s.cat, s.cursor, s.offset = i, 0, 0
return nil, true
}
if id == "compfilter" && !s.filtering {
s.filtering = true
return s.filter.Focus(), true
}
return nil, false
}
func (s *manageScreen) click(id string) (tea.Cmd, bool) {
switch s.mode {
case modeList:
acts := s.actions()
i, activate, ok := rowClick(id, "act:", &s.cursor, len(acts))
if ok && activate && acts[i].disabled == "" {
return s.choose(acts[i].id), true
}
return nil, ok
case modeServices:
_, activate, ok := rowClick(id, "unit:", &s.unit, len(s.units))
if ok && activate {
return s.update(enterKey), true
}
return nil, ok
}
return nil, false
}
func (s *historyScreen) click(id string) (tea.Cmd, bool) {
if s.confirm {
return nil, false
}
return listClick(id, &s.cursor, len(s.list), s.update)
}
func (s *restoreScreen) click(id string) (tea.Cmd, bool) {
if s.confirm {
return nil, false
}
return listClick(id, &s.cursor, len(s.list), s.update)
}
func (s *usersScreen) click(id string) (tea.Cmd, bool) {
if s.mode != usersList || s.busy {
return nil, false
}
return listClick(id, &s.cursor, len(s.users), s.update)
}
func (s *serversScreen) click(id string) (tea.Cmd, bool) {
if s.form != nil || s.confirm {
return nil, false
}
return listClick(id, &s.cursor, len(s.list), s.update)
}
func (s *tuningScreen) click(id string) (tea.Cmd, bool) {
if s.editing || s.err != nil || s.fetching {
return nil, false
}
if id == "tfilter" {
if !s.filtering {
s.filtering = true
return s.filter.Focus(), true
}
return nil, true
}
if s.filtering { // a click in the list ends the search, as ↑↓ do
s.filtering = false
s.filter.Blur()
}
if s.role < 0 {
_, activate, ok := rowClick(id, "trole:", &s.roleCursor, len(s.roleItems()))
if ok && activate {
return s.roleKey(enterKey), true
}
return nil, ok
}
_, activate, ok := rowClick(id, "tvar:", &s.cursor, len(s.items()))
if ok && activate {
if v, found := s.current(); found {
s.startEdit(v)
}
}
return nil, ok
}
+10 -8
View File
@@ -2,6 +2,7 @@ package ui
import (
"fmt"
"strconv"
"strings"
"github.com/charmbracelet/bubbles/textinput"
@@ -155,11 +156,11 @@ func (s *componentsScreen) view(w, h int) string {
}
}
label := cat + " " + fmt.Sprintf("%d/%d", on, n)
tab := sMuted.Padding(0, 2).Render(label)
if i == s.cat && s.filter.Value() == "" {
tabs = append(tabs, lipgloss.NewStyle().Foreground(lipgloss.Color("#111018")).Background(cPurple).Bold(true).Padding(0, 2).Render(label))
} else {
tabs = append(tabs, sMuted.Padding(0, 2).Render(label))
tab = lipgloss.NewStyle().Foreground(lipgloss.Color("#111018")).Background(cPurple).Bold(true).Padding(0, 2).Render(label)
}
tabs = append(tabs, mark("cat:"+strconv.Itoa(i), tab))
}
count := 0
@@ -174,6 +175,7 @@ func (s *componentsScreen) view(w, h int) string {
if s.filtering || s.filter.Value() != "" {
top = s.filter.View()
}
top = mark("compfilter", top)
top += strings.Repeat(" ", max(2, w-lipgloss.Width(top)-lipgloss.Width(total))) + total
items := s.items()
@@ -188,7 +190,7 @@ func (s *componentsScreen) view(w, h int) string {
// one shows its full description), so scroll by whole items.
blocks := make([]string, len(items))
for i, it := range items {
blocks[i] = s.row(it, i == s.cursor, w)
blocks[i] = markLines("comp:"+strconv.Itoa(i), s.row(it, i, i == s.cursor, w))
}
used := func(from, to int) int {
n := 0
@@ -245,17 +247,17 @@ func tabStrip(tabs []string, cur, w int) string {
}
left, right := " ", " "
if lo > 0 {
left = sAccent.Render("‹ ")
left = mark("key:←", sAccent.Render("‹ "))
}
if hi < len(tabs) {
right = sAccent.Render(" ›")
right = mark("key:→", sAccent.Render(" ›"))
}
return left + strings.Join(tabs[lo:hi], "") + right
}
// row renders one component: a name line with tags and a description.
// The current one gets a full description plus its DNS name and docs.
func (s *componentsScreen) row(c catalog.Component, cur bool, w int) string {
func (s *componentsScreen) row(c catalog.Component, i int, cur bool, w int) string {
box := sFaint.Render("○")
if s.selected[c.ID] {
box = sGood.Render("●")
@@ -283,7 +285,7 @@ func (s *componentsScreen) row(c catalog.Component, cur bool, w int) string {
if cur {
bar = sAccent.Render("▌") + " "
}
line := bar + box + " " + style.Render(c.Name)
line := bar + mark("compbox:"+strconv.Itoa(i), box) + " " + style.Render(c.Name)
if len(tags) > 0 {
line += " " + strings.Join(tags, sFaint.Render(" · "))
}
+1 -1
View File
@@ -672,7 +672,7 @@ func (s *deployScreen) resultView(w int) string {
}
return panel(cRed, append(lines,
sMuted.Render("Full log: ")+s.logPath(),
sMuted.Render(hint)+sKey.Render("r")+sMuted.Render(" to try again."))...)
sMuted.Render(hint)+keyLink("r")+sMuted.Render(" to try again."))...)
}
res := s.result
if res == nil {
+4 -3
View File
@@ -2,6 +2,7 @@ package ui
import (
"context"
"strconv"
"strings"
"time"
@@ -318,7 +319,7 @@ func (s *manageScreen) view(w, h int) string {
} else {
d = sFaint.Render(truncate(desc, textW))
}
blocks = append(blocks, bar+icon+" "+style.Render(a.title)+"\n"+pad+strings.ReplaceAll(d, "\n", "\n"+pad))
blocks = append(blocks, markLines("act:"+strconv.Itoa(i), bar+icon+" "+style.Render(a.title)+"\n"+pad+strings.ReplaceAll(d, "\n", "\n"+pad)))
}
out := strings.Join(blocks, "\n\n")
if lipgloss.Height(out) <= h {
@@ -346,9 +347,9 @@ func (s *manageScreen) servicesView(w, h int) string {
var rows []string
for i := start; i < len(s.units) && i < start+h; i++ {
if i == s.unit {
rows = append(rows, sAccent.Render("▌")+" "+sTitle.Render(s.units[i]))
rows = append(rows, mark("unit:"+strconv.Itoa(i), sAccent.Render("▌")+" "+sTitle.Render(s.units[i])))
} else {
rows = append(rows, " "+sMuted.Render(s.units[i]))
rows = append(rows, mark("unit:"+strconv.Itoa(i), " "+sMuted.Render(s.units[i])))
}
}
return strings.Join(rows, "\n")
+9 -7
View File
@@ -3,6 +3,7 @@ package ui
import (
"fmt"
"os"
"strconv"
"strings"
"github.com/charmbracelet/bubbles/spinner"
@@ -81,10 +82,11 @@ func (s *welcomeScreen) view(w, h int) string {
switch {
case s.installed:
opt := func(i int, title, desc string) string {
id := "welcome:" + strconv.Itoa(i)
if i == s.choice {
return sAccent.Render("▌ ◉ ") + sTitle.Render(title) + "\n" + sAccent.Render("▌") + " " + sMuted.Render(desc)
return markLines(id, sAccent.Render("▌ ◉ ")+sTitle.Render(title)+"\n"+sAccent.Render("▌")+" "+sMuted.Render(desc))
}
return " " + sFaint.Render("○ ") + sMuted.Render(title) + "\n" + " " + sFaint.Render(desc)
return markLines(id, " "+sFaint.Render("○ ")+sMuted.Render(title)+"\n"+" "+sFaint.Render(desc))
}
parts = append(parts,
sGood.Render("✓ This computer already set up ")+sTitle.Render(s.domain),
@@ -93,9 +95,9 @@ func (s *welcomeScreen) view(w, h int) string {
"",
opt(1, "Change the setup", "Walk through the wizard again with your saved answers."))
case s.loaded:
parts = append(parts, sGood.Render("✓ Picked up your previous answers."), "", "", sAccent.Render("Press enter to begin ›"))
parts = append(parts, sGood.Render("✓ Picked up your previous answers."), "", "", mark("key:enter", sAccent.Render("Press enter to begin ›")))
default:
parts = append(parts, sAccent.Render("Press enter to begin ›"))
parts = append(parts, mark("key:enter", sAccent.Render("Press enter to begin ›")))
}
block := lipgloss.JoinVertical(lipgloss.Left, parts...)
return lipgloss.Place(w, h, lipgloss.Center, lipgloss.Center, block)
@@ -249,7 +251,7 @@ func (s *networkScreen) checksView(w int) string {
return s.spin.View() + sMuted.Render(" testing every source…")
}
if s.checks == nil {
return sMuted.Render("Press ") + sKey.Render("ctrl+t") + sMuted.Render(" to test that every source is reachable from here.")
return sMuted.Render("Press ") + keyLink("ctrl+t") + sMuted.Render(" to test that every source is reachable from here.")
}
var lines []string
for _, c := range s.checks {
@@ -385,7 +387,7 @@ func (s *homeserverScreen) cards(w int, compact bool) string {
for i, hs := range catalog.Homeservers {
tag := sMuted.Render(" " + hs.Tagline)
if i != s.sel && compact {
cards = append(cards, " "+sFaint.Render("○ ")+sMuted.Render(hs.Name)+tag)
cards = append(cards, mark("hs:"+strconv.Itoa(i), " "+sFaint.Render("○ ")+sMuted.Render(hs.Name)+tag))
continue
}
style, name := card, sFaint.Render("○ ")+sTitle.Render(hs.Name)
@@ -393,7 +395,7 @@ func (s *homeserverScreen) cards(w int, compact bool) string {
style, name = card.BorderForeground(cPurple), sAccent.Render("◉ ")+gradient(hs.Name)
}
desc := sSub.Width(cardW - 9).Render(hs.Description)
cards = append(cards, style.Render(name+tag+"\n "+strings.ReplaceAll(desc, "\n", "\n ")))
cards = append(cards, markLines("hs:"+strconv.Itoa(i), style.Render(name+tag+"\n "+strings.ReplaceAll(desc, "\n", "\n "))))
}
return strings.Join(cards, "\n\n")
}
+11 -11
View File
@@ -58,16 +58,16 @@ func listRows(rows []string, cur, h int) string {
var out []string
for i := start; i < len(rows) && i < start+h; i++ {
if i == cur {
out = append(out, sAccent.Render("▌")+" "+rows[i])
out = append(out, mark("row:"+strconv.Itoa(i), sAccent.Render("▌")+" "+rows[i]))
} else {
out = append(out, " "+rows[i])
out = append(out, mark("row:"+strconv.Itoa(i), " "+rows[i]))
}
}
return strings.Join(out, "\n")
}
func errorView(err error) string {
return sBad.Render("✗ "+err.Error()) + "\n\n" + sMuted.Render("Press ") + sKey.Render("r") + sMuted.Render(" to try again or esc to go back.")
return sBad.Render("✗ "+err.Error()) + "\n\n" + sMuted.Render("Press ") + keyLink("r") + sMuted.Render(" to try again or esc to go back.")
}
func confirmView(w int, lines ...string) string {
@@ -290,7 +290,7 @@ func (s *historyScreen) view(w, h int) string {
sWarn.Render("Roll back to "+d.Time.Local().Format("2006-01-02 15:04")+"?"),
sSub.Render("The playbook goes back to "+d.Commit[:min(10, len(d.Commit))]+" and your answers to the ones used then (today's are kept in config.before-rollback.json). The database is backed up first."),
sSub.Render("Newer homeserver versions may have changed the database in ways an older one can't read; if it fails to start, restore the backup taken now with Manage › Restore."),
"", sKey.Render("y")+sMuted.Render(" roll back ")+sKey.Render("esc")+sMuted.Render(" cancel"))
"", keyLink("y")+sMuted.Render(" roll back ")+keyLink("esc")+sMuted.Render(" cancel"))
}
return out
}
@@ -357,7 +357,7 @@ func (s *restoreScreen) view(w, h int) string {
}
if len(s.list) == 0 {
return sMuted.Render("No backups of "+s.cfg.Domain+" in "+deploy.BackupDir()+".") + "\n\n" +
sMuted.Render("Make one with Manage › Back up the database, or press ") + sKey.Render("d") +
sMuted.Render("Make one with Manage › Back up the database, or press ") + keyLink("d") +
sMuted.Render(" to download the server's scheduled backups.")
}
var rows []string
@@ -371,7 +371,7 @@ func (s *restoreScreen) view(w, h int) string {
out += "\n\n" + confirmView(w,
sWarn.Render("Replace the database of "+s.cfg.Domain+" with the dump from "+b.Time.Local().Format("2006-01-02 15:04")+"?"),
sSub.Render("Every service stops, the current database is dumped to "+deploy.BackupDir()+" first, then emptied and loaded from this file. Messages sent since the dump are lost."),
"", sKey.Render("y")+sMuted.Render(" restore ")+sKey.Render("esc")+sMuted.Render(" cancel"))
"", keyLink("y")+sMuted.Render(" restore ")+keyLink("esc")+sMuted.Render(" cancel"))
}
return out
}
@@ -442,7 +442,7 @@ func (s *backupsScreen) apply() tea.Cmd {
func (s *backupsScreen) view(w, h int) string {
info := []string{
sSub.Render("Each scheduled backup is a full pg_dumpall, the same as Manage › Back up the database."),
sSub.Render("Press ") + sKey.Render("ctrl+d") + sSub.Render(" to copy them to ") + sTitle.Render(deploy.BackupDir()) +
sSub.Render("Press ") + keyLink("ctrl+d") + sSub.Render(" to copy them to ") + sTitle.Render(deploy.BackupDir()) +
sSub.Render("; Manage › Restore lists them there."),
}
if n := len(deploy.ListBackups(s.cfg.Domain)); n > 0 {
@@ -722,11 +722,11 @@ func (s *usersScreen) view(w, h int) string {
foot := strings.Join(status, "\n")
if s.mode == usersConfirm && s.op != nil {
foot = confirmView(w, sWarn.Render(strings.ToUpper(s.op.desc[:1])+s.op.desc[1:]+"?"), "",
sKey.Render("y")+sMuted.Render(" yes ")+sKey.Render("esc")+sMuted.Render(" cancel"))
keyLink("y")+sMuted.Render(" yes ")+keyLink("esc")+sMuted.Render(" cancel"))
if s.op.body["deactivated"] == true {
foot = confirmView(w, sWarn.Render("Deactivate "+s.op.user+"?"),
sSub.Render("They are signed out everywhere and can't sign in again until reactivated."), "",
sKey.Render("y")+sMuted.Render(" deactivate ")+sKey.Render("esc")+sMuted.Render(" cancel"))
keyLink("y")+sMuted.Render(" deactivate ")+keyLink("esc")+sMuted.Render(" cancel"))
}
}
if len(s.users) == 0 {
@@ -1086,7 +1086,7 @@ func (s *serversScreen) view(w, h int) string {
if s.confirm {
out += "\n\n" + confirmView(w, sWarn.Render("Forget "+s.list[s.cursor].Name+"?"),
sSub.Render("Only interzone's saved answers are deleted. Nothing changes on the server itself."), "",
sKey.Render("y")+sMuted.Render(" forget ")+sKey.Render("esc")+sMuted.Render(" cancel"))
keyLink("y")+sMuted.Render(" forget ")+keyLink("esc")+sMuted.Render(" cancel"))
}
if s.err != "" {
out += "\n\n" + sBad.Render("✗ "+s.err)
@@ -1187,7 +1187,7 @@ func (s *migrateScreen) view(w, h int) string {
sWarn.Render("Move "+s.cfg.Domain+" from "+from+" to "+to+"?"),
sSub.Render("Matrix is down from the moment the old server stops until the new one is installed. Afterwards, point these DNS records at the new server: "+
strings.Join(s.cfg.DNSRecords(), ", ")+"."),
"", sKey.Render("y")+sMuted.Render(" start ")+sKey.Render("esc")+sMuted.Render(" back"))
"", keyLink("y")+sMuted.Render(" start ")+keyLink("esc")+sMuted.Render(" back"))
}
return s.form.View(w, h-lipgloss.Height(info)-3) + "\n\n" + info
}
+11 -10
View File
@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"sort"
"strconv"
"strings"
"time"
@@ -475,7 +476,7 @@ func (s *tuningScreen) view(w, h int) string {
}
if s.err != nil {
return sWarn.Render("The playbook isn't downloaded yet, so its settings can't be listed.") + "\n\n" +
sMuted.Render("Press ") + sKey.Render("f") + sMuted.Render(" to download it from "+s.cfg.Sources.PlaybookGit+".") + "\n\n" +
sMuted.Render("Press ") + keyLink("f") + sMuted.Render(" to download it from "+s.cfg.Sources.PlaybookGit+".") + "\n\n" +
sFaint.Render(s.err.Error())
}
w = min(w, 120)
@@ -518,20 +519,20 @@ func (s *tuningScreen) view(w, h int) string {
if i == s.cursor {
bar, nameStyle = sAccent.Render("▌")+" ", sTitle
}
mark := " "
dot := " "
valStyle := sFaint
if over {
mark, valStyle = sPink.Render("●"), sPink
dot, valStyle = sPink.Render("●"), sPink
} else if !v.Derived {
valStyle = sSub
}
name := lipgloss.NewStyle().Width(nameW).Render(nameStyle.Render(truncate(v.Name, nameW-2)))
rows = append(rows, bar+mark+" "+name+valStyle.Render(truncate(first, max(8, w-nameW-6))))
rows = append(rows, mark("tvar:"+strconv.Itoa(i), bar+dot+" "+name+valStyle.Render(truncate(first, max(8, w-nameW-6)))))
}
if len(items) == 0 {
rows = append(rows, sMuted.Render(" nothing matches"))
}
return head + "\n" + filter + "\n\n" + strings.Join(rows, "\n") + "\n\n" + detail
return head + "\n" + mark("tfilter", filter) + "\n\n" + strings.Join(rows, "\n") + "\n\n" + detail
}
func (s *tuningScreen) rolesView(w, h int) string {
@@ -564,9 +565,9 @@ func (s *tuningScreen) rolesView(w, h int) string {
if i == s.roleCursor {
bar, nameStyle = sAccent.Render("▌")+" ", sTitle
}
mark := " "
dot := " "
if row.change > 0 {
mark = sPink.Render("●")
dot = sPink.Render("●")
}
count := plural(len(r.Vars), "setting")
if s.query() != "" && row.matching > 0 {
@@ -579,15 +580,15 @@ func (s *tuningScreen) rolesView(w, h int) string {
if r.inUse {
info += sGood.Render(" in use")
}
lines = append(lines, bar+mark+" "+lipgloss.NewStyle().Width(nameW).Render(nameStyle.Render(truncate(r.Name, nameW-2)))+
lipgloss.NewStyle().Width(labelW).Render(sSub.Render(truncate(r.label, labelW-2)))+info)
lines = append(lines, mark("trole:"+strconv.Itoa(i), truncateANSI(bar+dot+" "+lipgloss.NewStyle().Width(nameW).Render(nameStyle.Render(truncate(r.Name, nameW-2)))+
lipgloss.NewStyle().Width(labelW).Render(sSub.Render(truncate(r.label, labelW-2)))+info, w)))
}
if len(rows) == 0 {
lines = append(lines, sMuted.Render(" nothing matches"))
}
listH := max(3, h-lipgloss.Height(foot)-4)
start := max(0, min(s.roleCursor-listH/2, len(lines)-listH))
return head + "\n" + filter + "\n\n" + strings.Join(lines[start:min(len(lines), start+listH)], "\n") + foot
return head + "\n" + mark("tfilter", filter) + "\n\n" + strings.Join(lines[start:min(len(lines), start+listH)], "\n") + foot
}
func (s *tuningScreen) detailView(w int) string {
+22 -18
View File
@@ -3,6 +3,7 @@ package ui
import (
"os"
"path/filepath"
"strconv"
"strings"
"github.com/charmbracelet/lipgloss"
@@ -112,22 +113,23 @@ func (a *App) sidebar(h int) string {
}
return sFaint.Render(" " + glyph)
}
lines := []string{icon(sideSetup, "◇"), "", icon(sideManage, "◆"), "", icon(sideServers, "▤")}
lines := []string{mark("side:head:setup", icon(sideSetup, "◇")), "", mark("side:head:manage", icon(sideManage, "◆")), "",
mark("side:head:servers", icon(sideServers, "▤"))}
if !a.sideCollapsed {
lines = append(lines, "", "", sFaint.Render(" ⋯")) // too narrow; ctrl+b does nothing here
} else {
lines = append(lines, "", "", sFaint.Render(" ›"))
lines = append(lines, "", "", mark("side:fold", sFaint.Render(" ›")))
}
return sPanel.Padding(0).Width(sidebarRailW - 2).Height(h).Render(strings.Join(lines, "\n"))
}
inner := sidebarW - 4
item := func(on bool, mark, label string) string {
item := func(on bool, dot, label string) string {
label = truncate(label, inner-4)
if on {
return sAccent.Render("▌") + " " + mark + " " + sTitle.Render(label)
return sAccent.Render("▌") + " " + dot + " " + sTitle.Render(label)
}
return " " + mark + " " + sMuted.Render(label)
return " " + dot + " " + sMuted.Render(label)
}
head := func(s sideSection, title string, open bool) string {
switch {
@@ -141,18 +143,20 @@ func (a *App) sidebar(h int) string {
var lines []string
// Setup wizard
lines = append(lines, head(sideSetup, "Setup", false))
lines = append(lines, mark("side:head:setup", head(sideSetup, "Setup", false)))
if sec == sideSetup {
for i, s := range a.wizard() {
idx := i + 1
var line string
switch {
case idx == a.step:
lines = append(lines, item(true, sAccent.Render("◉"), s.name()))
line = item(true, sAccent.Render("◉"), s.name())
case idx < a.step:
lines = append(lines, item(false, sGood.Render("●"), s.name()))
line = item(false, sGood.Render("●"), s.name())
default:
lines = append(lines, item(false, sFaint.Render("○"), s.name()))
line = item(false, sFaint.Render("○"), s.name())
}
lines = append(lines, mark("side:step:"+strconv.Itoa(idx), line))
}
}
lines = append(lines, "")
@@ -162,18 +166,18 @@ func (a *App) sidebar(h int) string {
if a.cfg.Domain != "" {
title = "Manage " + a.cfg.Domain
}
lines = append(lines, head(sideManage, truncate(title, inner-2), false))
lines = append(lines, mark("side:head:manage", head(sideManage, truncate(title, inner-2), false)))
if sec == sideManage {
cur := a.manageCurrent()
for _, m := range manageMenu {
if m.screen == "Users" && a.cfg.Homeserver != "synapse" {
continue
}
mark := sFaint.Render("·")
dot := sFaint.Render("·")
if m.screen == cur {
mark = sAccent.Render("◆")
dot = sAccent.Render("◆")
}
lines = append(lines, item(m.screen == cur, mark, m.label))
lines = append(lines, mark("side:manage:"+m.screen, item(m.screen == cur, dot, m.label)))
if m.screen == cur && a.cur().name() == "Deploy" {
lines = append(lines, " "+sPink.Render("↳ ")+sSub.Render(truncate(a.deployLabel(), inner-6)))
}
@@ -187,19 +191,19 @@ func (a *App) sidebar(h int) string {
profiles = []config.Profile{{Name: config.DefaultProfile, Domain: a.cfg.Domain}}
}
showServers := sec == sideServers || sec == sideNone || len(profiles) > 1
lines = append(lines, head(sideServers, "Servers", showServers))
lines = append(lines, mark("side:head:servers", head(sideServers, "Servers", showServers)))
if showServers {
for _, p := range profiles {
active := p.Name == config.Active()
mark := sFaint.Render("○")
dot := sFaint.Render("○")
if active {
mark = sGood.Render("●")
dot = sGood.Render("●")
}
label := p.Name
if p.Domain != "" && p.Name == config.DefaultProfile {
label = p.Domain
}
lines = append(lines, item(active && sec == sideServers, mark, label))
lines = append(lines, mark("side:server:"+p.Name, item(active && sec == sideServers, dot, label)))
}
}
@@ -208,7 +212,7 @@ func (a *App) sidebar(h int) string {
if gap := h - lipgloss.Height(body) - 1; gap > 0 {
body += strings.Repeat("\n", gap)
}
body += "\n" + sFaint.Render("ctrl+b ‹ fold")
body += "\n" + mark("side:fold", sFaint.Render("ctrl+b ‹ fold"))
return sPanel.Padding(0, 1).Width(sidebarW - 2).Height(h).Render(body)
}
+6 -1
View File
@@ -38,6 +38,7 @@ func main() {
showVersion := flag.Bool("version", false, "print the version and exit")
reset := flag.Bool("reset", false, "forget saved answers and start fresh")
noMouse := flag.Bool("no-mouse", false, "don't take the mouse, so the terminal can select text without shift")
flag.Usage = func() {
fmt.Fprintln(flag.CommandLine.Output(), cli.Usage+"\n\nOptions:")
flag.PrintDefaults()
@@ -59,7 +60,11 @@ func main() {
cfg, loaded = config.Default(), false
}
p := tea.NewProgram(ui.New(cfg, loaded), tea.WithAltScreen())
opts := []tea.ProgramOption{tea.WithAltScreen()}
if !*noMouse {
opts = append(opts, tea.WithMouseCellMotion())
}
p := tea.NewProgram(ui.New(cfg, loaded), opts...)
if _, err := p.Run(); err != nil {
fmt.Fprintln(os.Stderr, "interzone:", err)
os.Exit(1)