diff --git a/Cargo.toml b/Cargo.toml index 1cacbe6ed..f23886ddb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,6 +30,7 @@ leb128 = "0.2" libc = "0.2" open = "1.2" palette = "0.4" +portable-pty = { path = "pty", features = ["serde_support"]} promise = { path = "promise" } rayon = "1.0" serde = {version="1.0", features = ["rc"]} diff --git a/pty/Cargo.toml b/pty/Cargo.toml new file mode 100644 index 000000000..bad50999a --- /dev/null +++ b/pty/Cargo.toml @@ -0,0 +1,33 @@ +[package] +name = "portable-pty" +version = "0.1.0" +authors = ["Wez Furlong"] +edition = "2018" +repository = "https://github.com/wez/wezterm" +description = "Cross platform pty interface" +license = "MIT" +documentation = "https://docs.rs/portable-pty" + +[dependencies] +failure = "0.1" +failure_derive = "0.1" +libc = "0.2" +serde_derive = {version="1.0", optional=true} +serde = {version="1.0", optional=true} + +[features] +default = [] +serde_support = ["serde", "serde_derive"] + +[target."cfg(windows)".dependencies] +shared_library = "0.1" +uds_windows = "0.1" +winapi = { version = "0.3", features = [ + "winuser", + "consoleapi", + "handleapi", + "fileapi", + "namedpipeapi", + "synchapi", +]} + diff --git a/src/pty/cmdbuilder.rs b/pty/src/cmdbuilder.rs similarity index 100% rename from src/pty/cmdbuilder.rs rename to pty/src/cmdbuilder.rs diff --git a/src/pty/mod.rs b/pty/src/lib.rs similarity index 95% rename from src/pty/mod.rs rename to pty/src/lib.rs index 8b02ded33..d15575df0 100644 --- a/src/pty/mod.rs +++ b/pty/src/lib.rs @@ -1,4 +1,5 @@ -use failure::Error; +use failure::{bail, format_err, Error}; +#[cfg(feature = "serde_support")] use serde_derive::*; use std::io::Result as IoResult; @@ -83,7 +84,8 @@ impl Child for std::process::Child { } #[allow(dead_code)] -#[derive(Debug, Clone, Copy, Deserialize)] +#[derive(Debug, Clone, Copy)] +#[cfg_attr(feature = "serde_support", derive(Deserialize))] pub enum PtySystemSelection { Unix, ConPty, diff --git a/src/pty/unix.rs b/pty/src/unix.rs similarity index 98% rename from src/pty/unix.rs rename to pty/src/unix.rs index 73d0b4903..5ce094124 100644 --- a/src/pty/unix.rs +++ b/pty/src/unix.rs @@ -1,7 +1,7 @@ //! Working with pseudo-terminals -use crate::pty::{Child, CommandBuilder, MasterPty, PtySize, PtySystem, SlavePty}; -use failure::Error; +use crate::{Child, CommandBuilder, MasterPty, PtySize, PtySystem, SlavePty}; +use failure::{bail, Error}; use libc::{self, winsize}; use std::io; use std::mem; diff --git a/src/pty/win/conpty.rs b/pty/src/win/conpty.rs similarity index 98% rename from src/pty/win/conpty.rs rename to pty/src/win/conpty.rs index 906ae70fa..39fc9a4d6 100644 --- a/src/pty/win/conpty.rs +++ b/pty/src/win/conpty.rs @@ -1,7 +1,7 @@ use super::ownedhandle::OwnedHandle; use super::WinChild; -use crate::pty::cmdbuilder::CommandBuilder; -use crate::pty::{Child, MasterPty, PtySize, PtySystem, SlavePty}; +use crate::cmdbuilder::CommandBuilder; +use crate::{Child, MasterPty, PtySize, PtySystem, SlavePty}; use failure::Error; use lazy_static::lazy_static; use shared_library::shared_library; diff --git a/src/pty/win/mod.rs b/pty/src/win/mod.rs similarity index 97% rename from src/pty/win/mod.rs rename to pty/src/win/mod.rs index e6f4b7518..c0c506beb 100644 --- a/src/pty/win/mod.rs +++ b/pty/src/win/mod.rs @@ -1,4 +1,4 @@ -use crate::pty::{Child, ExitStatus}; +use crate::{Child, ExitStatus}; use std::io::{Error as IoError, Result as IoResult}; use winapi::shared::minwindef::DWORD; use winapi::um::minwinbase::STILL_ACTIVE; diff --git a/src/pty/win/ownedhandle.rs b/pty/src/win/ownedhandle.rs similarity index 100% rename from src/pty/win/ownedhandle.rs rename to pty/src/win/ownedhandle.rs diff --git a/src/pty/win/winpty/mod.rs b/pty/src/win/winpty/mod.rs similarity index 96% rename from src/pty/win/winpty/mod.rs rename to pty/src/win/winpty/mod.rs index 0b7f2b5a5..93b54a2c1 100644 --- a/src/pty/win/winpty/mod.rs +++ b/pty/src/win/winpty/mod.rs @@ -1,7 +1,7 @@ use super::ownedhandle::OwnedHandle; use super::WinChild; -use crate::pty::cmdbuilder::CommandBuilder; -use crate::pty::{Child, MasterPty, PtySize, PtySystem, SlavePty}; +use crate::cmdbuilder::CommandBuilder; +use crate::{Child, MasterPty, PtySize, PtySystem, SlavePty}; use failure::Error; use safe::{AgentFlags, MouseMode, SpawnConfig, SpawnFlags, Timeout, WinPty, WinPtyConfig}; use std::ffi::OsString; diff --git a/src/pty/win/winpty/safe.rs b/pty/src/win/winpty/safe.rs similarity index 99% rename from src/pty/win/winpty/safe.rs rename to pty/src/win/winpty/safe.rs index 3c97be32a..484cb6a98 100644 --- a/src/pty/win/winpty/safe.rs +++ b/pty/src/win/winpty/safe.rs @@ -3,7 +3,7 @@ //! https://github.com/rprichard/winpty/blob/master/src/include/winpty.h #![allow(dead_code)] use super::sys::*; -use crate::pty::win::ownedhandle::OwnedHandle; +use crate::win::ownedhandle::OwnedHandle; use bitflags::bitflags; use failure::{format_err, Error}; use std::ffi::{OsStr, OsString}; diff --git a/src/pty/win/winpty/sys.rs b/pty/src/win/winpty/sys.rs similarity index 100% rename from src/pty/win/winpty/sys.rs rename to pty/src/win/winpty/sys.rs diff --git a/src/config.rs b/src/config.rs index b02ffdd91..162d1265f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -3,10 +3,9 @@ use crate::font::FontSystemSelection; use crate::frontend::FrontEndSelection; use crate::get_shell; -use crate::pty::CommandBuilder; -use crate::pty::PtySystemSelection; use failure::{err_msg, Error}; use lazy_static::lazy_static; +use portable_pty::{CommandBuilder, PtySystemSelection}; use serde_derive::*; use std; use std::ffi::OsStr; diff --git a/src/frontend/guicommon/localtab.rs b/src/frontend/guicommon/localtab.rs index 33ffc9190..d0215fc24 100644 --- a/src/frontend/guicommon/localtab.rs +++ b/src/frontend/guicommon/localtab.rs @@ -1,7 +1,7 @@ use crate::mux::renderable::Renderable; use crate::mux::tab::{alloc_tab_id, Tab, TabId}; -use crate::pty::{Child, MasterPty, PtySize}; use failure::Error; +use portable_pty::{Child, MasterPty, PtySize}; use std::cell::{RefCell, RefMut}; use term::{KeyCode, KeyModifiers, MouseEvent, Terminal, TerminalHost}; diff --git a/src/frontend/guicommon/window.rs b/src/frontend/guicommon/window.rs index 381c3c8b5..77028101b 100644 --- a/src/frontend/guicommon/window.rs +++ b/src/frontend/guicommon/window.rs @@ -6,9 +6,9 @@ use crate::mux::window::WindowId; use crate::mux::Mux; use crate::opengl::render::Renderer; use crate::opengl::textureatlas::OutOfTextureSpace; -use crate::pty::{PtySize, PtySystemSelection}; use failure::Error; use glium; +use portable_pty::{PtySize, PtySystemSelection}; use std::rc::Rc; use std::sync::Arc; diff --git a/src/main.rs b/src/main.rs index 28ed0d678..beae22c37 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,8 +27,7 @@ use crate::mux::Mux; mod font; use crate::font::{FontConfiguration, FontSystemSelection}; -mod pty; -use pty::PtySize; +use portable_pty::PtySize; use std::env; /// Determine which shell to run. diff --git a/src/mux/mod.rs b/src/mux/mod.rs index 520c65a82..c2e48ca8d 100644 --- a/src/mux/mod.rs +++ b/src/mux/mod.rs @@ -1,6 +1,6 @@ use crate::config::Config; -use crate::pty::ExitStatus; use failure::Error; +use portable_pty::ExitStatus; use promise::{Executor, Future}; use std::cell::{Ref, RefCell, RefMut}; use std::collections::HashMap;