Skip to main content

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 Strikethrough Text 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

fansi_text-0.1.1.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fansi_text-0.1.1-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file fansi_text-0.1.1.tar.gz.

File metadata

  • Download URL: fansi_text-0.1.1.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

Hashes for fansi_text-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2562df44d7bae3f973ed0dfcab730b3b9ac89f821c8052ed5e978fce24a27926
MD5 75ca42db891b35cc65547d6cea4f9663
BLAKE2b-256 af2271ce16a4961ce16f2d3d2f3f971fc55923b75a9ede2eef6af41070cd5f0e

See more details on using hashes here.

File details

Details for the file fansi_text-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: fansi_text-0.1.1-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

Hashes for fansi_text-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 433dc7ae4f6287e34095d3e9ee6074bcf3a9b17cda418806bc6b33f82a47047a
MD5 4d29374e71be091453c8590b85833465
BLAKE2b-256 4a80d509ce1ca2eae351d36a55631c1ba75a6267daacb19f48c482c49fa0c516

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page