Commit Graph

780 Commits

Author SHA1 Message Date
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
c39a57294c Versions bump 2015-12-15 21:38:56 +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
Benjamin Sago
f2143d948c Merge pull request #89 from jbeich/freebsd
Minor fixes for FreeBSD
2015-12-15 20:12:36 +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
f3e6a99676 Update screenshots
GitHub's new, wider view makes two screenshots side-to-side look nicer than one.
2015-11-23 19:48:30 +00:00
Ben S
5cd1d6a13c Update readme with latest option set 2015-11-19 13:21:49 +00:00
Ben S
d89307bc43 Replace missing man page fields 2015-11-19 13:21:31 +00: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
41905eaba4 Add new, pandoc-powered man page
This also includes some of the options that I forgot existed. Don't be mad.
2015-11-19 12:42:30 +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
9218799e6e Upgrade versions to working ones 2015-11-18 18:32:40 +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
021655faec Merge branch 'better-options' 2015-11-15 18:37:18 +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
Ben S
cc04d0452f Pin versions to those we know work 2015-11-04 17:01:05 +00:00
Benjamin Sago
caf5fce1e8 Merge pull request #85 from skade/move-to-stable
Move to stable
2015-11-04 16:31:05 +00:00
Florian Gilcher
30e4eb8b06 Fixup README version constraint 2015-11-04 16:27:51 +01:00
Florian Gilcher
c32ebdb904 Remove the other reference to nightly 2015-11-04 16:02:47 +01: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
ad39d6e282 Test on nightly, beta and stable 2015-11-04 11:29:29 +01:00
Florian Gilcher
5556c6a40b Update README 2015-11-04 11:12:20 +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
1bebab78d0 Upgrade Rust version necessary 2015-10-30 10:40:56 +00:00
Ben S
8f4a2087e6 Version v0.4.0 2015-10-18 20:34:46 +01:00
Ben S
cfc8df12b6 Update the version of Rust that's required 2015-10-02 01:04:07 +01:00
Ben S
878d54111d Pin to git2-rs version 0.3
This should prove more stable than relying on a Git version.
2015-10-02 00:56:39 +01: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