|
|
@ -23,10 +23,15 @@ use crate::terminal::position::*;
|
|
|
|
use melib::{error::*, log, ERROR};
|
|
|
|
use melib::{error::*, log, ERROR};
|
|
|
|
use smallvec::SmallVec;
|
|
|
|
use smallvec::SmallVec;
|
|
|
|
|
|
|
|
|
|
|
|
use nix::fcntl::{open, OFlag};
|
|
|
|
#[cfg(not(target_os = "macos"))]
|
|
|
|
|
|
|
|
use nix::{
|
|
|
|
|
|
|
|
fcntl::{open, OFlag},
|
|
|
|
|
|
|
|
pty::{grantpt, posix_openpt, ptsname, unlockpt},
|
|
|
|
|
|
|
|
sys::stat,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
use nix::libc::{STDERR_FILENO, STDIN_FILENO, STDOUT_FILENO};
|
|
|
|
use nix::libc::{STDERR_FILENO, STDIN_FILENO, STDOUT_FILENO};
|
|
|
|
use nix::pty::{grantpt, posix_openpt, ptsname, unlockpt, Winsize};
|
|
|
|
use nix::pty::Winsize;
|
|
|
|
use nix::sys::stat;
|
|
|
|
|
|
|
|
use nix::unistd::{dup2, fork, ForkResult};
|
|
|
|
use nix::unistd::{dup2, fork, ForkResult};
|
|
|
|
use nix::{ioctl_none_bad, ioctl_write_ptr_bad};
|
|
|
|
use nix::{ioctl_none_bad, ioctl_write_ptr_bad};
|
|
|
|
use std::ffi::{CString, OsStr};
|
|
|
|
use std::ffi::{CString, OsStr};
|
|
|
@ -43,6 +48,8 @@ pub use grid::{EmbedGrid, EmbedTerminal};
|
|
|
|
use libc::TIOCSCTTY;
|
|
|
|
use libc::TIOCSCTTY;
|
|
|
|
// ioctl request code to set window size of pty:
|
|
|
|
// ioctl request code to set window size of pty:
|
|
|
|
use libc::TIOCSWINSZ;
|
|
|
|
use libc::TIOCSWINSZ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(not(target_os = "macos"))]
|
|
|
|
use std::path::Path;
|
|
|
|
use std::path::Path;
|
|
|
|
|
|
|
|
|
|
|
|
use std::convert::TryFrom;
|
|
|
|
use std::convert::TryFrom;
|
|
|
@ -60,6 +67,8 @@ pub fn create_pty(
|
|
|
|
height: usize,
|
|
|
|
height: usize,
|
|
|
|
command: String,
|
|
|
|
command: String,
|
|
|
|
) -> Result<Arc<Mutex<EmbedTerminal>>> {
|
|
|
|
) -> Result<Arc<Mutex<EmbedTerminal>>> {
|
|
|
|
|
|
|
|
#[cfg(not(target_os = "macos"))]
|
|
|
|
|
|
|
|
let (master_fd, slave_name) = {
|
|
|
|
// Open a new PTY master
|
|
|
|
// Open a new PTY master
|
|
|
|
let master_fd = posix_openpt(OFlag::O_RDWR)?;
|
|
|
|
let master_fd = posix_openpt(OFlag::O_RDWR)?;
|
|
|
|
|
|
|
|
|
|
|
@ -70,8 +79,6 @@ pub fn create_pty(
|
|
|
|
// Get the name of the slave
|
|
|
|
// Get the name of the slave
|
|
|
|
let slave_name = unsafe { ptsname(&master_fd) }?;
|
|
|
|
let slave_name = unsafe { ptsname(&master_fd) }?;
|
|
|
|
|
|
|
|
|
|
|
|
// Try to open the slave
|
|
|
|
|
|
|
|
//let _slave_fd = open(Path::new(&slave_name), OFlag::O_RDWR, Mode::empty())?;
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
let winsize = Winsize {
|
|
|
|
let winsize = Winsize {
|
|
|
|
ws_row: <u16>::try_from(height).unwrap(),
|
|
|
|
ws_row: <u16>::try_from(height).unwrap(),
|
|
|
@ -83,9 +90,24 @@ pub fn create_pty(
|
|
|
|
let master_fd = master_fd.as_raw_fd();
|
|
|
|
let master_fd = master_fd.as_raw_fd();
|
|
|
|
unsafe { set_window_size(master_fd, &winsize)? };
|
|
|
|
unsafe { set_window_size(master_fd, &winsize)? };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
(master_fd, slave_name)
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
|
|
|
|
let (master_fd, slave_fd) = {
|
|
|
|
|
|
|
|
let winsize = Winsize {
|
|
|
|
|
|
|
|
ws_row: <u16>::try_from(height).unwrap(),
|
|
|
|
|
|
|
|
ws_col: <u16>::try_from(width).unwrap(),
|
|
|
|
|
|
|
|
ws_xpixel: 0,
|
|
|
|
|
|
|
|
ws_ypixel: 0,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let ends = nix::pty::openpty(Some(&winsize), None)?;
|
|
|
|
|
|
|
|
(ends.master, ends.slave)
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
let child_pid = match unsafe { fork()? } {
|
|
|
|
let child_pid = match unsafe { fork()? } {
|
|
|
|
ForkResult::Child => {
|
|
|
|
ForkResult::Child => {
|
|
|
|
|
|
|
|
#[cfg(not(target_os = "macos"))]
|
|
|
|
/* Open slave end for pseudoterminal */
|
|
|
|
/* Open slave end for pseudoterminal */
|
|
|
|
let slave_fd = open(Path::new(&slave_name), OFlag::O_RDWR, stat::Mode::empty())?;
|
|
|
|
let slave_fd = open(Path::new(&slave_name), OFlag::O_RDWR, stat::Mode::empty())?;
|
|
|
|
|
|
|
|
|
|
|
|