Skip to content

Commit

Permalink
feat: ^C 2x makes dev-admin exit (#1634)
Browse files Browse the repository at this point in the history
  • Loading branch information
jchip authored Apr 30, 2020
1 parent fd2c408 commit fcf78da
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
22 changes: 21 additions & 1 deletion packages/xarc-app-dev/lib/dev-admin/admin-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,11 @@ class AdminServer {
if (line !== undefined) {
this._statusLine = line;
}
const exitMsg = this._ctrlCExit ? "\n<orange> == Press ^C again to Exit == </>" : "";
this._io.updateItem(
DEV_ADMIN_STATUS,
ck`Press M show/hide menu | Q exit | L set App Log Show Level: <white.inverse> ${this._appLogLevel} </> | ${this._statusLine}${this._menu}`
ck`Press M show/hide menu | Q exit | L set App Log Show Level: <white.inverse> \
${this._appLogLevel} </> | ${this._statusLine}${this._menu}${exitMsg}`
);
}

Expand Down Expand Up @@ -230,6 +232,13 @@ ${proxyItem}<magenta>M</> - Show this menu <magenta>Q</> - Shutdown
async processCommand(str) {
const handlers = {
q: () => this._quit(),
"^c": () => {
if (!this._menu) {
this.showMenu();
} else {
this.updateStatus();
}
},
m: () => this.showMenu(),
//logs
l: () => this._changeLogShowLevel(),
Expand All @@ -247,6 +256,17 @@ ${proxyItem}<magenta>M</> - Show this menu <magenta>Q</> - Shutdown
// dev proxy server
p: () => DEV_PROXY_ENABLED && this.sendMsg(PROXY_SERVER_NAME, { name: "restart" })
};

if (str === "^c") {
if (this._ctrlCExit) {
return this._quit();
}
this._ctrlCExit = true;
} else if (this._ctrlCExit) {
this._ctrlCExit = false;
this.updateStatus();
}

return handlers[str] && (await handlers[str]());
}

Expand Down
2 changes: 1 addition & 1 deletion packages/xarc-app-dev/lib/dev-admin/console-io.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ConsoleIO extends VisualLogger {
return new Promise(resolve => {
process.stdin.once("keypress", (str, key) => {
if (key.ctrl && key.name === "c") {
str = "m";
str = "^c";
}
resolve({ str: str && str.toLowerCase(), key });
});
Expand Down

0 comments on commit fcf78da

Please sign in to comment.