summaryrefslogtreecommitdiffstats
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs38
1 files changed, 12 insertions, 26 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 66daaf9..e60a076 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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()
}