Skip to content

Commit 599ea47

Browse files
Tweak newline handling in --verbose output
"Loading book" now appears on separate lines. The progress indicators and "generating .." lines do not have newlines so that the carriage returns still work. When generating a single file, the verbose output has a newline at the end now. There are cases where this is one newline too many, but this seems better than having one too few. This could be avoided, but would require more logic that seems too much effort at this stage.
1 parent 50cd610 commit 599ea47

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

cmd/fakedoc/main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,11 @@ func generate(
132132
templ, limits, sizeFactor, forceMaxSize, rng, requireRegex, verbose)
133133

134134
if numOutputs == 1 {
135-
return generateToFile(generator, outputfile, formatted)
135+
err := generateToFile(generator, outputfile, formatted)
136+
if outputfile != "" {
137+
generator.Verbosef("\n")
138+
}
139+
return err
136140
}
137141

138142
tmplFilename, err := template.New("filename").Parse(outputfile)

pkg/fakedoc/generator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ func (gen *Generator) book(minlength, maxlength int, path string, limits *LimitN
625625
length := minlength + gen.Rand.IntN(maxlength-minlength+1)
626626
content, ok := gen.FileCache[path]
627627
if !ok {
628-
gen.Verbosef("Loading book %q\n", path)
628+
gen.Verbosef("\nLoading book %q\n", path)
629629
file, err := os.Open(path)
630630
if err != nil {
631631
return "", err

0 commit comments

Comments
 (0)