diff options
author | nea <romangraef@gmail.com> | 2022-08-26 15:12:25 +0200 |
---|---|---|
committer | nea <romangraef@gmail.com> | 2022-08-26 15:12:25 +0200 |
commit | 36374a03516517a89bbb74ce58053ac5ca44f752 (patch) | |
tree | 8d377d65691536cbae43a6ebd629c07146314ee3 /example/src/main/kotlin/moe | |
parent | 176e37844c17eaabb5c9da0f9c23237df9c0b5a8 (diff) | |
download | neamoe-36374a03516517a89bbb74ce58053ac5ca44f752.tar.gz neamoe-36374a03516517a89bbb74ce58053ac5ca44f752.tar.bz2 neamoe-36374a03516517a89bbb74ce58053ac5ca44f752.zip |
default commands
Diffstat (limited to 'example/src/main/kotlin/moe')
-rw-r--r-- | example/src/main/kotlin/moe/nea89/website/test/index.kt | 90 |
1 files changed, 5 insertions, 85 deletions
diff --git a/example/src/main/kotlin/moe/nea89/website/test/index.kt b/example/src/main/kotlin/moe/nea89/website/test/index.kt index c558868..846b0db 100644 --- a/example/src/main/kotlin/moe/nea89/website/test/index.kt +++ b/example/src/main/kotlin/moe/nea89/website/test/index.kt @@ -4,15 +4,9 @@ import kotlinext.js.require import kotlinx.browser.document import kotlinx.css.* 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.onLoadFunction -import kotlinx.html.js.p import moe.nea89.website.* import styled.injectGlobal -import kotlin.time.Duration.Companion.milliseconds val defaultFileSystem = fileSystem { "etc" { @@ -36,6 +30,7 @@ fun main() { val root = document.body!!.append.div() val console = KConsole.createFor(root, fileSystem = defaultFileSystem) console.text.id = "myconsole" + console.fileAccessor!!.cd("home/nea") injectGlobal { body { backgroundColor = Styles.bgColor.lighten(30) @@ -54,88 +49,13 @@ fun main() { console.addLine("Starting up terminal.") console.PS1 = { "${this.fileAccessor?.currentDir?.joinToString("/", "/") ?: ""} >" } console.rerender() - console.registerCommand(command("cwd", "pwd") { - val fa = requireFileAccessor() - console.addLine(fa.currentDir.joinToString(separator = "/", prefix = "/")) - }) - console.registerCommand(command("cd") { - val fa = requireFileAccessor() - 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 = requireFileAccessor() - 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) -> - wait(200.milliseconds) - console.addLine( - name + " ".repeat(longestName + 1 - name.length) + file.fileType - ) - console.rerender() - } - } - - else -> console.addLine("ls: is a ${file.fileType}") - } - }) + console.registerCommand(defaultCwdCommand("cwd", "pwd")) + console.registerCommand(defaultCdCommand("cd")) + console.registerCommand(defaultLsCommand("ls")) 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) { - 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.addLine(document.create.p { - img(src = file.url) { - this.onLoadFunction = { console.scrollDown() } - } - }) - - is KFile.Download -> { - val link = document.create.a(file.url) - link.download = file.name.last() - document.body!!.append(link) - link.click() - link.remove() - console.addLine("Download started") - } - } - }) + console.registerCommand(defaultCatCommand("cat")) console.registerCommand(command("dick", "cock") { console.addMultilineText("Hehe") }) |