Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- Function List:
- Adjust-Host
- Animate-Host
- Break-Line
- Choice-AdjustHost
- Superuser:
- https://superuser.com/a/1322721/868077
- Preview:
- https://imgur.com/a/B3FNaej
- Requires an array list at the beginning of the script:
- $HostLogArrayList = New-Object System.Collections.ArrayList
- Break-Line also supports seperators:
- !ui_seperator_big! : __________________________________________________
- __________________________________________________
- !ui_seperator_normal! : __________________________________________________
- !ui_seperator_thin! : --------------------------------------------------
- And default leading spaces:
- $DefaultLeadingSpaces = 1
- #>
- <#
- .SYNOPSIS
- Adjusts UI to window width.
- .DESCRIPTION
- Adjusts the UI to the window width as long as a monitored process is running or for n iterations.
- Also allows a simple dot animation based on Animate-Host.
- .PARAMETER MonitoredProcessId
- The Process ID (PID) of the process to be monitored.
- The loop will run as long as the monitored process is running.
- .PARAMETER Iteration
- Number of iterations for the loop.
- .PARAMETER Duration
- Duration in milliseconds for the loop.
- .PARAMETER BufferWidth
- Minimum buffer width (default is 50).
- .PARAMETER TempMessage
- A normal message which will not get logged.
- .PARAMETER TempLeadingSpaces
- Leading spaces to be displayed in front of the normal message.
- .PARAMETER TempColor
- The color of the normal message.
- .PARAMETER TempNoNewline
- .PARAMETER AnimateHostMessage
- The message to be displayed in front of the dots.
- .PARAMETER AnimateHostLeadingSpaces
- Leading spaces to be displayed in front of the animated message.
- .PARAMETER AnimateHostColor
- The color of the animated message.
- .PARAMETER AnimateHostTitleMain
- The console window title in front of the dots.
- .PARAMETER AnimateHostTitleSub
- The console window title after the dots.
- .PARAMETER BufferOnly
- Only adjusts the buffer size.
- .PARAMETER NoLog
- Does not add the $AnimateHostMessage to the $HostLogArrayList array.
- .EXAMPLE
- C:\PS> Adjust-Host -MonitoredProcessId 6376
- .EXAMPLE
- C:\PS> Adjust-Host 6379 -Duration 3000 -BufferOnly
- .EXAMPLE
- C:\PS> Adjust-Host -MonitoredProcessId $SomeProcess.Id -AnimateHostMessage "Downloading" -AnimateHostLeadingSpaces 1 -AnimateHostColor Yellow
- #>
- function Adjust-Host {
- Param (
- [Parameter(ParameterSetName = 'Monitoring', Position = 0)]
- [Int32[]] $MonitoredProcessId,
- [Parameter(ParameterSetName = 'Iterating', Position = 0)]
- [Int32] $Iteration,
- [Parameter(ParameterSetName = 'Duration', Position = 0)]
- [Int32] $Duration,
- [AllowNull()]
- [Int32] $BufferWidth,
- [String] $TempMessage,
- [Int32] $TempLeadingSpaces,
- [ConsoleColor] $TempColor,
- [Switch] $TempNoNewline,
- [String] $AnimateHostMessage,
- [Int32] $AnimateHostLeadingSpaces,
- [ConsoleColor] $AnimateHostColor,
- [String] $AnimateHostTitleMain,
- [String] $AnimateHostTitleSub,
- [Switch] $BufferOnly,
- [Switch] $NoLog
- )
- $IterationCounter = 0
- $AdjustHost_main_start = (Get-Date)
- $window_width = $Host.UI.RawUI.WindowSize.Width
- if ($MonitoredProcessId -eq $null -or $MonitoredProcessId -eq '') {
- $MonitoredProcessId = [Int32]::MaxValue
- }
- if ($AnimateHostColor -eq $null -or $AnimateHostColor -eq '') {
- $AnimateHostColor = $Host.UI.RawUI.ForegroundColor
- }
- if ($BufferWidth -eq $null -or $BufferWidth -eq '') {
- $BufferWidth = 50
- }
- while ((Get-Process -Id $MonitoredProcessId 2>$null) -ne $null -or $IterationCounter -lt $Iteration -or ((Get-Date) - $AdjustHost_main_start).TotalMilliseconds -lt $Duration) {
- if ($window_width -ne $Host.UI.RawUI.WindowSize.Width -or $Iteration -eq 1 -and !$BufferOnly) {
- if ($Host.UI.RawUI.WindowSize.Width -lt $BufferWidth) {
- $Host.UI.RawUI.BufferSize = New-Object System.Management.Automation.Host.Size($BufferWidth, $Host.UI.RawUI.BufferSize.Height)
- }
- Clear-Host
- for ($x=0; $x -le $HostLogArrayList.Count; $x += 5) {
- $prev_message = $cur_message
- $prev_leading_spaces = $cur_leading_spaces
- $prev_color = $cur_color
- $prev_new_line = $cur_new_line
- $prev_start_spacer = $cur_start_spacer
- $cur_message = $HostLogArrayList[$x]
- $cur_leading_spaces = $HostLogArrayList[$x+1]
- $cur_color = $HostLogArrayList[$x+2]
- $cur_new_line = $HostLogArrayList[$x+3]
- $cur_start_spacer = $HostLogArrayList[$x+4]
- if ($cur_color -eq $prev_color -and $cur_leading_spaces -eq $prev_leading_spaces -and ($prev_start_spacer -eq 'False' -or $prev_start_spacer -eq $false)) {
- if ($prev_new_line -eq 'True' -or $prev_new_line -eq $true) {
- $cur_message = $prev_message + $cur_message
- } else {
- $cur_message = $prev_message + "`n" + $cur_message
- }
- } else {
- if ($prev_color -eq '' -or $prev_color -eq $null) {
- $prev_color = $Host.UI.RawUI.ForegroundColor
- }
- if ($prev_start_spacer -eq 'True' -or $prev_start_spacer -eq $true) {
- if (($prev_new_line -eq 'True' -or $prev_new_line -eq $true) -and $prev_message -ne $null) {
- Break-Line $prev_message -Color $prev_color -LeadingSpaces $prev_leading_spaces -NoNewline -NoStartSpacer -NoLog
- } elseif ($prev_message -ne $null) {
- Break-Line $prev_message -Color $prev_color -LeadingSpaces $prev_leading_spaces -NoStartSpacer -NoLog
- }
- } else {
- if (($prev_new_line -eq 'True' -or $prev_new_line -eq $true) -and $prev_message -ne $null) {
- Break-Line $prev_message -Color $prev_color -LeadingSpaces $prev_leading_spaces -NoNewline -NoLog
- } elseif ($prev_message -ne $null) {
- Break-Line $prev_message -Color $prev_color -LeadingSpaces $prev_leading_spaces -NoLog
- }
- }
- }
- }
- if ($TempMessage -ne $null -and $TempMessage -ne '' -and $TempNoNewline) {
- Break-Line $TempMessage -LeadingSpaces $TempLeadingSpaces -Color $TempColor -NoLog -NoNewline
- } elseif ($TempMessage -ne $null -and $TempMessage -ne '') {
- Break-Line $TempMessage -LeadingSpaces $TempLeadingSpaces -Color $TempColor -NoLog
- }
- $window_width = $Host.UI.RawUI.WindowSize.Width
- } else {
- if ($Host.UI.RawUI.WindowSize.Width -lt $BufferWidth) {
- $Host.UI.RawUI.BufferSize = New-Object System.Management.Automation.Host.Size($BufferWidth, $Host.UI.RawUI.BufferSize.Height)
- $window_width = $Host.UI.RawUI.WindowSize.Width
- }
- if ($AnimateHostMessage -ne $null -and $AnimateHostMessage -ne '') {
- Animate-Host -MonitoredProcessId $MonitoredProcessId -Message $AnimateHostMessage -LeadingSpaces $AnimateHostLeadingSpaces -Color $AnimateHostColor -OnAdjustHost -TitleMain $AnimateHostTitleMain -TitleSub $AnimateHostTitleSub
- }
- }
- $IterationCounter++
- Sleep -Milliseconds 10
- }
- if ($AnimateHostMessage -ne $null -and $AnimateHostMessage -ne '' -and !$NoLog) {
- Break-Line "$AnimateHostMessage..." -LeadingSpaces $AnimateHostLeadingSpaces -Color $AnimateHostColor -NoNewline
- Adjust-Host -Iteration 1
- }
- }
- <#
- .SYNOPSIS
- Simple dot animation.
- .DESCRIPTION
- Animates dots while a monitored process is running.
- .PARAMETER MonitoredProcessId
- The Process ID (PID) of the process to be monitored.
- The loop will run as long as the monitored process is running.
- .PARAMETER Iteration
- Number of iterations for the loop (one iteration takes slightly more than 1 second).
- .PARAMETER Duration
- Duration in seconds for the loop (one iteration takes slightly more than 1 second).
- .PARAMETER Message
- The message to be displayed in front of the dots.
- .PARAMETER LeadingSpaces
- Leading spaces to be displayed in front of the message.
- .PARAMETER Color
- The color of the message.
- .PARAMETER TitleMain
- The console window title in front of the dots.
- .PARAMETER TitleSub
- The console window title after the dots.
- .PARAMETER OnAdjustHost
- Breaks the loop when the window width was changed.
- Only used by Adjust-Host.
- .EXAMPLE
- C:\PS> Animate-Host -MonitoredProcessId 1112 -Message "Doing stuff" -LeadingSpaces 1 -Color Green
- .EXAMPLE
- C:\PS> Animate-Host -Iteration 3 "Doing some more stuff" -TitleMain "MyProgramm - Doing some more stuff" -TitleSub "(Step 2/3)"
- #>
- function Animate-Host {
- Param (
- [Parameter(ParameterSetName = 'MonitoredProcess', Position = 0)]
- [Int32[]] $MonitoredProcessId,
- [Parameter(ParameterSetName = 'Iteration', Position = 0)]
- [Int32] $Iteration,
- [Parameter(ParameterSetName = 'Duration', Position = 0)]
- [Int32] $Duration,
- [Parameter(Mandatory = $true, Position = 1)]
- [String] $Message,
- [Int32] $LeadingSpaces,
- [ConsoleColor] $Color,
- [String] $TitleMain,
- [AllowNull()]
- [String] $TitleSub,
- [Switch] $OnAdjustHost
- )
- $IterationCounter = 0
- $AnimateHost_main_start = (Get-Date)
- if ($MonitoredProcessId -eq $null -or $MonitoredProcessId -eq '') {
- $MonitoredProcessId = [Int32]::MaxValue
- }
- if (($LeadingSpaces -eq $null -or $LeadingSpaces -eq '') -and $DefaultLeadingSpaces -is [int]) {
- $LeadingSpaces = $DefaultLeadingSpaces
- }
- if ($Color -eq '' -or $Color -eq $null) {
- $Color = $Host.UI.RawUI.ForegroundColor
- }
- Break-Line "$Message " -LeadingSpaces $LeadingSpaces -Color $Color -Width ($Host.UI.RawUI.WindowSize.Width + 3) -NoNewline -NoLog
- $window_width = $Host.UI.RawUI.WindowSize.Width
- $AnimateHost_loop = {
- $AnimateHost_loop_start = (Get-Date)
- while (((Get-Date) - $AnimateHost_loop_start).TotalMilliseconds -lt 250) {
- if ($OnAdjustHost -and $window_width -ne $Host.UI.RawUI.WindowSize.Width) {
- Break main
- } elseif ($OnAdjustHost -and $Host.UI.RawUI.WindowSize.Width -lt 50 -and $Host.UI.RawUI.BufferSize.Width -ne 50) {
- $Host.UI.RawUI.BufferSize = New-Object System.Management.Automation.Host.Size(50, $Host.UI.RawUI.BufferSize.Height)
- }
- Sleep -Milliseconds 1
- }
- }
- :main while ((Get-Process -Id $MonitoredProcessId 2>$null) -ne $null -or $IterationCounter -lt $Iteration -or ((Get-Date) - $AnimateHost_main_start).TotalMilliseconds -lt $Duration * 1000) {
- Write-Host "`b`b`b " -ForegroundColor $Color -NoNewline
- if ($TitleMain -ne '' -and $TitleMain -ne $null) {
- $Host.UI.RawUI.WindowTitle = "$TitleMain $TitleSub"
- }
- & $AnimateHost_loop
- Write-Host "`b`b`b. " -ForegroundColor $Color -NoNewline
- if ($TitleMain -ne '' -and $TitleMain -ne $null) {
- $Host.UI.RawUI.WindowTitle = "$TitleMain. $TitleSub"
- }
- & $AnimateHost_loop
- Write-Host "`b`b`b.. " -ForegroundColor $Color -NoNewline
- if ($TitleMain -ne '' -and $TitleMain -ne $null) {
- $Host.UI.RawUI.WindowTitle = "$TitleMain.. $TitleSub"
- }
- & $AnimateHost_loop
- Write-Host "`b`b`b..." -ForegroundColor $Color -NoNewline
- if ($TitleMain -ne '' -and $TitleMain -ne $null) {
- $Host.UI.RawUI.WindowTitle = "$TitleMain... $TitleSub"
- }
- $IterationCounter++
- & $AnimateHost_loop
- }
- if (!$OnAdjustHost) {
- Break-Line "$Message..." -LeadingSpaces $LeadingSpaces -Color $Color -NoNewline -LogOnly
- }
- }
- <#
- .SYNOPSIS
- Prevents words from getting split due to line breaks.
- .DESCRIPTION
- Splits a message at spaces based on a user defined Width or the window width.
- .PARAMETER Message
- The message to be split.
- .PARAMETER LeadingSpaces
- Leading spaces to be displayed in front of the message.
- .PARAMETER Color
- The color of the message.
- .PARAMETER Width
- The maximum Width per line.
- .PARAMETER WindowWidth
- Uses the window width instead of the Width.
- .PARAMETER NoNewline
- Does not add a new line ('`n') at the end of the message.
- .PARAMETER NoStartSpacer
- Does not add the spacer at the beginning of the first line.
- .PARAMETER NoLog
- Does not add the message to the $HostLogArrayList array.
- .PARAMETER LogOnly
- Only adds the message to the $HostLogArrayList array.
- .PARAMETER ReplaceLastMessage
- Replace the last message.
- .PARAMETER DontAddToLogFile
- Does not add the output to the log file.
- Output will still be added to the $HostLogArrayList!
- .EXAMPLE
- C:\PS> Break-Line "This is a very long message that would normally get split in the middle of a word" -LeadingSpaces 1 -WindowWidth
- .EXAMPLE
- C:\PS> Break-Line $MyMessage -Color Green -Width 50 -NoNewline -NoLog
- .EXAMPLE
- C:\PS> Break-Line "A short message" -WindowWidth -LogOnly
- .EXAMPLE
- C:\PS> Break-Line -ReplaceLastMessage -Message "My new message" -LeadingSpaces 0 -NoNewline
- #>
- function Break-Line {
- Param (
- [Parameter(Mandatory = $true, ParameterSetName = 'ReplaceLastMessage')]
- [Switch] $ReplaceLastMessage,
- [Parameter(Mandatory = $true, ParameterSetName = 'ReplaceLastMessage', Position = 1)]
- [Parameter(Mandatory = $true, ParameterSetName = 'Default', Position = 0)]
- [String] $Message,
- [Int32] $LeadingSpaces,
- [AllowNull()]
- [ConsoleColor] $Color,
- [Int32] $Width,
- [Switch] $WindowWidth,
- [Switch] $NoNewline,
- [Switch] $NoStartSpacer,
- [Switch] $NoLog,
- [Switch] $LogOnly,
- [Switch] $DontAddToLogFile
- )
- if ($ReplaceLastMessage) {
- if ($Message -ne '' -and $Message -ne $null) {
- $HostLogArrayList.Item($HostLogArrayList.Count - 5) = $Message
- }
- if ($LeadingSpaces -ne '' -and $LeadingSpaces -ne $null) {
- $HostLogArrayList.Item($HostLogArrayList.Count - 4) = $LeadingSpaces
- }
- if ($Color -ne '' -and $Color -ne $null) {
- $HostLogArrayList.Item($HostLogArrayList.Count - 3) = $Color
- }
- if ($NoNewline -ne '' -and $NoNewline -ne $null) {
- $HostLogArrayList.Item($HostLogArrayList.Count - 2) = $NoNewline
- }
- if ($NoStartSpacer -ne '' -and $NoStartSpacer -ne $null) {
- $HostLogArrayList.Item($HostLogArrayList.Count - 1) = $NoStartSpacer
- }
- Adjust-Host -Iteration 1
- } else {
- if ($WindowWidth -or $Width -eq '' -or $Width -eq $null) {
- $Width = $Host.UI.RawUI.BufferSize.Width
- if ($Width -lt 50) {
- $Width = 50
- }
- }
- if (($LeadingSpaces -eq $null -or $LeadingSpaces -eq '') -and $DefaultLeadingSpaces -is [int]) {
- $LeadingSpaces = $DefaultLeadingSpaces
- }
- if ($Color -eq '' -or $Color -eq $null) {
- $Color = $Host.UI.RawUI.ForegroundColor
- }
- if (!$NoLog -or $LogOnly) {
- $HostLogArrayList.Add($Message) 2>&1>$null
- $HostLogArrayList.Add($LeadingSpaces) 2>&1>$null
- $HostLogArrayList.Add($Color) 2>&1>$null
- $HostLogArrayList.Add($NoNewline) 2>&1>$null
- $HostLogArrayList.Add($NoStartSpacer) 2>&1>$null
- }
- if ($LeadingSpaces -gt 0 -and !$LogOnly) {
- $spacer = ' '*$LeadingSpaces
- if (!$NoStartSpacer) {
- $output = $spacer
- }
- }
- if ($LogFilePath -ne $null -and $LogFilePath -ne '' -and !$NoLog -and !$DontAddToLogFile) {
- $MessageOutFile = $Message -replace ('!ui_seperator_thin!', ("`n" + '-' * 100 + "`n")) -replace ('!ui_seperator_normal!', ("`n" + '_' * 100 + "`n")) -replace ('!ui_seperator_big!', ("`n" + [string]('_' * 100 + "`n") * 2))
- if ($NoNewline) {
- $MessageOutFile | Add-Content -Path $LogFilePath -Encoding Unicode -NoNewline
- } else {
- $MessageOutFile | Add-Content -Path $LogFilePath -Encoding Unicode
- }
- }
- $Message = $Message -replace ('!ui_seperator_thin!', ('-' * $Width + "`n")) -replace ('!ui_seperator_normal!', ('_' * $Width + "`n")) -replace ('!ui_seperator_big!', ([string]('_' * $Width) * 2 + "`n`n"))
- if (!$LogOnly) {
- $Message -split '(?<= )' -split "(?<=`n)" | ForEach-Object {
- if ($_.Contains(('-' * $Width)) -or $_.Contains(('_' * $Width)) -or $_.Contains([string]('_' * $Width) * 2)) {
- $output += "`n" + $_
- } elseif ($_.Contains("`n")) {
- if (($line_Width += $_.Length) -le $Width) {
- $output += ($_ + $spacer)
- } else {
- $output += ("`n" + $spacer + $_ + $spacer)
- }
- $line_Width = $LeadingSpaces
- } else {
- if (($line_Width += $_.Length) -lt $Width) {
- $output += $_
- } else {
- $output += ("`n" + $spacer + $_)
- $line_Width = $LeadingSpaces + $_.Length
- }
- }
- }
- }
- if ($NoNewline -and !$LogOnly) {
- Write-Host -ForegroundColor $Color $output -NoNewline
- } elseif (!$LogOnly) {
- Write-Host -ForegroundColor $Color $output
- }
- }
- }
- <#
- .SYNOPSIS
- Waits for user input while adjusting host and returns it or sets a variable.
- .DESCRIPTION
- Waits for user input and optionally adjusts host (function Adjust-Host required).
- If the $Options array contains the input it gets returned or a variable is set with either a specified value or the input itself.
- If it does not contain the input it repeats the loop.
- .PARAMETER Options
- Array of keys for choice option.
- .PARAMETER Name
- The name or an array of names of the variable(s) to be set.
- .PARAMETER SetOnlyDefined
- Will only assign a value to a variable if the option contains an array of a key and a value.
- .PARAMETER ChoiceMessage
- Array of short info for each choice option.
- .PARAMETER ChoiceMessageLeadingSpaces
- Leading spaces for the short info.
- .PARAMETER ChoiceMessageColor
- Color for the short info.
- .PARAMETER NoLog
- Does not add the message to the $HostLogArrayList array.
- .PARAMETER DontAdjust
- Does not adjust the host.
- .PARAMETER BufferOnly
- Only adjusts the buffer size.
- .PARAMETER Return
- Returns key even if a variable was defined.
- .PARAMETER NoReturn
- Does not return key even if no variable was defined.
- .OUTPUTS
- Pressed key.
- .EXAMPLE
- C:\PS> Choice-AdjustHost -Options ('y', 'n') -ChoiceMessage ('Yes', 'No') -ChoiceMessageLeadingSpaces 1 -ChoiceMessageColor Red
- .EXAMPLE
- C:\PS> Choice-AdjustHost (('a', 'valueA'), ('b', 'valueB'), 'c') -Name 'MyVariable_with_valueAorB' -SetOnlyDefined
- .EXAMPLE
- C:\PS> Choice-AdjustHost $MyOptionsArray -Name ('MyVariable_1_KeyCharValue', 'MyVariable_2_KeyCharValue', 'MyVariable_n_KeyCharValue')
- #>
- function Choice-AdjustHost {
- Param (
- [Parameter(Mandatory = $true)]
- [Array] $Options,
- [String[]] $Name,
- [Switch] $SetOnlyDefined,
- [Int32] $AdjustHostBufferWidth,
- [Array] $ChoiceMessage,
- [Int32] $ChoiceMessageLeadingSpaces,
- [ConsoleColor] $ChoiceMessageColor,
- [Switch] $NoLog,
- [Switch] $DontAdjust,
- [Switch] $BufferOnly,
- [Switch] $Return,
- [Switch] $NoReturn
- )
- if ($ChoiceMessage.Count -gt 0) {
- $ChoiceMessage | ForEach-Object {
- $MessageOptions += (' / [' + $_.Substring(0, 1) + ']' + $_.Substring(1))
- }
- $MessageOptions = $MessageOptions.Substring(3)
- if ($ChoiceMessageLeadingSpaces -isnot [int] -and $DefaultLeadingSpaces -is [int]) {
- $ChoiceMessageLeadingSpaces = $DefaultLeadingSpaces
- }
- if ($ChoiceMessageColor -isnot [ConsoleColor]) {
- $ChoiceMessageColor = $Host.UI.RawUI.ForegroundColor
- }
- Break-Line $MessageOptions -LeadingSpaces $ChoiceMessageLeadingSpaces -Color $ChoiceMessageColor -NoLog -NoNewline
- }
- $OptionKeys = $null
- $Options | ForEach-Object {
- if ($_ -is [Array]) {
- $OptionKeys += @($_[0])
- } else {
- $OptionKeys += @($_)
- }
- }
- $env:OptionKeys = $OptionKeys
- $ChoiceProcess = Start-Process PowerShell {
- $env:OptionKeys.Split(' ') | ForEach-Object {
- $OptionKeys += @($_)
- }
- $KeyChar = $null
- while (!$OptionKeys.Contains($KeyChar)) {
- $KeyChar = [string]([System.Console]::ReadKey('NoEcho')).KeyChar
- }
- $ChoiceCounter = 0
- while ($OptionKeys[$ChoiceCounter] -ne $KeyChar) {
- $ChoiceCounter++
- }
- return $ChoiceCounter
- } -PassThru -NoNewWindow -RedirectStandardOutput "$env:TEMP\r6s_extractor_choice_option_index.temp"
- if (!$DontAdjust -and $BufferOnly -and $ChoiceMessage.Count -gt 0) {
- Adjust-Host -MonitoredProcessId $ChoiceProcess.Id -BufferWidth $AdjustHostBufferWidth -BufferOnly -TempMessage $MessageOptions -TempLeadingSpaces $ChoiceMessageLeadingSpaces -TempColor $ChoiceMessageColor -TempNoNewline
- } elseif (!$DontAdjust -and $ChoiceMessage.Count -gt 0) {
- Adjust-Host -MonitoredProcessId $ChoiceProcess.Id -BufferWidth $AdjustHostBufferWidth -TempMessage $MessageOptions -TempLeadingSpaces $ChoiceMessageLeadingSpaces -TempColor $ChoiceMessageColor -TempNoNewline
- } else {
- while ((Get-Process -Id $ChoiceProcess.Id 2>$null) -ne $null) {
- Sleep -Milliseconds 10
- }
- }
- [Int32]$ChoiceCounter = (Get-Content "$env:TEMP\r6s_extractor_choice_option_index.temp")
- if ($ChoiceMessage.Count -eq 1) {
- Write-Host "`r" -NoNewline
- if ($NoLog) {
- Break-Line $MessageOptions -Color Yellow -NoLog
- } else {
- Break-Line $MessageOptions -Color Yellow
- }
- } elseif ($ChoiceMessage.Count -gt 1 -and $NoLog) {
- $SelectedMessage = ('[' + $ChoiceMessage[$ChoiceCounter].Substring(0, 1) + ']' + $ChoiceMessage[$ChoiceCounter].Substring(1))
- if ($ChoiceCounter -gt 0) {
- Break-Line ("`r" + $MessageOptions -split ($SelectedMessage).Replace('[', '\['))[0] -NoNewline -NoLog
- } else {
- Break-Line $SelectedMessage -Color Yellow -NoNewline -NoLog
- }
- if ($ChoiceCounter -lt $ChoiceMessage.Count - 1) {
- if ($ChoiceCounter -gt 0) {
- Write-Host -ForegroundColor Yellow (' ' * $DefaultLeadingSpaces + $SelectedMessage) -NoNewline
- }
- Break-Line ($MessageOptions -split ($SelectedMessage).Replace('[', '\['))[1] -NoLog
- } else {
- Write-Host -ForegroundColor Yellow (' ' * $DefaultLeadingSpaces + $SelectedMessage)
- }
- } elseif ($ChoiceMessage.Count -gt 1) {
- $SelectedMessage = ('[' + $ChoiceMessage[$ChoiceCounter].Substring(0, 1) + ']' + $ChoiceMessage[$ChoiceCounter].Substring(1))
- if ($ChoiceCounter -gt 0) {
- Write-Host "`r" -NoNewline
- Break-Line ($MessageOptions -split ($SelectedMessage).Replace('[', '\['))[0] -NoNewline
- Write-Host "`b" -NoNewline
- } else {
- Write-Host "`r" -NoNewline
- Break-Line $SelectedMessage -Color Yellow -NoNewline
- }
- if ($ChoiceCounter -lt $ChoiceMessage.Count - 1) {
- if ($ChoiceCounter -gt 0) {
- Break-Line $SelectedMessage -Color Yellow -NoNewline -NoStartSpacer -LogOnly
- Write-Host -ForegroundColor Yellow (' ' * $DefaultLeadingSpaces + $SelectedMessage) -NoNewline
- }
- Break-Line (($MessageOptions -split ($SelectedMessage).Replace('[', '\['))[1]).Substring(1)
- } else {
- Break-Line $SelectedMessage -Color Yellow -NoStartSpacer -LogOnly
- Write-Host -ForegroundColor Yellow (' ' * $DefaultLeadingSpaces + $SelectedMessage)
- }
- }
- if ($Name -ne $null -and $Name -ne '') {
- if ($Options[$ChoiceCounter] -is [Array]) {
- $Value = ($Options[$ChoiceCounter])[1]
- } elseif (!$SetOnlyDefined) {
- $Value = $Options[$ChoiceCounter]
- }
- if ($Value -ne $null -and [string]$Value -ne '') {
- if ($Name -is [Array]) {
- $Name | ForEach-Object {
- Set-Variable -Name $_ -Value $Value -Scope 1
- }
- } else {
- Set-Variable -Name $Name -Value $Value -Scope 1
- }
- } elseif (!$NoReturn) {
- return $OptionKeys[$ChoiceCounter]
- }
- }
- if (($Name -eq $null -or $Name -eq '' -or $Return) -and !$NoReturn) {
- return $OptionKeys[$ChoiceCounter]
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment