-
-
Notifications
You must be signed in to change notification settings - Fork 781
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
publish the pty module to crates.io #27
Comments
Sorry for the delay: I only just saw this (for some reason, I wasn't getting any notifications for this project at all: now fixed!) I don't have a strong objection to the idea, but want to note that I didn't design this to be a general pty solution, but rather one targeted for wezterm, so I wonder just how useful this is beyond wezterm. Can you share more on how you intend to use it? Do you have thoughts and feedback on the interface as it stands at the moment? |
The primary reason for this is because there are no cross platform pty crate for rust at all. Pty allows to create lot of other interesting programs such as tmux alternatives as there are non that works natively in windows. This seems to be in your readme so I’m looking forward to it :). I personally use dwm even for windows so I’m not worried about tabs https://github.com/prabirshrestha/dwm-win32. Also OpenGL doesn’t seem to play nicely on remote desktop alacritty/alacritty#1976. Wezterm also crashes with the same issue. |
Also one thing that is currently missing in pty is working directory. |
I published it as https://crates.io/crates/portable-pty; the docs should show up at https://docs.rs/portable-pty once it has been ingested by docs.rs. I didn't add an api for setting the cwd, but it should be pretty straight forward to add support for that to the CommandBuilder if someone needs it (PRs welcome!) |
Thanks for making the crate. Now when I'm trying to run spawn a simple command I get the following error when running on win10.0.17763.437. use portable_pty::{CommandBuilder, PtySize, PtySystemSelection};
fn main() {
let pty_system = PtySystemSelection::default().get().unwrap();
let (mut _master, slave) = pty_system.openpty(PtySize {
rows: 24,
cols: 80,
pixel_width: 0,
pixel_height: 0
}).unwrap();
let cmd = CommandBuilder::new("c:\\WINDOWS\\system32\\whoami.exe");
let _child = slave.spawn_command(cmd).unwrap();
} output for cargo run:
Let me know if I'm doing something wrong here. |
I just added an example that works on macos; I think there's a good chance that it will also run unmodified on windows. The key difference from your code snippet above is that it waits for the child process and reads from it. I suspect that the issue you hit is that the pty is being dropped as the child is starting up, because it isn't waiting for the child. https://github.com/wez/wezterm/blob/master/pty/examples/whoami.rs |
The example no longer crashes on windows but seems to hang now. If I remove this line it doesn't hang |
So tried this and seems like it is getting stuck in buffer read hence This is the new code that I ran on Windows and ArchLinux and seem to given different output. use std::io::{BufRead, BufReader};
use portable_pty::{CommandBuilder, PtySize, PtySystemSelection};
fn main() {
let pty_system = PtySystemSelection::default().get().unwrap();
let (master, slave) = pty_system
.openpty(PtySize {
rows: 24,
cols: 80,
pixel_width: 0,
pixel_height: 0,
})
.unwrap();
let cmd = CommandBuilder::new("whoami");
let mut child = slave.spawn_command(cmd).unwrap();
let reader = master.try_clone_reader().unwrap();
let br = BufReader::new(reader);
for line in br.lines() {
println!("{}", line.unwrap());
match child.try_wait().unwrap() {
Some(e) => { println!("Some({})", e.success()); return; },
None => { println!("None"); return; },
_ => { println!("_"); return; }
}
}
} Output on windows is always the following.
Output on ArchLinux is random, sometime
What would be the best way to keep buffering but once the child exits stop reading and quit the program. Also seems like the actual status code is not exposed to public. |
would something like this work? (sorry about the formatting Im on phone) loop {
match child.try_wait() {
Ok(None) => continue,
Err(e) => reteurn Err(e),
Ok(Some(status)) => if status.is_sucess() {
return Ok(())
} else {
return io::Error::last_os_err()
} } |
Example output on linux: ``` child status: ExitStatus { successful: true } output: wez\r\n% ``` Example output on windows: ``` child status: ExitStatus { successful: true } output: \u{1b}[2J\u{1b}[?25l\u{1b}[m\u{1b}[HDOMAIN\\wez\u{8}\u{1b}]0;C:\\windows\\system32\\whoami.EXE\u{0}\u{7}\u{1b}[?25h ``` Refs: #27
I've pushed an updated example with comments inline that should help understand where the blocking is happening |
It works now. Thanks for the detailed comments in the example. That was very helpful. |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
Would it be possible to publish the pty module as a crate that can be reused by other programs?
Currently there is non in rust that works on all 3 major OS.
I had made similar request here alacritty/alacritty#2079
The text was updated successfully, but these errors were encountered: