-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Colourise diffs in `test.File` * Add codecov file
- Loading branch information
1 parent
4464136
commit 597eb1e
Showing
3 changed files
with
61 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ignore: | ||
- internal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Package colour implements basic text colouring for showing text diffs. | ||
package colour | ||
|
||
// ANSI codes for coloured output, they are all the same length so as not to throw off | ||
// alignment of [text/tabwriter]. | ||
const ( | ||
codeRed = "\x1b[0;0031m" // Red, used for diff lines starting with '-' | ||
codeHeader = "\x1b[1;0036m" // Bold cyan, used for diff headers starting with '@@' | ||
codeGreen = "\x1b[0;0032m" // Green, used for diff lines starting with '+' | ||
codeReset = "\x1b[000000m" // Reset all attributes | ||
) | ||
|
||
// Header returns a diff header styled string. | ||
func Header(text string) string { | ||
return sprint(codeHeader, text) | ||
} | ||
|
||
// Green returns a green styled string. | ||
func Green(text string) string { | ||
return sprint(codeGreen, text) | ||
} | ||
|
||
// Red returns a red styled string. | ||
func Red(text string) string { | ||
return sprint(codeRed, text) | ||
} | ||
|
||
// sprint returns a string with a given colour and the reset code. | ||
// | ||
// It handles checking for NO_COLOR and FORCE_COLOR. | ||
func sprint(code, text string) string { | ||
return code + text + codeReset | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters