summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/kotlin/moe/nea89/website/Colored.kt21
-rw-r--r--src/main/kotlin/moe/nea89/website/KConsole.kt21
-rw-r--r--src/main/kotlin/moe/nea89/website/index.kt4
3 files changed, 41 insertions, 5 deletions
diff --git a/src/main/kotlin/moe/nea89/website/Colored.kt b/src/main/kotlin/moe/nea89/website/Colored.kt
new file mode 100644
index 0000000..1bb8668
--- /dev/null
+++ b/src/main/kotlin/moe/nea89/website/Colored.kt
@@ -0,0 +1,21 @@
+package moe.nea89.website
+
+import kotlinx.css.*
+
+enum class CustomColor(val color: Color) {
+ RED(Color("#ff0022")),
+ BLUE(Color("#3344ff")),
+ PURPLE(Color("#DA2EC2")),
+ GREEN(Color("#68DA2E"))
+}
+
+data class ColoredElement(
+ val color: CustomColor,
+ val text: String
+)
+
+fun red(text: String) = ColoredElement(CustomColor.RED, text)
+fun blue(text: String) = ColoredElement(CustomColor.BLUE, text)
+fun purple(text: String) = ColoredElement(CustomColor.PURPLE, text)
+fun green(text: String) = ColoredElement(CustomColor.GREEN, text)
+
diff --git a/src/main/kotlin/moe/nea89/website/KConsole.kt b/src/main/kotlin/moe/nea89/website/KConsole.kt
index 95b0e42..4814bf5 100644
--- a/src/main/kotlin/moe/nea89/website/KConsole.kt
+++ b/src/main/kotlin/moe/nea89/website/KConsole.kt
@@ -5,6 +5,7 @@ import kotlinx.html.dom.append
import kotlinx.html.dom.create
import kotlinx.html.js.p
import kotlinx.html.js.pre
+import kotlinx.html.js.span
import org.w3c.dom.HTMLElement
import org.w3c.dom.HTMLParagraphElement
import org.w3c.dom.HTMLPreElement
@@ -46,20 +47,30 @@ class KConsole(
var input: String = ""
fun addLines(newLines: List<String>) {
- newLines.forEach(this::addLine)
+ newLines.forEach { addLine(it) }
}
fun addMultilineText(text: String) {
addLines(text.split("\n"))
}
- fun addLine(line: String) {
- addLine(document.create.p {
- text(line)
+ fun addLine(vararg elements: Any) {
+ addLine(document.create.p().apply {
+ elements.forEach {
+ when (it) {
+ is HTMLElement -> append(it)
+ is ColoredElement -> append(document.create.span().also { el ->
+ el.style.color = it.color.color.toString()
+ el.append(it.text)
+ })
+ is String -> append(it)
+ else -> throw RuntimeException("Unknown element")
+ }
+ }
})
}
- fun addLine(element: HTMLParagraphElement) {
+ private fun addLine(element: HTMLParagraphElement) {
text.insertBefore(element, prompt)
}
diff --git a/src/main/kotlin/moe/nea89/website/index.kt b/src/main/kotlin/moe/nea89/website/index.kt
index 4eea755..d347364 100644
--- a/src/main/kotlin/moe/nea89/website/index.kt
+++ b/src/main/kotlin/moe/nea89/website/index.kt
@@ -77,6 +77,9 @@ fun main() {
else -> "is a ${file.fileType}"
}
})
+ console.registerCommand(command("color") {
+ console.addLine("This is a ", red("red"), " word: ", green("1.0"), " ", blue("BLUUEEE"))
+ })
console.registerCommand(command("cat") {
val fa = requireFileAccessor()
val path = when (args.size) {
@@ -103,6 +106,7 @@ fun main() {
document.body!!.append(link)
link.click()
link.remove()
+ console.addLine("Download started")
}
}
})