Commit Graph

34 Commits

Author SHA1 Message Date
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 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 3d82fc7683
Merge pull request #587 from brown121407/master
Fix "trait objects without an explicit `dyn` are deprecated"
2020-01-19 00:50:32 +00:00
Alexandru-Sergiu Marton f6071e9c46 Fix "trait objects without an explicit `dyn` are deprecated" 2019-10-01 18:55:09 +03:00
Bond_009 f599c7ce93 Update to Rust 2018 2019-07-19 20:40:21 +02:00
Benjamin Sago a45bcfe058 Rename broken_arrow to broken_symlink 2017-10-08 17:08:07 +01:00
Benjamin Sago 59d9e90f20 Replace “mi” colour with “bO” overlay
Fixes #288, but more-or-less as a side-effect.

The “mi” key in LS_COLORS was meant to be used for a missing link path, but it wasn’t really used like that. There was also a bug where control characters in a broken symlink’s path were assumed to be underlined, because that’s what happened in the default colour scheme, but this assumption doesn’t hold when colours were disabled.

The solution to these was not to introduce another configurable colour code, but to start using _overlays_ to alter a bunch of colours at once. The “mi” code will have to be added back later.
2017-10-08 17:08:07 +01:00
Benjamin Sago dc45332d7b Implement file name colouring in {exa,ls}_colors
This commit adds to the parsing of the LS_COLORS and EXA_COLORS variables so that non-two-letter codes (keys other than things like ‘di’ or ‘ln’ or ‘ex’) will be treated as file name globs, and get used to colour files accordingly.

Fixes #116 for good.
2017-09-13 08:51:57 +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 e5e23e23c7 Use the file type colour trait methods 2017-08-26 15:29:39 +01:00
Benjamin Sago 276d18cf7c Give block and character devices different colours
There are now two device colours instead of one. Even though they’re both set to the same style for the default colour set, LS_COLORS allows the two to look different, so exa has to support it too.

It’s probably a good idea to support it anyway.
2017-08-26 14:30:33 +01:00
Benjamin Sago d517e9e12b Split FileTypes into types and kinds
This separates the colours to give to files with different filesystem types (directories, links, sockets) from files with different names or extensions (images, videos, archives).

I’m not 100% sure I’ve got the terms “kind” and “type” the right way round, but whatever.

This was done because colouring files based on their name is going to be handled differently and extensibly from colouring files based on what the filesystem thinks.
2017-08-25 17:50:22 +01:00
Benjamin Sago c29170e345 Get the list of file extensions from the Options
The FileExtensions in the FileName is now a reference to the one in the original FileStyle, which gets put there in the options module.

This allows the extensions to be derived from the user, somehow, in the future when that part’s done.
2017-07-10 14:01:38 +01:00
Benjamin Sago 0d8d723408 Reify file extensions
Instead of having a File do its own extension checking, create a new type that takes a file and checks *that*. This new type (FileExtensions) is currently empty, but were it to contain values, those values could be used to determine the file’s colour.
2017-07-10 13:31:20 +01:00
Benjamin Sago bfa65b3bec Make not showing paths in link targets the default
This commit replaces the “two normal cases” of showing a link’s target or not with “one default and one special case” of preferring to hide them, displaying the link targets by setting a flag instead.

Doing this simplifies the file name constructor, which gets to remove an argument.
2017-07-08 12:24:22 +01:00
Benjamin Sago 0d613652a7 Replace FileName::new with a factory
The new FileStyles value will contain all the fields necessary to “style” a file’s name. Right now this is only the Classify field, but there can be more later. The benefit of this is that when we add more, we won’t need to update all the places where file names are displayed.
2017-07-08 12:11:11 +01:00
Benjamin Sago 31148eda7b Match up fields with parameter names
The arguments passed to File’s constructor were different from the field names used — these might as well both be the same.

Also, move ext and filename to be File methods to save an import, and add tests.

Also also, by passing a PathBuf in to the constructor directly, we can save one (possibly two) instance/s where we pass in a reference to something we were going to lose ownership of anyway, only to have it basically cloned.
2017-06-29 13:07:45 +01:00
Benjamin Sago 2f79b4db03 Start using new shorthand object field syntax 2017-05-18 22:43:32 +01:00
Benjamin Sago 4335f1978c Low-hanging clippy fruit 2017-05-07 17:15:22 +01:00
Benjamin Sago e916097e0e Similarly, turn Classify into an enum 2017-05-07 15:31:00 +01:00
Benjamin Sago 39381bfb49 Document the recent changes 2017-05-07 15:14:06 +01:00
Benjamin Sago 9f6376a560 Give broken links a different style in grid view
Because the link style and status are now both available to the function that picks the colour style, we can have it highlight broken links differently.

Fixes #131.
2017-05-07 14:45:04 +01:00
Benjamin Sago ccf8d44058 Replace the links boolean with an enum field 2017-05-07 14:08:36 +01:00
Benjamin Sago 88fecb7b26 Make the link target a field 2017-05-07 10:44:09 +01:00
Benjamin Sago 437ac0ea60 file_name -> FileName#paint 2017-05-02 08:52:24 +01:00
Benjamin Sago f51f5fe202 Also escape characters in broken symlinks 2017-05-02 08:46:43 +01:00
Benjamin Sago c81440429f Extract method add_parent_bits 2017-05-01 22:26:16 +01:00
Benjamin Sago 56d4d4c156 Also escape characters in links and headings
Doing this meant that the escaping functionality got used in three places, so it was extracted into a generalised function in its own module.

This is slighly slower for the case where escaped characters are displayed in the same colour as the displayable characters, which happens when listing a directory’s name when recursing. Optimise this, yeah?
2017-05-01 21:54:53 +01:00
Benjamin Sago 2d6d462439 Remember to escape characters in link targets
This was a bug introduced by 28fce347ff — it should have updated both places it does this in the function, rather than just one.
2017-05-01 16:53:51 +01:00
Benjamin Sago 5e0b9e0a10 A file’s colour is actually a style 2017-05-01 15:43:27 +01:00
Benjamin Sago 7531b2617c Split out function for --classify character 2017-05-01 15:41:29 +01:00
Benjamin Sago 05a0a5e199 Structify file_name -> FileName
This turns `file` into `self.file` and `colours` into `self.colours`, but it means we don’t need to pass arguments everywhere, which will be more of a problem the more functions there are.

Most of the code has just been indented.
2017-05-01 15:37:02 +01:00
Benjamin Sago 79feeba67d Move the functions in output to their own module
It didn’t feel quite right to have stand-alone functions in the module root file, which is usually just reserved for modules and exports.
2017-05-01 15:17:07 +01:00