allow using console interface within project
This commit is contained in:
parent
9a2ad7f2c5
commit
2ecdfcebf0
@ -3,6 +3,8 @@ export class CodeRunner {
|
||||
this.console = console;
|
||||
this.codeStopper = codeStopper;
|
||||
this.isRunning = false;
|
||||
|
||||
window.playgroundConsole = this.console;
|
||||
}
|
||||
|
||||
setCode(code) {
|
||||
@ -18,13 +20,13 @@ export class CodeRunner {
|
||||
|
||||
// Use RNG to prevent caching
|
||||
const encodedText = encodeURIComponent(
|
||||
this.code + `/*(tph): ${Math.random()}*/`,
|
||||
`let console=playgroundConsole;${this.code}/*(tph): ${Math.random()}*/`,
|
||||
);
|
||||
|
||||
try {
|
||||
await import(`data:text/javascript;charset=utf-8,${encodedText}`);
|
||||
} catch (error) {
|
||||
this.console.log(error);
|
||||
this.console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,29 @@ export class PlaygroundConsole {
|
||||
}
|
||||
|
||||
log(text) {
|
||||
this.elem.textContent += `\n${text}\n`;
|
||||
const el = document.createElement("span");
|
||||
el.textContent = `\n${text}\n`;
|
||||
this.elem.appendChild(el);
|
||||
}
|
||||
|
||||
error(text) {
|
||||
const el = document.createElement("span");
|
||||
el.className = "error";
|
||||
el.textContent = `\n${text}\n`;
|
||||
this.elem.appendChild(el);
|
||||
}
|
||||
|
||||
debug(text) {
|
||||
const el = document.createElement("span");
|
||||
el.className = "debug";
|
||||
el.textContent = `\n${text}\n`;
|
||||
this.elem.appendChild(el);
|
||||
}
|
||||
|
||||
info(text) {
|
||||
const el = document.createElement("span");
|
||||
el.className = "info";
|
||||
el.textContent = `\n${text}\n`;
|
||||
this.elem.appendChild(el);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user