summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre-Henri Symoneaux <pierre-henri.symoneaux@nokia.com>2017-05-29 22:37:52 +0200
committerPierre-Henri Symoneaux <pierre-henri.symoneaux@nokia.com>2017-05-29 22:46:19 +0200
commit3356ea2da7471ff29241d679aa3147c9d42fd175 (patch)
treefa1d7cc0d0e2c59cb481f1b21769c5630bc6cd69
parent43fe7364cb7ac6898cb2262bacc78db04f3b7108 (diff)
Added category "command-line-interface" to Cargo.toml
-rw-r--r--Cargo.toml1
-rw-r--r--examples/multiline.rs34
-rw-r--r--src/utils.rs84
3 files changed, 60 insertions, 59 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 7c82e0e..176b268 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -9,6 +9,7 @@ documentation = "http://phsym.github.io/prettytable-rs"
readme = "README.md"
authors = [ "Pierre-Henri Symoneaux" ]
keywords = ["tab", "table", "format", "pretty", "print"]
+categories = ["command-line-interface"]
license = "BSD-3-Clause"
[features]
diff --git a/examples/multiline.rs b/examples/multiline.rs
index e633531..a453255 100644
--- a/examples/multiline.rs
+++ b/examples/multiline.rs
@@ -1,23 +1,23 @@
#[macro_use]
extern crate prettytable;
-/*
- Following main function will print :
- +-------------------------+------------------------------+
- | Title 1 | Title 2 |
- +-------------------------+------------------------------+
- | This is | foo |
- | a multiline | |
- | cell | |
- +-------------------------+------------------------------+
- | Yo dawg ;) You can even | +---------+------+---------+ |
- | print tables | | ABC | DEFG | HIJKLMN | |
- | into tables | +---------+------+---------+ |
- | | | foobar | bar | foo | |
- | | +---------+------+---------+ |
- | | | foobar2 | bar2 | foo2 | |
- | | +---------+------+---------+ |
- +-------------------------+------------------------------+
+/*
+ Following main function will print :
+ +-------------------------+------------------------------+
+ | Title 1 | Title 2 |
+ +-------------------------+------------------------------+
+ | This is | foo |
+ | a multiline | |
+ | cell | |
+ +-------------------------+------------------------------+
+ | Yo dawg ;) You can even | +---------+------+---------+ |
+ | print tables | | ABC | DEFG | HIJKLMN | |
+ | into tables | +---------+------+---------+ |
+ | | | foobar | bar | foo | |
+ | | +---------+------+---------+ |
+ | | | foobar2 | bar2 | foo2 | |
+ | | +---------+------+---------+ |
+ +-------------------------+------------------------------+
*/
fn main() {
let table1 = table!(["ABC", "DEFG", "HIJKLMN"],
diff --git a/src/utils.rs b/src/utils.rs
index 085c574..8f4bbf3 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -1,34 +1,34 @@
-//! Internal only utilities
-use std::io::{Error, ErrorKind, Write};
-use std::str;
-
-use unicode_width::UnicodeWidthStr;
-
-use super::format::Alignment;
-
-#[cfg(any(not(windows), not(feature="win_crlf")))]
-pub static NEWLINE: &'static [u8] = b"\n";
-#[cfg(all(windows, feature="win_crlf"))]
-pub static NEWLINE: &'static [u8] = b"\r\n";
-
-/// Internal utility for writing data into a string
-pub struct StringWriter {
+//! Internal only utilities
+use std::io::{Error, ErrorKind, Write};
+use std::str;
+
+use unicode_width::UnicodeWidthStr;
+
+use super::format::Alignment;
+
+#[cfg(any(not(windows), not(feature="win_crlf")))]
+pub static NEWLINE: &'static [u8] = b"\n";
+#[cfg(all(windows, feature="win_crlf"))]
+pub static NEWLINE: &'static [u8] = b"\r\n";
+
+/// Internal utility for writing data into a string
+pub struct StringWriter {
string: String,
-}
-
-impl StringWriter {
+}
+
+impl StringWriter {
/// Create a new `StringWriter`
pub fn new() -> StringWriter {
StringWriter { string: String::new() }
}
-
+
/// Return a reference to the internally written `String`
pub fn as_string(&self) -> &str {
&self.string
}
-}
-
-impl Write for StringWriter {
+}
+
+impl Write for StringWriter {
fn write(&mut self, data: &[u8]) -> Result<usize, Error> {
let string = match str::from_utf8(data) {
Ok(s) => s,
@@ -40,16 +40,16 @@ impl Write for StringWriter {
self.string.push_str(string);
Ok(data.len())
}
-
+
fn flush(&mut self) -> Result<(), Error> {
// Nothing to do here
Ok(())
}
-}
-
-/// Align/fill a string and print it to `out`
-/// If `skip_right_fill` is set to `true`, then no space will be added after the string
-/// to complete alignment
+}
+
+/// Align/fill a string and print it to `out`
+/// If `skip_right_fill` is set to `true`, then no space will be added after the string
+/// to complete alignment
pub fn print_align<T: Write + ?Sized>(out: &mut T,
align: Alignment,
text: &str,
@@ -73,14 +73,14 @@ pub fn print_align<T: Write + ?Sized>(out: &mut T,
try!(out.write(&vec![fill as u8; nfill]));
}
Ok(())
-}
-
-#[cfg(test)]
-mod tests {
+}
+
+#[cfg(test)]
+mod tests {
use super::*;
use format::Alignment;
use std::io::Write;
-
+
#[test]
fn string_writer() {
let mut out = StringWriter::new();
@@ -90,42 +90,42 @@ mod tests {
out.write("bar".as_bytes()).unwrap();
assert_eq!(out.as_string(), "foo bar");
}
-
+
#[test]
fn fill_align() {
let mut out = StringWriter::new();
print_align(&mut out, Alignment::RIGHT, "foo", '*', 10, false).unwrap();
assert_eq!(out.as_string(), "*******foo");
-
+
let mut out = StringWriter::new();
print_align(&mut out, Alignment::LEFT, "foo", '*', 10, false).unwrap();
assert_eq!(out.as_string(), "foo*******");
-
+
let mut out = StringWriter::new();
print_align(&mut out, Alignment::CENTER, "foo", '*', 10, false).unwrap();
assert_eq!(out.as_string(), "***foo****");
-
+
let mut out = StringWriter::new();
print_align(&mut out, Alignment::CENTER, "foo", '*', 1, false).unwrap();
assert_eq!(out.as_string(), "foo");
}
-
+
#[test]
fn skip_right_fill() {
let mut out = StringWriter::new();
print_align(&mut out, Alignment::RIGHT, "foo", '*', 10, true).unwrap();
assert_eq!(out.as_string(), "*******foo");
-
+
let mut out = StringWriter::new();
print_align(&mut out, Alignment::LEFT, "foo", '*', 10, true).unwrap();
assert_eq!(out.as_string(), "foo");
-
+
let mut out = StringWriter::new();
print_align(&mut out, Alignment::CENTER, "foo", '*', 10, true).unwrap();
assert_eq!(out.as_string(), "***foo");
-
+
let mut out = StringWriter::new();
print_align(&mut out, Alignment::CENTER, "foo", '*', 1, false).unwrap();
assert_eq!(out.as_string(), "foo");
}
-}
+}