From 9a5e109bf0f4631f28e25a35b2452ab27a3f72f7 Mon Sep 17 00:00:00 2001 From: Joel Chen Date: Wed, 29 Apr 2020 22:40:32 -0700 Subject: [PATCH] feat: ^C 2x makes dev-admin exit --- .../lib/dev-admin/admin-server.js | 22 ++++++++++++++++++- .../xarc-app-dev/lib/dev-admin/console-io.js | 2 +- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/packages/xarc-app-dev/lib/dev-admin/admin-server.js b/packages/xarc-app-dev/lib/dev-admin/admin-server.js index 45145bc8c..308104ce8 100644 --- a/packages/xarc-app-dev/lib/dev-admin/admin-server.js +++ b/packages/xarc-app-dev/lib/dev-admin/admin-server.js @@ -106,9 +106,11 @@ class AdminServer { if (line !== undefined) { this._statusLine = line; } + const exitMsg = this._ctrlCExit ? "\n == 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: ${this._appLogLevel} | ${this._statusLine}${this._menu}` + ck`Press M show/hide menu | Q exit | L set App Log Show Level: \ +${this._appLogLevel} | ${this._statusLine}${this._menu}${exitMsg}` ); } @@ -230,6 +232,13 @@ ${proxyItem}M - Show this menu 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(), @@ -247,6 +256,17 @@ ${proxyItem}M - Show this menu 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]()); } diff --git a/packages/xarc-app-dev/lib/dev-admin/console-io.js b/packages/xarc-app-dev/lib/dev-admin/console-io.js index 223c21145..50967339a 100644 --- a/packages/xarc-app-dev/lib/dev-admin/console-io.js +++ b/packages/xarc-app-dev/lib/dev-admin/console-io.js @@ -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 }); });