1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
//! atty is a simple utility that answers one question //! > is this a tty? //! //! usage is just as simple //! //! ``` //! if atty::is() { //! println!("i'm a tty") //! } //! ``` //! //! ``` //! if atty::isnt() { //! println!("i'm not a tty") //! } //! ``` extern crate libc; /// returns true if this is a tty pub fn is() -> bool { let r = unsafe { libc::isatty(libc::STDOUT_FILENO) }; r != 0 } /// returns true if this is _not_ a tty pub fn isnt() -> bool { !is() } #[test] fn it_works() { }