mirror of
https://github.com/MCSManager/MCSManager.git
synced 2024-12-15 07:40:01 +08:00
Feat: add resize
This commit is contained in:
parent
799c9be80e
commit
3799186b52
24
daemon/src/entity/commands/docker/docker_pty_resize.ts
Normal file
24
daemon/src/entity/commands/docker/docker_pty_resize.ts
Normal 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
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
21
daemon/src/entity/commands/pty/node_pty_resize.ts
Normal file
21
daemon/src/entity/commands/pty/node_pty_resize.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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", {
|
||||
|
Loading…
Reference in New Issue
Block a user