Skip to content

Commit

Permalink
记忆上个控制台的输入历史
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Sep 27, 2024
1 parent b436b5d commit 215fd29
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/console/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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) => {
// 如果提交的数据只有空格,就忽略掉
Expand All @@ -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);
Expand Down
12 changes: 10 additions & 2 deletions src/console/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Pseudoterminal implements vscode.Pseudoterminal {
});
}

private historyStack: string[] = [];
public historyStack: string[] = [];
private historyIndex: number = 0;
private inputedBeforeHitEnter: string = '';

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 215fd29

Please sign in to comment.