KirkMunro / FormatPx

Better Formatting in PowerShell
Apache License 2.0
73 stars 5 forks source link

__FormatData property shows up in unexpected places in 1.0.1.2 and earlier #3

Closed KirkMunro closed 9 years ago

KirkMunro commented 9 years ago

Reported from direct email:

When using this Get-Phonetic function, __FormatData is outputted:

PS [4]: 'jOIHU56%%3##kdj?=4/' | Get-Phonetic

Input text: jOIHU56%%3##kdj?=4/

                          Char Phonetic                           __FormatData                    
                          ---- --------                           ------------                    
                             j juliett                            {FormatPx.FormatRecord}         
                             O OSCAR                              {FormatPx.FormatRecord}         
                             I INDIA                              {FormatPx.FormatRecord}         
                             H HOTEL                              {FormatPx.FormatRecord}         
                             U UNIFORM                            {FormatPx.FormatRecord}         
                             5 five                               {FormatPx.FormatRecord}         
                             6 six                                {FormatPx.FormatRecord}         
                             % %                                  {FormatPx.FormatRecord}         
                             % %                                  {FormatPx.FormatRecord}         
                             3 three                              {FormatPx.FormatRecord}         
                             # #                                  {FormatPx.FormatRecord}         
                             # #                                  {FormatPx.FormatRecord}         
                             k kilo                               {FormatPx.FormatRecord}         
                             d delta                              {FormatPx.FormatRecord}         
                             j juliett                            {FormatPx.FormatRecord}          
                             ? questionmark                       {FormatPx.FormatRecord}         
                             = =                                  {FormatPx.FormatRecord}         
                             4 four                               {FormatPx.FormatRecord}         
                             / /                                  {FormatPx.FormatRecord}   

Expected or bug?

KirkMunro commented 9 years ago

This was a bug (a shortcoming really) in the original design. I was adding a __FormatData PSNoteProperty to the objects that were being output, and that property would appear in several situations, one of which is when you have an object without a default display property set that you pass to ft -auto. For example, a simple test is this:

$x = [pscustomobject]@{one=1;two=2} $x | ft -auto

The second command would output a table with properties one, two, and FormatData. This is undesirable so I went poking around and found out that properties of type PSNoteProperty can be hidden from the output when using an internal field, so I updated how FormatData is created/added to the objects that go through FormatPx so that FormatData is automatically hidden. The end result is that the formatting information is hidden from the property output when using a Format-* command as well as from Get-Member output. The property is still there though, and you can see it in .PSObject.Properties['FormatData']. This is a nicer solution, so I released this in a new build. Update to version 1.0.2.3 or later to get this fix.