use crate::{panes::PaneId, ClientId};
use async_std::{fs::File as AsyncFile, io::ReadExt, os::unix::io::FromRawFd};
use interprocess::local_socket::LocalSocketStream;
use nix::{
pty::{openpty, OpenptyResult, Winsize},
sys::{
signal::{kill, Signal},
termios,
},
unistd,
};
use signal_hook::consts::*;
use sysinfo::{ProcessExt, ProcessRefreshKind, System, SystemExt};
use zellij_utils::{
async_std, channels,
channels::TrySendError,
data::Palette,
errors::prelude::*,
input::command::{RunCommand, TerminalAction},
interprocess,
ipc::{
ClientToServerMsg, ExitReason, IpcReceiverWithContext, IpcSenderWithContext,
ServerToClientMsg,
},
libc, nix,
shared::default_palette,
signal_hook,
tempfile::tempfile,
};
use std::{
collections::{BTreeMap, BTreeSet, HashMap},
env,
fs::File,
io::Write,
os::unix::{io::RawFd, process::CommandExt},
path::PathBuf,
process::{Child, Command},
sync::{Arc, Mutex},
};
pub use async_trait::async_trait;
pub use nix::unistd::Pid;
fn set_terminal_size_using_fd(
fd: RawFd,
columns: u16,
rows: u16,
width_in_pixels: Option<u16>,
height_in_pixels: Option<u16>,
) {
// TODO: do this with the nix ioctl
use libc::ioctl;
use libc::TIOCSWINSZ;
let ws_xpixel = width_in_pixels.unwrap_or(0);
let ws_ypixel = height_in_pixels.unwrap_or(0);
let winsize = Winsize {
ws_col: columns,
ws_row: rows,
ws_xpixel,
ws_ypixel,
};
// TIOCGWINSZ is an u32, but the second argument to ioctl is u64 on
// some platforms. When checked on Linux, clippy will complain about
// useless conversion.
#[allow(clippy::useless_conversion)]
unsafe {
ioctl(fd, TIOCSWINSZ.into(), &winsize)
};
}
/// Handle some signals for the child process. This will loop until the child
/// process exits.
fn handle_command_exit(mut child: Child) -> Result<Option<