diff --git a/module/PowerShellEditorServices/Commands/PowerShellEditorServices.Commands.psd1 b/module/PowerShellEditorServices/Commands/PowerShellEditorServices.Commands.psd1
index da611b92f..f46db0773 100644
--- a/module/PowerShellEditorServices/Commands/PowerShellEditorServices.Commands.psd1
+++ b/module/PowerShellEditorServices/Commands/PowerShellEditorServices.Commands.psd1
@@ -78,7 +78,8 @@ FunctionsToExport = @('Register-EditorCommand',
'Join-ScriptExtent',
'Test-ScriptExtent',
'Open-EditorFile',
- 'New-EditorFile')
+ 'New-EditorFile',
+ 'Clear-Host')
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
CmdletsToExport = @()
@@ -87,7 +88,7 @@ CmdletsToExport = @()
VariablesToExport = @()
# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
-AliasesToExport = @('psedit')
+AliasesToExport = @('psedit', 'cls', 'clear')
# DSC resources to export from this module
# DscResourcesToExport = @()
diff --git a/module/PowerShellEditorServices/Commands/Public/Clear-Host.ps1 b/module/PowerShellEditorServices/Commands/Public/Clear-Host.ps1
new file mode 100644
index 000000000..ffc5ac726
--- /dev/null
+++ b/module/PowerShellEditorServices/Commands/Public/Clear-Host.ps1
@@ -0,0 +1,24 @@
+#
+# Copyright (c) Microsoft. All rights reserved.
+# Licensed under the MIT license. See LICENSE file in the project root for full license information.
+#
+
+Microsoft.PowerShell.Management\Get-Item function:Clear-Host | Microsoft.PowerShell.Management\Set-Item function:__clearhost
+
+function Clear-Host {
+ [Alias('cls')]
+ param(
+ [Parameter()]
+ [switch]
+ $All
+ )
+
+ __clearhost
+ if ($All.IsPresent) {
+ $psEditor.Window.Terminal.Clear()
+ }
+}
+
+if (!$IsMacOS -and !$IsLinux) {
+ Set-Alias clear Clear-Host
+}
diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/EditorOperationsService.cs b/src/PowerShellEditorServices/Services/PowerShellContext/EditorOperationsService.cs
index 1d6ddd247..eeac33c5c 100644
--- a/src/PowerShellEditorServices/Services/PowerShellContext/EditorOperationsService.cs
+++ b/src/PowerShellEditorServices/Services/PowerShellContext/EditorOperationsService.cs
@@ -179,5 +179,10 @@ public async Task SetStatusBarMessageAsync(string message, int? timeout)
Timeout = timeout
});
}
+
+ public void ClearTerminal()
+ {
+ _languageServer.SendNotification("editor/clearTerminal");
+ }
}
}
diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Extensions/EditorTerminal.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Extensions/EditorTerminal.cs
new file mode 100644
index 000000000..a6fb52ed2
--- /dev/null
+++ b/src/PowerShellEditorServices/Services/PowerShellContext/Extensions/EditorTerminal.cs
@@ -0,0 +1,45 @@
+//
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+//
+
+namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext
+{
+ ///
+ /// Provides a PowerShell-facing API which allows scripts to
+ /// interact with the editor's terminal.
+ ///
+ public class EditorTerminal
+ {
+ #region Private Fields
+
+ private readonly IEditorOperations editorOperations;
+
+ #endregion
+
+ #region Constructors
+
+ ///
+ /// Creates a new instance of the EditorTerminal class.
+ ///
+ /// An IEditorOperations implementation which handles operations in the host editor.
+ internal EditorTerminal(IEditorOperations editorOperations)
+ {
+ this.editorOperations = editorOperations;
+ }
+
+ #endregion
+
+ #region Public Methods
+
+ ///
+ /// Triggers to the editor to clear the terminal.
+ ///
+ public void Clear()
+ {
+ this.editorOperations.ClearTerminal();
+ }
+
+ #endregion
+ }
+}
diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Extensions/EditorWindow.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Extensions/EditorWindow.cs
index f21a574ea..cf580b961 100644
--- a/src/PowerShellEditorServices/Services/PowerShellContext/Extensions/EditorWindow.cs
+++ b/src/PowerShellEditorServices/Services/PowerShellContext/Extensions/EditorWindow.cs
@@ -13,7 +13,16 @@ public class EditorWindow
{
#region Private Fields
- private IEditorOperations editorOperations;
+ private readonly IEditorOperations editorOperations;
+
+ #endregion
+
+ #region Public Properties
+
+ ///
+ /// Gets the terminal interface for the editor API.
+ ///
+ public EditorTerminal Terminal { get; private set; }
#endregion
@@ -26,6 +35,7 @@ public class EditorWindow
internal EditorWindow(IEditorOperations editorOperations)
{
this.editorOperations = editorOperations;
+ this.Terminal = new EditorTerminal(editorOperations);
}
#endregion
diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Extensions/IEditorOperations.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Extensions/IEditorOperations.cs
index 15a167203..ccc41e949 100644
--- a/src/PowerShellEditorServices/Services/PowerShellContext/Extensions/IEditorOperations.cs
+++ b/src/PowerShellEditorServices/Services/PowerShellContext/Extensions/IEditorOperations.cs
@@ -124,5 +124,10 @@ public interface IEditorOperations
/// If non-null, a timeout in milliseconds for how long the message should remain visible.
/// A Task that can be tracked for completion.
Task SetStatusBarMessageAsync(string message, int? timeout);
+
+ ///
+ /// Triggers to the editor to clear the terminal.
+ ///
+ void ClearTerminal();
}
}