Target: colorama — cross-platform terminal color support for Python
Package: chromapaint on PyPI
License: MIT
Python: 3.9+
Dependencies: Zero
- 262 million monthly PyPI downloads — one of the most-downloaded Python packages
- 1.4 million dependent projects
- Last release: v0.4.6, October 2022 (3.5+ years ago)
- 108 open issues with no triage
- Both maintainers (tartley, wiggin15) appear inactive
- Still contains Python 2 compatibility code
- No type annotations
- No 256-color or true color (24-bit) support
- No terminal capability detection
- PyCharm-specific hacks in the codebase
chromapaint is a single-package Python library with three layers:
Public API (init/deinit/Fore/Back/Style/Cursor)
↓
Stream Wrapper (AnsiToWin32 → intercepts write() calls)
↓
Platform Backend
├── POSIX: pass-through (ANSI natively supported)
└── Windows: Win32 Console API via ctypes (legacy)
OR enable VT processing (modern Win10+)
On POSIX systems, colorama is essentially a no-op (ANSI codes pass through natively). On Windows, it either enables native VT processing (Win10 1511+) or falls back to translating ANSI escape codes into Win32 Console API calls via ctypes.
def init(autoreset=False, convert=None, strip=None, wrap=True) -> None
def deinit() -> None
def reinit() -> None
def just_fix_windows_console() -> None
@contextlib.contextmanager
def colorama_text(*args, **kwargs) -> Generatorinit() parameters:
autoreset— if True, automatically appendStyle.RESET_ALLafter eachwrite()convert— if True, force Win32 API conversion; if False, disable it; if None, auto-detectstrip— if True, strip ANSI codes from output; if False, don't; if None, auto-detectwrap— if True, replace sys.stdout/stderr with wrapped streams
just_fix_windows_console() — the recommended modern API. On Windows, enables native ANSI support if available, or falls back to stream wrapping. No-op on POSIX. Idempotent.
# Foreground colors
Fore.BLACK, Fore.RED, Fore.GREEN, Fore.YELLOW
Fore.BLUE, Fore.MAGENTA, Fore.CYAN, Fore.WHITE
Fore.RESET
Fore.LIGHTBLACK_EX, Fore.LIGHTRED_EX, Fore.LIGHTGREEN_EX, Fore.LIGHTYELLOW_EX
Fore.LIGHTBLUE_EX, Fore.LIGHTMAGENTA_EX, Fore.LIGHTCYAN_EX, Fore.LIGHTWHITE_EX
# Background colors
Back.BLACK, Back.RED, Back.GREEN, Back.YELLOW
Back.BLUE, Back.MAGENTA, Back.CYAN, Back.WHITE
Back.RESET
Back.LIGHTBLACK_EX, Back.LIGHTRED_EX, Back.LIGHTGREEN_EX, Back.LIGHTYELLOW_EX
Back.LIGHTBLUE_EX, Back.LIGHTMAGENTA_EX, Back.LIGHTCYAN_EX, Back.LIGHTWHITE_EX
# Style attributes
Style.BRIGHT, Style.DIM, Style.NORMAL, Style.RESET_ALL
# Cursor movement (methods, not constants)
Cursor.UP(n=1), Cursor.DOWN(n=1), Cursor.FORWARD(n=1), Cursor.BACK(n=1)
Cursor.POS(x=1, y=1)All Fore.*, Back.*, and Style.* attributes are ANSI escape code strings (e.g., Fore.RED == '\033[31m').
def code_to_chars(code: int) -> str # SGR code → ANSI string
def set_title(title: str) -> str # OSC title-set string
def clear_screen(mode: int = 2) -> str # ED (Erase in Display)
def clear_line(mode: int = 2) -> str # EL (Erase in Line)class AnsiToWin32:
ANSI_CSI_RE: re.Pattern # CSI sequence regex
ANSI_OSC_RE: re.Pattern # OSC sequence regex
wrapped: TextIO # original stream
autoreset: bool
stream: StreamWrapper # proxy stream
strip: bool
convert: bool
on_stderr: bool
def __init__(self, wrapped, convert=None, strip=None, autoreset=False)
def should_wrap(self) -> bool
def write(self, text: str) -> None
def reset_all(self) -> None
def flush(self) -> Noneclass StreamWrapper:
def __init__(self, wrapped, converter)
def write(self, text: str) -> None
def isatty(self) -> bool
@property
def closed(self) -> bool
def __enter__(self, *args, **kwargs)
def __exit__(self, *args, **kwargs)
def __getattr__(self, name) # proxies all other attributes
def __getstate__(self) / def __setstate__(self, state) # pickling support# WinColor constants
class WinColor:
BLACK, BLUE, GREEN, CYAN, RED, MAGENTA, YELLOW, GREY = 0..7
# WinStyle constants
class WinStyle:
NORMAL = 0x00
BRIGHT = 0x08
BRIGHT_BACKGROUND = 0x80
# WinTerm — manages Windows console state
class WinTerm:
def reset_all(self, on_stderr=None)
def fore(self, fore=None, light=False, on_stderr=False)
def back(self, back=None, light=False, on_stderr=False)
def style(self, style=None, on_stderr=False)
def set_console(self, attrs=None, on_stderr=False)
def get_position(self, handle) -> COORD
def set_cursor_position(self, position=None, on_stderr=False)
def cursor_adjust(self, x, y, on_stderr=False)
def erase_screen(self, mode=0, on_stderr=False)
def erase_line(self, mode=0, on_stderr=False)
def set_title(self, title)
# VT processing
def enable_vt_processing(fd: int) -> bool
# Win32 API wrappers (ctypes)
def GetConsoleScreenBufferInfo(stream_id) -> CONSOLE_SCREEN_BUFFER_INFO
def SetConsoleTextAttribute(stream_id, attrs)
def SetConsoleCursorPosition(stream_id, position, adjust=True)
def FillConsoleOutputCharacter(stream_id, char, length, start)
def FillConsoleOutputAttribute(stream_id, attr, length, start)
def SetConsoleTitle(title)
def GetConsoleMode(handle) -> int
def SetConsoleMode(handle, mode)
def winapi_test() -> boolCSI (Control Sequence Introducer) sequences handled:
m— SGR (Select Graphic Rendition): colors and stylesJ— ED (Erase in Display): clear screen modes 0/1/2K— EL (Erase in Line): clear line modes 0/1/2H,f— CUP (Cursor Position): absolute positioningA— CUU (Cursor Up)B— CUD (Cursor Down)C— CUF (Cursor Forward)D— CUB (Cursor Back)
OSC (Operating System Command) sequences handled:
0;title— Set window title and icon2;title— Set window title
- Python 3.9+ only — remove all Python 2 compatibility code and conditional imports
- Full type annotations — complete type stubs for IDE support and mypy
- 256-color support (extension) —
Fore.color256(n),Back.color256(n)for 256-color palette - True color support (extension) —
Fore.rgb(r, g, b),Back.rgb(r, g, b)for 24-bit color - Terminal capability detection — auto-detect color support level (none/16/256/truecolor)
- NO_COLOR support — respect the NO_COLOR environment variable
- FORCE_COLOR support — respect
FORCE_COLORfor CI/CD environments - Remove PyCharm hack — handle IDE detection cleanly instead of special-casing
- Thread safety — protect global state with proper locking
- Modern Windows handling — prefer VT processing (Win10+), only fall back to Win32 API when necessary
Fore,Back,Style,Cursorconstants (exact same values as colorama)AnsiCodes,AnsiFore,AnsiBack,AnsiStyle,AnsiCursorclasses- Utility functions:
code_to_chars(),set_title(),clear_screen(),clear_line() CSI,OSC,BELconstants- Type annotations throughout
StreamWrapperclass with full proxy behaviorAnsiToWin32class with CSI/OSC regex parsing- ANSI sequence stripping logic
write(),write_and_convert(),write_plain_text()methodsextract_params(),call_win32(),convert_osc()methodsshould_wrap()detection logicautoresetbehavior
win32module with ctypes wrappers for all kernel32 functionsWinTermclass with full console state managementWinColor,WinStyleconstantsenable_vt_processing()for modern Windows- Screen/line erase, cursor positioning, title setting
- Proper error handling for non-console file descriptors
init(),deinit(),reinit(),just_fix_windows_console()colorama_text()context managerreset_all()with atexit registration- NO_COLOR / FORCE_COLOR environment variable support
- 256-color and true color extensions
- Terminal capability auto-detection
- Thread safety for global state
- PyPI package, CI/CD (test on Windows + POSIX), documentation
- Migration guide (import chromapaint as colorama)