Giter VIP home page Giter VIP logo

Comments (4)

tpoliaw avatar tpoliaw commented on May 31, 2024

Related to this, is it possible for Styled to represent a string with different styles? eg a string with a single word underlined or the first word in red etc? A workaround for the additional help idea would be to always show it but make it faint to make it distinct from the option itself.

from inquire.

mikaelmello avatar mikaelmello commented on May 31, 2024

I also tried wrapping my T in a new type and adding ansi formatting in its Display impl. This seemed to be cleared somewhere in the rendering.

That was precisely what I was going to suggest :). Can you share a snippet of code with this behavior?

keeping the presentation consistent across multiple prompts.

That's the hard part I guess. The first thing I can think of, for your use-case specifically at first, is calling a formatter function which should return something like Vec<Styled<String>> [1].

Forcing the dev to return a vec of Styled would allow us to still use our solution of shared backends for all platforms, instead of making the dev returning just a simple string with ansi codes scattered around.

[1] would allow you to fix both of your problems I guess. The callback could pass along additional properties of the string to-be-formatted (e.g. the index of the option, whether it is highlighted) and you could return whatever you wanted to be printed.


Sometimes when I'm writing I completely change my mind but I like to keep the original comment so you can see my thought process


I just remembered that the one thing that allowed me to create selection prompts of any type was that I required that they implemented Display. That allowed me to simply use this trait when writing to the terminal. If we were to go with the callback function, that would eliminate the purpose of the Display trait.

With that in mind, we could go with the route of making a new Trait like MultiSelectOption, which the value in the option would have to implement the "callback" function we just mentioned.

The drawback is that we would lose the simplicity of the Display trait solution, I'd like to find a way so that we can keep both of them available for simple uses: e.g. I just want to print without caring too much, just like it is now vs your use-case where you want to customize specific behaviors.

from inquire.

tpoliaw avatar tpoliaw commented on May 31, 2024

That was precisely what I was going to suggest :). Can you share a snippet of code with this behavior?

Trying to reproduce this makes me think it's me not understanding the colored library.
With let text = "foo".red(); write!(f, "{}", &text) writes in colour but f.write_str(&text) doesn't. I thinks it's something to do with how it implements Deref<str>.

This is probably enough for me for now (so feel free to close this) but the option to make the formatting depend on the selected state would still be interesting. If that's something that would fit this library, I don't mind having a dig around and see if I can get a PR together.

from inquire.

tpoliaw avatar tpoliaw commented on May 31, 2024

Testing this again, adding ansi formatting to display impl affects the filtering - eg making text green means that [32m will match all entries. This might be its own issue.

from inquire.

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.