Skip to content

Commit

Permalink
Add killAllSequence
Browse files Browse the repository at this point in the history
  • Loading branch information
lydell committed Feb 19, 2022
1 parent b673c9d commit 6a3ab30
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | <code>{ [regex: string]: [string,&nbsp;string] &vert; null }</code> | `{}` | Customize the status of the command in the dashboard. |
| defaultStatus | <code>[string,&nbsp;string] &vert; null</code> | `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 <kbd>ctrl+c</kbd>. |

- 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"]`.

Expand Down Expand Up @@ -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 <kbd>ctrl+c</kbd> 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
Expand Down
3 changes: 2 additions & 1 deletion example.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
16 changes: 12 additions & 4 deletions run-pty.js
Original file line number Diff line number Diff line change
Expand Up @@ -578,8 +578,9 @@ const cmdEscapeArg = (arg) =>
title: string,
cwd: string,
command: Array<string>,
status: Array<[RegExp, [string, string] | undefined]>
defaultStatus?: [string, string]
status: Array<[RegExp, [string, string] | undefined]>,
defaultStatus?: [string, string],
killAllSequence: string,
}} CommandDescription
*/

Expand Down Expand Up @@ -654,6 +655,7 @@ const parseArgs = (args) => {
command: command2,
status: [],
defaultStatus: undefined,
killAllSequence: KEY_CODES.kill,
})),
};
};
Expand Down Expand Up @@ -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" }
Expand Down Expand Up @@ -794,6 +800,7 @@ class Command {
command: [file, ...args],
status: statusRules,
defaultStatus,
killAllSequence,
},
onData,
onExit,
Expand All @@ -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 =
Expand Down Expand Up @@ -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": {
Expand All @@ -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;
Expand Down

0 comments on commit 6a3ab30

Please sign in to comment.