diff options
author | Ben S <ogham@bsago.me> | 2015-01-24 12:38:05 +0000 |
---|---|---|
committer | Ben S <ogham@bsago.me> | 2015-01-24 12:38:05 +0000 |
commit | 2ba0b3bd5f71d3ab96b0f1d9c8647c4ae9178921 (patch) | |
tree | ae91ce760e1fffa9fa9c988fe06ca07db691aedf /src/column.rs | |
parent | 6457f4b5772f659c5945a044168d0a2659fe2437 (diff) |
Convert docs to standard format
Diffstat (limited to 'src/column.rs')
-rw-r--r-- | src/column.rs | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/column.rs b/src/column.rs index 124b7b3..013b07f 100644 --- a/src/column.rs +++ b/src/column.rs @@ -23,9 +23,8 @@ pub enum SizeFormat { impl Copy for SizeFormat { } -// Each column can pick its own alignment. Usually, numbers are -// right-aligned, and text is left-aligned. - +/// Each column can pick its own **Alignment**. Usually, numbers are +/// right-aligned, and text is left-aligned. pub enum Alignment { Left, Right, } @@ -33,6 +32,8 @@ pub enum Alignment { impl Copy for Alignment { } impl Column { + + /// Get the alignment this column should use. pub fn alignment(&self) -> Alignment { match *self { Column::FileSize(_) => Alignment::Right, @@ -43,6 +44,8 @@ impl Column { } } + /// Get the text that should be printed at the top, when the user elects + /// to have a header row printed. pub fn header(&self) -> &'static str { match *self { Column::Permissions => "Permissions", @@ -57,16 +60,18 @@ impl Column { } } +/// Pad a string with the given number of spaces. fn spaces(length: usize) -> String { repeat(" ").take(length).collect() } -// An Alignment is used to pad a string to a certain length, letting -// it pick which end it puts the text on. It takes the amount of -// padding to apply, rather than the width the text should end up, -// because these strings are usually full of control characters. - impl Alignment { + /// Pad a string with the given alignment and number of spaces. + /// + /// This doesn't take the width the string *should* be, rather the number + /// of spaces to add: this is because the strings are usually full of + /// invisible control characters, so getting the displayed width of the + /// string is not as simple as just getting its length. pub fn pad_string(&self, string: &String, padding: usize) -> String { match *self { Alignment::Left => format!("{}{}", string, spaces(padding).as_slice()), |