-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix log4j, add repl for RCON, update config
- Loading branch information
Showing
9 changed files
with
203 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import React, { useState, useEffect, useRef } from "react"; | ||
|
||
import "../app.global.css"; | ||
|
||
interface ReplCommandData { | ||
command: string; | ||
data: string; | ||
} | ||
|
||
interface ReplProps { | ||
exec(command: string): Promise<string>; | ||
} | ||
|
||
const Repl = ({ exec }: ReplProps): JSX.Element => { | ||
const [history, setHistory] = useState<ReplCommandData[]>([]); | ||
const [commands, setCommands] = useState<ReplCommandData[]>([]); | ||
const [command, setCommand] = useState(""); | ||
const [isExec, setIsExec] = useState(false); | ||
const [placeholder, setPlaceholder] = useState(""); | ||
const [index, setIndex] = useState(0); | ||
|
||
const log = useRef<HTMLDivElement>(null); | ||
const term = useRef<HTMLPreElement>(null); | ||
|
||
useEffect(() => { | ||
setCommands(history.filter(({ command }) => command)); | ||
|
||
if (term.current) term.current.scrollTop = term.current?.scrollHeight; | ||
}, [history]); | ||
|
||
useEffect(() => { | ||
if (index && commands[index - 1]) | ||
setCommand(commands[index - 1].command); | ||
else if (!index) setCommand(""); | ||
}, [index]); | ||
|
||
return ( | ||
<pre ref={term} className="overflow-scroll"> | ||
<div ref={log}> | ||
{[...history].reverse().map((e, i) => ( | ||
<div key={i}> | ||
<span> | ||
{">"} {e.command} | ||
</span> | ||
<div>{e.data}</div> | ||
</div> | ||
))} | ||
</div> | ||
{placeholder && ( | ||
<span> | ||
{">"} {placeholder} | ||
</span> | ||
)} | ||
<div> | ||
{!isExec && <span>{"> "}</span>} | ||
<input | ||
autoFocus | ||
type="text" | ||
value={command} | ||
onChange={(e) => setCommand(e.target.value)} | ||
onKeyDown={async (e) => { | ||
if (e.code === "Enter") { | ||
if (command) { | ||
setPlaceholder(command); | ||
setCommand(""); | ||
|
||
const data = await exec(command); | ||
setPlaceholder(""); | ||
|
||
setHistory([{ command, data }, ...history]); | ||
return; | ||
} | ||
setHistory([{ command, data: "" }, ...history]); | ||
} else if (e.code === "ArrowUp") { | ||
if (index < commands.length) | ||
return setIndex(index + 1); | ||
} else if (e.code === "ArrowDown") { | ||
if (index > 0) return setIndex(index - 1); | ||
} | ||
}} | ||
/> | ||
</div> | ||
</pre> | ||
); | ||
}; | ||
|
||
export default Repl; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters