summaryrefslogtreecommitdiffstats
path: root/src/utils.rs
diff options
context:
space:
mode:
authorpierresy <phsym@msn.com>2016-01-03 22:08:45 +0100
committerpierresy <phsym@msn.com>2016-01-03 22:08:45 +0100
commitd9c2ce1791a2f653570bee193b4d7b2a9223a568 (patch)
tree902d3085f331af2febcbcf82420b45886140b03b /src/utils.rs
parenta145af315f14ed5aeac485d35a702259e5e8e78d (diff)
Updated readme
Diffstat (limited to 'src/utils.rs')
-rw-r--r--src/utils.rs16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/utils.rs b/src/utils.rs
index 744bf0d..dd0b0ee 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -48,13 +48,19 @@ impl Write for StringWriter {
pub fn print_align<T: Write+?Sized>(out: &mut T, align: Align, text: &str, fill: char, size: usize) -> Result<(), Error> {
let text_len = UnicodeWidthStr::width(text);
let mut nfill = if text_len < size { size - text_len } else { 0 };
- match align {
- Align::LEFT => {},
- Align:: RIGHT => {try!(out.write(&vec![fill as u8; nfill])); nfill = 0;},
- Align:: CENTER => {try!(out.write(&vec![fill as u8; nfill/2])); nfill -= nfill/2;}
+ let n = match align {
+ Align::LEFT => 0,
+ Align:: RIGHT => nfill,
+ Align:: CENTER => nfill/2
+ };
+ if n > 0 {
+ try!(out.write(&vec![fill as u8; n]));
+ nfill -= n;
}
try!(out.write(text.as_bytes()));
- try!(out.write(&vec![fill as u8; nfill]));
+ if nfill > 0 {
+ try!(out.write(&vec![fill as u8; nfill]));
+ }
return Ok(());
}