use alloc::vec::Vec;
use smallvec::SmallVec;
use crate::perform::Perform;
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum Event {
Print(char),
Execute(u8),
CsiDispatch {
params: SmallVec<i32, 6>,
intermediates: SmallVec<u8, 2>,
final_byte: u8,
},
EscDispatch {
intermediates: SmallVec<u8, 2>,
byte: u8,
},
DcsHook {
params: SmallVec<i32, 6>,
intermediates: SmallVec<u8, 2>,
final_byte: u8,
},
DcsPut(u8),
DcsUnhook,
OscDispatch {
params: SmallVec<Vec<u8>, 8>,
bell_terminated: bool,
},
}
#[derive(Debug, Default)]
pub struct Recording {
pub events: Vec<Event>,
}
impl Recording {
pub const DEFAULT: Self = Self { events: Vec::new() };
#[inline]
pub const fn new() -> Self {
Self::DEFAULT
}
}
impl Perform for Recording {
fn print(&mut self, c: char) {
self.events.push(Event::Print(c));
}
fn print_bytes(&mut self, s: &[u8]) {
for &b in s {
self.events.push(Event::Print(b as char));
}
}
fn execute(&mut self, byte: u8) {
self.events.push(Event::Execute(byte));
}
fn csi_dispatch(&mut self, params: &[i32], _sep: u16, intermediates: &[u8], final_byte: u8) {
self.events.push(Event::CsiDispatch {
params: params.iter().copied().collect(),
intermediates: intermediates.iter().copied().collect(),
final_byte,
});
}
fn esc_dispatch(&mut self, intermediates: &[u8], byte: u8) {
self.events.push(Event::EscDispatch {
intermediates: intermediates.iter().copied().collect(),
byte,
});
}
fn hook(&mut self, params: &[i32], intermediates: &[u8], final_byte: u8) {
self.events.push(Event::DcsHook {
params: params.iter().copied().collect(),
intermediates: intermediates.iter().copied().collect(),
final_byte,
});
}
fn put(&mut self, byte: u8) {
self.events.push(Event::DcsPut(byte));
}
fn unhook(&mut self) {
self.events.push(Event::DcsUnhook);
}
fn osc_dispatch(&mut self, params: &[&[u8]], bell_terminated: bool) {
self.events.push(Event::OscDispatch {
params: params.iter().map(|p| p.to_vec()).collect(),
bell_terminated,
});
}
}