Skip to content

Commit 3fa3e67

Browse files
committed
Fix spinner updates for multiline progress
1 parent 05fdcf8 commit 3fa3e67

3 files changed

Lines changed: 49 additions & 14 deletions

File tree

internal/cli/cli.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ func (a *App) executeLookup(config LookupConfig) error {
389389
BaseHost: config.BaseHost,
390390
Subdomains: config.Subdomains,
391391
DomainEndings: config.Endings,
392-
Concurrency: 24,
392+
Concurrency: 0,
393393
Progress: func(progress ping.LookupProgress) {
394394
current.Store(progress)
395395
},
@@ -418,7 +418,7 @@ func formatLookupProgress(progress ping.LookupProgress, frame int) string {
418418
bar := buildProgressBar(progress.Completed, progress.Total, frame, 20)
419419
percent := (float64(progress.Completed) / float64(progress.Total)) * 100
420420
return fmt.Sprintf(
421-
"%s %d/%d (%.0f%%) | Subdomain: %s | Endung: %s | Host: %s",
421+
"%s %d/%d (%.0f%%)\nSubdomain: %-12s | Endung: %-10s | Host: %s",
422422
bar,
423423
progress.Completed,
424424
progress.Total,

internal/cli/ui.go

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -235,22 +235,49 @@ func withSpinner(title string, message func(frame int) string, tick time.Duratio
235235
defer ticker.Stop()
236236

237237
frame := 0
238-
lastLen := 0
238+
lastLines := 0
239239
for {
240240
select {
241241
case res := <-resultCh:
242-
if lastLen > 0 {
243-
fmt.Print("\r", strings.Repeat(" ", lastLen), "\r")
242+
if lastLines > 1 {
243+
moveCursorUp(lastLines - 1)
244+
}
245+
for i := 0; i < lastLines; i++ {
246+
clearLine()
247+
if i < lastLines-1 {
248+
fmt.Print("\n")
249+
}
244250
}
245251
fmt.Println()
246252
return res.result, res.err
247253
case <-ticker.C:
248-
line := fmt.Sprintf("%s %s", style(message(frame), colorDim), style(frames[frame], colorAccent))
249-
if lastLen > 0 && len(line) < lastLen {
250-
line += strings.Repeat(" ", lastLen-len(line))
254+
parts := strings.Split(message(frame), "\n")
255+
if len(parts) == 0 {
256+
parts = []string{""}
257+
}
258+
renderLines := len(parts)
259+
if lastLines > renderLines {
260+
renderLines = lastLines
261+
}
262+
263+
if lastLines > 1 {
264+
moveCursorUp(lastLines - 1)
251265
}
252-
fmt.Print("\r", line)
253-
lastLen = len(line)
266+
for i := 0; i < renderLines; i++ {
267+
clearLine()
268+
if i < len(parts) {
269+
line := style(parts[i], colorDim)
270+
if i == len(parts)-1 {
271+
line = fmt.Sprintf("%s %s", line, style(frames[frame], colorAccent))
272+
}
273+
fmt.Print(line)
274+
}
275+
if i < renderLines-1 {
276+
fmt.Print("\n")
277+
}
278+
}
279+
280+
lastLines = len(parts)
254281
frame = (frame + 1) % len(frames)
255282
}
256283
}

internal/ping/lookup.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package ping
33
import (
44
"context"
55
"fmt"
6+
"runtime"
67
"strings"
78
"sync"
89
"sync/atomic"
@@ -53,14 +54,21 @@ func LookupDomains(ctx context.Context, config LookupConfig) (LookupResult, erro
5354
subdomains = []string{""}
5455
}
5556

56-
concurrency := config.Concurrency
57-
if concurrency <= 0 {
58-
concurrency = 16
59-
}
6057
total := len(subdomains) * len(endings)
6158
if total == 0 {
6259
return LookupResult{}, fmt.Errorf("keine kombinationen verfügbar")
6360
}
61+
concurrency := config.Concurrency
62+
if concurrency <= 0 {
63+
base := runtime.NumCPU() * 8
64+
if base < 32 {
65+
base = 32
66+
}
67+
concurrency = base
68+
}
69+
if concurrency > total {
70+
concurrency = total
71+
}
6472

6573
type lookupCandidate struct {
6674
subdomain string

0 commit comments

Comments
 (0)