diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 38 | ||||
-rw-r--r-- | src/main.rs | 3 |
2 files changed, 13 insertions, 28 deletions
@@ -178,17 +178,11 @@ impl<'a> TableSlice<'a> { /// as not beeing tty, and ANSI escape characters won't be displayed unless `force colorize` /// is set to `true`. /// # Returns - /// The number of lines printed - /// # Panic - /// Panic if writing to standard output fails - pub fn print_tty(&self, force_colorize: bool) -> usize { - let r = match (stdout(), atty::is(atty::Stream::Stdout) || force_colorize) { + /// A `Result` holding the number of lines printed, or an `io::Error` if any failure happens + pub fn print_tty(&self, force_colorize: bool) -> Result<usize, Error> { + match (stdout(), atty::is(atty::Stream::Stdout) || force_colorize) { (Some(mut o), true) => self.print_term(&mut *o), _ => self.print(&mut io::stdout()), - }; - match r { - Err(e) => panic!("Cannot print table to standard output : {}", e), - Ok(height) => height } } @@ -196,13 +190,10 @@ impl<'a> TableSlice<'a> { /// stdout is a tty terminal. This means that if stdout is redirected to a file, or piped /// to another program, no color will be displayed. /// To force colors rendering, use `print_tty()` method. - /// Calling `printstd()` is equivalent to calling `print_tty(false)` - /// # Returns - /// The number of lines printed - /// # Panic - /// Panic if writing to standard output fails - pub fn printstd(&self) -> usize { - self.print_tty(false) + /// Any failure to print is ignored. For better control, use `print_tty()`. + /// Calling `printstd()` is equivalent to calling `print_tty(false)` and ignoring the result. + pub fn printstd(&self) { + let _ = self.print_tty(false); // Ignore result } } @@ -352,10 +343,8 @@ impl Table { /// as not beeing tty, and ANSI escape characters won't be displayed unless `force colorize` /// is set to `true`. /// # Returns - /// The number of lines printed - /// # Panic - /// Panic if writing to standard output fails - pub fn print_tty(&self, force_colorize: bool) -> usize { + /// A `Result` holding the number of lines printed, or an `io::Error` if any failure happens + pub fn print_tty(&self, force_colorize: bool) -> Result<usize, Error> { self.as_ref().print_tty(force_colorize) } @@ -363,12 +352,9 @@ impl Table { /// stdout is a tty terminal. This means that if stdout is redirected to a file, or piped /// to another program, no color will be displayed. /// To force colors rendering, use `print_tty()` method. - /// Calling `printstd()` is equivalent to calling `print_tty(false)` - /// # Returns - /// The number of lines printed - /// # Panic - /// Panic if writing to standard output fails - pub fn printstd(&self) -> usize { + /// Any failure to print is ignored. For better control, use `print_tty()`. + /// Calling `printstd()` is equivalent to calling `print_tty(false)` and ignoring the result. + pub fn printstd(&self) { self.as_ref().printstd() } diff --git a/src/main.rs b/src/main.rs index 28d7b78..f18461b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -45,7 +45,6 @@ fn main() { table.set_titles(row!["Title 1", "Title 2"]); table.set_format(*consts::FORMAT_DEFAULT); table.get_format().indent(8); - let size = table.printstd(); - println!("Table height = {}", size); + table.printstd(); // println!("{:#?}", table); } |