2021-12-26 16:51:35 +01:00
|
|
|
import { MutableRefObject, useRef, useState } from "react";
|
2021-12-15 18:56:32 +01:00
|
|
|
import REPLInput from "./REPLInput";
|
2021-12-16 00:21:14 +01:00
|
|
|
import REPLHistory from "./REPLHistory";
|
2021-12-26 15:16:09 +01:00
|
|
|
import styles from "../../styles/REPL/REPLComplete.module.css";
|
2021-12-26 16:51:35 +01:00
|
|
|
import type { NextPage } from "next";
|
2021-12-15 18:56:32 +01:00
|
|
|
|
2022-01-14 14:27:19 +01:00
|
|
|
interface IREPLProps {
|
|
|
|
inputRef: MutableRefObject<HTMLInputElement|undefined>;
|
|
|
|
modalManipulation: {
|
|
|
|
setModalVisible: CallableFunction;
|
|
|
|
setModalProject: CallableFunction;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const REPL: NextPage<IREPLProps> = ({ inputRef, modalManipulation }) => {
|
2021-12-16 00:21:14 +01:00
|
|
|
const [history, manipulateHistory] = useState<string[]>([]);
|
|
|
|
const onCommandExecuted = (result: string[]) => manipulateHistory(result.reverse().concat(history).slice(0, 1000));
|
2021-12-26 14:17:11 +01:00
|
|
|
const onClearHistory = () => manipulateHistory([]);
|
2021-12-16 00:21:14 +01:00
|
|
|
|
2021-12-26 13:59:22 +01:00
|
|
|
const focusInput = () => {
|
|
|
|
if (inputRef.current) inputRef.current.focus();
|
2022-01-05 17:52:20 +01:00
|
|
|
};
|
2021-12-26 13:59:22 +01:00
|
|
|
|
2021-12-26 15:16:09 +01:00
|
|
|
return (<div className={styles.container}>
|
2021-12-16 01:15:43 +01:00
|
|
|
<REPLHistory history={history} inputRef={inputRef} />
|
2022-01-14 14:27:19 +01:00
|
|
|
<REPLInput historyCallback={onCommandExecuted} historyClear={onClearHistory} inputRef={inputRef} modalManipulation={modalManipulation} />
|
2021-12-26 13:59:22 +01:00
|
|
|
<div style={{flexGrow: 2}} onClick={focusInput}></div>
|
2021-12-26 15:16:09 +01:00
|
|
|
</div>);
|
2021-12-15 18:56:32 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
export default REPL;
|