diff options
| author | Kunal Mohan <kunalmohan99@gmail.com> | 2021-02-11 21:15:38 +0530 |
|---|---|---|
| committer | Kunal Mohan <kunalmohan99@gmail.com> | 2021-05-04 20:47:48 +0530 |
| commit | 588cdaa00894a9ae46e6a293f73ba62d5b1df18f (patch) | |
| tree | a75863550610cbea67d4804ef15c26712603674c /src/client | |
| parent | docs(changelog): update change (diff) | |
| download | sl0ppij-588cdaa00894a9ae46e6a293f73ba62d5b1df18f.tar.gz sl0ppij-588cdaa00894a9ae46e6a293f73ba62d5b1df18f.tar.xz sl0ppij-588cdaa00894a9ae46e6a293f73ba62d5b1df18f.zip | |
isolate pty thread
Diffstat (limited to 'src/client')
| -rw-r--r-- | src/client/panes/terminal_pane.rs | 4 | ||||
| -rw-r--r-- | src/client/tab.rs | 99 |
2 files changed, 53 insertions, 50 deletions
diff --git a/src/client/panes/terminal_pane.rs b/src/client/panes/terminal_pane.rs index a5a957e6..1834e722 100644 --- a/src/client/panes/terminal_pane.rs +++ b/src/client/panes/terminal_pane.rs @@ -1,6 +1,8 @@ use crate::tab::Pane; use ::nix::pty::Winsize; use ::std::os::unix::io::RawFd; +use ::vte::Perform; +use serde::{Deserialize, Serialize}; use std::fmt::Debug; use std::time::Instant; @@ -10,7 +12,7 @@ use crate::panes::terminal_character::{ }; use crate::pty_bus::VteBytes; -#[derive(PartialEq, Eq, Ord, PartialOrd, Hash, Clone, Copy, Debug)] +#[derive(PartialEq, Eq, Ord, PartialOrd, Hash, Clone, Copy, Debug, Serialize, Deserialize)] pub enum PaneId { Terminal(RawFd), Plugin(u32), // FIXME: Drop the trait object, make this a wrapper for the struct? diff --git a/src/client/tab.rs b/src/client/tab.rs index b01e04e5..b87926b7 100644 --- a/src/client/tab.rs +++ b/src/client/tab.rs @@ -69,7 +69,6 @@ pub struct Tab { fullscreen_is_active: bool, synchronize_is_active: bool, os_api: Box<dyn OsApi>, - pub send_pty_instructions: SenderWithContext<PtyInstruction>, pub send_plugin_instructions: SenderWithContext<PluginInstruction>, pub send_app_instructions: SenderWithContext<AppInstruction>, should_clear_display_before_rendering: bool, @@ -226,7 +225,6 @@ impl Tab { name: String, full_screen_ws: &PositionAndSize, mut os_api: Box<dyn OsApi>, - send_pty_instructions: SenderWithContext<PtyInstruction>, send_plugin_instructions: SenderWithContext<PluginInstruction>, send_app_instructions: SenderWithContext<AppInstruction>, max_panes: Option<usize>, @@ -261,7 +259,6 @@ impl Tab { synchronize_is_active: false, os_api, send_app_instructions, - send_pty_instructions, send_plugin_instructions, should_clear_display_before_rendering: false, mode_info, @@ -354,8 +351,10 @@ impl Tab { // this is a bit of a hack and happens because we don't have any central location that // can query the screen as to how many panes it needs to create a layout // fixing this will require a bit of an architecture change - self.send_pty_instructions - .send(PtyInstruction::ClosePane(PaneId::Terminal(*unused_pid))) + self.send_app_instructions + .send(AppInstruction::ToPty(PtyInstruction::ClosePane( + PaneId::Terminal(*unused_pid), + ))) .unwrap(); } self.active_terminal = self.panes.iter().map(|(id, _)| id.to_owned()).next(); @@ -399,8 +398,8 @@ impl Tab { }, ); if terminal_id_to_split.is_none() { - self.send_pty_instructions - .send(PtyInstruction::ClosePane(pid)) // we can't open this pane, close the pty + self.send_app_instructions + .send(AppInstruction::ToPty(PtyInstruction::ClosePane(pid))) // we can't open this pane, close the pty .unwrap(); return; // likely no terminal large enough to split } @@ -475,24 +474,25 @@ impl Tab { self.panes.insert(pid, Box::new(new_terminal)); self.active_terminal = Some(pid); } - } else if let PaneId::Terminal(term_pid) = pid { - // TODO: check minimum size of active terminal - let active_pane_id = &self.get_active_pane_id().unwrap(); - let active_pane = self.panes.get_mut(active_pane_id).unwrap(); - if active_pane.rows() < MIN_TERMINAL_HEIGHT * 2 + 1 { - self.send_pty_instructions - .send(PtyInstruction::ClosePane(pid)) // we can't open this pane, close the pty - .unwrap(); - return; - } - let terminal_ws = PositionAndSize { - x: active_pane.x(), - y: active_pane.y(), - rows: active_pane.rows(), - columns: active_pane.columns(), - ..Default::default() - }; - let (top_winsize, bottom_winsize) = split_horizontally_with_gap(&terminal_ws); + } else { + // FIXME: This could use a second look + if let PaneId::Terminal(term_pid) = pid { + // TODO: check minimum size of active terminal + let active_pane_id = &self.get_active_pane_id().unwrap(); + let active_pane = self.panes.get_mut(active_pane_id).unwrap(); + if active_pane.rows() < MIN_TERMINAL_HEIGHT * 2 + 1 { + self.send_app_instructions + .send(AppInstruction::ToPty(PtyInstruction::ClosePane(pid))) // we can't open this pane, close the pty + .unwrap(); + return; + } + let terminal_ws = PositionAndSize { + x: active_pane.x(), + y: active_pane.y(), + rows: active_pane.rows(), + columns: active_pane.columns(), + }; + let (top_winsize, bottom_winsize) = split_horizontally_with_gap(&terminal_ws); active_pane.change_pos_and_size(&top_winsize); @@ -532,26 +532,25 @@ impl Tab { self.panes.insert(pid, Box::new(new_terminal)); self.active_terminal = Some(pid); } - } else if let PaneId::Terminal(term_pid) = pid { - // TODO: check minimum size of active terminal - let active_pane_id = &self.get_active_pane_id().unwrap(); - let active_pane = self.panes.get_mut(active_pane_id).unwrap(); - if active_pane.columns() < MIN_TERMINAL_WIDTH * 2 + 1 { - self.send_pty_instructions - .send(PtyInstruction::ClosePane(pid)) // we can't open this pane, close the pty - .unwrap(); - return; - } - let terminal_ws = PositionAndSize { - x: active_pane.x(), - y: active_pane.y(), - rows: active_pane.rows(), - columns: active_pane.columns(), - ..Default::default() - }; - let (left_winsize, right_winsize) = split_vertically_with_gap(&terminal_ws); - - active_pane.change_pos_and_size(&left_winsize); + } else { + // FIXME: This could use a second look + if let PaneId::Terminal(term_pid) = pid { + // TODO: check minimum size of active terminal + let active_pane_id = &self.get_active_pane_id().unwrap(); + let active_pane = self.panes.get_mut(active_pane_id).unwrap(); + if active_pane.columns() < MIN_TERMINAL_WIDTH * 2 + 1 { + self.send_app_instructions + .send(AppInstruction::ToPty(PtyInstruction::ClosePane(pid))) // we can't open this pane, close the pty + .unwrap(); + return; + } + let terminal_ws = PositionAndSize { + x: active_pane.x(), + y: active_pane.y(), + rows: active_pane.rows(), + columns: active_pane.columns(), + }; + let (left_winsize, right_winsize) = split_vertically_with_gap(&terminal_ws); let new_terminal = TerminalPane::new(term_pid, right_winsize); self.os_api.set_terminal_size_using_fd( @@ -2105,8 +2104,8 @@ impl Tab { if let Some(max_panes) = self.max_panes { let terminals = self.get_pane_ids(); for &pid in terminals.iter().skip(max_panes - 1) { - self.send_pty_instructions - .send(PtyInstruction::ClosePane(pid)) + self.send_app_instructions + .send(AppInstruction::ToPty(PtyInstruction::ClosePane(pid))) .unwrap(); self.close_pane_without_rerender(pid); } @@ -2217,8 +2216,10 @@ impl Tab { pub fn close_focused_pane(&mut self) { if let Some(active_pane_id) = self.get_active_pane_id() { self.close_pane(active_pane_id); - self.send_pty_instructions - .send(PtyInstruction::ClosePane(active_pane_id)) + self.send_app_instructions + .send(AppInstruction::ToPty(PtyInstruction::ClosePane( + active_pane_id, + ))) .unwrap(); } } |
