Comments (5)
@Peltoche Please take a look at #15 and see if this is something that could help with your use case. Please note that you will still be required to write some logic on your own if you don't want to use the style_for_path
/style_for_path_with_metadata
methods.
from lscolors.
Thank you very much for the feedback and sorry for the late response.
Before we add another public method to the API, I'd like to consider alternative options.
In your use case, instead of converting from fs::Metadata
to lsd::Metadata
to lscolors::Filetype
, wouldn't it be easier (and faster) to just keep the original fs::Metadata
object around (and call LsColors::style_for_path_with_metadata
)?
If this is not possible for some reason, we could also think of using a trait (with methods such as is_directory
) that would come with an implementation for fs::Metadata
. You could then implement this trait for lsd::Metadata
.
The third alternative is your enum
version, which also sounds like a reasonable way to go (although I'd like to find another name for the function).
from lscolors.
The first two solution seems a little complicated for us at the moment due to the colorize
signature and our architecture in general:
pub fn colorize<'a>(&self, input: String, elem: &Elem) -> ColoredString<'a>
pub enum Elem {
/// Node type
File,
SymLink,
...
/// Permissions
Read,
Write,
...
/// Last Time Modified
DayOld,
...
}
The Elem
enum allow us to keep the non color related logic outside the color
package. For example we don't want to parse the last modified date and check if the file is older than 24H inside the color package. We can probably change the signature and add a fs::Metadata
as argument but it would be only used when the LS_COLORS variable is set and I would not be very comfortable with this sort of optional variable.
The second solution would be more easy for us but still relatively hard as we would need to implement the trait for each value of the Elem
enum (~25 elements).
In our case the third alternative seems to be the only viable solution between all the ones proposed. For the name, if you accept the proposition, you can choose what you want, the one above was only a quick proposition for the example.
from lscolors.
I'm going to close this (for now) as this seems to be resolved to me.
from lscolors.
It seems all good! Thanks!
from lscolors.
Related Issues (20)
- Support for `tui-rs`? HOT 1
- Windows support? HOT 19
- [feature request] API to style file paths that don't exist on disk HOT 6
- Feature request: Always add ANSI coloring sequence, HOT 1
- Feature request: option to return a substring of the colored file name HOT 1
- Release a new version for the support of crossterm HOT 1
- Support for bright/light colors HOT 1
- Crossterm conversion using incorrect colors HOT 2
- Generate ls_colors from file_type() call HOT 4
- Tracking issue for incompatibilities with GNU ls HOT 5
- support crossterm 0.24 with it's new underline styles HOT 2
- Support LSCOLORS env variable on macOS HOT 6
- Released a new version? HOT 2
- README doesn't explain how to build the command-line application HOT 3
- option to set "root" path HOT 6
- "-n" input ignore
- color input even if it has spaces at the beginning and end
- Reversed background/foreground for the sticky bit HOT 3
- Option to output colored file name only HOT 7
- Add color codes to parts that are not colored to simplify parsing HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lscolors.