Expand description
§egui_sgr
A library for converting ASCII/ANSI escape sequence color models to colored text in egui.
§Features
- Supports 4-bit color (16 colors) model
- Supports 8-bit color (256 colors) model
- Supports 24-bit true color model
- Automatically detects and converts mixed color sequences
- Supports simultaneous setting of foreground and background colors
- Handles malformed ANSI sequences gracefully
- Strips non-SGR control sequences (OSC, etc.)
§Usage Example
use egui_sgr::ansi_to_rich_text;
// Convert ANSI color sequences to egui RichText
let red_text = ansi_to_rich_text("\x1b[31mRed Text\x1b[0m");
let orange_text = ansi_to_rich_text("\x1b[38;5;208mOrange Text\x1b[0m");
let pink_text = ansi_to_rich_text("\x1b[38;2;255;105;180mPink Text\x1b[0m");
let colored_bg = ansi_to_rich_text("\x1b[41;33mYellow on Red\x1b[0m");
// Empty reset sequence (equivalent to [0m)
let reset_text = ansi_to_rich_text("\x1b[31mRed\x1b[mDefault");Modules§
Structs§
- Ansi
Parser - ANSI escape sequence parser that converts ANSI color codes to egui colors.
- Colored
Text - Represents a text segment with optional foreground and background color information.
Functions§
- ansi_
to_ rich_ text - Convenience function: directly converts text with ANSI escape sequences to a list of RichText
- convert_
to_ rich_ text - Converts a list of ColoredText to a list of RichText that can be displayed in egui
- example_
usage - Creates an example function to demonstrate how to use this library
- parse_
4bit_ color - Parses a 4-bit color ANSI sequence and applies the color
- parse_
8bit_ color - Parses an 8-bit color ANSI sequence and applies the color
- parse_
24bit_ color - Parses a 24-bit true color ANSI sequence and applies the color