@velvetbaldmime was working on something similar: GitHub - neandertech/cue4s: Experimental library for CLI prompts in Scala 3, available on JS, JVM, and Native platforms
Funny that cue4s came up twice in independent conversations in the last 7 days cc @lbialy
The very simple task of making even a prompts clone in Scala for all 3 platforms has proven to be more difficult than I anticipated â but mostly due to my lack of experience with TUIs and how they work under the hood. I would love to help train more contributors to share the burden.
On the subject of this conversation: I agree with some of the posters that println
has a much wider applicability than readLine
, the latter being only near and dear to the hearts of classically trained computer science students, such as myself
For people building actual apps, the console interactions of today are much more complex (see GitHub - charmbracelet/bubbletea: A powerful little TUI framework đ for inspiration), and having readLine available without import would not move the needle in the slightest.
People seemed to be open to the idea to make âtoolkitsâ more powerful.
I think this is actually not so difficult. The compiler has switches for almost everything discussed so far (besides the âsetup scriptsâ). You can add global imports, or switch Predef.
So if âtoolkitsâ could define compiler (or scala-cli) parameters I guess one could easily create customized environments just by using
a âtoolkitâ.
The compiler call and all its details (Predef, -Yimports
, compiler flags) would be hidden this way, which is quite beginner friendly.
I also donât recall the last time I used readLine
in Scala.
However, I think there might be a bit of a chicken and egg problem:
I feel like I would use readLn
more often in my scripts (e.g. if an argument is missing), but I donât because itâs cumbersome.
Which in turn might be the reason why most tooling/libraries have a nice support for arguments, but thereâs not much options for interactive TUIs.
At least I think I would use cue4s in my scripts, if it wasnât for the âLibrary is experimental and is only available in Sonatype Snapshotsâ part
Iâm a Scala beginner who have Java experiences. I haven never called readLine function before.
Here are two toolkits help me to learn Scala with ease:
- Scala worksheet: Itâs something like Jupyter notebook but much easier to use for beginners. And scastie is an online version of it. I can just install vscodeâs extension and create a file named
demo.worksheet.sc
and start learning. IMO, for a beginner, Put literal values on the worksheet and see the results on demand is easier than using readLine (which may require type conversions) - Scala-CLI: It makes adding dependencies easier for single file. The
using directives
also support worksheet, and I can explore libraries on-demand by combining Scala-CLI and worksheet.
Hope my experience can be helpful for this discussion.