Skip to main content

Crate egui_sgr

Crate egui_sgr 

Source
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§

eight_bit
four_bit
twenty_four_bit

Structs§

AnsiParser
ANSI escape sequence parser that converts ANSI color codes to egui colors.
ColoredText
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