Module colorizer.parser.xterm
This module provides a parser for identifying and converting xterm color codes to RGB hexadecimal format.
It supports both #xNN format (decimal, 0-255) and ANSI escape sequences \e[38;5;NNNm for xterm 256-color palette. The function reads the color code and returns the corresponding RGB hex string from the xterm color palette.
Functions
| parser (line, i) | Parses xterm color codes and converts them to RGB hex format. |
Functions
- parser (line, i)
-
Parses xterm 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 for xterm 256-color palette.
3. ANSI escape sequences \e[X;Ym for xterm 16-color palette.
It returns the corresponding RGB hex string from the xterm color palette.
Parameters:
- line string: The line of text to parse for xterm color codes
- i number: The starting index within the line where parsing should begin
Returns:
- number|nil: The end index of the parsed xterm color code within the line, or `nil` if parsing failed
- string|nil: The RGB hexadecimal color from the xterm palette, or `nil` if parsing failed