A Python module for formatting text with ANSI escape codes.
Project description
fansi_text
A Python module for formatting text with ANSI escape codes.
Installation
pip install fansi_text
Usage
from fansi_text import Red
print(Red("Red text"))
from fansi_text import RGBColor
print(RGBColor("RGB Text", 200, 130, 60))
You can also form complex combinations of overlapping effects.
import fansi_text as ft
print(
ft.Bold("Bold, " +
ft.Green("green and bold. ")) +
"Then normal text. Then " +
ft.Underline(ft.Overline("under and over lined. ")) +
"Next " +
ft.Italic("italics. Add " +
ft.Yellow("yellow " +
ft.Bold("and bold too! ") +
"Then back to yellow and italics, ") +
"then just italics, ") +
"and finally back to normal."
)
A demo_all method is provided to allow for testing all supported colours and effects in your terminal.
import fansi_text as ft
ft.demo_all()
The full list of colours and effects are shown below (notes per Wikipedia). Note that support for each code varies between terminals.
| ANSI Code | Name | Example | Note |
|---|---|---|---|
| 0 | Reset | All attributes become turned off | |
| 1 | Bold | Bold Text | As with faint, the color change is a PC (SCO / CGA) invention. |
| 2 | Faint | Faint Text | May be implemented as a light font weight like bold. |
| 3 | Italic | Italic Text | Not widely supported. Sometimes treated as inverse or blink. |
| 4 | Underline | Underlined Text | Style extensions exist for Kitty, VTE, mintty, iTerm2 and Konsole. |
| 5 | SlowBlink | (Example not supported in README) | Sets blinking to less than 150 times per minute |
| 6 | FastBlink | (Example not supported in README) | MS-DOS ANSI.SYS, 150+ per minute; not widely supported |
| 7 | Invert | Inverted | Swap foreground and background colors; inconsistent emulation |
| 8 | Conceal | Not widely supported. | |
| 9 | Strikethrough | Characters legible but marked as if for deletion. Not supported in Terminal.app. | |
| 10 | Font0 | - | Default Font |
| 11 | Font1 | - | Select alternative font n − 10 |
| 12 | Font2 | - | Select alternative font n − 10 |
| 13 | Font3 | - | Select alternative font n − 10 |
| 14 | Font4 | - | Select alternative font n − 10 |
| 15 | Font5 | - | Select alternative font n − 10 |
| 16 | Font6 | - | Select alternative font n − 10 |
| 17 | Font7 | - | Select alternative font n − 10 |
| 18 | Font8 | - | Select alternative font n − 10 |
| 19 | Font9 | - | Select alternative font n − 10 |
| 20 | FrakturFont | (Example not supported in README) | Rarely supported |
| 21 | DoubleUnderlined | Double Underline | Double-underline per ECMA-48 but often disables bold intensity. |
| 26 | ProportionalSpacing | - | ITU T.61 and T.416, not known to be used on terminals |
| 30 | Black | Black Text | Set text colour to black |
| 31 | Red | Red Text | Set text colour to red |
| 32 | Green | Green Text | Set text colour to green |
| 33 | Yellow | Yellow Text | Set text colour to yellow |
| 34 | Blue | Blue Text | Set text colour to blue |
| 35 | Magenta | Magenta Text | Set text colour to magenta |
| 36 | Cyan | Cyan Text | Set text colour to cyan |
| 37 | White | White Text | Set text colour to white |
| 38 | RGBColor | RGBColor(172,100,112) | Use with parameters e.g. RGBColor('Text', 200, 130, 60) |
| 40 | BgBlack | Text | Set black background |
| 41 | BgRed | Text | Set red background |
| 42 | BgGreen | Text | Set green background |
| 43 | BgYellow | Text | Set yellow background |
| 44 | BgBlue | Text | Set blue background |
| 45 | BgMagenta | Text | Set magenta background |
| 46 | BgCyan | Text | Set cyan background |
| 47 | BgWhite | Text | Set white background |
| 48 | RGBBgColor | RGBBgColor(172,100,112) | Use with parameters e.g. RBGBgColor('Text', 200, 130, 60) |
| 51 | Framed | Framed Text | Implemented as "emoji variation selector" in mintty. |
| 52 | Encircled | Encircled Text | |
| 53 | Overlined | Overlined Text | Not supported in Terminal.app |
| 58 | UnderlineColor | (Example not supported in README) | Not in standard; implemented in Kitty, VTE, mintty, and iTerm2. Next arguments are 5;n or 2;r;g;b. |
| 60–64 | Ideogram effects | (Example not supported in README) | Rarely supported |
| 73 | Superscript | Superscript | Implemented only in mintty |
| 74 | Subscript | Subscript | |
| 90 | BrightBlack | Bright Black Text | Set text colour to bright black (gray) |
| 91 | BrightRed | Bright Red Text | Set text colour to bright red |
| 92 | BrightGreen | Bright Green Text | Set text colour to bright green |
| 93 | BrightYellow | Bright Yellow Text | Set text colour to bright yellow |
| 94 | BrightBlue | Bright Blue Text | Set text colour to bright blue |
| 95 | BrightMagenta | Bright Magenta Text | Set text colour to bright magenta |
| 96 | BrightCyan | Bright Cyan Text | Set text colour to bright cyan |
| 97 | BrightWhite | Bright White Text | Set text colour to bright white |
| 100 | BgBrightBlack | Bright Black Background | Set bright black (gray) background |
| 101 | BgBrightRed | Bright Red Background | Set bright red background |
| 102 | BgBrightGreen | Bright Green Background | Set bright green background |
| 103 | BgBrightYellow | Bright Yellow Background | Set bright yellow background |
| 104 | BgBrightBlue | Bright Blue Background | Set bright blue background |
| 105 | BgBrightMagenta | Bright Magenta Background | Set bright magenta background |
| 106 | BgBrightCyan | Bright Cyan Background | Set bright cyan background |
| 107 | BgBrightWhite | Bright White Background | Set bright white background |
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fansi_text-0.1.2.tar.gz.
File metadata
- Download URL: fansi_text-0.1.2.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
71feed056ea23626b93397d05deca1b178ab80f8428c4fc273bd39d682864553
|
|
| MD5 |
192810eaa595d4091126c0086346b999
|
|
| BLAKE2b-256 |
8bde5c193f6767b9c311e8d66cdd9e8766bf7d2cfab583bc53e92863f5add492
|
File details
Details for the file fansi_text-0.1.2-py3-none-any.whl.
File metadata
- Download URL: fansi_text-0.1.2-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ae19efafdb8ec66ee2857900e0aa6115e70f10140c75d1cfc62858e495a028d6
|
|
| MD5 |
73e78cbbaccffe8ae71ab32f90cd0e30
|
|
| BLAKE2b-256 |
59ca4489a57f4d008c046605e5b0f669842f1ae1f8f9933a53f02b00bc5c2f18
|