Profiler icon indicating copy to clipboard operation
Profiler copied to clipboard

Adding ANSI Support to File Properties

Open HCRitter opened this issue 1 year ago • 3 comments

Hi @nohwnd,

As we previously discussed, adding ANSI support to the file property would significantly enhance usability by allowing users to Ctrl+Click in the Windows Terminal to directly open files.

I propose using a format like the following:

"`e]8;;$($_.FullName)`e\$($_.Name)`e]8;;`e\"

I attempted to modify the format.ps1xml file to implement this, but I ran into some challenges, as I'm still new to that area.

I would appreciate any advice or suggestions on how to move forward with this enhancement.

Thank you!

HCRitter avatar Sep 25 '24 16:09 HCRitter

without testing it I think you need entry like this:

https://github.com/nohwnd/Profiler/blob/main/Profiler/Profiler.Format.ps1xml#L15

in here https://github.com/nohwnd/Profiler/blob/main/Profiler/Profiler.Format.ps1xml#L330

To show it in the selfDuration view, and similar change in all the other views.

@JustinGrote @fflaten any one of you has some experience with putting ansi into format files? I am especially interested in detecting if the console can handle ansi and not breaking the experience for people who don't use ansi enabled console. I know how to detect it (it's complicated), but I am not sure how to not repeat the check over and over. maybe static property on a class we export from Profiler?

nohwnd avatar Sep 26 '24 08:09 nohwnd

You can always just use a scriptblock to define a format property and it can call a static method in profiler for the implementation detail,.

JustinGrote avatar Sep 26 '24 14:09 JustinGrote

Formatting runs in global scope, so any public method/member should do. I'd avoid the ANSI-codes in the XML, if it even parses correctly.

As an alternative to Justin's helper-method suggestion, PowerShell uses a hidden code property like NameString for DirectoryInfo. Keeps format data clean and is testable which is nice.

Not sure how they hide it in Get-Member without -Force though as the TypeData says it's not hidden and I can't find the source.

PS /workspaces/Pester> (Get-TypeData System.IO.DirectoryInfo).Members.NameString | fl *                                                 

GetCodeReference : System.String NameString(System.Management.Automation.PSObject)
SetCodeReference : 
IsHidden         : False
Name             : NameString

fflaten avatar Oct 06 '24 12:10 fflaten