Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 4 additions & 23 deletions src/System.Management.Automation/engine/InitialSessionState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4065,34 +4065,16 @@ internal void ImportCmdletsFromAssembly(Assembly assembly, PSModuleInfo module)
";

/// <summary>
/// This is the default function to use for clear-host. On Windows it rewrites the
/// host, and on Linux, it delegates to the native binary, 'clear'.
/// This is the default function to use for clear-host.
/// </summary>
internal static string GetClearHostFunctionText()
{
if (Platform.IsWindows)
{
return @"
$RawUI = $Host.UI.RawUI
$RawUI.CursorPosition = @{X=0;Y=0}
$RawUI.SetBufferContents(
@{Top = -1; Bottom = -1; Right = -1; Left = -1},
@{Character = ' '; ForegroundColor = $rawui.ForegroundColor; BackgroundColor = $rawui.BackgroundColor})
# .Link
# https://go.microsoft.com/fwlink/?LinkID=225747
# .ExternalHelp System.Management.Automation.dll-help.xml
";
}
else
{
// Porting note: non-Windows platforms use `clear`
return @"
& (Get-Command -CommandType Application clear | Select-Object -First 1).Definition
return @"
[Console]::Clear()
# .Link
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't going to work for non-console hosts like ISE, VSCode(?) and remoting. On those platforms, you still need to use the $RawUI portability APIs. A nice solution would be to actually add a new RawUI.Clear() API and then implement that using Console.Clear() in the console host but that may end up being a bunch of work...

# https://go.microsoft.com/fwlink/?LinkID=225747
# .ExternalHelp System.Management.Automation.dll-help.xml
";
}
}

/// <summary>
Expand Down Expand Up @@ -4536,6 +4518,7 @@ internal static SessionStateAliasEntry[] BuiltInAliases
#if !UNIX
// ac is a native command on macOS
new SessionStateAliasEntry("ac", "Add-Content", string.Empty, ReadOnly),
new SessionStateAliasEntry("clear", "Clear-Host"),
new SessionStateAliasEntry("compare", "Compare-Object", string.Empty, ReadOnly),
new SessionStateAliasEntry("cpp", "Copy-ItemProperty", string.Empty, ReadOnly),
new SessionStateAliasEntry("diff", "Compare-Object", string.Empty, ReadOnly),
Expand Down Expand Up @@ -4568,8 +4551,6 @@ internal static SessionStateAliasEntry[] BuiltInAliases
new SessionStateAliasEntry("kill", "Stop-Process"),
new SessionStateAliasEntry("pwd", "Get-Location"),
new SessionStateAliasEntry("type", "Get-Content"),
// Native commands we keep because the functions act correctly on Linux
new SessionStateAliasEntry("clear", "Clear-Host"),
// #if !CORECLR is used to disable aliases for cmdlets which are not available on OneCore or not appropriate for PSCore6 due to conflicts
#if !CORECLR
new SessionStateAliasEntry("gwmi", "Get-WmiObject", string.Empty, ReadOnly),
Expand Down
2 changes: 1 addition & 1 deletion test/powershell/engine/Basic/DefaultCommands.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Describe "Verify approved aliases list" -Tags "CI" {
"Alias", "CFS", "ConvertFrom-String", $($FullCLR ), "ReadOnly", "", ""
"Alias", "chdir", "Set-Location", $($FullCLR -or $CoreWindows -or $CoreUnix), "", "", ""
"Alias", "clc", "Clear-Content", $($FullCLR -or $CoreWindows -or $CoreUnix), "ReadOnly", "", ""
"Alias", "clear", "Clear-Host", $($FullCLR -or $CoreWindows -or $CoreUnix), "", "", ""
"Alias", "clear", "Clear-Host", $($FullCLR -or $CoreWindows ), "", "", ""
"Alias", "clhy", "Clear-History", $($FullCLR -or $CoreWindows -or $CoreUnix), "ReadOnly", "", ""
"Alias", "cli", "Clear-Item", $($FullCLR -or $CoreWindows -or $CoreUnix), "ReadOnly", "", ""
"Alias", "clp", "Clear-ItemProperty", $($FullCLR -or $CoreWindows -or $CoreUnix), "ReadOnly", "", ""
Expand Down