Feat: add resize

This commit is contained in:
unitwk 2024-03-08 15:19:44 +08:00
parent 799c9be80e
commit 3799186b52
3 changed files with 51 additions and 2 deletions

View File

@ -0,0 +1,24 @@
import Instance from "../../instance/instance";
import InstanceCommand from "../base/command";
import { DockerProcessAdapter } from "./docker_start";
export interface IResizeOptions {
h: number;
w: number;
}
export default class DockerResizeCommand extends InstanceCommand {
constructor() {
super("ResizeTTY");
}
async exec(instance: Instance, size?: IResizeOptions): Promise<any> {
const dockerProcess = instance?.process as Partial<DockerProcessAdapter>;
if (typeof dockerProcess?.container?.resize === "function") {
await dockerProcess?.container?.resize({
h: size.h,
w: size.w
});
}
}
}

View File

@ -0,0 +1,21 @@
import Instance from "../../instance/instance";
import InstanceCommand from "../base/command";
import { NodeProcessAdapter } from "./node_pty_start";
interface IResizeOptions {
h: number;
w: number;
}
export default class NodePtyResizeCommand extends InstanceCommand {
constructor() {
super("ResizeTTY");
}
async exec(instance: Instance, size?: IResizeOptions): Promise<any> {
const dockerProcess = instance.process as Partial<NodeProcessAdapter>;
if (typeof dockerProcess?.resize === "function") {
dockerProcess?.resize(size.w, size.h);
}
}
}

View File

@ -25,7 +25,7 @@ class StartupError extends Error {
}
// process adapter
class ProcessAdapter extends EventEmitter implements IInstanceProcess {
export class NodeProcessAdapter extends EventEmitter implements IInstanceProcess {
public pid?: number;
public exitCode: number;
@ -39,6 +39,10 @@ class ProcessAdapter extends EventEmitter implements IInstanceProcess {
});
}
public resize(w: number, h: number) {
this.process.resize(w, h);
}
public write(data?: string) {
return this.process.write(data);
}
@ -157,7 +161,7 @@ export default class NodePtyStartCommand extends InstanceCommand {
throw new StartupError($t("TXT_CODE_general_start.startErr"));
}
const processAdapter = new ProcessAdapter(ptyProcess);
const processAdapter = new NodeProcessAdapter(ptyProcess);
instance.started(processAdapter);
logger.info(
$t("TXT_CODE_pty_start.startSuccess", {