From 0b64683a6014cbc5f718eeb5d8fed89887e46758 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sun, 1 Nov 2020 22:48:54 -0800 Subject: [PATCH] term: allow embedding application to hook device control mode refs: https://github.com/wez/wezterm/issues/336 --- term/src/terminal.rs | 4 ++++ term/src/terminalstate.rs | 13 ++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/term/src/terminal.rs b/term/src/terminal.rs index a9e69e6ff..b813d1af6 100644 --- a/term/src/terminal.rs +++ b/term/src/terminal.rs @@ -17,6 +17,10 @@ impl Clipboard for Box { } } +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 diff --git a/term/src/terminalstate.rs b/term/src/terminalstate.rs index 62a6d816c..40149d7c8 100644 --- a/term/src/terminalstate.rs +++ b/term/src/terminalstate.rs @@ -286,6 +286,7 @@ pub struct TerminalState { pixel_height: usize, clipboard: Option>, + device_control_handler: Option>, current_dir: Option, @@ -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) { + 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), + }, } }