diff options
Diffstat (limited to 'src/main/kotlin/moe/nea89/website/KConsole.kt')
-rw-r--r-- | src/main/kotlin/moe/nea89/website/KConsole.kt | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/main/kotlin/moe/nea89/website/KConsole.kt b/src/main/kotlin/moe/nea89/website/KConsole.kt index b0ae06f..51a6734 100644 --- a/src/main/kotlin/moe/nea89/website/KConsole.kt +++ b/src/main/kotlin/moe/nea89/website/KConsole.kt @@ -3,20 +3,27 @@ package moe.nea89.website import kotlinx.browser.document import kotlinx.html.dom.append import kotlinx.html.js.pre -import org.w3c.dom.* +import org.w3c.dom.HTMLElement +import org.w3c.dom.HTMLPreElement import org.w3c.dom.events.KeyboardEvent import kotlin.collections.set -class KConsole(private val root: HTMLElement, private val text: HTMLPreElement) { +class KConsole( + private val root: HTMLElement, + private val text: HTMLPreElement, + private val fileSystem: KFileSystem?, +) { + + val fileAccessor = fileSystem?.let { FileAccessor(it) } companion object { val shlexRegex = """"([^"\\]+|\\.)+"|([^ "'\\]+|\\.)+|'([^'\\]+|\\.)+'""".toRegex() - fun createFor(element: HTMLElement): KConsole { + fun createFor(element: HTMLElement, fileSystem: KFileSystem? = null): KConsole { val text = element.append.pre() element.classList.add(Styles.consoleClass) - val console = KConsole(element, text) + val console = KConsole(element, text, fileSystem) document.body!!.onkeydown = console::keydown console.addLine("Starting up terminal.") console.rerender() @@ -86,6 +93,7 @@ class KConsole(private val root: HTMLElement, private val text: HTMLPreElement) println("Could not shlex: $command") return null } + // TODO: Proper string unescaping parts.add(match.groupValues.drop(1).firstOrNull { it != "" } ?: "") i += match.value.length while (command[i] == ' ' && i < command.length) |