Add XON/XOFF support
This commit is contained in:
parent
e5144a8e6e
commit
63012f5e37
18
src/main.rs
18
src/main.rs
@ -5,7 +5,10 @@ use std::{
|
|||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
os::mikros::{ipc, syscalls},
|
os::mikros::{ipc, syscalls},
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
sync::Arc,
|
sync::{
|
||||||
|
atomic::{AtomicBool, Ordering},
|
||||||
|
Arc,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
use parking_lot::{Mutex, RwLock};
|
use parking_lot::{Mutex, RwLock};
|
||||||
@ -16,6 +19,7 @@ struct Pty {
|
|||||||
input_buffer: Mutex<Vec<u8>>,
|
input_buffer: Mutex<Vec<u8>>,
|
||||||
output_buffer: Mutex<Vec<u8>>,
|
output_buffer: Mutex<Vec<u8>>,
|
||||||
termios: Termios,
|
termios: Termios,
|
||||||
|
output_paused: AtomicBool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Pty {
|
impl Pty {
|
||||||
@ -24,10 +28,14 @@ impl Pty {
|
|||||||
input_buffer: Mutex::new(Vec::new()),
|
input_buffer: Mutex::new(Vec::new()),
|
||||||
output_buffer: Mutex::new(Vec::new()),
|
output_buffer: Mutex::new(Vec::new()),
|
||||||
termios: Termios::default(),
|
termios: Termios::default(),
|
||||||
|
output_paused: AtomicBool::new(false),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_master(&self, len: usize) -> Result<Vec<u8>, ()> {
|
fn read_master(&self, len: usize) -> Result<Vec<u8>, ()> {
|
||||||
|
if self.output_paused.load(Ordering::Relaxed) {
|
||||||
|
return Ok(vec![]);
|
||||||
|
}
|
||||||
let mut output_buffer = self.output_buffer.lock();
|
let mut output_buffer = self.output_buffer.lock();
|
||||||
let buf_len = output_buffer.len();
|
let buf_len = output_buffer.len();
|
||||||
let rem_buf = output_buffer.split_off(usize::min(buf_len, 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<(), ()> {
|
fn write_master(&self, data: &[u8]) -> Result<(), ()> {
|
||||||
if !self.termios.cflags.cread {
|
if !self.termios.cflags.cread {
|
||||||
return Ok(())
|
return Ok(());
|
||||||
}
|
}
|
||||||
let mut input_buffer = self.input_buffer.lock();
|
let mut input_buffer = self.input_buffer.lock();
|
||||||
let mut output_buffer = self.output_buffer.lock();
|
let mut output_buffer = self.output_buffer.lock();
|
||||||
@ -66,6 +74,12 @@ impl Pty {
|
|||||||
}
|
}
|
||||||
input_buffer.pop();
|
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 {
|
} else {
|
||||||
input_buffer.push(byte);
|
input_buffer.push(byte);
|
||||||
if self.termios.lflags.echo || (byte == b'\n' && self.termios.lflags.echonl) {
|
if self.termios.lflags.echo || (byte == b'\n' && self.termios.lflags.echonl) {
|
||||||
|
@ -27,7 +27,7 @@ impl Default for Iflags {
|
|||||||
istrip: false,
|
istrip: false,
|
||||||
ixany: false,
|
ixany: false,
|
||||||
ixoff: false,
|
ixoff: false,
|
||||||
ixon: false,
|
ixon: true,
|
||||||
parmark: false,
|
parmark: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user