Move isatty() to utils.rs
This commit is contained in:
parent
a1d28bf41c
commit
831db35a83
2 changed files with 20 additions and 19 deletions
|
|
@ -12,6 +12,7 @@ use diff;
|
|||
use std::collections::VecDeque;
|
||||
use std::io;
|
||||
use term;
|
||||
use utils::isatty;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum DiffLine {
|
||||
|
|
@ -105,25 +106,6 @@ where
|
|||
}
|
||||
_ => print_diff_basic(diff, get_section_title),
|
||||
}
|
||||
|
||||
// isatty shamelessly adapted from cargo.
|
||||
#[cfg(unix)]
|
||||
fn isatty() -> bool {
|
||||
extern crate libc;
|
||||
|
||||
unsafe { libc::isatty(libc::STDOUT_FILENO) != 0 }
|
||||
}
|
||||
#[cfg(windows)]
|
||||
fn isatty() -> bool {
|
||||
extern crate kernel32;
|
||||
extern crate winapi;
|
||||
|
||||
unsafe {
|
||||
let handle = kernel32::GetStdHandle(winapi::winbase::STD_OUTPUT_HANDLE);
|
||||
let mut out = 0;
|
||||
kernel32::GetConsoleMode(handle, &mut out) != 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn print_diff_fancy<F>(
|
||||
|
|
|
|||
19
src/utils.rs
19
src/utils.rs
|
|
@ -516,3 +516,22 @@ pub fn left_most_sub_expr(e: &ast::Expr) -> &ast::Expr {
|
|||
_ => e,
|
||||
}
|
||||
}
|
||||
|
||||
// isatty shamelessly adapted from cargo.
|
||||
#[cfg(unix)]
|
||||
pub fn isatty() -> bool {
|
||||
extern crate libc;
|
||||
|
||||
unsafe { libc::isatty(libc::STDOUT_FILENO) != 0 }
|
||||
}
|
||||
#[cfg(windows)]
|
||||
pub fn isatty() -> bool {
|
||||
extern crate kernel32;
|
||||
extern crate winapi;
|
||||
|
||||
unsafe {
|
||||
let handle = kernel32::GetStdHandle(winapi::winbase::STD_OUTPUT_HANDLE);
|
||||
let mut out = 0;
|
||||
kernel32::GetConsoleMode(handle, &mut out) != 0
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue