Commit Graph

519 Commits

Author SHA1 Message Date
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
Benjamin Sago
4249cf0fcc Give control characters their own colour 2017-05-01 15:10:39 +01:00
Benjamin Sago
eb7e53ef6c Only highlight escaped characters in file names
Rather than the *entire* file name.

The current method is extremely inefficient, but having control characters in file names is also extremely uncommon; it’s something that should be fixed, only eventually.
2017-05-01 15:06:37 +01:00
Benjamin Sago
a53c268c54 Measure, rather than calculating, cell widths
exa deals with cells and widths a lot: the items in a grid need to be aligned according to their *contents’* widths, rather than the length of their strings, which often included ANSI escape characters. As an optimisation, it used to calculate this separately based on the filename, and dealing with any extra characters (such as the classify ones) in that function too.

Recently, though, file names have become a lot more complicated. Classification added zero to one extra characters, and now with escaped control characters in file names, it’s not so easy to calculate the display width of a filename.

This commit removes the function that calculated the width, in favour of building the output string (it’s going to be displayed anyway) and just getting the width of what it displays instead.
2017-05-01 14:11:16 +01:00
Benjamin Sago
28fce347ff Initial implementation of file name escaping
It doesn’t do a perfect job, but at least there aren’t newlines littering the output anymore.
2017-05-01 12:23:28 +01:00
Benjamin Sago
70f8ae6e20 Move “coloured file name” into its own function 2017-05-01 11:50:52 +01:00
Benjamin Sago
91ad09e188 Merge pull request #169 from kballard/symlink_leading_path
Don't prepend current path to symlink targets
2017-04-30 11:13:00 +01:00
Kevin Ballard
f8624ed308 Don't prepend current path to symlink targets
It's confusing, and `ls` doesn't do this either. We're not prepending
the current path to all of the directory entries, and the user is going
to interpret the symlink target as relative to the directory containing
the symlink.
2017-04-29 15:01:54 -07:00
Kevin Ballard
4beb7b6cb1 Handle linking to root directories better
We don't need a special case for this.
2017-04-29 14:38:28 -07:00
Benjamin Sago
956aa85b3b Special-case the root directory when linking to it
It’s the only file where its path is the same as its file name, and has been the source of numerous bugs in the past… this special-case isn’t very clean, but it works.
2017-04-29 11:52:10 +01:00
Benjamin Sago
7d6c1eb724 Merge pull request #168 from kballard/dot_filename
Print . and .. components properly
2017-04-29 10:58:39 +01:00
Benjamin Sago
e671217d60 Merge pull request #167 from kballard/two_path_components
Print paths with 2 components properly
2017-04-29 10:43:08 +01:00
Benjamin Sago
c205c3592b Merge pull request #159 from MakeNowJust/feature/classify
Implement -F/--classify option
2017-04-28 23:24:52 +01:00
Kevin Ballard
dd63774e37 Print . and .. components properly
`Path.file_name()` returns `None` if the path ends in `.` or `..`, which
causes e.g. `exa -d ..` to print a blank line.
2017-04-26 22:28:34 -07:00
Kevin Ballard
a28bd8fa64 Print paths with 2 components properly
Previously, `exa -d foo/bar` would print the file as "bar", but
`exa -d foo/bar/baz` would correctly print "foo/bar/baz".
2017-04-25 15:55:05 -07:00
Raphaël Pinson
8ac68f9964
Add cr2 as image 2017-04-19 00:08:29 +02:00
TSUYUSATO Kitsune
e81b83b4ac Implement -F/--classify option 2017-04-14 07:27:37 +09:00
Benjamin Sago
3087565c01 Merge pull request #154 from neosilky/clippy-fixes
Fix some issues indicated by clippy
2017-04-11 08:18:55 +01:00
Laurent Arnoud
8b61a3a0f2
Exit with a non-zero status on error
With `ls` from Debian coreutils 8.26-2

```
ls /bad/path
echo $? # => 2
```

Reproduced same behaviour with exa

Fix https://github.com/ogham/exa/issues/135
2017-04-01 00:10:49 +02:00
Daniel Lockyer
cc4a65ac4b Remove lifetimes as they aren't needed 2017-03-31 17:12:20 +01:00
Daniel Lockyer
79b4f1a6ee Switch to better handling method 2017-03-31 17:12:01 +01:00
Daniel Lockyer
ec84f16da7 Collapse down similar branches of match-statement 2017-03-31 17:11:49 +01:00
Daniel Lockyer
91459d608c Replace double-quote with single-quote 2017-03-31 17:10:18 +01:00
Daniel Lockyer
b68627ce1a Switch to padding reference as variable not consumed 2017-03-31 17:09:50 +01:00
Daniel Lockyer
e059fb5ba7 Remove unnecessary reference 2017-03-31 17:09:32 +01:00
Daniel Lockyer
da3061d1b3 Replace use of .iter() with reference 2017-03-31 17:08:11 +01:00
Benjamin Sago
3bce55f569 Run Untry over the entire source tree 2017-03-26 17:35:50 +01:00
Ben S
0ffb331976 Wire up the colour-scale option 2016-10-30 16:42:33 +00:00
Ben S
86065f832d File size colours on a scale
This adds an option (always on at the moment) to use a colour scale of green to yellow to orange for the file size field instead of always green. See #65.
2016-10-30 15:50:09 +00:00
Ben S
91e8ef5c78 Prepare to make the size colour take an argument
This makes the Colours value pick a colour based on the size of the file, instead of necessarily having them all green. (They are all green for now, though.)
2016-10-30 15:09:36 +00:00
Ben S
93f8ad27dc Remember to add ignore-glob to the help 2016-10-30 14:47:38 +00:00
Ben S
95596297a9 Basic glob ignoring
See #97 and recently #130 too.

This allows the user to pass in options such as "--ignore '*.pyc'" to not list any files ending in '.pyc' in the output. It uses the Rust glob crate and currently does a simple split on pipe, without any escaping, so it’s not really *complete*, but is at least something.
2016-10-30 14:43:33 +00:00
Ben S
a6712994c5 Make the views non-Copy
This has to be done for when ignore patterns get introduced and have to be stored in a Vec.
2016-10-30 14:31:25 +00:00
Ben S
74358c188a Properly handle errors when following a symlink
Fixes #123. The code assumes that every File that has its link_target() method called would first have been checked to make sure it’s actually a link first. Unfortunately it also assumed that the only thing that can go wrong while following a link is if the file wasn’t a link, meaning it crashes when given a link it doesn’t have permission to follow.

This makes the file_target() method able to return either a file or path for displaying, as before, but also an IO error for when things go wrong.
2016-10-29 20:27:23 +01:00
Ben S
dcc17b1d15 This lint flag started to cause all kinds of fuss 2016-10-29 19:52:21 +01:00
Ben S
36d9b6844e Add .tgz to the compressed file extensions
Fixes #129
2016-10-29 19:28:41 +01:00
Ben S
a7e3456b0d Only engage the view when there are files to show
This changes the way that views are used to display the actual lists of files. It used to pass empty vectors to the view methods, which most of the time would not print anything because there are no files to list — except when there’s a header row which gets printed for no files.

By not calling the view method at all when there’s nothing to print, exa won’t ever print extra things in the view unless it needs to for a file.

This fixes #106 “Don’t print the header if the result set is empty”
2016-10-29 19:07:43 +01:00
Benjamin Sago
6d3e6b7cad Merge pull request #122 from quodlibetor/include-legal-args-in-error-messages
Add legal values to error messages
2016-10-05 16:48:55 +01:00
Benjamin Sago
a8b05fce83 Merge pull request #119 from gemmarx/use_stderr
Change to put error messages into stderr
2016-10-05 16:47:51 +01:00
Brandon W Maister
7e15e0dd49 Add legal values to error messages
Now when you do `--sort time` instead of saying "unknown option --sort
time" it will say "unknown options '--sort time' (choices: name...)"
with all legal options.

