...

Source file src/github.com/logrusorgru/aurora/v3/value.go

Documentation: github.com/logrusorgru/aurora/v3

     1  //
     2  // Copyright (c) 2016-2020 The Aurora Authors. All rights reserved.
     3  // This program is free software. It comes without any warranty,
     4  // to the extent permitted by applicable law. You can redistribute
     5  // it and/or modify it under the terms of the Unlicense. See LICENSE
     6  // file for more details or see below.
     7  //
     8  
     9  //
    10  // This is free and unencumbered software released into the public domain.
    11  //
    12  // Anyone is free to copy, modify, publish, use, compile, sell, or
    13  // distribute this software, either in source code form or as a compiled
    14  // binary, for any purpose, commercial or non-commercial, and by any
    15  // means.
    16  //
    17  // In jurisdictions that recognize copyright laws, the author or authors
    18  // of this software dedicate any and all copyright interest in the
    19  // software to the public domain. We make this dedication for the benefit
    20  // of the public at large and to the detriment of our heirs and
    21  // successors. We intend this dedication to be an overt act of
    22  // relinquishment in perpetuity of all present and future rights to this
    23  // software under copyright law.
    24  //
    25  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    26  // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    27  // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    28  // IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
    29  // OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
    30  // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
    31  // OTHER DEALINGS IN THE SOFTWARE.
    32  //
    33  // For more information, please refer to <http://unlicense.org/>
    34  //
    35  
    36  package aurora
    37  
    38  import (
    39  	"fmt"
    40  	"strconv"
    41  	"unicode/utf8"
    42  )
    43  
    44  // A Value represents any printable value
    45  // with it's color
    46  type Value interface {
    47  	// String returns string with colors. If there are any color
    48  	// or format the string will be terminated with \033[0m
    49  	fmt.Stringer
    50  	// Format implements fmt.Formatter interface
    51  	fmt.Formatter
    52  	// Color returns value's color
    53  	Color() Color
    54  	// Value returns value's value (welcome to the tautology club)
    55  	Value() interface{}
    56  
    57  	//  internals
    58  	tail() Color
    59  	setTail(Color) Value
    60  
    61  	// Bleach returns copy of original value without colors
    62  	//
    63  	// Deprecated: use Reset instead.
    64  	Bleach() Value
    65  	// Reset colors and formats
    66  	Reset() Value
    67  
    68  	//
    69  	// Formats
    70  	//
    71  	//
    72  	// Bold or increased intensity (1).
    73  	Bold() Value
    74  	// Faint, decreased intensity, reset the Bold (2).
    75  	Faint() Value
    76  	//
    77  	// DoublyUnderline or Bold off, double-underline
    78  	// per ECMA-48 (21). It depends.
    79  	DoublyUnderline() Value
    80  	// Fraktur, rarely supported (20).
    81  	Fraktur() Value
    82  	//
    83  	// Italic, not widely supported, sometimes
    84  	// treated as inverse (3).
    85  	Italic() Value
    86  	// Underline (4).
    87  	Underline() Value
    88  	//
    89  	// SlowBlink, blinking less than 150
    90  	// per minute (5).
    91  	SlowBlink() Value
    92  	// RapidBlink, blinking 150+ per minute,
    93  	// not widely supported (6).
    94  	RapidBlink() Value
    95  	// Blink is alias for the SlowBlink.
    96  	Blink() Value
    97  	//
    98  	// Reverse video, swap foreground and
    99  	// background colors (7).
   100  	Reverse() Value
   101  	// Inverse is alias for the Reverse
   102  	Inverse() Value
   103  	//
   104  	// Conceal, hidden, not widely supported (8).
   105  	Conceal() Value
   106  	// Hidden is alias for the Conceal
   107  	Hidden() Value
   108  	//
   109  	// CrossedOut, characters legible, but
   110  	// marked for deletion (9).
   111  	CrossedOut() Value
   112  	// StrikeThrough is alias for the CrossedOut.
   113  	StrikeThrough() Value
   114  	//
   115  	// Framed (51).
   116  	Framed() Value
   117  	// Encircled (52).
   118  	Encircled() Value
   119  	//
   120  	// Overlined (53).
   121  	Overlined() Value
   122  
   123  	//
   124  	// Foreground colors
   125  	//
   126  	//
   127  	// Black foreground color (30)
   128  	Black() Value
   129  	// Red foreground color (31)
   130  	Red() Value
   131  	// Green foreground color (32)
   132  	Green() Value
   133  	// Yellow foreground color (33)
   134  	Yellow() Value
   135  	// Brown foreground color (33)
   136  	//
   137  	// Deprecated: use Yellow instead, following specification
   138  	Brown() Value
   139  	// Blue foreground color (34)
   140  	Blue() Value
   141  	// Magenta foreground color (35)
   142  	Magenta() Value
   143  	// Cyan foreground color (36)
   144  	Cyan() Value
   145  	// White foreground color (37)
   146  	White() Value
   147  	//
   148  	// Bright foreground colors
   149  	//
   150  	// BrightBlack foreground color (90)
   151  	BrightBlack() Value
   152  	// BrightRed foreground color (91)
   153  	BrightRed() Value
   154  	// BrightGreen foreground color (92)
   155  	BrightGreen() Value
   156  	// BrightYellow foreground color (93)
   157  	BrightYellow() Value
   158  	// BrightBlue foreground color (94)
   159  	BrightBlue() Value
   160  	// BrightMagenta foreground color (95)
   161  	BrightMagenta() Value
   162  	// BrightCyan foreground color (96)
   163  	BrightCyan() Value
   164  	// BrightWhite foreground color (97)
   165  	BrightWhite() Value
   166  	//
   167  	// Other
   168  	//
   169  	// Index of pre-defined 8-bit foreground color
   170  	// from 0 to 255 (38;5;n).
   171  	//
   172  	//       0-  7:  standard colors (as in ESC [ 30–37 m)
   173  	//       8- 15:  high intensity colors (as in ESC [ 90–97 m)
   174  	//      16-231:  6 × 6 × 6 cube (216 colors): 16 + 36 × r + 6 × g + b (0 ≤ r, g, b ≤ 5)
   175  	//     232-255:  grayscale from black to white in 24 steps
   176  	//
   177  	Index(n uint8) Value
   178  	// Gray from 0 to 24.
   179  	Gray(n uint8) Value
   180  
   181  	//
   182  	// Background colors
   183  	//
   184  	//
   185  	// BgBlack background color (40)
   186  	BgBlack() Value
   187  	// BgRed background color (41)
   188  	BgRed() Value
   189  	// BgGreen background color (42)
   190  	BgGreen() Value
   191  	// BgYellow background color (43)
   192  	BgYellow() Value
   193  	// BgBrown background color (43)
   194  	//
   195  	// Deprecated: use BgYellow instead, following specification
   196  	BgBrown() Value
   197  	// BgBlue background color (44)
   198  	BgBlue() Value
   199  	// BgMagenta background color (45)
   200  	BgMagenta() Value
   201  	// BgCyan background color (46)
   202  	BgCyan() Value
   203  	// BgWhite background color (47)
   204  	BgWhite() Value
   205  	//
   206  	// Bright background colors
   207  	//
   208  	// BgBrightBlack background color (100)
   209  	BgBrightBlack() Value
   210  	// BgBrightRed background color (101)
   211  	BgBrightRed() Value
   212  	// BgBrightGreen background color (102)
   213  	BgBrightGreen() Value
   214  	// BgBrightYellow background color (103)
   215  	BgBrightYellow() Value
   216  	// BgBrightBlue background color (104)
   217  	BgBrightBlue() Value
   218  	// BgBrightMagenta background color (105)
   219  	BgBrightMagenta() Value
   220  	// BgBrightCyan background color (106)
   221  	BgBrightCyan() Value
   222  	// BgBrightWhite background color (107)
   223  	BgBrightWhite() Value
   224  	//
   225  	// Other
   226  	//
   227  	// BgIndex of 8-bit pre-defined background color
   228  	// from 0 to 255 (48;5;n).
   229  	//
   230  	//       0-  7:  standard colors (as in ESC [ 40–47 m)
   231  	//       8- 15:  high intensity colors (as in ESC [100–107 m)
   232  	//      16-231:  6 × 6 × 6 cube (216 colors): 16 + 36 × r + 6 × g + b (0 ≤ r, g, b ≤ 5)
   233  	//     232-255:  grayscale from black to white in 24 steps
   234  	//
   235  	BgIndex(n uint8) Value
   236  	// BgGray from 0 to 24.
   237  	BgGray(n uint8) Value
   238  
   239  	//
   240  	// Special
   241  	//
   242  	// Colorize removes existing colors and
   243  	// formats of the argument and applies given.
   244  	Colorize(color Color) Value
   245  }
   246  
   247  // Value without colors
   248  
   249  type valueClear struct {
   250  	value interface{}
   251  }
   252  
   253  func (vc valueClear) String() string { return fmt.Sprint(vc.value) }
   254  
   255  func (vc valueClear) Color() Color       { return 0 }
   256  func (vc valueClear) Value() interface{} { return vc.value }
   257  
   258  func (vc valueClear) tail() Color         { return 0 }
   259  func (vc valueClear) setTail(Color) Value { return vc }
   260  
   261  func (vc valueClear) Bleach() Value { return vc }
   262  func (vc valueClear) Reset() Value  { return vc }
   263  
   264  func (vc valueClear) Bold() Value            { return vc }
   265  func (vc valueClear) Faint() Value           { return vc }
   266  func (vc valueClear) DoublyUnderline() Value { return vc }
   267  func (vc valueClear) Fraktur() Value         { return vc }
   268  func (vc valueClear) Italic() Value          { return vc }
   269  func (vc valueClear) Underline() Value       { return vc }
   270  func (vc valueClear) SlowBlink() Value       { return vc }
   271  func (vc valueClear) RapidBlink() Value      { return vc }
   272  func (vc valueClear) Blink() Value           { return vc }
   273  func (vc valueClear) Reverse() Value         { return vc }
   274  func (vc valueClear) Inverse() Value         { return vc }
   275  func (vc valueClear) Conceal() Value         { return vc }
   276  func (vc valueClear) Hidden() Value          { return vc }
   277  func (vc valueClear) CrossedOut() Value      { return vc }
   278  func (vc valueClear) StrikeThrough() Value   { return vc }
   279  func (vc valueClear) Framed() Value          { return vc }
   280  func (vc valueClear) Encircled() Value       { return vc }
   281  func (vc valueClear) Overlined() Value       { return vc }
   282  
   283  func (vc valueClear) Black() Value         { return vc }
   284  func (vc valueClear) Red() Value           { return vc }
   285  func (vc valueClear) Green() Value         { return vc }
   286  func (vc valueClear) Yellow() Value        { return vc }
   287  func (vc valueClear) Brown() Value         { return vc }
   288  func (vc valueClear) Blue() Value          { return vc }
   289  func (vc valueClear) Magenta() Value       { return vc }
   290  func (vc valueClear) Cyan() Value          { return vc }
   291  func (vc valueClear) White() Value         { return vc }
   292  func (vc valueClear) BrightBlack() Value   { return vc }
   293  func (vc valueClear) BrightRed() Value     { return vc }
   294  func (vc valueClear) BrightGreen() Value   { return vc }
   295  func (vc valueClear) BrightYellow() Value  { return vc }
   296  func (vc valueClear) BrightBlue() Value    { return vc }
   297  func (vc valueClear) BrightMagenta() Value { return vc }
   298  func (vc valueClear) BrightCyan() Value    { return vc }
   299  func (vc valueClear) BrightWhite() Value   { return vc }
   300  func (vc valueClear) Index(uint8) Value    { return vc }
   301  func (vc valueClear) Gray(uint8) Value     { return vc }
   302  
   303  func (vc valueClear) BgBlack() Value         { return vc }
   304  func (vc valueClear) BgRed() Value           { return vc }
   305  func (vc valueClear) BgGreen() Value         { return vc }
   306  func (vc valueClear) BgYellow() Value        { return vc }
   307  func (vc valueClear) BgBrown() Value         { return vc }
   308  func (vc valueClear) BgBlue() Value          { return vc }
   309  func (vc valueClear) BgMagenta() Value       { return vc }
   310  func (vc valueClear) BgCyan() Value          { return vc }
   311  func (vc valueClear) BgWhite() Value         { return vc }
   312  func (vc valueClear) BgBrightBlack() Value   { return vc }
   313  func (vc valueClear) BgBrightRed() Value     { return vc }
   314  func (vc valueClear) BgBrightGreen() Value   { return vc }
   315  func (vc valueClear) BgBrightYellow() Value  { return vc }
   316  func (vc valueClear) BgBrightBlue() Value    { return vc }
   317  func (vc valueClear) BgBrightMagenta() Value { return vc }
   318  func (vc valueClear) BgBrightCyan() Value    { return vc }
   319  func (vc valueClear) BgBrightWhite() Value   { return vc }
   320  func (vc valueClear) BgIndex(uint8) Value    { return vc }
   321  func (vc valueClear) BgGray(uint8) Value     { return vc }
   322  func (vc valueClear) Colorize(Color) Value   { return vc }
   323  
   324  func (vc valueClear) Format(s fmt.State, verb rune) {
   325  	// it's enough for many cases (%-+020.10f)
   326  	// %          - 1
   327  	// availFlags - 3 (5)
   328  	// width      - 2
   329  	// prec       - 3 (.23)
   330  	// verb       - 1
   331  	// --------------
   332  	//             10
   333  	format := make([]byte, 1, 10)
   334  	format[0] = '%'
   335  	var f byte
   336  	for i := 0; i < len(availFlags); i++ {
   337  		if f = availFlags[i]; s.Flag(int(f)) {
   338  			format = append(format, f)
   339  		}
   340  	}
   341  	var width, prec int
   342  	var ok bool
   343  	if width, ok = s.Width(); ok {
   344  		format = strconv.AppendInt(format, int64(width), 10)
   345  	}
   346  	if prec, ok = s.Precision(); ok {
   347  		format = append(format, '.')
   348  		format = strconv.AppendInt(format, int64(prec), 10)
   349  	}
   350  	if verb > utf8.RuneSelf {
   351  		format = append(format, string(verb)...)
   352  	} else {
   353  		format = append(format, byte(verb))
   354  	}
   355  	fmt.Fprintf(s, string(format), vc.value)
   356  }
   357  
   358  // Value within colors
   359  
   360  type value struct {
   361  	value     interface{} // value as it
   362  	color     Color       // this color
   363  	tailColor Color       // tail color
   364  }
   365  
   366  func (v value) String() string {
   367  	if v.color != 0 {
   368  		if v.tailColor != 0 {
   369  			return esc + v.color.Nos(true) + "m" +
   370  				fmt.Sprint(v.value) +
   371  				esc + v.tailColor.Nos(true) + "m"
   372  		}
   373  		return esc + v.color.Nos(false) + "m" + fmt.Sprint(v.value) + clear
   374  	}
   375  	return fmt.Sprint(v.value)
   376  }
   377  
   378  func (v value) Color() Color { return v.color }
   379  
   380  func (v value) Bleach() Value {
   381  	v.color, v.tailColor = 0, 0
   382  	return v
   383  }
   384  
   385  func (v value) Reset() Value {
   386  	v.color, v.tailColor = 0, 0
   387  	return v
   388  }
   389  
   390  func (v value) tail() Color { return v.tailColor }
   391  
   392  func (v value) setTail(t Color) Value {
   393  	v.tailColor = t
   394  	return v
   395  }
   396  
   397  func (v value) Value() interface{} { return v.value }
   398  
   399  func (v value) Format(s fmt.State, verb rune) {
   400  
   401  	// it's enough for many cases (%-+020.10f)
   402  	// %          - 1
   403  	// availFlags - 3 (5)
   404  	// width      - 2
   405  	// prec       - 3 (.23)
   406  	// verb       - 1
   407  	// --------------
   408  	//             10
   409  	// +
   410  	// \033[                            5
   411  	// 0;1;3;4;5;7;8;9;20;21;51;52;53  30
   412  	// 38;5;216                         8
   413  	// 48;5;216                         8
   414  	// m                                1
   415  	// +
   416  	// \033[0m                          7
   417  	//
   418  	// x2 (possible tail color)
   419  	//
   420  	// 10 + 59 * 2 = 128
   421  
   422  	format := make([]byte, 0, 128)
   423  	if v.color != 0 {
   424  		format = append(format, esc...)
   425  		format = v.color.appendNos(format, v.tailColor != 0)
   426  		format = append(format, 'm')
   427  	}
   428  	format = append(format, '%')
   429  	var f byte
   430  	for i := 0; i < len(availFlags); i++ {
   431  		if f = availFlags[i]; s.Flag(int(f)) {
   432  			format = append(format, f)
   433  		}
   434  	}
   435  	var width, prec int
   436  	var ok bool
   437  	if width, ok = s.Width(); ok {
   438  		format = strconv.AppendInt(format, int64(width), 10)
   439  	}
   440  	if prec, ok = s.Precision(); ok {
   441  		format = append(format, '.')
   442  		format = strconv.AppendInt(format, int64(prec), 10)
   443  	}
   444  	if verb > utf8.RuneSelf {
   445  		format = append(format, string(verb)...)
   446  	} else {
   447  		format = append(format, byte(verb))
   448  	}
   449  	if v.color != 0 {
   450  		if v.tailColor != 0 {
   451  			// set next (previous) format clearing current one
   452  			format = append(format, esc...)
   453  			format = v.tailColor.appendNos(format, true)
   454  			format = append(format, 'm')
   455  		} else {
   456  			format = append(format, clear...) // just clear
   457  		}
   458  	}
   459  	fmt.Fprintf(s, string(format), v.value)
   460  }
   461  
   462  func (v value) Bold() Value {
   463  	v.color = (v.color &^ FaintFm) | BoldFm
   464  	return v
   465  }
   466  
   467  func (v value) Faint() Value {
   468  	v.color = (v.color &^ BoldFm) | FaintFm
   469  	return v
   470  }
   471  
   472  func (v value) DoublyUnderline() Value {
   473  	v.color |= DoublyUnderlineFm
   474  	return v
   475  }
   476  
   477  func (v value) Fraktur() Value {
   478  	v.color |= FrakturFm
   479  	return v
   480  }
   481  
   482  func (v value) Italic() Value {
   483  	v.color |= ItalicFm
   484  	return v
   485  }
   486  
   487  func (v value) Underline() Value {
   488  	v.color |= UnderlineFm
   489  	return v
   490  }
   491  
   492  func (v value) SlowBlink() Value {
   493  	v.color = (v.color &^ RapidBlinkFm) | SlowBlinkFm
   494  	return v
   495  }
   496  
   497  func (v value) RapidBlink() Value {
   498  	v.color = (v.color &^ SlowBlinkFm) | RapidBlinkFm
   499  	return v
   500  }
   501  
   502  func (v value) Blink() Value {
   503  	return v.SlowBlink()
   504  }
   505  
   506  func (v value) Reverse() Value {
   507  	v.color |= ReverseFm
   508  	return v
   509  }
   510  
   511  func (v value) Inverse() Value {
   512  	return v.Reverse()
   513  }
   514  
   515  func (v value) Conceal() Value {
   516  	v.color |= ConcealFm
   517  	return v
   518  }
   519  
   520  func (v value) Hidden() Value {
   521  	return v.Conceal()
   522  }
   523  
   524  func (v value) CrossedOut() Value {
   525  	v.color |= CrossedOutFm
   526  	return v
   527  }
   528  
   529  func (v value) StrikeThrough() Value {
   530  	return v.CrossedOut()
   531  }
   532  
   533  func (v value) Framed() Value {
   534  	v.color |= FramedFm
   535  	return v
   536  }
   537  
   538  func (v value) Encircled() Value {
   539  	v.color |= EncircledFm
   540  	return v
   541  }
   542  
   543  func (v value) Overlined() Value {
   544  	v.color |= OverlinedFm
   545  	return v
   546  }
   547  
   548  func (v value) Black() Value {
   549  	v.color = (v.color &^ maskFg) | BlackFg
   550  	return v
   551  }
   552  
   553  func (v value) Red() Value {
   554  	v.color = (v.color &^ maskFg) | RedFg
   555  	return v
   556  }
   557  
   558  func (v value) Green() Value {
   559  	v.color = (v.color &^ maskFg) | GreenFg
   560  	return v
   561  }
   562  
   563  func (v value) Yellow() Value {
   564  	v.color = (v.color &^ maskFg) | YellowFg
   565  	return v
   566  }
   567  
   568  func (v value) Brown() Value {
   569  	return v.Yellow()
   570  }
   571  
   572  func (v value) Blue() Value {
   573  	v.color = (v.color &^ maskFg) | BlueFg
   574  	return v
   575  }
   576  
   577  func (v value) Magenta() Value {
   578  	v.color = (v.color &^ maskFg) | MagentaFg
   579  	return v
   580  }
   581  
   582  func (v value) Cyan() Value {
   583  	v.color = (v.color &^ maskFg) | CyanFg
   584  	return v
   585  }
   586  
   587  func (v value) White() Value {
   588  	v.color = (v.color &^ maskFg) | WhiteFg
   589  	return v
   590  }
   591  
   592  func (v value) BrightBlack() Value {
   593  	v.color = (v.color &^ maskFg) | BrightFg | BlackFg
   594  	return v
   595  }
   596  
   597  func (v value) BrightRed() Value {
   598  	v.color = (v.color &^ maskFg) | BrightFg | RedFg
   599  	return v
   600  }
   601  
   602  func (v value) BrightGreen() Value {
   603  	v.color = (v.color &^ maskFg) | BrightFg | GreenFg
   604  	return v
   605  }
   606  
   607  func (v value) BrightYellow() Value {
   608  	v.color = (v.color &^ maskFg) | BrightFg | YellowFg
   609  	return v
   610  }
   611  
   612  func (v value) BrightBlue() Value {
   613  	v.color = (v.color &^ maskFg) | BrightFg | BlueFg
   614  	return v
   615  }
   616  
   617  func (v value) BrightMagenta() Value {
   618  	v.color = (v.color &^ maskFg) | BrightFg | MagentaFg
   619  	return v
   620  }
   621  
   622  func (v value) BrightCyan() Value {
   623  	v.color = (v.color &^ maskFg) | BrightFg | CyanFg
   624  	return v
   625  }
   626  
   627  func (v value) BrightWhite() Value {
   628  	v.color = (v.color &^ maskFg) | BrightFg | WhiteFg
   629  	return v
   630  }
   631  
   632  func (v value) Index(n uint8) Value {
   633  	v.color = (v.color &^ maskFg) | (Color(n) << shiftFg) | flagFg
   634  	return v
   635  }
   636  
   637  func (v value) Gray(n uint8) Value {
   638  	if n > 23 {
   639  		n = 23
   640  	}
   641  	v.color = (v.color &^ maskFg) | (Color(232+n) << shiftFg) | flagFg
   642  	return v
   643  }
   644  
   645  func (v value) BgBlack() Value {
   646  	v.color = (v.color &^ maskBg) | BlackBg
   647  	return v
   648  }
   649  
   650  func (v value) BgRed() Value {
   651  	v.color = (v.color &^ maskBg) | RedBg
   652  	return v
   653  }
   654  
   655  func (v value) BgGreen() Value {
   656  	v.color = (v.color &^ maskBg) | GreenBg
   657  	return v
   658  }
   659  
   660  func (v value) BgYellow() Value {
   661  	v.color = (v.color &^ maskBg) | YellowBg
   662  	return v
   663  }
   664  
   665  func (v value) BgBrown() Value {
   666  	return v.BgYellow()
   667  }
   668  
   669  func (v value) BgBlue() Value {
   670  	v.color = (v.color &^ maskBg) | BlueBg
   671  	return v
   672  }
   673  
   674  func (v value) BgMagenta() Value {
   675  	v.color = (v.color &^ maskBg) | MagentaBg
   676  	return v
   677  }
   678  
   679  func (v value) BgCyan() Value {
   680  	v.color = (v.color &^ maskBg) | CyanBg
   681  	return v
   682  }
   683  
   684  func (v value) BgWhite() Value {
   685  	v.color = (v.color &^ maskBg) | WhiteBg
   686  	return v
   687  }
   688  
   689  func (v value) BgBrightBlack() Value {
   690  	v.color = (v.color &^ maskBg) | BrightBg | BlackBg
   691  	return v
   692  }
   693  
   694  func (v value) BgBrightRed() Value {
   695  	v.color = (v.color &^ maskBg) | BrightBg | RedBg
   696  	return v
   697  }
   698  
   699  func (v value) BgBrightGreen() Value {
   700  	v.color = (v.color &^ maskBg) | BrightBg | GreenBg
   701  	return v
   702  }
   703  
   704  func (v value) BgBrightYellow() Value {
   705  	v.color = (v.color &^ maskBg) | BrightBg | YellowBg
   706  	return v
   707  }
   708  
   709  func (v value) BgBrightBlue() Value {
   710  	v.color = (v.color &^ maskBg) | BrightBg | BlueBg
   711  	return v
   712  }
   713  
   714  func (v value) BgBrightMagenta() Value {
   715  	v.color = (v.color &^ maskBg) | BrightBg | MagentaBg
   716  	return v
   717  }
   718  
   719  func (v value) BgBrightCyan() Value {
   720  	v.color = (v.color &^ maskBg) | BrightBg | CyanBg
   721  	return v
   722  }
   723  
   724  func (v value) BgBrightWhite() Value {
   725  	v.color = (v.color &^ maskBg) | BrightBg | WhiteBg
   726  	return v
   727  }
   728  
   729  func (v value) BgIndex(n uint8) Value {
   730  	v.color = (v.color &^ maskBg) | (Color(n) << shiftBg) | flagBg
   731  	return v
   732  }
   733  
   734  func (v value) BgGray(n uint8) Value {
   735  	if n > 23 {
   736  		n = 23
   737  	}
   738  	v.color = (v.color &^ maskBg) | (Color(232+n) << shiftBg) | flagBg
   739  	return v
   740  }
   741  
   742  func (v value) Colorize(color Color) Value {
   743  	v.color = color
   744  	return v
   745  }
   746  

View as plain text