import type { NextPage } from "next"; import React from "react" import { commandCompletion } from "../lib/commands" import styles from "../styles/REPLInput.module.css" const REPLInput: NextPage = () => { const typed = React.createRef(); const completion = React.createRef(); const [currentCmd, setCurrentCmd] = React.useState(""); const replinOnChange = (e: React.FormEvent) => { const currentInput = (e.target as HTMLInputElement).value; const suggest = commandCompletion(currentInput); setCurrentCmd(suggest); if (typed.current) typed.current.innerHTML = currentInput; if (completion.current) completion.current.innerHTML = suggest.substring(currentInput.length); } const tabComplete = (e: React.KeyboardEvent) => { if (e.key === "Tab" && currentCmd !== "") { e.preventDefault(); (e.target as HTMLInputElement).value = currentCmd; if(typed.current) typed.current.innerHTML = currentCmd; if(completion.current) completion.current.innerHTML = ""; } return false; } return
} export default REPLInput;