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

org.jetbrains.kotlinx.jupyter.util.StdIO.kt Maven / Gradle / Ivy

Go to download

Implementation of REPL compiler and preprocessor for Jupyter dialect of Kotlin (IDE-compatible)

There is a newer version: 0.12.0-333
Show newest version
package org.jetbrains.kotlinx.jupyter.util

import java.io.Closeable
import kotlin.reflect.KMutableProperty0

var systemErrStream
    get() = System.err
    set(value) {
        System.setErr(value)
    }

var systemOutStream
    get() = System.out
    set(value) {
        System.setOut(value)
    }

var systemInStream
    get() = System.`in`
    set(value) {
        System.setIn(value)
    }

fun  withSubstitutedStream(
    standardStreamProp: KMutableProperty0,
    newStreamFactory: (StreamT) -> StreamT,
    body: (StreamT) -> R,
): R {
    val originalStream = standardStreamProp.get()
    val newStream = newStreamFactory(originalStream)
    return try {
        standardStreamProp.set(newStream)
        body(newStream)
    } finally {
        newStream.close()
        standardStreamProp.set(originalStream)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy