com.simiacryptus.skyenet.AgentPatterns.kt Maven / Gradle / Ivy
package com.simiacryptus.skyenet
import com.simiacryptus.skyenet.webui.application.ApplicationInterface
import java.util.*
object AgentPatterns {
fun displayMapInTabs(
map: Map,
ui: ApplicationInterface? = null,
split: Boolean = map.entries.map { it.value.length + it.key.length }.sum() > 10000
): String = if (split && ui != null) {
val tasks = map.entries.map { (key, value) ->
key to ui.newTask(root = false)
}.toMap()
ui.socketManager?.scheduledThreadPoolExecutor?.schedule({
tasks.forEach { (key, task) ->
task.complete(map[key]!!)
}
}, 200, java.util.concurrent.TimeUnit.MILLISECONDS)
displayMapInTabs(tasks.mapValues { it.value.placeholder }, ui = ui, split = false)
} else {
"""
${
map.keys.joinToString("\n") { key ->
""""""
}
}
${
map.entries.withIndex().joinToString("\n") { (idx, t) ->
val (key, value) = t
"""
""
}
}" data-tab="$key">
${value/*.indent(" ")*/}
"""
}
}
"""
}
}