Skip to content

Commit d779cbf

Browse files
committed
Add timing, skip too many newlines.
1 parent d44bbcb commit d779cbf

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

src/env.js

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ class InBrowserEnvironment {
1515
this.worker.postMessage({ id: 'constructor', data: remotePort },
1616
[remotePort]);
1717
this.terminal = terminal;
18+
this.setShowTiming(true);
19+
this.skip_newlines = false;
20+
this.in_compiling = false;
1821
}
1922

2023
setShowTiming(value) {
@@ -42,6 +45,28 @@ class InBrowserEnvironment {
4245
console.log(event);
4346
switch (event.data.id) {
4447
case 'write':
48+
// Workaround for noisy wasm-clang output
49+
if (event.data.data.includes('Compiling test.wasm')) {
50+
this.in_compiling = true;
51+
return;
52+
} else {
53+
if (this.in_compiling) {
54+
if (event.data.data !== '\n') {
55+
return;
56+
}
57+
this.in_compiling = false;
58+
}
59+
}
60+
if (this.skip_newlines && event.data.data === '\n') {
61+
return;
62+
}
63+
if (event.data.data.includes('clang -cc1') || event.data.data.includes('wasm-ld')) {
64+
this.skip_newlines = true;
65+
} else {
66+
this.skip_newlines = false;
67+
}
68+
// Workaround ends here
69+
4570
this.terminal(event.data.data, 'stdout');
4671
break;
4772

@@ -87,17 +112,10 @@ export async function runCode(log, setStatus, runBtn, stdinInput) {
87112
setStatus('running');
88113
const editor = getEditor();
89114
const code = editor.getValue();
90-
// log('─'.repeat(50), 'system');
91-
// log('Compiling...', 'info');
115+
log('Compiling and running...', 'system');
92116
try {
93117
env.terminal = log;
94-
let result = await env.compileLinkRun(code);
95-
console.log(result);
96-
// log('Program output:', 'info');
97-
// log('─'.repeat(50), 'system');
98-
// log(result, 'stdout');
99-
// log('─'.repeat(50), 'system');
100-
// log(`Program finished execution`, 'success');
118+
await env.compileLinkRun(code);
101119
setStatus('ready');
102120
} catch (error) {
103121
log(`Error: ${error.message}`, 'stderr');

0 commit comments

Comments
 (0)