From ebf7210ae6505ad62b7564252ebbbf3cea2637ce Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sat, 16 Feb 2019 08:21:21 -0800 Subject: [PATCH] stub out some windows vs unix bits --- src/main.rs | 22 ++++++++++++++++++---- src/winpty.rs | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 src/winpty.rs diff --git a/src/main.rs b/src/main.rs index 25addd8db..e03faaf39 100644 --- a/src/main.rs +++ b/src/main.rs @@ -44,11 +44,8 @@ extern crate xcb_util; #[cfg(all(unix, not(target_os = "macos")))] mod xwindows; -use std::env; -use std::ffi::CStr; use std::process::Command; use std::rc::Rc; -use std::str; mod config; @@ -67,19 +64,31 @@ use guiloop::{GuiEventLoop, TerminalWindow}; mod font; use font::FontConfiguration; +#[cfg(unix)] mod pty; +#[cfg(unix)] +pub use pty::{openpty, MasterPty, SlavePty}; +#[cfg(windows)] +mod winpty; +#[cfg(windows)] +pub use winpty::{openpty, MasterPty, SlavePty}; +#[cfg(unix)] mod sigchld; /// Determine which shell to run. /// We take the contents of the $SHELL env var first, then /// fall back to looking it up from the password database. +#[cfg(unix)] fn get_shell() -> Result { + use std::env; env::var("SHELL").or_else(|_| { let ent = unsafe { libc::getpwuid(libc::getuid()) }; if ent.is_null() { Ok("/bin/sh".into()) } else { + use std::ffi::CStr; + use std::str; let shell = unsafe { CStr::from_ptr((*ent).pw_shell) }; shell .to_str() @@ -89,6 +98,11 @@ fn get_shell() -> Result { }) } +#[cfg(windows)] +fn get_shell() -> Result { + bail!("you must specify which application to run") +} + // let message = "; ❤ 😍🤢\n\x1b[91;mw00t\n\x1b[37;104;m bleet\x1b[0;m."; // terminal.advance_bytes(message); // != @@ -162,7 +176,7 @@ fn spawn_window( let initial_pixel_width = initial_cols * metrics.cell_width.ceil() as u16; let initial_pixel_height = initial_rows * metrics.cell_height.ceil() as u16; - let (master, slave) = pty::openpty( + let (master, slave) = openpty( initial_rows, initial_cols, initial_pixel_width, diff --git a/src/winpty.rs b/src/winpty.rs new file mode 100644 index 000000000..eed2aba8f --- /dev/null +++ b/src/winpty.rs @@ -0,0 +1,37 @@ +use failure::Error; +use std::process::{Child, Command}; + +pub struct MasterPty {} +pub struct SlavePty {} +pub struct winsize {} + +impl MasterPty { + pub fn resize( + &self, + num_rows: u16, + num_cols: u16, + pixel_width: u16, + pixel_height: u16, + ) -> Result<(), Error> { + bail!("MasterPty::resize not implemented") + } + + pub fn get_size(&self) -> Result { + bail!("MasterPty::get_size not implemented") + } +} + +impl SlavePty { + pub fn spawn_command(self, mut cmd: Command) -> Result { + bail!("spawn_command not implemented") + } +} + +pub fn openpty( + num_rows: u16, + num_cols: u16, + pixel_width: u16, + pixel_height: u16, +) -> Result<(MasterPty, SlavePty), Error> { + bail!("openpty not implemented") +}