This also adds the legal values to the default help text.
2016-08-28 21:56:32 -04:00
Gemmarx
8d25719b6b Change to put error messages into stderr 2016-07-31 04:12:03 +09:00
Gemmarx
943ac87466 Change to ignore broken pipe error 2016-07-30 22:53:11 +09:00
Linden Krouse
a9bb275250 Exa now recognizes pipes, devices, and sockets on unix systems. Fixes #112 2016-06-13 23:14:36 -04:00
Ben S
b8191670c7 Fix, and add tests for, slashes in link paths 2016-06-11 16:54:06 +01:00
Ben S
331d5ea724 Rename underscored lifetimes
See https://github.com/rust-lang/rfcs/pull/1177
2016-06-11 13:35:40 +01:00
Hendrik Sollich
c2d42e7d84 Fix building without default features 2016-05-03 00:03:22 +02:00
Benjamin Sago
110a1c716b Convert exa into a library
This commit removes the 'main' function present in main.rs, renames it to exa.rs, and puts the 'main' function in its own binary. This, I think, makes it more clear how the program works and where the main entry point is.

Librarification also means that we can start testing as a whole. Two tests have been added that test everything, passing in raw command-line arguments then comparing against the binary coloured text that gets produced.

Casualties include having to specifically mark some code blocks in documentation as 'tests', as rustdoc kept on trying to execute my ANSI art.
2016-04-19 07:48:41 +01:00
Benjamin Sago
a02f37cb45 Change views to print to a Writer, not stdout
This will mean that we can test exa's output as a whole, without having to rely on process or IO or anything like that.
2016-04-18 18:39:32 +01:00
Benjamin Sago
476406f43b Remove unused argument 2016-04-17 21:01:30 +01:00
Benjamin Sago
78ff651326 Remove unnecessary .to_string()s from option tests 2016-04-17 20:56:06 +01:00
Benjamin Sago
e9e1161cec Split up the options module
The original options was becoming a bit unwieldy, and would have been even more so if I added the same amount of comments. So this commit splits it up.

There's no extra hiding going on here, or rearranging things within the module: (almost) everything now has to be marked 'pub' to let other sub-modules in the new options module to see it.
2016-04-17 20:38:37 +01:00
Benjamin Sago
b44ae1b56b Remove pointless OptionSet trait
The trait was only used internally to the options module, so it doesn't actually need to be exist or implemented on anything! We can just impl them directly on the types and have those methods be local to the module.
2016-04-16 22:25:24 +01:00
Benjamin Sago
45c93b1b63 Correct the list of crypto extensions
They were the same as the archive/compressed extensions, and I never noticed!
2016-04-16 22:17:12 +01:00
Benjamin Sago
fae0f3874e Create info module with business logic routines
Currently these routines number two: file type checking based on a file's name, and source file checking, also based on the file's name.
2016-04-16 22:05:50 +01:00
Benjamin Sago
b83844f384 Move a file's type out of its permissions field 2016-04-16 20:01:45 +01:00
Benjamin Sago
570fac0c18 Add comments to the new fields module 2016-04-16 19:56:44 +01:00
Benjamin Sago
efa372cb3b Source file rearrangements
This commit moves file, dir, and the feature modules into one parent 'fs' module. Now there are three main 'areas' of the code: main and options, the filesystem-touching code, and the output-displaying code.

It should be the case that nothing in 'output' touches 'std::fs'.
2016-04-16 18:59:25 +01:00
Benjamin Sago
b65043d6d9 Update raw libc types for Rust 1.8.0
Fixes #108. MetadataExt now returns direct numeric types rather than platform-specific ones, so we need to adjust the functions that use these to have the new types. I've just aliased the types to specific ones so the rest of the code remains the same (file.rs is the only place that uses this)

The RFC that changed this is here: https://github.com/rust-lang/rust/pull/31551
2016-04-16 17:06:26 +01:00
Benjamin Sago
9b87ef1da2 Print the parent path for passed-in files
This commit changes all the views to accommodate printing each path's prefix, if it has one.

Previously, each file was stripped of its ancestry, leaving only its file name to be displayed. So running "exa /usr/bin/*" would display only filenames, while running "ls /usr/bin/*" would display each file prefixed with "/usr/bin/". But running "ls /usr/bin/" -- without the glob -- would run ls on just the directory, printing out the file names with no prefix or anything.

This functionality turned out to be useful in quite a few situations: firstly, if the user passes in files from different directories, it would be hard to tell where they came from (especially if they have the same name, such as find | xargs). Secondly, this also applied when following symlinks, making it unclear exactly which file a symlink would be pointing to.

