ansi_escape/doc/color.md

50 lines
1.5 KiB
Markdown
Raw Normal View History

2021-03-12 21:33:18 +00:00
Color
=====
256 8-bit colors
----------------
```python
print(ansi_escape.color("fg", "red") + "red text")
```
Makes the color of the text itself (aka the foreground color) red.
```python
print(ansi_escape.color("bg", "bright-cyan") + "bright cyan text background")
```
This will make the background color bright cyan.
ansi_escape.color() also supports the numbers 0-255 [here is a list explaining each number.](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit)
```python
print(ansi_escape.color("bg", 33) + "text")
```
You can also use the following human readable names insteead of 0-16:
| Instead of | Use |
| ---------: | :------------- |
| 0|"black" |
| 1|"red" |
| 2|"green" |
| 3|"yellow" |
| 4|"blue" |
| 5|"magenta" |
| 6|"cyan" |
| 7|"white" |
| 8|"bright-black" |
| 9|"bright-red" |
| 10|"bright-green" |
| 11|"bright-yellow" |
| 12|"bright-blue" |
| 13|"bright-magenta"|
| 14|"bright-cyan" |
| 15|"bright-white" |
24-bit True Color
-----------------
To do this provide ansi_escape.color() with "fg" or "bg" + 3 comma reperated values for r, g, and b respectivley, each rgb value can be a number between 0-255.
```python
print(ansi_escape.color("bg", 128, 0, 255) + "bg for background color")
print(ansi_escape.color("fg", 255, 69, 128) + "fg for foreground color")
```