Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding ANSI Support to File Properties #70

Open
HCRitter opened this issue Sep 25, 2024 · 3 comments
Open

Adding ANSI Support to File Properties #70

HCRitter opened this issue Sep 25, 2024 · 3 comments

Comments

@HCRitter
Copy link

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!

@nohwnd
Copy link
Owner

nohwnd commented Sep 26, 2024

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?

@JustinGrote
Copy link

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,.

@fflaten
Copy link
Contributor

fflaten commented Oct 6, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants