Skip to content

Commit

Permalink
term: allow embedding application to hook device control mode
Browse files Browse the repository at this point in the history
refs: #336
  • Loading branch information
wez committed Nov 20, 2020
1 parent 6035e16 commit 0b64683
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 4 additions & 0 deletions term/src/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions term/src/terminalstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,

Expand Down Expand Up @@ -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(),
Expand All @@ -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:
Expand Down Expand Up @@ -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),
},
}
}

Expand Down

0 comments on commit 0b64683

Please sign in to comment.