scripts/modules/shared/display-functions.ps1
# strangeloop Setup - Shared Display Functions # Version: 1.0.0 # UI and display functions for consistent branding and help system function Show-Banner { <# .SYNOPSIS Displays the strangeloop Setup banner with version information .PARAMETER Version The version number to display (defaults to 1.0.0) .PARAMETER Title Custom title text (defaults to "strangeloop Setup") #> param( [string]$Version = "1.0.0", [string]$Title = "strangeloop Setup" ) Write-Host "" Write-Host "╔═══════════════════════════════════════════════════════════════════════════════╗" -ForegroundColor Blue Write-Host "║ _ ║" -ForegroundColor Blue Write-Host "║ _ | | ║" -ForegroundColor Blue Write-Host "║ ___ _| |_ ____ _____ ____ ____ _____| | ___ ___ ____ ║" -ForegroundColor Blue Write-Host "║ /___|_ _)/ ___|____ | _ \ / _ | ___ | |/ _ \ / _ \| _ \ ║" -ForegroundColor Blue Write-Host "║ |___ | | |_| | / ___ | | | ( (_| | ____| | |_| | |_| | |_| | ║" -ForegroundColor Blue Write-Host "║ (___/ \__)_| \_____|_| |_|\___ |_____)\_)___/ \___/| __/ ║" -ForegroundColor Blue Write-Host "║ (_____| |_| ║" -ForegroundColor Blue Write-Host "║ $($Title.PadRight(75)) ║" -ForegroundColor Blue Write-Host "║ Version: $($Version.PadRight(67)) ║" -ForegroundColor Blue Write-Host "╚═══════════════════════════════════════════════════════════════════════════════╝" -ForegroundColor Blue Write-Host "" } function Show-Phases { <# .SYNOPSIS Displays all available phases with descriptions .PARAMETER ShowDependencies Whether to show phase dependencies .PARAMETER ShowOrder Whether to show execution order numbers #> param( [switch]$ShowDependencies, [switch]$ShowOrder ) # Import phase functions to get phase information $phaseFunctionsPath = Join-Path (Split-Path $PSScriptRoot -Parent) "shared\phase-functions.ps1" if (Test-Path $phaseFunctionsPath) { . $phaseFunctionsPath $phaseInfo = Get-PhaseInfo $phaseOrder = Get-PhaseOrder Write-Host "" Write-Host "Available Phases:" -ForegroundColor Green Write-Host "=================" -ForegroundColor Green Write-Host "" foreach ($phase in $phaseOrder) { $info = $phaseInfo[$phase] # Build phase display line $displayLine = "" if ($ShowOrder) { $displayLine += "[$($info.Order.ToString().PadLeft(2))] " } $displayLine += "$($phase.PadRight(15)) - $($info.Description)" Write-Host $displayLine -ForegroundColor Cyan if ($ShowDependencies -and $info.Dependencies.Count -gt 0) { Write-Host " Dependencies: $($info.Dependencies -join ', ')" -ForegroundColor Gray } } Write-Host "" Write-Host "Usage Examples:" -ForegroundColor Yellow Write-Host " -from-phase environment # Start from environment and run subsequent phases" -ForegroundColor Gray Write-Host " -only-phase pipelines # Run only the pipelines phase" -ForegroundColor Gray Write-Host " -skip-phases wsl,authentication # Skip specific phases" -ForegroundColor Gray Write-Host "" } else { Write-Warning "Phase information not available - phase-functions.ps1 not found" } } function Show-Help { <# .SYNOPSIS Displays comprehensive help information for the setup script .PARAMETER ScriptName The name of the script (for display purposes) .PARAMETER ShowExamples Whether to show usage examples .PARAMETER ShowPhases Whether to show available phases #> param( [string]$ScriptName = "setup-strangeloop.ps1", [switch]$ShowExamples, [switch]$ShowPhases ) Write-Host "" Write-Host "strangeloop Setup Help" -ForegroundColor Green Write-Host "======================" -ForegroundColor Green Write-Host "" Write-Host "DESCRIPTION:" -ForegroundColor Yellow Write-Host " Automated setup script for strangeloop development environments" -ForegroundColor Gray Write-Host " Supports both Windows and WSL environments with modular architecture" -ForegroundColor Gray Write-Host "" Write-Host "SYNTAX:" -ForegroundColor Yellow Write-Host " .\$ScriptName [parameters]" -ForegroundColor Gray Write-Host "" Write-Host "PARAMETERS:" -ForegroundColor Yellow Write-Host " -loop-name <string> strangeloop template to use" -ForegroundColor Gray Write-Host " -project-name <string> Name for the new project" -ForegroundColor Gray Write-Host " -project-path <string> Parent directory where project folder will be created" -ForegroundColor Gray Write-Host " -from-phase <string> Start from this phase and run all subsequent phases" -ForegroundColor Gray Write-Host " -only-phase <string> Run only this specific phase" -ForegroundColor Gray Write-Host " -skip-phases <string[]> Skip specific phases (comma-separated)" -ForegroundColor Gray Write-Host " -list-phases List all available phases and exit" -ForegroundColor Gray Write-Host " -help Show this help message" -ForegroundColor Gray Write-Host "" if ($ShowExamples) { Write-Host "EXAMPLES:" -ForegroundColor Yellow Write-Host " .\$ScriptName" -ForegroundColor Gray Write-Host " Run full setup with interactive prompts" -ForegroundColor Gray Write-Host "" Write-Host " .\$ScriptName -only-phase pipelines -project-name 'MyApp' -project-path '/parent/dir'" -ForegroundColor Gray Write-Host " Run only the pipelines phase with specific project details" -ForegroundColor Gray Write-Host "" Write-Host " .\$ScriptName -from-phase environment" -ForegroundColor Gray Write-Host " Start from environment phase and run all subsequent phases" -ForegroundColor Gray Write-Host "" Write-Host " .\$ScriptName -skip-phases wsl,pipelines" -ForegroundColor Gray Write-Host " Run all phases except WSL and pipelines" -ForegroundColor Gray Write-Host "" Write-Host " .\$ScriptName -project-name 'MyApp' -loop-name 'python-cli'" -ForegroundColor Gray Write-Host " Create project with specific parameters" -ForegroundColor Gray Write-Host "" Write-Host " .\$ScriptName -list-phases" -ForegroundColor Gray Write-Host " Show all available phases and exit" -ForegroundColor Gray Write-Host "" } if ($ShowPhases) { Show-Phases -ShowOrder } Write-Host "For more information, visit: https://msasg.visualstudio.com/Bing_Ads/_git/Strangeloop" -ForegroundColor Cyan Write-Host "" } function Show-LoopSelection { <# .SYNOPSIS Displays available loops organized by platform for user selection #> # Import loop functions to get loop information $loopFunctionsPath = Join-Path (Split-Path $PSScriptRoot -Parent) "shared\loop-functions.ps1" if (Test-Path $loopFunctionsPath) { . $loopFunctionsPath $loopsByPlatform = Get-LoopsByPlatform Write-Host "" Write-Host "Available strangeloop Templates:" -ForegroundColor Green Write-Host "================================" -ForegroundColor Green Write-Host "" Write-Host " Windows Loops:" -ForegroundColor Cyan foreach ($loop in $loopsByPlatform['Windows']) { $loopInfo = Get-LoopRequirements -LoopName $loop Write-Host " $($loop.PadRight(30)) - $($loopInfo.Description)" -ForegroundColor Gray } Write-Host "" Write-Host " WSL Loops:" -ForegroundColor Cyan foreach ($loop in $loopsByPlatform['WSL']) { $loopInfo = Get-LoopRequirements -LoopName $loop Write-Host " $($loop.PadRight(30)) - $($loopInfo.Description)" -ForegroundColor Gray } } else { Write-Warning "Loop information not available - loop-functions.ps1 not found" } Write-Host "" Write-Host "NOTES:" -ForegroundColor Yellow Write-Host " • WSL loops require Windows Subsystem for Linux to be available" -ForegroundColor Gray Write-Host " • Windows loops run natively on Windows" -ForegroundColor Gray Write-Host " • Project paths should match the loop's platform requirements" -ForegroundColor Gray Write-Host " • Use absolute paths for best compatibility" -ForegroundColor Gray Write-Host "" } function Show-LoopCategories { <# .SYNOPSIS Displays loops organized by platform (WSL vs Windows) #> # Import loop functions to get loop information $loopFunctionsPath = Join-Path (Split-Path $PSScriptRoot -Parent) "shared\loop-functions.ps1" if (Test-Path $loopFunctionsPath) { . $loopFunctionsPath $loopsByPlatform = Get-LoopsByPlatform $knownLoops = Get-KnownLoops Write-Host "" Write-Host "Available Loops by Platform:" -ForegroundColor Green Write-Host "============================" -ForegroundColor Green Write-Host "" foreach ($platform in @('Windows', 'WSL')) { if ($loopsByPlatform[$platform].Count -gt 0) { Write-Host "$platform Loops:" -ForegroundColor Cyan foreach ($loop in $loopsByPlatform[$platform] | Sort-Object) { $loopInfo = $knownLoops[$loop] $platformBadge = if ($loopInfo.Platform -eq 'WSL') { "[WSL]" } else { "[WIN]" } Write-Host " $platformBadge $($loop.PadRight(30)) - $($loopInfo.Description)" -ForegroundColor Gray } Write-Host "" } } } else { Write-Warning "Loop information not available - loop-functions.ps1 not found" } } function Write-SectionHeader { <# .SYNOPSIS Writes a formatted section header .PARAMETER Title The title text for the section .PARAMETER Color The color for the header (default: Blue) .PARAMETER Width The width of the header box (default: 80) #> param( [Parameter(Mandatory)] [string]$Title, [string]$Color = "Blue", [int]$Width = 80 ) $paddedTitle = " $Title ".PadLeft(($Width + $Title.Length) / 2).PadRight($Width - 2) Write-Host "" Write-Host "╔$('═' * ($Width - 2))╗" -ForegroundColor $Color Write-Host "║$paddedTitle║" -ForegroundColor $Color Write-Host "╚$('═' * ($Width - 2))╝" -ForegroundColor $Color Write-Host "" } function Write-ProgressStatus { <# .SYNOPSIS Writes progress status with consistent formatting .PARAMETER Message The status message .PARAMETER Status The status type: 'Info', 'Success', 'Warning', 'Error' .PARAMETER ShowTimestamp Whether to include a timestamp #> param( [Parameter(Mandatory)] [string]$Message, [ValidateSet('Info', 'Success', 'Warning', 'Error')] [string]$Status = 'Info', [switch]$ShowTimestamp ) $timestamp = if ($ShowTimestamp) { "[$(Get-Date -Format 'HH:mm:ss')] " } else { "" } switch ($Status) { 'Info' { Write-Host "$timestamp$Message" -ForegroundColor Cyan } 'Success' { Write-Host "$timestamp[+] $Message" -ForegroundColor Green } 'Warning' { Write-Host "$timestamp[!] $Message" -ForegroundColor Yellow } 'Error' { Write-Host "$timestamp[X] $Message" -ForegroundColor Red } } } # Export functions for module usage only if ($MyInvocation.MyCommand.ModuleName) { Export-ModuleMember -Function @( 'Show-Banner', 'Show-Phases', 'Show-Help', 'Show-LoopSelection', 'Show-LoopCategories', 'Write-SectionHeader', 'Write-ProgressStatus' ) } |