Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Colorable trait to factor out metadata retrieval #45

Merged
merged 1 commit into from
May 15, 2022

Conversation

tavianator
Copy link
Contributor

The new Colorable trait exposes accessors for file name, type, and
metadata. LsColors::style_for_path() and ..._with_metadata() are now
implemented in terms of style_for(Colorable).

With file type potentially separated from metadata, the indicator_for()
implementation is careful to only call metadata() when actually
necessary to color the file. The new Colorable impl for DirEntry takes
advantage of this, potentially avoiding a stat() call when d_type is
sufficient.

Fixes #42.

The new Colorable trait exposes accessors for file name, type, and
metadata.  LsColors::style_for_path() and ..._with_metadata() are now
implemented in terms of style_for(Colorable).

With file type potentially separated from metadata, the indicator_for()
implementation is careful to only call metadata() when actually
necessary to color the file.  The new Colorable impl for DirEntry takes
advantage of this, potentially avoiding a stat() call when d_type is
sufficient.

Fixes sharkdp#42.
@sharkdp sharkdp merged commit 729660a into sharkdp:master May 15, 2022
@sharkdp
Copy link
Owner

sharkdp commented May 15, 2022

Very nice - thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generate ls_colors from file_type() call
2 participants