-use std::io::{self, Read, Write};
+use std::io::{self, IsTerminal, Read, Write};
use std::mem::MaybeUninit;
use std::os::unix::io::{AsRawFd, OwnedFd};
(winsize.ws_row as usize, winsize.ws_col as usize)
}
-/// Returns whether the current stdout is a tty .
-/// # Safety
-///
-/// uses unsafe call to libc::isatty
+/// Returns whether the current stdout is a tty.
+#[deprecated(note = "Use std::io::stdout().is_terminal()")]
pub fn stdout_isatty() -> bool {
- unsafe { libc::isatty(std::io::stdin().as_raw_fd()) == 1 }
+ std::io::stdout().is_terminal()
}
-/// Returns whether the current stdin is a tty .
-/// # Safety
-///
-/// uses unsafe call to libc::isatty
+/// Returns whether the current stdin is a tty.
+#[deprecated(note = "Use std::io::stdin().is_terminal()")]
pub fn stdin_isatty() -> bool {
- unsafe { libc::isatty(std::io::stdin().as_raw_fd()) == 1 }
+ std::io::stdin().is_terminal()
}
pub enum TtyOutput {
/// Get an output file descriptor for the current terminal.
pub fn open() -> io::Result<Option<Self>> {
let stdout = std::io::stdout();
- if unsafe { libc::isatty(stdout.as_raw_fd()) } == 1 {
+ if stdout.is_terminal() {
Ok(Some(TtyOutput::Stdout(stdout)))
} else {
match crate::fd::open(
/// first.
pub fn read_password(query: &str) -> Result<Vec<u8>, Error> {
let input = std::io::stdin();
- if unsafe { libc::isatty(input.as_raw_fd()) } != 1 {
+ if !input.is_terminal() {
let mut out = String::new();
input.read_line(&mut out)?;
return Ok(out.into_bytes());