mirror of
https://gitlab.com/TECHNOFAB/nixtest.git
synced 2026-02-02 03:15:12 +01:00
fix: handle final newline in messages correctly
This commit is contained in:
parent
c1ad61b367
commit
5436abf377
1 changed files with 5 additions and 0 deletions
|
|
@ -27,11 +27,13 @@ func printErrors(results Results) {
|
||||||
message = fmt.Sprintf("Diff:\n%s", dmp.DiffPrettyText(diffs))
|
message = fmt.Sprintf("Diff:\n%s", dmp.DiffPrettyText(diffs))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
endedWithNewline := false
|
||||||
// handle multi-line colored changes
|
// handle multi-line colored changes
|
||||||
colorState := ""
|
colorState := ""
|
||||||
colorRegex := regexp.MustCompile(`\x1b\[[0-9;]*m`) // Match any escape sequence
|
colorRegex := regexp.MustCompile(`\x1b\[[0-9;]*m`) // Match any escape sequence
|
||||||
for line := range strings.Lines(message) {
|
for line := range strings.Lines(message) {
|
||||||
coloredLine := colorState + line
|
coloredLine := colorState + line
|
||||||
|
endedWithNewline = strings.HasSuffix(coloredLine, "\n")
|
||||||
fmt.Printf("%s %s", text.FgRed.Sprint("|"), coloredLine)
|
fmt.Printf("%s %s", text.FgRed.Sprint("|"), coloredLine)
|
||||||
|
|
||||||
matches := colorRegex.FindAllString(line, -1)
|
matches := colorRegex.FindAllString(line, -1)
|
||||||
|
|
@ -46,6 +48,9 @@ func printErrors(results Results) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if endedWithNewline {
|
||||||
|
fmt.Printf("%s", text.FgRed.Sprint("|"))
|
||||||
|
}
|
||||||
if message == "" {
|
if message == "" {
|
||||||
fmt.Printf("- no output -")
|
fmt.Printf("- no output -")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue