1
Vote

Show-Tree: allow non-ASCII mode on other codepages

description

I am on a German Windows installation and no matter what I do (useAsciiArt on or off), I always get ASCII art output like
|--CHANGELOG.md
|--ender.js
|--LICENSE
|--moment.js
|--package.js
|--package.json
\--README.md
I found the culprit in src\Pscx\Modules\Utility\Pscx.Utility.psm1, line 1719:
$asciiChars = @{
    EndCap        = '\'
    Junction      = '|'
    HorizontalBar = '-'
    VerticalBar   = '|'
}

$cp437Chars = @{
    EndCap        = '└'
    Junction      = '├'
    HorizontalBar = '─'
    VerticalBar   = '│'
}

if (($Host.CurrentCulture.TextInfo.OEMCodePage -eq 437) -and !$UseAsciiLineArt) # here
{
    $lineChars = $cp437Chars
}
else
{
    $lineChars = $asciiChars
}
My value of $Host.CurrentCulture.TextInfo.OEMCodePage is 840 (not 437), but the old MS-DOS tree command works perfectly. Please remove this restriction or at least allow to override it.

comments

r_keith_hill wrote Jan 13, 2016 at 3:51 AM

We could add a parameter to the command that takes a hashtable of chars.
Show-Tree -LineChars @{EndCap='';Junction='';HorizontalBar='';VerticalBar=''}
But it would suck to have to provide that parameter every time you invoke the command.

We could add a preference variable for ShowTree where you would specify this once in your profile e.g.:
$pscx:preferences['Show-Tree-LineChars'] = @{EndCap='';Junction='';HorizontalBar='';VerticalBar=''}
Then the above set of line chars would get used for every invocation of Show-Tree there-after.

I hestitate trying to tackle getting the correct line chars for every possible code-page. I can't even chcp to 840 on my dev PC to test.

Thoughts?

wrote Jan 13, 2016 at 3:53 AM

felixfbecker wrote Jan 13, 2016 at 1:38 PM

But why is it working with the old DOS tree command without any problems?

r_keith_hill wrote Jan 13, 2016 at 6:01 PM

