Răsfoiți Sursa

Merge pull request #128 from gierens/width-option

Add Width Option
Christina Sørensen 2 ani în urmă
părinte
comite
5a3ef7ccc5
7 a modificat fișierele cu 29 adăugiri și 5 ștergeri
  1. 1 0
      README.md
  2. 1 0
      completions/fish/eza.fish
  3. 1 0
      completions/zsh/_eza
  4. 4 1
      man/eza.1.md
  5. 2 1
      src/options/flags.rs
  6. 1 0
      src/options/help.rs
  7. 19 3
      src/options/view.rs

+ 1 - 0
README.md

@@ -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
 

+ 1 - 0
completions/fish/eza.fish

@@ -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'

+ 1 - 0
completions/zsh/_eza

@@ -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]" \

+ 4 - 1
man/eza.1.md

@@ -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
 =============================
@@ -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.
 

+ 2 - 1
src/options/flags.rs

@@ -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)) };
@@ -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,

+ 1 - 0
src/options/help.rs

@@ -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

+ 19 - 3
src/options/view.rs

@@ -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 })
@@ -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))