termwiz: recognize some dec private SGR codes
Recognize DEC private SGR codes that are equivalent to super/subscript, overline and reset. refs: https://github.com/mintty/mintty/issues/1171#issuecomment-1250317539
This commit is contained in:
1 parent
1b99690990
commit
6d375091a1
2 files changed
+72
-2
No files matched your search
@@ -2446,7 +2446,10 @@ impl<'a> CSIParser<'a> {
|
||||
} else {
|
||||
for p in params {
|
||||
match p {
|
||||
CsiParam::P(b';') | CsiParam::P(b':') | CsiParam::Integer(_) => {}
|
||||
CsiParam::P(b';')
|
||||
| CsiParam::P(b':')
|
||||
| CsiParam::P(b'?')
|
||||
| CsiParam::Integer(_) => {}
|
||||
_ => return Err(()),
|
||||
}
|
||||
}
|
||||
@@ -2457,12 +2460,45 @@ impl<'a> CSIParser<'a> {
|
||||
Ok(self.advance_by(1, params, $t))
|
||||
};
|
||||
}
|
||||
// Consume two parameters and return the parsed result
|
||||
macro_rules! two {
|
||||
($t:expr) => {
|
||||
Ok(self.advance_by(2, params, $t))
|
||||
};
|
||||
}
|
||||
|
||||
match ¶ms[0] {
|
||||
CsiParam::P(b';') => {
|
||||
// Starting with an empty item is equivalent to a reset
|
||||
self.advance_by(1, params, Ok(Sgr::Reset))
|
||||
}
|
||||
|
||||
// There are a small number of DEC private SGR parameters that
|
||||
// have equivalents in the normal SGR space.
|
||||
// We're simply inlining recognizing them here, and mapping them
|
||||
// to those SGR equivalents. That makes parsing "lossy" in the
|
||||
// sense that the original sequence is lost, but semantically,
|
||||
// the result is the same.
|
||||
// These codes are taken from the "SGR" section of
|
||||
// "Digital ANSI-Compliant Printing Protocol
|
||||
// Level 2 Programming Reference Manual"
|
||||
// on page 7-78.
|
||||
// <https://vaxhaven.com/images/f/f7/EK-PPLV2-PM-B01.pdf>
|
||||
CsiParam::P(b'?') if params.len() > 1 => match ¶ms[1] {
|
||||
CsiParam::Integer(i) => match FromPrimitive::from_i64(*i) {
|
||||
None => Err(()),
|
||||
Some(code) => match code {
|
||||
0 => two!(Sgr::Reset),
|
||||
4 => two!(Sgr::VerticalAlign(VerticalAlign::SuperScript)),
|
||||
5 => two!(Sgr::VerticalAlign(VerticalAlign::SubScript)),
|
||||
6 => two!(Sgr::Overline(true)),
|
||||
24 => two!(Sgr::VerticalAlign(VerticalAlign::BaseLine)),
|
||||
26 => two!(Sgr::Overline(false)),
|
||||
_ => Err(()),
|
||||
},
|
||||
},
|
||||
_ => Err(()),
|
||||
},
|
||||
CsiParam::P(_) => Err(()),
|
||||
CsiParam::Integer(i) => match FromPrimitive::from_i64(*i) {
|
||||
None => Err(()),
|
||||
|
||||
@@ -338,7 +338,7 @@ impl<'a, F: FnMut(Action)> VTActor for Performer<'a, F> {
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use crate::cell::{Intensity, Underline};
|
||||
use crate::cell::{Intensity, Underline, VerticalAlign};
|
||||
use crate::color::ColorSpec;
|
||||
use crate::escape::csi::{
|
||||
CharacterPath, DecPrivateMode, DecPrivateModeCode, Device, Mode, Sgr, Window, XtSmGraphics,
|
||||
@@ -942,6 +942,40 @@ mod test {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dec_private_sgr() {
|
||||
assert_eq!(
|
||||
parse_as("\x1b[?0m", "\x1b[0m"),
|
||||
vec![Action::CSI(CSI::Sgr(Sgr::Reset))]
|
||||
);
|
||||
assert_eq!(
|
||||
parse_as("\x1b[?4m", "\x1b[73m"),
|
||||
vec![Action::CSI(CSI::Sgr(Sgr::VerticalAlign(
|
||||
VerticalAlign::SuperScript
|
||||
)))]
|
||||
);
|
||||
assert_eq!(
|
||||
parse_as("\x1b[?5m", "\x1b[74m"),
|
||||
vec![Action::CSI(CSI::Sgr(Sgr::VerticalAlign(
|
||||
VerticalAlign::SubScript
|
||||
)))]
|
||||
);
|
||||
assert_eq!(
|
||||
parse_as("\x1b[?24m", "\x1b[75m"),
|
||||
vec![Action::CSI(CSI::Sgr(Sgr::VerticalAlign(
|
||||
VerticalAlign::BaseLine
|
||||
)))]
|
||||
);
|
||||
assert_eq!(
|
||||
parse_as("\x1b[?6m", "\x1b[53m"),
|
||||
vec![Action::CSI(CSI::Sgr(Sgr::Overline(true)))]
|
||||
);
|
||||
assert_eq!(
|
||||
parse_as("\x1b[?26m", "\x1b[55m"),
|
||||
vec![Action::CSI(CSI::Sgr(Sgr::Overline(false)))]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn decset() {
|
||||
assert_eq!(
|
||||
|
||||
Reference in new issue
Block a user