kotlin-playground icon indicating copy to clipboard operation
kotlin-playground copied to clipboard

Feature Request: Interactive Kotlin Playground Option

Open mirianfonkam opened this issue 9 months ago • 0 comments

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 signature fun main(args: Array<String>) and call args.first(). My favorite workaround is using JS on playground as suggested in this answer: https://stackoverflow.com/a/73898805

Links to similar discussions

mirianfonkam avatar Jan 08 '25 18:01 mirianfonkam