Commit Graph

211 Commits

Author SHA1 Message Date
Ben S
19e0f9b70d Add inode number column 2014-06-22 07:44:00 +01:00
Ben S
fc8f8d6c6a Add number of hard links column
This is behaviour cribbed from ls. Even though I've never personally used it, I'm sure someone has a use for it.
2014-06-22 07:40:40 +01:00
Ben S
8839cf4ca5 Show file colours for symlink targets
This requires the dir field to store a reference to the path that
created it, so that path can be used to join onto the filename so it can
be properly statted.
2014-06-21 19:39:27 +01:00
Ben S
eff87440fa Do similar for block devices and named pipes
There doesn't seem to be an io::FileType entry for character special
devices or sockets, so these fall under the io::UnknownType entry. Which
also gets highlighted in yellow, for precisely that reason.
2014-06-21 18:27:26 +01:00
Ben S
a542fdc9f9 Highlight symlinks in cyan 2014-06-21 18:17:24 +01:00
Ben S
49d3caf0e9 Print directory names when given more than one 2014-06-21 18:12:29 +01:00
Ben S
b5a1b24bda Cache user and group names
I checked strace and it was reading /etc/passwd every time it needed to
look up a user or group. Now it only does it once per.
2014-06-21 17:50:37 +01:00
Ben S
5c0d2d07d0 Show files on the end of symlinks 2014-06-21 10:11:50 +01:00
Ben S
2adc9b8dc9 Actually display is better used here 2014-06-20 21:40:31 +01:00
Ben S
9187ded71b Tidy up unused imports 2014-06-20 21:08:02 +01:00
Ben S
92b45e6908 Handle errors instead of fail!()ing
Dir::readdir and File::from path now both return IoResults, rather than just calling fail! and exiting. This allows the program to continue after an error.
2014-06-20 21:07:53 +01:00
Ben S
355ca51617 Stop adding spaces to the end of each line
This left-aligns the final column, but the final column is the file name, so that's okay.
2014-06-20 19:43:15 +01:00
Ben S
8b68d699db Fix bug in sort where numbers could get too long
Fall back to strings. Also, add some unit tests.
2014-06-18 17:26:28 +01:00
Ben S
2bb563d448 Upgrade to latest Rust nightly
- s/syntax/phase
- no more boxed array syntax
- getopts fail implements Show
- option#expect now requires &str
2014-06-18 13:39:55 +01:00
Ben S
98b759d65d Merge branch 'refs/heads/file-types' 2014-06-18 08:27:15 +01:00
Ben S
f6b6d4d6a7 Merge the two source-file methods 2014-06-18 08:27:06 +01:00
Ben S
75e8d829f3 Make file types a trait 2014-06-17 22:17:22 +01:00
Ben S
03ec414dfb Move file-type detection to its own module
I'd much rather have this separate, as it has the definite potential to
balloon up to a huge size and end up making the other parts of the file
module hard to read. But on the other hand, it meant making a few more
methods public on file... readability over cleanliness, I guess.
2014-06-17 09:35:40 +01:00
Ben S
a5e404da55 Cache readdir results in a Dir object
This new object is then passed down to the File, so it can see what files are around it. This means it doesn't need to re-query the filesystem several times per file, instead using the in-memory copy.

Also, switch to using the built-in Path#with_extension method.
2014-06-17 00:27:05 +01:00
Ben S
78771a3a3e Add a bunch more file types
And an extra level of compiled files that don't get highlighted when their source files aren't present. I don't really like having two functions that do (almost) the same thing, but I have to due to the way colouring is done.
2014-06-16 23:34:22 +01:00
Ben S
cce20d5953 Highlight compiled files if their source is present
Compiled files with a source present (such as code.o when code.c is present) are now classified as temporary files. If the source isn't present, they're highlighted in a kind of drab colour (using the new 255-colour ability, yay!)

The code does do exists() checks on the filesystem when it could be possible to compare the files to the list of files we got from the call to readdir(), but it doesn't.
2014-06-16 21:20:09 +01:00
Ben S
b9fd420be2 Get rid of silly warning 2014-06-16 20:32:23 +01:00
Ben S
64770d0a5a 256-colour support
Add a Fixed(u8) constructor to Colour, which represents the 256 colours
that some terminals support. This means we can:

- stop using black bold to mean grey, which looks weird on terminals
  that haven't been set up to use it;
