Skip to content

Commit 194eaa2

Browse files
TMHSDigitalclaude
andcommitted
TUI: wrap the finished counters; abort after a warning (#343)
The finished screen's counters line is about 100 columns with every counter set and had no width limit, so an 80-column terminal wrapped it and pushed the layout one row past chromeLines; the height tests missed it because lipgloss.Height counts newlines, not terminal rows. countersLine now wraps between counters to the terminal width, and layout gives the extra lines to the counters once the scan is done. failed() drops its errText clause: since #308 only fatal errors set errText, and the engine's Failed already covers them, so ctrl+c during the permutation pass after a -no-abort warning is an abort. Fixes #343 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent ab6ab53 commit 194eaa2

3 files changed

Lines changed: 105 additions & 15 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6767
- Less memory on large wordlists and busy scans: `-sources`, `-ct`, `-axfr` and `-permute` check their names against the wordlist without building a set as large as it (about 200 MB per feature and target on a 5M-line list), a `-simulate-zone` lab scan no longer keeps a count per queried name (about 170 MB on a 1M-line list), and a `CNAME` lookup reads a UDP answer into a buffer sized for the 1232-byte EDNS payload it advertises instead of 64 KB. Results are unchanged (#321).
6868

6969
### Fixed
70+
- The TUI's finished screen wraps its counters between counters to the terminal width and gives the extra lines to the layout, so with every counter set it still fits an 80×24 terminal instead of the terminal wrapping the line and pushing the screen one row down. ctrl+c during the permutation pass after a `-no-abort` reliability warning shows an abort, not a failure (#343).
7071
- A `-diff` baseline that is also an `-o` file is recognised however the two paths are spelled (`x` and `./x`, a relative and an absolute path, another case on Windows), so a stopped run leaves it unchanged for the resumed run, as it already did for identical spellings (#342).
7172
- A `CNAME` lookup of a name with an empty label or one over 63 bytes is reported as not found without a query, as a name over 255 bytes already was, instead of dialling, counting a query and reporting a failure that the reliability guard counts (#344).
7273
- Under `-no-abort`, the reliability guard's warning is printed as `Warning: ...` (level `warn` with `-log-format json`) instead of `Error: warning: ...`, and a target that finished no longer carries it as its `error` in the `-stats` report next to `"status": "ok"`. The TUI shows it as a warning too (#308).

‎internal/tui/scan_view.go‎

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ func (m *scanViewModel) layout() {
126126
if mv := m.messagesView(); mv != "" {
127127
msgLines = lipgloss.Height(mv)
128128
}
129+
if m.done {
130+
// chromeLines has one line for the counters; a narrow terminal
131+
// needs more (#343).
132+
msgLines += lipgloss.Height(m.countersLine()) - 1
133+
}
129134
m.viewport.SetHeight(max(1, m.height-chromeLines-msgLines))
130135
m.progress.SetWidth(max(1, m.width-4))
131136
}
@@ -422,6 +427,7 @@ func (m *scanViewModel) applyEvent(ev scan.Event) {
422427
m.done = true
423428
}
424429
}
430+
m.layout() // the finished counters may take more than one line
425431
m.refresh()
426432
}
427433
}
@@ -460,26 +466,17 @@ func (m scanViewModel) View() string {
460466
switch {
461467
case m.failed():
462468
b.WriteString(errorStyle.Render("Failed: "+m.errText) + "\n")
463-
b.WriteString(dimStyle.Render(fmt.Sprintf(
464-
"processed %d/%d - found %d - nxdomain %d - timeout %d - refused %d - other %d - wildcard-filtered %d",
465-
m.processed, m.total, m.found, m.stats.NXDomain, m.stats.Timeout, m.stats.Refused, m.stats.Other, m.stats.WildcardFiltered,
466-
)) + "\n")
469+
b.WriteString(m.countersLine() + "\n")
467470
b.WriteString(m.doneHint())
468471
case m.done && (m.aborted || m.stopped):
469472
if !m.stopped {
470473
b.WriteString(m.verdictLine() + "\n")
471474
}
472-
b.WriteString(dimStyle.Render(fmt.Sprintf(
473-
"Aborted - processed %d/%d - found %d - nxdomain %d - timeout %d - refused %d - other %d - wildcard-filtered %d",
474-
m.processed, m.total, m.found, m.stats.NXDomain, m.stats.Timeout, m.stats.Refused, m.stats.Other, m.stats.WildcardFiltered,
475-
)+m.extraCounts()) + "\n")
475+
b.WriteString(m.countersLine() + "\n")
476476
b.WriteString(m.doneHint())
477477
case m.done:
478478
b.WriteString(m.verdictLine() + "\n")
479-
b.WriteString(summaryStyle.Render(fmt.Sprintf(
480-
"Done - processed %d/%d - found %d - nxdomain %d - timeout %d - refused %d - other %d - wildcard-filtered %d",
481-
m.processed, m.total, m.found, m.stats.NXDomain, m.stats.Timeout, m.stats.Refused, m.stats.Other, m.stats.WildcardFiltered,
482-
)+m.extraCounts()) + "\n")
479+
b.WriteString(m.countersLine() + "\n")
483480
b.WriteString(m.doneHint())
484481
default:
485482
status := fmt.Sprintf(" %d/%d processed • %d found", m.processed, m.total, m.found)
@@ -517,6 +514,45 @@ func (m scanViewModel) verdictLine() string {
517514
return style.Bold(true).MaxWidth(max(1, m.width)).Render("Verdict: " + t.Verdict + " - " + t.Reason)
518515
}
519516

517+
// countersLine renders the finished screen's counters, wrapped to the
518+
// terminal width: with every counter set it is longer than 80 columns, and
519+
// a line the terminal wraps by itself would push the layout one row past
520+
// what layout reserved for it (#343). layout counts the wrapped lines.
521+
func (m scanViewModel) countersLine() string {
522+
text := fmt.Sprintf("processed %d/%d - found %d - nxdomain %d - timeout %d - refused %d - other %d - wildcard-filtered %d",
523+
m.processed, m.total, m.found, m.stats.NXDomain, m.stats.Timeout, m.stats.Refused, m.stats.Other, m.stats.WildcardFiltered)
524+
style := summaryStyle
525+
switch {
526+
case m.failed():
527+
style = dimStyle
528+
case m.aborted || m.stopped:
529+
text, style = "Aborted - "+text+m.extraCounts(), dimStyle
530+
default:
531+
text = "Done - " + text + m.extraCounts()
532+
}
533+
return style.Render(wrapCounters(text, max(1, m.width)))
534+
}
535+
536+
// wrapCounters wraps a " - "-separated counters line to width, breaking only
537+
// between counters so none is split; a counter wider than width is cut by
538+
// lipgloss.Wrap.
539+
func wrapCounters(text string, width int) string {
540+
var lines []string
541+
cur := ""
542+
for part := range strings.SplitSeq(text, " - ") {
543+
switch {
544+
case cur == "":
545+
cur = part
546+
case len(cur)+len(" - ")+len(part) <= width:
547+
cur += " - " + part
548+
default:
549+
lines = append(lines, cur)
550+
cur = part
551+
}
552+
}
553+
return lipgloss.Wrap(strings.Join(append(lines, cur), "\n"), width, "")
554+
}
555+
520556
// extraCounts is the tail of the finished counters line: the run facts
521557
// that are only worth showing when they are not zero.
522558
func (m scanViewModel) extraCounts() string {
@@ -540,10 +576,10 @@ func (m scanViewModel) extraCounts() string {
540576
// code. The engine says so on each pass's EventDone (#308): a fatal error
541577
// (preflight failure, wildcard abort, reliability abort) fails the scan, the
542578
// reliability warning under -no-abort does not, and neither does a user
543-
// abort (#55). As before #308, a permutation pass that did not get through
544-
// its candidates also fails a scan that reported an error.
579+
// abort (#55), even during a permutation pass that follows that warning
580+
// (#343).
545581
func (m scanViewModel) failed() bool {
546-
return m.done && (m.scanFailed || (m.errText != "" && m.perm.unfinished()))
582+
return m.done && m.scanFailed
547583
}
548584

549585
type wordlistLoadedMsg struct {

‎internal/tui/scan_view_test.go‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,59 @@ func TestScanViewShowsVerdict(t *testing.T) {
212212
}
213213
}
214214

215+
// TestScanViewCountersFitWidth covers #343: with every counter set the
216+
// finished counters are wider than 80 columns, so they wrap between
217+
// counters, and the view still fills an 80x24 terminal exactly, measured in
218+
// terminal rows rather than newlines.
219+
func TestScanViewCountersFitWidth(t *testing.T) {
220+
const width, height = 80, 24
221+
stats := scan.Stats{Found: 12345, NXDomain: 987654, Timeout: 4321, Refused: 321, Other: 21, WildcardFiltered: 4567,
222+
Skipped: 40000, Retried: 600, Recovered: 200, Takeover: 7, RateBackoffs: 3}
223+
for _, aborted := range []bool{false, true} {
224+
m := newScanViewModel(width, height, false)
225+
m.aborted = aborted
226+
m, _ = m.Update(eventMsg{scan.Event{Kind: scan.EventDone, Processed: 1009876, Total: 1049876, Found: stats.Found, Stats: stats}})
227+
view := m.View()
228+
lines := strings.Split(view, "\n")
229+
for _, line := range lines {
230+
if w := lipgloss.Width(line); w > width {
231+
t.Errorf("aborted %v: a %d-column line on an %d-column terminal: %q", aborted, w, width, line)
232+
}
233+
}
234+
if len(lines) != height {
235+
t.Errorf("aborted %v: view is %d lines, want exactly %d:\n%s", aborted, len(lines), height, view)
236+
}
237+
flat := strings.ReplaceAll(view, "\n", " - ")
238+
for _, want := range []string{"wildcard-filtered 4567", "retried 600 (recovered 200)", "rate back-offs 3"} {
239+
if !strings.Contains(flat, want) {
240+
t.Errorf("aborted %v: counter %q split or missing:\n%s", aborted, want, view)
241+
}
242+
}
243+
}
244+
}
245+
246+
// TestScanViewAbortAfterNoAbortWarning covers #343: with No Abort and
247+
// Permute on, ctrl+c during the permutation pass after the main pass's
248+
// reliability warning is an abort, not a failure.
249+
func TestScanViewAbortAfterNoAbortWarning(t *testing.T) {
250+
m := newScanViewModel(120, 30, false)
251+
m.permute = true
252+
m, _ = m.Update(eventMsg{scan.Event{Kind: scan.EventError, Message: "warning: 30% of 200 queries failed"}})
253+
m, _ = m.Update(eventMsg{scan.Event{Kind: scan.EventDone, Processed: 200, Total: 200}})
254+
if m.done || m.main == nil {
255+
t.Fatal("the main pass did not hand over to the permutation pass")
256+
}
257+
m.perm = &permutationPass{seeds: 1, candidates: 90}
258+
m.aborted = true
259+
m, _ = m.Update(eventMsg{scan.Event{Kind: scan.EventDone, Stopped: true}})
260+
if !m.done || m.failed() {
261+
t.Fatalf("done %v failed %v, want an abort:\n%s", m.done, m.failed(), m.View())
262+
}
263+
if view := m.View(); strings.Contains(view, "Failed:") || !strings.Contains(view, "Aborted - processed") {
264+
t.Errorf("abort shown as a failure:\n%s", view)
265+
}
266+
}
267+
215268
func TestScanViewSummaryIncludesStats(t *testing.T) {
216269
m := newScanViewModel(100, 24, false)
217270
m, _ = m.Update(eventMsg{scan.Event{

0 commit comments

Comments
 (0)