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; + } }