diff --git a/Write-Menu.ps1 b/Write-Menu.ps1 index 45b0f01..3250d64 100644 --- a/Write-Menu.ps1 +++ b/Write-Menu.ps1 @@ -165,11 +165,21 @@ function Write-Menu { Set-Color #> - function Set-Color ([switch]$Inverted) { + function Set-Color ([switch]$Inverted) { switch ($Inverted) { $true { - [System.Console]::ForegroundColor = $colorBackground - [System.Console]::BackgroundColor = $colorForeground + # If foregroundColor is not set it to black + [System.Console]::ForegroundColor = if([System.Console]::ForegroundColor -eq -1){ + 'Black' + }else{ + $colorBackground + } + # If backgroundColor is not set it to yellow + [System.Console]::BackgroundColor = if([System.Console]::BackgroundColor -eq -1){ + 'Yellow' + }else{ + $colorForeground + } } Default { [System.Console]::ForegroundColor = $colorForeground @@ -432,9 +442,20 @@ function Write-Menu { # Move cursor to first entry and beginning of line [System.Console]::CursorTop = $lineTop [System.Console]::Write("`r") - - # Get pressed key - $menuInput = [System.Console]::ReadKey($false) + + # Redirect standard input to null stream + $nullStream = [System.IO.Stream]::Null + $nullReader = [System.IO.StreamReader]::new($nullStream) + [System.Console]::SetIn($nullReader) + + # Hide input while detecting keypresses + try { + # Get pressed key + $menuInput = [System.Console]::ReadKey($true) + } finally { + # Restore standard input + [System.Console]::SetIn([System.IO.StreamReader]::new([System.IO.MemoryStream]::new())) + } # Define selected entry $entrySelected = $menuEntries[($pageEntryFirst + $lineSelected)]