Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Width Option #128

Merged
merged 7 commits into from
Aug 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ eza’s options are almost, but not quite, entirely unlike `ls`’s.
- **--icons**: display icons
- **--no-icons**: don't display icons (always overrides --icons)
- **--hyperlink**: display entries as hyperlinks
- **-w**, **--width=(columns)**: set screen width in columns

### Filtering options

Expand Down
1 change: 1 addition & 0 deletions completions/fish/eza.fish
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ complete -c eza -l git-ignore -d "Ignore files mentioned in '.gitignore'"
complete -c eza -s a -l all -d "Show hidden and 'dot' files"
complete -c eza -s d -l list-dirs -d "List directories like regular files"
complete -c eza -s L -l level -d "Limit the depth of recursion" -x -a "1 2 3 4 5 6 7 8 9"
complete -c eza -s w -l width -d "Limits column output of grid, 0 implies auto-width"
complete -c eza -s r -l reverse -d "Reverse the sort order"
complete -c eza -s s -l sort -d "Which field to sort by" -x -a "
accessed\t'Sort by file accessed time'
Expand Down
1 change: 1 addition & 0 deletions completions/zsh/_eza
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ __eza() {
{-d,--list-dirs}"[List directories like regular files]" \
{-D,--only-dirs}"[List only directories]" \
{-L,--level}"+[Limit the depth of recursion]" \
{-w,--width}"+[Limits column output of grid, 0 implies auto-width]" \
{-r,--reverse}"[Reverse the sort order]" \
{-s,--sort}="[Which field to sort by]:(sort field):(accessed age changed created date extension Extension filename Filename inode modified oldest name Name newest none size time type)" \
{-I,--ignore-glob}"[Ignore files that match these glob patterns]" \
Expand Down
5 changes: 4 additions & 1 deletion man/eza.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ Valid settings are ‘`always`’, ‘`automatic`’, and ‘`never`’.
`--hyperlink`
: Display entries as hyperlinks

`-w`, `--width=COLS`
Set screen width in columns.


FILTERING AND SORTING OPTIONS
=============================
Expand Down Expand Up @@ -204,7 +207,7 @@ eza responds to the following environment variables:

## `COLUMNS`

Overrides the width of the terminal, in characters.
Overrides the width of the terminal, in characters, however, `-w` takes precedence.

For example, ‘`COLUMNS=80 eza`’ will show a grid view with a maximum width of 80 characters.

Expand Down
3 changes: 2 additions & 1 deletion src/options/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub static RECURSE: Arg = Arg { short: Some(b'R'), long: "recurse", take
pub static TREE: Arg = Arg { short: Some(b'T'), long: "tree", takes_value: TakesValue::Forbidden };
pub static CLASSIFY: Arg = Arg { short: Some(b'F'), long: "classify", takes_value: TakesValue::Forbidden };
pub static DEREF_LINKS: Arg = Arg { short: Some(b'X'), long: "dereference", takes_value: TakesValue::Forbidden };
pub static WIDTH: Arg = Arg { short: Some(b'w'), long: "width", takes_value: TakesValue::Necessary(None) };

pub static COLOR: Arg = Arg { short: None, long: "color", takes_value: TakesValue::Necessary(Some(COLOURS)) };
pub static COLOUR: Arg = Arg { short: None, long: "colour", takes_value: TakesValue::Necessary(Some(COLOURS)) };
Expand Down Expand Up @@ -77,7 +78,7 @@ pub static ALL_ARGS: Args = Args(&[
&VERSION, &HELP,

&ONE_LINE, &LONG, &GRID, &ACROSS, &RECURSE, &TREE, &CLASSIFY, &DEREF_LINKS,
&COLOR, &COLOUR, &COLOR_SCALE, &COLOUR_SCALE,
&COLOR, &COLOUR, &COLOR_SCALE, &COLOUR_SCALE, &WIDTH,

&ALL, &ALMOST_ALL, &LIST_DIRS, &LEVEL, &REVERSE, &SORT, &DIRS_FIRST,
&IGNORE_GLOB, &GIT_IGNORE, &ONLY_DIRS,
Expand Down
1 change: 1 addition & 0 deletions src/options/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ DISPLAY OPTIONS
--icons display icons
--no-icons don't display icons (always overrides --icons)
--hyperlink display entries as hyperlinks
-w, --width COLS set screen width in columns

FILTERING AND SORTING OPTIONS
-a, --all show hidden and 'dot' files
Expand Down
22 changes: 19 additions & 3 deletions src/options/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::output::time::TimeFormat;
impl View {
pub fn deduce<V: Vars>(matches: &MatchedFlags<'_>, vars: &V) -> Result<Self, OptionsError> {
let mode = Mode::deduce(matches, vars)?;
let width = TerminalWidth::deduce(vars)?;
let width = TerminalWidth::deduce(matches, vars)?;
let file_style = FileStyle::deduce(matches, vars)?;
let deref_links = matches.has(&flags::DEREF_LINKS)?;
Ok(Self { mode, width, file_style, deref_links })
Expand Down Expand Up @@ -145,10 +145,26 @@ impl details::Options {


impl TerminalWidth {
fn deduce<V: Vars>(vars: &V) -> Result<Self, OptionsError> {
fn deduce<V: Vars>(matches: &MatchedFlags<'_>, vars: &V) -> Result<Self, OptionsError> {
use crate::options::vars;

if let Some(columns) = vars.get(vars::COLUMNS).and_then(|s| s.into_string().ok()) {
if let Some(width) = matches.get(&flags::WIDTH)? {
let arg_str = width.to_string_lossy();
match arg_str.parse() {
Ok(w) => {
if w >= 1 {
Ok(Self::Set(w))
} else {
Ok(Self::Automatic)
}
}
Err(e) => {
let source = NumberSource::Arg(&flags::WIDTH);
Err(OptionsError::FailedParse(arg_str.to_string(), source, e))
}
}
}
else if let Some(columns) = vars.get(vars::COLUMNS).and_then(|s| s.into_string().ok()) {
match columns.parse() {
Ok(width) => {
Ok(Self::Set(width))
Expand Down