diff options
author | Thomas Linford <tlinford@users.noreply.github.com> | 2022-05-16 21:14:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-16 21:14:57 +0200 |
commit | e8f955906293fcfe84d73a8af4a3c7f458708d06 (patch) | |
tree | ce45348a986896bae8db99cab174de5a96169b21 /zellij-server/src/pty_writer.rs | |
parent | 69e570cf710abc34bd7f5ec39a27d4b1c71bf233 (diff) |
fix(pty): paste freeze with large amounts of text (#1383)
add pty writer thread to avoid screen thread blocking on unistd::write
Diffstat (limited to 'zellij-server/src/pty_writer.rs')
-rw-r--r-- | zellij-server/src/pty_writer.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/zellij-server/src/pty_writer.rs b/zellij-server/src/pty_writer.rs new file mode 100644 index 000000000..9cdcd9769 --- /dev/null +++ b/zellij-server/src/pty_writer.rs @@ -0,0 +1,34 @@ +use zellij_utils::errors::{ContextType, PtyWriteContext}; + +use crate::thread_bus::Bus; + +#[derive(Debug, Clone)] +pub(crate) enum PtyWriteInstruction { + Write(Vec<u8>, i32), +} + +impl From<&PtyWriteInstruction> for PtyWriteContext { + fn from(tty_write_instruction: &PtyWriteInstruction) -> Self { + match *tty_write_instruction { + PtyWriteInstruction::Write(..) => PtyWriteContext::Write, + } + } +} + +pub(crate) fn pty_writer_main(bus: Bus<PtyWriteInstruction>) { + loop { + let (event, mut err_ctx) = bus.recv().expect("failed to receive event on channel"); + err_ctx.add_call(ContextType::PtyWrite((&event).into())); + let os_input = bus.os_input.clone().unwrap(); + match event { + PtyWriteInstruction::Write(bytes, terminal_id) => { + if let Err(e) = os_input.write_to_tty_stdin(terminal_id, &bytes) { + log::error!("failed to write to terminal: {}", e); + } + if let Err(e) = os_input.tcdrain(terminal_id) { + log::error!("failed to drain terminal: {}", e); + }; + } + } + } +} |