github.com/blend/go-sdk@v1.20220411.3/ansi/color.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package ansi 9 10 // Black applies a given color. 11 func Black(text string) string { 12 return Apply(ColorBlack, text) 13 } 14 15 // Red applies a given color. 16 func Red(text string) string { 17 return Apply(ColorRed, text) 18 } 19 20 // Green applies a given color. 21 func Green(text string) string { 22 return Apply(ColorGreen, text) 23 } 24 25 // Yellow applies a given color. 26 func Yellow(text string) string { 27 return Apply(ColorYellow, text) 28 } 29 30 // Blue applies a given color. 31 func Blue(text string) string { 32 return Apply(ColorBlue, text) 33 } 34 35 // Purple applies a given color. 36 func Purple(text string) string { 37 return Apply(ColorPurple, text) 38 } 39 40 // Cyan applies a given color. 41 func Cyan(text string) string { 42 return Apply(ColorCyan, text) 43 } 44 45 // White applies a given color. 46 func White(text string) string { 47 return Apply(ColorWhite, text) 48 } 49 50 // LightBlack applies a given color. 51 func LightBlack(text string) string { 52 return Apply(ColorLightBlack, text) 53 } 54 55 // LightRed applies a given color. 56 func LightRed(text string) string { 57 return Apply(ColorLightRed, text) 58 } 59 60 // LightGreen applies a given color. 61 func LightGreen(text string) string { 62 return Apply(ColorLightGreen, text) 63 } 64 65 // LightYellow applies a given color. 66 func LightYellow(text string) string { 67 return Apply(ColorLightYellow, text) 68 } 69 70 // LightBlue applies a given color. 71 func LightBlue(text string) string { 72 return Apply(ColorLightBlue, text) 73 } 74 75 // LightPurple applies a given color. 76 func LightPurple(text string) string { 77 return Apply(ColorLightPurple, text) 78 } 79 80 // LightCyan applies a given color. 81 func LightCyan(text string) string { 82 return Apply(ColorLightCyan, text) 83 } 84 85 // LightWhite applies a given color. 86 func LightWhite(text string) string { 87 return Apply(ColorLightWhite, text) 88 } 89 90 // Apply applies a given color. 91 func Apply(colorCode Color, text string) string { 92 return colorCode.Normal() + text + ColorReset 93 } 94 95 // Bold applies a given color as bold. 96 func Bold(colorCode Color, text string) string { 97 return colorCode.Bold() + text + ColorReset 98 } 99 100 // Underline applies a given color as underline. 101 func Underline(colorCode Color, text string) string { 102 return colorCode.Underline() + text + ColorReset 103 } 104 105 // Color represents an ansi color code fragment. 106 type Color string 107 108 // Normal escapes the color for use in the terminal. 109 func (c Color) Normal() string { 110 return "\033[0;" + string(c) 111 } 112 113 // Bold escapes the color for use in the terminal as a bold color. 114 func (c Color) Bold() string { 115 return "\033[1;" + string(c) 116 } 117 118 // Underline escapes the color for use in the terminal as underlined color. 119 func (c Color) Underline() string { 120 return "\033[4;" + string(c) 121 } 122 123 // Apply applies a color to a given string. 124 func (c Color) Apply(text string) string { 125 return Apply(c, text) 126 } 127 128 // Utility Color Codes 129 const ( 130 ColorReset = "\033[0m" 131 ) 132 133 // Color codes 134 const ( 135 ColorDefault Color = "39m" 136 ColorBlack Color = "30m" 137 ColorRed Color = "31m" 138 ColorGreen Color = "32m" 139 ColorYellow Color = "33m" 140 ColorBlue Color = "34m" 141 ColorPurple Color = "35m" 142 ColorCyan Color = "36m" 143 ColorWhite Color = "37m" 144 ) 145 146 // BrightColorCodes 147 const ( 148 ColorLightBlack Color = "90m" 149 ColorLightRed Color = "91m" 150 ColorLightGreen Color = "92m" 151 ColorLightYellow Color = "93m" 152 ColorLightBlue Color = "94m" 153 ColorLightPurple Color = "95m" 154 ColorLightCyan Color = "96m" 155 ColorLightWhite Color = "97m" 156 ) 157 158 // BackgroundColorCodes 159 const ( 160 ColorBackgroundBlack Color = "40m" 161 ColorBackgroundRed Color = "41m" 162 ColorBackgroundGreen Color = "42m" 163 ColorBackgroundYellow Color = "43m" 164 ColorBackgroundBlue Color = "44m" 165 ColorBackgroundPurple Color = "45m" 166 ColorBackgroundCyan Color = "46m" 167 ColorBackgroundWhite Color = "47m" 168 ) 169 170 // BackgroundColorCodes 171 const ( 172 ColorBackgroundBrightBlack Color = "100m" 173 ColorBackgroundBrightRed Color = "101m" 174 ColorBackgroundBrightGreen Color = "102m" 175 ColorBackgroundBrightYellow Color = "103m" 176 ColorBackgroundBrightBlue Color = "104m" 177 ColorBackgroundBrightPurple Color = "105m" 178 ColorBackgroundBrightCyan Color = "106m" 179 ColorBackgroundBrightWhite Color = "107m" 180 )