The reason that it did it this way beforehand was that I didn't think of these use-cases, rather than for any technical reason; this new method should not have any drawbacks save making the output slightly wider in a few cases. Compatibility with ls is also a big plus.

Fixes #104, and relates to #88 and #92.
2016-04-11 19:10:55 +01:00
Benjamin Sago
f35d28d1b8 Fix bug where the directory name was not printed 2016-04-11 07:48:23 +01:00
Benjamin Sago
c009a68ae5 Add Add impl and various tests for DisplayWidth 2016-04-05 18:45:35 +01:00
Ben S
f6c5c89f55 Always sort files the same way
This fixes a bug where extra sorting options (dirs first, reverse) were not applied when listing in long mode. In other words, fixes #105.

The bug occurred because the sorting function only took Files, but the details view uses File eggs that only contain Files. This commit changes the sorting function to accept anything that AsRefs to File, and impls that on both File and Egg so the same function works for both.
2016-03-31 23:13:15 +01:00
Ben S
eaa799c647 Replace deprecated raw types with libc ones
This limits it to stable until the APIs stabilise (weird, huh?)
2016-03-31 21:42:53 +01:00
Ben S
ee4c09dd30 Use only the time zone data present on the system
Thinking about it, it doesn't make sense to use an *external* time zone source when the program we want to compare it to, ls, uses the system one. So just use the system one.

Also, handle the case where the time zone data file can't be loaded by showing the files in UTC rather than falling over and quitting.
2016-03-31 21:19:29 +01:00
Ben S
8805ce9e3b Add case-insensitive extension sorting
This finishes off and closes #102. The code in this and the previous commit
were partly authored by `zv0n` on GitHub.
2016-03-19 15:06:26 +00:00
Benjamin Sago
3e9616cffa Add --sort=Name case-insensitive sorting
This uses the case-insensitive sort function in the `natord` crate to
convert both strings to lowercase lazily, sorting them as it goes. It
also adds tests for `--sort` in general.

The case sensitivity has been made an enum so it can be reused for other
fields (say, the file extension).

See #102.
2016-03-18 10:20:44 -04:00
Benjamin Sago
d3846468a3 Fix my own broken changes
- Fix visibility errors I stupidly didn't test before committing earlier
  today
- Silence warnings about casting that were necessary for ARM
- Update dependencies
2016-03-18 08:19:51 -04:00
Ben S
8ef316e1a4 Remove unnecessary FileTypes trait 2016-03-17 20:40:04 +00:00
Ben S
252eba4844 Improve error when we can't find a time zone 2016-02-11 15:52:40 +00:00
Ben S
2e8de3fb71 Fix import of TZResult 2016-02-10 19:11:10 +00:00
Ben S
7f480ab06b Improve system time zone detection 2016-02-10 19:02:20 +00:00
Ben S
b3d252522a Update test timezone to one we know exists
It wasn't the Arc unwrap causing the crash on Linux. Maybe it's this.
2016-02-10 16:16:09 +00:00
Ben S
2b213b3aea Rewrite tests to not use unwrap
Something about these seemed to be causing a crash on Travis (build 327)... I have no idea what would set it off, but this makes the code better anyway.
2016-02-10 16:08:15 +00:00
Ben S
75b2748ab1 Update packages to latest versions
- Users v0.5.1, which renames OSUsers to UsersCache
- Locale v0.2, which returns to libc v0.1
- Datetime v0.4.2, which mimics the locale update, and puts timezone definitions in:
- Zoneinfo-data, which is needed to obtain the current timezone
2016-02-10 15:22:43 +00:00
Benjamin Sago
4c3266310d Fix bug where xattr '@' characters weren't shown
The `--long` flag should show the '@' character in the permissions list if that feature has been compiled in, but only the `--extended` flag should actually show their keys, rather than just their presence.
2016-01-16 12:19:00 -10:00
Benjamin Sago
7f980935c5 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 11:56:37 -10:00
Benjamin Sago
d009ba5938 Move tree code to its module, and add tests
This commit separates the code used to generate the tree structure characters from the code used to build tables, meaning that it'll become possible to display tree structures without using any of the table code.

