Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
Make iterm2 and terminology optional
Browse files Browse the repository at this point in the history
  • Loading branch information
swsnr committed Aug 25, 2018
1 parent c3e4fd4 commit 0d620ec
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
24 changes: 17 additions & 7 deletions src/terminal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;

Expand All @@ -53,15 +57,21 @@ pub use self::write::Terminal;
pub fn detect_terminal() -> Box<Terminal<TerminalWrite = io::Stdout>> {
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()))
Expand Down

0 comments on commit 0d620ec

Please sign in to comment.