But why is it working with the old DOS tree command without any problems?
I don't know. I don't work for Microsoft and don't have access to that code. I suspect they pick suitable chars for the each codepage. Or maybe they're using Unicode chars (I'll look into that).

If it winds up being a different set of chars per codepage then perhaps we make that preference setting a hashtable of hashtables where the outer key is the codepage number. If you could provide me with the appropriate values for codpage 840, I could prepopulate the table with those values (and add to it over time).

felixfbecker wrote Jan 15, 2016 at 7:39 AM

How can I find those out?

r_keith_hill wrote Jan 15, 2016 at 6:08 PM

Find a small folder structure but something with at least one subdir with contents and run
tree c:\small_folder /f | pscx\format-hex
That will show the codes for the characters or if the output isn't too big, paste it here.

r_keith_hill wrote Jan 15, 2016 at 6:19 PM

Need to tweak that command to handle Unicode chars:
tree c:\small_folder /f | pscx\format-hex -encoding Unicode

felixfbecker wrote Jan 15, 2016 at 6:54 PM

Ascii output
$ tree . /f
Auflistung der Ordnerpfade
Volumeseriennummer : 2A81-ACF0
C:\USERS\FELIX\DESKTOP\TEST
├───test
│       testfile.txt
│       testfile2.txt
│
└───test2
    │   testfile3.txt
    │
    └───test3
            testfile3.txt
Hex
$ tree . /f | pscx\format-hex

Address:  0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F ASCII
-------- ----------------------------------------------- ----------------
00000000 41 00 75 00 66 00 6C 00 69 00 73 00 74 00 75 00 A.u.f.l.i.s.t.u.
00000010 6E 00 67 00 20 00 64 00 65 00 72 00 20 00 4F 00 n.g. .d.e.r. .O.
00000020 72 00 64 00 6E 00 65 00 72 00 70 00 66 00 61 00 r.d.n.e.r.p.f.a.
00000030 64 00 65 00 56 00 6F 00 6C 00 75 00 6D 00 65 00 d.e.V.o.l.u.m.e.
00000040 73 00 65 00 72 00 69 00 65 00 6E 00 6E 00 75 00 s.e.r.i.e.n.n.u.
00000050 6D 00 6D 00 65 00 72 00 20 00 3A 00 20 00 32 00 m.m.e.r. .:. .2.
00000060 41 00 38 00 31 00 2D 00 41 00 43 00 46 00 30 00 A.8.1.-.A.C.F.0.
00000070 43 00 3A 00 5C 00 55 00 53 00 45 00 52 00 53 00 C.:.\.U.S.E.R.S.
00000080 5C 00 46 00 45 00 4C 00 49 00 58 00 5C 00 44 00 \.F.E.L.I.X.\.D.
00000090 45 00 53 00 4B 00 54 00 4F 00 50 00 5C 00 54 00 E.S.K.T.O.P.\.T.
000000A0 45 00 53 00 54 00 1C 25 00 25 00 25 00 25 74 00 E.S.T..%.%.%.%t.
000000B0 65 00 73 00 74 00 02 25 20 00 20 00 20 00 20 00 e.s.t..% . . . .
000000C0 20 00 20 00 20 00 74 00 65 00 73 00 74 00 66 00  . . .t.e.s.t.f.
000000D0 69 00 6C 00 65 00 2E 00 74 00 78 00 74 00 02 25 i.l.e...t.x.t..%
000000E0 20 00 20 00 20 00 20 00 20 00 20 00 20 00 74 00  . . . . . . .t.
000000F0 65 00 73 00 74 00 66 00 69 00 6C 00 65 00 32 00 e.s.t.f.i.l.e.2.
00000100 2E 00 74 00 78 00 74 00 02 25 20 00 20 00 20 00 ..t.x.t..% . . .
00000110 20 00 20 00 20 00 20 00 14 25 00 25 00 25 00 25  . . . ..%.%.%.%
00000120 74 00 65 00 73 00 74 00 32 00 20 00 20 00 20 00 t.e.s.t.2. . . .
00000130 20 00 02 25 20 00 20 00 20 00 74 00 65 00 73 00  ..% . . .t.e.s.
00000140 74 00 66 00 69 00 6C 00 65 00 33 00 2E 00 74 00 t.f.i.l.e.3...t.
00000150 78 00 74 00 20 00 20 00 20 00 20 00 02 25 20 00 x.t. . . . ..% .
00000160 20 00 20 00 20 00 20 00 20 00 20 00 14 25 00 25  . . . . . ..%.%
00000170 00 25 00 25 74 00 65 00 73 00 74 00 33 00 20 00 .%.%t.e.s.t.3. .
00000180 20 00 20 00 20 00 20 00 20 00 20 00 20 00 20 00  . . . . . . . .
00000190 20 00 20 00 20 00 74 00 65 00 73 00 74 00 66 00  . . .t.e.s.t.f.
000001A0 69 00 6C 00 65 00 33 00 2E 00 74 00 78 00 74 00 i.l.e.3...t.x.t.
000001B0 20 00 20 00 20 00 20 00 20 00 20 00 20 00 20 00  . . . . . . . .
000001C0 20 00 20 00 20 00 20 00                          . . . .

r_keith_hill wrote Jan 15, 2016 at 8:26 PM

OK tree.com is using the same Unicode chars that I'm using in cp437chars. Can you try modifying lines 1705 to 1726 in {pscxInstallDir}/Modules\Utility\Pscx.Utility.psm1 to this:
        $asciiChars = @{
            EndCap        = '\'
            Junction      = '|'
            HorizontalBar = '-'
            VerticalBar   = '|'
        }
        
        $unicodeChars = @{
            EndCap        = '└'
            Junction      = '├'
            HorizontalBar = '─'
            VerticalBar   = '│'
        }
        
        if ($UseAsciiLineArt)
        {
            $lineChars = $asciiChars
        }
        else
        {
            $lineChars = $unicodeChars
        }
You will need to remove the signature block at the bottom of this file since the contents have been modified or it won't load. Does Show-Tree work as you would expect it now?

felixfbecker wrote Jan 17, 2016 at 6:04 PM

Works perfectly!

r_keith_hill wrote Jan 17, 2016 at 6:27 PM

Thanks. I'll make that change and push out an update on the PowerShell Gallery in a week or so. I have some other changes I need to finish up first.