fix: handle final newline in messages correctly

This commit is contained in:
technofab 2025-05-31 18:28:17 +02:00
parent c1ad61b367
commit 5436abf377

View file

@ -27,11 +27,13 @@ func printErrors(results Results) {
message = fmt.Sprintf("Diff:\n%s", dmp.DiffPrettyText(diffs))
}
endedWithNewline := false
// handle multi-line colored changes
colorState := ""
colorRegex := regexp.MustCompile(`\x1b\[[0-9;]*m`) // Match any escape sequence
for line := range strings.Lines(message) {
coloredLine := colorState + line
endedWithNewline = strings.HasSuffix(coloredLine, "\n")
fmt.Printf("%s %s", text.FgRed.Sprint("|"), coloredLine)
matches := colorRegex.FindAllString(line, -1)
@ -46,6 +48,9 @@ func printErrors(results Results) {
}
}
}
if endedWithNewline {
fmt.Printf("%s", text.FgRed.Sprint("|"))
}
if message == "" {
fmt.Printf("- no output -")
}