Make tail box display ANSII colors

This commit is contained in:
Olivier Gagnon
2022-07-14 16:34:42 -04:00
parent ad098e1f05
commit 00ddeb751c

View File

@@ -19,6 +19,7 @@ import { findRunningScript } from "../../Script/ScriptHelpers";
import { Player } from "../../Player"; import { Player } from "../../Player";
import { debounce } from "lodash"; import { debounce } from "lodash";
import { Settings } from "../../Settings/Settings"; import { Settings } from "../../Settings/Settings";
import { ANSIITypography } from "./ANSIITypography";
let layerCounter = 0; let layerCounter = 0;
@@ -185,20 +186,20 @@ function LogWindow(props: IProps): React.ReactElement {
setMinimized(!minimized); setMinimized(!minimized);
} }
function lineColor(s: string): string { function lineColor(s: string): "error" | "success" | "warn" | "info" | "primary" {
if (s.match(/(^\[[^\]]+\] )?ERROR/) || s.match(/(^\[[^\]]+\] )?FAIL/)) { if (s.match(/(^\[[^\]]+\] )?ERROR/) || s.match(/(^\[[^\]]+\] )?FAIL/)) {
return Settings.theme.error; return "error";
} }
if (s.match(/(^\[[^\]]+\] )?SUCCESS/)) { if (s.match(/(^\[[^\]]+\] )?SUCCESS/)) {
return Settings.theme.success; return "success";
} }
if (s.match(/(^\[[^\]]+\] )?WARN/)) { if (s.match(/(^\[[^\]]+\] )?WARN/)) {
return Settings.theme.warning; return "warn";
} }
if (s.match(/(^\[[^\]]+\] )?INFO/)) { if (s.match(/(^\[[^\]]+\] )?INFO/)) {
return Settings.theme.info; return "info";
} }
return Settings.theme.primary; return "primary";
} }
// And trigger fakeDrag when the window is resized // And trigger fakeDrag when the window is resized
@@ -319,10 +320,10 @@ function LogWindow(props: IProps): React.ReactElement {
<span style={{ display: "flex", flexDirection: "column" }}> <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} sx={{ color: lineColor(line) }}> <React.Fragment key={i}>
{line} <ANSIITypography text={line} color={lineColor(line)} />
<br /> <br />
</Typography> </React.Fragment>
), ),
)} )}
</span> </span>