vtparse: fix DCS parsing
This corrects an issue where the mode byte of the DCS sequence was discarded from the DcsHook, making it impossible to know what sequence is being activated. So far this hasn't come up as these sequences are relatively rare, but in looking at sixel parsing I noticed the error.
This commit is contained in:
1 parent
ff9151bb9b
commit
65f94bd57b
7 files changed
+143
-7
No files matched your search
Generated
+2
-2
@@ -3258,7 +3258,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "termwiz"
|
||||
version = "0.9.0"
|
||||
version = "0.10.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"base64 0.10.1",
|
||||
@@ -3564,7 +3564,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "vtparse"
|
||||
version = "0.2.2"
|
||||
version = "0.3.0"
|
||||
dependencies = [
|
||||
"pretty_assertions",
|
||||
"utf8parse",
|
||||
|
||||
+1
-1
@@ -9,4 +9,4 @@ license = "MIT"
|
||||
documentation = "https://docs.rs/tabout"
|
||||
|
||||
[dependencies]
|
||||
termwiz = { path = "../termwiz", version="0.9"}
|
||||
termwiz = { path = "../termwiz", version="0.10"}
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
authors = ["Wez Furlong"]
|
||||
name = "termwiz"
|
||||
version = "0.9.0"
|
||||
version = "0.10.0"
|
||||
edition = "2018"
|
||||
repository = "https://github.com/wez/wezterm"
|
||||
description = "Terminal Wizardry for Unix and Windows"
|
||||
@@ -32,7 +32,7 @@ terminfo = "0.7"
|
||||
unicode-segmentation = "1.5"
|
||||
unicode-width = "0.1"
|
||||
xi-unicode = "0.2"
|
||||
vtparse = { version="0.2", path="../vtparse" }
|
||||
vtparse = { version="0.3", path="../vtparse" }
|
||||
|
||||
[features]
|
||||
widgets = ["cassowary", "fnv"]
|
||||
|
||||
@@ -57,6 +57,8 @@ pub enum DeviceControlMode {
|
||||
/// active, data is made available to the device mode via
|
||||
/// the `Data` variant.
|
||||
Enter {
|
||||
/// The final byte in the DCS mode
|
||||
byte: u8,
|
||||
params: Vec<i64>,
|
||||
// TODO: can we just make intermediates a single u8?
|
||||
intermediates: Vec<u8>,
|
||||
|
||||
@@ -118,11 +118,13 @@ impl<'a, F: FnMut(Action)> VTActor for Performer<'a, F> {
|
||||
|
||||
fn dcs_hook(
|
||||
&mut self,
|
||||
byte: u8,
|
||||
params: &[i64],
|
||||
intermediates: &[u8],
|
||||
ignored_extra_intermediates: bool,
|
||||
) {
|
||||
(self.callback)(Action::DeviceControl(Box::new(DeviceControlMode::Enter {
|
||||
byte,
|
||||
params: params.to_vec(),
|
||||
intermediates: intermediates.to_vec(),
|
||||
ignored_extra_intermediates,
|
||||
@@ -301,4 +303,43 @@ mod test {
|
||||
);
|
||||
assert_eq!(encode(&actions), "\x1b%H");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sixel() {
|
||||
let mut p = Parser::new();
|
||||
let actions = p.parse_as_vec(b"\x1bP1;2;3;qwat\x1b\\");
|
||||
assert_eq!(
|
||||
vec![
|
||||
Action::DeviceControl(Box::new(DeviceControlMode::Enter {
|
||||
byte: b'q',
|
||||
params: vec![1, 2, 3],
|
||||
intermediates: vec![],
|
||||
ignored_extra_intermediates: false,
|
||||
})),
|
||||
Action::DeviceControl(Box::new(DeviceControlMode::Data(b'w'))),
|
||||
Action::DeviceControl(Box::new(DeviceControlMode::Data(b'a'))),
|
||||
Action::DeviceControl(Box::new(DeviceControlMode::Data(b't'))),
|
||||
Action::DeviceControl(Box::new(DeviceControlMode::Exit)),
|
||||
Action::Esc(Esc::Code(EscCode::StringTerminator)),
|
||||
],
|
||||
actions
|
||||
);
|
||||
|
||||
/*
|
||||
// This is the "HI" example from wikipedia
|
||||
let mut p = Parser::new();
|
||||
let actions = p.parse_as_vec(
|
||||
b"\x1bPq\
|
||||
#0;2;0;0;0#1;2;100;100;0#2;2;0;100;0\
|
||||
#1~~@@vv@@~~@@~~$\
|
||||
#2??}}GG}}??}}??-\
|
||||
#1!14@\
|
||||
\x1b\\",
|
||||
);
|
||||
assert_eq!(
|
||||
vec![Action::Esc(Esc::Code(EscCode::HorizontalTabSet))],
|
||||
actions
|
||||
);
|
||||
*/
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
authors = ["Wez Furlong <wez@wezfurlong.org>"]
|
||||
name = "vtparse"
|
||||
version = "0.2.2"
|
||||
version = "0.3.0"
|
||||
edition = "2018"
|
||||
repository = "https://github.com/wez/wezterm"
|
||||
description = "Low level escape sequence parser"
|
||||
|
||||
+94
-1
@@ -108,6 +108,7 @@ pub trait VTActor {
|
||||
/// for more information on device control strings.
|
||||
fn dcs_hook(
|
||||
&mut self,
|
||||
mode: u8,
|
||||
params: &[i64],
|
||||
intermediates: &[u8],
|
||||
ignored_excess_intermediates: bool,
|
||||
@@ -175,6 +176,7 @@ pub enum VTAction {
|
||||
params: Vec<i64>,
|
||||
intermediates: Vec<u8>,
|
||||
ignored_excess_intermediates: bool,
|
||||
byte: u8,
|
||||
},
|
||||
DcsPut(u8),
|
||||
DcsUnhook,
|
||||
@@ -228,11 +230,13 @@ impl VTActor for CollectingVTActor {
|
||||
|
||||
fn dcs_hook(
|
||||
&mut self,
|
||||
byte: u8,
|
||||
params: &[i64],
|
||||
intermediates: &[u8],
|
||||
ignored_excess_intermediates: bool,
|
||||
) {
|
||||
self.actions.push(VTAction::DcsHook {
|
||||
byte,
|
||||
params: params.to_vec(),
|
||||
intermediates: intermediates.to_vec(),
|
||||
ignored_excess_intermediates,
|
||||
@@ -423,6 +427,7 @@ impl VTParser {
|
||||
Action::Hook => {
|
||||
self.finish_param();
|
||||
actor.dcs_hook(
|
||||
param,
|
||||
&self.params[0..self.num_params],
|
||||
&self.intermediates[0..self.num_intermediates],
|
||||
self.ignored_excess_intermediates,
|
||||
@@ -555,7 +560,7 @@ impl VTParser {
|
||||
self.action(lookup_exit(self.state), 0, actor);
|
||||
}
|
||||
self.action(action, byte, actor);
|
||||
self.action(lookup_entry(state), 0, actor);
|
||||
self.action(lookup_entry(state), byte, actor);
|
||||
self.utf8_return_state = self.state;
|
||||
self.state = state;
|
||||
} else {
|
||||
@@ -787,4 +792,92 @@ mod test {
|
||||
vec![VTAction::Print('\u{af}')]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tmux_control() {
|
||||
assert_eq!(
|
||||
parse_as_vec("\x1bP1000phello\x1b\\".as_bytes()),
|
||||
vec![
|
||||
VTAction::DcsHook {
|
||||
byte: b'p',
|
||||
params: vec![1000],
|
||||
intermediates: vec![],
|
||||
ignored_excess_intermediates: false,
|
||||
},
|
||||
VTAction::DcsPut(b'h'),
|
||||
VTAction::DcsPut(b'e'),
|
||||
VTAction::DcsPut(b'l'),
|
||||
VTAction::DcsPut(b'l'),
|
||||
VTAction::DcsPut(b'o'),
|
||||
VTAction::DcsUnhook,
|
||||
VTAction::EscDispatch {
|
||||
params: vec![],
|
||||
intermediates: vec![],
|
||||
ignored_excess_intermediates: false,
|
||||
byte: b'\\',
|
||||
}
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tmux_passthru() {
|
||||
// I'm not convinced that we *should* represent this tmux sequence
|
||||
// in this way, but it is how it currently maps.
|
||||
// It's worth noting that we see this as final byte `t` here, which
|
||||
// collides with decVT105G in https://vt100.net/emu/dcsseq_dec.html
|
||||
assert_eq!(
|
||||
parse_as_vec("\x1bPtmux;data\x1b\\".as_bytes()),
|
||||
vec![
|
||||
VTAction::DcsHook {
|
||||
byte: b't',
|
||||
params: vec![],
|
||||
intermediates: vec![],
|
||||
ignored_excess_intermediates: false,
|
||||
},
|
||||
VTAction::DcsPut(b'm'),
|
||||
VTAction::DcsPut(b'u'),
|
||||
VTAction::DcsPut(b'x'),
|
||||
VTAction::DcsPut(b';'),
|
||||
VTAction::DcsPut(b'd'),
|
||||
VTAction::DcsPut(b'a'),
|
||||
VTAction::DcsPut(b't'),
|
||||
VTAction::DcsPut(b'a'),
|
||||
VTAction::DcsUnhook,
|
||||
VTAction::EscDispatch {
|
||||
params: vec![],
|
||||
intermediates: vec![],
|
||||
ignored_excess_intermediates: false,
|
||||
byte: b'\\',
|
||||
}
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sixel() {
|
||||
assert_eq!(
|
||||
parse_as_vec("\x1bPqhello\x1b\\".as_bytes()),
|
||||
vec![
|
||||
VTAction::DcsHook {
|
||||
byte: b'q',
|
||||
params: vec![],
|
||||
intermediates: vec![],
|
||||
ignored_excess_intermediates: false,
|
||||
},
|
||||
VTAction::DcsPut(b'h'),
|
||||
VTAction::DcsPut(b'e'),
|
||||
VTAction::DcsPut(b'l'),
|
||||
VTAction::DcsPut(b'l'),
|
||||
VTAction::DcsPut(b'o'),
|
||||
VTAction::DcsUnhook,
|
||||
VTAction::EscDispatch {
|
||||
params: vec![],
|
||||
intermediates: vec![],
|
||||
ignored_excess_intermediates: false,
|
||||
byte: b'\\',
|
||||
}
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user