in src/content/lines.rs [75:111]
fn parse_line(&mut self, parser: &mut termwiz::escape::parser::Parser, s: &str) -> Line {
// Because we only stick "printable" characters onto the buffer, and skip any other
// class of characters that we don't recognize, this should be a
// roughly sanitized string. We do one more pass when we create the Span, just to
// make sure, but that is a pretty fast check.
parser.parse(s.as_bytes(), |a| match a {
Action::Print(c) => {
self.line_buffer.push(c);
}
Action::CSI(CSI::Sgr(Sgr::Reset)) => {
self.push_current();
self.foreground_color = None;
self.background_color = None;
self.attributes = Attributes::default();
}
Action::CSI(CSI::Sgr(Sgr::Intensity(intensity))) => {
self.push_current();
self.attributes = match intensity {
Intensity::Normal => Attributes::default(),
Intensity::Bold => Attributes::from(Attribute::Bold),
Intensity::Half => Attributes::from(Attribute::Dim),
};
}
Action::CSI(CSI::Sgr(Sgr::Foreground(spec))) => {
self.push_current();
self.foreground_color = Self::spec_to_color(spec);
}
Action::CSI(CSI::Sgr(Sgr::Background(spec))) => {
self.push_current();
self.background_color = Self::spec_to_color(spec);
}
_ => {}
});
self.push_current();
Line(std::mem::take(&mut self.spans))
}