|
|
|
@ -32,6 +32,11 @@ export default function useTerminal(inputEl: HTMLTextAreaElement, commands: Simp
|
|
|
|
|
inputEl.setSelectionRange(pos, pos)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function cursorTouchesPrompt() {
|
|
|
|
|
const promptEnd = inputEl.value.lastIndexOf(prompt) + prompt.length
|
|
|
|
|
return inputEl.selectionStart === promptEnd
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setFocus() {
|
|
|
|
|
inputEl.focus()
|
|
|
|
|
}
|
|
|
|
@ -189,6 +194,15 @@ export default function useTerminal(inputEl: HTMLTextAreaElement, commands: Simp
|
|
|
|
|
case 'Backspace':
|
|
|
|
|
if (cursorAtPrompt()) ev.preventDefault()
|
|
|
|
|
break
|
|
|
|
|
case 'ArrowUp':
|
|
|
|
|
// TODO: commandHistory(-1)
|
|
|
|
|
ev.preventDefault()
|
|
|
|
|
break
|
|
|
|
|
case 'ArrowLeft':
|
|
|
|
|
if (cursorTouchesPrompt()) ev.preventDefault()
|
|
|
|
|
break
|
|
|
|
|
default:
|
|
|
|
|
console.debug('key pressed:', ev.key, ev.keyCode)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|