silverbullet/plugs/core/debug.ts

90 lines
2.0 KiB
TypeScript
Raw Normal View History

2022-10-14 21:11:33 +08:00
import { sandbox } from "$sb/plugos-syscall/mod.ts";
2022-05-09 20:59:12 +08:00
import {
2022-10-14 21:11:33 +08:00
editor,
markdown,
sandbox as serverSandbox,
} from "$sb/silverbullet-syscall/mod.ts";
2022-05-09 20:59:12 +08:00
export async function parsePageCommand() {
2022-07-04 21:51:04 +08:00
console.log(
"AST",
2022-10-14 21:11:33 +08:00
JSON.stringify(
await markdown.parseMarkdown(await editor.getText()),
null,
2,
),
2022-07-04 21:51:04 +08:00
);
2022-05-09 20:59:12 +08:00
}
export async function showLogsCommand() {
2022-10-14 21:11:33 +08:00
const clientLogs = await sandbox.getLogs();
const serverLogs = await serverSandbox.getServerLogs();
2022-05-09 20:59:12 +08:00
2022-10-14 21:11:33 +08:00
await editor.showPanel(
2022-09-30 23:06:12 +08:00
"bhs",
1,
2022-05-09 20:59:12 +08:00
`
<style>
#client-log-header {
position: absolute;
left: 0;
top: 5px;
}
#server-log-header {
position: absolute;
right: 0;
top: 5px;
width: 50%;
}
#client-log {
position: absolute;
left: 0;
top: 30px;
bottom: 0;
width: 50%;
overflow: scroll;
}
#server-log {
position: absolute;
right: 0;
top: 30px;
bottom: 0;
width: 50%;
overflow: scroll;
}
</style>
<div id="client-log-header">Client logs (max 100)</div>
<div id="client-log">
2022-10-12 17:47:13 +08:00
<pre>${
clientLogs
2022-05-09 20:59:12 +08:00
.map((le) => `[${le.level}] ${le.message}`)
2022-10-12 17:47:13 +08:00
.join("\n")
}</pre>
2022-05-09 20:59:12 +08:00
</div>
<div id="server-log-header">Server logs (max 100)</div>
<div id="server-log">
2022-10-12 17:47:13 +08:00
<pre>${
serverLogs
2022-05-09 20:59:12 +08:00
.map((le) => `[${le.level}] ${le.message}`)
2022-10-12 17:47:13 +08:00
.join("\n")
}</pre>
2022-05-09 20:59:12 +08:00
</div>`,
`
var clientDiv = document.getElementById("client-log");
clientDiv.scrollTop = clientDiv.scrollHeight;
var serverDiv = document.getElementById("server-log");
serverDiv.scrollTop = serverDiv.scrollHeight;
2022-05-12 02:10:45 +08:00
if(window.reloadInterval) {
clearInterval(window.reloadInterval);
}
window.reloadInterval = setInterval(() => {
sendEvent("log:reload");
}, 1000);
2022-10-12 17:47:13 +08:00
`,
2022-05-09 20:59:12 +08:00
);
}
export async function hideBhsCommand() {
2022-10-14 21:11:33 +08:00
await editor.hidePanel("bhs");
2022-05-09 20:59:12 +08:00
}