Commit Graph

101 Commits

Author SHA1 Message Date
Benjamin Sago
51be9f4c43 Introduce EXA_ICON_SPACING environment variable
This commit remove the extra space that was added between icons and file names in commit 128fadd, and adds an option to put them back.

Re-fixes GH-619 and fixes GH-541.
2020-10-24 19:41:07 +01:00
Benjamin Sago
a1869f208e Move common icons option to file style struct
All four of the view mode command-line argument parsers tested for the --icons option. Because it was common, the behaviour has been moved to the struct that handles file styles, meaning it can be parsed in one place.

This is a better place for it, as the icons are to do with the file name, not the view. It also means that the lines view has no options left for it, which is fitting.
2020-10-23 23:57:10 +01:00
Benjamin Sago
fd730e436c Make View command-line args position-dependent
This commit changes the way the View (long mode, lines mode, grid mode, etc) is parsed from the command-line arguments.

Previously, it checked for long and long-grid, then tree, then lines, then grid, in that order, no matter which order the arguments were given in on the command-line. Now, it bases the view on whichever argument comes last in the list.

Unfortunately, the options-parsing code for Views is getting really complicated, but I can't see a way to simplify it while retaining the existing functionality.

It also links the parsing of DirAction to the result of parsing the View, so that you can't use tree mode if your view isn't Details. This is to fix an issue where `exa --tree --oneline` would just emit ".", because the DirAction was treating directories as files, and the argument was ".", and the View made it use lines view. Now, the --tree is ignored, as the view isn't Details.

Fixes GH-407 and GH-583.
2020-10-23 23:04:22 +01:00
Benjamin Sago
3419afa7cf 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 22:34:00 +01:00
Benjamin Sago
eb90b4d168 Ignore --across --long conflict not in strict mode
Fixes #476.
2020-10-20 22:48:05 +01:00
Benjamin Sago
85414b2a61 Very slight test cleaning
I'm not 100% on the way these tests are laid out, but it _is_ helpful to see all the test data aligned like that.
2020-10-20 22:42:04 +01:00
Benjamin Sago
002080cde8 Clippy pedantic lints
This commit fixes a couple of Clippy warnings, and adds the list of lints we're OK with.

It does raise some important warnings, such as those to do with casting, which aren't allowed so they can be fixed later.
2020-10-13 01:46:17 +01:00
Benjamin Sago
3dc86c99ad New set of lints, and Rust 2018 idioms 2020-10-13 01:36:41 +01:00
Benjamin Sago
ed59428cbc 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 23:47:36 +01:00
Benjamin Sago
f8df02dae7 Batch source formatting
I read through every file and applied a couple of rustfmt suggestions. The brace placement and alignment of items on similar lines has been made consistent, even if neither are rustfmt's default style (a file has been put in place to enforce this). Other changes are:

• Alphabetical imports and modules
• Comma placement at the end of match blocks
• Use newlines and indentation judiciously
• Spaces around associated types
• Spaces after negations (it makes it more clear imho)
• Comment formatting
• Use early-returns and Optional `?` where appropriate
2020-10-10 20:02:55 +01:00
Benjamin Sago
a25cfe765d Remove some enum glob imports
These are holdovers from how I used to write Rust ("back in the day" of 2014). There are still some places in the code where I think it's worth glob-importing enums, but not these places.
2020-10-10 15:46:39 +01:00
Benjamin Sago
f0c139ca68 Better referencing
This commit makes changes to the way variables are referenced:

