Skip to main content

seqsee/output/
raw.rs

1use termio::{Color, StyledText};
2use crate::ansi::AnsiElement;
3use crate::formatter::FormatAnsi;
4
5pub struct RawFormatter {
6    pub colorize: bool,
7}
8
9impl RawFormatter {
10    pub fn new(colorize: bool) -> Self {
11        Self { colorize }
12    }
13}
14
15impl Default for RawFormatter {
16    fn default() -> Self {
17        Self { colorize: true }
18    }
19}
20
21impl FormatAnsi for RawFormatter {
22    fn format(&self, elements: &[AnsiElement]) -> String {
23        let mut result = String::new();
24        
25        for element in elements {
26            match element {
27                AnsiElement::Text(text) => {
28                    result.push_str(text);
29                },
30                _ => {
31                    // Highlight sequences in the original text
32                    if self.colorize {
33                        match element.element_type() {
34                            "CSI" => result.push_str(&element.escape_repr().color(Color::Blue).to_string()),
35                            "Ctrl" => result.push_str(&element.escape_repr().color(Color::Yellow).to_string()),
36                            _ => result.push_str(&element.escape_repr().color(Color::IntenseMagenta).to_string()),
37                        }
38                    } else {
39                        result.push_str(&element.escape_repr());
40                    }
41                }
42            }
43        }
44        
45        result
46    }
47}