Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

feat: capture console logs to Output panel

esenginef0e3c68d1b1a
diff --git a/desktop/index.html b/desktop/index.html
index caa23cb77..3cf611d68 100644
--- a/desktop/index.html
+++ b/desktop/index.html
@@ -13,7 +13,7 @@
-webkit-user-select: none;
user-select: none;
}
- input, textarea, [contenteditable] {
+ input, textarea, [contenteditable], .es-output-content, .es-output-content * {
-webkit-user-select: text;
user-select: text;
}
diff --git a/editor/src/Editor.ts b/editor/src/Editor.ts
index ddbd96f25..d034c043d 100644
--- a/editor/src/Editor.ts
+++ b/editor/src/Editor.ts
@@ -602,6 +602,27 @@ export class Editor {
}
}
+ private installConsoleCapture(): void {
+ const original = {
+ log: console.log.bind(console),
+ info: console.info.bind(console),
+ warn: console.warn.bind(console),
+ error: console.error.bind(console),
+ };
+
+ const forward = (type: 'stdout' | 'stderr' | 'error', args: unknown[]) => {
+ const text = args.map(a =>
+ typeof a === 'string' ? a : JSON.stringify(a, null, 2) ?? String(a)
+ ).join(' ');
+ this.appendOutput(text + '\n', type);
+ };
+
+ console.log = (...args) => { original.log(...args); forward('stdout', args); };
+ console.info = (...args) => { original.info(...args); forward('stdout', args); };
+ console.warn = (...args) => { original.warn(...args); forward('stderr', args); };
+ console.error = (...args) => { original.error(...args); forward('error', args); };
+ }
+
private appendOutput(text: string, type: 'command' | 'stdout' | 'stderr' | 'error' | 'success'): void {
const outputPanel = this.panelInstances_.get('output');
if (outputPanel && isOutputAppendable(outputPanel)) {
@@ -646,6 +667,7 @@ export class Editor {
this.setupToolbarEvents();
this.store_.subscribe(() => this.updateToolbarState());
this.store_.subscribe(() => this.updateStatusbar());
+ this.installConsoleCapture();
}
private buildTabBarHTML(): string {
diff --git a/editor/src/styles/editor.css b/editor/src/styles/editor.css
index 888821525..0859aaa95 100644
--- a/editor/src/styles/editor.css
+++ b/editor/src/styles/editor.css
@@ -1488,6 +1488,11 @@ svg {
background: var(--es-bg-primary);
}
+.es-editor-bottom > .es-panel-container {
+ flex: 1;
+ overflow: hidden;
+}
+
.es-content-browser-container,
.es-output-container {
flex: 1;
@@ -1897,6 +1902,8 @@ svg {
padding: 8px;
font-family: 'Consolas', 'Monaco', monospace;
font-size: 12px;
+ user-select: text;
+ cursor: text;
}
.es-output-empty {