param([Parameter(Mandatory=$true)][string]$OutFile, [Parameter(Mandatory=$true)][string]$Work) $lines = New-Object System.Collections.Generic.List[string] function L($s) { $lines.Add($s); [System.IO.File]::WriteAllLines($OutFile, $lines, (New-Object System.Text.UTF8Encoding($false))) } L ("PSVersion: " + $PSVersionTable.PSVersion) $nstack = Join-Path $Work 'nstack111\lib\netstandard2.0\NStack.dll' $tg = Join-Path $Work 'tg115\lib\net472\Terminal.Gui.dll' Add-Type -Path $nstack -ErrorAction Stop Add-Type -Path $tg -ErrorAction Stop $asm = [AppDomain]::CurrentDomain.GetAssemblies() | Where-Object { $_.GetName().Name -eq 'Terminal.Gui' } | Select-Object -First 1 L "=== WHO implements IMainLoopDriver? ===" $mlT = $asm.GetType('Terminal.Gui.IMainLoopDriver') L (" IMainLoopDriver: " + [bool]$mlT + " members: " + (($mlT.GetMembers() | ForEach-Object { $_.Name }) -join ', ')) foreach ($t in $asm.GetTypes()) { if ($t.IsClass -and -not $t.IsAbstract -and $mlT.IsAssignableFrom($t)) { L (" IMPLEMENTOR: " + $t.FullName + " public ctor: " + [bool]($t.GetConstructor([Type[]]@()))) } } L "" L "=== also list Net* driver types ===" foreach ($t in ($asm.GetTypes() | Where-Object { $_.Name -like 'Net*' -or $_.Name -like '*MainLoop*' })) { L (" " + $t.FullName + " interfaces: " + (($t.GetInterfaces() | ForEach-Object { $_.Name }) -join ',')) } L "" L "=== ALL static Init/Run overloads on Application (exhaustive) ===" $appT = $asm.GetType('Terminal.Gui.Application') foreach ($m in ($appT.GetMethods([System.Reflection.BindingFlags]'Public,Static') | Where-Object { $_.Name -in @('Init','Run','Shutdown','Refresh','Begin','End','RunState') })) { L (" " + $m.ReturnType.Name + " " + $m.Name + "(" + (($m.GetParameters() | ForEach-Object { $_.ParameterType.Name + " " + $_.Name }) -join ', ') + ")") } L "" L "=== Application static PROPERTIES ===" foreach ($p in ($appT.GetProperties([System.Reflection.BindingFlags]'Public,Static'))) { L (" " + $p.PropertyType.Name + " " + $p.Name + " CanWrite=" + $p.CanWrite) } L "" L "=== does Terminal.Gui touch the console only at Init() time? test with redirected stdout ===" L (" IsOutputRedirected = " + [Console]::IsOutputRedirected) try { $drvT = $asm.GetType('Terminal.Gui.NetDriver') $loopT = $asm.GetTypes() | Where-Object { $_.FullName -and $mlT.IsAssignableFrom($_) -and -not $_.IsAbstract -and $_.IsClass } | Select-Object -First 1 L (" using driver=" + $drvT.FullName + " mainloop=" + $loopT.FullName) $initM = $appT.GetMethod('Init', [Type[]]@($drvT, $mlT)) $drv = [Activator]::CreateInstance($drvT) $loop = [Activator]::CreateInstance($loopT) $initM.Invoke($null, @($drv, $loop)) | Out-Null L " Application.Init(NetDriver, NetMainLoop) -> SUCCEEDED *** Terminal.Gui 1.15.0 is LIVE on PowerShell " + $PSVersionTable.PSVersion + " ***" $winT = $asm.GetType('Terminal.Gui.Window'); $lblT = $asm.GetType('Terminal.Gui.Label'); $btnT = $asm.GetType('Terminal.Gui.Button') $w = [Activator]::CreateInstance($winT, [object[]]@('BakNRet - Terminal.Gui on PowerShell ' + $PSVersionTable.PSVersion)) $l1 = [Activator]::CreateInstance($lblT, [object[]]@('Terminal.Gui 1.15.0 (net472) on ' + $(if ($PSVersionTable.PSEdition -eq 'Desktop') { '.NET Framework ' } else { '.NET ' }) + [System.Environment]::Version)) $l2 = [Activator]::CreateInstance($lblT, [object[]]@('CJK: 2 Chinese chars = 4 columns')) $b1 = [Activator]::CreateInstance($btnT, [object[]]@('OK')) $w.Add($l1); $w.Add($l2); $w.Add($b1) $w.X = 1; $w.Y = 1; $w.Width = 76; $w.Height = 8 $l1.Y = 1; $l2.Y = 3; $b1.Y = 5; $b1.X = 2 ($appT.GetProperty('TopLevel')).SetValue($null, $w) $w.SetFocus(); $w.Redraw($w.Bounds) $appT.GetMethod('Refresh', [Type[]]@()).Invoke($null, @()) | Out-Null L " painted Window(76x8) + 2 Labels + Button" Start-Sleep -Seconds 5 $appT.GetMethod('Shutdown', [Type[]]@()).Invoke($null, @()) | Out-Null L " Application.Shutdown() -> clean" L "RESULT: TerminalGui=WORKS" } catch { L (" FAILED: " + $_.Exception.GetType().Name + ': ' + $_.Exception.Message) $ie = $_.Exception.InnerException; while ($ie) { L (" inner: " + $ie.GetType().Name + ': ' + ($ie.Message -split "`n")[0]); $ie = $ie.InnerException } L "RESULT: TerminalGui=FAILED" }