param([Parameter(Mandatory=$true)][string]$OutFile, [Parameter(Mandatory=$true)][string]$Work, [int]$HoldSeconds = 6) $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))) } function Asm([string]$n) { return [AppDomain]::CurrentDomain.GetAssemblies() | Where-Object { $_.GetName().Name -eq $n } | Select-Object -First 1 } L ("PSVersion: " + $PSVersionTable.PSVersion) try { Add-Type -Path (Join-Path $Work 'nstack111\lib\netstandard2.0\NStack.dll') -ErrorAction Stop Add-Type -Path (Join-Path $Work 'tg115\lib\net472\Terminal.Gui.dll') -ErrorAction Stop $tgAsm = Asm 'Terminal.Gui' $usT = (Asm 'NStack').GetType('NStack.ustring') L (" NStack.ustring type: " + [bool]$usT) $winT = $tgAsm.GetType('Terminal.Gui.Window') L " Window constructors:" foreach ($c in $winT.GetConstructors()) { L (" (" + (($c.GetParameters() | ForEach-Object { $_.ParameterType.Name + ' ' + $_.Name }) -join ', ') + ")") } L " Note: title parameters are NStack.ustring, not System.String -> PowerShell cannot bind a string literal." # convert $implicit = $usT.GetMethod('op_Implicit', [Type[]]@([string])) L (" ustring implicit conversion from string: " + [bool]$implicit) $us = $implicit.Invoke($null, @('BakNRet - Terminal.Gui')) L (" converted title object: " + $us.GetType().FullName) $appT = $tgAsm.GetType('Terminal.Gui.Application') $drvT = $tgAsm.GetType('Terminal.Gui.NetDriver') $mlT = $tgAsm.GetType('Terminal.Gui.IMainLoopDriver') $loopT = $tgAsm.GetType('Terminal.Gui.NetMainLoop') $drv = [Activator]::CreateInstance($drvT) $ctor = $loopT.GetConstructors([System.Reflection.BindingFlags]'Public,NonPublic,Instance') | Select-Object -First 1 $loop = $ctor.Invoke(@($drv)) $appT.GetMethod('Init', [Type[]]@($drvT, $mlT)).Invoke($null, @($drv, $loop)) | Out-Null L " Application.Init -> OK" $lblT = $tgAsm.GetType('Terminal.Gui.Label'); $btnT = $tgAsm.GetType('Terminal.Gui.Button') $w = [Activator]::CreateInstance($winT, [object[]]@($us)) L (" Window created with ustring title: " + ($w.GetType().FullName)) # Labels also take ustring; use implicit conversion $l1 = [Activator]::CreateInstance($lblT, [object[]]@($implicit.Invoke($null, @('Terminal.Gui 1.15.0 / Label via ustring conversion')))) $l2 = [Activator]::CreateInstance($lblT, [object[]]@($implicit.Invoke($null, @('CJK cell test: 2 CJK chars -> 4 columns')))) $b1 = [Activator]::CreateInstance($btnT, [object[]]@($implicit.Invoke($null, @('OK')))) $w.Add($l1); $w.Add($l2); $w.Add($b1) $w.X = 1; $w.Y = 1; $w.Width = 78; $w.Height = 9 $l1.Y = 1; $l2.Y = 3 $b1.Y = 5; $b1.X = 2 $appT.GetProperty('Top').SetValue($null, $w) $appT.GetProperty('Current').SetValue($null, $w) $w.SetFocus(); $w.Redraw($w.Bounds) $appT.GetMethod('Refresh', [Type[]]@()).Invoke($null, @()) | Out-Null L " *** FULLY WORKING Terminal.Gui TUI painted: Window(78x9) + 2 Labels + Button ***" L "RESULT: TerminalGui=FULL-WIN via reflection + ustring conversion" Write-Host "" Write-Host (" ===== Terminal.Gui 1.15.0 live on PowerShell $($PSVersionTable.PSVersion) =====") -ForegroundColor Cyan Start-Sleep -Seconds $HoldSeconds $appT.GetMethod('Shutdown', [Type[]]@()).Invoke($null, @()) | Out-Null L " Shutdown clean" } 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" } if (-not [Console]::IsOutputRedirected) { Start-Sleep -Seconds 2 }