Code Monkey home page Code Monkey logo

Comments (5)

sharkdp avatar sharkdp commented on June 13, 2024 1

@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.

sharkdp avatar sharkdp commented on June 13, 2024

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.

Peltoche avatar Peltoche commented on June 13, 2024

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.

sharkdp avatar sharkdp commented on June 13, 2024

I'm going to close this (for now) as this seems to be resolved to me.

from lscolors.

Peltoche avatar Peltoche commented on June 13, 2024

It seems all good! Thanks!

from lscolors.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.