Comments (3)
@initial-mockingbird Thanks for putting so much time into the design specification! I'll need some time to think if it's possible to come up with a simpler design
Another few points that need refinement:
- How do you decide which value to put in
[]
in the prompt here?If it's the default value, it doesn't have a function to print it to string. Also, not only it can be different from the value returned by the parsing function, it might be different from the first element in theAre you sure? [y]/n
NonEmpty
list entirely! - Sometimes it's desirable to avoid the default value entirely and force users to select an option specifically.
Also, this can be done separately but I needed in the past the ability to specify several values by the multiple-choice option. Would be nice if this can be easily supported by a single representation but I also see the value in keeping the interface simple for users.
from iris.
@chshersh Thank you for taking the time to review everything so thoughtfully!
- How do you decide which value to put in
[]
in the prompt here?Are you sure? [y]/n
The value between the []
would be the displayName
from the head of the Non-Empty list (that is, the default value will always be the head of the list).
- Sometimes it's desirable to avoid the default value entirely and force users to select an option specifically.
You are right! maybe a quick fix would be to turn the default :: a
(which represents the default value that should be returned in case an empty/whitespaced string is input) field into a default :: Maybe a
.
Also, this can be done separately but I needed in the past the ability to specify several values by the multiple-choice option.
Would be nice if this can be easily supported by a single representation but I also see the value in keeping the interface simple for users
Sadly, I don't really see how to incorporate this into the current proposal :( (how would the user input multiple choices?). Nevertheless, maybe a better design than the one I proposed would fall along the lines of the GHCUP TUI menu? i.e:
┌──────────────────────────────────────────────────────────────────────────────┐
│ Multiple Choice Questions? │
│ > [✔️] yay │
│ > [❌] Not this one! │
│ > [✔️] This too! │
└──────────────────────────────────────────────────────────────────────────────┘
┌──────────────────────────────────────────────────────────────────────────────┐
│ Single Choice Question with default? │
│ > [✔️] yay │
│ > [❌] No Sir! │
│ > [❌] Only one check can be marked at a time │
└──────────────────────────────────────────────────────────────────────────────┘
┌──────────────────────────────────────────────────────────────────────────────┐
│ Single Choice Question with no default? │
│ > [❌] Initially all disabled │
│ > [❌] No Sir! │
│ > [❌] Only one check can be marked at a time │
└──────────────────────────────────────────────────────────────────────────────┘
This means that:
- We don't need to ask for parsing functions
- We no longer need the
default
field. - The
multipleChoiceQuestion
function always succeeds (no need to return a maybe).
Thus, the design would end up being:
-- tag in case one wants to receive multiple answes
data Mode = SingleAnswer | MultipleAnswer
data MultipleChoiceOption a = MultipleChoiceOption
{ displayName :: ByteString
, initiallyActive :: Bool -- which options should be active by default?
, value :: a -- no more parsing!
}
data MultipleChoicePrompt a = MultipleChoicePrompt
{ promptMessage :: ByteString
, promptOptions :: NonEmpty (MultipleChoiceOption a)
, mode :: Mode
}
multipleChoiceQuestion
:: MonadIO m
=> MultipleChoicePrompt a
-> m (NonEmpty a)
And then we can expose things like Yes/No questions, as partial application of multipleChoice
:
As a final note, I think this would benefit from the ncurses library.
Caveats:
- The
initiallyActive
may conflict with theMode
(manyinitiallyActive
s against aSingleAnswer
), in those cases, the single default value can be the first one on the list. - I'm not really sure how portable
ncurses
is (does it work on every terminal? what about windows terminal?). - Maybe
multipleChoiceQuestion
should also get an additional argument for aesthetic options? (Should the question be boxed? should the options have the check and cross or other characters?)
from iris.
Iris focuses only on CLI, not TUI. So TUI-inspired interfaces are out of scope for this project. And we won't benefit from ncurses
either.
And then we can expose things like Yes/No questions, as partial application of multipleChoice:
I would be pretty happy to have a separate data Answer = No | Yes
type and specialised functions for yes-no prompts. No need to scaffold a bigger machinery for a simple case
As for the design of this feature, I'm still not satisfied. But I need to think about the better design
from iris.
Related Issues (20)
- [RFC] Support interactive output (progress bars, spinners, etc.)
- Implement 'out', 'outLn', 'err' and 'errLn' functions for outputting 'Text' to corresponding handlers HOT 7
- Split 'Test.Iris.Cli' into multiple modules
- Add 'Emoji' type
- [RFC] The 'Output' abstraction HOT 1
- Support GHC 9.6 HOT 5
- Create release checklist
- Rethink 'CliEnvSettings' and 'defaultCliEnvSettings' HOT 3
- Configure pre-commit hooks HOT 8
- Create Pull Request template HOT 1
- Implement colouring capabilities HOT 1
- Fix all the pre-commit hooks problems HOT 1
- Run pre-commit-hooks on CI HOT 6
- Support GHC 9.4 HOT 2
- Add 'hlint' to pre-commit hooks HOT 1
- Add 'putStdoutColoured' and 'putStderrColoured'
- Changes types in 'Iris.Colour.Formatting' from 'ByteString' to 'Text' HOT 2
- Use Data.Text instead of ByteString in simple-grep example to match the Text usage in Iris.Colour.Formatting HOT 1
- Running tests on local through `stack` fails HOT 8
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 iris.