Skip to content

Commit

Permalink
Handle clearTerminal message by using vscode clear command (#2316)
Browse files Browse the repository at this point in the history
* handle clearTerminal message by using vscode clear command

* Codacy

* changed name of setting

* delete comment
  • Loading branch information
TylerLeonhardt authored Nov 27, 2019
1 parent dba7d83 commit fb59b37
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,10 @@
"default": false,
"description": "Falls back to the legacy (lightweight) ReadLine experience. This will disable the use of PSReadLine in the PowerShell Integrated Console."
},
"powershell.integratedConsole.forceClearScrollbackBuffer": {
"type": "boolean",
"description": "Use the vscode API to clear the terminal since that's the only reliable way to clear the scrollback buffer. Turn this on if you're use to 'Clear-Host' clearing scroll history as wellclear-terminal-via-lsp."
},
"powershell.debugging.createTemporaryIntegratedConsole": {
"type": "boolean",
"default": false,
Expand Down
17 changes: 16 additions & 1 deletion src/features/ExtensionCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import * as fs from "fs";
import * as os from "os";
import * as path from "path";
import * as vscode from "vscode";
import { LanguageClient, NotificationType, Position, Range, RequestType } from "vscode-languageclient";
import { LanguageClient, NotificationType, NotificationType0,
Position, Range, RequestType } from "vscode-languageclient";
import { IFeature } from "../feature";
import { Logger } from "../logging";
import Settings = require("../settings");

export interface IExtensionCommand {
name: string;
Expand Down Expand Up @@ -155,6 +157,9 @@ export const SetStatusBarMessageRequestType =
new RequestType<IStatusBarMessageDetails, EditorOperationResponse, void, void>(
"editor/setStatusBarMessage");

export const ClearTerminalNotificationType =
new NotificationType0("editor/clearTerminal");

export interface ISaveFileDetails {
filePath: string;
newPath?: string;
Expand Down Expand Up @@ -265,6 +270,16 @@ export class ExtensionCommandsFeature implements IFeature {
this.languageClient.onRequest(
SetStatusBarMessageRequestType,
(messageDetails) => this.setStatusBarMessage(messageDetails));

this.languageClient.onNotification(
ClearTerminalNotificationType,
() => {
// We check to see if they have TrueClear on. If not, no-op because the
// overriden Clear-Host already calls [System.Console]::Clear()
if (Settings.load().integratedConsole.forceClearScrollbackBuffer) {
vscode.commands.executeCommand("workbench.action.terminal.clear");
}
});
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export interface IIntegratedConsoleSettings {
showOnStartup?: boolean;
focusConsoleOnExecute?: boolean;
useLegacyReadLine?: boolean;
forceClearScrollbackBuffer?: boolean;
}

export function load(): ISettings {
Expand Down Expand Up @@ -154,6 +155,7 @@ export function load(): ISettings {
showOnStartup: true,
focusConsoleOnExecute: true,
useLegacyReadLine: false,
forceClearScrollbackBuffer: false,
};

return {
Expand Down

0 comments on commit fb59b37

Please sign in to comment.