termwiz: shift Boxing of DCS around

Previously, we'd require boxing the entire DCS representation
in the escape sequence parser.  This was due to some clippy
advice that made sense at the time, but now that I'm looking
at more things using DCS it seems wasteful to Box each byte of
the dcs sequence.  This commit shifts the box to the heavier
weight portion: the DCS hook/entry representation.
This commit is contained in:
Wez Furlong committed 2020-06-09 22:01:26 -07:00
1 parent 18a234a162
commit d7c04b154d
2 files changed
+35 -30

No files matched your search

+14 -11
View File
@@ -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<DeviceControlMode>),
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<i64>,
// TODO: can we just make intermediates a single u8?
intermediates: Vec<u8>,
/// 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<i64>,
// TODO: can we just make intermediates a single u8?
intermediates: Vec<u8>,
/// if true, more than two intermediates arrived and the
/// remaining data was ignored
ignored_extra_intermediates: bool,
},
Enter(Box<EnterDeviceControlMode>),
/// Exit the current device control mode
Exit,
/// Data for the device mode to consume
+21 -19
View File
@@ -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