diff --git a/src/lib.rs b/src/lib.rs index d6c94238..d2fe4e8e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,13 +19,13 @@ //! Write markdown to TTYs. // Used by iTerm support on macos -// #[cfg(target_os = "macos")] +#[cfg(feature = "iterm2")] extern crate base64; -// #[cfg(target_os = "macos")] +#[cfg(feature = "iterm2")] extern crate mime; // Used by Terminology support -// #[cfg(all(unix, not(target_os = "macos")))] +#[cfg(feature = "terminology")] extern crate immeta; extern crate atty; @@ -50,11 +50,11 @@ use syntect::highlighting::{Theme, ThemeSet}; use syntect::parsing::SyntaxSet; // These modules support iterm2; we do not need them if iterm2 is off. -// #[cfg(target_os = "macos")] +#[cfg(feature = "iterm2")] mod magic; -// #[cfg(target_os = "macos")] +#[cfg(feature = "iterm2")] mod process; -// #[cfg(target_os = "macos")] +#[cfg(feature = "iterm2")] mod svg; mod resources; diff --git a/src/terminal/mod.rs b/src/terminal/mod.rs index 451bd04c..aa87d1e9 100644 --- a/src/terminal/mod.rs +++ b/src/terminal/mod.rs @@ -23,14 +23,18 @@ mod write; // Terminal implementations; mod ansi; mod dumb; +#[cfg(feature = "iterm2")] mod iterm2; +#[cfg(feature = "terminology")] mod terminology; mod vte50; use atty; use std::io; +#[cfg(feature = "iterm2")] use self::iterm2::*; +#[cfg(feature = "terminology")] use self::terminology::*; use self::vte50::*; @@ -53,15 +57,21 @@ pub use self::write::Terminal; pub fn detect_terminal() -> Box> { if atty::is(atty::Stream::Stdout) { let ansi = AnsiTerminal::new(io::stdout()); - if iterm2::is_iterm2() { - Box::new(ITerm2::new(ansi)) - } else if terminology::is_terminology() { - Box::new(Terminology::new(ansi)) - } else { - match vte50::get_vte_version() { + match true { + #[cfg(feature = "iterm2")] + _ if iterm2::is_iterm2() => + { + Box::new(ITerm2::new(ansi)) + } + #[cfg(feature = "terminology")] + _ if terminology::is_terminology() => + { + Box::new(Terminology::new(ansi)) + } + _ => match vte50::get_vte_version() { Some(version) if version >= (50, 0) => Box::new(VTE50Terminal::new(ansi)), _ => Box::new(ansi), - } + }, } } else { Box::new(DumbTerminal::new(io::stdout()))