mirror of
https://github.com/louislam/dockge.git
synced 2026-05-22 06:22:17 +00:00
wip
This commit is contained in:
43
backend/terminal.ts
Normal file
43
backend/terminal.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { DockgeServer } from "./dockge-server";
|
||||
import * as os from "node:os";
|
||||
import * as pty from "node-pty";
|
||||
import { LimitQueue } from "./utils/limit-queue";
|
||||
|
||||
const shell = os.platform() === "win32" ? "pwsh.exe" : "bash";
|
||||
|
||||
export class Terminal {
|
||||
|
||||
ptyProcess;
|
||||
private server : DockgeServer;
|
||||
private buffer : LimitQueue<string> = new LimitQueue(100);
|
||||
|
||||
constructor(server : DockgeServer) {
|
||||
this.server = server;
|
||||
|
||||
this.ptyProcess = pty.spawn(shell, [], {
|
||||
name: "dockge-terminal",
|
||||
cwd: "./tmp",
|
||||
});
|
||||
|
||||
// this.ptyProcess.write("npm remove lodash\r");
|
||||
//this.ptyProcess.write("npm install lodash\r");
|
||||
|
||||
this.ptyProcess.onData((data) => {
|
||||
this.buffer.push(data);
|
||||
this.server.io.to("terminal").emit("commandOutput", data);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
write(input : string) {
|
||||
this.ptyProcess.write(input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the terminal output string for re-connecting
|
||||
*/
|
||||
getBuffer() : string {
|
||||
return this.buffer.join("");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user