diff --git a/src/config.rs b/src/config.rs index d399a8ac2..b02ffdd91 100644 --- a/src/config.rs +++ b/src/config.rs @@ -4,6 +4,7 @@ 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 serde_derive::*; @@ -69,6 +70,9 @@ pub struct Config { #[serde(default)] pub front_end: FrontEndSelection, + #[serde(default)] + pub pty: PtySystemSelection, + /// When using the MuxServer, this specifies the path to the unix /// domain socket to use to communicate with the mux server. pub mux_server_unix_domain_socket_path: Option, @@ -104,6 +108,7 @@ impl Default for Config { font_rules: Vec::new(), font_system: FontSystemSelection::default(), front_end: FrontEndSelection::default(), + pty: PtySystemSelection::default(), colors: None, scrollback_lines: None, hyperlink_rules: default_hyperlink_rules(), diff --git a/src/main.rs b/src/main.rs index 52dd29eaa..28ed0d678 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,7 +28,7 @@ mod font; use crate::font::{FontConfiguration, FontSystemSelection}; mod pty; -use pty::{PtySize, PtySystemSelection}; +use pty::PtySize; use std::env; /// Determine which shell to run. @@ -200,7 +200,7 @@ fn spawn_tab( let initial_pixel_width = 0; let initial_pixel_height = 0; - let pty_sys = PtySystemSelection::default().get()?; + let pty_sys = config.pty.get()?; let (master, slave) = pty_sys.openpty(PtySize { rows: initial_rows, cols: initial_cols, diff --git a/src/pty/mod.rs b/src/pty/mod.rs index 9d73af008..0464034b9 100644 --- a/src/pty/mod.rs +++ b/src/pty/mod.rs @@ -1,4 +1,5 @@ use failure::Error; +use serde_derive::*; use std::io::Result as IoResult; pub mod cmdbuilder; @@ -82,6 +83,7 @@ impl Child for std::process::Child { } #[allow(dead_code)] +#[derive(Debug, Clone, Copy, Deserialize)] pub enum PtySystemSelection { Unix, ConPty, @@ -93,7 +95,7 @@ impl PtySystemSelection { pub fn get(&self) -> Result, Error> { match self { PtySystemSelection::Unix => Ok(Box::new(unix::UnixPtySystem {})), - _ => bail!("{:?} not available on unix"), + _ => bail!("{:?} not available on unix", self), } } #[cfg(windows)] @@ -101,7 +103,27 @@ impl PtySystemSelection { match self { PtySystemSelection::ConPty => Ok(Box::new(win::conpty::ConPtySystem {})), PtySystemSelection::WinPty => Ok(Box::new(win::winpty::WinPtySystem {})), - _ => bail!("{:?} not available on Windows"), + _ => bail!("{:?} not available on Windows", self), + } + } + + pub fn variants() -> Vec<&'static str> { + vec!["Unix", "ConPty", "WinPty"] + } +} + +impl std::str::FromStr for PtySystemSelection { + type Err = Error; + fn from_str(s: &str) -> Result { + match s.to_lowercase().as_ref() { + "unix" => Ok(PtySystemSelection::Unix), + "winpty" => Ok(PtySystemSelection::WinPty), + "conpty" => Ok(PtySystemSelection::ConPty), + _ => Err(format_err!( + "{} is not a valid PtySystemSelection variant, possible values are {:?}", + s, + PtySystemSelection::variants() + )), } } }