draft: terminal

This commit is contained in:
2024-08-23 05:14:45 +07:00
parent 145bf3f1a9
commit e1c630acce
11 changed files with 208 additions and 1 deletions
+42
View File
@@ -0,0 +1,42 @@
import Page from "@/context/page-context";
import { useEffect, useRef } from "react";
import { Terminal } from "@xterm/xterm";
import { AttachAddon } from "@xterm/addon-attach";
import "@xterm/xterm/css/xterm.css";
const WS_URL = "ws://" + location.host + "/ws";
const TerminalPage = () => {
const terminalContainerRef = useRef<HTMLDivElement | null>(null);
const wsRef = useRef<WebSocket | null>(null);
useEffect(() => {
const container = terminalContainerRef.current;
if (!container || wsRef.current) {
return;
}
const url = WS_URL + "/terminal";
const ws = new WebSocket(url);
wsRef.current = ws;
const term = new Terminal();
const attachAddon = new AttachAddon(ws);
term.loadAddon(attachAddon);
term.open(container);
// return () => {
// term.dispose();
// ws.close();
// };
}, []);
return (
<div className="container">
<Page title="Terminal" />
<div ref={terminalContainerRef}></div>
</div>
);
};
export default TerminalPage;