summaryrefslogtreecommitdiffstats
path: root/src/lib.rs
diff options
context:
space:
mode:
authorpierresy <pierre-henri.symoneaux@alcatel-lucent.com>2015-11-07 12:18:50 +0100
committerpierresy <pierre-henri.symoneaux@alcatel-lucent.com>2015-11-07 12:18:50 +0100
commit0837f83b7d50dfcd1d17025c6f09cde810c1b5c7 (patch)
treea5fc5d3882ee0d51aa2948ca8eb1c58e6de88176 /src/lib.rs
parentd499b48860de79733b41ad61f9f3b4657a614554 (diff)
Added dependency "term" and support to styles (color, etc ...)
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 08db98a..5ef830c 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,10 +1,13 @@
//! A formatted and aligned table printer written in rust
extern crate unicode_width;
+extern crate term;
-use std::io::{stdout, Write, Error};
+use std::io::{Write, Error};
use std::fmt;
use std::iter::{FromIterator, IntoIterator};
+use term::{Terminal, stdout};
+
pub mod cell;
pub mod row;
pub mod format;
@@ -172,11 +175,27 @@ impl Table {
return out.flush();
}
+ pub fn print_term<T: Terminal+?Sized>(&self, out: &mut T) -> Result<(), Error> {
+ // Compute columns width
+ let col_width = self.get_all_column_width();
+ try!(self.format.print_line_separator(out, &col_width));
+ if let Some(ref t) = self.titles {
+ try!(t.print_term(out, &self.format, &col_width));
+ try!(self.format.print_title_separator(out, &col_width));
+ }
+ // Print rows
+ for r in &self.rows {
+ try!(r.print_term(out, &self.format, &col_width));
+ try!(self.format.print_line_separator(out, &col_width));
+ }
+ return out.flush();
+ }
+
/// Print the table to standard output
/// # Panic
/// Panic if writing to standard output fails
pub fn printstd(&self) {
- self.print(&mut stdout())
+ self.print_term(&mut *stdout().unwrap())
.ok()
.expect("Cannot print table to standard output");
}