summaryrefslogtreecommitdiffstats
path: root/src/cell.rs
diff options
context:
space:
mode:
authorpierresy <pierre-henri.symoneaux@alcatel-lucent.com>2015-11-19 22:37:28 +0100
committerpierresy <pierre-henri.symoneaux@alcatel-lucent.com>2015-11-19 22:37:28 +0100
commit35665ce05f37e75729c98e47542b0bb3ebabb370 (patch)
tree89fd3069543cb4d5f30a368c3470aa860864d3fc /src/cell.rs
parent2d2544e684cec7a05c3f0517ab20a652df1d1d77 (diff)
Reset style before applying new style from string
Diffstat (limited to 'src/cell.rs')
-rw-r--r--src/cell.rs23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/cell.rs b/src/cell.rs
index 335bcfd..046bc11 100644
--- a/src/cell.rs
+++ b/src/cell.rs
@@ -103,6 +103,7 @@ impl Cell {
/// * **B** : Bright Blue
/// * ... and so on ...
pub fn style_spec(mut self, spec: &str) -> Cell {
+ self.reset_style();
let mut foreground = false;
let mut background = false;
for c in spec.chars() {
@@ -267,7 +268,7 @@ mod tests {
}
#[test]
- fn ascii() {
+ fn print_ascii() {
let ascii_cell = Cell::new("hello");
assert_eq!(ascii_cell.get_width(), 5);
@@ -277,7 +278,7 @@ mod tests {
}
#[test]
- fn unicode() {
+ fn print_unicode() {
let unicode_cell = Cell::new("привет");
assert_eq!(unicode_cell.get_width(), 6);
@@ -312,13 +313,29 @@ mod tests {
#[test]
fn style_spec() {
- let cell = Cell::new("test").style_spec("FrBBbuic");
+ let mut cell = Cell::new("test").style_spec("FrBBbuic");
+ assert_eq!(cell.style.len(), 5);
assert!(cell.style.contains(&Attr::Underline(true)));
assert!(cell.style.contains(&Attr::Italic(true)));
assert!(cell.style.contains(&Attr::Bold));
assert!(cell.style.contains(&Attr::ForegroundColor(color::RED)));
assert!(cell.style.contains(&Attr::BackgroundColor(color::BRIGHT_BLUE)));
assert_eq!(cell.align, Align::CENTER);
+
+ cell = cell.style_spec("FDBwr");
+ assert_eq!(cell.style.len(), 2);
+ assert!(cell.style.contains(&Attr::ForegroundColor(color::BRIGHT_BLACK)));
+ assert!(cell.style.contains(&Attr::BackgroundColor(color::WHITE)));
+ assert_eq!(cell.align, Align::RIGHT)
+ }
+
+ #[test]
+ fn reset_style() {
+ let mut cell = Cell::new("test").style_spec("FDBwr");
+ assert_eq!(cell.style.len(), 2);
+ cell.reset_style();
+ assert_eq!(cell.style.len(), 0);
+ assert_eq!(cell.align, Align::LEFT);
}
}