• Make types Copy when possible
• Make methods take `self` instead of `&self` where possible (trivially_copy_pass_by_ref)
• Remove unnecessary borrowing (needless_ref)
• Remove unnecessary cloning (clone_on_copy)
• Remove `ref` from match arms where possible (new Rust match ergonomics)
2020-10-10 15:30:19 +01:00
Benjamin Sago
70a30ed683 The Selfening
This commit uses Clippy to fix all the 'use_self' warnings. Using Self instead of the type name has been good Rust style for a while now, and it's become the style I'm used to seeing.
2020-10-10 13:55:26 +01:00
Benjamin Sago
dbbc4e465b
Merge pull request #704 from LarsHaalck/master
Add --octal-permissions argument
2020-10-08 22:14:38 +01:00
Lars Haalck
16046d57de
Add --octal-permissions argument
Using --octal_permissions will insert another column before the existing
permissions where permissions are encoded using octal values as
requested in #316
2020-07-24 13:47:34 +02:00
ariasuni
dba3f37b0a Fix Clippy lints 2020-05-24 21:43:55 +02:00
Benjamin Sago
490d9680c2 Merge branch 'fix-handling-maybe-unsupported-time-metadata' of https://github.com/ariasuni/exa into ariasuni-fix-handling-maybe-unsupported-time-metadata
# Conflicts:
#	src/fs/file.rs
#	src/options/filter.rs
#	src/options/view.rs
2020-01-19 16:46:51 +00:00
Benjamin Sago
416818fda2
Merge pull request #597 from FliegendeWurst/bugfixes
Two small bugfixes
2020-01-19 00:55:58 +00:00
Benjamin Sago
1f167dda41
Merge pull request #577 from 0rvar/feature/suppress-columns
Add support for suppressing table columns
2020-01-19 00:41:27 +00:00
ariasuni
a636d08f8b Fix handling of potentially unsupported time metadata
- Checking on a directory doesn’t tell us if supported elsewhere
(some filesystems, like tmpfs, don’t support created time)
- We want to be able to display a column even if some subfiles or
subdirectories don’t support it

So now if unsupported a time of zero is used, and displayed as `-`
2019-12-20 05:37:29 +01:00
FliegendeWurst
6010ed5213
Use the long view when stdout isn't a terminal and a long grid view was requested (fixes #522) 2019-10-12 11:58:31 +02:00
Orvar Segerström
925f5173c1 Add support for suppressing table columns 2019-08-29 14:34:30 +02:00
Bond_009
f599c7ce93 Update to Rust 2018 2019-07-19 20:40:21 +02:00
Benjamin Sago
9497b30b33 Merge branch 'glyphs' of https://github.com/asoderman/exa into asoderman-glyphs
# Conflicts:
#	src/options/flags.rs
#	src/options/view.rs
#	src/output/grid.rs
2019-07-15 03:54:31 +01:00
Benjamin Sago
9e1200f9b7 Fix failing tests 2019-07-15 03:37:05 +01:00
ariasuni
f0e7321506 Fix and add tests 2019-03-23 17:23:43 +01:00
ariasuni
39a49a3d36 Check if the sort field is supported by the OS 2019-03-23 17:23:43 +01:00
ariasuni
56717c7336 Add “changed” sort option, to replace old incorrect “created” 2019-03-23 17:23:40 +01:00
Benjamin Sago
c2bb986618 Replace Default impls that use state with fns
The Default impls for DefaultFormat and LoadFormat were originally called ‘new’, to which Clippy suggested that they be changed. But as these functions change based on what the year is, a function called something other than ‘new’, like ‘load’.
2018-10-13 22:15:10 +01:00
Benjamin Sago
ecc4138d56 Merge branch 'clippy_fixes' of https://github.com/thibran/exa into thibran-clippy_fixes
# Conflicts:
#	src/options/view.rs
#	src/style/lsc.rs
2018-10-13 22:07:35 +01:00
Thibaut Brandscheid
755876e9b6 fix most clippy warnings 2018-06-19 17:17:39 +02:00
mopp
991781070e refers TIME_STYLE environment variable if it exists and the argument is not given 2018-06-15 04:38:32 +09:00
Alex Soderman
68954f9142 Added --icons for oneline mode 2018-04-01 19:00:27 -04:00
Alex Soderman
5991bd4ab7 Added icons for --long view 2018-04-01 18:28:31 -04:00
Alex Soderman
217d1eefa9 moved icons functionality to grid mode 2018-03-26 17:02:05 -04:00
Alex Soderman
57e8802977 Added icons mode w/ prepending (icons themselves do not appear yet) 2018-03-22 19:13:02 -04:00
Benjamin Sago
a8bf990674 Tie value suggestions to their arguments
This commit changes the definition of Arg so that it knows about which values it can accept, and can display them in the help text. They were already being shown in the help text, but they were passed in separately, so one argument could show two different sets of options if it wanted. Now, the argument itself knows whether there are suggestions, so it doesn’t have to be passed in separately.

