Skip to content
This repository was archived by the owner on Nov 13, 2024. It is now read-only.

Commit b0f0470

Browse files
committed
Feat: enable multi-command stop command
1 parent 4a597b5 commit b0f0470

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

src/entity/commands/general/general_stop.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,19 @@ export default class GeneralStopCommand extends InstanceCommand {
1616

1717
instance.status(Instance.STATUS_STOPPING);
1818

19-
if (stopCommand.toLocaleLowerCase() == "^c") {
20-
instance.process.kill("SIGINT");
21-
} else {
22-
await instance.exec(new SendCommand(stopCommand));
19+
const stopCommandList = stopCommand.split(/(\^c|\^C|\\n|\\N)/g);
20+
for (const stopCommandColumn of stopCommandList) {
21+
if (stopCommandColumn == "") {
22+
continue;
23+
}
24+
if (stopCommandColumn.toLocaleLowerCase() == "\\n") {
25+
continue;
26+
}
27+
if (stopCommandColumn.toLocaleLowerCase() == "^c") {
28+
instance.process.kill("SIGINT");
29+
} else {
30+
await instance.exec(new SendCommand(stopCommandColumn));
31+
}
2332
}
2433

2534
instance.println("INFO", $t("general_stop.execCmd", { stopCommand }));

src/entity/commands/pty/pty_stop.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,21 @@ export default class PtyStopCommand extends InstanceCommand {
1717
instance.status(Instance.STATUS_STOPPING);
1818

1919
instance.println("INFO", $t("pty_stop.execCmd", { stopCommand: stopCommand }));
20-
if (stopCommand.toLowerCase() == "^c") stopCommand = "\x03";
21-
await instance.exec(new SendCommand(stopCommand));
20+
21+
const stopCommandList = stopCommand.split(/(\^c|\^C|\\n|\\N)/g);
22+
for (const stopCommandColumn of stopCommandList) {
23+
if (stopCommandColumn == "") {
24+
continue;
25+
}
26+
if (stopCommandColumn.toLocaleLowerCase() == "\\n") {
27+
continue;
28+
}
29+
if (stopCommandColumn.toLocaleLowerCase() == "^c") {
30+
await instance.exec(new SendCommand("\x03"));
31+
} else {
32+
await instance.exec(new SendCommand(stopCommandColumn));
33+
}
34+
}
2235

2336
// If the instance is still in the stopped state after 10 minutes, restore the state
2437
const cacheStartCount = instance.startCount;

0 commit comments

Comments
 (0)