Comments (4)
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.
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.
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.
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)
- Add code coverage metrics to get a better idea of test coverage
- inquire derive and attribute macro HOT 3
- Show proper error message for CustomType prompt HOT 1
- Alt+{left, right, backspace} support HOT 3
- DateSelect default help message incorrect ? HOT 2
- Support for up-arrow previous prompt history, and control-keys HOT 2
- Inquire leaves the terminal in a broken state HOT 3
- Render issue using the `console` backend HOT 2
- Inquire forgets to add newlines in 0.7.1 HOT 5
- "external_print" Functionality
- Make Scrolling More Obvious (Customizable maybe?) HOT 1
- MultiSelect list doesn't show after filter is cleared on selection HOT 1
- Suppressing static lifetimes from Text (and other modules ?) HOT 1
- typo in README for termion link
- Password prompt with redirected `stdout`
- inquire now strips ANSI escape codes making colorised text inside prompts impossible HOT 1
- Single state prompt HOT 1
- Feature: Different colors for select options
- Feature Request: improvement about `prompts::DateSelect` for user friendly purpose
- Upgrade crossterm to 0.27.0
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 inquire.