mirror of
https://gitlab.com/TECHNOFAB/nixtest.git
synced 2025-12-12 02:00:18 +01:00
fix: display multi-line diffs with correct colors
This commit is contained in:
parent
b50a1c61a6
commit
2b7c215ffa
1 changed files with 19 additions and 1 deletions
|
|
@ -3,6 +3,7 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/jedib0t/go-pretty/v6/table"
|
||||
|
|
@ -26,8 +27,25 @@ func printErrors(results Results) {
|
|||
} else {
|
||||
message = result.ErrorMessage
|
||||
}
|
||||
|
||||
// handle multi-line colored changes
|
||||
colorState := ""
|
||||
colorRegex := regexp.MustCompile(`\x1b\[[0-9;]*m`) // Match any escape sequence
|
||||
for line := range strings.Lines(message) {
|
||||
fmt.Printf("%s %s", text.FgRed.Sprint("|"), line)
|
||||
coloredLine := colorState + line
|
||||
fmt.Printf("%s %s", text.FgRed.Sprint("|"), coloredLine)
|
||||
|
||||
matches := colorRegex.FindAllString(line, -1)
|
||||
|
||||
// determine last color code, to copy to next line
|
||||
if len(matches) > 0 {
|
||||
lastMatch := matches[len(matches)-1]
|
||||
if lastMatch == "\x1b[0m" {
|
||||
colorState = "" // reset color state
|
||||
} else {
|
||||
colorState = lastMatch // save color state for next line
|
||||
}
|
||||
}
|
||||
}
|
||||
if message == "" {
|
||||
fmt.Printf("- no output -")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue