diff --git a/src/main.rs b/src/main.rs index 079b34c..384e120 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,10 @@ use std::{ collections::HashMap, os::mikros::{ipc, syscalls}, path::{Path, PathBuf}, - sync::Arc, + sync::{ + atomic::{AtomicBool, Ordering}, + Arc, + }, }; use parking_lot::{Mutex, RwLock}; @@ -16,6 +19,7 @@ struct Pty { input_buffer: Mutex>, output_buffer: Mutex>, termios: Termios, + output_paused: AtomicBool, } impl Pty { @@ -24,10 +28,14 @@ impl Pty { input_buffer: Mutex::new(Vec::new()), output_buffer: Mutex::new(Vec::new()), termios: Termios::default(), + output_paused: AtomicBool::new(false), } } fn read_master(&self, len: usize) -> Result, ()> { + if self.output_paused.load(Ordering::Relaxed) { + return Ok(vec![]); + } let mut output_buffer = self.output_buffer.lock(); let buf_len = output_buffer.len(); let rem_buf = output_buffer.split_off(usize::min(buf_len, len)); @@ -37,7 +45,7 @@ impl Pty { fn write_master(&self, data: &[u8]) -> Result<(), ()> { if !self.termios.cflags.cread { - return Ok(()) + return Ok(()); } let mut input_buffer = self.input_buffer.lock(); let mut output_buffer = self.output_buffer.lock(); @@ -66,6 +74,12 @@ impl Pty { } input_buffer.pop(); } + } else if byte as char == self.termios.vstop && self.termios.iflags.ixon { + self.output_paused.store(true, Ordering::Relaxed); + } else if (byte as char == self.termios.vstart && self.termios.iflags.ixon) + || (self.termios.iflags.ixany && self.output_paused.load(Ordering::Relaxed)) + { + self.output_paused.store(false, Ordering::Relaxed); } else { input_buffer.push(byte); if self.termios.lflags.echo || (byte == b'\n' && self.termios.lflags.echonl) { diff --git a/src/termios.rs b/src/termios.rs index 412cca5..181109b 100644 --- a/src/termios.rs +++ b/src/termios.rs @@ -27,7 +27,7 @@ impl Default for Iflags { istrip: false, ixany: false, ixoff: false, - ixon: false, + ixon: true, parmark: false, } }