diff options
author | nea <romangraef@loves.dicksinhisan.us> | 2021-12-10 03:22:34 +0100 |
---|---|---|
committer | nea <romangraef@loves.dicksinhisan.us> | 2021-12-10 03:22:34 +0100 |
commit | 633f68d0c9a0f9a120f14da7e8ccea6102965c41 (patch) | |
tree | f8f4a5c7638c43e9b3948ce77ee12f317e559b05 /src/main | |
parent | ddf592aa0c1f48a09599e6982cb2e20dd4b56545 (diff) | |
download | neamoe-633f68d0c9a0f9a120f14da7e8ccea6102965c41.tar.gz neamoe-633f68d0c9a0f9a120f14da7e8ccea6102965c41.tar.bz2 neamoe-633f68d0c9a0f9a120f14da7e8ccea6102965c41.zip |
downloads and images
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/kotlin/moe/nea89/website/KConsole.kt | 39 | ||||
-rw-r--r-- | src/main/kotlin/moe/nea89/website/ShellExecutionContext.kt | 18 | ||||
-rw-r--r-- | src/main/kotlin/moe/nea89/website/index.kt | 18 | ||||
-rw-r--r-- | src/main/resources/images/me.jpeg | bin | 0 -> 567270 bytes | |||
-rw-r--r-- | src/main/resources/images/moisturized.jpg | bin | 0 -> 41960 bytes |
5 files changed, 52 insertions, 23 deletions
diff --git a/src/main/kotlin/moe/nea89/website/KConsole.kt b/src/main/kotlin/moe/nea89/website/KConsole.kt index 6c4f707..95b0e42 100644 --- a/src/main/kotlin/moe/nea89/website/KConsole.kt +++ b/src/main/kotlin/moe/nea89/website/KConsole.kt @@ -2,8 +2,11 @@ package moe.nea89.website import kotlinx.browser.document import kotlinx.html.dom.append +import kotlinx.html.dom.create +import kotlinx.html.js.p import kotlinx.html.js.pre import org.w3c.dom.HTMLElement +import org.w3c.dom.HTMLParagraphElement import org.w3c.dom.HTMLPreElement import org.w3c.dom.events.KeyboardEvent import kotlin.collections.set @@ -11,7 +14,8 @@ import kotlin.collections.set class KConsole( private val root: HTMLElement, private val text: HTMLPreElement, - private val fileSystem: KFileSystem?, + private val prompt: HTMLElement, + fileSystem: KFileSystem?, ) { val fileAccessor = fileSystem?.let { FileAccessor(it) } @@ -22,8 +26,9 @@ class KConsole( fun createFor(element: HTMLElement, fileSystem: KFileSystem? = null): KConsole { val text = element.append.pre() + val prompt = text.append.p() element.classList.add(Styles.consoleClass) - val console = KConsole(element, text, fileSystem) + val console = KConsole(element, text, prompt, fileSystem) document.body!!.onkeydown = console::keydown console.addLine("Starting up terminal.") console.rerender() @@ -38,12 +43,10 @@ class KConsole( var state = ConsoleState.SHELLPROMPT - val lines = mutableListOf<String>() - var input: String = "" fun addLines(newLines: List<String>) { - lines.addAll(newLines) + newLines.forEach(this::addLine) } fun addMultilineText(text: String) { @@ -51,19 +54,25 @@ class KConsole( } fun addLine(line: String) { - lines.add(line) + addLine(document.create.p { + text(line) + }) } - fun scrollDown() { - text.lastElementChild?.scrollIntoView() + fun addLine(element: HTMLParagraphElement) { + text.insertBefore(element, prompt) } fun rerender() { - var view = lines.joinToString(separator = "\n") - if (state == ConsoleState.SHELLPROMPT) { - view += "\n${'$'} $input" + if (state == KConsole.ConsoleState.SHELLPROMPT) { + prompt.innerText = "${'$'} $input" + } else { + prompt.innerText = "" } - text.innerText = view + } + + fun scrollDown() { + text.lastElementChild?.scrollIntoView() } fun registerCommand(command: Command) { @@ -77,10 +86,13 @@ class KConsole( fun executeCommand(commandLine: String) { val parts = shlex(commandLine) - if (parts.isNullOrEmpty()) { + if (parts == null) { addLine("Syntax Error") return } + if (parts.isEmpty()) { + return + } val command = parts[0] println("Running command: $command") val arguments = parts.drop(1) @@ -127,6 +139,7 @@ class KConsole( if (event.key.length == 1 || event.key.any { it !in 'a'..'z' && it !in 'A'..'Z' }) input += event.key } + event.preventDefault() rerender() scrollDown() } diff --git a/src/main/kotlin/moe/nea89/website/ShellExecutionContext.kt b/src/main/kotlin/moe/nea89/website/ShellExecutionContext.kt index cec0b9e..bd72421 100644 --- a/src/main/kotlin/moe/nea89/website/ShellExecutionContext.kt +++ b/src/main/kotlin/moe/nea89/website/ShellExecutionContext.kt @@ -35,15 +35,17 @@ class ShellExecutionContext( ) { console.state = KConsole.ConsoleState.IN_PROGRAM val se = ShellExecutionContext(console, name, args) - command.runner.createCoroutine(se, object : Continuation<Unit> { - override val context: CoroutineContext - get() = EmptyCoroutineContext + window.requestAnimationFrame { + command.runner.createCoroutine(se, object : Continuation<Unit> { + override val context: CoroutineContext + get() = EmptyCoroutineContext - override fun resumeWith(result: Result<Unit>) { - console.state = KConsole.ConsoleState.SHELLPROMPT - console.rerender() - } - }).resume(Unit) + override fun resumeWith(result: Result<Unit>) { + console.state = KConsole.ConsoleState.SHELLPROMPT + console.rerender() + } + }).resume(Unit) + } } } } diff --git a/src/main/kotlin/moe/nea89/website/index.kt b/src/main/kotlin/moe/nea89/website/index.kt index 4a69a14..4eea755 100644 --- a/src/main/kotlin/moe/nea89/website/index.kt +++ b/src/main/kotlin/moe/nea89/website/index.kt @@ -3,7 +3,11 @@ package moe.nea89.website import kotlinext.js.require import kotlinx.browser.document import kotlinx.html.dom.append +import kotlinx.html.dom.create +import kotlinx.html.img +import kotlinx.html.js.a import kotlinx.html.js.div +import kotlinx.html.js.p import styled.injectGlobal import kotlin.time.Duration.Companion.milliseconds @@ -17,6 +21,8 @@ val defaultFileSystem = fileSystem { | - finish this website | - convince the general public that comic sans is a viable font """.trimMargin() + "moisturized" image require("images/moisturized.jpg") + "download" download require("images/me.jpeg") } "flag" text "CTF{12345abcdefghijklmonp3.1.4.1.5.9.2.8}" } @@ -88,8 +94,16 @@ fun main() { when (file) { is KFile.Directory -> console.addLine("cat: Is a directory") is KFile.Text -> console.addMultilineText(file.text) - is KFile.Image -> console.addMultilineText("Imagine here was an image: ${file.url}") - is KFile.Download -> console.addMultilineText("Imageine here was a download: ${file.url}") + is KFile.Image -> console.addLine(document.create.p { + img(src = file.url) + }) + is KFile.Download -> { + val link = document.create.a(file.url) + link.download = file.name.last() + document.body!!.append(link) + link.click() + link.remove() + } } }) console.registerCommand(command("dick", "cock") { diff --git a/src/main/resources/images/me.jpeg b/src/main/resources/images/me.jpeg Binary files differnew file mode 100644 index 0000000..1d829fa --- /dev/null +++ b/src/main/resources/images/me.jpeg diff --git a/src/main/resources/images/moisturized.jpg b/src/main/resources/images/moisturized.jpg Binary files differnew file mode 100644 index 0000000..89767ea --- /dev/null +++ b/src/main/resources/images/moisturized.jpg |