Skip to content

Feature Request: Interactive Kotlin Playground Option #226

@mirianfonkam

Description

@mirianfonkam

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions