| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,250 @@ |
| 1 |
+# Following Vim's dark/light naming convention. |
|
| 2 |
+COLOR_DARKBLACK=0 |
|
| 3 |
+COLOR_DARKRED=1 |
|
| 4 |
+COLOR_DARKGREEN=2 |
|
| 5 |
+COLOR_DARKYELLOW=3 |
|
| 6 |
+COLOR_DARKBLUE=4 |
|
| 7 |
+COLOR_DARKMAGENTA=5 |
|
| 8 |
+COLOR_DARKCYAN=6 |
|
| 9 |
+COLOR_DARKWHITE=7 |
|
| 10 |
+COLOR_LIGHTBLACK=8 |
|
| 11 |
+COLOR_LIGHTRED=9 |
|
| 12 |
+COLOR_LIGHTGREEN=10 |
|
| 13 |
+COLOR_LIGHTYELLOW=11 |
|
| 14 |
+COLOR_LIGHTBLUE=12 |
|
| 15 |
+COLOR_LIGHTMAGENTA=13 |
|
| 16 |
+COLOR_LIGHTCYAN=14 |
|
| 17 |
+COLOR_LIGHTWHITE=15 |
|
| 18 |
+# Default to light. |
|
| 19 |
+COLOR_BLACK="$COLORS_LIGHTBLACK" |
|
| 20 |
+COLOR_RED="$COLORS_LIGHTRED" |
|
| 21 |
+COLOR_GREEN="$COLORS_LIGHTGREEN" |
|
| 22 |
+COLOR_YELLOW="$COLORS_LIGHTYELLOW" |
|
| 23 |
+COLOR_BLUE="$COLORS_LIGHTBLUE" |
|
| 24 |
+COLOR_MAGENTA="$COLORS_LIGHTMAGENTA" |
|
| 25 |
+COLOR_CYAN="$COLORS_LIGHTCYAN" |
|
| 26 |
+COLOR_WHITE="$COLORS_LIGHTWHITE" |
|
| 27 |
+ |
|
| 28 |
+__color_enabled="$(command -v tput)" |
|
| 29 |
+__color_count="$([ "$__color_enabled" ] && tput colors || echo 0)" |
|
| 30 |
+ |
|
| 31 |
+__color_test_put() |
|
| 32 |
+{
|
|
| 33 |
+ [ "$__color_enabled" ] || return 0 |
|
| 34 |
+ for __color |
|
| 35 |
+ do |
|
| 36 |
+ if [ $__color_count -lt 16 ] && [ $__color -ge 8 ] |
|
| 37 |
+ then |
|
| 38 |
+ __color=$((__color - 8)) |
|
| 39 |
+ tput bold |
|
| 40 |
+ fi |
|
| 41 |
+ tput setaf "$__color" |
|
| 42 |
+ printf '%s' '██' |
|
| 43 |
+ tput sgr0 |
|
| 44 |
+ done |
|
| 45 |
+} |
|
| 46 |
+ |
|
| 47 |
+__color_test() |
|
| 48 |
+{
|
|
| 49 |
+ __color_test_put 0 |
|
| 50 |
+ __color_test_put $(seq 1 6) |
|
| 51 |
+ __color_test_put 7 |
|
| 52 |
+ printf '\n' |
|
| 53 |
+ __color_test_put 8 |
|
| 54 |
+ __color_test_put $(seq 9 14) |
|
| 55 |
+ __color_test_put 15 |
|
| 56 |
+ printf '\n' |
|
| 57 |
+} |
|
| 58 |
+ |
|
| 59 |
+__color_test1() |
|
| 60 |
+{
|
|
| 61 |
+ __color_test_put 0 |
|
| 62 |
+ printf '\n' |
|
| 63 |
+ __color_test_put 8 |
|
| 64 |
+ printf '\n' |
|
| 65 |
+ __color_test_put 7 |
|
| 66 |
+ __color_test_put $(seq 1 6) |
|
| 67 |
+ printf '\n' |
|
| 68 |
+ __color_test_put 15 |
|
| 69 |
+ __color_test_put $(seq 9 14) |
|
| 70 |
+ printf '\n' |
|
| 71 |
+} |
|
| 72 |
+ |
|
| 73 |
+__color_test2() |
|
| 74 |
+{
|
|
| 75 |
+ __color_test_put 0 |
|
| 76 |
+ printf '\n' |
|
| 77 |
+ __color_test_put 8 |
|
| 78 |
+ __color_test_put $(seq 1 6) |
|
| 79 |
+ printf '\n' |
|
| 80 |
+ __color_test_put 7 |
|
| 81 |
+ printf '\n' |
|
| 82 |
+ __color_test_put 15 |
|
| 83 |
+ __color_test_put $(seq 9 14) |
|
| 84 |
+ printf '\n' |
|
| 85 |
+} |
|
| 86 |
+ |
|
| 87 |
+__color_format() |
|
| 88 |
+{
|
|
| 89 |
+ for __color |
|
| 90 |
+ do |
|
| 91 |
+ # Same as `ceil(__color/0xff*1000)`. |
|
| 92 |
+ printf '%s\n' "$(((__color * 1000 + 0xfe) / 0xff))" |
|
| 93 |
+ done |
|
| 94 |
+} |
|
| 95 |
+ |
|
| 96 |
+# `terminfo` does not define capabilities for setting the default foreground |
|
| 97 |
+# and background colors, so if the terminal supports at least 16 colors we use |
|
| 98 |
+# OSC 10/11 directly and hope for the best. This causes `tmux` to explicitly |
|
| 99 |
+# render the background color, which causes issues with transparency. This also |
|
| 100 |
+# causes Vim's `:terminal` to interpret the escape character as an escape key |
|
| 101 |
+# press which puts readline in vi command mode. Therefore we only do this if |
|
| 102 |
+# we're a login shell. |
|
| 103 |
+__color_set_fg() |
|
| 104 |
+{
|
|
| 105 |
+ [ -z "$TMUX" ] || return 0 |
|
| 106 |
+ [ -z "$VIM" ] || return 0 |
|
| 107 |
+ # [ "$__color_count" -ge 16 ] || return 0 |
|
| 108 |
+ # case "$0" in |
|
| 109 |
+ # -*) break ;; |
|
| 110 |
+ # *) return 0 ;; |
|
| 111 |
+ # esac |
|
| 112 |
+ printf '\33]10;rgb:%02x/%02x/%02x\33\\' "$@" |
|
| 113 |
+} |
|
| 114 |
+__color_set_bg() |
|
| 115 |
+{
|
|
| 116 |
+ [ -z "$TMUX" ] || return 0 |
|
| 117 |
+ [ -z "$VIM" ] || return 0 |
|
| 118 |
+ # [ "$__color_count" -ge 16 ] || return 0 |
|
| 119 |
+ # case "$0" in |
|
| 120 |
+ # -*) break ;; |
|
| 121 |
+ # *) return 0 ;; |
|
| 122 |
+ # esac |
|
| 123 |
+ printf '\33]11;rgb:%02x/%02x/%02x\33\\' "$@" |
|
| 124 |
+} |
|
| 125 |
+ |
|
| 126 |
+__color_set() |
|
| 127 |
+{
|
|
| 128 |
+ [ "$__color_enabled" ] || return 0 |
|
| 129 |
+ __color=$((0)) |
|
| 130 |
+ while read -r __color_r __color_g __color_b __color_comment |
|
| 131 |
+ do |
|
| 132 |
+ [ "$__color_r" ] || continue |
|
| 133 |
+ # Palette. |
|
| 134 |
+ tput initc "$((__color))" $(__color_format \ |
|
| 135 |
+ "$__color_r" \ |
|
| 136 |
+ "$__color_g" \ |
|
| 137 |
+ "$__color_b" |
|
| 138 |
+ ) |
|
| 139 |
+ # Background (color 0, to match the Linux console). |
|
| 140 |
+ if [ "$__color" -eq 0 ] |
|
| 141 |
+ then |
|
| 142 |
+ __color_set_bg \ |
|
| 143 |
+ "$__color_r" \ |
|
| 144 |
+ "$__color_g" \ |
|
| 145 |
+ "$__color_b" |
|
| 146 |
+ fi |
|
| 147 |
+ # Foreground (color 7, to match the Linux console). |
|
| 148 |
+ if [ "$__color" -eq 7 ] |
|
| 149 |
+ then |
|
| 150 |
+ __color_set_fg \ |
|
| 151 |
+ "$__color_r" \ |
|
| 152 |
+ "$__color_g" \ |
|
| 153 |
+ "$__color_b" |
|
| 154 |
+ fi |
|
| 155 |
+ __color=$((__color + 1)) |
|
| 156 |
+ done |
|
| 157 |
+} |
|
| 158 |
+ |
|
| 159 |
+__color_set_uniform_hard_linear() |
|
| 160 |
+{
|
|
| 161 |
+ # https://notes.rcrnstn.net/colors.md |
|
| 162 |
+ # hard-linear |
|
| 163 |
+ echo ' |
|
| 164 |
+ 0x00 0x00 0x00 Black |
|
| 165 |
+ 0xa4 0x6a 0x6a Red |
|
| 166 |
+ 0x4e 0x86 0x56 Green |
|
| 167 |
+ 0x87 0x79 0x40 Yellow |
|
| 168 |
+ 0x64 0x7a 0xa4 Blue |
|
| 169 |
+ 0x9c 0x68 0x98 Magenta |
|
| 170 |
+ 0x07 0x87 0x88 Cyan |
|
| 171 |
+ 0x79 0x79 0x79 White |
|
| 172 |
+ 0x3e 0x3e 0x3e Bright Black |
|
| 173 |
+ 0xff 0xa6 0xa7 Bright Red |
|
| 174 |
+ 0x7b 0xd1 0x88 Bright Green |
|
| 175 |
+ 0xd3 0xbe 0x67 Bright Yellow |
|
| 176 |
+ 0x9d 0xbf 0xff Bright Blue |
|
| 177 |
+ 0xf3 0xa3 0xec Bright Magenta |
|
| 178 |
+ 0x00 0xd3 0xd4 Bright Cyan |
|
| 179 |
+ 0xbe 0xbe 0xbe Bright White |
|
| 180 |
+ ' | __color_set |
|
| 181 |
+} |
|
| 182 |
+ |
|
| 183 |
+__color_set_twisted1() |
|
| 184 |
+{
|
|
| 185 |
+ echo ' |
|
| 186 |
+ 0x00 0x00 0x00 Black |
|
| 187 |
+ 0x9a 0x6a 0x4b Red |
|
| 188 |
+ 0x08 0x84 0x65 Green |
|
| 189 |
+ 0x6d 0x7b 0x32 Yellow |
|
| 190 |
+ 0x7d 0x6b 0xa4 Blue |
|
| 191 |
+ 0xa4 0x5e 0x83 Magenta |
|
| 192 |
+ 0x08 0x80 0x95 Cyan |
|
| 193 |
+ 0x75 0x75 0x75 White |
|
| 194 |
+ 0x3b 0x3b 0x3b BrightBlack |
|
| 195 |
+ 0xee 0xa6 0x77 BrightRed |
|
| 196 |
+ 0x09 0xce 0x9e BrightGreen |
|
| 197 |
+ 0xab 0xbf 0x51 BrightYellow |
|
| 198 |
+ 0xc3 0xa8 0xfd BrightBlue |
|
| 199 |
+ 0xfe 0x94 0xcd BrightMagenta |
|
| 200 |
+ 0x07 0xc7 0xe8 BrightCyan |
|
| 201 |
+ 0xb6 0xb6 0xb6 BrightWhite |
|
| 202 |
+ ' | __color_set |
|
| 203 |
+} |
|
| 204 |
+ |
|
| 205 |
+__color_set_twisted2() |
|
| 206 |
+{
|
|
| 207 |
+ echo ' |
|
| 208 |
+ 0x00 0x00 0x00 Black |
|
| 209 |
+ 0xa4 0x5e 0x83 Red |
|
| 210 |
+ 0x6d 0x7b 0x32 Green |
|
| 211 |
+ 0x9a 0x6a 0x4b Yellow |
|
| 212 |
+ 0x08 0x80 0x95 Blue |
|
| 213 |
+ 0x7d 0x6b 0xa4 Magenta |
|
| 214 |
+ 0x08 0x84 0x65 Cyan |
|
| 215 |
+ 0x75 0x75 0x75 White |
|
| 216 |
+ 0x3b 0x3b 0x3b BrightBlack |
|
| 217 |
+ 0xfe 0x94 0xcd BrightRed |
|
| 218 |
+ 0xab 0xbf 0x51 BrightGreen |
|
| 219 |
+ 0xee 0xa6 0x77 BrightYellow |
|
| 220 |
+ 0x07 0xc7 0xe8 BrightBlue |
|
| 221 |
+ 0xc3 0xa8 0xfd BrightMagenta |
|
| 222 |
+ 0x09 0xce 0x9e BrightCyan |
|
| 223 |
+ 0xb6 0xb6 0xb6 BrightWhite |
|
| 224 |
+ ' | __color_set |
|
| 225 |
+} |
|
| 226 |
+ |
|
| 227 |
+__color_set_alacritty() |
|
| 228 |
+{
|
|
| 229 |
+ # https://github.com/alacritty/alacritty/blob/master/extra/man/alacritty.5.scd#colors |
|
| 230 |
+ echo ' |
|
| 231 |
+ 0x0f 0x0f 0x0f Black |
|
| 232 |
+ 0x71 0x2b 0x2b Red |
|
| 233 |
+ 0x5f 0x6f 0x3a Green |
|
| 234 |
+ 0xa1 0x7e 0x4d Yellow |
|
| 235 |
+ 0x45 0x68 0x77 Blue |
|
| 236 |
+ 0x70 0x4d 0x68 Magenta |
|
| 237 |
+ 0x4d 0x77 0x70 Cyan |
|
| 238 |
+ 0x8e 0x8e 0x8e White |
|
| 239 |
+ 0x6b 0x6b 0x6b Bright Black |
|
| 240 |
+ 0xc5 0x55 0x55 Bright Red |
|
| 241 |
+ 0xaa 0xc4 0x74 Bright Green |
|
| 242 |
+ 0xfe 0xca 0x88 Bright Yellow |
|
| 243 |
+ 0x82 0xb8 0xc8 Bright Blue |
|
| 244 |
+ 0xc2 0x8c 0xb8 Bright Magenta |
|
| 245 |
+ 0x93 0xd3 0xc3 Bright Cyan |
|
| 246 |
+ 0xf8 0xf8 0xf8 Bright White |
|
| 247 |
+ ' | __color_set |
|
| 248 |
+} |
|
| 249 |
+ |
|
| 250 |
+__color_set_uniform_hard_linear |