diff --git a/termwiz/src/escape/mod.rs b/termwiz/src/escape/mod.rs index 8775a180e..77b612f33 100644 --- a/termwiz/src/escape/mod.rs +++ b/termwiz/src/escape/mod.rs @@ -25,7 +25,7 @@ pub enum Action { /// A C0 or C1 control code Control(ControlCode), /// Device control. This is uncommon wrt. terminal emulation. - DeviceControl(Box), + DeviceControl(DeviceControlMode), /// A command that typically doesn't change the contents of the /// terminal, but rather influences how it displays or otherwise /// interacts with the rest of the system @@ -49,6 +49,18 @@ impl Display for Action { } } +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct EnterDeviceControlMode { + /// The final byte in the DCS mode + byte: u8, + params: Vec, + // TODO: can we just make intermediates a single u8? + intermediates: Vec, + /// if true, more than two intermediates arrived and the + /// remaining data was ignored + ignored_extra_intermediates: bool, +} + #[derive(Debug, Clone, PartialEq, Eq)] pub enum DeviceControlMode { /// Identify device control mode from the encoded parameters. @@ -56,16 +68,7 @@ pub enum DeviceControlMode { /// `Exit` is observed. While the mode is /// 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, - // TODO: can we just make intermediates a single u8? - intermediates: Vec, - /// if true, more than two intermediates arrived and the - /// remaining data was ignored - ignored_extra_intermediates: bool, - }, + Enter(Box), /// Exit the current device control mode Exit, /// Data for the device mode to consume diff --git a/termwiz/src/escape/parser/mod.rs b/termwiz/src/escape/parser/mod.rs index 90f6f8f4c..165d198fa 100644 --- a/termwiz/src/escape/parser/mod.rs +++ b/termwiz/src/escape/parser/mod.rs @@ -1,4 +1,6 @@ -use crate::escape::{Action, DeviceControlMode, Esc, OperatingSystemCommand, CSI}; +use crate::escape::{ + Action, DeviceControlMode, EnterDeviceControlMode, Esc, OperatingSystemCommand, CSI, +}; use log::error; use num; use std::cell::RefCell; @@ -123,22 +125,22 @@ impl<'a, F: FnMut(Action)> VTActor for Performer<'a, F> { 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, - }))); - } - - fn dcs_put(&mut self, data: u8) { - (self.callback)(Action::DeviceControl(Box::new(DeviceControlMode::Data( - data, + (self.callback)(Action::DeviceControl(DeviceControlMode::Enter(Box::new( + EnterDeviceControlMode { + byte, + params: params.to_vec(), + intermediates: intermediates.to_vec(), + ignored_extra_intermediates, + }, )))); } + fn dcs_put(&mut self, data: u8) { + (self.callback)(Action::DeviceControl(DeviceControlMode::Data(data))); + } + fn dcs_unhook(&mut self) { - (self.callback)(Action::DeviceControl(Box::new(DeviceControlMode::Exit))); + (self.callback)(Action::DeviceControl(DeviceControlMode::Exit)); } fn osc_dispatch(&mut self, osc: &[&[u8]]) { @@ -310,16 +312,16 @@ mod test { let actions = p.parse_as_vec(b"\x1bP1;2;3;qwat\x1b\\"); assert_eq!( vec![ - Action::DeviceControl(Box::new(DeviceControlMode::Enter { + Action::DeviceControl(DeviceControlMode::Enter(Box::new(EnterDeviceControlMode { 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::DeviceControl(DeviceControlMode::Data(b'w')), + Action::DeviceControl(DeviceControlMode::Data(b'a')), + Action::DeviceControl(DeviceControlMode::Data(b't')), + Action::DeviceControl(DeviceControlMode::Exit), Action::Esc(Esc::Code(EscCode::StringTerminator)), ], actions