Also, some tests are added to make sure that the tree code *basically* works.
2015-12-22 15:44:51 +11:00
Benjamin Sago
54319a685e Use Vec::resize now that it has stabilised 2015-12-22 15:36:36 +11:00
Benjamin Sago
d1ea4c0ff5 Move TreePart to its own module 2015-12-22 13:14:32 +11:00
Benjamin Sago
2e15b81249 Optimise imports
1. imports from std
2. imports from external crates
3. imports from local modules
4. imports from self
2015-12-22 12:15:59 +11:00
Benjamin Sago
1b3492ce45 Move colours module into output
This commit moves the colours module to be a sub-module of the output one.
This makes sense because finding which colour a certain file should be is only
done during output, and (I think) the only places that the `Colours` struct's
fields are ever queried is from the output module.

The only casualty was that the `file_colour` from the filetype module had to
be moved, as determining colours is no longer part of that module - only
determining filetype is. So it now reflects its name!
2015-12-20 17:56:57 +11:00
Benjamin Sago
15cd67abe6 Turn TextCellContents into a struct
The benefit of this is that it make it possible to convert text cell contents
vectors into text cells with a method (see next commit). Casualties include
having to call `.into()` on vectors everywhere, which I'm not convinced is a
bad thing.
2015-12-17 17:51:42 +08:00
Benjamin Sago
39aa210437 Rename cell 'length' to 'width'
Because, strictly speaking, it's not a length, it's a width!

Also, re-order some struct constructors so that they're no longer
order-dependent (it's no longer the case that a value will be borrowed for one
field then consumed in another, meaning they have to be ordered in a certain
way to compile. Now the value is just worked out beforehand and the fields can
be specified in any order)
2015-12-17 10:34:11 +08:00
Benjamin Sago
88653a00eb Remove dependency between file and output mods
By removing the `File#file_name_width` method, we can make the file module
have no dependency on the output module -- in other words, the model (file)
and the view (output) are now separate again!
2015-12-17 10:27:44 +08:00
Benjamin Sago
4c2bf2f2e6 Encapsulate "display width" in a struct
This commit introduces the `output::cell::DisplayWidth` struct, which
encapsulates the Unicode *display width* of a string in a struct that makes it
less easily confused with the *length* of a string.

The use of this type means that it's now harder to accidentally use a string's
length-in-bytes as its width. I've fixed at least one case in the code where
this was being done!

The only casualty is that it introduces a dependency on the output module from
the file module, which will be removed next commit.
2015-12-17 10:15:09 +08:00
Benjamin Sago
c911b5f6e4 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 08:25:20 +08:00
Benjamin Sago
95c0d63045 io::Result -> IOResult 2015-12-15 21:47:37 +00:00
Benjamin Sago
47b088d662 Merge pull request #87 from petevine/master
Fix compilation on arm using stable rust 1.5
2015-12-15 20:15:16 +00:00
Jan Beich
92328d9093 Move CString to where it's actually used
src/feature/xattr.rs:6:5: 6:22 warning: unused import, #[warn(unused_imports)] on by default
src/feature/xattr.rs:6 use std::ffi::CString;
                           ^~~~~~~~~~~~~~~~~
2015-12-14 03:13:40 +00:00
Jan Beich
b35927f247 Fix logic inversion with --git in --help
$ exa --help
[...]
  -@, --extended     display extended attribute keys and sizes

$ exa -@
Unrecognized option: '@'.

$ exa --extended
Unrecognized option: 'extended'.

$ exa --git
Option --git is useless without option --long.

$ exa -l --git
.rw-r--r--  11k user 10 Dec 18:26 -- Cargo.lock
[...]
2015-12-14 04:11:03 +03:00
Jan Beich
b9eb364823 Fix getting tty window size on more BSDs
src/term.rs:37:39: 37:49 error: unresolved name `TIOCGWINSZ` [E0425]
src/term.rs:37     let result = ioctl(STDOUT_FILENO, TIOCGWINSZ, &mut window);
                                                     ^~~~~~~~~~
2015-12-14 04:10:46 +03:00
petevine
734c5084ba Update xattr.rs 2015-12-11 05:50:20 +01:00
Ben S
1756a0a841 Fix bug where details view needed a terminal width
The buggy code assumed that, if output isn't to a terminal, then the only view available is the Lines view. This is incorrect, as the Details view doesn't require a set width either, so check for --long even when there's no set width.
2015-11-19 12:47:53 +00:00
Ben S
f92459d957 Add --colo[u]r options
The user can now control the output parameters by specifying the console width and when to show colours.

