MSInfo32TUI.ps1
|
<#PSScriptInfo .VERSION 1.0.5 .GUID 2e7a1b5d-ef3a-4db5-9e6b-0cf231ab42a3 .AUTHOR Robert .COMPANYNAME OAOA-DEV .COPYRIGHT .TAGS Big TUI Tools PowerShellToolkit .LICENSEURI .PROJECTURI https://oaoa.dev/tools .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDMODULES .EXTERNALSCRIPTDEPENDENCIES .RELEASENOTES .PRIVATEDATA .DESCRIPTION A console TUI application for Windows System Information (MSInfo32). #> <# .SYNOPSIS Provides a text user interface (TUI) inside the PowerShell console to view hardware resources, components, and software environment. .DESCRIPTION A console TUI application for Windows System Information (MSInfo32). .PARAMETER None .EXAMPLE MSInfo32TUI #> # --- TUI LAYOUT ENGINE MODULE FUNCTIONS --- # Generic Reusable PowerShell Console TUI Library # Author: Antigravity $ESC = [char]27 # Global Layout Variables (defaults, dynamically updated on resize) $global:leftWidth = 35 # mainHeight will be dynamically updated $global:mainHeight = 25 # ANSI Color Utilities function Get-ANSIColor($name) { switch ($name) { 'Reset' { "$ESC[0m" } 'Bold' { "$ESC[1m" } 'Inverse' { "$ESC[7m" } 'SelectedActive' { "$ESC[37;44m" } # White on Blue 'SelectedInactive' { "$ESC[37;100m" } # White on Dark Gray 'Error' { "$ESC[91m" } # Bright Red 'Warning' { "$ESC[93m" } # Bright Yellow 'Info' { "$ESC[92m" } # Bright Green 'Gray' { "$ESC[90m" } # Dark Gray 'White' { "$ESC[97m" } # White 'Cyan' { "$ESC[96m" } # Cyan 'Blue' { "$ESC[94m" } # Blue 'Header' { "$ESC[30;47m" } # Black on Light Gray 'ErrorRow' { "$ESC[37;41m" } # White on Red background 'WarningRow' { "$ESC[30;43m" } # Black on Yellow background 'GreenRow' { "$ESC[32m" } # Green text default { "$ESC[0m" } } } # Position the cursor function Set-Cursor($x, $y) { [Console]::SetCursorPosition($x, $y) } # Write text at specific coordinates function Write-At($x, $y, $text, $colorName = 'Reset') { $color = Get-ANSIColor $colorName $reset = Get-ANSIColor 'Reset' Set-Cursor $x $y [Console]::Write("$color$text$reset") } # Initialize console settings for TUI function Initialize-Console { $global:originalCursorVisible = [Console]::CursorVisible $global:originalOutputEncoding = [Console]::OutputEncoding [Console]::CursorVisible = $false [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 # Enter Alternate Screen Buffer to preserve user scrollback [Console]::Write("$ESC[?1049h") [Console]::Write("$ESC[?25l") # ANSI Hide Cursor [Console]::Write("$ESC[2J") # Clear entire screen } # Restore original console settings on exit function Restore-Console { # Exit Alternate Screen Buffer [Console]::Write("$ESC[?1049l") [Console]::Write("$ESC[?25h") # ANSI Show Cursor [Console]::CursorVisible = $global:originalCursorVisible [Console]::OutputEncoding = $global:originalOutputEncoding } # Generic Borders Drawing function Draw-Borders { param( [int]$Width, [int]$Height, [int]$LeftWidth, [int]$MainHeight, [int]$FocusArea, [string]$LeftTitle = "", [string]$RightTopTitle = "", [string]$RightBottomTitle = "", [bool]$HasVerticalDivider = $true, [bool]$HasHorizontalDivider = $true, [double]$RightTopWidthPercent = 1.0 ) $rightWidth = $Width - $LeftWidth - 3 # 1. Draw top border $topBorder = "┌" + ("─" * $LeftWidth) + $(if ($HasVerticalDivider) { "┬" } else { "─" }) + ("─" * $rightWidth) + "┐" Write-At 0 1 $topBorder 'Gray' # 2. Draw middle lines for ($y = 2; $y -le ($Height - 3); $y++) { Write-At 0 $y "│" 'Gray' if ($HasVerticalDivider) { Write-At ($LeftWidth + 1) $y "│" 'Gray' } Write-At ($Width - 1) $y "│" 'Gray' } # 3. Draw horizontal divider between Table and Details (right side only, if exists) if ($HasHorizontalDivider) { $dividerStart = if ($HasVerticalDivider) { $LeftWidth + 1 } else { 0 } $rightDivider = $(if ($HasVerticalDivider) { "├" } else { "│" }) + ("─" * $rightWidth) + "┤" Write-At $dividerStart ($MainHeight + 1) $rightDivider 'Gray' } # 4. Draw bottom border $bottomBorder = "└" + ("─" * $LeftWidth) + $(if ($HasVerticalDivider) { "┴" } else { "─" }) + ("─" * $rightWidth) + "┘" Write-At 0 ($Height - 2) $bottomBorder 'Gray' # 5. Draw secondary vertical divider if RightTopWidthPercent is < 1.0 (for Resource Monitor graph) if ($HasVerticalDivider -and $RightTopWidthPercent -lt 1.0 -and $RightTopWidthPercent -gt 0.0) { $listWidth = [int]($rightWidth * $RightTopWidthPercent) $dividerX = $LeftWidth + 2 + $listWidth for ($y = 2; $y -le $MainHeight; $y++) { Write-At $dividerX $y "│" 'Gray' } Write-At $dividerX 1 "┬" 'Gray' if ($HasHorizontalDivider) { Write-At $dividerX ($MainHeight + 1) "┴" 'Gray' } } # 6. Draw highlighted titles to indicate focus if ($LeftTitle) { $lTitleText = if ($FocusArea -eq 0) { "● $LeftTitle ●" } else { " $LeftTitle " } $lTitleX = [int](($LeftWidth - $lTitleText.Length) / 2) + 1 $lColor = if ($FocusArea -eq 0) { 'SelectedActive' } else { 'Header' } Write-At $lTitleX 1 $lTitleText $lColor } if ($RightTopTitle) { $rtTitleText = if ($FocusArea -eq 1) { "● $RightTopTitle ●" } else { " $RightTopTitle " } $rtWidth = if ($RightTopWidthPercent -lt 1.0) { [int]($rightWidth * $RightTopWidthPercent) } else { $rightWidth } $rtTitleX = $LeftWidth + 2 + [int](($rtWidth - $rtTitleText.Length) / 2) $rtColor = if ($FocusArea -eq 1) { 'SelectedActive' } else { 'Header' } Write-At $rtTitleX 1 $rtTitleText $rtColor } if ($RightBottomTitle -and $HasHorizontalDivider) { $rbTitleText = if ($FocusArea -eq 2) { "● $RightBottomTitle ●" } else { " $RightBottomTitle " } $rbTitleX = $LeftWidth + 2 + [int](($rightWidth - $rbTitleText.Length) / 2) $rbColor = if ($FocusArea -eq 2) { 'SelectedActive' } else { 'Header' } Write-At $rbTitleX ($MainHeight + 1) $rbTitleText $rbColor } } # Generic Menu Bar Drawing function Draw-Menu { param( [int]$Width, [string[]]$Items ) $menuColor = Get-ANSIColor 'Header' $reset = Get-ANSIColor 'Reset' $menuText = " " + ($Items -join " ") $paddedMenu = $menuText.PadRight($Width).Substring(0, $Width) Set-Cursor 0 0 [Console]::Write("$menuColor$paddedMenu$reset") } # Generic Status Bar Drawing function Draw-Status { param( [string]$StatusText, [string]$FocusAreaText, [string]$HelpText, [int]$Width, [int]$Height ) $statusColor = Get-ANSIColor 'Header' $reset = Get-ANSIColor 'Reset' $focusPart = if ($FocusAreaText) { "[$FocusAreaText]" } else { "" } $helpPart = if ($HelpText) { $HelpText + " │ " } else { "" } $maxStatusLen = $Width - $focusPart.Length - $helpPart.Length - 10 $leftText = $StatusText if ($leftText.Length -gt $maxStatusLen) { $leftText = $leftText.Substring(0, $maxStatusLen - 3) + "..." } $paddedStatusText = " " + $helpPart + $leftText $remainingSpaces = $Width - $paddedStatusText.Length - $focusPart.Length - 2 if ($remainingSpaces -lt 0) { $remainingSpaces = 0 } $fullStatus = $paddedStatusText + (" " * $remainingSpaces) + $focusPart + " " Set-Cursor 0 ($Height - 1) [Console]::Write("$statusColor$fullStatus$reset") } # Recalculate dimensions function Update-LayoutDimensions { param( [int]$Width, [int]$Height ) $global:mainHeight = $Height - 16 if ($global:mainHeight -lt 5) { $global:mainHeight = 5 } $global:leftWidth = 35 $maxWidth = [int]($Width * 0.4) if ($global:leftWidth -gt $maxWidth) { $global:leftWidth = $maxWidth } if ($global:leftWidth -lt 15) { $global:leftWidth = 15 } } # --- TREE VIEW COMPONENTS --- function Get-VisibleNodes($node) { $result = [System.Collections.ArrayList]::new() function Add-Node($n) { $result.Add($n) | Out-Null if (!$n.IsLeaf -and $n.IsExpanded -and $n.Children) { foreach ($child in $n.Children) { Add-Node $child } } } Add-Node $node return $result } function Draw-TreeView { param( [System.Collections.ArrayList]$VisibleNodes, [int]$SelectedIndex, [int]$ScrollOffset, [int]$LeftWidth, [int]$TreeHeight, [bool]$IsFocused = $true ) $startX = 1 $startY = 2 $reset = Get-ANSIColor 'Reset' for ($i = 0; $i -lt $TreeHeight; $i++) { $nodeIndex = $ScrollOffset + $i $y = $startY + $i if ($nodeIndex -lt $VisibleNodes.Count) { $node = $VisibleNodes[$nodeIndex] $prefix = if ($node.IsLeaf) { " " } else { if ($node.IsExpanded) { "▼ " } else { "▶ " } } $indent = " " * ($node.Level + 1) $displayText = $indent + $prefix + $node.Label if ($displayText.Length -gt $LeftWidth) { $displayText = $displayText.Substring(0, $LeftWidth - 3) + "..." } $paddedText = $displayText.PadRight($LeftWidth) if ($nodeIndex -eq $SelectedIndex) { $color = if ($IsFocused) { Get-ANSIColor 'SelectedActive' } else { Get-ANSIColor 'SelectedInactive' } } else { $color = Get-ANSIColor 'Reset' } Write-At $startX $y $paddedText # Set highlight Set-Cursor $startX $y [Console]::Write("$color$paddedText$reset") } else { Write-At $startX $y (" " * $LeftWidth) } } } # --- GENERIC TABLE VIEW COMPONENTS --- # Helper to format bytes function Format-Bytes { param($bytes) if ($null -eq $bytes) { return "0 B" } try { $bytes = [double]$bytes } catch { return "0 B" } if ($bytes -ge 1GB) { return "{0:N2} GB" -f ($bytes / 1GB) } if ($bytes -ge 1MB) { return "{0:N2} MB" -f ($bytes / 1MB) } if ($bytes -ge 1KB) { return "{0:N2} KB" -f ($bytes / 1KB) } return "{0:N0} B" -f $bytes } # Helper to format date strings like "20260527" -> "2026-05-27" function Format-DateString { param($str) if ($null -eq $str -or $str.Length -ne 8) { return $str } return "$($str.Substring(0,4))-$($str.Substring(4,2))-$($str.Substring(6,2))" } # Draw generic table header function Draw-TableHeader { param( [int]$StartX, [int]$StartY, [array]$Columns, # @{ Label="Name"; Width=15; Align="Left" } [int]$Width ) $reset = Get-ANSIColor 'Reset' $headerColor = Get-ANSIColor 'Header' $headerParts = @() foreach ($col in $Columns) { $label = $col.Label $w = $col.Width if ($label.Length -gt $w) { $label = $label.Substring(0, $w) } $padded = if ($col.Align -eq 'Right') { $label.PadLeft($w) } else { $label.PadRight($w) } $headerParts += $padded } $headerText = $headerParts -join "│" $paddedHeader = $headerText.PadRight($Width).Substring(0, $Width) Set-Cursor $startX $startY [Console]::Write("$headerColor$paddedHeader$reset") } # Draw generic table rows function Draw-TableRows { param( [System.Collections.ArrayList]$Items, [int]$SelectedIndex, [int]$ScrollOffset, [array]$Columns, [int]$StartX, [int]$StartY, [int]$Width, [int]$Height, [bool]$IsFocused = $true, [scriptblock]$RowColorScript = $null ) $reset = Get-ANSIColor 'Reset' for ($i = 0; $i -lt $Height; $i++) { $itemIndex = $ScrollOffset + $i $y = $startY + $i if ($itemIndex -lt $Items.Count) { $item = $Items[$itemIndex] $rowParts = @() foreach ($col in $Columns) { $val = $null if ($null -ne $item) { if ($item -is [hashtable]) { $val = $item[$col.Prop] } else { $val = $item.$($col.Prop) } } if ($null -eq $val) { $val = "" } # Format cell values $formattedVal = switch ($col.Format) { 'Percent' { "{0:F1} %" -f $val } 'MB' { "{0:N1} MB" -f ($val / 1MB) } 'Bytes' { Format-Bytes $val } 'Decimal' { "{0:F1}" -f $val } 'DateTime' { if ($val -is [DateTime]) { $val.ToString("yyyy-MM-dd HH:mm:ss") } else { $val.ToString() } } 'RegistryDate'{ Format-DateString $val } default { $val.ToString() } } $w = $col.Width if ($formattedVal.Length -gt $w) { $formattedVal = if ($w -gt 2) { $formattedVal.Substring(0, $w - 2) + ".." } else { $formattedVal.Substring(0, $w) } } $padded = if ($col.Align -eq 'Right') { $formattedVal.PadLeft($w) } else { $formattedVal.PadRight($w) } $rowParts += $padded } $rowText = $rowParts -join "│" # Select background based on active selection if ($itemIndex -eq $SelectedIndex) { $color = if ($IsFocused) { Get-ANSIColor 'SelectedActive' } else { Get-ANSIColor 'SelectedInactive' } } else { if ($null -ne $RowColorScript) { $colorName = & $RowColorScript $item $color = Get-ANSIColor $colorName } else { $color = Get-ANSIColor 'Reset' } } $paddedRow = $rowText.PadRight($Width).Substring(0, $Width) Set-Cursor $StartX $y [Console]::Write("$color$paddedRow$reset") } else { # Empty row Set-Cursor $StartX $y [Console]::Write(" " * $Width) } } } # --- DETAILS VIEW COMPONENTS --- function Get-DetailPropertyLine($lbl1, $val1, $lbl2, $val2, $colWidth) { $lblW = 12 $valW = $colWidth - $lblW if ($valW -lt 5) { $valW = 5 } $lbl1Str = $lbl1.PadRight($lblW).Substring(0, $lblW) $val1Str = if ($null -ne $val1) { $val1.ToString() } else { "" } if ($val1Str.Length -gt $valW) { $val1Str = $val1Str.Substring(0, $valW - 3) + "..." } $col1Text = ($lbl1Str + $val1Str).PadRight($colWidth) $lbl2Str = $lbl2.PadRight($lblW).Substring(0, $lblW) $val2Str = if ($null -ne $val2) { $val2.ToString() } else { "" } if ($val2Str.Length -gt $valW) { $val2Str = $val2Str.Substring(0, $valW - 3) + "..." } $col2Text = ($lbl2Str + $val2Str).PadRight($colWidth) return "$col1Text │ $col2Text" } # Wrap text lines helper function Wrap-Text($text, $maxLength) { if ([string]::IsNullOrEmpty($text)) { return @("") } $paragraphs = $text.Split(@("`r`n", "`n"), [System.StringSplitOptions]::None) $lines = [System.Collections.ArrayList]::new() foreach ($para in $paragraphs) { if ($para.Length -le $maxLength) { $lines.Add($para) | Out-Null continue } $words = $para.Split(' ') $currentLine = "" foreach ($word in $words) { if ($currentLine.Length -eq 0) { $currentLine = $word } elseif (($currentLine.Length + 1 + $word.Length) -le $maxLength) { $currentLine += " " + $word } else { $lines.Add($currentLine) | Out-Null $currentLine = $word } } if ($currentLine.Length -gt 0) { $lines.Add($currentLine) | Out-Null } } return $lines } function Draw-Details { param( [array]$HeaderLines, [array]$MessageLines, [int]$ScrollOffset, [int]$StartX, [int]$StartY, [int]$Width, [int]$Height ) # Draw the header lines (up to 4) $headerCount = if ($null -eq $HeaderLines) { 0 } else { $HeaderLines.Count } for ($i = 0; $i -lt 4; $i++) { $y = $StartY + $i $lineText = if ($i -lt $headerCount) { $HeaderLines[$i] } else { "" } if ($lineText.Length -gt $Width) { $lineText = $lineText.Substring(0, $Width) } Set-Cursor $StartX $y [Console]::Write($lineText.PadRight($Width)) } # Draw divider line $yDivider = $StartY + 4 $reset = Get-ANSIColor 'Reset' $gray = Get-ANSIColor 'Gray' Set-Cursor $StartX $yDivider [Console]::Write("$gray" + ("─" * $Width) + "$reset") # Draw scrollable body message lines $scrollAreaHeight = $Height - 5 $messageCount = if ($null -eq $MessageLines) { 0 } else { $MessageLines.Count } for ($i = 0; $i -lt $scrollAreaHeight; $i++) { $lineIndex = $ScrollOffset + $i $y = $StartY + 5 + $i $lineText = if ($lineIndex -lt $messageCount) { $MessageLines[$lineIndex] } else { "" } if ($lineText.Length -gt $Width) { $lineText = $lineText.Substring(0, $Width) } Set-Cursor $StartX $y [Console]::Write($lineText.PadRight($Width)) } # Fill remaining space for ($y = $StartY + 5 + $scrollAreaHeight; $y -lt $StartY + $Height; $y++) { Set-Cursor $StartX $y [Console]::Write(" " * $Width) } } # --- TEXT DIALOG INPUT BOX --- function Show-InputBox { param( [string]$Prompt, [string]$Title, [int]$Width, [int]$Height ) $boxW = 60 $boxH = 5 $boxX = [int](($Width - $boxW) / 2) $boxY = [int](($Height - $boxH) / 2) $reset = Get-ANSIColor 'Reset' $borderC = Get-ANSIColor 'White' $titleC = Get-ANSIColor 'SelectedActive' # 1. Draw outer frames of the box $topB = "╔" + ("═" * ($boxW - 2)) + "╗" $midB = "║" + (" " * ($boxW - 2)) + "║" $botB = "╚" + ("═" * ($boxW - 2)) + "╝" Write-At $boxX $boxY $topB 'White' Write-At $boxX ($boxY + 1) $midB 'White' Write-At $boxX ($boxY + 2) $midB 'White' Write-At $boxX ($boxY + 3) $midB 'White' Write-At $boxX ($boxY + 4) $botB 'White' # Draw title $titleText = " $Title " $titleX = $boxX + [int](($boxW - $titleText.Length) / 2) Write-At $titleX $boxY $titleText 'SelectedActive' # Draw prompt text Write-At ($boxX + 2) ($boxY + 1) $Prompt $inputText = "" $inputX = $boxX + 2 $inputY = $boxY + 2 $maxInputLen = $boxW - 4 # Temporarily show cursor [Console]::Write("$ESC[?25h") [Console]::CursorVisible = $true while ($true) { # Render current text Set-Cursor $inputX $inputY $displayText = $inputText if ($displayText.Length -gt $maxInputLen) { $displayText = "..." + $displayText.Substring($displayText.Length - $maxInputLen + 3) } [Console]::Write($displayText.PadRight($maxInputLen)) $cursorX = $inputX + [Math]::Min($displayText.Length, $maxInputLen) Set-Cursor $cursorX $inputY $key = [Console]::ReadKey($true) if ($key.Key -eq 'Enter') { break } if ($key.Key -eq 'Escape') { $inputText = $null break } if ($key.Key -eq 'Backspace') { if ($inputText.Length -gt 0) { $inputText = $inputText.Substring(0, $inputText.Length - 1) } } else { if ($key.KeyChar -ge 32 -and $key.KeyChar -le 126) { $inputText += $key.KeyChar } } } [Console]::Write("$ESC[?25l") [Console]::CursorVisible = $false return $inputText } # --- SCROLLABLE CHECKLIST DIALOG WITH SEARCH FILTERING --- function Show-CheckListDialog { param( [string]$Prompt, [string]$Title, [System.Collections.ArrayList]$Items, # Array of @{ Label = 'Name'; Checked = $true/$false } [int]$Width, [int]$Height ) $boxW = 66 $boxH = 18 $boxX = [int](($Width - $boxW) / 2) $boxY = [int](($Height - $boxH) / 2) if ($boxY -lt 1) { $boxY = 1 } $reset = Get-ANSIColor 'Reset' $topB = "╔" + ("═" * ($boxW - 2)) + "╗" $midB = "║" + (" " * ($boxW - 2)) + "║" $botB = "╚" + ("═" * ($boxW - 2)) + "╝" $searchQuery = "" $selectedIndex = 0 $scrollOffset = 0 $listHeight = $boxH - 8 while ($true) { # 1. Draw outer frame Write-At $boxX $boxY $topB 'White' for ($i = 1; $i -lt ($boxH - 1); $i++) { Write-At $boxX ($boxY + $i) $midB 'White' } Write-At $boxX ($boxY + $boxH - 1) $botB 'White' # Title $titleText = " $Title " $titleX = $boxX + [int](($boxW - $titleText.Length) / 2) Write-At $titleX $boxY $titleText 'SelectedActive' # Prompt Write-At ($boxX + 2) ($boxY + 1) $Prompt # Search Box label Write-At ($boxX + 2) ($boxY + 2) "Search Filter: $searchQuery" 'Cyan' Write-At ($boxX + 2) ($boxY + 3) ("─" * ($boxW - 4)) 'Gray' # Filter items based on search query $filteredItems = [System.Collections.ArrayList]::new() foreach ($item in $Items) { if ([string]::IsNullOrEmpty($searchQuery) -or $item.Label.IndexOf($searchQuery, [System.StringComparison]::OrdinalIgnoreCase) -ge 0) { $filteredItems.Add($item) | Out-Null } } # Bounds check if ($selectedIndex -ge $filteredItems.Count) { $selectedIndex = [Math]::Max(0, $filteredItems.Count - 1) } if ($selectedIndex -lt 0) { $selectedIndex = 0 } if ($selectedIndex -lt $scrollOffset) { $scrollOffset = $selectedIndex } if ($selectedIndex -ge ($scrollOffset + $listHeight)) { $scrollOffset = $selectedIndex - $listHeight + 1 } if ($scrollOffset -lt 0) { $scrollOffset = 0 } # Draw Checklist items for ($i = 0; $i -lt $listHeight; $i++) { $itemIdx = $scrollOffset + $i $y = $boxY + 4 + $i if ($itemIdx -lt $filteredItems.Count) { $item = $filteredItems[$itemIdx] $chk = if ($item.Checked) { "[x]" } else { "[ ]" } $text = " $chk $($item.Label) " if ($text.Length -gt ($boxW - 6)) { $text = $text.Substring(0, $boxW - 9) + "..." } $paddedText = $text.PadRight($boxW - 6) if ($itemIdx -eq $selectedIndex) { $color = Get-ANSIColor 'SelectedActive' } else { $color = Get-ANSIColor 'Reset' } Set-Cursor ($boxX + 3) $y [Console]::Write("$color$paddedText$reset") } else { Write-At ($boxX + 3) $y (" " * ($boxW - 6)) } } Write-At ($boxX + 2) ($boxY + $boxH - 3) ("─" * ($boxW - 4)) 'Gray' Write-At ($boxX + 2) ($boxY + $boxH - 2) " [Space] Toggle | [Arrows] Navigate | [A-Z] Filter | [Enter] OK | [Esc] Cancel" 'Header' # Read Key $key = [Console]::ReadKey($true) if ($key.Key -eq 'Escape') { return $null } if ($key.Key -eq 'Enter') { return $Items } if ($key.Key -eq 'UpArrow') { if ($selectedIndex -gt 0) { $selectedIndex-- } } elseif ($key.Key -eq 'DownArrow') { if ($selectedIndex -lt ($filteredItems.Count - 1)) { $selectedIndex++ } } elseif ($key.Key -eq 'PageUp') { $selectedIndex = [Math]::Max(0, $selectedIndex - $listHeight) } elseif ($key.Key -eq 'PageDown') { $selectedIndex = [Math]::Min($filteredItems.Count - 1, $selectedIndex + $listHeight) } elseif ($key.Key -eq 'Space') { if ($filteredItems.Count -gt 0) { $selectedItem = $filteredItems[$selectedIndex] $selectedItem.Checked = -not $selectedItem.Checked } } elseif ($key.Key -eq 'Backspace') { if ($searchQuery.Length -gt 0) { $searchQuery = $searchQuery.Substring(0, $searchQuery.Length - 1) $selectedIndex = 0 $scrollOffset = 0 } } else { if ($key.KeyChar -ge 32 -and $key.KeyChar -le 126) { $searchQuery += $key.KeyChar $selectedIndex = 0 $scrollOffset = 0 } } } } # Export functions # --- MAIN UTILITY DRIVER EXECUTION --- # PowerShell TUI System Information (MSInfo32) Main Driver # Run this script to start the System Information console interface. # Author: Antigravity $scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path # --- STATIC CATEGORY HIERARCHY --- function Build-MSInfoTree { $root = @{ Id = "Summary"; Label = "System Summary"; IsLeaf = $true; Level = -1; IsExpanded = $true; Children = [System.Collections.ArrayList]::new() } $hardware = @{ Id = "Hardware"; Label = "Hardware Resources"; IsLeaf = $false; Level = 0; IsExpanded = $true; Parent = $root; Children = [System.Collections.ArrayList]::new() } $root.Children.Add($hardware) | Out-Null $hwNodes = @( @{ Id = "Conflicts"; Label = "Conflicts/Sharing"; IsLeaf = $true; Level = 1; Parent = $hardware } @{ Id = "DMA"; Label = "DMA"; IsLeaf = $true; Level = 1; Parent = $hardware } @{ Id = "IO"; Label = "I/O"; IsLeaf = $true; Level = 1; Parent = $hardware } @{ Id = "IRQs"; Label = "IRQs"; IsLeaf = $true; Level = 1; Parent = $hardware } @{ Id = "Memory"; Label = "Memory"; IsLeaf = $true; Level = 1; Parent = $hardware } ) foreach ($node in $hwNodes) { $hardware.Children.Add($node) | Out-Null } $components = @{ Id = "Components"; Label = "Components"; IsLeaf = $false; Level = 0; IsExpanded = $true; Parent = $root; Children = [System.Collections.ArrayList]::new() } $root.Children.Add($components) | Out-Null $compNodes = @( @{ Id = "Display"; Label = "Display"; IsLeaf = $true; Level = 1; Parent = $components } @{ Id = "Sound"; Label = "Sound Device"; IsLeaf = $true; Level = 1; Parent = $components } @{ Id = "Drives"; Label = "Storage - Drives"; IsLeaf = $true; Level = 1; Parent = $components } @{ Id = "Disks"; Label = "Storage - Disks"; IsLeaf = $true; Level = 1; Parent = $components } @{ Id = "Network"; Label = "Network - Adapter"; IsLeaf = $true; Level = 1; Parent = $components } @{ Id = "USB"; Label = "USB"; IsLeaf = $true; Level = 1; Parent = $components } ) foreach ($node in $compNodes) { $components.Children.Add($node) | Out-Null } $software = @{ Id = "Software"; Label = "Software Environment"; IsLeaf = $false; Level = 0; IsExpanded = $true; Parent = $root; Children = [System.Collections.ArrayList]::new() } $root.Children.Add($software) | Out-Null $swNodes = @( @{ Id = "Drivers"; Label = "System Drivers"; IsLeaf = $true; Level = 1; Parent = $software } @{ Id = "Env"; Label = "Environment Variables"; IsLeaf = $true; Level = 1; Parent = $software } @{ Id = "Tasks"; Label = "Running Tasks"; IsLeaf = $true; Level = 1; Parent = $software } @{ Id = "Services"; Label = "Services"; IsLeaf = $true; Level = 1; Parent = $software } @{ Id = "Startup"; Label = "Startup Programs"; IsLeaf = $true; Level = 1; Parent = $software } ) foreach ($node in $swNodes) { $software.Children.Add($node) | Out-Null } return $root } # --- DYNAMIC WMI DATA QUERIES --- function Load-CategoryData($catId) { $dataList = [System.Collections.ArrayList]::new() switch ($catId) { "Summary" { # OS details $os = Get-CimInstance Win32_OperatingSystem -ErrorAction SilentlyContinue $cs = Get-CimInstance Win32_ComputerSystem -ErrorAction SilentlyContinue $bios = Get-CimInstance Win32_Bios -ErrorAction SilentlyContinue $proc = Get-CimInstance Win32_Processor -ErrorAction SilentlyContinue $summaryProps = @( @{ Item = "OS Name"; Value = $os.Caption } @{ Item = "Version"; Value = $os.Version } @{ Item = "OS Manufacturer"; Value = $os.Manufacturer } @{ Item = "System Name"; Value = [Environment]::MachineName } @{ Item = "System Manufacturer"; Value = $cs.Manufacturer } @{ Item = "System Model"; Value = $cs.Model } @{ Item = "System Type"; Value = $cs.SystemType } @{ Item = "Processor"; Value = $proc.Name } @{ Item = "BIOS Version/Date"; Value = $bios.SMBIOSBIOSVersion } @{ Item = "SMBIOS Version"; Value = $bios.SMBIOSMajorVersion.ToString() + "." + $bios.SMBIOSMinorVersion.ToString() } @{ Item = "Windows Directory"; Value = $os.WindowsDirectory } @{ Item = "System Directory"; Value = $os.SystemDirectory } @{ Item = "Boot Device"; Value = $os.BootDevice } @{ Item = "Locale"; Value = $os.Locale } @{ Item = "Total Physical Memory"; Value = Format-Bytes $cs.TotalPhysicalMemory } @{ Item = "Available Physical Memory"; Value = Format-Bytes $os.FreePhysicalMemory } @{ Item = "Total Virtual Memory"; Value = Format-Bytes ($os.TotalVirtualMemorySize * 1024) } @{ Item = "Available Virtual Memory"; Value = Format-Bytes ($os.FreeVirtualMemory * 1024) } ) foreach ($p in $summaryProps) { $dataList.Add([PSCustomObject]$p) | Out-Null } } "Conflicts" { # List shared IRQs as conflicts example $irqs = Get-CimInstance Win32_IRQResource -ErrorAction SilentlyContinue | Group-Object IRQNumber $shared = $irqs | Where-Object { $_.Count -gt 1 } if ($shared) { foreach ($g in $shared) { $devs = $g.Group | ForEach-Object { $_.Name } | Select-Object -Unique $dataList.Add([PSCustomObject]@{ Resource = "IRQ " + $g.Name; Device = $devs -join ", " }) | Out-Null } } else { $dataList.Add([PSCustomObject]@{ Resource = "None"; Device = "No conflicts or sharing resource conflicts detected." }) | Out-Null } } "DMA" { $dmas = Get-CimInstance Win32_DMAChannel -ErrorAction SilentlyContinue | Sort-Object DMAChannel foreach ($d in $dmas) { $dataList.Add([PSCustomObject]@{ Channel = "Channel " + $d.DMAChannel; Device = $d.Name; Status = $d.Status }) | Out-Null } } "IO" { $ports = Get-CimInstance Win32_PortResource -ErrorAction SilentlyContinue | Select-Object -First 50 foreach ($p in $ports) { $dataList.Add([PSCustomObject]@{ Address = $p.Name; Device = $p.Caption }) | Out-Null } } "IRQs" { $irqs = Get-CimInstance Win32_IRQResource -ErrorAction SilentlyContinue | Sort-Object IRQNumber foreach ($i in $irqs) { $dataList.Add([PSCustomObject]@{ IRQ = $i.IRQNumber; Device = $i.Name; Status = $i.Status }) | Out-Null } } "Memory" { $mems = Get-CimInstance Win32_DeviceMemoryAddress -ErrorAction SilentlyContinue | Select-Object -First 50 foreach ($m in $mems) { $dataList.Add([PSCustomObject]@{ Address = $m.Name; Device = $m.Caption }) | Out-Null } } "Display" { $gpus = Get-CimInstance Win32_VideoController -ErrorAction SilentlyContinue foreach ($gpu in $gpus) { $gpuProps = @( @{ Item = "Name"; Value = $gpu.Name } @{ Item = "Adapter RAM"; Value = Format-Bytes $gpu.AdapterRAM } @{ Item = "Video Processor"; Value = $gpu.VideoProcessor } @{ Item = "Driver Version"; Value = $gpu.DriverVersion } @{ Item = "PNP Device ID"; Value = $gpu.PNPDeviceID } ) foreach ($p in $gpuProps) { $dataList.Add([PSCustomObject]$p) | Out-Null } } } "Sound" { $sounds = Get-CimInstance Win32_SoundDevice -ErrorAction SilentlyContinue foreach ($snd in $sounds) { $sndProps = @( @{ Item = "Device Name"; Value = $snd.Name } @{ Item = "Manufacturer"; Value = $snd.Manufacturer } @{ Item = "Status"; Value = $snd.Status } @{ Item = "PNP Device ID"; Value = $snd.PNPDeviceID } ) foreach ($p in $sndProps) { $dataList.Add([PSCustomObject]$p) | Out-Null } } } "Drives" { $disks = Get-CimInstance Win32_LogicalDisk -ErrorAction SilentlyContinue foreach ($d in $disks) { $dataList.Add([PSCustomObject]@{ Drive = $d.DeviceID Description = $d.Description VolumeName = $d.VolumeName FileSystem = $d.FileSystem Size = $d.Size FreeSpace = $d.FreeSpace }) | Out-Null } } "Disks" { $drives = Get-CimInstance Win32_DiskDrive -ErrorAction SilentlyContinue foreach ($drv in $drives) { $dataList.Add([PSCustomObject]@{ Model = $drv.Model Size = $drv.Size Partitions = $drv.Partitions MediaType = $drv.MediaType }) | Out-Null } } "Network" { $adapters = Get-CimInstance Win32_NetworkAdapter -ErrorAction SilentlyContinue | Where-Object { $_.PhysicalAdapter } foreach ($adp in $adapters) { $dataList.Add([PSCustomObject]@{ Adapter = $adp.Name Type = $adp.AdapterType MACAddress = $adp.MACAddress Speed = $adp.Speed }) | Out-Null } } "USB" { $usbs = Get-CimInstance Win32_PnPEntity -ErrorAction SilentlyContinue | Where-Object { $_.Service -like "*usb*" -or $_.PNPClass -eq "USBDevice" } | Select-Object -First 50 foreach ($u in $usbs) { $dataList.Add([PSCustomObject]@{ DeviceName = $u.Name; Manufacturer = $u.Manufacturer; Status = $u.Status }) | Out-Null } } "Drivers" { $drivers = Get-CimInstance Win32_SystemDriver -ErrorAction SilentlyContinue | Select-Object -First 100 foreach ($d in $drivers) { $dataList.Add([PSCustomObject]@{ Name = $d.Name; Description = $d.DisplayName; State = $d.State; StartMode = $d.StartMode }) | Out-Null } } "Env" { $envs = [Environment]::GetEnvironmentVariables().GetEnumerator() | Sort-Object Name foreach ($e in $envs) { $dataList.Add([PSCustomObject]@{ Variable = $e.Name; Value = $e.Value }) | Out-Null } } "Tasks" { $procs = Get-Process | Where-Object { $_.Path } | Sort-Object Name | Select-Object -First 100 foreach ($p in $procs) { $dataList.Add([PSCustomObject]@{ ProcessName = $p.Name; PID = $p.Id; WorkingSet = $p.WorkingSet64; Path = $p.Path }) | Out-Null } } "Services" { $services = Get-CimInstance Win32_Service -ErrorAction SilentlyContinue | Select-Object -First 100 foreach ($s in $services) { $dataList.Add([PSCustomObject]@{ DisplayName = $s.DisplayName; Name = $s.Name; State = $s.State; StartMode = $s.StartMode }) | Out-Null } } "Startup" { $startups = Get-CimInstance Win32_StartupCommand -ErrorAction SilentlyContinue foreach ($s in $startups) { $dataList.Add([PSCustomObject]@{ Program = $s.Name; Command = $s.Command; User = $s.User; Location = $s.Location }) | Out-Null } } } return $dataList } # --- COLUMNS CONFIG MAP --- function Get-ColumnsConfig($catId) { switch ($catId) { "Summary" { return @(@{ Label = "Item"; Prop = "Item"; Align = "Left"; Width = 25 }, @{ Label = "Value"; Prop = "Value"; Align = "Left"; Width = 40 }) } "Conflicts" { return @(@{ Label = "Resource"; Prop = "Resource"; Align = "Left"; Width = 20 }, @{ Label = "Device"; Prop = "Device"; Align = "Left"; Width = 45 }) } "DMA" { return @(@{ Label = "Channel"; Prop = "Channel"; Align = "Left"; Width = 15 }, @{ Label = "Device"; Prop = "Device"; Align = "Left"; Width = 30 }, @{ Label = "Status"; Prop = "Status"; Align = "Left"; Width = 12 }) } "IO" { return @(@{ Label = "I/O Port Range"; Prop = "Address"; Align = "Left"; Width = 25 }, @{ Label = "Device"; Prop = "Device"; Align = "Left"; Width = 40 }) } "IRQs" { return @(@{ Label = "IRQ Number"; Prop = "IRQ"; Align = "Left"; Width = 15 }, @{ Label = "Device"; Prop = "Device"; Align = "Left"; Width = 35 }, @{ Label = "Status"; Prop = "Status"; Align = "Left"; Width = 12 }) } "Memory" { return @(@{ Label = "Memory Range"; Prop = "Address"; Align = "Left"; Width = 25 }, @{ Label = "Device"; Prop = "Device"; Align = "Left"; Width = 40 }) } "Display" { return @(@{ Label = "Property"; Prop = "Item"; Align = "Left"; Width = 20 }, @{ Label = "Value"; Prop = "Value"; Align = "Left"; Width = 45 }) } "Sound" { return @(@{ Label = "Property"; Prop = "Item"; Align = "Left"; Width = 20 }, @{ Label = "Value"; Prop = "Value"; Align = "Left"; Width = 45 }) } "Drives" { return @( @{ Label = "Drive"; Prop = "Drive"; Align = "Left"; Width = 8 } @{ Label = "Description"; Prop = "Description"; Align = "Left"; Width = 15 } @{ Label = "Volume Name"; Prop = "VolumeName"; Align = "Left"; Width = 15 } @{ Label = "FS"; Prop = "FileSystem"; Align = "Left"; Width = 8 } @{ Label = "Size"; Prop = "Size"; Align = "Right"; Width = 12; Format = "Bytes" } @{ Label = "Free Space"; Prop = "FreeSpace"; Align = "Right"; Width = 12; Format = "Bytes" } ) } "Disks" { return @( @{ Label = "Disk Model"; Prop = "Model"; Align = "Left"; Width = 28 } @{ Label = "Size"; Prop = "Size"; Align = "Right"; Width = 12; Format = "Bytes" } @{ Label = "Partitions"; Prop = "Partitions"; Align = "Right"; Width = 12 } @{ Label = "Media Type"; Prop = "MediaType"; Align = "Left"; Width = 18 } ) } "Network" { return @( @{ Label = "Adapter Name"; Prop = "Adapter"; Align = "Left"; Width = 28 } @{ Label = "Type"; Prop = "Type"; Align = "Left"; Width = 15 } @{ Label = "MAC Address"; Prop = "MACAddress"; Align = "Left"; Width = 18 } @{ Label = "Speed"; Prop = "Speed"; Align = "Right"; Width = 12; Format = "Decimal" } ) } "USB" { return @(@{ Label = "USB Device Name"; Prop = "DeviceName"; Align = "Left"; Width = 30 }, @{ Label = "Manufacturer"; Prop = "Manufacturer"; Align = "Left"; Width = 20 }, @{ Label = "Status"; Prop = "Status"; Align = "Left"; Width = 12 }) } "Drivers" { return @(@{ Label = "Driver Name"; Prop = "Name"; Align = "Left"; Width = 15 }, @{ Label = "Description"; Prop = "Description"; Align = "Left"; Width = 30 }, @{ Label = "State"; Prop = "State"; Align = "Left"; Width = 12 }, @{ Label = "Start Mode"; Prop = "StartMode"; Align = "Left"; Width = 12 }) } "Env" { return @(@{ Label = "Variable Name"; Prop = "Variable"; Align = "Left"; Width = 22 }, @{ Label = "Value"; Prop = "Value"; Align = "Left"; Width = 40 }) } "Tasks" { return @( @{ Label = "Task Name"; Prop = "ProcessName"; Align = "Left"; Width = 15 } @{ Label = "PID"; Prop = "PID"; Align = "Right"; Width = 8 } @{ Label = "Working Set"; Prop = "WorkingSet"; Align = "Right"; Width = 12; Format = "Bytes" } @{ Label = "Path"; Prop = "Path"; Align = "Left"; Width = 35 } ) } "Services" { return @(@{ Label = "Display Name"; Prop = "DisplayName"; Align = "Left"; Width = 25 }, @{ Label = "Name"; Prop = "Name"; Align = "Left"; Width = 15 }, @{ Label = "State"; Prop = "State"; Align = "Left"; Width = 10 }, @{ Label = "Start Mode"; Prop = "StartMode"; Align = "Left"; Width = 12 }) } "Startup" { return @(@{ Label = "Program"; Prop = "Program"; Align = "Left"; Width = 15 }, @{ Label = "Command"; Prop = "Command"; Align = "Left"; Width = 30 }, @{ Label = "User"; Prop = "User"; Align = "Left"; Width = 12 }, @{ Label = "Location"; Prop = "Location"; Align = "Left"; Width = 15 }) } default { return @(@{ Label = "Item"; Prop = "Item"; Align = "Left"; Width = 20 }, @{ Label = "Value"; Prop = "Value"; Align = "Left"; Width = 40 }) } } } # --- STATE VARIABLES --- $rootNode = Build-MSInfoTree $treeVisibleNodes = Get-VisibleNodes $rootNode $treeSelectedIndex = 0 $treeScrollOffset = 0 $activeNode = $treeVisibleNodes[$treeSelectedIndex] $statusText = "Loading details for System Summary..." $loadedDetails = Load-CategoryData $activeNode.Id $activeCols = Get-ColumnsConfig $activeNode.Id $tableSelectedIndex = 0 $tableScrollOffset = 0 $global:focusArea = 0 # 0: Tree, 1: Table $width = [Console]::WindowWidth $height = [Console]::WindowHeight Update-LayoutDimensions $width $height Initialize-Console [Console]::Write("$ESC[2J") $redrawAll = $true $needsTreeRedraw = $true $needsTableRedraw = $true $needsStatusRedraw = $true $statusText = "Ready. Use Arrow keys to navigate categories. Tab to focus details." try { while ($true) { # 1. Resize Check $newWidth = [Console]::WindowWidth $newHeight = [Console]::WindowHeight if ($newWidth -ne $width -or $newHeight -ne $height) { $width = $newWidth $height = $newHeight Update-LayoutDimensions $width $height [Console]::Write("$ESC[2J") $redrawAll = $true } # 2. Redraw Components if ($redrawAll) { $rightWidth = $width - $global:leftWidth - 3 # We don't have a bottom details splitter, so HasHorizontalDivider = $false Draw-Borders $width $height $global:leftWidth $global:mainHeight $global:focusArea "CATEGORIES" "SYSTEM INFORMATION VALUES" "" -HasHorizontalDivider $false Draw-Menu $width @("Enter: Select", "Ctrl+Q: Exit") $needsTreeRedraw = $true $needsTableRedraw = $true $needsStatusRedraw = $true $redrawAll = $false } if ($needsTreeRedraw) { Draw-TreeView $treeVisibleNodes $treeSelectedIndex $treeScrollOffset $global:leftWidth ($height - 4) ($global:focusArea -eq 0) $needsTreeRedraw = $false } if ($needsTableRedraw) { $rightWidth = $width - $global:leftWidth - 3 # Dynamically size columns to fill the table panel # We locate the last column and make it fill the rest of the space $totalW = 0 for ($i = 0; $i -lt ($activeCols.Count - 1); $i++) { $totalW += $activeCols[$i].Width + 1 } $lastCol = $activeCols[-1] $lastCol.Width = $rightWidth - $totalW - 1 if ($lastCol.Width -lt 10) { $lastCol.Width = 10 } Draw-TableHeader ($global:leftWidth + 2) 2 $activeCols $rightWidth # Details view occupies full right height $tableHeight = $height - 4 Draw-TableRows $loadedDetails $tableSelectedIndex $tableScrollOffset $activeCols ($global:leftWidth + 2) 3 $rightWidth $tableHeight ($global:focusArea -eq 1) $needsTableRedraw = $false } if ($needsStatusRedraw) { $focusTxt = if ($global:focusArea -eq 0) { "Tree View" } else { "Details Table" } Draw-Status $statusText $focusTxt "Tab: Switch Pane" $width $height $needsStatusRedraw = $false } Set-Cursor 0 0 # 3. Read Key Input if (-not [Console]::KeyAvailable) { Start-Sleep -Milliseconds 20 continue } $key = [Console]::ReadKey($true) $isCtrl = ($key.Modifiers -band [System.ConsoleModifiers]::Control) -eq [System.ConsoleModifiers]::Control if ($isCtrl) { if ($key.Key -eq 'Q') { break } } # --- FOCUS NAVIGATION --- if ($global:focusArea -eq 0) { # Tree View $node = $treeVisibleNodes[$treeSelectedIndex] if ($key.Key -eq 'UpArrow') { if ($treeSelectedIndex -gt 0) { $treeSelectedIndex-- if ($treeSelectedIndex -lt $treeScrollOffset) { $treeScrollOffset = $treeSelectedIndex } $needsTreeRedraw = $true if ($treeVisibleNodes[$treeSelectedIndex].IsLeaf) { $activeNode = $treeVisibleNodes[$treeSelectedIndex] $statusText = "Loading details for $($activeNode.Label)..." $needsStatusRedraw = $true Draw-Status $statusText "" "" $width $height $loadedDetails = Load-CategoryData $activeNode.Id $activeCols = Get-ColumnsConfig $activeNode.Id $tableSelectedIndex = 0 $tableScrollOffset = 0 $needsTableRedraw = $true $statusText = "Loaded $($activeNode.Label)." } } } elseif ($key.Key -eq 'DownArrow') { if ($treeSelectedIndex -lt ($treeVisibleNodes.Count - 1)) { $treeSelectedIndex++ $treeHeight = $height - 4 if ($treeSelectedIndex -ge ($treeScrollOffset + $treeHeight)) { $treeScrollOffset = $treeSelectedIndex - $treeHeight + 1 } $needsTreeRedraw = $true if ($treeVisibleNodes[$treeSelectedIndex].IsLeaf) { $activeNode = $treeVisibleNodes[$treeSelectedIndex] $statusText = "Loading details for $($activeNode.Label)..." $needsStatusRedraw = $true Draw-Status $statusText "" "" $width $height $loadedDetails = Load-CategoryData $activeNode.Id $activeCols = Get-ColumnsConfig $activeNode.Id $tableSelectedIndex = 0 $tableScrollOffset = 0 $needsTableRedraw = $true $statusText = "Loaded $($activeNode.Label)." } } } elseif ($key.Key -eq 'PageUp') { $treeHeight = $height - 4 $treeSelectedIndex = [Math]::Max(0, $treeSelectedIndex - $treeHeight) $treeScrollOffset = [Math]::Max(0, $treeScrollOffset - $treeHeight) if ($treeSelectedIndex -lt $treeScrollOffset) { $treeSelectedIndex = $treeScrollOffset } $needsTreeRedraw = $true if ($treeVisibleNodes[$treeSelectedIndex].IsLeaf) { $activeNode = $treeVisibleNodes[$treeSelectedIndex] $loadedDetails = Load-CategoryData $activeNode.Id $activeCols = Get-ColumnsConfig $activeNode.Id $tableSelectedIndex = 0 $tableScrollOffset = 0 $needsTableRedraw = $true } } elseif ($key.Key -eq 'PageDown') { $treeHeight = $height - 4 $treeSelectedIndex = [Math]::Min($treeVisibleNodes.Count - 1, $treeSelectedIndex + $treeHeight) $treeScrollOffset = [Math]::Min($treeVisibleNodes.Count - $treeHeight, $treeScrollOffset + $treeHeight) if ($treeScrollOffset -lt 0) { $treeScrollOffset = 0 } if ($treeSelectedIndex -ge ($treeScrollOffset + $treeHeight)) { $treeSelectedIndex = $treeScrollOffset + $treeHeight - 1 } $needsTreeRedraw = $true if ($treeVisibleNodes[$treeSelectedIndex].IsLeaf) { $activeNode = $treeVisibleNodes[$treeSelectedIndex] $loadedDetails = Load-CategoryData $activeNode.Id $activeCols = Get-ColumnsConfig $activeNode.Id $tableSelectedIndex = 0 $tableScrollOffset = 0 $needsTableRedraw = $true } } elseif ($key.Key -eq 'RightArrow') { if (-not $node.IsLeaf -and -not $node.IsExpanded) { $node.IsExpanded = $true $treeVisibleNodes = Get-VisibleNodes $rootNode $needsTreeRedraw = $true $statusText = "Expanded $($node.Label)." $needsStatusRedraw = $true } } elseif ($key.Key -eq 'LeftArrow') { if (-not $node.IsLeaf -and $node.IsExpanded) { $node.IsExpanded = $false $treeVisibleNodes = Get-VisibleNodes $rootNode $needsTreeRedraw = $true $statusText = "Collapsed $($node.Label)." $needsStatusRedraw = $true } elseif ($null -ne $node.Parent -and $node.Parent.Id -ne 'Summary') { $parentIndex = $treeVisibleNodes.IndexOf($node.Parent) if ($parentIndex -ge 0) { $treeSelectedIndex = $parentIndex if ($treeSelectedIndex -lt $treeScrollOffset) { $treeScrollOffset = $treeSelectedIndex } $needsTreeRedraw = $true } } } elseif ($key.Key -eq 'Enter') { if ($node.IsLeaf) { $activeNode = $node $statusText = "Loading details for $($activeNode.Label)..." $needsStatusRedraw = $true Draw-Status $statusText "" "" $width $height $loadedDetails = Load-CategoryData $activeNode.Id $activeCols = Get-ColumnsConfig $activeNode.Id $tableSelectedIndex = 0 $tableScrollOffset = 0 $global:focusArea = 1 $statusText = "Loaded $($activeNode.Label)." $redrawAll = $true } } elseif ($key.Key -eq 'Tab') { if ($loadedDetails.Count -gt 0) { $global:focusArea = 1 $redrawAll = $true } } } elseif ($global:focusArea -eq 1) { # Table View $tableHeight = $height - 4 if ($key.Key -eq 'UpArrow') { if ($tableSelectedIndex -gt 0) { $tableSelectedIndex-- if ($tableSelectedIndex -lt $tableScrollOffset) { $tableScrollOffset = $tableSelectedIndex } $needsTableRedraw = $true } } elseif ($key.Key -eq 'DownArrow') { if ($tableSelectedIndex -lt ($loadedDetails.Count - 1)) { $tableSelectedIndex++ if ($tableSelectedIndex -ge ($tableScrollOffset + $tableHeight)) { $tableScrollOffset = $tableSelectedIndex - $tableHeight + 1 } $needsTableRedraw = $true } } elseif ($key.Key -eq 'PageUp') { $tableSelectedIndex = [Math]::Max(0, $tableSelectedIndex - $tableHeight) $tableScrollOffset = [Math]::Max(0, $tableScrollOffset - $tableHeight) if ($tableSelectedIndex -lt $tableScrollOffset) { $tableSelectedIndex = $tableScrollOffset } $needsTableRedraw = $true } elseif ($key.Key -eq 'PageDown') { $tableSelectedIndex = [Math]::Min($loadedDetails.Count - 1, $tableSelectedIndex + $tableHeight) $tableScrollOffset = [System.Math]::Min($loadedDetails.Count - $tableHeight, $tableScrollOffset + $tableHeight) if ($tableScrollOffset -lt 0) { $tableScrollOffset = 0 } if ($tableSelectedIndex -ge ($tableScrollOffset + $tableHeight)) { $tableSelectedIndex = $tableScrollOffset + $tableHeight - 1 } $needsTableRedraw = $true } elseif ($key.Key -eq 'Escape' -or $key.Key -eq 'Tab') { $global:focusArea = 0 $redrawAll = $true } } } } finally { Restore-Console } |