Module colorizer.parser.xterm
Xterm Parser This module provides a parser for identifying and converting xterm/ANSI color codes to RGB hexadecimal format.
Supported formats: - #xNN (decimal, 0-255) for xterm 256-color palette - \e[38;5;NNNm / \e[48;5;NNNm for 256-color foreground/background - \e[38;2;R;G;Bm / \e[48;2;R;G;Bm for 24-bit true-color foreground/background - \e[X;Ym for 16-color foreground (30-37) and background (40-47) with brightness
Exposes the 256-color palette for reuse:
- M.lookup_256(idx) returns the RGB hex for 0..255, or nil
- M.get_palette() returns a fresh copy of the full 256-entry palette
Functions
| get_palette () | Return a fresh copy of the full xterm 256-color palette. |
| lookup_256 (idx) | Look up an xterm 256-color palette entry. |
| parser (line, i) | Parses xterm/ANSI color codes and converts them to RGB hex format. |
Tables
| spec | Parser spec for the registry |
Functions
- get_palette ()
- Return a fresh copy of the full xterm 256-color palette.
- lookup_256 (idx)
- Look up an xterm 256-color palette entry.
- parser (line, i)
- Parses xterm/ANSI color codes and converts them to RGB hex format. This function matches following color codes: 1. #xNN format (decimal, 0-255). 2. ANSI escape sequences \e[38;5;NNNm and \e[48;5;NNNm for 256-color palette. 3. ANSI escape sequences \e[38;2;R;G;Bm and \e[48;2;R;G;Bm for 24-bit true-color. 4. ANSI escape sequences \e[X;Ym for 16-color foreground (30-37) and background (40-47). It returns the corresponding RGB hex string.