117 lines
4.9 KiB
Markdown
117 lines
4.9 KiB
Markdown
![]() |
---
|
||
|
title: color
|
||
|
description:
|
||
|
published: true
|
||
|
date: 2023-04-28T02:38:18.678Z
|
||
|
tags:
|
||
|
editor: markdown
|
||
|
dateCreated: 2023-04-28T02:22:37.379Z
|
||
|
---
|
||
|
|
||
|
# Style and Colors in the terminal
|
||
|
who doesn't love Style and Colors?
|
||
|
|
||
|
---
|
||
|
## Style is a mixed bag in terms of support
|
||
|
Some things are rarely supported, but it won't hurt.
|
||
|
| Number | Style | Code | Disable | Support |
|
||
|
| ------ | ----- | ---- | ------- | ------- |
|
||
|
| 0 | Reset | "\e[0m" | | All |
|
||
|
| 1 | Bold | "\e[1m" | "\e[22m" | All |
|
||
|
| 2 | thin | "\e[2m" | "\e[22m" | Most |
|
||
|
| 3 | Cursive | "\e[3m" | "\e[23m" | Most |
|
||
|
| 4 | Underline | "\e[4m" | "\e[24m" | Most |
|
||
|
| 5 | Blinking Slow | "\e[5m" | "\e[25m" | Most |
|
||
|
| 6 | Blinking Fast | "\e[6m" | "\e[25m" | Some |
|
||
|
| 7 | Inverted Color | "\e[7m" | "\e[27m" | All |
|
||
|
| 8 | Conceal | "\e[8m" | "\e[28m" | Some |
|
||
|
| 9 | Striketrough | "\e[9m" | "\e[29m" | Most |
|
||
|
| 11-20 | Other Fonts | "\e[11-20m" | "\e[10m" | Most |
|
||
|
| 21 | Double Underline | "\e[21m" | "\e[24m" | Some |
|
||
|
| 26 | No Monospace | "\e[26m" | "\e[50m" | Some |
|
||
|
| 51 | Framed | "\e[51m" | "\e[54m" | Some |
|
||
|
| 52 | Circled | "\e[52m" | "\e[54m" | Some |
|
||
|
| 53 | Overline | "\e[53m" | "\e[55m" | Some |
|
||
|
|
||
|
---
|
||
|
## The 8 colors supported by all modern terminal emulators
|
||
|
3 bit color, a bit strange but every bit was valueable back then
|
||
|
| Number | Color | Foreground | Background |
|
||
|
| ------ | ----- | ---------- | ---------- |
|
||
|
| 0 | Black | "\e[30m" | "\e[40m" |
|
||
|
| 1 | Red | "\e[31m" | "\e[41m" |
|
||
|
| 2 | Green | "\e[32m" | "\e[42m" |
|
||
|
| 3 | Yellow | "\e[33m" | "\e[43m" |
|
||
|
| 4 | Blue | "\e[34m" | "\e[44m" |
|
||
|
| 5 | Magenta | "\e[35m" | "\e[45m" |
|
||
|
| 6 | Cyan | "\e[36m" | "\e[46m" |
|
||
|
| 7 | White | "\e[37m" | "\e[47m" |
|
||
|
| 9 | Reset | "\e[39m" | "\e[49m" |
|
||
|
|
||
|
---
|
||
|
## Combinations are supported by all modern terminal emulators
|
||
|
In general try to do style first, then color
|
||
|
| Code | Description |
|
||
|
| ---- | ----------- |
|
||
|
| "\e[0;0m" | Reset All |
|
||
|
| "\e[1;3m" | Bold and Cursive |
|
||
|
| "\e[30;44m" | Black letters on Blue background |
|
||
|
| "\e[1;30;47m" | Bold Black letters on White background |
|
||
|
| "\e[45;32m" | Green letters on Magenta Background |
|
||
|
| "\e[1;3;4;5m" | Bold Cursive Underlined and Blinking slow |
|
||
|
| "\e[2;9;31;46m" | Thin Striketrough Style with Red letters on Cyan background |
|
||
|
|
||
|
---
|
||
|
## Bright Colors are supported by most modern terminal emulators
|
||
|
4 bit color, With a added brighter variant of the 8 default colors
|
||
|
| Number | Color | Foreground | Background |
|
||
|
| ------ | ----- | ---------- | ---------- |
|
||
|
| 0 | Black | "\e[90m" | "\e[100m" |
|
||
|
| 1 | Red | "\e[91m" | "\e[101m" |
|
||
|
| 2 | Green | "\e[92m" | "\e[102m" |
|
||
|
| 3 | Yellow | "\e[93m" | "\e[103m" |
|
||
|
| 4 | Blue | "\e[94m" | "\e[104m" |
|
||
|
| 5 | Magenta | "\e[95m" | "\e[105m" |
|
||
|
| 6 | Cyan | "\e[96m" | "\e[106m" |
|
||
|
| 7 | White | "\e[97m" | "\e[107m" |
|
||
|
| 9 | Reset | "\e[39m" | "\e[49m" |
|
||
|
|
||
|
---
|
||
|
## 256 Colors are supported by most modern terminal emulators
|
||
|
8 bit color this is the most common among terminal emulators
|
||
|
0 to 15 are the 8 standard and 8 bright colors
|
||
|
16 to 231 are the extra colors
|
||
|
232 to 255 are some extra grayscale options
|
||
|
| Number | Foreground | Background | Underline |
|
||
|
| ------ | ---------- | ---------- | --------- |
|
||
|
| 0 | "\e[38;5;0m" | "\e[48;5;0m" | "\e[58;5;0m" |
|
||
|
| 1 | "\e[38;5;1m" | "\e[48;5;1m" | "\e[58;5;1m" |
|
||
|
| 2 | "\e[38;5;2m" | "\e[48;5;2m" | "\e[58;5;2m" |
|
||
|
| 3 | "\e[38;5;3m" | "\e[48;5;3m" | "\e[58;5;3m" |
|
||
|
| ... | "\e[38;5;...m" | "\e[48;5;...m" | "\e[58;5;...m" |
|
||
|
| 255 | "\e[38;5;255m" | "\e[48;5;255m" | "\e[58;5;255m" |
|
||
|
| Reset | "\e[39m" | "\e[49m" | "\e[59m" |
|
||
|
|
||
|
|
||
|
#### You can print all of the 256 colors using the following command
|
||
|
print "Basic 16 colors are part of the 256 colors"; for i in {0..15}; do print -Pn "%K{$i} %k%F{$i}${(l:3::0:)i}%f " ${${(M)$(($((i+1))%8))#0}:+"\n"}; done; print "The Extra Colors in 256 colors"; for i in {16..231}; do print -Pn "%K{$i} %k%F{$i}${(l:3::0:)i}%f " ${${(M)$(($((i-3))%12))#0}:+"\n"}; done; print "The Grayscale options in 256 colors"; for i in {232..255}; do print -Pn "%K{$i} %k%F{$i}${(l:3::0:)i}%f " ${${(M)$(($((i-3))%6))#0}:+"\n"}; done
|
||
|
|
||
|
---
|
||
|
## True Color is supported by some modern terminal emulators
|
||
|
24 bit color which is all the color we need for our puny little human eyes
|
||
|
You can replace any of the RGB values you want with your own custom colors
|
||
|
| Color | Foreground | Background | Underline |
|
||
|
| ----- | ---------- | ---------- | --------- |
|
||
|
| Black | "\e[38;2;0;0;0m" | "\e[48;2;0;0;0m" | "\e[58;2;0;0;0m" |
|
||
|
| Red | "\e[38;2;255;0;0m" | "\e[48;2;255;0;0m" | "\e[58;2;255;0;0m" |
|
||
|
| Green | "\e[38;2;0;255;0m" | "\e[48;2;0;255;0m" | "\e[58;2;0;255;0m" |
|
||
|
| Yellow | "\e[38;2;255;255;0m" | "\e[48;2;255;255;0m" | "\e[58;2;255;255;0m" |
|
||
|
| Blue | "\e[38;2;0;0;255m" | "\e[48;2;0;0;255m" | "\e[58;2;0;0;255m" |
|
||
|
| Magenta | "\e[38;2;255;0;255m" | "\e[48;2;255;0;255m" | "\e[58;2;255;0;255m" |
|
||
|
| Cyan | "\e[38;2;0;255;255m" | "\e[48;2;0;255;255m" | "\e[58;2;0;255;255m" |
|
||
|
| White | "\e[38;2;255;255;255m" | "\e[48;2;255;255;255m" | "\e[58;2;255;255;255m" |
|
||
|
| RGB | "\e[38;2;R;G;Bm" | "\e[48;2;R;G;Bm" | "\e[58;2;R;G;Bm" |
|
||
|
| Reset | "\e[39m" | "\e[49m" | "\e[59m" |
|
||
|
|
||
|
---
|