- support a *lot* more file type colours.

I'm a little suspicious of how much string allocation is being done in
colours.rs, but that's a problem for another time.
2014-06-16 12:43:34 +01:00
Ben S
f2ae611b49 Switch to Linux 2014-06-04 14:42:30 +01:00
Ben S
bc4df2cf3c Darken file size suffixes
I think this is necessary because 'bytes' currently has no 'B' suffix, and it's
kind of hard to distinguish a long number from a suffix.
2014-06-04 14:00:25 +01:00
Ben S
e5e426fc60 Right-align file sizes
Currently there's only one numeric column, and that's the file size, so it gets
special treatment.

I was originally going to have a folder file size field be filled up with '-'s
as far as it could go, leaving it entirely up to the column how its field gets
formatted. But then I saw just one '-' working just fine, so I left it like
that. In the first try, columns could do anything they want when padding a
string (including changing the padding character or just changing it entirely),
but now there's no point.
2014-06-04 13:45:14 +01:00
Ben S
2d41333117 Upgrade to latest Rust nightly
- s/to_owned/to_string/g
- TotalEq/TotalOrd changes
- snake_case of identifiers
2014-06-02 21:02:06 +01:00
Ben S
5abd53742e Remove extraneous lifetimes 2014-06-01 16:30:18 +01:00
Ben S
a631bc099f Sort case-insensitively 2014-06-01 13:07:45 +01:00
Ben S
4722c8991b Implement natural sorting on filenames 2014-06-01 11:54:31 +01:00
Ben S
6edf2c0d4d Highlight the current user 2014-05-27 19:05:15 +01:00
Ben S
48d8a46df8 Code cleanup (commenting the why) 2014-05-27 12:37:51 +01:00
Ben S
7091a42ab8 Hide the group by default 2014-05-26 18:08:58 +01:00
Ben S
0dd74a022f Add --binary flag
This finally means that the list of columns is no longer fixed, which means it has to be generated somewhere. And guess where it got moved to? That's right, the options object! (see previous commits)
2014-05-26 15:44:16 +01:00
Ben S
573765b62b Move filtering to options object, too
I'd like to have as few public methods on it as possible.
2014-05-26 12:46:51 +01:00
Ben S
1dbe20c8c5 Move sorting and reversing into options object 2014-05-26 11:50:46 +01:00
Ben S
05b2d541ac s/StrBuf/String/g 2014-05-26 11:08:33 +01:00
Ben S
566ed0bba8 Move columns to options object 2014-05-25 19:42:31 +01:00
Ben S
cb6dd57ca0 Move getopts code into options module 2014-05-25 18:14:00 +01:00
Ben S
ff0bef66e5 Cache the lengths of formatting-striped fields
The code could do with some comments, but it works.
2014-05-25 17:14:50 +01:00
Ben S
b116889abc Change format of file sizes to be shorter
I'm copying ls here because we don't really need the 'B' for bytes to be
listed every time. I think it looks better the new way. Unlike ls, don't
list directory sizes, because I've never found the pseudo-sizes they get
given at all useful.

Also, fix a bug where aligning columns didn't work when the number of
format characters (like '\x1B' and '[') were different between each
line.
2014-05-25 15:52:36 +01:00
Ben S
d60c2ce839 Add reverse parameter 2014-05-24 21:45:24 +01:00
Ben S
4d1aea12b0 Add colouring for media and compressed files 2014-05-24 20:40:31 +01:00
Ben S
7063c21ba0 Actually, cache the calls to ext
They get computed often enough for this to be worthwhile, and I have plans for using the extension even if it's not what's being sorted by.
2014-05-24 02:36:00 +01:00
Ben S
184de0ce79 Allow sorting by file extension 2014-05-24 02:32:57 +01:00
Ben S
cb1b8bc2d7 Add sort option
And move options struct into its own module
2014-05-24 02:17:43 +01:00
Ben S
fdf58e887b Upgrade to latest Rust (s/~str/StrBuf/)
See https://github.com/mozilla/rust/pull/14310
2014-05-24 01:14:40 +01:00
Ben S
f65d170b48 Add a readme 2014-05-22 13:55:11 +01:00
Ben S
503dfc07e6 Let's GPLv3 this. 2014-05-22 13:52:57 +01:00
Ben S
87f0bdea9e Print numeric UIDs and GIDs if they don't map to anything 2014-05-22 13:26:13 +01:00