-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add functions to color text on a terminal
- Loading branch information
Showing
1 changed file
with
26 additions
and
0 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,26 @@ | ||
package terminal | ||
|
||
import "fmt" | ||
|
||
//Yellow add ANSI escape codes to the given string so when printed on a terminal | ||
//the text foreground is yellow. | ||
func Yellow(s string) string { | ||
return colorize(s, 220) | ||
} | ||
|
||
//Red add ANSI escape codes to the given string so when printed on a terminal | ||
//the text foreground is red. | ||
func Red(s string) string { | ||
return colorize(s, 88) | ||
} | ||
|
||
//White add ANSI escape codes to the given string so when printed on a terminal | ||
//the text foreground is white. | ||
func White(s string) string { | ||
return colorize(s, 244) | ||
} | ||
|
||
//colorize applies the given color to the given text using the "extended set foreground color" code | ||
func colorize(s string, color uint8) string { | ||
return fmt.Sprintf("\033[38;5;%03dm%s\033[0m", color, s) | ||
} |