From 215fd29607e831af7b2cb61b50a2df1147fede53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 27 Sep 2024 19:03:13 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=B0=E5=BF=86=E4=B8=8A=E4=B8=AA=E6=8E=A7?= =?UTF-8?q?=E5=88=B6=E5=8F=B0=E7=9A=84=E8=BE=93=E5=85=A5=E5=8E=86=E5=8F=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/console/client.ts | 9 ++++++++- src/console/terminal.ts | 12 ++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/console/client.ts b/src/console/client.ts index 361266b..d565e93 100644 --- a/src/console/client.ts +++ b/src/console/client.ts @@ -71,10 +71,15 @@ export class Client extends vscode.Disposable { } } + static terminalHistory: { [name: string]: string[]} = {}; + constructor(private onSend: (obj: Response | Request | Notify) => void) { super(() => { this.closeAllRequests(); - this.terminal?.dispose(); + if (this.terminal) { + Client.terminalHistory[this.name] = this.terminal.getHistoryStack(); + this.terminal.dispose(); + } this.treeViewManager.dispose(); Client.allClients.splice(Client.allClients.indexOf(this), 1); Client.updateButton(); @@ -88,6 +93,7 @@ export class Client extends vscode.Disposable { public name = '默认客户端'; private createTerminal(name: string) { + Client.terminalHistory[name] ??= []; this.terminal?.dispose(); this.terminal = new Terminal(name, async (data) => { // 如果提交的数据只有空格,就忽略掉 @@ -97,6 +103,7 @@ export class Client extends vscode.Disposable { this.notify('command', { data: data }); }); this.terminal.multiMode = this.multiMode; + this.terminal.setHistoryStack(Client.terminalHistory[this.name] ?? []); } readonly treeViewManager = new TreeViewManager(this); diff --git a/src/console/terminal.ts b/src/console/terminal.ts index 17c3069..54e64de 100644 --- a/src/console/terminal.ts +++ b/src/console/terminal.ts @@ -68,7 +68,7 @@ class Pseudoterminal implements vscode.Pseudoterminal { }); } - private historyStack: string[] = []; + public historyStack: string[] = []; private historyIndex: number = 0; private inputedBeforeHitEnter: string = ''; @@ -413,7 +413,7 @@ export class Terminal extends vscode.Disposable { }); this.updateStartSymbol(); this.terminal = vscode.window.createTerminal({ - name: `Y3控制台 - ${name}`, + name: `Y3: ${name}`, pty: this.pseudoterminal, }); this.terminal.show(); @@ -446,4 +446,12 @@ export class Terminal extends vscode.Disposable { enableInput() { this.pseudoterminal.enableInput(); } + + getHistoryStack() { + return this.pseudoterminal.historyStack; + } + + setHistoryStack(stack: string[]) { + this.pseudoterminal.historyStack = stack; + } }