Fixes #75.
2015-11-19 12:31:43 +00:00
Ben S
c543e61ced Improve code in two insignificant little places 2015-11-19 12:19:04 +00:00
Ben S
ceae7e747c Rearrange trait definitions in options
This puts the impls for the structs defined in the module first, then impls for the structs defined in the columns module second.
2015-11-15 21:04:48 +00:00
Ben S
e07992d08c Use lazy_static to cache datetime formats
One of those two date formats was re-compiled before any date was displayed. Now they are compiled only the first time they're used, and cached versions are used thereafter, resulting in a speedup.
2015-11-15 19:26:58 +00:00
Ben S
edeec0f6f2 Improve help text
Instead of using the getopts crate’s dynamically-generated usage string, use a more static one:

- The options are organised by category now
- You can use `--help --long` to display only the ones that pertain to `--long`
- They’re aligned in a table sort of way

It could be generated statically, because all the options to change it are determined at compile time, but they’re not, yet...
2015-11-15 17:18:02 +00:00
Ben S
590fb9cd60 Move time type picking to details module
Technically speaking, picking which timestamp to show for a file is a function of an output module, rather than the file itself. This also means that the `output::column` and `file` modules are now completely separate.
2015-11-15 16:12:16 +00:00
Ben S
ca65c981f1 Avoid cloning the file names vector
By taking the file names as a mutable vector, we can avoid having to allocate a new one when it’s empty. The recent changes to Options::getopts have made it more obvious that we could move the same vector out of getopts’s matches, instead of cloning it there.
2015-11-15 15:52:55 +00:00
Ben S
2efaf7ec45 Options and FileFilter are also deducible
We may as well use this trait now that it’s available!
2015-11-15 15:07:19 +00:00
Ben S
534d3c3fa5 Extract 'bad argument' method 2015-11-15 00:02:39 +00:00
Ben S
8b9f074d63 Inline SortField::from_word
With the new OptionSet trait, the from_word constructor doesn't really do much by itself.
2015-11-14 23:47:13 +00:00
Ben S
10468797bb Move many Options structs to the output module
This cleans up the options module, moving the structs that were *only* in use for the columns view out of it.

The new OptionSet trait is used to add the ‘deduce’ methods that used to be present on the values.
2015-11-14 23:32:57 +00:00
Florian Gilcher
48d1e5164c Move file mode constants to a private module 2015-11-04 15:56:37 +01:00
Florian Gilcher
d083d26eaf Fix tree output 2015-11-04 15:22:51 +01:00
Florian Gilcher
77fa8974c4 Fixup: split prefix tests by property 2015-11-04 11:39:01 +01:00
Florian Gilcher
7a97b7d40c Reserve Vector elements instead of resizing 2015-11-04 11:07:31 +01:00
Florian Gilcher
7f53da73b7 Use slicing instead of future slice_last 2015-11-04 11:07:08 +01:00
Florian Gilcher
e8ea96ee86 Avoid unstable c_string conversion features 2015-11-04 10:25:20 +01:00
Florian Gilcher
b3e3825417 Replace unstable fs_mode by internal constants 2015-11-04 09:51:34 +01:00
Florian Gilcher
679b9e18b2 Replace sum call by stable fold(0, Add::add) 2015-11-04 09:41:49 +01:00
Ben S
63bd929eb5 Upgrade to latest ansi_term
Changes to the way ANSIStrings work mean we need to dereference the strings before putting them in an ANSIString. There's more that can be done here, but this gets it to compile for now.
2015-11-03 11:17:44 +00:00
Ben S
bc47073281 Feature slice_splits and vec_resize stabilised
As of rustc 1.6.0-nightly (1a2eaffb6 2015-10-31), anyway.
2015-11-03 11:16:19 +00:00
Ben S
f7131a740b Fix warning when building on 64-bit systems
This warning was 'caused' by the previous commit (but it's small and easy to fix, so don't worry)
2015-10-02 00:56:09 +01:00
rhysd
3dbc441c78 Fix integer length error on 32bit environment
this commit fixes below type mismatch error:

