summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2021-12-31 00:18:02 -0500
committerJesse Luehrs <doy@tozt.net>2021-12-31 00:18:02 -0500
commita5179c4124e7fd8c4a1b31154d616e7a435477ae (patch)
treed64633e9360f5dc8984f6c87af52fb56f7d07fe8
parente6200649a87a7fdc04ad62b6348068d61f53925a (diff)
downloadnbsh-a5179c4124e7fd8c4a1b31154d616e7a435477ae.tar.gz
nbsh-a5179c4124e7fd8c4a1b31154d616e7a435477ae.zip
update pty_process
and make everything executed in a single command share a pty
-rw-r--r--Cargo.lock13
-rw-r--r--Cargo.toml5
-rw-r--r--src/state/history/mod.rs44
3 files changed, 33 insertions, 29 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 17eac54..88a9329 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -95,7 +95,7 @@ dependencies = [
[[package]]
name = "async-process"
version = "1.3.0"
-source = "git+https://github.com/doy/async-process?branch=status-drop#4438e61dac21d58c29ab4cc7d8152c829977a62d"
+source = "git+https://github.com/doy/async-process#5e25598d6fcf3865f2b9e106ba049a26a490a884"
dependencies = [
"async-io",
"blocking",
@@ -307,9 +307,9 @@ checksum = "88d1c26957f23603395cd326b0ffe64124b818f4449552f960d815cfba83a53d"
[[package]]
name = "futures-io"
-version = "0.3.17"
+version = "0.3.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "522de2a0fe3e380f1bc577ba0474108faf3f6b18321dbf60b3b9c39a75073377"
+checksum = "b1f9d34af5a1aac6fb380f735fe510746c38067c5bf16c7fd250280503c971b2"
[[package]]
name = "futures-lite"
@@ -482,9 +482,9 @@ dependencies = [
[[package]]
name = "nix"
-version = "0.23.0"
+version = "0.23.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f305c2c2e4c39a82f7bf0bf65fb557f9070ce06781d4f2454295cc34b1c43188"
+checksum = "9f866317acbd3a240710c63f065ffb1e4fd466259045ccb504130b7f668f35c6"
dependencies = [
"bitflags",
"cc",
@@ -601,11 +601,10 @@ dependencies = [
[[package]]
name = "pty-process"
version = "0.2.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b5c0159357669a990d96531d7095fd9d5eaa9f59d3d7d522f65b438dc8d1c109"
dependencies = [
"async-io",
"async-process",
+ "futures-io",
"libc",
"nix",
]
diff --git a/Cargo.toml b/Cargo.toml
index 1942ac4..47e83d2 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -15,7 +15,7 @@ nix = "0.23.0"
once_cell = "1.9.0"
pest = "2.1.3"
pest_derive = "2.1.0"
-pty-process = { version = "0.2.0", features = ["backend-async-std"] }
+pty-process = { version = "0.2.0", features = ["async"] }
signal-hook = "0.3.12"
signal-hook-async-std = "0.2.1"
terminal_size = "0.1.17"
@@ -27,4 +27,5 @@ vt100 = "0.15.0"
[patch.crates-io]
# https://github.com/smol-rs/async-process/pull/19
-async-process = { git = "https://github.com/doy/async-process", branch = "status-drop" }
+async-process = { git = "https://github.com/doy/async-process" }
+pty-process = { path = "../pty-process" }
diff --git a/src/state/history/mod.rs b/src/state/history/mod.rs
index 1df2f67..9091d78 100644
--- a/src/state/history/mod.rs
+++ b/src/state/history/mod.rs
@@ -1,6 +1,5 @@
use async_std::io::{ReadExt as _, WriteExt as _};
use futures_lite::future::FutureExt as _;
-use pty_process::Command as _;
use std::os::unix::process::ExitStatusExt as _;
mod builtins;
@@ -101,6 +100,7 @@ impl History {
ast.clone(),
ProcessEnv::new(
async_std::sync::Arc::clone(&entry),
+ self.size,
input_r,
resize_r,
event_w,
@@ -538,6 +538,7 @@ impl ExitInfo {
#[derive(Clone)]
pub struct ProcessEnv {
entry: async_std::sync::Arc<async_std::sync::Mutex<Entry>>,
+ pty: async_std::sync::Arc<pty_process::Pty>,
input_r: async_std::channel::Receiver<Vec<u8>>,
resize_r: async_std::channel::Receiver<(u16, u16)>,
event_w: async_std::channel::Sender<crate::event::Event>,
@@ -548,12 +549,16 @@ pub struct ProcessEnv {
impl ProcessEnv {
fn new(
entry: async_std::sync::Arc<async_std::sync::Mutex<Entry>>,
+ size: (u16, u16),
input_r: async_std::channel::Receiver<Vec<u8>>,
resize_r: async_std::channel::Receiver<(u16, u16)>,
event_w: async_std::channel::Sender<crate::event::Event>,
) -> Self {
+ let pty = pty_process::Pty::new().unwrap();
+ pty.resize(pty_process::Size::new(size.0, size.1)).unwrap();
Self {
entry,
+ pty: async_std::sync::Arc::new(pty),
input_r,
resize_r,
event_w,
@@ -570,6 +575,14 @@ impl ProcessEnv {
self.entry().await.vt.process(buf);
}
+ async fn read_pty(&self, buf: &mut [u8]) -> std::io::Result<usize> {
+ (&*self.pty).read(buf).await
+ }
+
+ async fn write_pty(&self, buf: &[u8]) -> std::io::Result<usize> {
+ (&*self.pty).write(buf).await
+ }
+
async fn read_input(
&self,
) -> Result<Vec<u8>, async_std::channel::RecvError> {
@@ -647,25 +660,17 @@ async fn run_binary(
exe: &crate::parse::Exe,
env: &ProcessEnv,
) -> async_std::process::ExitStatus {
- let mut process = async_std::process::Command::new(exe.exe());
+ let mut process = pty_process::Command::new(exe.exe());
process.args(exe.args());
- let size = env.entry().await.vt.screen().size();
- let child =
- process.spawn_pty(Some(&pty_process::Size::new(size.0, size.1)));
+ let child = process.spawn(&env.pty);
let child = match child {
Ok(child) => child,
Err(e) => {
let mut entry = env.entry().await;
- let e_str = match e {
- pty_process::Error::CreatePty(e)
- | pty_process::Error::SetTermSize(e)
- | pty_process::Error::Spawn(e) => {
- if let pty_process::Source::Io(e) = e {
- crate::format::io_error(&e)
- } else {
- e.to_string()
- }
- }
+ let e_str = if let pty_process::Error::Io(e) = e {
+ crate::format::io_error(&e)
+ } else {
+ e.to_string()
};
entry.vt.process(
format!("nbsh: {}: {}", e_str, exe.exe()).as_bytes(),
@@ -683,8 +688,7 @@ async fn run_binary(
),
}
let mut buf = [0_u8; 4096];
- let mut pty = child.pty();
- let read = async { Res::Read(pty.read(&mut buf).await) };
+ let read = async { Res::Read(env.read_pty(&mut buf).await) };
let write = async { Res::Write(env.read_input().await) };
let resize = async { Res::Resize(env.read_resize().await) };
let exit = async { Res::Exit(child.status_no_drop().await) };
@@ -715,7 +719,7 @@ async fn run_binary(
},
Res::Write(res) => match res {
Ok(bytes) => {
- pty.write(&bytes).await.unwrap();
+ env.write_pty(&bytes).await.unwrap();
}
Err(e) => {
panic!("failed to read from input channel: {}", e);
@@ -723,8 +727,8 @@ async fn run_binary(
},
Res::Resize(res) => match res {
Ok(size) => {
- child
- .resize_pty(&pty_process::Size::new(size.0, size.1))
+ env.pty
+ .resize(pty_process::Size::new(size.0, size.1))
.unwrap();
env.entry().await.vt.set_size(size.0, size.1);
}