Refaoct: 重构配置项

This commit is contained in:
Suwings 2022-07-10 11:09:54 +08:00
parent 79a8f76295
commit 9217024884
4 changed files with 9 additions and 6 deletions

View File

@ -65,7 +65,7 @@ export default class FunctionDispatcher extends InstanceCommand {
}
// 是否启用 PTY 模式
const ptyProgramPath = path.normalize(path.join(process.cwd(), "lib"));
if (instance.config.pty && instance.config.ptyWindowCol && instance.config.ptyWindowRow) {
if (instance.config.terminalOption.pty && instance.config.terminalOption.ptyWindowCol && instance.config.terminalOption.ptyWindowRow) {
if (!fs.existsSync(ptyProgramPath)) throw new Error("无法启用 PTY 模式,因为 ./lib/pty 附属程序不存在");
instance.setPreset("start", new PtyStartCommand());
}

View File

@ -97,7 +97,7 @@ export default class PtyStartCommand extends InstanceCommand {
let ptyAppName = "pty.exe";
if (os.platform() !== "win32") ptyAppName = "pty";
const ptyAppPath = path.normalize(path.join(process.cwd(), "lib", ptyAppName));
const ptyParameter = ["-dir", instance.config.cwd, "-cmd", commandList.join(" "), "-size", `${instance.config.ptyWindowCol},${instance.config.ptyWindowRow}`];
const ptyParameter = ["-dir", instance.config.cwd, "-cmd", commandList.join(" "), "-size", `${instance.config.terminalOption.ptyWindowCol},${instance.config.terminalOption.ptyWindowRow}`];
logger.info("----------------");
logger.info(`会话 ${source}: 请求开启实例.`);

View File

@ -43,16 +43,16 @@ export default class InstanceConfig {
public fileCode: string = "utf-8";
public processType: string = "general";
public updateCommand: string = "";
public pty: boolean = true;
public ptyWindowCol = 80;
public ptyWindowRow = 40;
// 自定义命令列表
public actionCommandList: IActionCommand[] = [];
// terminal option
public terminalOption = {
haveColor: true
haveColor: true,
pty: true,
ptyWindowCol: 80,
ptyWindowRow: 40
};
// Event task

View File

@ -158,6 +158,9 @@ export default class Instance extends EventEmitter {
}
if (cfg.terminalOption) {
configureEntityParams(this.config.terminalOption, cfg.terminalOption, "haveColor", Boolean);
configureEntityParams(this.config.terminalOption, cfg.terminalOption, "pty", Boolean);
configureEntityParams(this.config.terminalOption, cfg.terminalOption, "ptyWindowCol", Number);
configureEntityParams(this.config.terminalOption, cfg.terminalOption, "ptyWindowRow", Number);
}
StorageSubsystem.store("InstanceConfig", this.instanceUuid, this.config);
}