This means we can use it for other things, including listing choices when an option is missed out, without having to repeat the list.

With Misfire::BadArgument now only having two fields, it’s not worth using a constructor function anymore.
2017-09-14 01:22:37 +01:00
Benjamin Sago
b86074d63b Rename Style to Styles to avoid a name clash 2017-09-13 08:44:59 +01:00
Benjamin Sago
28b4b672d4 Move FileStyle to the same options file as Colours
They are going to be deduced together (from the same environment variable) so it makes sense to put them in the same file first.
2017-09-03 19:50:40 +01:00
Benjamin Sago
dd838c2dc1 Move Colours and LSColors to their own module
The ‘options’ module is allowed to depend on ‘style’, but ‘options::render’ is not.
2017-08-26 21:40:37 +01:00
Benjamin Sago
945fa1e83d Isolate and document the environment variables 2017-08-26 21:36:27 +01:00
Benjamin Sago
bfb8a5a573 Extract trait above file name colours
This commit meddles about with both the Colours and the FileExtensions.

Even though all the renderable fields were turned into traits, the FileName struct kept on accessing fields directly on the Colours value instead of calling methods on it. It also did the usual amount of colour misappropriation (such as ‘punctuation’ instead of specifying ‘normal_arrow’)

In preparation for when custom file colours are configurable (any day now), the colourise-file-by-kind functionality (links, sockets, or directories) was separated from the colourise-file-by-name functionality (images, videos, archives). The FileStyle struct already allowed for both to be separate; it was only changed so that a type other than FileExtensions could be used instead, as long as it implements the FileColours trait. (I feel like I should re-visit the naming of all these at some point in the future)

The decision to separate the two means that FileExtensions is the one assigning the colours, rather than going through the fields on a Colours value, which have all been removed. This is why a bunch of arbitrary Styles now exist in filetype.rs.

Because the decision on which colourise-file-by-name code to use (currently just the standard extensions, or nothing if we aren’t colourising) is now determined by the Colours type (instead of being derived), it’s possible to get it wrong. And wrong it was! There was a bug where file names were colourised even though the rest of the --long output wasn’t, and this wasn’t caught by the xtests. It is now.
2017-08-26 20:43:47 +01:00
Benjamin Sago
fb3395883e Start actually parsing ls_colors
So far it only changes the colour of a directory, but it’s a start.
2017-08-25 17:43:36 +01:00
Benjamin Sago
4907565baf Move colour options to their own file 2017-08-24 23:38:26 +01:00
Benjamin Sago
30f3c6eb00 Strict mode and tests for colour scale 2017-08-23 11:45:29 +01:00
Benjamin Sago
bcf5213cc8 Tie the row threshold to EXA_GRID_ROWS
This makes it its own type, rather than just another environment variable that’s easily missed.
2017-08-13 11:15:40 +01:00
Benjamin Sago
6740faa781 env vars should be referenced, not copied
Just because the type that gets used right now is Copy and Clone doesn’t mean that when we pass mock ones in for tests they’ll be those two as well. So we have to go through and add &s everywhere.
2017-08-13 11:14:58 +01:00
Benjamin Sago
33e83accd0 match-to-if-let 2017-08-12 22:51:45 +01:00
Benjamin Sago
da00e2fda2 Thread the row threshold through grid_details
No new features here, just some restructuring. Mode::GridDetails was nice and elegant with those two fields, but now there’s a grid-details-only option the elegance has gone out the window.
2017-08-12 22:49:16 +01:00
Benjamin Sago
eec1a4f78a Stop --git from complaining too
Re-fixes #152
2017-08-11 21:43:56 +01:00