summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonas Bushart <jonas@bushart.org>2019-01-20 18:10:23 +0100
committerJonas Bushart <jonas@bushart.org>2019-08-26 00:36:03 +0200
commit66b913fa54ca0ce700506125867c3ab117f7667f (patch)
tree2f8efd8f1c82faace06271949cd8b68ef90912dc
parent917e480a673d1ab03218702d0e9e726131e48799 (diff)
downloadprettytable-rs-66b913fa54ca0ce700506125867c3ab117f7667f.tar.gz
prettytable-rs-66b913fa54ca0ce700506125867c3ab117f7667f.tar.xz
Integrate the new HTML printing with Evcxr
* Add optional feature for Evcxr integration * Implement trait for everything which can be converted into a Tableslice. The trait prints the Tableslice in plain-text and HTML format in a Evcxr compatible manner.
-rw-r--r--Cargo.toml1
-rw-r--r--src/evcxr.rs30
-rw-r--r--src/lib.rs3
3 files changed, 34 insertions, 0 deletions
diff --git a/Cargo.toml b/Cargo.toml
index a3d0939..b6be3b1 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -20,6 +20,7 @@ codecov = { repository = "phsym/prettytable-rs", branch = "master", service = "g
[features]
default = ["win_crlf", "csv"]
+evcxr = []
win_crlf = []
[[bin]]
diff --git a/src/evcxr.rs b/src/evcxr.rs
new file mode 100644
index 0000000..11d632a
--- /dev/null
+++ b/src/evcxr.rs
@@ -0,0 +1,30 @@
+//! This modules contains traits and implementations to work within Evcxr
+
+use super::TableSlice;
+use super::utils::StringWriter;
+use std::io::Write;
+
+/// Evcxr specific output trait
+pub trait EvcxrDisplay {
+ /// Print self in one or multiple Evcxr compatile types.
+ fn evcxr_display(&self);
+}
+
+impl<'a, T> EvcxrDisplay for T
+where
+ T: AsRef<TableSlice<'a>>,
+{
+ fn evcxr_display(&self) {
+ let mut writer = StringWriter::new();
+ // Plain Text
+ let _ = writer.write_all(b"EVCXR_BEGIN_CONTENT text/plain\n");
+ let _ = self.as_ref().print(&mut writer);
+ let _ = writer.write_all(b"\nEVCXR_END_CONTENT\n");
+
+ // Html
+ let _ = writer.write_all(b"EVCXR_BEGIN_CONTENT text/html\n");
+ let _ = self.as_ref().print_html(&mut writer);
+ let _ = writer.write_all(b"\nEVCXR_END_CONTENT\n");
+ println!("{}", writer.as_string());
+ }
+}
diff --git a/src/lib.rs b/src/lib.rs
index 1e02055..9ccb008 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -24,6 +24,9 @@ mod utils;
#[cfg(feature = "csv")]
pub mod csv;
+#[cfg(feature = "evcxr")]
+pub mod evcxr;
+
pub use row::Row;
pub use cell::Cell;
use format::{TableFormat, LinePosition, consts};