mirror of
https://github.com/uutils/uutils-term-grid.git
synced 2026-06-10 16:13:01 -07:00
Add some new methods for exa
This commit is contained in:
+1
-1
@@ -7,7 +7,7 @@ documentation = "http://bsago.me/doc/term_grid/"
|
||||
homepage = "https://github.com/ogham/rust-term-grid"
|
||||
license = "MIT"
|
||||
readme = "README.md"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
|
||||
[lib]
|
||||
name = "term_grid"
|
||||
|
||||
+26
@@ -177,6 +177,12 @@ struct Dimensions {
|
||||
widths: Vec<Width>,
|
||||
}
|
||||
|
||||
impl Dimensions {
|
||||
pub fn total_width(&self, separator_width: Width) -> Width {
|
||||
sum(self.widths.iter().map(|&x| x)) + separator_width * (self.widths.len() - 1)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Everything needed to format the cells with the grid options.
|
||||
///
|
||||
@@ -302,6 +308,26 @@ pub struct Display<'grid> {
|
||||
dimensions: Dimensions,
|
||||
}
|
||||
|
||||
impl<'grid> Display<'grid> {
|
||||
|
||||
/// Returns how many columns this display takes up, based on the separator
|
||||
/// width and the number and width of the columns.
|
||||
pub fn width(&self) -> Width {
|
||||
self.dimensions.total_width(self.grid.options.separator_width)
|
||||
}
|
||||
|
||||
/// Returns whether this display takes up as many columns as were allotted
|
||||
/// to it.
|
||||
///
|
||||
/// It's possible to construct tables that don't actually use up all the
|
||||
/// columns that they could, such as when there are more columns than
|
||||
/// cells! In this case, a column would have a width of zero. This just
|
||||
/// checks for that.
|
||||
pub fn is_complete(&self) -> bool {
|
||||
self.dimensions.widths.iter().all(|&x| x > 0)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'grid> fmt::Display for Display<'grid> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
for y in 0 .. self.dimensions.num_lines {
|
||||
|
||||
Reference in New Issue
Block a user