github.com/qioalice/ekago/v3@v3.3.2-0.20221202205325-5c262d586ee4/internal/3rdparty/xtermcolor/colors.go (about)

     1  // Package xtermcolor provides a palette for xterm colors, and conversion to that palette from anything implementing color.Color
     2  package xtermcolor
     3  
     4  import (
     5  	"errors"
     6  	"image/color"
     7  	"strconv"
     8  )
     9  
    10  // Colors lists Xterm color codes vs. RGBA; values taken from https://gist.github.com/jasonm23/2868981
    11  // color.Palette is really []color.Color and provides .Convert() and .Index()
    12  //
    13  //goland:noinspection GoStructInitializationWithoutFieldNames
    14  var Colors = color.Palette{
    15  	// Basic block
    16  	0:  color.RGBA{0x00, 0x00, 0x00, 0xff},
    17  	1:  color.RGBA{0x80, 0x00, 0x00, 0xff},
    18  	2:  color.RGBA{0x00, 0x80, 0x00, 0xff},
    19  	3:  color.RGBA{0x80, 0x80, 0x00, 0xff},
    20  	4:  color.RGBA{0x00, 0x00, 0x80, 0xff},
    21  	5:  color.RGBA{0x80, 0x00, 0x80, 0xff},
    22  	6:  color.RGBA{0x00, 0x80, 0x80, 0xff},
    23  	7:  color.RGBA{0xc0, 0xc0, 0xc0, 0xff},
    24  	8:  color.RGBA{0x80, 0x80, 0x80, 0xff},
    25  	9:  color.RGBA{0xff, 0x00, 0x00, 0xff},
    26  	10: color.RGBA{0x00, 0xff, 0x00, 0xff},
    27  	11: color.RGBA{0xff, 0xff, 0x00, 0xff},
    28  	12: color.RGBA{0x00, 0x00, 0xff, 0xff},
    29  	13: color.RGBA{0xff, 0x00, 0xff, 0xff},
    30  	14: color.RGBA{0x00, 0xff, 0xff, 0xff},
    31  	15: color.RGBA{0xff, 0xff, 0xff, 0xff},
    32  
    33  	// 6x6x6 cube block
    34  	16:  color.RGBA{0x00, 0x00, 0x00, 0xff},
    35  	17:  color.RGBA{0x00, 0x00, 0x5f, 0xff},
    36  	18:  color.RGBA{0x00, 0x00, 0x87, 0xff},
    37  	19:  color.RGBA{0x00, 0x00, 0xaf, 0xff},
    38  	20:  color.RGBA{0x00, 0x00, 0xd7, 0xff},
    39  	21:  color.RGBA{0x00, 0x00, 0xff, 0xff},
    40  	22:  color.RGBA{0x00, 0x5f, 0x00, 0xff},
    41  	23:  color.RGBA{0x00, 0x5f, 0x5f, 0xff},
    42  	24:  color.RGBA{0x00, 0x5f, 0x87, 0xff},
    43  	25:  color.RGBA{0x00, 0x5f, 0xaf, 0xff},
    44  	26:  color.RGBA{0x00, 0x5f, 0xd7, 0xff},
    45  	27:  color.RGBA{0x00, 0x5f, 0xff, 0xff},
    46  	28:  color.RGBA{0x00, 0x87, 0x00, 0xff},
    47  	29:  color.RGBA{0x00, 0x87, 0x5f, 0xff},
    48  	30:  color.RGBA{0x00, 0x87, 0x87, 0xff},
    49  	31:  color.RGBA{0x00, 0x87, 0xaf, 0xff},
    50  	32:  color.RGBA{0x00, 0x87, 0xd7, 0xff},
    51  	33:  color.RGBA{0x00, 0x87, 0xff, 0xff},
    52  	34:  color.RGBA{0x00, 0xaf, 0x00, 0xff},
    53  	35:  color.RGBA{0x00, 0xaf, 0x5f, 0xff},
    54  	36:  color.RGBA{0x00, 0xaf, 0x87, 0xff},
    55  	37:  color.RGBA{0x00, 0xaf, 0xaf, 0xff},
    56  	38:  color.RGBA{0x00, 0xaf, 0xd7, 0xff},
    57  	39:  color.RGBA{0x00, 0xaf, 0xff, 0xff},
    58  	40:  color.RGBA{0x00, 0xd7, 0x00, 0xff},
    59  	41:  color.RGBA{0x00, 0xd7, 0x5f, 0xff},
    60  	42:  color.RGBA{0x00, 0xd7, 0x87, 0xff},
    61  	43:  color.RGBA{0x00, 0xd7, 0xaf, 0xff},
    62  	44:  color.RGBA{0x00, 0xd7, 0xd7, 0xff},
    63  	45:  color.RGBA{0x00, 0xd7, 0xff, 0xff},
    64  	46:  color.RGBA{0x00, 0xff, 0x00, 0xff},
    65  	47:  color.RGBA{0x00, 0xff, 0x5f, 0xff},
    66  	48:  color.RGBA{0x00, 0xff, 0x87, 0xff},
    67  	49:  color.RGBA{0x00, 0xff, 0xaf, 0xff},
    68  	50:  color.RGBA{0x00, 0xff, 0xd7, 0xff},
    69  	51:  color.RGBA{0x00, 0xff, 0xff, 0xff},
    70  	82:  color.RGBA{0x5f, 0xff, 0x00, 0xff},
    71  	83:  color.RGBA{0x5f, 0xff, 0x5f, 0xff},
    72  	84:  color.RGBA{0x5f, 0xff, 0x87, 0xff},
    73  	85:  color.RGBA{0x5f, 0xff, 0xaf, 0xff},
    74  	86:  color.RGBA{0x5f, 0xff, 0xd7, 0xff},
    75  	87:  color.RGBA{0x5f, 0xff, 0xff, 0xff},
    76  	76:  color.RGBA{0x5f, 0xd7, 0x00, 0xff},
    77  	77:  color.RGBA{0x5f, 0xd7, 0x5f, 0xff},
    78  	78:  color.RGBA{0x5f, 0xd7, 0x87, 0xff},
    79  	79:  color.RGBA{0x5f, 0xd7, 0xaf, 0xff},
    80  	80:  color.RGBA{0x5f, 0xd7, 0xd7, 0xff},
    81  	81:  color.RGBA{0x5f, 0xd7, 0xff, 0xff},
    82  	70:  color.RGBA{0x5f, 0xaf, 0x00, 0xff},
    83  	71:  color.RGBA{0x5f, 0xaf, 0x5f, 0xff},
    84  	72:  color.RGBA{0x5f, 0xaf, 0x87, 0xff},
    85  	73:  color.RGBA{0x5f, 0xaf, 0xaf, 0xff},
    86  	74:  color.RGBA{0x5f, 0xaf, 0xd7, 0xff},
    87  	75:  color.RGBA{0x5f, 0xaf, 0xff, 0xff},
    88  	64:  color.RGBA{0x5f, 0x87, 0x00, 0xff},
    89  	65:  color.RGBA{0x5f, 0x87, 0x5f, 0xff},
    90  	66:  color.RGBA{0x5f, 0x87, 0x87, 0xff},
    91  	67:  color.RGBA{0x5f, 0x87, 0xaf, 0xff},
    92  	68:  color.RGBA{0x5f, 0x87, 0xd7, 0xff},
    93  	69:  color.RGBA{0x5f, 0x87, 0xff, 0xff},
    94  	58:  color.RGBA{0x5f, 0x5f, 0x00, 0xff},
    95  	59:  color.RGBA{0x5f, 0x5f, 0x5f, 0xff},
    96  	60:  color.RGBA{0x5f, 0x5f, 0x87, 0xff},
    97  	61:  color.RGBA{0x5f, 0x5f, 0xaf, 0xff},
    98  	62:  color.RGBA{0x5f, 0x5f, 0xd7, 0xff},
    99  	63:  color.RGBA{0x5f, 0x5f, 0xff, 0xff},
   100  	52:  color.RGBA{0x5f, 0x00, 0x00, 0xff},
   101  	53:  color.RGBA{0x5f, 0x00, 0x5f, 0xff},
   102  	54:  color.RGBA{0x5f, 0x00, 0x87, 0xff},
   103  	55:  color.RGBA{0x5f, 0x00, 0xaf, 0xff},
   104  	56:  color.RGBA{0x5f, 0x00, 0xd7, 0xff},
   105  	57:  color.RGBA{0x5f, 0x00, 0xff, 0xff},
   106  	93:  color.RGBA{0x87, 0x00, 0xff, 0xff},
   107  	92:  color.RGBA{0x87, 0x00, 0xd7, 0xff},
   108  	91:  color.RGBA{0x87, 0x00, 0xaf, 0xff},
   109  	90:  color.RGBA{0x87, 0x00, 0x87, 0xff},
   110  	89:  color.RGBA{0x87, 0x00, 0x5f, 0xff},
   111  	88:  color.RGBA{0x87, 0x00, 0x00, 0xff},
   112  	99:  color.RGBA{0x87, 0x5f, 0xff, 0xff},
   113  	98:  color.RGBA{0x87, 0x5f, 0xd7, 0xff},
   114  	97:  color.RGBA{0x87, 0x5f, 0xaf, 0xff},
   115  	96:  color.RGBA{0x87, 0x5f, 0x87, 0xff},
   116  	95:  color.RGBA{0x87, 0x5f, 0x5f, 0xff},
   117  	94:  color.RGBA{0x87, 0x5f, 0x00, 0xff},
   118  	105: color.RGBA{0x87, 0x87, 0xff, 0xff},
   119  	104: color.RGBA{0x87, 0x87, 0xd7, 0xff},
   120  	103: color.RGBA{0x87, 0x87, 0xaf, 0xff},
   121  	102: color.RGBA{0x87, 0x87, 0x87, 0xff},
   122  	101: color.RGBA{0x87, 0x87, 0x5f, 0xff},
   123  	100: color.RGBA{0x87, 0x87, 0x00, 0xff},
   124  	111: color.RGBA{0x87, 0xaf, 0xff, 0xff},
   125  	110: color.RGBA{0x87, 0xaf, 0xd7, 0xff},
   126  	109: color.RGBA{0x87, 0xaf, 0xaf, 0xff},
   127  	108: color.RGBA{0x87, 0xaf, 0x87, 0xff},
   128  	107: color.RGBA{0x87, 0xaf, 0x5f, 0xff},
   129  	106: color.RGBA{0x87, 0xaf, 0x00, 0xff},
   130  	117: color.RGBA{0x87, 0xd7, 0xff, 0xff},
   131  	116: color.RGBA{0x87, 0xd7, 0xd7, 0xff},
   132  	115: color.RGBA{0x87, 0xd7, 0xaf, 0xff},
   133  	114: color.RGBA{0x87, 0xd7, 0x87, 0xff},
   134  	113: color.RGBA{0x87, 0xd7, 0x5f, 0xff},
   135  	112: color.RGBA{0x87, 0xd7, 0x00, 0xff},
   136  	123: color.RGBA{0x87, 0xff, 0xff, 0xff},
   137  	122: color.RGBA{0x87, 0xff, 0xd7, 0xff},
   138  	121: color.RGBA{0x87, 0xff, 0xaf, 0xff},
   139  	120: color.RGBA{0x87, 0xff, 0x87, 0xff},
   140  	119: color.RGBA{0x87, 0xff, 0x5f, 0xff},
   141  	118: color.RGBA{0x87, 0xff, 0x00, 0xff},
   142  	159: color.RGBA{0xaf, 0xff, 0xff, 0xff},
   143  	158: color.RGBA{0xaf, 0xff, 0xd7, 0xff},
   144  	157: color.RGBA{0xaf, 0xff, 0xaf, 0xff},
   145  	156: color.RGBA{0xaf, 0xff, 0x87, 0xff},
   146  	155: color.RGBA{0xaf, 0xff, 0x5f, 0xff},
   147  	154: color.RGBA{0xaf, 0xff, 0x00, 0xff},
   148  	153: color.RGBA{0xaf, 0xd7, 0xff, 0xff},
   149  	152: color.RGBA{0xaf, 0xd7, 0xd7, 0xff},
   150  	151: color.RGBA{0xaf, 0xd7, 0xaf, 0xff},
   151  	150: color.RGBA{0xaf, 0xd7, 0x87, 0xff},
   152  	149: color.RGBA{0xaf, 0xd7, 0x5f, 0xff},
   153  	148: color.RGBA{0xaf, 0xd7, 0x00, 0xff},
   154  	147: color.RGBA{0xaf, 0xaf, 0xff, 0xff},
   155  	146: color.RGBA{0xaf, 0xaf, 0xd7, 0xff},
   156  	145: color.RGBA{0xaf, 0xaf, 0xaf, 0xff},
   157  	144: color.RGBA{0xaf, 0xaf, 0x87, 0xff},
   158  	143: color.RGBA{0xaf, 0xaf, 0x5f, 0xff},
   159  	142: color.RGBA{0xaf, 0xaf, 0x00, 0xff},
   160  	141: color.RGBA{0xaf, 0x87, 0xff, 0xff},
   161  	140: color.RGBA{0xaf, 0x87, 0xd7, 0xff},
   162  	139: color.RGBA{0xaf, 0x87, 0xaf, 0xff},
   163  	138: color.RGBA{0xaf, 0x87, 0x87, 0xff},
   164  	137: color.RGBA{0xaf, 0x87, 0x5f, 0xff},
   165  	136: color.RGBA{0xaf, 0x87, 0x00, 0xff},
   166  	135: color.RGBA{0xaf, 0x5f, 0xff, 0xff},
   167  	134: color.RGBA{0xaf, 0x5f, 0xd7, 0xff},
   168  	133: color.RGBA{0xaf, 0x5f, 0xaf, 0xff},
   169  	132: color.RGBA{0xaf, 0x5f, 0x87, 0xff},
   170  	131: color.RGBA{0xaf, 0x5f, 0x5f, 0xff},
   171  	130: color.RGBA{0xaf, 0x5f, 0x00, 0xff},
   172  	129: color.RGBA{0xaf, 0x00, 0xff, 0xff},
   173  	128: color.RGBA{0xaf, 0x00, 0xd7, 0xff},
   174  	127: color.RGBA{0xaf, 0x00, 0xaf, 0xff},
   175  	126: color.RGBA{0xaf, 0x00, 0x87, 0xff},
   176  	125: color.RGBA{0xaf, 0x00, 0x5f, 0xff},
   177  	124: color.RGBA{0xaf, 0x00, 0x00, 0xff},
   178  	160: color.RGBA{0xd7, 0x00, 0x00, 0xff},
   179  	161: color.RGBA{0xd7, 0x00, 0x5f, 0xff},
   180  	162: color.RGBA{0xd7, 0x00, 0x87, 0xff},
   181  	163: color.RGBA{0xd7, 0x00, 0xaf, 0xff},
   182  	164: color.RGBA{0xd7, 0x00, 0xd7, 0xff},
   183  	165: color.RGBA{0xd7, 0x00, 0xff, 0xff},
   184  	166: color.RGBA{0xd7, 0x5f, 0x00, 0xff},
   185  	167: color.RGBA{0xd7, 0x5f, 0x5f, 0xff},
   186  	168: color.RGBA{0xd7, 0x5f, 0x87, 0xff},
   187  	169: color.RGBA{0xd7, 0x5f, 0xaf, 0xff},
   188  	170: color.RGBA{0xd7, 0x5f, 0xd7, 0xff},
   189  	171: color.RGBA{0xd7, 0x5f, 0xff, 0xff},
   190  	172: color.RGBA{0xd7, 0x87, 0x00, 0xff},
   191  	173: color.RGBA{0xd7, 0x87, 0x5f, 0xff},
   192  	174: color.RGBA{0xd7, 0x87, 0x87, 0xff},
   193  	175: color.RGBA{0xd7, 0x87, 0xaf, 0xff},
   194  	176: color.RGBA{0xd7, 0x87, 0xd7, 0xff},
   195  	177: color.RGBA{0xd7, 0x87, 0xff, 0xff},
   196  	178: color.RGBA{0xdf, 0xaf, 0x00, 0xff},
   197  	179: color.RGBA{0xdf, 0xaf, 0x5f, 0xff},
   198  	180: color.RGBA{0xdf, 0xaf, 0x87, 0xff},
   199  	181: color.RGBA{0xdf, 0xaf, 0xaf, 0xff},
   200  	182: color.RGBA{0xdf, 0xaf, 0xdf, 0xff},
   201  	183: color.RGBA{0xdf, 0xaf, 0xff, 0xff},
   202  	184: color.RGBA{0xdf, 0xdf, 0x00, 0xff},
   203  	185: color.RGBA{0xdf, 0xdf, 0x5f, 0xff},
   204  	186: color.RGBA{0xdf, 0xdf, 0x87, 0xff},
   205  	187: color.RGBA{0xdf, 0xdf, 0xaf, 0xff},
   206  	188: color.RGBA{0xdf, 0xdf, 0xdf, 0xff},
   207  	189: color.RGBA{0xdf, 0xdf, 0xff, 0xff},
   208  	190: color.RGBA{0xdf, 0xff, 0x00, 0xff},
   209  	191: color.RGBA{0xdf, 0xff, 0x5f, 0xff},
   210  	192: color.RGBA{0xdf, 0xff, 0x87, 0xff},
   211  	193: color.RGBA{0xdf, 0xff, 0xaf, 0xff},
   212  	194: color.RGBA{0xdf, 0xff, 0xdf, 0xff},
   213  	195: color.RGBA{0xdf, 0xff, 0xff, 0xff},
   214  	226: color.RGBA{0xff, 0xff, 0x00, 0xff},
   215  	227: color.RGBA{0xff, 0xff, 0x5f, 0xff},
   216  	228: color.RGBA{0xff, 0xff, 0x87, 0xff},
   217  	229: color.RGBA{0xff, 0xff, 0xaf, 0xff},
   218  	230: color.RGBA{0xff, 0xff, 0xdf, 0xff},
   219  	231: color.RGBA{0xff, 0xff, 0xff, 0xff},
   220  	220: color.RGBA{0xff, 0xdf, 0x00, 0xff},
   221  	221: color.RGBA{0xff, 0xdf, 0x5f, 0xff},
   222  	222: color.RGBA{0xff, 0xdf, 0x87, 0xff},
   223  	223: color.RGBA{0xff, 0xdf, 0xaf, 0xff},
   224  	224: color.RGBA{0xff, 0xdf, 0xdf, 0xff},
   225  	225: color.RGBA{0xff, 0xdf, 0xff, 0xff},
   226  	214: color.RGBA{0xff, 0xaf, 0x00, 0xff},
   227  	215: color.RGBA{0xff, 0xaf, 0x5f, 0xff},
   228  	216: color.RGBA{0xff, 0xaf, 0x87, 0xff},
   229  	217: color.RGBA{0xff, 0xaf, 0xaf, 0xff},
   230  	218: color.RGBA{0xff, 0xaf, 0xdf, 0xff},
   231  	219: color.RGBA{0xff, 0xaf, 0xff, 0xff},
   232  	208: color.RGBA{0xff, 0x87, 0x00, 0xff},
   233  	209: color.RGBA{0xff, 0x87, 0x5f, 0xff},
   234  	210: color.RGBA{0xff, 0x87, 0x87, 0xff},
   235  	211: color.RGBA{0xff, 0x87, 0xaf, 0xff},
   236  	212: color.RGBA{0xff, 0x87, 0xdf, 0xff},
   237  	213: color.RGBA{0xff, 0x87, 0xff, 0xff},
   238  	202: color.RGBA{0xff, 0x5f, 0x00, 0xff},
   239  	203: color.RGBA{0xff, 0x5f, 0x5f, 0xff},
   240  	204: color.RGBA{0xff, 0x5f, 0x87, 0xff},
   241  	205: color.RGBA{0xff, 0x5f, 0xaf, 0xff},
   242  	206: color.RGBA{0xff, 0x5f, 0xdf, 0xff},
   243  	207: color.RGBA{0xff, 0x5f, 0xff, 0xff},
   244  	196: color.RGBA{0xff, 0x00, 0x00, 0xff},
   245  	197: color.RGBA{0xff, 0x00, 0x5f, 0xff},
   246  	198: color.RGBA{0xff, 0x00, 0x87, 0xff},
   247  	199: color.RGBA{0xff, 0x00, 0xaf, 0xff},
   248  	200: color.RGBA{0xff, 0x00, 0xdf, 0xff},
   249  	201: color.RGBA{0xff, 0x00, 0xff, 0xff},
   250  
   251  	// Grayscale block
   252  	232: color.RGBA{0x08, 0x08, 0x08, 0xff},
   253  	233: color.RGBA{0x12, 0x12, 0x12, 0xff},
   254  	234: color.RGBA{0x1c, 0x1c, 0x1c, 0xff},
   255  	235: color.RGBA{0x26, 0x26, 0x26, 0xff},
   256  	236: color.RGBA{0x30, 0x30, 0x30, 0xff},
   257  	237: color.RGBA{0x3a, 0x3a, 0x3a, 0xff},
   258  	238: color.RGBA{0x44, 0x44, 0x44, 0xff},
   259  	239: color.RGBA{0x4e, 0x4e, 0x4e, 0xff},
   260  	240: color.RGBA{0x58, 0x58, 0x58, 0xff},
   261  	241: color.RGBA{0x62, 0x62, 0x62, 0xff},
   262  	242: color.RGBA{0x6c, 0x6c, 0x6c, 0xff},
   263  	243: color.RGBA{0x76, 0x76, 0x76, 0xff},
   264  	255: color.RGBA{0xee, 0xee, 0xee, 0xff},
   265  	254: color.RGBA{0xe4, 0xe4, 0xe4, 0xff},
   266  	253: color.RGBA{0xda, 0xda, 0xda, 0xff},
   267  	252: color.RGBA{0xd0, 0xd0, 0xd0, 0xff},
   268  	251: color.RGBA{0xc6, 0xc6, 0xc6, 0xff},
   269  	250: color.RGBA{0xbc, 0xbc, 0xbc, 0xff},
   270  	249: color.RGBA{0xb2, 0xb2, 0xb2, 0xff},
   271  	248: color.RGBA{0xa8, 0xa8, 0xa8, 0xff},
   272  	247: color.RGBA{0x9e, 0x9e, 0x9e, 0xff},
   273  	246: color.RGBA{0x94, 0x94, 0x94, 0xff},
   274  	245: color.RGBA{0x8a, 0x8a, 0x8a, 0xff},
   275  	244: color.RGBA{0x80, 0x80, 0x80, 0xff},
   276  }
   277  
   278  var (
   279  	// ErrorEmptyHexStr is returned by FromHexStr when an empty hex string is provided
   280  	ErrorEmptyHexStr = errors.New("Empty hex string provided")
   281  
   282  	// ErrorHexParse is returned by FromHexStr when an invalid hex string is provided
   283  	ErrorHexParse = errors.New("Failed to parse string as hex; try something like #CC66FF")
   284  )
   285  
   286  // Convert a 32 bit color to a color.RGBA
   287  func intToRGBA(c uint32) color.RGBA {
   288  	r := uint8((c >> 24) & 0xff)
   289  	g := uint8((c >> 16) & 0xff)
   290  	b := uint8((c >> 8) & 0xff)
   291  	a := uint8(c & 0xff)
   292  	return color.RGBA{r, g, b, a}
   293  }
   294  
   295  // FromColor finds the closest xterm colour to a given color.Color
   296  func FromColor(target color.Color) uint8 {
   297  
   298  	return uint8(Colors.Index(target))
   299  }
   300  
   301  // FromInt finds the closest xterm color to a given 32 bit RGBA color (e.g. 0xff00ff00).
   302  func FromInt(target uint32) uint8 {
   303  	return FromColor(intToRGBA(target))
   304  }
   305  
   306  // FromHexStr finds the closest xterm color to a given 24 bit hex string, e.g. "#CC66FF" or "FEFEFE"
   307  // It's mostly useful if you're used to specifying colours as hex in CSS etc
   308  func FromHexStr(str string) (uint8, error) {
   309  	if len(str) == 0 {
   310  		return 0, ErrorEmptyHexStr
   311  	}
   312  
   313  	if str[0] == '#' {
   314  		str = str[1:]
   315  	}
   316  	v, err := strconv.ParseUint(str, 16, 24)
   317  	if err != nil {
   318  		return 0, ErrorHexParse
   319  	}
   320  	return FromInt(uint32((v << 8) + 0xFF)), nil
   321  }