diff --git a/README.md b/README.md index b5683b7..cc3ee9a 100644 --- a/README.md +++ b/README.md @@ -154,6 +154,7 @@ The JSON format lets you specify additional things apart from the command itself | cwd | `string` | `"."` | Current working directory for the command. | | status | { [regex: string]: [string, string] | null } | `{}` | Customize the status of the command in the dashboard. | | defaultStatus | [string, string] | null | `null` | Customize the default status of the command in the dashboard. | +| killAllSequence | `string` | `"\u0003"` | Sequence to send to the command when using “kill all”. The default is the escape code for ctrl+c. | - command: On the command line, you let your shell split the commands into arguments. In the JSON format, you need to do it yourself. For example, if you had `run-pty % npm run frontend` on the command line, the JSON version of it is `["npm", "run", "frontend"]`. And `run-pty % echo 'hello world'` would be `["echo", "hello world"]`. @@ -182,6 +183,8 @@ The JSON format lets you specify additional things apart from the command itself - defaultStatus: This lets you replace 🟢 with a custom status indicator at startup (before your command has written anything). The value works like for `status`. +- killAllSequence: When you use “kill all” run-pty sends ctrl+c to all commands. However, not all commands exit when you do that. In such cases, you can use `killAllSequence` to specify what sequence of characters to the command to make it exit. + Instead of JSON, you can also use [NDJSON] – one JSON object per line (blank lines are OK, too). This is handy if you generate the file on the fly using some primitive scripting language. ## Credits diff --git a/example.json b/example.json index 62a0838..85c956e 100644 --- a/example.json +++ b/example.json @@ -23,6 +23,7 @@ "defaultStatus": [ "status Lorem ipsum dolor sit amet consectetur adipiscing elit ac faucibus, senectus neque etiam tempus tortor suscipit quis auctor, id ad fusce eleifend lobortis integer elementum praesent. Sodales quam elementum dui conubia purus aliquam facilisi bibendum senectus, netus consequat nec felis posuere erat himenaeos. Vitae conubia nisi interdum vestibulum neque est quisque, facilisis elementum ultricies commodo feugiat natoque mi, eu potenti posuere eros condimentum ridiculus", "status Lorem ipsum dolor sit amet consectetur adipiscing elit ac faucibus, senectus neque etiam tempus tortor suscipit quis auctor, id ad fusce eleifend lobortis integer elementum praesent. Sodales quam elementum dui conubia purus aliquam facilisi bibendum senectus, netus consequat nec felis posuere erat himenaeos. Vitae conubia nisi interdum vestibulum neque est quisque, facilisis elementum ultricies commodo feugiat natoque mi, eu potenti posuere eros condimentum ridiculus" - ] + ], + "killAllSequence": "\u0003\u0003" } ] diff --git a/run-pty.js b/run-pty.js index 1311151..097f278 100755 --- a/run-pty.js +++ b/run-pty.js @@ -578,8 +578,9 @@ const cmdEscapeArg = (arg) => title: string, cwd: string, command: Array, - status: Array<[RegExp, [string, string] | undefined]> - defaultStatus?: [string, string] + status: Array<[RegExp, [string, string] | undefined]>, + defaultStatus?: [string, string], + killAllSequence: string, }} CommandDescription */ @@ -654,6 +655,7 @@ const parseArgs = (args) => { command: command2, status: [], defaultStatus: undefined, + killAllSequence: KEY_CODES.kill, })), }; }; @@ -736,6 +738,10 @@ const commandDescriptionDecoder = Decode.fields( ) ), defaultStatus: field("defaultStatus", Decode.optional(statusDecoder)), + killAllSequence: field( + "killAllSequence", + Decode.optional(Decode.string, KEY_CODES.kill) + ), }; }, { exact: "throw" } @@ -794,6 +800,7 @@ class Command { command: [file, ...args], status: statusRules, defaultStatus, + killAllSequence, }, onData, onExit, @@ -803,6 +810,7 @@ class Command { this.file = file; this.args = args; this.cwd = cwd; + this.killAllSequence = killAllSequence; this.title = removeGraphicRenditions(title); this.titleWithGraphicRenditions = title; this.formattedCommandWithTitle = @@ -924,7 +932,7 @@ class Command { this.onData("", false); } }, SLOW_KILL); - this.status.terminal.write(KEY_CODES.kill); + this.status.terminal.write(this.killAllSequence); return undefined; case "Killing": { @@ -939,7 +947,7 @@ class Command { this.status.terminal.kill("SIGKILL"); } } else { - this.status.terminal.write(KEY_CODES.kill); + this.status.terminal.write(this.killAllSequence); } this.status.lastKillPress = now; return undefined;