This commit is contained in:
Chris Wanstrath 2025-09-20 11:39:20 -07:00
parent a4b08dd811
commit 03caf64231
2 changed files with 11 additions and 3 deletions

View File

@ -1,8 +1,9 @@
////
// this file controls the command textbox
// input is handled by a <textarea> and friends
//
import { cmdTextbox, cmdLine } from "./dom.js"
import { runCommand } from "./shell.js"
export function initInput() {
cmdTextbox.addEventListener("keydown", inputHandler)
@ -12,17 +13,17 @@ function inputHandler(event: KeyboardEvent) {
const target = event.target as HTMLElement
if (target?.id !== cmdTextbox.id) return
console.log(event.key)
if (event.key === "Tab") {
event.preventDefault()
} else if (event.shiftKey && event.key === "Enter") {
cmdTextbox.rows += 1
cmdLine.dataset.extended = "true"
console.log(cmdTextbox.value)
} else if (event.key === "Enter") {
cmdTextbox.value = ""
cmdTextbox.rows = 1
cmdLine.dataset.extended = "false"
event.preventDefault()
runCommand(cmdTextbox.value)
}
}

7
src/js/shell.ts Normal file
View File

@ -0,0 +1,7 @@
////
// the shell runs on the server and processes input, returning output
//
export function runCommand(input: string) {
}