diff --git a/internal/ui/app.go b/internal/ui/app.go index ca8e2eb..daa4a40 100644 --- a/internal/ui/app.go +++ b/internal/ui/app.go @@ -209,6 +209,9 @@ func (a *App) update(msg tea.Msg) (tea.Model, tea.Cmd) { case noteMsg: a.status = sGood.Render(string(m)) return a, nil + case failNoteMsg: + a.status = sBad.Render(string(m)) + return a, nil case autoBackMsg: if _, ok := a.cur().(*deployScreen); ok { a.status = sGood.Render("✓ " + m.text) @@ -275,6 +278,11 @@ func (a *App) update(msg tea.Msg) (tea.Model, tea.Cmd) { return a, a.go_(1) } case "ctrl+p", "pgup": + // Past the wizard, pgup scrolls the screen (the deploy log, + // Fine-tune's lists), as pgdown does; ctrl+p still goes back. + if m.String() == "pgup" && a.step > a.index("Review") { + break + } if !(deploying && ds.running) { return a, a.back() } diff --git a/internal/ui/import.go b/internal/ui/import.go index 11acb68..7e11417 100644 --- a/internal/ui/import.go +++ b/internal/ui/import.go @@ -27,6 +27,8 @@ type importReadMsg struct { err error } +func (importReadMsg) owner() string { return "Servers" } + type importSavedMsg struct { name string cfg *config.Config @@ -34,6 +36,8 @@ type importSavedMsg struct { err error } +func (importSavedMsg) owner() string { return "Servers" } + type importState struct { form *form im *config.Import // read, waiting for enter diff --git a/internal/ui/maintenance.go b/internal/ui/maintenance.go index 0e2cdab..0a0137f 100644 --- a/internal/ui/maintenance.go +++ b/internal/ui/maintenance.go @@ -246,7 +246,7 @@ func (s *maintenanceScreen) keepDays() (int, error) { func databaseShell(c *config.Config) tea.Cmd { return tea.ExecProcess(deploy.DatabaseShell(c), func(err error) tea.Msg { if err != nil { - return noteMsg("The database shell ended: " + err.Error()) + return failNoteMsg("The database shell ended: " + err.Error()) } return nil }) diff --git a/internal/ui/mirrors.go b/internal/ui/mirrors.go index 0319e52..4a9eb51 100644 --- a/internal/ui/mirrors.go +++ b/internal/ui/mirrors.go @@ -52,6 +52,8 @@ type mirrorsMsg struct { res mirrorsResult } +func (mirrorsMsg) owner() string { return "Mirrors" } + type mirrorsScreen struct { cfg *config.Config server string diff --git a/internal/ui/presets.go b/internal/ui/presets.go index c390763..5be168c 100644 --- a/internal/ui/presets.go +++ b/internal/ui/presets.go @@ -32,6 +32,9 @@ type homeserverScreen struct { // noteMsg puts a line on the status bar. type noteMsg string +// failNoteMsg puts a line on the status bar that says something failed. +type failNoteMsg string + func (s *homeserverScreen) name() string { return "Homeserver" } func (s *homeserverScreen) title() string { if s.saver != nil { diff --git a/internal/ui/refresh_test.go b/internal/ui/refresh_test.go index afb82d0..7a98d46 100644 --- a/internal/ui/refresh_test.go +++ b/internal/ui/refresh_test.go @@ -21,6 +21,32 @@ func TestResultReachesItsScreen(t *testing.T) { } } +// The same for the other screens that wait on the server: a user's new +// password, shown only once, isn't lost by looking elsewhere meanwhile. +func TestMoreResultsReachTheirScreens(t *testing.T) { + a := demoApp(t, 120, 36) + openUsers(a) + us := a.cur().(*usersScreen) + us.busy = true + openDashboard(a) + if a.cur() == us { + t.Fatal("still on Users") + } + a.Update(userOpMsg{op: &userOp{user: "@bob:example.org"}, info: "new password", password: "s3cret"}) + if us.busy || us.password != "s3cret" { + t.Errorf("users missed its answer: busy %v, password %q", us.busy, us.password) + } + + ms := a.screens[a.index("Mirrors")].(*mirrorsScreen) + ms.loading = [3]bool{true, true, true} + for part := range ms.loading { + a.Update(mirrorsMsg{server: ms.server, part: part}) + } + if ms.loading != [3]bool{} { + t.Errorf("mirrors still loading: %v", ms.loading) + } +} + func TestDashboardRefreshesItself(t *testing.T) { a := demoApp(t, 120, 36) openDashboard(a) diff --git a/internal/ui/screens_components.go b/internal/ui/screens_components.go index 19b106a..009b732 100644 --- a/internal/ui/screens_components.go +++ b/internal/ui/screens_components.go @@ -123,14 +123,14 @@ func (s *componentsScreen) update(msg tea.Msg) tea.Cmd { } items := s.items() switch k.String() { - case "up", "ctrl+k": + case "up": // not ctrl+k: that's Go-to, everywhere s.cursor = max(0, s.cursor-1) return nil case "down", "ctrl+j": - s.cursor = min(len(items)-1, s.cursor+1) + s.cursor = max(0, min(len(items)-1, s.cursor+1)) return nil case " ", "ctrl+@": - if s.cursor < len(items) { + if s.cursor >= 0 && s.cursor < len(items) { it := items[s.cursor] if s.toggles(it) { s.selected[it.ID] = !s.selected[it.ID] @@ -169,7 +169,7 @@ func (s *componentsScreen) update(msg tea.Msg) tea.Cmd { case "k": s.cursor = max(0, s.cursor-1) case "j": - s.cursor = min(len(items)-1, s.cursor+1) + s.cursor = max(0, min(len(items)-1, s.cursor+1)) case "p": s.leave(s.cfg) p, ok := currentPreset(s.cfg) diff --git a/internal/ui/screens_deploy.go b/internal/ui/screens_deploy.go index abe4100..ac428d9 100644 --- a/internal/ui/screens_deploy.go +++ b/internal/ui/screens_deploy.go @@ -32,6 +32,8 @@ type checksPartMsg struct { ch chan checksPartMsg } +func (checksPartMsg) owner() string { return "Review" } + func waitChecks(ch chan checksPartMsg) tea.Cmd { return func() tea.Msg { m, ok := <-ch diff --git a/internal/ui/screens_manage.go b/internal/ui/screens_manage.go index b0ee9fc..a539545 100644 --- a/internal/ui/screens_manage.go +++ b/internal/ui/screens_manage.go @@ -31,6 +31,8 @@ type servicesMsg struct { err error } +func (servicesMsg) owner() string { return "Manage" } + type manageMode int const ( diff --git a/internal/ui/screens_setup.go b/internal/ui/screens_setup.go index a3886e1..bc9601e 100644 --- a/internal/ui/screens_setup.go +++ b/internal/ui/screens_setup.go @@ -143,6 +143,8 @@ func (s *welcomeScreen) view(w, h int) string { type checksMsg []deploy.Check +func (checksMsg) owner() string { return "Server" } + type serverScreen struct { cfg *config.Config form *form diff --git a/internal/ui/screens_tools.go b/internal/ui/screens_tools.go index 1aaac57..7acf185 100644 --- a/internal/ui/screens_tools.go +++ b/internal/ui/screens_tools.go @@ -102,6 +102,8 @@ type changesMsg struct { err error } +func (changesMsg) owner() string { return "Updates" } + type updatesScreen struct { cfg *config.Config loading bool @@ -604,10 +606,12 @@ func (s *serversScreen) update(msg tea.Msg) tea.Cmd { } if s.confirm { if confirmKey(k.String(), &s.cursor, &s.confirm, len(s.list)) || k.String() == "x" { - if err := config.RemoveProfile(s.list[s.cursor].Name); err != nil { + err := config.RemoveProfile(s.list[s.cursor].Name) + cmd := s.enter(s.cfg) // clears s.err + if err != nil { s.err = err.Error() } - return s.enter(s.cfg) + return cmd } return nil } diff --git a/internal/ui/screens_tuning.go b/internal/ui/screens_tuning.go index a4284af..81668b1 100644 --- a/internal/ui/screens_tuning.go +++ b/internal/ui/screens_tuning.go @@ -31,6 +31,8 @@ type defaultsMsg struct { err error } +func (defaultsMsg) owner() string { return "Tuning" } + // tuneRole is a role as the screen lists it. type tuneRole struct { config.Role diff --git a/internal/ui/theme.go b/internal/ui/theme.go index 0c373a4..c3571a0 100644 --- a/internal/ui/theme.go +++ b/internal/ui/theme.go @@ -98,9 +98,8 @@ var themes = []theme{ } var ( - themeName string - cPurple, cMint, cPink, cAmber, cRed, cText, cMuted, cFaint, cPanel ac - cOnAccent ac + themeName string + cPurple, cMint, cPink, cAmber, cRed, cText, cMuted, cFaint, cOnAccent ac sTitle, sSub, sMuted, sFaint, sAccent, sGood, sWarn, sBad, sPink, sKey, sSection lipgloss.Style sPanel, sPanelFocus, sBadge lipgloss.Style @@ -111,7 +110,7 @@ func init() { applyTheme(themes[0]) } func applyTheme(t theme) { themeName = t.name cPurple, cMint, cPink, cAmber, cRed = t.accent, t.good, t.pink, t.amber, t.red - cText, cMuted, cFaint, cPanel, cOnAccent = t.text, t.muted, t.faint, t.panel, t.onAccent + cText, cMuted, cFaint, cOnAccent = t.text, t.muted, t.faint, t.onAccent sTitle = lipgloss.NewStyle().Foreground(cText).Bold(true) sSub = lipgloss.NewStyle().Foreground(cMuted) @@ -235,11 +234,9 @@ func gradient(s string) string { return b.String() } -// gradientLines colours a multi-line block column-wise so each line shares the ramp. -func gradientLines(block string) string { return gradientLinesAt(block, 0) } - -// gradientLinesAt is gradientLines with the ramp moved along by shift: it -// runs there and back, so any shift is a smooth step from the last. +// gradientLinesAt colours a multi-line block column-wise so each line +// shares the ramp, moved along by shift: it runs there and back, so any +// shift is a smooth step from the last. func gradientLinesAt(block string, shift float64) string { stops := gradientStops() lines := strings.Split(block, "\n") diff --git a/internal/ui/users.go b/internal/ui/users.go index 0cb24ef..4896072 100644 --- a/internal/ui/users.go +++ b/internal/ui/users.go @@ -43,6 +43,8 @@ type userOpMsg struct { err error } +func (userOpMsg) owner() string { return "Users" } + type userMode int const (