summaryrefslogtreecommitdiff
path: root/src/jsMain/kotlin/moe/nea89/website/KConsole.kt
diff options
context:
space:
mode:
authorecho <91651232+exhq@users.noreply.github.com>2022-10-11 18:49:49 +0330
committerecho <91651232+exhq@users.noreply.github.com>2022-10-11 18:49:49 +0330
commit3bb7bb0fe2d728dd862a21b3dbb916e19951dbc8 (patch)
treebbb465d24d40588aa6ba2916c9adf9b923e519f4 /src/jsMain/kotlin/moe/nea89/website/KConsole.kt
parent8969ceea52d3d97a5fc3c2c747d8235c8af0f85e (diff)
downloadneamoe-3bb7bb0fe2d728dd862a21b3dbb916e19951dbc8.tar.gz
neamoe-3bb7bb0fe2d728dd862a21b3dbb916e19951dbc8.tar.bz2
neamoe-3bb7bb0fe2d728dd862a21b3dbb916e19951dbc8.zip
added up and down arrow functionality - my head hurts
Diffstat (limited to 'src/jsMain/kotlin/moe/nea89/website/KConsole.kt')
-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
+ }
+ }
}