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

jupyter.kotlin.VariablesReport.kt Maven / Gradle / Ivy

package jupyter.kotlin

import org.jetbrains.kotlinx.jupyter.api.MimeTypedResult
import org.jetbrains.kotlinx.jupyter.api.Notebook
import org.jetbrains.kotlinx.jupyter.api.VariableState
import org.jetbrains.kotlinx.jupyter.api.htmlResult

const val VARIABLES_TABLE_STYLE_CLASS = "variables_table"

val Notebook.variablesReportAsHTML: MimeTypedResult get() {
    return htmlResult(generateHTMLVarsReport(variablesState))
}

val Notebook.variablesReport: String get() {
    return if (variablesState.isEmpty()) {
        ""
    } else {
        buildString {
            append("Visible vars: \n")
            variablesState.forEach { (name, currentState) ->
                append("\t$name : ${currentState.stringValue}\n")
            }
        }
    }
}

fun generateHTMLVarsReport(variablesState: Map): String {
    return buildString {
        append(generateStyleSection())
        if (variablesState.isEmpty()) {
            append("

Variables State's Empty

\n") return toString() } append("

Variables State

\n") append(generateVarsTable(variablesState)) } } private fun generateStyleSection( borderPx: Int = 1, paddingPx: Int = 5, ): String { //language=HTML return """ """.trimIndent() } private fun generateVarsTable(variablesState: Map): String { return buildString { append( """ """.trimIndent(), ) variablesState.entries.forEach { append( """ """.trimIndent(), ) } append("\n
Variable Value
${it.key}
${it.value.stringValue}
\n") } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy