term: allow embedding application to hook device control mode

refs: https://github.com/wez/wezterm/issues/336
This commit is contained in:
Wez Furlong committed 2020-11-20 09:24:48 -08:00
1 parent 6035e16f33
commit 0b64683a60
2 files changed
+14 -3

No files matched your search

+4
View File
@@ -17,6 +17,10 @@ impl Clipboard for Box<dyn Clipboard> {
}
}
pub trait DeviceControlHandler {
fn handle_device_control(&mut self, _control: termwiz::escape::DeviceControlMode);
}
/// Represents an instance of a terminal emulator.
pub struct Terminal {
/// The terminal model/state
+10 -3
View File
@@ -286,6 +286,7 @@ pub struct TerminalState {
pixel_height: usize,
clipboard: Option<Arc<dyn Clipboard>>,
device_control_handler: Option<Box<dyn DeviceControlHandler>>,
current_dir: Option<Url>,
@@ -383,6 +384,7 @@ impl TerminalState {
pixel_height,
pixel_width,
clipboard: None,
device_control_handler: None,
current_dir: None,
term_program: term_program.to_string(),
term_version: term_version.to_string(),
@@ -395,6 +397,10 @@ impl TerminalState {
self.clipboard.replace(Arc::clone(clipboard));
}
pub fn set_device_control_handler(&mut self, handler: Box<dyn DeviceControlHandler>) {
self.device_control_handler.replace(handler);
}
/// Returns the title text associated with the terminal session.
/// The title can be changed by the application using a number
/// of escape sequences:
@@ -2752,9 +2758,10 @@ impl<'a> Performer<'a> {
_ => log::error!("unhandled {:?}", s),
}
}
ctrl => {
log::error!("unhandled {:?}", ctrl);
}
_ => match self.device_control_handler.as_mut() {
Some(handler) => handler.handle_device_control(ctrl),
None => log::error!("unhandled {:?}", ctrl),
},
}
}