Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Colors (Issue copied from the archived project) #1

Open
WarpRat opened this issue Mar 15, 2024 · 0 comments
Open

Colors (Issue copied from the archived project) #1

WarpRat opened this issue Mar 15, 2024 · 0 comments

Comments

@WarpRat
Copy link

WarpRat commented Mar 15, 2024

I came across this issue while googling for something similar. As the readme in both projects says, these projects directly track the upstream internal package which the Go authors have decided they will not move to a non-internal path. @victorboissiere I assume you've already solved this issue but for anyone else who may stumble across this, this is easy to impliment yourself with a small function to color the diff:

func colorDiff(diffs string) string {
	green := "\x1b[32m"
        // green := "\x1b[48;5;194m" // if you prefer a light green background
	red := "\x1b[31m"
        // red := ""\x1b[48;5;210m" // if you prefer a light red/pink background
	reset := "\x1b[0m" // Reset to default terminal colors

	var colorDiff strings.Builder
	lines := strings.Split(diffs, "\n")
	for _, line := range lines {
		if len(line) > 0 {
			switch string(line[0]) {
			case "-":
				colorDiff.WriteString(red + line + reset + "\n")
			case "+":
				colorDiff.WriteString(green + line + reset + "\n")
			default:
				colorDiff.WriteString(line + "\n")
			}
		} else {
			colorDiff.WriteString(line + "\n")
		}
	}

	return colorDiff.String()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant