35 lines
1.0 KiB
JavaScript
Raw Normal View History

2024-04-28 20:06:47 -04:00
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Pty = void 0;
const node_pty_1 = require("node-pty");
const os_1 = __importDefault(require("os"));
class Pty {
2024-04-29 00:50:25 -04:00
constructor(socket, id, cwd) {
2024-04-28 20:06:47 -04:00
this.socket = socket;
2024-04-29 00:50:25 -04:00
this.id = id;
2024-04-29 02:19:27 -04:00
this.ptyProcess = (0, node_pty_1.spawn)(os_1.default.platform() === "win32" ? "cmd.exe" : "bash", [], {
2024-04-28 20:06:47 -04:00
name: "xterm",
cols: 100,
2024-04-29 00:50:25 -04:00
cwd: cwd,
2024-04-28 20:06:47 -04:00
});
this.ptyProcess.onData((data) => {
console.log("onData", data);
this.send(data);
});
// this.write("hello world")
}
write(data) {
console.log("writing data", data);
this.ptyProcess.write(data);
}
send(data) {
this.socket.emit("terminalResponse", {
data: Buffer.from(data, "utf-8"),
});
}
}
exports.Pty = Pty;