-
Notifications
You must be signed in to change notification settings - Fork 264
#285 add color output for mage list #301
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
9495507
#285 add color output for mage list
mirogta 0a042a3
added color configuration via MAGEFILE_ENABLE_COLOR and MAGEFILE_TARG…
mirogta 9a98a25
fixed template
mirogta 90314f9
typo
mirogta d1da6c9
more typos
mirogta 50d2587
fix test
mirogta a894948
simplify color terminal detection
mirogta d4fdf58
fix: color output test in CI
mirogta 71bfbb0
fix: test in CI
mirogta 7afad3c
Update mage/main_test.go
natefinch a1f2a7c
Update mg/runtime.go
natefinch 7254217
Update mg/runtime.go
natefinch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,80 @@ | ||
package mg | ||
|
||
// Color is ANSI color type | ||
type Color int | ||
|
||
// If you add/change/remove any items in this constant, | ||
// you will need to run "stringer -type=Color" in this directory again. | ||
// NOTE: Please keep the list in an alphabetical order. | ||
const ( | ||
Black Color = iota | ||
Red | ||
Green | ||
Yellow | ||
Blue | ||
Magenta | ||
Cyan | ||
White | ||
BrightBlack | ||
BrightRed | ||
BrightGreen | ||
BrightYellow | ||
BrightBlue | ||
BrightMagenta | ||
BrightCyan | ||
BrightWhite | ||
) | ||
|
||
// AnsiColor are ANSI color codes for supported terminal colors. | ||
var ansiColor = map[Color]string{ | ||
Black: "\u001b[30m", | ||
Red: "\u001b[31m", | ||
Green: "\u001b[32m", | ||
Yellow: "\u001b[33m", | ||
Blue: "\u001b[34m", | ||
Magenta: "\u001b[35m", | ||
Cyan: "\u001b[36m", | ||
White: "\u001b[37m", | ||
BrightBlack: "\u001b[30;1m", | ||
BrightRed: "\u001b[31;1m", | ||
BrightGreen: "\u001b[32;1m", | ||
BrightYellow: "\u001b[33;1m", | ||
BrightBlue: "\u001b[34;1m", | ||
BrightMagenta: "\u001b[35;1m", | ||
BrightCyan: "\u001b[36;1m", | ||
BrightWhite: "\u001b[37;1m", | ||
} | ||
|
||
// AnsiColorReset is an ANSI color code to reset the terminal color. | ||
const AnsiColorReset = "\033[0m" | ||
|
||
// DefaultTargetAnsiColor is a default ANSI color for colorizing targets. | ||
// It is set to Cyan as an arbitrary color, because it has a neutral meaning | ||
var DefaultTargetAnsiColor = ansiColor[Cyan] | ||
|
||
func toLowerCase(s string) string { | ||
// this is a naive implementation | ||
// borrowed from https://golang.org/src/strings/strings.go | ||
// and only considers alphabetical characters [a-zA-Z] | ||
// so that we don't depend on the "strings" package | ||
buf := make([]byte, len(s)) | ||
for i := 0; i < len(s); i++ { | ||
c := s[i] | ||
if 'A' <= c && c <= 'Z' { | ||
c += 'a' - 'A' | ||
} | ||
buf[i] = c | ||
} | ||
return string(buf) | ||
} | ||
|
||
func getAnsiColor(color string) (string, bool) { | ||
colorLower := toLowerCase(color) | ||
for k, v := range ansiColor { | ||
colorConstLower := toLowerCase(k.String()) | ||
if colorConstLower == colorLower { | ||
return v, true | ||
} | ||
} | ||
return "", false | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.