All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dev.forkhandles.bunting.IO.kt Maven / Gradle / Ivy

There is a newer version: 2.20.0.0
Show newest version
package dev.forkhandles.bunting

import dev.forkhandles.bunting.Visibility.Public
import dev.forkhandles.bunting.Visibility.Secret

interface IO {
    fun read(visibility: Visibility): String
    fun write(message: String)
}

object ConsoleIO : IO {
    override fun read(visibility: Visibility): String = when (visibility) {
        Secret -> System.console()?.readPassword()?.let { String(it) } ?: read(Public)
        Public -> readLine() ?: throw IllegalArgumentException("Failed to read input")
    }

    override fun write(message: String) = print(message)
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy