cabal icon indicating copy to clipboard operation
cabal copied to clipboard

Remember "Choose a language for" choice on `cabal init`

Open bcardiff opened this issue 1 year ago • 4 comments

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.

bcardiff avatar Jun 10 '24 13:06 bcardiff

Reasonable UX request

ffaf1 avatar Jun 10 '24 14:06 ffaf1

This sounds like a great newcomer issue, thank you for submitting it. If you feel like implementing it, we're happy to advise.

ulysses4ever avatar Jun 11 '24 01:06 ulysses4ever

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

  1. Allow Interactive to retrieve and update a specific lastLanguageChoice :: String. Let languagePrompt read and set that explicitly.
  2. Same but a bit more generic useful for arbitrary questions, so that Interactive does not need to mention something about "language prompt" in it's functions.
  3. 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?

bcardiff avatar Jun 12 '24 01:06 bcardiff

I have an implementation for this in #10115, we can discuss the implementation over there.

bcardiff avatar Jun 14 '24 14:06 bcardiff