mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-02 05:41:16 -03:00
Add io_streams_t::out_is_terminal()
This encapsulates a "is our output going to the terminal" check we do in a few places - functions, type, set_color, possibly test
This commit is contained in:
@@ -7,6 +7,9 @@
|
||||
use crate::wgetopt::{wgetopter_t, wopt, woption, woption_argument_t};
|
||||
use cxx::{type_id, ExternType};
|
||||
use libc::c_int;
|
||||
use libc::isatty;
|
||||
use libc::STDOUT_FILENO;
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::fs::File;
|
||||
use std::io::{BufRead, BufReader, Read};
|
||||
@@ -164,6 +167,10 @@ pub fn ffi_ref(&self) -> &builtins_ffi::io_streams_t {
|
||||
unsafe { &*self.streams }
|
||||
}
|
||||
|
||||
pub fn out_is_terminal(&self) -> bool {
|
||||
!self.out_is_redirected && unsafe { isatty(STDOUT_FILENO) == 1 }
|
||||
}
|
||||
|
||||
pub fn stdin_is_directly_redirected(&self) -> bool {
|
||||
self.ffi_ref().ffi_stdin_is_directly_redirected()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user