From db3bca6da40f2b36e78c0e83af00f6d8f93ea604 Mon Sep 17 00:00:00 2001 From: d048927 Date: Wed, 20 Dec 2023 14:37:14 +0100 Subject: [PATCH] Initial release --- .gitignore | 1 + README.md | 17 ++++++++++++++++- constants.go | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 constants.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..62c8935 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea/ \ No newline at end of file diff --git a/README.md b/README.md index 77de4f8..15fac2b 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,17 @@ # color -Go package containing color constants for ANSI terminals +Go package containing color constants for ANSI terminals. + +# Intention +The idea is to provide constants that can be used for simple color commands. Colors are simple +string constants that can be included in printf commands, such as: +```go + fmt.Printf("Normal text – %sthis is green%s this is bold and green%s and this is regular again.\n", + color.Green, color.Bold, color.Reset) +``` +You can also combine instructions such as: +```go +const ErrorColor = color.Red + color.Bold +fmt.Printf("%sThis is wrong\n%s", ErrorColor, color.Reset) +``` +There is intentionally no code such as functions to print something in a specific color. If you are looking for +something like that, look into [fatih/color](https://github.com/fatih/color). \ No newline at end of file diff --git a/constants.go b/constants.go new file mode 100644 index 0000000..c6da4fc --- /dev/null +++ b/constants.go @@ -0,0 +1,51 @@ +package color + +const ( + Reset = "\033[0m" + + Black = "\033[30m" + Red = "\033[31m" + Green = "\033[32m" + Yellow = "\033[33m" + Blue = "\033[34m" + Magenta = "\033[35m" + Cyan = "\033[36m" + White = "\033[37m" + + HiBlack = "\033[90m" + HiRed = "\033[91m" + HiGreen = "\033[92m" + HiYellow = "\033[93m" + HiBlue = "\033[94m" + HiMagenta = "\033[95m" + HiCyan = "\033[96m" + HiWhite = "\033[97m" + + Bold = "\033[1m" + Faint = "\033[2m" + Italic = "\033[3m" + Underline = "\033[4m" + BlinkSlow = "\033[5m" + BlinkRapid = "\033[6m" + ReverseVideo = "\033[7m" + Concealed = "\033[8m" + CrossedOut = "\033[9m" + + BgBlack = "\033[40m" + BgRed = "\033[41m" + BgGreen = "\033[42m" + BgYellow = "\033[43m" + BgBlue = "\033[44m" + BgMagenta = "\033[45m" + BgCyan = "\033[46m" + BgWhite = "\033[47m" + + BgHiBlack = "\033[100m" + BgHiRed = "\033[101m" + BgHiGreen = "\033[102m" + BgHiYellow = "\033[103m" + BgHiBlue = "\033[104m" + BgHiMagenta = "\033[105m" + BgHiCyan = "\033[106m" + BgHiWhite = "\033[107m" +)