sharkdp / lscolors

A Rust library and tool to colorize paths using LS_COLORS
Apache License 2.0
265 stars 18 forks source link

Add a Colorable trait to factor out metadata retrieval #45

Closed tavianator closed 2 years ago

tavianator commented 2 years ago

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.

sharkdp commented 2 years ago

Very nice - thank you!