1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
#[cfg(unix)]
mod unix;
#[cfg(unix)]
pub(crate) use unix::*;
#[cfg(windows)]
use portable_pty::{native_pty_system, Child, CommandBuilder, MasterPty, PtySize};
#[cfg(windows)]
pub(crate) struct SpawnedPty {
pub master: Box<dyn MasterPty + Send>,
pub child: Box<dyn Child + Send + Sync>,
}
#[cfg(windows)]
pub(crate) fn spawn_with_portable_pty(
rows: u16,
cols: u16,
cmd: CommandBuilder,
) -> std::io::Result<SpawnedPty> {
let pty_system = native_pty_system();
let pair = pty_system
.openpty(PtySize {
rows,
cols,
pixel_width: 0,
pixel_height: 0,
})
.map_err(|err| std::io::Error::other(err.to_string()))?;
let child = pair
.slave
.spawn_command(cmd)
.map_err(|err| std::io::Error::other(err.to_string()))?;
Ok(SpawnedPty {
master: pair.master,
child,
})
}
|