jupyter.kotlin.ScriptTemplateWithDisplayHelpers.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlin-jupyter-lib Show documentation
Show all versions of kotlin-jupyter-lib Show documentation
Internal part of Kotlin Jupyter API used only inside notebook cells
package jupyter.kotlin
import org.jetbrains.kotlinx.jupyter.api.Notebook
import org.jetbrains.kotlinx.jupyter.api.ResultsAccessor
import org.jetbrains.kotlinx.jupyter.api.libraries.CodeExecution
import org.jetbrains.kotlinx.jupyter.api.libraries.JupyterIntegration
import org.jetbrains.kotlinx.jupyter.api.libraries.LibraryDefinition
abstract class ScriptTemplateWithDisplayHelpers(
val notebook: Notebook,
private val hostProvider: KotlinKernelHostProvider
) {
fun DISPLAY(value: Any) = hostProvider.host!!.display(value)
fun EXECUTE(code: String) = hostProvider.host!!.scheduleExecution(CodeExecution(code).toExecutionCallback())
fun USE(library: LibraryDefinition) = hostProvider.host!!.addLibrary(library)
fun USE(builder: JupyterIntegration.Builder.() -> Unit) {
val o = object : JupyterIntegration() {
override fun Builder.onLoaded() {
builder()
}
}
USE(o.getDefinitions(notebook).single())
}
val Out: ResultsAccessor get() = ResultsAccessor { id ->
notebook.getResult(id)
}
val JavaRuntimeUtils get() = notebook.jreInfo
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy