diff options
author | Benjamin Sago <ogham@bsago.me> | 2015-01-24 17:26:26 +0000 |
---|---|---|
committer | Benjamin Sago <ogham@bsago.me> | 2015-01-24 17:26:26 +0000 |
commit | 449592c1502b5804ae2a32247e23dde31b95daaa (patch) | |
tree | 18fea9d81cae356dea9d133570d60649f7341427 /src/column.rs | |
parent | f82dc741de96f056e85efbd8418e488d47a1f1fd (diff) |
Do column width calculations ourselves (speedup)
Instead of stripping the ANSI formatting characters from our strings, work out the length without them and use that. This is per-column, but most of them are simple (just the same number of characters in the non-coloured string).
Sometimes, this is really simple: for example, trwxrwxrwx permissions strings are always going to be ten characters long, and the strings that get returned are chock full of ANSI escape codes.
This should have a small benefit on performance.
Diffstat (limited to 'src/column.rs')
-rw-r--r-- | src/column.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/column.rs b/src/column.rs index 013b07f..d842a86 100644 --- a/src/column.rs +++ b/src/column.rs @@ -1,5 +1,7 @@ use std::iter::repeat; +use ansi_term::Style; + #[derive(PartialEq, Show)] pub enum Column { Permissions, @@ -79,3 +81,17 @@ impl Alignment { } } } + +pub struct Cell { + pub length: usize, + pub text: String, +} + +impl Cell { + pub fn paint(style: Style, string: &str) -> Cell { + Cell { + text: style.paint(string).to_string(), + length: string.len(), + } + } +} |