```
src/output/details.rs:585:49: 585:60 error: mismatched types:
 expected `i64`,
    found `i32`
(expected i64,
    found i32) [E0308]
src/output/details.rs:585         let date = self.tz.at(LocalDateTime::at(timestamp.0));
                                                                          ^~~~~~~~~~~
src/output/details.rs:585:49: 585:60 help: run `rustc --explain E0308` to see a detailed explanation
error: aborting due to previous error
Could not compile `exa`.
```
2015-09-28 11:42:52 +09:00
Ben S
41fb02a02d Upgrade to latest version of datetime crate
- VariableOffset -> TimeZone::VariableOffset
2015-09-21 00:15:07 +01:00
Benjamin Sago
3d3acc2e93 Dismiss some compile-time warnings
The `unused_results` lint was complaining that the results of inserting into a `MockUsers` object weren't being inspected. These are mock users, so all that would be returned is `None` to indicate that they weren't already in the table -- they're fine to ignore! So, suppress the warnings for those two testing modules.
2015-09-15 20:05:27 +01:00
Michael Neumann
6317417a98 This makes exa work on other platforms than linux and macosx. 2015-09-14 01:37:52 +02:00
Benjamin Sago
6cf9274828 Do not attempt to print nothing
This fixes a bug where an extra header line was printed when in --long --grid mode.
2015-09-05 17:40:02 +01:00
Ben S
65967355a8 Make sure we check the ioctl term size result 2015-09-04 11:30:46 +01:00
Ben S
d1e682b0c1 Remove pad crate and unnecessary qualifications 2015-09-04 11:20:13 +01:00
Ben S
f526d24911 Remove trivial cast 2015-09-04 11:17:59 +01:00
Ben S
10fecbd7f6 Details view comments and tidy-ups 2015-09-03 18:48:53 +01:00
Ben S
a14f1d82f0 It's hardly worth giving Exa its own constructor 2015-09-03 13:38:18 +01:00
Ben S
83f05ffb3c Remove redundant attribute field 2015-09-03 13:38:06 +01:00
Ben S
4424a6df96 Rename readdir -> read_dir 2015-09-03 10:51:59 +01:00
Ben S
4e49b91d23 Parallelise the details view!
This commit removes the threadpool in `main.rs` that stats each command-line argument separately, and replaces it with a *scoped* threadpool in `options/details.rs` that builds the table in parallel! Running this on my machine halves the execution time when tree-ing my entire home directory (which isn't exactly a common occurrence, but it's the only way to give exa a large running time)

The statting will be added back in parallel at a later stage. This was facilitated by the previous changes to recursion that made it easier to deal with.

There's a lot of large sweeping architectural changes. Here's a smattering of them:

- In `main.rs`, the files are now passed around as vectors of files rather than array slices of files. This is because `File`s aren't `Clone`, and the `Vec` is necessary to give away ownership of the files at the appropriate point.
- In the details view, files are now sorted *all* the time, rather than obeying the command-line order. As they're run in parallel, they have no guaranteed order anyway, so we *have* to sort them again. (I'm not sure if this should be the intended behaviour or not!) This means that the `Details` struct has to have the filter *all* the time, not only while recursing, so it's been moved out of the `recurse` field.
- We use `scoped_threadpool` over `threadpool`, a recent addition. It's only safely used on Nightly, which we're using anyway, so that's OK!
- Removed a bunch of out-of-date comments.

This also fixes #77, mainly by accident :)
2015-09-02 23:19:10 +01:00
Ben S
5f48bfd8b4 Propagate errors that occur during readdir
Fixes #71 - the I/O error should now be displayed as an error, rather than as a panic.

Also, fix some comments.
2015-08-26 12:19:23 +01:00
Ben S
5e1ff9cdcd Restore xattrs to their long view column
Had to thread the value in at display-time to get it to only query the attributes once!

This isn't the nicest way to do it, but this *is* a bit of an edge-case (it's the only thing where a column depends on something that gets calculated later)
2015-08-26 12:00:31 +01:00
Ben S
31dec1d1ba Use the correct ASCII for rows with errors/attrs
This prints three separate groups of child nodes: firstly the xattrs, then the errors, then any file children. It's done this way to only check for the 'last' child when necessary.
2015-08-26 11:36:10 +01:00
Ben S
b5edee53bd Scan for nested files on-demand, not all the time
This does a similar thing that we did with the xattrs, except with the nested files: it removes the 'this' field on File, and replaces it with a method (to_dir) that has the same effect.

