diff --git a/components/REPL/REPLInput.tsx b/components/REPL/REPLInput.tsx index 7366081..2f175fb 100644 --- a/components/REPL/REPLInput.tsx +++ b/components/REPL/REPLInput.tsx @@ -38,7 +38,7 @@ const REPLInput: NextPage = ({historyCallback, inputRef}) => { } }; - const tabComplete = (e: React.KeyboardEvent) => { + const keyEvent = (e: React.KeyboardEvent) => { const input = (e.target as HTMLInputElement); if (e.key === "Tab" && currentCmd.length !== 0) { e.preventDefault(); @@ -49,6 +49,7 @@ const REPLInput: NextPage = ({historyCallback, inputRef}) => { } else setJustTabbed(0); if (e.key === "Enter") { + e.preventDefault(); const result = executeCommand((e.target as HTMLInputElement).value); input.value = ""; if(typed.current) typed.current.innerHTML = ""; @@ -56,13 +57,22 @@ const REPLInput: NextPage = ({historyCallback, inputRef}) => { historyCallback(result); } + if (e.key === "d" && e.ctrlKey) { + e.preventDefault(); + const result = executeCommand("exit"); + input.value = ""; + if(typed.current) typed.current.innerHTML = ""; + if(completion.current) completion.current.innerHTML = ""; + historyCallback(result); + } + return false; }; return
- } className={styles.in} type={"text"} onChange={replinOnChange} onKeyDown={tabComplete} spellCheck={"false"} autoFocus maxLength={20} /> + } className={styles.in} type={"text"} onChange={replinOnChange} onKeyDown={keyEvent} spellCheck={"false"} autoFocus maxLength={20} />
; diff --git a/lib/commands/definitions.ts b/lib/commands/definitions.ts index 479689e..3347834 100644 --- a/lib/commands/definitions.ts +++ b/lib/commands/definitions.ts @@ -178,4 +178,21 @@ const project: Command = { } }; -export const commandList = [about, help, man, project]; \ No newline at end of file +const exitCmd: Command = { + name: "exit", + desc: "Tries to close this tab. Mostly fails because of restrictions.", + execute: () => { + if (typeof window !== undefined) { + window.opener = null; + window.open('', '_self'); + window.close(); + } + return [ + "If you can read this, closing the window did not work.", + "This is because of restriction in JavaScript.", + "Read more here: https://developer.mozilla.org/en-US/docs/Web/API/Window/close" + ] + } +} + +export const commandList = [about, help, man, project, exitCmd]; \ No newline at end of file