summaryrefslogtreecommitdiff
path: root/src/jsMain/kotlin
diff options
context:
space:
mode:
Diffstat (limited to 'src/jsMain/kotlin')
-rw-r--r--src/jsMain/kotlin/moe/nea89/website/KConsole.kt36
1 files changed, 33 insertions, 3 deletions
diff --git a/src/jsMain/kotlin/moe/nea89/website/KConsole.kt b/src/jsMain/kotlin/moe/nea89/website/KConsole.kt
index a7b1102..c5850fc 100644
--- a/src/jsMain/kotlin/moe/nea89/website/KConsole.kt
+++ b/src/jsMain/kotlin/moe/nea89/website/KConsole.kt
@@ -31,6 +31,9 @@ class KConsole(
private lateinit var uninjectKeyHandler: () -> Unit
val fileAccessor = fileSystem?.let { FileAccessor(it) }
+ var wholecommand = ""
+ var currenthistory = 0
+ var commandHistory : Array<String> = emptyArray()
var PS1: KConsole.() -> String = { "$" }
private lateinit var mobileInput: HTMLInputElement
@@ -142,7 +145,14 @@ class KConsole(
return
}
val command = parts[0]
- println("Running command: $command")
+ wholecommand = ""
+ println("whole command:")
+ for (element in parts){
+ wholecommand += element + " "
+ }
+ println(wholecommand)
+ commandHistory += wholecommand
+
val arguments = parts.drop(1)
val commandThing = commands[command]
if (commandThing == null) {
@@ -172,6 +182,7 @@ class KConsole(
}
fun handleSubmit() {
+ currenthistory = 0
val toExecute = input
addLine("${PS1.invoke(this)} $toExecute")
input = ""
@@ -184,6 +195,9 @@ class KConsole(
handleControlDown(event)
return
}
+ if (event.keyCode == 38 || event.keyCode == 40) {
+ handleArrowKeys(event)
+ }
if (event.isComposing) return
if (state != ConsoleState.SHELLPROMPT) return
if (justHandledInput) {
@@ -213,8 +227,8 @@ class KConsole(
rerender()
scrollDown()
}
-
-
+
+
fun handleControlDown(event: KeyboardEvent){
if (event.key == "v"){
event.preventDefault()
@@ -225,4 +239,20 @@ class KConsole(
}
}
}
+ fun handleArrowKeys(event: KeyboardEvent){
+ if (event.keyCode == 40) {
+ if (commandHistory.isEmpty() || currenthistory > commandHistory.size || currenthistory == 0){
+ return
+ }
+ input = commandHistory[commandHistory.size-currenthistory]
+ currenthistory -= 1
+ }
+ if (event.keyCode == 38) {
+ if (commandHistory.isEmpty() || currenthistory == commandHistory.size){
+ return
+ }
+ input = commandHistory[commandHistory.size-1-currenthistory]
+ currenthistory += 1
+ }
+ }
}