This means we get to remove a bunch of 'recurse' fields and parameters that really had no business being there! Now the table doesn't need to know whether it's going to need to list files recursively or not.
2015-08-26 09:35:11 +01:00
Ben S
69b22a0d66 Print xattrs in tree view like we do errors
This changes the way extended attributes (xattrs) are printed. Before, they were artificially printed out on their own line both in lines mode *and* details mode, which looked a bit weird. Now, they are additional 'child nodes' of that item that get printed alongside errors.

All this allows all the 'extra info' that is going to be present for very few entries to be consolidated and listed in the same way, without resorting to extra printlns.

As a great side-effect, it allows taking out some of the more redundant code in the Table impl -- it is now *always* going to be in create-child-nodes mode, as *any* file now can, not only when we have the --tree flag in use.

Also, it now actually displays errors when failing to read the extended attributes, such as if the user doesn't have permission to read them.

The extended attribute flag has been temporarily disabled while I work out the best way to do it!
2015-08-26 09:03:43 +01:00
Ben S
a250f21282 Coalesce platform-specific xattr modules
Now we have one Ur-module that contains functionality common to both supported platforms.

The benefits of doing it this way are that:

1. It doesn't implement a dummy interface - rather, there will be less code generated when the feature is not present;
2. The code shared between them can be kept in sync. The other two modules were something like 80% the same.
2015-08-25 18:29:23 +01:00
Ben S
2741c19e93 Fix bug where errors' tree parts ended early
Have to collect the results into a Vec in order to make sure we only do the ending part for the last one.
2015-08-25 15:27:24 +01:00
Ben S
2a9b6fe930 Display errors inline in the tree
When tree mode is active, this will print out errors as another form of child node in the tree, instead of in one big block before any output.

The 'this' field now holds the io::Result of the readdir call, rather than only a *successful* result.
2015-08-25 15:04:15 +01:00
Ben S
7deb08644a Comment corrections 2015-08-25 11:50:07 +01:00
Ben S
ec0539d314 Make the cells optional for display Rows.
This will be used to not provide any information for the rows that will have no data (attributes, errors).
2015-08-25 11:45:27 +01:00
Ben S
5d0bd37168 Make Dir return an Iterator of files, not Vec
This is part of work to make the flow of files more iterator-able, rather than going in and out of vectors. Here, a Dir returns an iterator of files, rather than a pre-filled vector.

For now, this removes the ability for error messages to be displayed. Will be added in later though!
2015-08-25 11:27:08 +01:00
Ben S
d547c3f5d7 Fix bug where Git repos were always queried
This is very slow (see #28) at the moment, so there's an option to switch off repo discovery. However, they were still always being queried. Now, if there's no Git option in the flags, it won't try to discover a repo.
2015-08-03 18:44:33 +01:00
Ben S
e1f4ea9215 Allow --tree without --long
This kind of abuses the details view by giving it no columns when the Columns value is None (it's now Optional).
2015-08-03 13:54:25 +01:00
Ben S
ebbac61c74 Slim down symlink arrow
Fixes #74. There's one argument for changing the arrow, and none against!
2015-08-03 10:22:24 +01:00
Ben S
21ee2fbb30 Use new slice_splits functions
These replace `init()` and `tail()` which are deprecated in favour of these.

In fact, it's a good thing they're deprecated, because part of the path_prefix code involved working around a call to init() that would panic otherwise - doing the same check with an `Option` is much more ergonomic.
2015-08-02 15:28:40 +01:00
Ben S
d710151ea9 Updates for term-grid
The separator_width field in the term_grid crate was replaced with a filling field.
2015-07-15 21:16:08 +01:00
Ben S
56895ab84f Extract some methods 2015-06-29 14:47:07 +01:00
Ben S
2bc7fde715 Allow using --across with --long --grid 2015-06-29 13:13:23 +01:00
Ben S
6d6e8b78f0 Fix bug where unfilled displays were being checked 2015-06-28 21:27:18 +01:00
Ben S
26e3abc6b1 Re-add missing failing option combinations 2015-06-28 20:41:38 +01:00