Various log box improvements

This commit is contained in:
nickofolas 2022-05-09 18:15:23 -05:00
parent bc9bce0d2c
commit d4e97d786c

@ -80,21 +80,12 @@ interface IProps {
const useStyles = makeStyles((_theme: Theme) => const useStyles = makeStyles((_theme: Theme) =>
createStyles({ createStyles({
title: {
"&.is-minimized + *": {
border: "none",
margin: 0,
"max-height": 0,
padding: 0,
"pointer-events": "none",
visibility: "hidden",
},
},
logs: { logs: {
overflowY: "scroll", overflowY: "scroll",
overflowX: "hidden", overflowX: "hidden",
scrollbarWidth: "auto", scrollbarWidth: "auto",
flexDirection: "column-reverse", flexDirection: "column-reverse",
whiteSpace: "pre-wrap",
}, },
titleButton: { titleButton: {
padding: "1px 0", padding: "1px 0",
@ -176,7 +167,7 @@ function LogWindow(props: IProps): React.ReactElement {
setMinimized(!minimized); setMinimized(!minimized);
} }
function lineClass(s: string): string { function lineColor(s: string): string {
if (s.match(/(^\[[^\]]+\] )?ERROR/) || s.match(/(^\[[^\]]+\] )?FAIL/)) { if (s.match(/(^\[[^\]]+\] )?ERROR/) || s.match(/(^\[[^\]]+\] )?FAIL/)) {
return Settings.theme.error; return Settings.theme.error;
} }
@ -228,74 +219,99 @@ function LogWindow(props: IProps): React.ReactElement {
if (e.clientX < 0 || e.clientY < 0 || e.clientX > innerWidth || e.clientY > innerHeight) return false; if (e.clientX < 0 || e.clientY < 0 || e.clientX > innerWidth || e.clientY > innerHeight) return false;
}; };
// Max [width, height]
const minConstraints: [number, number] = [250, 33];
return ( return (
<Draggable handle=".drag" onDrag={boundToBody} ref={rootRef}> <Draggable handle=".drag" onDrag={boundToBody} ref={rootRef} onMouseDown={updateLayer}>
<Paper <Box
style={{ display="flex"
display: "flex", sx={{
flexFlow: "column", flexFlow: "column",
position: "fixed", position: "fixed",
left: "40%", left: "40%",
top: "30%", top: "30%",
zIndex: 1400, zIndex: 1400,
minWidth: `${minConstraints[0]}px`,
minHeight: `${minConstraints[1]}px`,
...(minimized
? {
border: "none",
margin: 0,
maxHeight: 0,
padding: 0,
}
: {
border: `1px solid ${Settings.theme.welllight}`,
}),
}} }}
ref={container} ref={container}
> >
<div onMouseDown={updateLayer}> <ResizableBox
<Paper height={500}
className={classes.title + " " + (minimized ? "is-minimized" : "")} width={500}
style={{ minConstraints={minConstraints}
cursor: "grab", handle={
}} <span
> style={{
<Box className="drag" display="flex" alignItems="center" ref={draggableRef}> position: "absolute",
<Typography color="primary" variant="h6" sx={{ marginRight: "auto" }} title={title(true)}> right: "-10px",
{title()} bottom: "-13px",
cursor: "nw-resize",
display: minimized ? "none" : "inline-block",
}}
>
<ArrowForwardIosIcon color="primary" style={{ transform: "rotate(45deg)", fontSize: "1.75rem" }} />
</span>
}
>
<>
<Paper className="drag" sx={{ display: "flex", alignItems: "center", cursor: "grab" }} ref={draggableRef}>
<Typography
variant="h6"
sx={{ marginRight: "auto", textOverflow: "ellipsis", whiteSpace: "nowrap", overflow: "hidden" }}
title={title(true)}
>
{title(true)}
</Typography> </Typography>
{!workerScripts.has(script.pid) ? ( <span style={{ minWidth: "fit-content", height: `${minConstraints[1]}px` }}>
<Button className={classes.titleButton} onClick={run} onTouchEnd={run}> {!workerScripts.has(script.pid) ? (
Run <Button className={classes.titleButton} onClick={run} onTouchEnd={run}>
Run
</Button>
) : (
<Button className={classes.titleButton} onClick={kill} onTouchEnd={kill}>
Kill
</Button>
)}
<Button className={classes.titleButton} onClick={minimize} onTouchEnd={minimize}>
{minimized ? "\u{1F5D6}" : "\u{1F5D5}"}
</Button> </Button>
) : ( <Button className={classes.titleButton} onClick={props.onClose} onTouchEnd={props.onClose}>
<Button className={classes.titleButton} onClick={kill} onTouchEnd={kill}> Close
Kill
</Button> </Button>
)} </span>
<Button className={classes.titleButton} onClick={minimize} onTouchEnd={minimize}> </Paper>
{minimized ? "\u{1F5D6}" : "\u{1F5D5}"}
</Button> <Paper
<Button className={classes.titleButton} onClick={props.onClose} onTouchEnd={props.onClose}>
Close
</Button>
</Box>
</Paper>
<Paper sx={{ overflow: "scroll", overflowWrap: "break-word", whiteSpace: "pre-wrap" }}>
<ResizableBox
className={classes.logs} className={classes.logs}
height={500} sx={{ height: `calc(100% - ${minConstraints[1]}px)`, display: minimized ? "none" : "flex" }}
width={500}
minConstraints={[250, 30]}
handle={
<span style={{ position: "absolute", right: "-10px", bottom: "-13px", cursor: "nw-resize" }}>
<ArrowForwardIosIcon color="primary" style={{ transform: "rotate(45deg)" }} />
</span>
}
> >
<Box> <span style={{ display: "flex", flexDirection: "column" }}>
{script.logs.map( {script.logs.map(
(line: string, i: number): JSX.Element => ( (line: string, i: number): JSX.Element => (
<Typography key={i} className={lineClass(line)}> <Typography key={i} sx={{ color: lineColor(line) }}>
{line} {line}
<br /> <br />
</Typography> </Typography>
), ),
)} )}
</Box> </span>
</ResizableBox> </Paper>
</Paper> </>
</div> </ResizableBox>
</Paper> </Box>
</Draggable> </Draggable>
); );
} }