Skip to content

Commit

Permalink
Merge pull request #11 from BurntSushi/windows-only-deps
Browse files Browse the repository at this point in the history
Use target specific dependencies.
  • Loading branch information
softprops authored Jan 14, 2017
2 parents af9735a + bcb96e4 commit ca2ab17
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ matrix:
- rust: nightly
- rust: beta
- rust: stable
- rust: 1.8.0
os:
- linux
- osx
Expand Down
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ repository = "https://github.com/softprops/atty"
keywords = ["terminal", "tty"]
license = "MIT"

[dependencies]
[target.'cfg(not(windows))'.dependencies]
libc = "0.2"
winapi = "0.2"

[target.'cfg(windows)'.dependencies]
kernel32-sys = "0.2"
winapi = "0.2"
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ environment:
- TARGET: nightly-i686-pc-windows-msvc
- TARGET: nightly-x86_64-pc-windows-gnu
- TARGET: nightly-i686-pc-windows-gnu
- TARGET: 1.6.0-x86_64-pc-windows-gnu
- TARGET: 1.8.0-x86_64-pc-windows-gnu
install:
- ps: Start-FileDownload "https://static.rust-lang.org/dist/rust-${env:TARGET}.exe" -FileName "rust-install.exe"
- ps: .\rust-install.exe /VERYSILENT /NORESTART /DIR="C:\rust" | Out-Null
Expand Down
19 changes: 16 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
//! }
//! ```
extern crate libc;

/// possible stream sources
pub enum Stream {
Stdout,
Expand All @@ -27,6 +25,8 @@ pub enum Stream {
/// returns true if this is a tty
#[cfg(unix)]
pub fn is(stream: Stream) -> bool {
extern crate libc;

let fd = match stream {
Stream::Stdout => libc::STDOUT_FILENO,
Stream::Stderr => libc::STDERR_FILENO,
Expand Down Expand Up @@ -91,14 +91,27 @@ mod tests {
assert!(is(Stream::Stdin))
}

#[test]
#[cfg(unix)]
fn is_err() {
assert!(is(Stream::Stderr))
}

#[test]
#[cfg(unix)]
fn is_out() {
assert!(is(Stream::Stdout))
}

#[test]
#[cfg(unix)]
#[cfg(target_os = "macos")]
fn is_in() {
// macos on travis seems to pipe its input
assert!(!is(Stream::Stdin))
}

#[test]
#[cfg(all(not(target_os = "macos"), unix))]
fn is_in() {
assert!(is(Stream::Stdin))
}
Expand Down

0 comments on commit ca2ab17

Please sign in to comment.