소스 검색

fix: use `std::io::IsTerminal` to eliminate compatibility issue

Previsouly we tried to use `terminal_size_using_fd` on unix, and `terminal_size_using_handle` on windows to detect if stdout is connected to a terminal.
This can be done by using `std::io::IsTerminal` on `std::io::stdout`, eliminating the need of conditional compiling.
hehelego 2 년 전
부모
커밋
c7aaecc2f0
1개의 변경된 파일3개의 추가작업 그리고 15개의 파일을 삭제
  1. 3 15
      src/main.rs

+ 3 - 15
src/main.rs

@@ -23,7 +23,7 @@
 
 use std::env;
 use std::ffi::{OsStr, OsString};
-use std::io::{self, ErrorKind, Write};
+use std::io::{self, ErrorKind, IsTerminal, Write};
 use std::path::{Component, PathBuf};
 use std::process::exit;
 
@@ -57,20 +57,8 @@ fn main() {
     if let Err(e) = ansiterm::enable_ansi_support() {
         warn!("Failed to enable ANSI support: {}", e);
     }
-    #[cfg(unix)]
-    let stdout_istty = {
-        use std::os::fd::AsRawFd;
-        terminal_size::terminal_size_using_fd(io::stdout().as_raw_fd()).is_some()
-    };
-    #[cfg(windows)]
-    let stdout_istty = {
-        use std::os::windows::io::RawHandle;
-        use windows_sys::Win32::System::Console::{GetStdHandle, STD_OUTPUT_HANDLE};
-        terminal_size::terminal_size_using_handle(unsafe {
-            GetStdHandle(STD_OUTPUT_HANDLE) as RawHandle
-        })
-        .is_some()
-    };
+
+    let stdout_istty = io::stdout().is_terminal();
 
     let args: Vec<_> = env::args_os().skip(1).collect();
     match Options::parse(args.iter().map(std::convert::AsRef::as_ref), &LiveVars) {