mirror of
https://github.com/PowerShell/PowerShell.git
synced 2024-11-23 09:43:57 +08:00
Make experimental feature PSAnsiRenderingFileInfo
stable (#18042)
This commit is contained in:
parent
6744ffb826
commit
61b5dceb60
@ -1,5 +1,4 @@
|
||||
[
|
||||
"PSAnsiRenderingFileInfo",
|
||||
"PSCommandNotFoundSuggestion",
|
||||
"PSLoadAssemblyFromNativeCode",
|
||||
"PSNativeCommandErrorActionPreference",
|
||||
|
@ -1,5 +1,4 @@
|
||||
[
|
||||
"PSAnsiRenderingFileInfo",
|
||||
"PSCommandNotFoundSuggestion",
|
||||
"PSLoadAssemblyFromNativeCode",
|
||||
"PSNativeCommandErrorActionPreference",
|
||||
|
@ -114,9 +114,6 @@ namespace System.Management.Automation
|
||||
new ExperimentalFeature(
|
||||
name: "PSLoadAssemblyFromNativeCode",
|
||||
description: "Expose an API to allow assembly loading from native code"),
|
||||
new ExperimentalFeature(
|
||||
name: "PSAnsiRenderingFileInfo",
|
||||
description: "Enable coloring for FileInfo objects"),
|
||||
new ExperimentalFeature(
|
||||
name: PSNativeCommandErrorActionPreferenceFeatureName,
|
||||
description: "Native commands with non-zero exit codes issue errors according to $ErrorActionPreference when $PSNativeCommandUseErrorActionPreference is $true"),
|
||||
|
@ -2068,43 +2068,32 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <returns>Name if a file or directory, Name -> Target if symlink.</returns>
|
||||
public static string NameString(PSObject instance)
|
||||
{
|
||||
if (ExperimentalFeature.IsEnabled("PSAnsiRenderingFileInfo"))
|
||||
if (instance?.BaseObject is FileSystemInfo fileInfo)
|
||||
{
|
||||
if (instance?.BaseObject is FileSystemInfo fileInfo)
|
||||
if (InternalSymbolicLinkLinkCodeMethods.IsReparsePointLikeSymlink(fileInfo))
|
||||
{
|
||||
if (InternalSymbolicLinkLinkCodeMethods.IsReparsePointLikeSymlink(fileInfo))
|
||||
{
|
||||
return $"{PSStyle.Instance.FileInfo.SymbolicLink}{fileInfo.Name}{PSStyle.Instance.Reset} -> {fileInfo.LinkTarget}";
|
||||
}
|
||||
else if (fileInfo.Attributes.HasFlag(FileAttributes.Directory))
|
||||
{
|
||||
return $"{PSStyle.Instance.FileInfo.Directory}{fileInfo.Name}{PSStyle.Instance.Reset}";
|
||||
}
|
||||
else if (PSStyle.Instance.FileInfo.Extension.ContainsKey(fileInfo.Extension))
|
||||
{
|
||||
return $"{PSStyle.Instance.FileInfo.Extension[fileInfo.Extension]}{fileInfo.Name}{PSStyle.Instance.Reset}";
|
||||
}
|
||||
else if ((Platform.IsWindows && CommandDiscovery.PathExtensions.Contains(fileInfo.Extension.ToLower())) ||
|
||||
(!Platform.IsWindows && Platform.NonWindowsIsExecutable(fileInfo.FullName)))
|
||||
{
|
||||
return $"{PSStyle.Instance.FileInfo.Executable}{fileInfo.Name}{PSStyle.Instance.Reset}";
|
||||
}
|
||||
else
|
||||
{
|
||||
return fileInfo.Name;
|
||||
}
|
||||
return $"{PSStyle.Instance.FileInfo.SymbolicLink}{fileInfo.Name}{PSStyle.Instance.Reset} -> {fileInfo.LinkTarget}";
|
||||
}
|
||||
else if (fileInfo.Attributes.HasFlag(FileAttributes.Directory))
|
||||
{
|
||||
return $"{PSStyle.Instance.FileInfo.Directory}{fileInfo.Name}{PSStyle.Instance.Reset}";
|
||||
}
|
||||
else if (PSStyle.Instance.FileInfo.Extension.ContainsKey(fileInfo.Extension))
|
||||
{
|
||||
return $"{PSStyle.Instance.FileInfo.Extension[fileInfo.Extension]}{fileInfo.Name}{PSStyle.Instance.Reset}";
|
||||
}
|
||||
else if ((Platform.IsWindows && CommandDiscovery.PathExtensions.Contains(fileInfo.Extension.ToLower())) ||
|
||||
(!Platform.IsWindows && Platform.NonWindowsIsExecutable(fileInfo.FullName)))
|
||||
{
|
||||
return $"{PSStyle.Instance.FileInfo.Executable}{fileInfo.Name}{PSStyle.Instance.Reset}";
|
||||
}
|
||||
else
|
||||
{
|
||||
return fileInfo.Name;
|
||||
}
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
return instance?.BaseObject is FileSystemInfo fileInfo
|
||||
? InternalSymbolicLinkLinkCodeMethods.IsReparsePointLikeSymlink(fileInfo)
|
||||
? $"{fileInfo.Name} -> {fileInfo.LinkTarget}"
|
||||
: fileInfo.Name
|
||||
: string.Empty;
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -208,17 +208,12 @@ Describe "Get-Item environment provider on Windows with accidental case-variant
|
||||
|
||||
Describe 'Formatting for FileInfo objects' -Tags 'CI' {
|
||||
BeforeAll {
|
||||
$PSDefaultParameterValues.Add('It:Skip', (-not $EnabledExperimentalFeatures.Contains('PSAnsiRenderingFileInfo')))
|
||||
$extensionTests = [System.Collections.Generic.List[HashTable]]::new()
|
||||
foreach ($extension in @('.zip', '.tgz', '.tar', '.gz', '.nupkg', '.cab', '.7z', '.ps1', '.psd1', '.psm1', '.ps1xml')) {
|
||||
$extensionTests.Add(@{extension = $extension})
|
||||
}
|
||||
}
|
||||
|
||||
AfterAll {
|
||||
$PSDefaultParameterValues.Remove('It:Skip')
|
||||
}
|
||||
|
||||
It 'File type <extension> should have correct color' -TestCases $extensionTests {
|
||||
param($extension)
|
||||
|
||||
@ -250,14 +245,6 @@ Describe 'Formatting for FileInfo objects' -Tags 'CI' {
|
||||
}
|
||||
|
||||
Describe 'Formatting for FileInfo requiring admin' -Tags 'CI','RequireAdminOnWindows' {
|
||||
BeforeAll {
|
||||
$PSDefaultParameterValues.Add('It:Skip', (-not $EnabledExperimentalFeatures.Contains('PSAnsiRenderingFileInfo')))
|
||||
}
|
||||
|
||||
AfterAll {
|
||||
$PSDefaultParameterValues.Remove('It:Skip')
|
||||
}
|
||||
|
||||
It 'Symlink should have correct color' {
|
||||
$linkPath = Join-Path -Path $TestDrive -ChildPath 'link'
|
||||
$link = New-Item -ItemType SymbolicLink -Name 'link' -Value $TestDrive -Path $TestDrive
|
||||
|
Loading…
Reference in New Issue
Block a user