Skip to content

Commit c8eca18

Browse files
authored
Fix progress bar when previously printed text has color (#247)
* Remove unused dependency in ActionLogger * Fix typo * Show progress bar even when printed text has color
1 parent b721a12 commit c8eca18

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

internal/campaigns/logger.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ type ActionLogger struct {
3131
verbose bool
3232
keepLogs bool
3333

34-
highlight func(a ...interface{}) string
35-
3634
progress *progress
3735
out io.WriteCloser
3836

@@ -50,10 +48,9 @@ func NewActionLogger(verbose, keepLogs bool) *ActionLogger {
5048
progress := new(progress)
5149

5250
return &ActionLogger{
53-
verbose: verbose,
54-
keepLogs: keepLogs,
55-
highlight: color.New(color.Bold, color.FgGreen).SprintFunc(),
56-
progress: progress,
51+
verbose: verbose,
52+
keepLogs: keepLogs,
53+
progress: progress,
5754
out: &progressWriter{
5855
p: progress,
5956
w: os.Stderr,
@@ -355,7 +352,7 @@ func (w *progressWriter) Write(data []byte) (int, error) {
355352
return w.w.Write(data)
356353
}
357354

358-
if !bytes.HasSuffix(data, []byte("\n")) {
355+
if !bytes.HasSuffix(data, []byte("\n")) && !bytes.HasSuffix(data, []byte("\n\x1b[0m")) {
359356
w.shouldClear = false
360357
return w.w.Write(data)
361358
}
@@ -377,10 +374,10 @@ func (w *progressWriter) Write(data []byte) (int, error) {
377374
bar += ">"
378375
}
379376
bar += strings.Repeat(" ", maxLength-len(bar))
380-
progessText := fmt.Sprintf("[%s] Steps: %d/%d (%s, %s)", bar, w.p.StepsComplete(), w.p.TotalSteps(), boldRed.Sprintf("%d failed", w.p.TotalStepsFailed()), hiGreen.Sprintf("%d patches", w.p.PatchCount()))
381-
fmt.Fprint(w.w, progessText)
377+
progressText := fmt.Sprintf("[%s] Steps: %d/%d (%s, %s)", bar, w.p.StepsComplete(), w.p.TotalSteps(), boldRed.Sprintf("%d failed", w.p.TotalStepsFailed()), hiGreen.Sprintf("%d patches", w.p.PatchCount()))
378+
fmt.Fprint(w.w, progressText)
382379
w.shouldClear = true
383-
w.progressLogLength = len(progessText)
380+
w.progressLogLength = len(progressText)
384381
return n, err
385382
}
386383

0 commit comments

Comments
 (0)