kotlin-playground
kotlin-playground copied to clipboard
Feature Request: Interactive Kotlin Playground Option
Feature Request
Currently, the Kotlin Playground does not support standard input directly. Meaning that running the following code will not work:
val number = readln()
println("You entered: $number")
It will throw Exception in thread "main" kotlin.io.ReadAfterEOFException: EOF has already been reached at kotlin.io.ConsoleKt.readln (Console.kt:152).
This feature would be add more interactivity for the playground. This will be specially helpful for beginners. A solution could be to show a pop up dialog for input.
Some workarounds for this issue is to create a custom function with stubbed input, or use
readlnOrNull()(e.g.readlnOrNull() ?: "this is a simulated input", or to put arguments in the argument box, have the signaturefun main(args: Array<String>)and callargs.first(). My favorite workaround is using JS on playground as suggested in this answer: https://stackoverflow.com/a/73898805
Links to similar discussions
- Problem using readLine() in Playground
- /kotlin doesnot support readline()
- Can't get input from user
- https://github.com/JetBrains/kotlin-playground/issues/214
- Kotlin readLine gives error in a basic program where input is taken from user and the same is shown as output
- Can't read from System.in in Kotlin Playground
- Kotlin Playground: Add support for program input