From 66b913fa54ca0ce700506125867c3ab117f7667f Mon Sep 17 00:00:00 2001 From: Jonas Bushart Date: Sun, 20 Jan 2019 18:10:23 +0100 Subject: 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. --- src/evcxr.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/evcxr.rs (limited to 'src/evcxr.rs') 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>, +{ + 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()); + } +} -- cgit v1.2.3