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/client | |
| 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/client')
| -rw-r--r-- | src/client/panes/plugin_pane.rs | 4 | ||||
| -rw-r--r-- | src/client/panes/terminal_pane.rs | 52 | ||||
| -rw-r--r-- | src/client/tab.rs | 8 |
3 files changed, 26 insertions, 38 deletions
diff --git a/src/client/panes/plugin_pane.rs b/src/client/panes/plugin_pane.rs index caf49acc..49cf2aee 100644 --- a/src/client/panes/plugin_pane.rs +++ b/src/client/panes/plugin_pane.rs @@ -1,6 +1,6 @@ #![allow(clippy::clippy::if_same_then_else)] -use crate::{common::SenderWithContext, pty_bus::VteEvent, tab::Pane, wasm_vm::PluginInstruction}; +use crate::{common::SenderWithContext, pty_bus::VteBytes, tab::Pane, wasm_vm::PluginInstruction}; use std::{sync::mpsc::channel, unimplemented}; @@ -79,7 +79,7 @@ impl Pane for PluginPane { self.position_and_size_override = Some(position_and_size_override); self.should_render = true; } - fn handle_event(&mut self, _event: VteEvent) { + fn handle_pty_bytes(&mut self, _event: VteBytes) { unimplemented!() } fn cursor_coordinates(&self) -> Option<(usize, usize)> { diff --git a/src/client/panes/terminal_pane.rs b/src/client/panes/terminal_pane.rs index 13575475..d2473ba3 100644 --- a/src/client/panes/terminal_pane.rs +++ b/src/client/panes/terminal_pane.rs @@ -3,15 +3,14 @@ use crate::tab::Pane; use ::nix::pty::Winsize; use ::std::os::unix::io::RawFd; -use ::vte::Perform; use std::fmt::Debug; use crate::panes::grid::Grid; use crate::panes::terminal_character::{ CharacterStyles, TerminalCharacter, EMPTY_TERMINAL_CHARACTER, }; +use crate::pty_bus::VteBytes; use crate::utils::logging::debug_log_to_file; -use crate::VteEvent; #[derive(PartialEq, Eq, Ord, PartialOrd, Hash, Clone, Copy, Debug)] pub enum PaneId { @@ -86,34 +85,10 @@ impl Pane for TerminalPane { self.position_and_size_override = Some(position_and_size_override); self.reflow_lines(); } - fn handle_event(&mut self, event: VteEvent) { - match event { - VteEvent::Print(c) => { - self.print(c); - self.mark_for_rerender(); - } - VteEvent::Execute(byte) => { - self.execute(byte); - } - VteEvent::Hook(params, intermediates, ignore, c) => { - self.hook(¶ms, &intermediates, ignore, c); - } - VteEvent::Put(byte) => { - self.put(byte); - } - VteEvent::Unhook => { - self.unhook(); - } - VteEvent::OscDispatch(params, bell_terminated) => { - let params: Vec<&[u8]> = params.iter().map(|p| &p[..]).collect(); - self.osc_dispatch(¶ms[..], bell_terminated); - } - VteEvent::CsiDispatch(params, intermediates, ignore, c) => { - self.csi_dispatch(¶ms, &intermediates, ignore, c); - } - VteEvent::EscDispatch(intermediates, ignore, byte) => { - self.esc_dispatch(&intermediates, ignore, byte); - } + fn handle_pty_bytes(&mut self, bytes: VteBytes) { + let mut vte_parser = vte::Parser::new(); + for byte in bytes.iter() { + vte_parser.advance(self, *byte); } } fn cursor_coordinates(&self) -> Option<(usize, usize)> { @@ -379,6 +354,13 @@ impl TerminalPane { self.grid.rotate_scroll_region_down(count); self.mark_for_rerender(); } + fn reset_terminal_state(&mut self) { + let rows = self.get_rows(); + let columns = self.get_columns(); + self.grid = Grid::new(rows, columns); + self.alternative_grid = None; + self.cursor_key_mode = false; + } fn add_newline(&mut self) { let pad_character = EMPTY_TERMINAL_CHARACTER; self.grid.add_canonical_line(pad_character); @@ -678,8 +660,14 @@ impl vte::Perform for TerminalPane { } fn esc_dispatch(&mut self, intermediates: &[u8], _ignore: bool, byte: u8) { - if let (b'M', None) = (byte, intermediates.get(0)) { - self.grid.move_cursor_up_with_scrolling(1); + match (byte, intermediates.get(0)) { + (b'M', None) => { + self.grid.move_cursor_up_with_scrolling(1); + } + (b'c', None) => { + self.reset_terminal_state(); + } + _ => {} } } } diff --git a/src/client/tab.rs b/src/client/tab.rs index 08135499..35fc3915 100644 --- a/src/client/tab.rs +++ b/src/client/tab.rs @@ -6,7 +6,7 @@ use crate::common::{input::handler::parse_keys, AppInstruction, SenderWithContex use crate::layout::Layout; use crate::os_input_output::OsApi; use crate::panes::{PaneId, PositionAndSize, TerminalPane}; -use crate::pty_bus::{PtyInstruction, VteEvent}; +use crate::pty_bus::{PtyInstruction, VteBytes}; use crate::utils::shared::adjust_to_size; use crate::wasm_vm::PluginInstruction; use crate::{boundaries::Boundaries, panes::PluginPane}; @@ -94,7 +94,7 @@ pub trait Pane { fn reset_size_and_position_override(&mut self); fn change_pos_and_size(&mut self, position_and_size: &PositionAndSize); fn override_size_and_position(&mut self, x: usize, y: usize, size: &PositionAndSize); - fn handle_event(&mut self, event: VteEvent); + fn handle_pty_bytes(&mut self, bytes: VteBytes); fn cursor_coordinates(&self) -> Option<(usize, usize)>; fn adjust_input_to_terminal(&self, input_bytes: Vec<u8>) -> Vec<u8>; @@ -571,14 +571,14 @@ impl Tab { pub fn has_terminal_pid(&self, pid: RawFd) -> bool { self.panes.contains_key(&PaneId::Terminal(pid)) } - pub fn handle_pty_event(&mut self, pid: RawFd, event: VteEvent) { + pub fn handle_pty_bytes(&mut self, pid: RawFd, bytes: VteBytes) { // if we don't have the terminal in self.terminals it's probably because // of a race condition where the terminal was created in pty_bus but has not // yet been created in Screen. These events are currently not buffered, so // if you're debugging seemingly randomly missing stdout data, this is // the reason if let Some(terminal_output) = self.panes.get_mut(&PaneId::Terminal(pid)) { - terminal_output.handle_event(event); + terminal_output.handle_pty_bytes(bytes); } } pub fn write_to_active_terminal(&mut self, input_bytes: Vec<u8>) { |
