pub struct AnsiCodeTracker {
pub bold: bool,
pub italic: bool,
pub underline: bool,
pub fg_color: Option<String>,
pub bg_color: Option<String>,
pub hyperlink: Option<ActiveHyperlink>,
}Expand description
Tracks active ANSI SGR and OSC 8 state across line breaks.
When wrapping styled text, styles must be closed at the end of each physical line and reopened at the start of the next. This struct records which attributes are currently active and can emit the corresponding escape sequences.
§Example
use photon_ui::utils::AnsiCodeTracker;
let mut tracker = AnsiCodeTracker::new();
tracker.process("\x1b[1m"); // bold on
tracker.process("\x1b[31m"); // red fg
assert_eq!(tracker.current_codes(), "\x1b[1;31m");Fields§
§bold: boolBold (SGR 1) is active.
italic: boolItalic (SGR 3) is active.
underline: boolUnderline (SGR 4) is active.
fg_color: Option<String>Active foreground color SGR parameter, e.g. "31" or "38;5;240".
bg_color: Option<String>Active background color SGR parameter, e.g. "41" or "48;5;240".
hyperlink: Option<ActiveHyperlink>Active OSC 8 hyperlink, if any.
Implementations§
Source§impl AnsiCodeTracker
impl AnsiCodeTracker
Sourcepub fn process(&mut self, seq: &str)
pub fn process(&mut self, seq: &str)
Process an ANSI escape sequence, updating internal state.
Supports:
- OSC 8 hyperlink open / close (
\x1b]8;;URL\x1b\\,\x1b]8;;\x1b\\) - SGR codes (
\x1b[…m) for bold, italic, underline, and colors
Sourcepub fn current_codes(&self) -> String
pub fn current_codes(&self) -> String
Return the escape sequences needed to restore all active codes.
This is used to reopen styles at the beginning of a continuation line.
Sourcepub fn line_end_reset(&self) -> String
pub fn line_end_reset(&self) -> String
Return the escape sequences needed to close active codes at a line end.
Unlike a full SGR reset, this only closes attributes that would bleed
into padding or subsequent lines (underline and hyperlinks). The caller
is responsible for emitting \x1b[0m when a full SGR reset is needed.
Sourcepub fn has_active_codes(&self) -> bool
pub fn has_active_codes(&self) -> bool
Returns true if any SGR or OSC 8 code is currently active.
Trait Implementations§
Source§impl Clone for AnsiCodeTracker
impl Clone for AnsiCodeTracker
Source§fn clone(&self) -> AnsiCodeTracker
fn clone(&self) -> AnsiCodeTracker
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for AnsiCodeTracker
impl Debug for AnsiCodeTracker
Source§impl Default for AnsiCodeTracker
impl Default for AnsiCodeTracker
Source§fn default() -> AnsiCodeTracker
fn default() -> AnsiCodeTracker
Source§impl PartialEq for AnsiCodeTracker
impl PartialEq for AnsiCodeTracker
Source§fn eq(&self, other: &AnsiCodeTracker) -> bool
fn eq(&self, other: &AnsiCodeTracker) -> bool
self and other values to be equal, and is used by ==.