Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | import React, { useCallback, useLayoutEffect, useRef } from "react"; import styled, { css } from "styled-components"; import l10n from "shared/lib/lang/l10n"; import { useAppDispatch, useAppSelector } from "store/hooks"; import editorActions from "store/features/editor/editorActions"; import { ConsoleLink } from "store/features/console/consoleState"; import { ResourceLinkedText } from "ui/links/ResourceLinkedText"; import { DebuggerBuildFooter } from "components/debugger/DebuggerBuildFooter"; const PIN_TO_BOTTOM_RANGE = 100; const isNearBottom = (el: HTMLDivElement) => el.scrollTop >= el.scrollHeight - el.clientHeight - PIN_TO_BOTTOM_RANGE; const Wrapper = styled.div` display: flex; flex-direction: column; width: 100%; height: 100%; overflow: auto; font-size: 11px; `; const Terminal = styled.div` flex-grow: 1; background: #111; color: #fff; padding: 10px; font-family: monospace; font-size: 12px; white-space: pre-wrap; overflow: auto; user-select: text; `; interface LogLineProps { $type: "log" | "warn"; } const LogLine = styled.div<LogLineProps>` color: white; ${(props) => props.$type === "warn" ? css` color: orange; ` : ""}; `; const LogLink = styled.a` cursor: pointer; `; interface BuildLogLineProps { text: string; link?: ConsoleLink; type: "log" | "warn"; } const BuildLogLine = ({ text, type, link }: BuildLogLineProps) => { const dispatch = useAppDispatch(); return ( <LogLine $type={type}> <ResourceLinkedText text={text} /> {link && ( <LogLink onClick={() => { if (link.type === "customEvent") { dispatch( editorActions.openEditorResourceById({ type: "customEvent", customEventId: link.entityId, }), ); } else if (link.type === "actor") { dispatch( editorActions.openEditorResourceById({ type: "actor", actorId: link.entityId, sceneId: link.sceneId, }), ); } else if (link.type === "trigger") { dispatch( editorActions.openEditorResourceById({ type: "trigger", triggerId: link.entityId, sceneId: link.sceneId, }), ); } else if (link.type === "scene") { dispatch( editorActions.openEditorResourceById({ type: "scene", sceneId: link.sceneId, }), ); } }} > ➡️ <u>{link.linkText}</u> </LogLink> )} </LogLine> ); }; const DebuggerBuildLog = () => { const scrollRef = useRef<HTMLDivElement>(null); const shouldPinToBottomRef = useRef(true); const output = useAppSelector((state) => state.console.output); const warnings = useAppSelector((state) => state.console.warnings); const status = useAppSelector((state) => state.console.status); // Only show the latest 500 lines during build // show full output on complete const outputLines = status === "complete" ? output : output.slice(-500); const onScroll = useCallback(() => { const scrollEl = scrollRef.current; if (!scrollEl) { return; } shouldPinToBottomRef.current = isNearBottom(scrollEl); }, []); useLayoutEffect(() => { // Pin scroll to bottom of console as new lines arrive if currently near bottom of scroll anyway const scrollEl = scrollRef.current; if (!scrollEl) { return; } if (shouldPinToBottomRef.current) { scrollEl.scrollTop = scrollEl.scrollHeight; } }, [outputLines.length, warnings.length, status]); useLayoutEffect(() => { // Pin scroll to bottom of console on initial load const scrollEl = scrollRef.current; if (!scrollEl) { return; } scrollEl.scrollTop = scrollEl.scrollHeight; shouldPinToBottomRef.current = true; }, []); return ( <Wrapper> <Terminal ref={scrollRef} onScroll={onScroll}> {outputLines.map((out, index) => ( <BuildLogLine key={index} text={out.text} type={out.type === "err" ? "warn" : "log"} link={out.link} /> ))} {status === "cancelled" && ( <div style={{ color: "orange" }}>{l10n("BUILD_CANCELLING")}...</div> )} {status === "complete" && warnings.length > 0 && ( <div> <br /> Warnings: {warnings.map((out, index) => ( <BuildLogLine key={index} type="warn" text={out.text} link={out.link} /> ))} </div> )} </Terminal> <DebuggerBuildFooter showClear /> </Wrapper> ); }; export default DebuggerBuildLog; |