Review: no crash after scrolling a hidden preview; z makes room for DNS
With the checks, ports and estimate Review got tall enough that the vars.yml preview doesn't fit a 45-row window and is hidden. ↑↓ still scrolled it, at a negative height, past its end, and the next taller window panicked drawing it. Its height and offset are now kept in range. z put the DNS records into that hidden preview, so it seemed to do nothing; now the left column is cut short to show them. choiceField panics when labels and choices differ in number, so an option that can't be picked (as Matrix room was) fails every test that opens its screen. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b7a32cf44e
commit
cd5ddf6f81
3 files changed
+50
-2
No files matched your search
@@ -96,6 +96,9 @@ func toggleField(key, label string, on bool, help string) *field {
|
||||
}
|
||||
|
||||
func choiceField(key, label string, choices, labels []string, value, help string) *field {
|
||||
if labels != nil && len(labels) != len(choices) {
|
||||
panic("choiceField " + key + ": the labels don't match the choices") // an unmatched one can't be picked
|
||||
}
|
||||
f := &field{key: key, label: label, help: help, kind: fChoice, choices: choices, labels: labels}
|
||||
for i, c := range choices {
|
||||
if c == value {
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
|
||||
"interzone/internal/deploy"
|
||||
)
|
||||
|
||||
// With many checks the preview doesn't fit; scrolling it then must not
|
||||
// crash once the window grows, and z still shows the DNS records.
|
||||
func TestReviewHiddenPreview(t *testing.T) {
|
||||
a := demoApp(t, 120, 45)
|
||||
a.jump(a.index("Review"))
|
||||
s := a.cur().(*reviewScreen)
|
||||
for i := range 12 {
|
||||
s.checks = append(s.checks, deploy.Finding{Group: "Clients", Name: fmt.Sprint("Check ", i), Level: deploy.Fail,
|
||||
Detail: "a long reason that wraps onto a second line of the left column, as real failures do"})
|
||||
}
|
||||
s.view(92, 40)
|
||||
for range 40 {
|
||||
s.update(tea.KeyMsg{Type: tea.KeyDown})
|
||||
}
|
||||
s.view(92, 70) // panicked: the offset had run past the end
|
||||
s.view(150, 70)
|
||||
|
||||
s.update(zoneMsg{"matrix.example.org. 3600 IN A 203.0.113.7"})
|
||||
if out := s.view(92, 40); !strings.Contains(out, "IN A 203.0.113.7") || !strings.Contains(out, "a taller window shows them") {
|
||||
t.Errorf("z shows no records:\n%s", out)
|
||||
}
|
||||
}
|
||||
@@ -303,12 +303,23 @@ func (s *reviewScreen) view(w, h int) string {
|
||||
left := lipgloss.JoinVertical(lipgloss.Left, append(summary, append(gap, status...)...)...)
|
||||
if wide {
|
||||
s.vp.Width = w - lw - 4
|
||||
s.vp.Height = h - 4
|
||||
s.vp.Height = max(0, h-4)
|
||||
s.vp.SetYOffset(s.vp.YOffset) // back in range after a resize
|
||||
right := sPanel.Width(w - lw - 2).Render(s.previewTitle() + "\n\n" + s.vp.View())
|
||||
return lipgloss.JoinHorizontal(lipgloss.Top, lipgloss.NewStyle().Width(lw).Render(left), right)
|
||||
}
|
||||
s.vp.Width = w - 4
|
||||
s.vp.Height = h - lipgloss.Height(left) - 5
|
||||
room := h - lipgloss.Height(left) - 5
|
||||
if room < 3 && s.zone != nil { // the DNS records were asked for: cut the left short for them
|
||||
lines := strings.Split(left, "\n")
|
||||
if keep := max(4, h-5-10); len(lines) > keep {
|
||||
left = strings.Join(lines[:keep-1], "\n") + "\n" + sFaint.Render(fmt.Sprintf(" ▼ %d more lines; a taller window shows them", len(lines)-keep+1))
|
||||
}
|
||||
room = h - lipgloss.Height(left) - 5
|
||||
}
|
||||
// ↑↓ scroll it even while it's hidden, so its height and offset stay in range.
|
||||
s.vp.Height = max(0, room)
|
||||
s.vp.SetYOffset(s.vp.YOffset)
|
||||
if s.vp.Height < 3 {
|
||||
return left
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user