Remember "Choose a language for" choice on `cabal init`
Describe the feature request
When I do a cabal init to create Library and Executable I need to specify multiple times which language version I want.
Additional context
I understand that the executable, library and test are able to choose different language. But from a user perspective I would rather prefer that cabal init remember my very last choice 2 seconds ago.
Currently we have the following interaction where the user needs to specify three times their choice.
Choose a language for your library:
* 1) Haskell2010
2) Haskell98
3) GHC2021 (requires at least GHC 9.2)
4) Other (specify)
Your choice? [default: Haskell2010] 3
...
Choose a language for your executable:
* 1) Haskell2010
2) Haskell98
3) GHC2021 (requires at least GHC 9.2)
4) Other (specify)
Your choice? [default: Haskell2010] 3
...
Choose a language for your test suite:
* 1) Haskell2010
2) Haskell98
3) GHC2021 (requires at least GHC 9.2)
4) Other (specify)
Your choice? [default: Haskell2010] 3
I would rather prefer for cabal init to remember the last choice (or the first choice) in the current cabal init session so I don't need repeat myself.
Choose a language for your library:
* 1) Haskell2010
2) Haskell98
3) GHC2021 (requires at least GHC 9.2)
4) Other (specify)
Your choice? [default: Haskell2010] 3
...
Choose a language for your executable:
1) Haskell2010
2) Haskell98
* 3) GHC2021 (requires at least GHC 9.2)
4) Other (specify)
Your choice? [default: GHC2021]
...
Choose a language for your test suite:
1) Haskell2010
2) Haskell98
* 3) GHC2021 (requires at least GHC 9.2)
4) Other (specify)
Your choice? [default: GHC2021]
I couldn't find any issue suggesting this. I haven't participate much in the ecosystem so far. Let me know if this should be discussed elsewhere first.
Reasonable UX request
This sounds like a great newcomer issue, thank you for submitting it. If you feel like implementing it, we're happy to advise.
Sure! I see that languagePrompt :: Interactive m => InitFlags -> String -> m Language is where things are asked. InitFlags are a subset of the information present in .cabal and Interactive does not seem to hold state from the user input.
I can think of a couple of ideas
- Allow
Interactiveto retrieve and update a specificlastLanguageChoice :: String. LetlanguagePromptread and set that explicitly. - Same but a bit more generic useful for arbitrary questions, so that
Interactivedoes not need to mention something about "language prompt" in it's functions. - Extend promptList to have a "remember" parameter directly that will be used before the default.
I am not sure how Interactive could have some state like IORef since it's essentially IO and not something that carries in-memory context, right? Maybe initializing some kind of IORef in Interactive.Command.createProject and pass it around to implement any of the above alternative is enough.
Does this looks good? What would you suggest?
I have an implementation for this in #10115, we can discuss the implementation over there.