diff options
Diffstat (limited to 'src/main/kotlin/moe/nea89/website/index.kt')
-rw-r--r-- | src/main/kotlin/moe/nea89/website/index.kt | 101 |
1 files changed, 95 insertions, 6 deletions
diff --git a/src/main/kotlin/moe/nea89/website/index.kt b/src/main/kotlin/moe/nea89/website/index.kt index 8496b3a..b122cec 100644 --- a/src/main/kotlin/moe/nea89/website/index.kt +++ b/src/main/kotlin/moe/nea89/website/index.kt @@ -10,13 +10,102 @@ fun main() { require("@fontsource/comic-mono/index.css") injectGlobal(Styles.global) val root = document.body!!.append.div() - val console = KConsole.createFor(root) - console.registerCommand(object : Command { - override val name: String = "dick" - override val aliases: Set<String> = setOf("cock") - override fun run(console: KConsole, name: String, args: List<String>) { - console.addMultilineText("Hehe") + val console = KConsole.createFor(root, fileSystem = fileSystem { + "etc" { + "passwd" text "hunter2" + } + "home/nea" { + "todo" text """ + | - git gud + | - finish this website + | - convince the general public that comic sans is a viable font + """.trimMargin() + } + "flag" text "CTF{12345abcdefghijklmonp3.1.4.1.5.9.2.8}" + }) + console.registerCommand(command("cwd", "pwd") { + val fa = console.fileAccessor + if (fa == null) { + console.addLine("There is no file accessor present :(") + return@command + } + console.addLine(fa.currentDir.joinToString(separator = "/", prefix = "/")) + }) + console.registerCommand(command("cd") { + val fa = console.fileAccessor + if (fa == null) { + console.addLine("There is no file accessor present :(") + return@command + } + val path = args.singleOrNull() + if (path == null) { + console.addLine("Usage: cd <directory>") + return@command + } + val error = fa.cd(path) + if (error != null) { + console.addLine("cd: ${error.name}") + } + }) + console.registerCommand(command("ls") { + val fa = console.fileAccessor + if (fa == null) { + console.addLine("There is no file accessor present :(") + return@command + } + val path = when (args.size) { + 0 -> "." + 1 -> args[0] + else -> { + console.addLine("Usage: ls [directory or file]") + return@command + } + } + val file = fa.resolve(path) + if (file == null) { + console.addLine("ls: Could not find file or directory") + return@command + } + when (file) { + is KFile.Directory -> { + val longestName = file.files.keys.maxOf { it.length } + file.files.forEach { (name, file) -> + console.addLine( + name + " ".repeat(longestName + 1 - name.length) + file.fileType + ) + } + } + else -> "is a ${file.fileType}" + } + }) + console.registerCommand(command("cat") { + val fa = console.fileAccessor + if (fa == null) { + console.addLine("There is no file accessor present :(") + return@command + } + val path = when (args.size) { + 0 -> "." + 1 -> args[0] + else -> { + console.addLine("Usage: cat [directory or file]") + return@command + } + } + val file = fa.resolve(path) + if (file == null) { + console.addLine("cat: Could not find file or directory") + return@command } + 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}") + } + }) + console.registerCommand(command("dick", "cock") { + console.addMultilineText("Hehe") }) console.registerCommand(object : Command { override val name: String = "booob" |