diff options
| author | denis <denismaximov98@gmail.com> | 2021-04-13 11:30:54 +0300 |
|---|---|---|
| committer | denis <denismaximov98@gmail.com> | 2021-04-13 11:30:54 +0300 |
| commit | e5526df46af1d7b86d146c6041492e93c62813e5 (patch) | |
| tree | 745f72331bc1b0ea16fc4fe796531b08cf964372 /src/common | |
| parent | wip: looks cleaner (diff) | |
| parent | fix(performance): remove unnecessary allocations from pty (#264) (diff) | |
| download | sl0ppij-e5526df46af1d7b86d146c6041492e93c62813e5.tar.gz sl0ppij-e5526df46af1d7b86d146c6041492e93c62813e5.tar.xz sl0ppij-e5526df46af1d7b86d146c6041492e93c62813e5.zip | |
Merge branch 'main' into x-colors
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/errors.rs | 4 | ||||
| -rw-r--r-- | src/common/mod.rs | 6 | ||||
| -rw-r--r-- | src/common/pty_bus.rs | 92 | ||||
| -rw-r--r-- | src/common/screen.rs | 4 |
4 files changed, 12 insertions, 94 deletions
diff --git a/src/common/errors.rs b/src/common/errors.rs index 1548aec0..9801428c 100644 --- a/src/common/errors.rs +++ b/src/common/errors.rs @@ -168,7 +168,7 @@ impl Display for ContextType { /// Stack call representations corresponding to the different types of [`ScreenInstruction`]s. #[derive(Debug, Clone, Copy, PartialEq)] pub enum ScreenContext { - HandlePtyEvent, + HandlePtyBytes, Render, NewPane, HorizontalSplit, @@ -210,7 +210,7 @@ pub enum ScreenContext { impl From<&ScreenInstruction> for ScreenContext { fn from(screen_instruction: &ScreenInstruction) -> Self { match *screen_instruction { - ScreenInstruction::Pty(..) => ScreenContext::HandlePtyEvent, + ScreenInstruction::PtyBytes(..) => ScreenContext::HandlePtyBytes, ScreenInstruction::Render => ScreenContext::Render, ScreenInstruction::NewPane(_) => ScreenContext::NewPane, ScreenInstruction::HorizontalSplit(_) => ScreenContext::HorizontalSplit, diff --git a/src/common/mod.rs b/src/common/mod.rs index 0e3e733b..b3bcec9b 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -285,19 +285,19 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs) { screen.send_app_instructions.update(err_ctx); screen.send_pty_instructions.update(err_ctx); match event { - ScreenInstruction::Pty(pid, vte_event) => { + ScreenInstruction::PtyBytes(pid, vte_bytes) => { let active_tab = screen.get_active_tab_mut().unwrap(); if active_tab.has_terminal_pid(pid) { // it's most likely that this event is directed at the active tab // look there first - active_tab.handle_pty_event(pid, vte_event); + active_tab.handle_pty_bytes(pid, vte_bytes); } else { // if this event wasn't directed at the active tab, start looking // in other tabs let all_tabs = screen.get_tabs_mut(); for tab in all_tabs.values_mut() { if tab.has_terminal_pid(pid) { - tab.handle_pty_event(pid, vte_event); + tab.handle_pty_bytes(pid, vte_bytes); break; } } diff --git a/src/common/pty_bus.rs b/src/common/pty_bus.rs index 7e854257..2cab8ae8 100644 --- a/src/common/pty_bus.rs +++ b/src/common/pty_bus.rs @@ -6,7 +6,6 @@ use ::std::os::unix::io::RawFd; use ::std::pin::*; use ::std::sync::mpsc::Receiver; use ::std::time::{Duration, Instant}; -use ::vte; use std::path::PathBuf; use super::{ScreenInstruction, SenderWithContext, OPENCALLS}; @@ -64,86 +63,7 @@ impl Stream for ReadFromPid { } } -#[derive(Debug, Clone)] -pub enum VteEvent { - // TODO: try not to allocate Vecs - Print(char), - Execute(u8), // byte - Hook(Vec<i64>, Vec<u8>, bool, char), // params, intermediates, ignore, char - Put(u8), // byte - Unhook, - OscDispatch(Vec<Vec<u8>>, bool), // params, bell_terminated - CsiDispatch(Vec<i64>, Vec<u8>, bool, char), // params, intermediates, ignore, char - EscDispatch(Vec<u8>, bool, u8), // intermediates, ignore, byte -} - -struct VteEventSender { - id: RawFd, - sender: SenderWithContext<ScreenInstruction>, -} - -impl VteEventSender { - pub fn new(id: RawFd, sender: SenderWithContext<ScreenInstruction>) -> Self { - VteEventSender { id, sender } - } -} - -impl vte::Perform for VteEventSender { - fn print(&mut self, c: char) { - let _ = self - .sender - .send(ScreenInstruction::Pty(self.id, VteEvent::Print(c))); - } - fn execute(&mut self, byte: u8) { - let _ = self - .sender - .send(ScreenInstruction::Pty(self.id, VteEvent::Execute(byte))); - } - - fn hook(&mut self, params: &[i64], intermediates: &[u8], ignore: bool, c: char) { - let params = params.iter().copied().collect(); - let intermediates = intermediates.iter().copied().collect(); - let instruction = - ScreenInstruction::Pty(self.id, VteEvent::Hook(params, intermediates, ignore, c)); - let _ = self.sender.send(instruction); - } - - fn put(&mut self, byte: u8) { - let _ = self - .sender - .send(ScreenInstruction::Pty(self.id, VteEvent::Put(byte))); - } - - fn unhook(&mut self) { - let _ = self - .sender - .send(ScreenInstruction::Pty(self.id, VteEvent::Unhook)); - } - - fn osc_dispatch(&mut self, params: &[&[u8]], bell_terminated: bool) { - let params = params.iter().map(|p| p.to_vec()).collect(); - let instruction = - ScreenInstruction::Pty(self.id, VteEvent::OscDispatch(params, bell_terminated)); - let _ = self.sender.send(instruction); - } - - fn csi_dispatch(&mut self, params: &[i64], intermediates: &[u8], ignore: bool, c: char) { - let params = params.iter().copied().collect(); - let intermediates = intermediates.iter().copied().collect(); - let instruction = ScreenInstruction::Pty( - self.id, - VteEvent::CsiDispatch(params, intermediates, ignore, c), - ); - let _ = self.sender.send(instruction); - } - - fn esc_dispatch(&mut self, intermediates: &[u8], ignore: bool, byte: u8) { - let intermediates = intermediates.iter().copied().collect(); - let instruction = - ScreenInstruction::Pty(self.id, VteEvent::EscDispatch(intermediates, ignore, byte)); - let _ = self.sender.send(instruction); - } -} +pub type VteBytes = Vec<u8>; /// Instructions related to PTYs (pseudoterminals). #[derive(Clone, Debug)] @@ -178,8 +98,6 @@ fn stream_terminal_bytes( async move { err_ctx.add_call(ContextType::AsyncTask); send_screen_instructions.update(err_ctx); - let mut vte_parser = vte::Parser::new(); - let mut vte_event_sender = VteEventSender::new(pid, send_screen_instructions.clone()); let mut terminal_bytes = ReadFromPid::new(&pid, os_input); let mut last_byte_receive_time: Option<Instant> = None; @@ -188,13 +106,13 @@ fn stream_terminal_bytes( while let Some(bytes) = terminal_bytes.next().await { let bytes_is_empty = bytes.is_empty(); - for byte in bytes { - if debug { - debug_to_file(byte, pid).unwrap(); + if debug { + for byte in bytes.iter() { + debug_to_file(*byte, pid).unwrap(); } - vte_parser.advance(&mut vte_event_sender, byte); } if !bytes_is_empty { + let _ = send_screen_instructions.send(ScreenInstruction::PtyBytes(pid, bytes)); // for UX reasons, if we got something on the wire, we only send the render notice if: // 1. there aren't any more bytes on the wire afterwards // 2. a certain period (currently 30ms) has elapsed since the last render diff --git a/src/common/screen.rs b/src/common/screen.rs index 6ef7e9e0..563221e9 100644 --- a/src/common/screen.rs +++ b/src/common/screen.rs @@ -8,7 +8,7 @@ use std::sync::mpsc::Receiver; use super::{AppInstruction, SenderWithContext}; use crate::os_input_output::OsApi; use crate::panes::PositionAndSize; -use crate::pty_bus::{PtyInstruction, VteEvent}; +use crate::pty_bus::{PtyInstruction, VteBytes}; use crate::tab::Tab; use crate::{errors::ErrorContext, wasm_vm::PluginInstruction}; use crate::{layout::Layout, panes::PaneId}; @@ -18,7 +18,7 @@ use zellij_tile::data::{Event, InputMode, ModeInfo, Palette, TabInfo}; /// Instructions that can be sent to the [`Screen`]. #[derive(Debug, Clone)] pub enum ScreenInstruction { - Pty(RawFd, VteEvent), + PtyBytes(RawFd, VteBytes), Render, NewPane(PaneId), HorizontalSplit(PaneId), |
