2017-08-12 11:50:59 +00:00
|
|
|
|
//! The grid-details view lists several details views side-by-side.
|
|
|
|
|
|
2020-10-12 23:54:06 +00:00
|
|
|
|
use std::io::{self, Write};
|
2015-06-28 12:21:21 +00:00
|
|
|
|
|
2020-10-24 17:03:36 +00:00
|
|
|
|
use ansi_term::ANSIStrings;
|
2015-06-28 12:21:21 +00:00
|
|
|
|
use term_grid as grid;
|
|
|
|
|
|
2018-12-07 23:43:31 +00:00
|
|
|
|
use crate::fs::{Dir, File};
|
|
|
|
|
use crate::fs::feature::git::GitCache;
|
|
|
|
|
use crate::fs::feature::xattr::FileAttributes;
|
|
|
|
|
use crate::fs::filter::FileFilter;
|
|
|
|
|
use crate::output::cell::TextCell;
|
|
|
|
|
use crate::output::details::{Options as DetailsOptions, Row as DetailsRow, Render as DetailsRender};
|
Massive theming and view options refactor
This commit significantly refactors the way that options are parsed. It introduces the Theme type which contains both styling and extension configuration, converts the option-parsing process into a being a pure function, and removes some rather gnarly old code.
The main purpose of the refactoring is to fix GH-318, "Tests fail when not connected to a terminal". Even though exa was compiling fine on my machine and on Travis, it was failing for automated build scripts. This was because of what the option-parsing code was trying to accomplish: it wasn't just providing a struct of the user's settings, it was also checking the terminal, providing a View directly.
This has been changed so that the options module now _only_ looks at the command-line arguments and environment variables. Instead of returning a View, it returns the user's _preference_, and it's then up to the 'main' module to examine the terminal width and figure out if the view is doable, downgrading it if necessary.
The code that used to determine the view was horrible and I'm pleased it can be cut out. Also, the terminal width used to be in a lazy_static because it was queried multiple times, and now it's not in one because it's only queried once, which is a good sign for things going in the right direction.
There are also some naming and organisational changes around themes. The blanket terms "Colours" and "Styles" have been yeeted in favour of "Theme", which handles both extensions and UI colours. The FileStyle struct has been replaced with file_name::Options, making it similar to the views in how it has an Options struct and a Render struct.
Finally, eight unit tests have been removed because they turned out to be redundant (testing --colour and --color) after examining the tangled code, and the default theme has been put in its own file in preparation for more themes.
2020-10-22 21:34:00 +00:00
|
|
|
|
use crate::output::file_name::Options as FileStyle;
|
2020-10-10 18:49:46 +00:00
|
|
|
|
use crate::output::grid::Options as GridOptions;
|
2018-12-07 23:43:31 +00:00
|
|
|
|
use crate::output::table::{Table, Row as TableRow, Options as TableOptions};
|
|
|
|
|
use crate::output::tree::{TreeParams, TreeDepth};
|
Massive theming and view options refactor
This commit significantly refactors the way that options are parsed. It introduces the Theme type which contains both styling and extension configuration, converts the option-parsing process into a being a pure function, and removes some rather gnarly old code.
The main purpose of the refactoring is to fix GH-318, "Tests fail when not connected to a terminal". Even though exa was compiling fine on my machine and on Travis, it was failing for automated build scripts. This was because of what the option-parsing code was trying to accomplish: it wasn't just providing a struct of the user's settings, it was also checking the terminal, providing a View directly.
This has been changed so that the options module now _only_ looks at the command-line arguments and environment variables. Instead of returning a View, it returns the user's _preference_, and it's then up to the 'main' module to examine the terminal width and figure out if the view is doable, downgrading it if necessary.
The code that used to determine the view was horrible and I'm pleased it can be cut out. Also, the terminal width used to be in a lazy_static because it was queried multiple times, and now it's not in one because it's only queried once, which is a good sign for things going in the right direction.
There are also some naming and organisational changes around themes. The blanket terms "Colours" and "Styles" have been yeeted in favour of "Theme", which handles both extensions and UI colours. The FileStyle struct has been replaced with file_name::Options, making it similar to the views in how it has an Options struct and a Render struct.
Finally, eight unit tests have been removed because they turned out to be redundant (testing --colour and --color) after examining the tangled code, and the default theme has been put in its own file in preparation for more themes.
2020-10-22 21:34:00 +00:00
|
|
|
|
use crate::theme::Theme;
|
2015-11-14 23:32:57 +00:00
|
|
|
|
|
2015-06-28 12:21:21 +00:00
|
|
|
|
|
Replace Misfire with a testable OptionsResult
This was meant to be a small change, but it spiralled into a big one.
The original intention was to separate OptionsResult and OptionsError. With these types separated, the Help and Version variants can only be returned from the Options::parse function, and the later option-parsing functions can only return success or errors.
Also, Misfire was a silly name.
As a side-effect of Options::parse returning OptionsResult instead of Result<Options, Misfire>, we could no longer use unwrap() or unwrap_err() to get the contents out. This commit makes OptionsResult into a value type, and Options::parse a pure function. It feels like it should be one, having its return value entirely dependent on its arguments, but it also loaded locales and time zones. These parts have been moved into lazy_static references, and the code still passes tests without much change.
OptionsResult isn't PartialEq yet, because the file colouring uses a Box internally.
2020-10-12 22:47:36 +00:00
|
|
|
|
#[derive(PartialEq, Debug)]
|
2017-08-12 21:49:16 +00:00
|
|
|
|
pub struct Options {
|
|
|
|
|
pub grid: GridOptions,
|
|
|
|
|
pub details: DetailsOptions,
|
2017-08-13 10:15:40 +00:00
|
|
|
|
pub row_threshold: RowThreshold,
|
|
|
|
|
}
|
|
|
|
|
|
Massive theming and view options refactor
This commit significantly refactors the way that options are parsed. It introduces the Theme type which contains both styling and extension configuration, converts the option-parsing process into a being a pure function, and removes some rather gnarly old code.
The main purpose of the refactoring is to fix GH-318, "Tests fail when not connected to a terminal". Even though exa was compiling fine on my machine and on Travis, it was failing for automated build scripts. This was because of what the option-parsing code was trying to accomplish: it wasn't just providing a struct of the user's settings, it was also checking the terminal, providing a View directly.
This has been changed so that the options module now _only_ looks at the command-line arguments and environment variables. Instead of returning a View, it returns the user's _preference_, and it's then up to the 'main' module to examine the terminal width and figure out if the view is doable, downgrading it if necessary.
The code that used to determine the view was horrible and I'm pleased it can be cut out. Also, the terminal width used to be in a lazy_static because it was queried multiple times, and now it's not in one because it's only queried once, which is a good sign for things going in the right direction.
There are also some naming and organisational changes around themes. The blanket terms "Colours" and "Styles" have been yeeted in favour of "Theme", which handles both extensions and UI colours. The FileStyle struct has been replaced with file_name::Options, making it similar to the views in how it has an Options struct and a Render struct.
Finally, eight unit tests have been removed because they turned out to be redundant (testing --colour and --color) after examining the tangled code, and the default theme has been put in its own file in preparation for more themes.
2020-10-22 21:34:00 +00:00
|
|
|
|
impl Options {
|
|
|
|
|
pub fn to_details_options(&self) -> &DetailsOptions {
|
|
|
|
|
&self.details
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-08-13 10:15:40 +00:00
|
|
|
|
/// The grid-details view can be configured to revert to just a details view
|
|
|
|
|
/// (with one column) if it wouldn’t produce enough rows of output.
|
|
|
|
|
///
|
|
|
|
|
/// Doing this makes the resulting output look a bit better: when listing a
|
|
|
|
|
/// small directory of four files in four columns, the files just look spaced
|
|
|
|
|
/// out and it’s harder to see what’s going on. So it can be enabled just for
|
|
|
|
|
/// larger directory listings.
|
Replace Misfire with a testable OptionsResult
This was meant to be a small change, but it spiralled into a big one.
The original intention was to separate OptionsResult and OptionsError. With these types separated, the Help and Version variants can only be returned from the Options::parse function, and the later option-parsing functions can only return success or errors.
Also, Misfire was a silly name.
As a side-effect of Options::parse returning OptionsResult instead of Result<Options, Misfire>, we could no longer use unwrap() or unwrap_err() to get the contents out. This commit makes OptionsResult into a value type, and Options::parse a pure function. It feels like it should be one, having its return value entirely dependent on its arguments, but it also loaded locales and time zones. These parts have been moved into lazy_static references, and the code still passes tests without much change.
OptionsResult isn't PartialEq yet, because the file colouring uses a Box internally.
2020-10-12 22:47:36 +00:00
|
|
|
|
#[derive(PartialEq, Debug, Copy, Clone)]
|
2017-08-13 10:15:40 +00:00
|
|
|
|
pub enum RowThreshold {
|
|
|
|
|
|
|
|
|
|
/// Only use grid-details view if it would result in at least this many
|
|
|
|
|
/// rows of output.
|
|
|
|
|
MinimumRows(usize),
|
|
|
|
|
|
|
|
|
|
/// Use the grid-details view no matter what.
|
|
|
|
|
AlwaysGrid,
|
2017-08-12 21:49:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-06-25 23:53:48 +00:00
|
|
|
|
pub struct Render<'a> {
|
2017-08-12 11:50:59 +00:00
|
|
|
|
|
|
|
|
|
/// The directory that’s being rendered here.
|
|
|
|
|
/// We need this to know which columns to put in the output.
|
2017-06-25 23:53:48 +00:00
|
|
|
|
pub dir: Option<&'a Dir>,
|
2017-08-12 11:50:59 +00:00
|
|
|
|
|
|
|
|
|
/// The files that have been read from the directory. They should all
|
|
|
|
|
/// hold a reference to it.
|
2017-06-25 23:53:48 +00:00
|
|
|
|
pub files: Vec<File<'a>>,
|
2017-08-12 11:50:59 +00:00
|
|
|
|
|
|
|
|
|
/// How to colour various pieces of text.
|
Massive theming and view options refactor
This commit significantly refactors the way that options are parsed. It introduces the Theme type which contains both styling and extension configuration, converts the option-parsing process into a being a pure function, and removes some rather gnarly old code.
The main purpose of the refactoring is to fix GH-318, "Tests fail when not connected to a terminal". Even though exa was compiling fine on my machine and on Travis, it was failing for automated build scripts. This was because of what the option-parsing code was trying to accomplish: it wasn't just providing a struct of the user's settings, it was also checking the terminal, providing a View directly.
This has been changed so that the options module now _only_ looks at the command-line arguments and environment variables. Instead of returning a View, it returns the user's _preference_, and it's then up to the 'main' module to examine the terminal width and figure out if the view is doable, downgrading it if necessary.
The code that used to determine the view was horrible and I'm pleased it can be cut out. Also, the terminal width used to be in a lazy_static because it was queried multiple times, and now it's not in one because it's only queried once, which is a good sign for things going in the right direction.
There are also some naming and organisational changes around themes. The blanket terms "Colours" and "Styles" have been yeeted in favour of "Theme", which handles both extensions and UI colours. The FileStyle struct has been replaced with file_name::Options, making it similar to the views in how it has an Options struct and a Render struct.
Finally, eight unit tests have been removed because they turned out to be redundant (testing --colour and --color) after examining the tangled code, and the default theme has been put in its own file in preparation for more themes.
2020-10-22 21:34:00 +00:00
|
|
|
|
pub theme: &'a Theme,
|
2017-08-12 11:50:59 +00:00
|
|
|
|
|
|
|
|
|
/// How to format filenames.
|
Massive theming and view options refactor
This commit significantly refactors the way that options are parsed. It introduces the Theme type which contains both styling and extension configuration, converts the option-parsing process into a being a pure function, and removes some rather gnarly old code.
The main purpose of the refactoring is to fix GH-318, "Tests fail when not connected to a terminal". Even though exa was compiling fine on my machine and on Travis, it was failing for automated build scripts. This was because of what the option-parsing code was trying to accomplish: it wasn't just providing a struct of the user's settings, it was also checking the terminal, providing a View directly.
This has been changed so that the options module now _only_ looks at the command-line arguments and environment variables. Instead of returning a View, it returns the user's _preference_, and it's then up to the 'main' module to examine the terminal width and figure out if the view is doable, downgrading it if necessary.
The code that used to determine the view was horrible and I'm pleased it can be cut out. Also, the terminal width used to be in a lazy_static because it was queried multiple times, and now it's not in one because it's only queried once, which is a good sign for things going in the right direction.
There are also some naming and organisational changes around themes. The blanket terms "Colours" and "Styles" have been yeeted in favour of "Theme", which handles both extensions and UI colours. The FileStyle struct has been replaced with file_name::Options, making it similar to the views in how it has an Options struct and a Render struct.
Finally, eight unit tests have been removed because they turned out to be redundant (testing --colour and --color) after examining the tangled code, and the default theme has been put in its own file in preparation for more themes.
2020-10-22 21:34:00 +00:00
|
|
|
|
pub file_style: &'a FileStyle,
|
2017-08-12 11:50:59 +00:00
|
|
|
|
|
|
|
|
|
/// The grid part of the grid-details view.
|
2017-06-25 23:53:48 +00:00
|
|
|
|
pub grid: &'a GridOptions,
|
2017-08-12 11:50:59 +00:00
|
|
|
|
|
|
|
|
|
/// The details part of the grid-details view.
|
2017-06-25 23:53:48 +00:00
|
|
|
|
pub details: &'a DetailsOptions,
|
2017-08-12 11:50:59 +00:00
|
|
|
|
|
|
|
|
|
/// How to filter files after listing a directory. The files in this
|
|
|
|
|
/// render will already have been filtered and sorted, but any directories
|
|
|
|
|
/// that we recurse into will have to have this applied.
|
2017-07-02 00:02:17 +00:00
|
|
|
|
pub filter: &'a FileFilter,
|
2017-08-12 19:19:30 +00:00
|
|
|
|
|
|
|
|
|
/// The minimum number of rows that there need to be before grid-details
|
|
|
|
|
/// mode is activated.
|
2017-08-13 10:15:40 +00:00
|
|
|
|
pub row_threshold: RowThreshold,
|
2020-10-09 23:09:44 +00:00
|
|
|
|
|
|
|
|
|
/// Whether we are skipping Git-ignored files.
|
|
|
|
|
pub git_ignoring: bool,
|
2020-10-13 00:28:42 +00:00
|
|
|
|
|
|
|
|
|
pub git: Option<&'a GitCache>,
|
Massive theming and view options refactor
This commit significantly refactors the way that options are parsed. It introduces the Theme type which contains both styling and extension configuration, converts the option-parsing process into a being a pure function, and removes some rather gnarly old code.
The main purpose of the refactoring is to fix GH-318, "Tests fail when not connected to a terminal". Even though exa was compiling fine on my machine and on Travis, it was failing for automated build scripts. This was because of what the option-parsing code was trying to accomplish: it wasn't just providing a struct of the user's settings, it was also checking the terminal, providing a View directly.
This has been changed so that the options module now _only_ looks at the command-line arguments and environment variables. Instead of returning a View, it returns the user's _preference_, and it's then up to the 'main' module to examine the terminal width and figure out if the view is doable, downgrading it if necessary.
The code that used to determine the view was horrible and I'm pleased it can be cut out. Also, the terminal width used to be in a lazy_static because it was queried multiple times, and now it's not in one because it's only queried once, which is a good sign for things going in the right direction.
There are also some naming and organisational changes around themes. The blanket terms "Colours" and "Styles" have been yeeted in favour of "Theme", which handles both extensions and UI colours. The FileStyle struct has been replaced with file_name::Options, making it similar to the views in how it has an Options struct and a Render struct.
Finally, eight unit tests have been removed because they turned out to be redundant (testing --colour and --color) after examining the tangled code, and the default theme has been put in its own file in preparation for more themes.
2020-10-22 21:34:00 +00:00
|
|
|
|
|
|
|
|
|
pub console_width: usize,
|
2015-06-28 12:21:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-25 23:53:48 +00:00
|
|
|
|
impl<'a> Render<'a> {
|
2017-08-12 13:21:34 +00:00
|
|
|
|
|
|
|
|
|
/// Create a temporary Details render that gets used for the columns of
|
2020-10-10 18:49:46 +00:00
|
|
|
|
/// the grid-details render that’s being generated.
|
2017-08-12 13:21:34 +00:00
|
|
|
|
///
|
|
|
|
|
/// This includes an empty files vector because the files get added to
|
|
|
|
|
/// the table in *this* file, not in details: we only want to insert every
|
|
|
|
|
/// *n* files into each column’s table, not all of them.
|
Massive theming and view options refactor
This commit significantly refactors the way that options are parsed. It introduces the Theme type which contains both styling and extension configuration, converts the option-parsing process into a being a pure function, and removes some rather gnarly old code.
The main purpose of the refactoring is to fix GH-318, "Tests fail when not connected to a terminal". Even though exa was compiling fine on my machine and on Travis, it was failing for automated build scripts. This was because of what the option-parsing code was trying to accomplish: it wasn't just providing a struct of the user's settings, it was also checking the terminal, providing a View directly.
This has been changed so that the options module now _only_ looks at the command-line arguments and environment variables. Instead of returning a View, it returns the user's _preference_, and it's then up to the 'main' module to examine the terminal width and figure out if the view is doable, downgrading it if necessary.
The code that used to determine the view was horrible and I'm pleased it can be cut out. Also, the terminal width used to be in a lazy_static because it was queried multiple times, and now it's not in one because it's only queried once, which is a good sign for things going in the right direction.
There are also some naming and organisational changes around themes. The blanket terms "Colours" and "Styles" have been yeeted in favour of "Theme", which handles both extensions and UI colours. The FileStyle struct has been replaced with file_name::Options, making it similar to the views in how it has an Options struct and a Render struct.
Finally, eight unit tests have been removed because they turned out to be redundant (testing --colour and --color) after examining the tangled code, and the default theme has been put in its own file in preparation for more themes.
2020-10-22 21:34:00 +00:00
|
|
|
|
fn details_for_column(&self) -> DetailsRender<'a> {
|
2017-07-02 00:02:17 +00:00
|
|
|
|
DetailsRender {
|
2020-10-10 18:49:46 +00:00
|
|
|
|
dir: self.dir,
|
|
|
|
|
files: Vec::new(),
|
Massive theming and view options refactor
This commit significantly refactors the way that options are parsed. It introduces the Theme type which contains both styling and extension configuration, converts the option-parsing process into a being a pure function, and removes some rather gnarly old code.
The main purpose of the refactoring is to fix GH-318, "Tests fail when not connected to a terminal". Even though exa was compiling fine on my machine and on Travis, it was failing for automated build scripts. This was because of what the option-parsing code was trying to accomplish: it wasn't just providing a struct of the user's settings, it was also checking the terminal, providing a View directly.
This has been changed so that the options module now _only_ looks at the command-line arguments and environment variables. Instead of returning a View, it returns the user's _preference_, and it's then up to the 'main' module to examine the terminal width and figure out if the view is doable, downgrading it if necessary.
The code that used to determine the view was horrible and I'm pleased it can be cut out. Also, the terminal width used to be in a lazy_static because it was queried multiple times, and now it's not in one because it's only queried once, which is a good sign for things going in the right direction.
There are also some naming and organisational changes around themes. The blanket terms "Colours" and "Styles" have been yeeted in favour of "Theme", which handles both extensions and UI colours. The FileStyle struct has been replaced with file_name::Options, making it similar to the views in how it has an Options struct and a Render struct.
Finally, eight unit tests have been removed because they turned out to be redundant (testing --colour and --color) after examining the tangled code, and the default theme has been put in its own file in preparation for more themes.
2020-10-22 21:34:00 +00:00
|
|
|
|
theme: self.theme,
|
|
|
|
|
file_style: self.file_style,
|
2020-10-10 18:49:46 +00:00
|
|
|
|
opts: self.details,
|
|
|
|
|
recurse: None,
|
|
|
|
|
filter: self.filter,
|
|
|
|
|
git_ignoring: self.git_ignoring,
|
2020-10-13 00:28:42 +00:00
|
|
|
|
git: self.git,
|
2017-07-02 00:02:17 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-12 19:19:30 +00:00
|
|
|
|
/// Create a Details render for when this grid-details render doesn’t fit
|
Massive theming and view options refactor
This commit significantly refactors the way that options are parsed. It introduces the Theme type which contains both styling and extension configuration, converts the option-parsing process into a being a pure function, and removes some rather gnarly old code.
The main purpose of the refactoring is to fix GH-318, "Tests fail when not connected to a terminal". Even though exa was compiling fine on my machine and on Travis, it was failing for automated build scripts. This was because of what the option-parsing code was trying to accomplish: it wasn't just providing a struct of the user's settings, it was also checking the terminal, providing a View directly.
This has been changed so that the options module now _only_ looks at the command-line arguments and environment variables. Instead of returning a View, it returns the user's _preference_, and it's then up to the 'main' module to examine the terminal width and figure out if the view is doable, downgrading it if necessary.
The code that used to determine the view was horrible and I'm pleased it can be cut out. Also, the terminal width used to be in a lazy_static because it was queried multiple times, and now it's not in one because it's only queried once, which is a good sign for things going in the right direction.
There are also some naming and organisational changes around themes. The blanket terms "Colours" and "Styles" have been yeeted in favour of "Theme", which handles both extensions and UI colours. The FileStyle struct has been replaced with file_name::Options, making it similar to the views in how it has an Options struct and a Render struct.
Finally, eight unit tests have been removed because they turned out to be redundant (testing --colour and --color) after examining the tangled code, and the default theme has been put in its own file in preparation for more themes.
2020-10-22 21:34:00 +00:00
|
|
|
|
/// in the terminal (or something has gone wrong) and we have given up, or
|
|
|
|
|
/// when the user asked for a grid-details view but the terminal width is
|
|
|
|
|
/// not available, so we downgrade.
|
2017-08-12 19:19:30 +00:00
|
|
|
|
pub fn give_up(self) -> DetailsRender<'a> {
|
|
|
|
|
DetailsRender {
|
2020-10-10 18:49:46 +00:00
|
|
|
|
dir: self.dir,
|
|
|
|
|
files: self.files,
|
Massive theming and view options refactor
This commit significantly refactors the way that options are parsed. It introduces the Theme type which contains both styling and extension configuration, converts the option-parsing process into a being a pure function, and removes some rather gnarly old code.
The main purpose of the refactoring is to fix GH-318, "Tests fail when not connected to a terminal". Even though exa was compiling fine on my machine and on Travis, it was failing for automated build scripts. This was because of what the option-parsing code was trying to accomplish: it wasn't just providing a struct of the user's settings, it was also checking the terminal, providing a View directly.
This has been changed so that the options module now _only_ looks at the command-line arguments and environment variables. Instead of returning a View, it returns the user's _preference_, and it's then up to the 'main' module to examine the terminal width and figure out if the view is doable, downgrading it if necessary.
The code that used to determine the view was horrible and I'm pleased it can be cut out. Also, the terminal width used to be in a lazy_static because it was queried multiple times, and now it's not in one because it's only queried once, which is a good sign for things going in the right direction.
There are also some naming and organisational changes around themes. The blanket terms "Colours" and "Styles" have been yeeted in favour of "Theme", which handles both extensions and UI colours. The FileStyle struct has been replaced with file_name::Options, making it similar to the views in how it has an Options struct and a Render struct.
Finally, eight unit tests have been removed because they turned out to be redundant (testing --colour and --color) after examining the tangled code, and the default theme has been put in its own file in preparation for more themes.
2020-10-22 21:34:00 +00:00
|
|
|
|
theme: self.theme,
|
|
|
|
|
file_style: self.file_style,
|
2020-10-10 18:49:46 +00:00
|
|
|
|
opts: self.details,
|
|
|
|
|
recurse: None,
|
|
|
|
|
filter: self.filter,
|
|
|
|
|
git_ignoring: self.git_ignoring,
|
2020-10-13 00:28:42 +00:00
|
|
|
|
git: self.git,
|
2017-08-12 13:21:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-28 15:13:47 +00:00
|
|
|
|
// This doesn’t take an IgnoreCache even though the details one does
|
|
|
|
|
// because grid-details has no tree view.
|
|
|
|
|
|
2020-10-13 00:28:42 +00:00
|
|
|
|
pub fn render<W: Write>(mut self, w: &mut W) -> io::Result<()> {
|
|
|
|
|
if let Some((grid, width)) = self.find_fitting_grid() {
|
2017-08-12 13:21:34 +00:00
|
|
|
|
write!(w, "{}", grid.fit_into_columns(width))
|
|
|
|
|
}
|
|
|
|
|
else {
|
2020-10-13 00:28:42 +00:00
|
|
|
|
self.give_up().render(w)
|
2017-08-12 13:21:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-08-26 11:00:31 +00:00
|
|
|
|
|
2020-10-13 00:28:42 +00:00
|
|
|
|
pub fn find_fitting_grid(&mut self) -> Option<(grid::Grid, grid::Width)> {
|
2017-07-05 20:01:01 +00:00
|
|
|
|
let options = self.details.table.as_ref().expect("Details table options not given!");
|
2015-06-28 18:57:13 +00:00
|
|
|
|
|
Massive theming and view options refactor
This commit significantly refactors the way that options are parsed. It introduces the Theme type which contains both styling and extension configuration, converts the option-parsing process into a being a pure function, and removes some rather gnarly old code.
The main purpose of the refactoring is to fix GH-318, "Tests fail when not connected to a terminal". Even though exa was compiling fine on my machine and on Travis, it was failing for automated build scripts. This was because of what the option-parsing code was trying to accomplish: it wasn't just providing a struct of the user's settings, it was also checking the terminal, providing a View directly.
This has been changed so that the options module now _only_ looks at the command-line arguments and environment variables. Instead of returning a View, it returns the user's _preference_, and it's then up to the 'main' module to examine the terminal width and figure out if the view is doable, downgrading it if necessary.
The code that used to determine the view was horrible and I'm pleased it can be cut out. Also, the terminal width used to be in a lazy_static because it was queried multiple times, and now it's not in one because it's only queried once, which is a good sign for things going in the right direction.
There are also some naming and organisational changes around themes. The blanket terms "Colours" and "Styles" have been yeeted in favour of "Theme", which handles both extensions and UI colours. The FileStyle struct has been replaced with file_name::Options, making it similar to the views in how it has an Options struct and a Render struct.
Finally, eight unit tests have been removed because they turned out to be redundant (testing --colour and --color) after examining the tangled code, and the default theme has been put in its own file in preparation for more themes.
2020-10-22 21:34:00 +00:00
|
|
|
|
let drender = self.details_for_column();
|
Use Mutex lock on only the users columns
This makes use of a change in the `users` crate to change which parts of exa's code are accessed under a `Mutex`. The change is that the methods on `Users` can now take just `&self`, instead of `&mut self`. This has a knock-on effect in exa, as many methods now don't need to take a mutable `&self`, meaning that the Mutex can be moved to only containing the users information instead of having to be queried for *every column*. This means that threading should now be a lot faster, as fewer parts have to be executed on a single thread.
The main change to facilitate this is that `Table`'s structure has changed: everything environmental that gets loaded at the beginning is now in an `Environment` struct, which can be mocked out if necessary, as one of `Table`'s fields. (They were kind of in a variety of places before.)
Casualties include having to make some of the test code more verbose, as it explicitly takes the columns and environment as references rather than values, and those both need to be put on the stack beforehand. Also, all the colours are now hidden behind an `opts` field, so a lot of the rendering code is more verbose too (but not greatly so).
2016-01-16 21:56:37 +00:00
|
|
|
|
|
2020-10-13 00:28:42 +00:00
|
|
|
|
let (first_table, _) = self.make_table(options, &drender);
|
Use Mutex lock on only the users columns
This makes use of a change in the `users` crate to change which parts of exa's code are accessed under a `Mutex`. The change is that the methods on `Users` can now take just `&self`, instead of `&mut self`. This has a knock-on effect in exa, as many methods now don't need to take a mutable `&self`, meaning that the Mutex can be moved to only containing the users information instead of having to be queried for *every column*. This means that threading should now be a lot faster, as fewer parts have to be executed on a single thread.
The main change to facilitate this is that `Table`'s structure has changed: everything environmental that gets loaded at the beginning is now in an `Environment` struct, which can be mocked out if necessary, as one of `Table`'s fields. (They were kind of in a variety of places before.)
Casualties include having to make some of the test code more verbose, as it explicitly takes the columns and environment as references rather than values, and those both need to be put on the stack beforehand. Also, all the colours are now hidden behind an `opts` field, so a lot of the rendering code is more verbose too (but not greatly so).
2016-01-16 21:56:37 +00:00
|
|
|
|
|
2017-07-02 00:02:17 +00:00
|
|
|
|
let rows = self.files.iter()
|
|
|
|
|
.map(|file| first_table.row_for_file(file, file_has_xattrs(file)))
|
2020-10-10 18:49:46 +00:00
|
|
|
|
.collect::<Vec<_>>();
|
Replace Cells with growable TextCells
A recent change to ansi-term [1] means that `ANSIString`s can now hold either
owned *or* borrowed data (Rust calls this the Cow type). This means that we
can delay formatting ANSIStrings into ANSI-control-code-formatted strings
until it's absolutely necessary. The process for doing this was:
1. Replace the `Cell` type with a `TextCell` type that holds a vector of
`ANSIString` values instead of a formatted string. It still does the
width tracking.
2. Rework the details module's `render` functions to emit values of this
type.
3. Similarly, rework the functions that produce cells containing filenames
to use a `File` value's `name` field, which is an owned `String` that
can now be re-used.
4. Update the printing, formatting, and width-calculating code in the
details and grid-details views to produce a table by adding vectors
together instead of adding strings together, delaying the formatting as
long as it can.
This results in fewer allocations (as fewer `String` values are produced), and
makes the API tidier (as fewer `String` values are being passed around without
having their contents specified).
This also paves the way to Windows support, or at least support for
non-ANSI terminals: by delaying the time until strings are formatted,
it'll now be easier to change *how* they are formatted.
Casualties include:
- Bump to ansi_term v0.7.1, which impls `PartialEq` and `Debug` on
`ANSIString`.
- The grid_details and lines views now need to take a vector of files, rather
than a borrowed slice, so the filename cells produced now own the filename
strings that get taken from files.
- Fixed the signature of `File#link_target` to specify that the
file produced refers to the same directory, rather than some phantom
directory with the same lifetime as the file. (This was wrong from the
start, but it broke nothing until now)
References:
[1]: ansi-term@f6a6579ba8174de1cae64d181ec04af32ba2a4f0
2015-12-17 00:25:20 +00:00
|
|
|
|
|
2017-07-02 00:02:17 +00:00
|
|
|
|
let file_names = self.files.iter()
|
2020-10-24 17:03:36 +00:00
|
|
|
|
.map(|file| self.file_style.for_file(file, self.theme).paint().promote())
|
2020-10-10 18:49:46 +00:00
|
|
|
|
.collect::<Vec<_>>();
|
Use Mutex lock on only the users columns
This makes use of a change in the `users` crate to change which parts of exa's code are accessed under a `Mutex`. The change is that the methods on `Users` can now take just `&self`, instead of `&mut self`. This has a knock-on effect in exa, as many methods now don't need to take a mutable `&self`, meaning that the Mutex can be moved to only containing the users information instead of having to be queried for *every column*. This means that threading should now be a lot faster, as fewer parts have to be executed on a single thread.
The main change to facilitate this is that `Table`'s structure has changed: everything environmental that gets loaded at the beginning is now in an `Environment` struct, which can be mocked out if necessary, as one of `Table`'s fields. (They were kind of in a variety of places before.)
Casualties include having to make some of the test code more verbose, as it explicitly takes the columns and environment as references rather than values, and those both need to be put on the stack beforehand. Also, all the colours are now hidden behind an `opts` field, so a lot of the rendering code is more verbose too (but not greatly so).
2016-01-16 21:56:37 +00:00
|
|
|
|
|
2020-10-13 00:28:42 +00:00
|
|
|
|
let mut last_working_table = self.make_grid(1, options, &file_names, rows.clone(), &drender);
|
2015-06-28 12:21:21 +00:00
|
|
|
|
|
2017-08-12 13:21:34 +00:00
|
|
|
|
// If we can’t fit everything in a grid 100 columns wide, then
|
|
|
|
|
// something has gone seriously awry
|
|
|
|
|
for column_count in 2..100 {
|
2020-10-13 00:28:42 +00:00
|
|
|
|
let grid = self.make_grid(column_count, options, &file_names, rows.clone(), &drender);
|
2015-06-28 12:21:21 +00:00
|
|
|
|
|
2015-06-28 20:27:18 +00:00
|
|
|
|
let the_grid_fits = {
|
|
|
|
|
let d = grid.fit_into_columns(column_count);
|
Massive theming and view options refactor
This commit significantly refactors the way that options are parsed. It introduces the Theme type which contains both styling and extension configuration, converts the option-parsing process into a being a pure function, and removes some rather gnarly old code.
The main purpose of the refactoring is to fix GH-318, "Tests fail when not connected to a terminal". Even though exa was compiling fine on my machine and on Travis, it was failing for automated build scripts. This was because of what the option-parsing code was trying to accomplish: it wasn't just providing a struct of the user's settings, it was also checking the terminal, providing a View directly.
This has been changed so that the options module now _only_ looks at the command-line arguments and environment variables. Instead of returning a View, it returns the user's _preference_, and it's then up to the 'main' module to examine the terminal width and figure out if the view is doable, downgrading it if necessary.
The code that used to determine the view was horrible and I'm pleased it can be cut out. Also, the terminal width used to be in a lazy_static because it was queried multiple times, and now it's not in one because it's only queried once, which is a good sign for things going in the right direction.
There are also some naming and organisational changes around themes. The blanket terms "Colours" and "Styles" have been yeeted in favour of "Theme", which handles both extensions and UI colours. The FileStyle struct has been replaced with file_name::Options, making it similar to the views in how it has an Options struct and a Render struct.
Finally, eight unit tests have been removed because they turned out to be redundant (testing --colour and --color) after examining the tangled code, and the default theme has been put in its own file in preparation for more themes.
2020-10-22 21:34:00 +00:00
|
|
|
|
d.is_complete() && d.width() <= self.console_width
|
2015-06-28 20:27:18 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if the_grid_fits {
|
2015-06-28 15:25:59 +00:00
|
|
|
|
last_working_table = grid;
|
|
|
|
|
}
|
|
|
|
|
else {
|
2017-08-12 19:19:30 +00:00
|
|
|
|
// If we’ve figured out how many columns can fit in the user’s
|
|
|
|
|
// terminal, and it turns out there aren’t enough rows to
|
|
|
|
|
// make it worthwhile, then just resort to the lines view.
|
2017-08-13 10:15:40 +00:00
|
|
|
|
if let RowThreshold::MinimumRows(thresh) = self.row_threshold {
|
2017-08-12 19:19:30 +00:00
|
|
|
|
if last_working_table.fit_into_columns(column_count - 1).row_count() < thresh {
|
|
|
|
|
return None;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-12 13:21:34 +00:00
|
|
|
|
return Some((last_working_table, column_count - 1));
|
2015-06-28 15:25:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-04-18 17:39:32 +00:00
|
|
|
|
|
2017-08-12 13:21:34 +00:00
|
|
|
|
None
|
2015-06-28 15:25:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-13 00:36:41 +00:00
|
|
|
|
fn make_table(&mut self, options: &'a TableOptions, drender: &DetailsRender<'_>) -> (Table<'a>, Vec<DetailsRow>) {
|
2020-10-13 00:28:42 +00:00
|
|
|
|
match (self.git, self.dir) {
|
|
|
|
|
(Some(g), Some(d)) => if ! g.has_anything_for(&d.path) { self.git = None },
|
|
|
|
|
(Some(g), None) => if ! self.files.iter().any(|f| g.has_anything_for(&f.path)) { self.git = None },
|
2017-09-02 11:13:41 +00:00
|
|
|
|
(None, _) => {/* Keep Git how it is */},
|
|
|
|
|
}
|
|
|
|
|
|
Massive theming and view options refactor
This commit significantly refactors the way that options are parsed. It introduces the Theme type which contains both styling and extension configuration, converts the option-parsing process into a being a pure function, and removes some rather gnarly old code.
The main purpose of the refactoring is to fix GH-318, "Tests fail when not connected to a terminal". Even though exa was compiling fine on my machine and on Travis, it was failing for automated build scripts. This was because of what the option-parsing code was trying to accomplish: it wasn't just providing a struct of the user's settings, it was also checking the terminal, providing a View directly.
This has been changed so that the options module now _only_ looks at the command-line arguments and environment variables. Instead of returning a View, it returns the user's _preference_, and it's then up to the 'main' module to examine the terminal width and figure out if the view is doable, downgrading it if necessary.
The code that used to determine the view was horrible and I'm pleased it can be cut out. Also, the terminal width used to be in a lazy_static because it was queried multiple times, and now it's not in one because it's only queried once, which is a good sign for things going in the right direction.
There are also some naming and organisational changes around themes. The blanket terms "Colours" and "Styles" have been yeeted in favour of "Theme", which handles both extensions and UI colours. The FileStyle struct has been replaced with file_name::Options, making it similar to the views in how it has an Options struct and a Render struct.
Finally, eight unit tests have been removed because they turned out to be redundant (testing --colour and --color) after examining the tangled code, and the default theme has been put in its own file in preparation for more themes.
2020-10-22 21:34:00 +00:00
|
|
|
|
let mut table = Table::new(options, self.git, &self.theme);
|
2017-07-02 00:02:17 +00:00
|
|
|
|
let mut rows = Vec::new();
|
Use Mutex lock on only the users columns
This makes use of a change in the `users` crate to change which parts of exa's code are accessed under a `Mutex`. The change is that the methods on `Users` can now take just `&self`, instead of `&mut self`. This has a knock-on effect in exa, as many methods now don't need to take a mutable `&self`, meaning that the Mutex can be moved to only containing the users information instead of having to be queried for *every column*. This means that threading should now be a lot faster, as fewer parts have to be executed on a single thread.
The main change to facilitate this is that `Table`'s structure has changed: everything environmental that gets loaded at the beginning is now in an `Environment` struct, which can be mocked out if necessary, as one of `Table`'s fields. (They were kind of in a variety of places before.)
Casualties include having to make some of the test code more verbose, as it explicitly takes the columns and environment as references rather than values, and those both need to be put on the stack beforehand. Also, all the colours are now hidden behind an `opts` field, so a lot of the rendering code is more verbose too (but not greatly so).
2016-01-16 21:56:37 +00:00
|
|
|
|
|
2017-07-02 00:02:17 +00:00
|
|
|
|
if self.details.header {
|
2017-07-03 16:40:05 +00:00
|
|
|
|
let row = table.header_row();
|
|
|
|
|
table.add_widths(&row);
|
|
|
|
|
rows.push(drender.render_header(row));
|
2017-07-02 00:02:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
(table, rows)
|
2015-06-29 13:47:07 +00:00
|
|
|
|
}
|
2015-06-28 12:21:21 +00:00
|
|
|
|
|
2020-10-13 00:36:41 +00:00
|
|
|
|
fn make_grid(&mut self, column_count: usize, options: &'a TableOptions, file_names: &[TextCell], rows: Vec<TableRow>, drender: &DetailsRender<'_>) -> grid::Grid {
|
Use Mutex lock on only the users columns
This makes use of a change in the `users` crate to change which parts of exa's code are accessed under a `Mutex`. The change is that the methods on `Users` can now take just `&self`, instead of `&mut self`. This has a knock-on effect in exa, as many methods now don't need to take a mutable `&self`, meaning that the Mutex can be moved to only containing the users information instead of having to be queried for *every column*. This means that threading should now be a lot faster, as fewer parts have to be executed on a single thread.
The main change to facilitate this is that `Table`'s structure has changed: everything environmental that gets loaded at the beginning is now in an `Environment` struct, which can be mocked out if necessary, as one of `Table`'s fields. (They were kind of in a variety of places before.)
Casualties include having to make some of the test code more verbose, as it explicitly takes the columns and environment as references rather than values, and those both need to be put on the stack beforehand. Also, all the colours are now hidden behind an `opts` field, so a lot of the rendering code is more verbose too (but not greatly so).
2016-01-16 21:56:37 +00:00
|
|
|
|
let mut tables = Vec::new();
|
|
|
|
|
for _ in 0 .. column_count {
|
2020-10-13 00:28:42 +00:00
|
|
|
|
tables.push(self.make_table(options, drender));
|
Use Mutex lock on only the users columns
This makes use of a change in the `users` crate to change which parts of exa's code are accessed under a `Mutex`. The change is that the methods on `Users` can now take just `&self`, instead of `&mut self`. This has a knock-on effect in exa, as many methods now don't need to take a mutable `&self`, meaning that the Mutex can be moved to only containing the users information instead of having to be queried for *every column*. This means that threading should now be a lot faster, as fewer parts have to be executed on a single thread.
The main change to facilitate this is that `Table`'s structure has changed: everything environmental that gets loaded at the beginning is now in an `Environment` struct, which can be mocked out if necessary, as one of `Table`'s fields. (They were kind of in a variety of places before.)
Casualties include having to make some of the test code more verbose, as it explicitly takes the columns and environment as references rather than values, and those both need to be put on the stack beforehand. Also, all the colours are now hidden behind an `opts` field, so a lot of the rendering code is more verbose too (but not greatly so).
2016-01-16 21:56:37 +00:00
|
|
|
|
}
|
2015-06-28 12:21:21 +00:00
|
|
|
|
|
2017-07-02 00:02:17 +00:00
|
|
|
|
let mut num_cells = rows.len();
|
2015-06-29 12:13:23 +00:00
|
|
|
|
if self.details.header {
|
|
|
|
|
num_cells += column_count;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-02 00:02:17 +00:00
|
|
|
|
let original_height = divide_rounding_up(rows.len(), column_count);
|
2015-06-29 13:47:07 +00:00
|
|
|
|
let height = divide_rounding_up(num_cells, column_count);
|
2015-06-28 18:11:39 +00:00
|
|
|
|
|
2017-07-02 00:02:17 +00:00
|
|
|
|
for (i, (file_name, row)) in file_names.iter().zip(rows.into_iter()).enumerate() {
|
2015-06-29 12:13:23 +00:00
|
|
|
|
let index = if self.grid.across {
|
|
|
|
|
i % column_count
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
i / original_height
|
|
|
|
|
};
|
|
|
|
|
|
2017-07-02 00:02:17 +00:00
|
|
|
|
let (ref mut table, ref mut rows) = tables[index];
|
|
|
|
|
table.add_widths(&row);
|
2017-07-03 22:25:56 +00:00
|
|
|
|
let details_row = drender.render_file(row, file_name.clone(), TreeParams::new(TreeDepth::root(), false));
|
2017-07-02 00:02:17 +00:00
|
|
|
|
rows.push(details_row);
|
2015-06-28 12:21:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-10 18:49:46 +00:00
|
|
|
|
let columns = tables
|
|
|
|
|
.into_iter()
|
|
|
|
|
.map(|(table, details_rows)| {
|
|
|
|
|
drender.iterate_with_table(table, details_rows)
|
|
|
|
|
.collect::<Vec<_>>()
|
|
|
|
|
})
|
|
|
|
|
.collect::<Vec<_>>();
|
2015-06-28 12:21:21 +00:00
|
|
|
|
|
2015-06-29 12:13:23 +00:00
|
|
|
|
let direction = if self.grid.across { grid::Direction::LeftToRight }
|
|
|
|
|
else { grid::Direction::TopToBottom };
|
|
|
|
|
|
2020-10-10 18:49:46 +00:00
|
|
|
|
let filling = grid::Filling::Spaces(4);
|
|
|
|
|
let mut grid = grid::Grid::new(grid::GridOptions { direction, filling });
|
2015-06-28 12:21:21 +00:00
|
|
|
|
|
2015-06-29 12:13:23 +00:00
|
|
|
|
if self.grid.across {
|
|
|
|
|
for row in 0 .. height {
|
2017-03-31 16:08:11 +00:00
|
|
|
|
for column in &columns {
|
2015-06-29 12:13:23 +00:00
|
|
|
|
if row < column.len() {
|
|
|
|
|
let cell = grid::Cell {
|
Replace Cells with growable TextCells
A recent change to ansi-term [1] means that `ANSIString`s can now hold either
owned *or* borrowed data (Rust calls this the Cow type). This means that we
can delay formatting ANSIStrings into ANSI-control-code-formatted strings
until it's absolutely necessary. The process for doing this was:
1. Replace the `Cell` type with a `TextCell` type that holds a vector of
`ANSIString` values instead of a formatted string. It still does the
width tracking.
2. Rework the details module's `render` functions to emit values of this
type.
3. Similarly, rework the functions that produce cells containing filenames
to use a `File` value's `name` field, which is an owned `String` that
can now be re-used.
4. Update the printing, formatting, and width-calculating code in the
details and grid-details views to produce a table by adding vectors
together instead of adding strings together, delaying the formatting as
long as it can.
This results in fewer allocations (as fewer `String` values are produced), and
makes the API tidier (as fewer `String` values are being passed around without
having their contents specified).
This also paves the way to Windows support, or at least support for
non-ANSI terminals: by delaying the time until strings are formatted,
it'll now be easier to change *how* they are formatted.
Casualties include:
- Bump to ansi_term v0.7.1, which impls `PartialEq` and `Debug` on
`ANSIString`.
- The grid_details and lines views now need to take a vector of files, rather
than a borrowed slice, so the filename cells produced now own the filename
strings that get taken from files.
- Fixed the signature of `File#link_target` to specify that the
file produced refers to the same directory, rather than some phantom
directory with the same lifetime as the file. (This was wrong from the
start, but it broke nothing until now)
References:
[1]: ansi-term@f6a6579ba8174de1cae64d181ec04af32ba2a4f0
2015-12-17 00:25:20 +00:00
|
|
|
|
contents: ANSIStrings(&column[row].contents).to_string(),
|
2015-12-17 02:34:11 +00:00
|
|
|
|
width: *column[row].width,
|
2015-06-29 12:13:23 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
grid.add(cell);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2017-03-31 16:08:11 +00:00
|
|
|
|
for column in &columns {
|
2015-06-29 12:13:23 +00:00
|
|
|
|
for cell in column.iter() {
|
|
|
|
|
let cell = grid::Cell {
|
Replace Cells with growable TextCells
A recent change to ansi-term [1] means that `ANSIString`s can now hold either
owned *or* borrowed data (Rust calls this the Cow type). This means that we
can delay formatting ANSIStrings into ANSI-control-code-formatted strings
until it's absolutely necessary. The process for doing this was:
1. Replace the `Cell` type with a `TextCell` type that holds a vector of
`ANSIString` values instead of a formatted string. It still does the
width tracking.
2. Rework the details module's `render` functions to emit values of this
type.
3. Similarly, rework the functions that produce cells containing filenames
to use a `File` value's `name` field, which is an owned `String` that
can now be re-used.
4. Update the printing, formatting, and width-calculating code in the
details and grid-details views to produce a table by adding vectors
together instead of adding strings together, delaying the formatting as
long as it can.
This results in fewer allocations (as fewer `String` values are produced), and
makes the API tidier (as fewer `String` values are being passed around without
having their contents specified).
This also paves the way to Windows support, or at least support for
non-ANSI terminals: by delaying the time until strings are formatted,
it'll now be easier to change *how* they are formatted.
Casualties include:
- Bump to ansi_term v0.7.1, which impls `PartialEq` and `Debug` on
`ANSIString`.
- The grid_details and lines views now need to take a vector of files, rather
than a borrowed slice, so the filename cells produced now own the filename
strings that get taken from files.
- Fixed the signature of `File#link_target` to specify that the
file produced refers to the same directory, rather than some phantom
directory with the same lifetime as the file. (This was wrong from the
start, but it broke nothing until now)
References:
[1]: ansi-term@f6a6579ba8174de1cae64d181ec04af32ba2a4f0
2015-12-17 00:25:20 +00:00
|
|
|
|
contents: ANSIStrings(&cell.contents).to_string(),
|
2015-12-17 02:34:11 +00:00
|
|
|
|
width: *cell.width,
|
2015-06-29 12:13:23 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
grid.add(cell);
|
|
|
|
|
}
|
2015-06-28 15:25:59 +00:00
|
|
|
|
}
|
2015-06-28 12:21:21 +00:00
|
|
|
|
}
|
2015-06-28 15:25:59 +00:00
|
|
|
|
|
|
|
|
|
grid
|
2015-06-28 12:21:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-06-29 13:47:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn divide_rounding_up(a: usize, b: usize) -> usize {
|
|
|
|
|
let mut result = a / b;
|
2020-10-10 18:49:46 +00:00
|
|
|
|
|
|
|
|
|
if a % b != 0 {
|
|
|
|
|
result += 1;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-29 13:47:07 +00:00
|
|
|
|
result
|
2017-05-10 08:26:50 +00:00
|
|
|
|
}
|
2017-06-25 23:53:48 +00:00
|
|
|
|
|
|
|
|
|
|
2020-10-13 00:36:41 +00:00
|
|
|
|
fn file_has_xattrs(file: &File<'_>) -> bool {
|
2017-06-25 23:53:48 +00:00
|
|
|
|
match file.path.attributes() {
|
2020-10-10 18:49:46 +00:00
|
|
|
|
Ok(attrs) => ! attrs.is_empty(),
|
|
|
|
|
Err(_) => false,
|
2017-06-25 23:53:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|