From 39444201a3313bde989cac40a3692c154aeb05c9 Mon Sep 17 00:00:00 2001 From: fofolee Date: Thu, 28 Apr 2022 23:21:59 +0800 Subject: [PATCH] =?UTF-8?q?ctrlC=20=E7=BB=88=E6=AD=A2=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/CommandRunResult.vue | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/components/CommandRunResult.vue b/src/components/CommandRunResult.vue index 008fcec..f5cc522 100644 --- a/src/components/CommandRunResult.vue +++ b/src/components/CommandRunResult.vue @@ -61,6 +61,7 @@ export default { runResultStatus: true, subInputValue: "", subInputListener: null, + ctrlCListener: null, quickcommandListener: null, history: [], historyIdx: null, @@ -152,6 +153,15 @@ export default { : this.showRunResult(stdout, true); } ); + // ctrl c 终止 + this.ctrlCListener = (e) => { + if (e.key === "c" && e.ctrlKey) { + quickcommand.kill(this.childProcess.pid); + quickcommand.showMessageBox("命令已终止"); + document.removeEventListener("keydown", this.ctrlCListener); + } + }; + document.addEventListener("keydown", this.ctrlCListener); } }, // 特殊变量赋值 @@ -260,9 +270,8 @@ export default { this.clear(); }, clear() { - if (!!this.childProcess) { - quickcommand.kill(this.childProcess.pid); - } + !!this.ctrlCListener && + document.removeEventListener("keydown", this.ctrlCListener); quickcommand.removeListener(); quickcommand.closeWaitButton(); },