From 9e4485373b9dd6079e8baee9ba0b33c2c5e7db69 Mon Sep 17 00:00:00 2001 From: pierresy Date: Tue, 19 Jan 2016 10:14:51 +0100 Subject: Added a section in README about formatting --- src/format.rs | 53 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 13 deletions(-) (limited to 'src/format.rs') diff --git a/src/format.rs b/src/format.rs index 364653d..c4b874e 100644 --- a/src/format.rs +++ b/src/format.rs @@ -100,19 +100,14 @@ pub struct TableFormat { impl TableFormat { - /// Create a new TableFormat. - /// - /// `csep` is the character used for separating columns. - /// `lsep` is an optional `LineSeparator` defining how to separate lines. - /// `tsep` is an optional `LineSeparator` defining the format of the separator after the title line (if set). - /// If `tsep` is set to `None`, then `lsep` will be used, f it's set. - pub fn new(csep: Option, lsep: Option, tsep: Option) -> TableFormat { + /// Create a new empty TableFormat. + pub fn new() -> TableFormat { return TableFormat{ - csep: csep, + csep: None, lborder: None, rborder: None, - lsep: lsep, - tsep: tsep, + lsep: None, + tsep: None, top_sep: None, bottom_sep: None, pad_left: 0, @@ -198,7 +193,7 @@ impl TableFormat { impl Default for TableFormat { fn default() -> Self { - return TableFormat::new(None, None, None); + return TableFormat::new(); } } @@ -210,7 +205,7 @@ pub struct FormatBuilder { impl FormatBuilder { pub fn new() -> FormatBuilder { return FormatBuilder { - format: Box::new(TableFormat::new(None, None, None)) + format: Box::new(TableFormat::new()) }; } @@ -369,7 +364,7 @@ pub mod consts { /// a b /// d c /// ``` - pub static ref FORMAT_NO_BORDER: TableFormat = FormatBuilder::new() + pub static ref FORMAT_CLEAN: TableFormat = FormatBuilder::new() .padding(1, 1) .build(); @@ -392,5 +387,37 @@ pub mod consts { .separator(LinePosition::Top, *MINUS_PLUS_SEP) .borders('|') .build(); + + /// A table with no external border + /// + /// # Example + /// ```text + /// T1 | T2 + /// ====+==== + /// a | b + /// ----+---- + /// c | d + /// ``` + pub static ref FORMAT_NO_BORDER: TableFormat = FormatBuilder::new() + .padding(1, 1) + .separator(LinePosition::Intern, *MINUS_PLUS_SEP) + .separator(LinePosition::Title, *EQU_PLUS_SEP) + .column_separator('|') + .build(); + + /// A table with no external border and no line separation + /// + /// # Example + /// ```text + /// T1 | T2 + /// ----+---- + /// a | b + /// c | d + /// ``` + pub static ref FORMAT_NO_BORDER_LINE_SEPARATOR: TableFormat = FormatBuilder::new() + .padding(1, 1) + .separator(LinePosition::Title, *MINUS_PLUS_SEP) + .column_separator('|') + .build(); } } -- cgit v1.2.3