Console improvements

This commit is contained in:
nickofolas
2022-01-13 19:46:30 -06:00
parent 01d6edb2a1
commit 8b95697bd4

View File

@@ -23,7 +23,7 @@ const useStyles = makeStyles((theme: Theme) =>
width: "100%", width: "100%",
}, },
input: { input: {
backgroundColor: "#000", backgroundColor: theme.colors.backgroundsecondary,
}, },
nopadding: { nopadding: {
padding: theme.spacing(0), padding: theme.spacing(0),
@@ -56,6 +56,7 @@ export function Console(props: IProps): React.ReactElement {
const classes = useStyles(); const classes = useStyles();
const [command, setCommand] = useState(""); const [command, setCommand] = useState("");
const setRerender = useState(false)[1]; const setRerender = useState(false)[1];
const consoleInput = useRef<HTMLInputElement>(null);
function handleCommandChange(event: React.ChangeEvent<HTMLInputElement>): void { function handleCommandChange(event: React.ChangeEvent<HTMLInputElement>): void {
setCommand(event.target.value); setCommand(event.target.value);
@@ -131,15 +132,21 @@ export function Console(props: IProps): React.ReactElement {
} }
} }
function handleClick(): void {
if (!consoleInput.current) return
consoleInput.current.focus();
}
return ( return (
<Paper> <Paper sx={{ p: 1 }}>
<Box sx={{ <Box sx={{
height: '60vh', height: '60vh',
paddingBottom: '8px', paddingBottom: '8px',
display: 'flex', display: 'flex',
alignItems: 'stretch', alignItems: 'stretch',
whiteSpace: 'pre-wrap', whiteSpace: 'pre-wrap',
}}> }}
onClick={handleClick}>
<Box> <Box>
<Logs entries={[...props.bladeburner.consoleLogs]} /> <Logs entries={[...props.bladeburner.consoleLogs]} />
</Box> </Box>
@@ -149,6 +156,7 @@ export function Console(props: IProps): React.ReactElement {
autoFocus autoFocus
tabIndex={1} tabIndex={1}
type="text" type="text"
inputRef={consoleInput}
value={command} value={command}
onChange={handleCommandChange} onChange={handleCommandChange}
onKeyDown={handleKeyDown} onKeyDown={handleKeyDown}
@@ -171,7 +179,7 @@ interface ILogProps {
entries: string[]; entries: string[];
} }
function Logs({entries}: ILogProps): React.ReactElement { function Logs({ entries }: ILogProps): React.ReactElement {
const scrollHook = useRef<HTMLUListElement>(null); const scrollHook = useRef<HTMLUListElement>(null);
// TODO: Text gets shifted up as new entries appear, if the user scrolled up it should attempt to keep the text focused // TODO: Text gets shifted up as new entries appear, if the user scrolled up it should attempt to keep the text focused
@@ -182,7 +190,7 @@ function Logs({entries}: ILogProps): React.ReactElement {
useEffect(() => { useEffect(() => {
scrollToBottom(); scrollToBottom();
}, [entries]); }, [entries.length]);
return ( return (
<List sx={{ height: "100%", overflow: "auto", p: 1 }} ref={scrollHook}> <List sx={{ height: "100%", overflow: "auto", p: 1 }} ref={scrollHook}>