mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-09-27 20:59:02 +00:00
63bd929eb5
Changes to the way ANSIStrings work mean we need to dereference the strings before putting them in an ANSIString. There's more that can be done here, but this gets it to compile for now.
45 lines
1.2 KiB
Rust
45 lines
1.2 KiB
Rust
use colours::Colours;
|
|
use file::File;
|
|
use filetype::file_colour;
|
|
|
|
use term_grid as grid;
|
|
|
|
|
|
#[derive(PartialEq, Debug, Copy, Clone)]
|
|
pub struct Grid {
|
|
pub across: bool,
|
|
pub console_width: usize,
|
|
pub colours: Colours,
|
|
}
|
|
|
|
impl Grid {
|
|
pub fn view(&self, files: &[File]) {
|
|
let direction = if self.across { grid::Direction::LeftToRight }
|
|
else { grid::Direction::TopToBottom };
|
|
|
|
let mut grid = grid::Grid::new(grid::GridOptions {
|
|
direction: direction,
|
|
filling: grid::Filling::Spaces(2),
|
|
});
|
|
|
|
grid.reserve(files.len());
|
|
|
|
for file in files.iter() {
|
|
grid.add(grid::Cell {
|
|
contents: file_colour(&self.colours, file).paint(&*file.name).to_string(),
|
|
width: file.file_name_width(),
|
|
});
|
|
}
|
|
|
|
if let Some(display) = grid.fit_into_width(self.console_width) {
|
|
print!("{}", display);
|
|
}
|
|
else {
|
|
// File names too long for a grid - drop down to just listing them!
|
|
for file in files.iter() {
|
|
println!("{}", file_colour(&self.colours, file).paint(&*file.name));
|
|
}
|
|
}
|
|
}
|
|
}
|