summaryrefslogtreecommitdiffstats
path: root/src/lib.rs
diff options
context:
space:
mode:
authorpierresy <pierre-henri.symoneaux@alcatel-lucent.com>2016-02-14 15:47:29 +0100
committerpierresy <pierre-henri.symoneaux@alcatel-lucent.com>2016-02-14 15:47:29 +0100
commit9806281ebec96854dbd74d45c3c3716c612e0ef3 (patch)
treee9a6bb6ec1ed49682cae70f54852f3835ed694ef /src/lib.rs
parenteaff73df9751b9c9163bca003f2be5a14ba40761 (diff)
Detect if attached to a tty standard output when calling Table.printstd().
Printing using term (for colors, etc...) is performed only if output is a tty, else, fallbacks to normal printing
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 7e373e1..b2e77e2 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,6 +1,7 @@
//! A formatted and aligned table printer written in rust
extern crate unicode_width;
extern crate term;
+extern crate atty;
#[macro_use] extern crate lazy_static;
use std::io;
@@ -147,9 +148,9 @@ impl <'a> TableSlice<'a> {
/// # Panic
/// Panic if writing to standard output fails
pub fn printstd(&self) {
- let r = match stdout() {
- Some(mut o) => self.print_term(&mut *o),
- None => self.print(&mut io::stdout()),
+ let r = match (stdout(), atty::is()) {
+ (Some(mut o), true) => self.print_term(&mut *o),
+ _ => self.print(&mut io::stdout()),
};
if let Err(e) = r {
panic!("Cannot print table to standard output : {}", e);