1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558
|
//
// Copyright (c) 2016-2020 The Aurora Authors. All rights reserved.
// This program is free software. It comes without any warranty,
// to the extent permitted by applicable law. You can redistribute
// it and/or modify it under the terms of the Unlicense. See LICENSE
// file for more details or see below.
//
//
// This is free and unencumbered software released into the public domain.
//
// Anyone is free to copy, modify, publish, use, compile, sell, or
// distribute this software, either in source code form or as a compiled
// binary, for any purpose, commercial or non-commercial, and by any
// means.
//
// In jurisdictions that recognize copyright laws, the author or authors
// of this software dedicate any and all copyright interest in the
// software to the public domain. We make this dedication for the benefit
// of the public at large and to the detriment of our heirs and
// successors. We intend this dedication to be an overt act of
// relinquishment in perpetuity of all present and future rights to this
// software under copyright law.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
// For more information, please refer to <http://unlicense.org/>
//
package aurora
// Colorize wraps given value into Value with
// given colors. For example
//
// s := Colorize("some", BlueFg|GreenBg|BoldFm)
//
// returns a Value with blue foreground, green
// background and bold. Unlike functions like
// Red/BgBlue/Bold etc. This function clears
// all previous colors and formats. Thus
//
// s := Colorize(Red("some"), BgBlue)
//
// clears red color from value
func Colorize(arg interface{}, color Color) Value {
if val, ok := arg.(value); ok {
val.color = color
return val
}
return value{arg, color, 0}
}
// Reset wraps given argument returning Value
// without formats and colors.
func Reset(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.Reset()
}
return value{value: arg}
}
//
// Formats
//
// Bold or increased intensity (1).
func Bold(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.Bold()
}
return value{value: arg, color: BoldFm}
}
// Faint decreases intensity (2).
// The Faint rejects the Bold.
func Faint(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.Faint()
}
return value{value: arg, color: FaintFm}
}
// DoublyUnderline or Bold off, double-underline
// per ECMA-48 (21).
func DoublyUnderline(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.DoublyUnderline()
}
return value{value: arg, color: DoublyUnderlineFm}
}
// Fraktur is rarely supported (20).
func Fraktur(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.Fraktur()
}
return value{value: arg, color: FrakturFm}
}
// Italic is not widely supported, sometimes
// treated as inverse (3).
func Italic(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.Italic()
}
return value{value: arg, color: ItalicFm}
}
// Underline (4).
func Underline(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.Underline()
}
return value{value: arg, color: UnderlineFm}
}
// SlowBlink makes text blink less than
// 150 per minute (5).
func SlowBlink(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.SlowBlink()
}
return value{value: arg, color: SlowBlinkFm}
}
// RapidBlink makes text blink 150+ per
// minute. It is not widely supported (6).
func RapidBlink(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.RapidBlink()
}
return value{value: arg, color: RapidBlinkFm}
}
// Blink is alias for the SlowBlink.
func Blink(arg interface{}) Value {
return SlowBlink(arg)
}
// Reverse video, swap foreground and
// background colors (7).
func Reverse(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.Reverse()
}
return value{value: arg, color: ReverseFm}
}
// Inverse is alias for the Reverse
func Inverse(arg interface{}) Value {
return Reverse(arg)
}
// Conceal hides text, preserving an ability to select
// the text and copy it. It is not widely supported (8).
func Conceal(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.Conceal()
}
return value{value: arg, color: ConcealFm}
}
// Hidden is alias for the Conceal
func Hidden(arg interface{}) Value {
return Conceal(arg)
}
// CrossedOut makes characters legible, but
// marked for deletion (9).
func CrossedOut(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.CrossedOut()
}
return value{value: arg, color: CrossedOutFm}
}
// StrikeThrough is alias for the CrossedOut.
func StrikeThrough(arg interface{}) Value {
return CrossedOut(arg)
}
// Framed (51).
func Framed(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.Framed()
}
return value{value: arg, color: FramedFm}
}
// Encircled (52).
func Encircled(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.Encircled()
}
return value{value: arg, color: EncircledFm}
}
// Overlined (53).
func Overlined(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.Overlined()
}
return value{value: arg, color: OverlinedFm}
}
//
// Foreground colors
//
//
// Black foreground color (30)
func Black(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.Black()
}
return value{value: arg, color: BlackFg}
}
// Red foreground color (31)
func Red(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.Red()
}
return value{value: arg, color: RedFg}
}
// Green foreground color (32)
func Green(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.Green()
}
return value{value: arg, color: GreenFg}
}
// Yellow foreground color (33)
func Yellow(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.Yellow()
}
return value{value: arg, color: YellowFg}
}
// Brown foreground color (33)
//
// Deprecated: use Yellow instead, following specification
func Brown(arg interface{}) Value {
return Yellow(arg)
}
// Blue foreground color (34)
func Blue(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.Blue()
}
return value{value: arg, color: BlueFg}
}
// Magenta foreground color (35)
func Magenta(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.Magenta()
}
return value{value: arg, color: MagentaFg}
}
// Cyan foreground color (36)
func Cyan(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.Cyan()
}
return value{value: arg, color: CyanFg}
}
// White foreground color (37)
func White(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.White()
}
return value{value: arg, color: WhiteFg}
}
//
// Bright foreground colors
//
// BrightBlack foreground color (90)
func BrightBlack(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.BrightBlack()
}
return value{value: arg, color: BrightFg | BlackFg}
}
// BrightRed foreground color (91)
func BrightRed(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.BrightRed()
}
return value{value: arg, color: BrightFg | RedFg}
}
// BrightGreen foreground color (92)
func BrightGreen(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.BrightGreen()
}
return value{value: arg, color: BrightFg | GreenFg}
}
// BrightYellow foreground color (93)
func BrightYellow(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.BrightYellow()
}
return value{value: arg, color: BrightFg | YellowFg}
}
// BrightBlue foreground color (94)
func BrightBlue(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.BrightBlue()
}
return value{value: arg, color: BrightFg | BlueFg}
}
// BrightMagenta foreground color (95)
func BrightMagenta(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.BrightMagenta()
}
return value{value: arg, color: BrightFg | MagentaFg}
}
// BrightCyan foreground color (96)
func BrightCyan(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.BrightCyan()
}
return value{value: arg, color: BrightFg | CyanFg}
}
// BrightWhite foreground color (97)
func BrightWhite(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.BrightWhite()
}
return value{value: arg, color: BrightFg | WhiteFg}
}
//
// Other
//
// Index of pre-defined 8-bit foreground color
// from 0 to 255 (38;5;n).
//
// 0- 7: standard colors (as in ESC [ 30–37 m)
// 8- 15: high intensity colors (as in ESC [ 90–97 m)
// 16-231: 6 × 6 × 6 cube (216 colors): 16 + 36 × r + 6 × g + b (0 ≤ r, g, b ≤ 5)
// 232-255: grayscale from black to white in 24 steps
//
func Index(n uint8, arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.Index(n)
}
return value{value: arg, color: (Color(n) << shiftFg) | flagFg}
}
// Gray from 0 to 24.
func Gray(n uint8, arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.Gray(n)
}
if n > 23 {
n = 23
}
return value{value: arg, color: (Color(232+n) << shiftFg) | flagFg}
}
//
// Background colors
//
//
// BgBlack background color (40)
func BgBlack(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.BgBlack()
}
return value{value: arg, color: BlackBg}
}
// BgRed background color (41)
func BgRed(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.BgRed()
}
return value{value: arg, color: RedBg}
}
// BgGreen background color (42)
func BgGreen(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.BgGreen()
}
return value{value: arg, color: GreenBg}
}
// BgYellow background color (43)
func BgYellow(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.BgYellow()
}
return value{value: arg, color: YellowBg}
}
// BgBrown background color (43)
//
// Deprecated: use BgYellow instead, following specification
func BgBrown(arg interface{}) Value {
return BgYellow(arg)
}
// BgBlue background color (44)
func BgBlue(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.BgBlue()
}
return value{value: arg, color: BlueBg}
}
// BgMagenta background color (45)
func BgMagenta(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.BgMagenta()
}
return value{value: arg, color: MagentaBg}
}
// BgCyan background color (46)
func BgCyan(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.BgCyan()
}
return value{value: arg, color: CyanBg}
}
// BgWhite background color (47)
func BgWhite(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.BgWhite()
}
return value{value: arg, color: WhiteBg}
}
//
// Bright background colors
//
// BgBrightBlack background color (100)
func BgBrightBlack(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.BgBrightBlack()
}
return value{value: arg, color: BrightBg | BlackBg}
}
// BgBrightRed background color (101)
func BgBrightRed(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.BgBrightRed()
}
return value{value: arg, color: BrightBg | RedBg}
}
// BgBrightGreen background color (102)
func BgBrightGreen(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.BgBrightGreen()
}
return value{value: arg, color: BrightBg | GreenBg}
}
// BgBrightYellow background color (103)
func BgBrightYellow(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.BgBrightYellow()
}
return value{value: arg, color: BrightBg | YellowBg}
}
// BgBrightBlue background color (104)
func BgBrightBlue(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.BgBrightBlue()
}
return value{value: arg, color: BrightBg | BlueBg}
}
// BgBrightMagenta background color (105)
func BgBrightMagenta(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.BgBrightMagenta()
}
return value{value: arg, color: BrightBg | MagentaBg}
}
// BgBrightCyan background color (106)
func BgBrightCyan(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.BgBrightCyan()
}
return value{value: arg, color: BrightBg | CyanBg}
}
// BgBrightWhite background color (107)
func BgBrightWhite(arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.BgBrightWhite()
}
return value{value: arg, color: BrightBg | WhiteBg}
}
//
// Other
//
// BgIndex of 8-bit pre-defined background color
// from 0 to 255 (48;5;n).
//
// 0- 7: standard colors (as in ESC [ 40–47 m)
// 8- 15: high intensity colors (as in ESC [100–107 m)
// 16-231: 6 × 6 × 6 cube (216 colors): 16 + 36 × r + 6 × g + b (0 ≤ r, g, b ≤ 5)
// 232-255: grayscale from black to white in 24 steps
//
func BgIndex(n uint8, arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.BgIndex(n)
}
return value{value: arg, color: (Color(n) << shiftBg) | flagBg}
}
// BgGray from 0 to 24.
func BgGray(n uint8, arg interface{}) Value {
if val, ok := arg.(Value); ok {
return val.BgGray(n)
}
if n > 23 {
n = 23
}
return value{value: arg, color: (Color(n+232) << shiftBg) | flagBg}
}
|