Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <# https://pastebin.com/e0n3mWy0
- NOTE: Save this with UTF-8-BOM encoding!
- This scripts previews the majority of the features of the SimpleUI module. You can get the module here: https://pastebin.com/9RSusrvC
- A "dirty" version of this script can be found here: https://pastebin.com/kN3VkzkN
- The SimpleUI module improves user friendliness and readability of the PowerShell console and comes with a few gimmicks which contribute to an overall better console experience.
- Amongst other things it features a stable buffer width, correct word splitting, leading spaces, a simple three dot animation and a neat looking user prompt with some additional features.
- Feel free to use and modify this module as you desire.
- You can report issues, give feedback, suggest features or ask for help by sending an email to: FatalBulletHit@gmail.com
- #>
- # Location of the SimpleUI module.
- $ModuleLocation = '.\SimpleUI.psm1'
- # Initialization
- Import-Module $ModuleLocation -DisableNameChecking
- if ($Host.UI.RawUI.WindowTitle -match 'cmd') {
- $DarkMagenta = 'Black'
- $DarkYellow = 'White'
- } else {
- $DarkMagenta = 'DarkMagenta'
- $DarkYellow = 'DarkYellow'
- }
- # Introduction
- if ((Get-Content -LiteralPath '.\SimpleUIPreview.ps1' -Tail 1) -ne '#') {
- Monitor-Console -Width 120
- Set-Console -WindowSize 32 -WindowTitle 'SimpleUI Preview' -ClearHost
- Write-Console -Seperator 'Big'
- Write-Console -Message '`p(500)Welcome to the previe`p(500)' -NoNewline -Typewriter
- Write-Console -Message '- Hold on!`p(1000)' -ForegroundColor Yellow -Typewriter
- Set-Console -WindowSize 120
- Write-Console -Message "``p(1000)That's better!``p(500) Let's try this again, shall we?``p(500)" -ForegroundColor Yellow -Typewriter
- Clear-Host
- Start-Sleep -Seconds 1
- Write-Console -Seperator 'Big'
- Write-Console -Message "``p(500)Welcome to the preview of the " -NoNewline -Typewriter
- ('Red','Magenta','Blue','Cyan','Green','Yellow',$DarkYellow,$DarkYellow) | ForEach-Object {
- Write-Host -Object 'SimpleUI'[$i++] -ForegroundColor $_ -NoNewline
- Start-Sleep -Milliseconds (Get-Random -Minimum 25 -Maximum 75)
- }
- Write-Console -Message "module!`n``p(2000)" -Typewriter
- Write-Console -Message "Oh, crap, I thought I had more time!``p(1000)`nWell, I'm not completely done yet, so do me a favor and chose a background color and I take care of the rest.``p(500)`nSimply press the key which is displayed in between the square brackets of the option you want to chose.`n``p(1000)" -ForegroundColor Yellow -Typewriter
- Read-Console -Duration 1500 -Options (1..9) -DefaultOptionsIndex 0 -Message ('1 Black','2 DarkBlue','3 DarkGreen','4 DarkCyan','5 DarkRed','6 DarkMagenta','7 DarkYellow','8 Gray','9 DarkGray') -Style 'Vertical' -VariableName 'Result' -MessageAsValue
- if ($Result -eq [int]::MaxValue) {
- $Color = 'Black'
- Set-Console -BackgroundColor $Color -ForegroundColor Cyan -ClearHost
- Write-Console -Message "`n``p(2500)Oh!``p(1000) What happened?!``p(2500)`nI see, a 0 to little on that timer - ``p(500)that's the stress, I'm telling you!``p(1000)`nOh, well, hope you are happy with ordinary black as your background color for this preview.``p(500) While we are at it, let's change the foreground color, too...``p(1000)" -ForegroundColor Yellow -NoNewline -Typewriter
- Write-Console -Message 'there we go!`p(1000)' -Typewriter
- } else {
- Start-Sleep -Seconds 1
- if (($DarkMagenta -eq 'Black' -and $Color.Substring(2) -match 'Dark') -or ('DarkGreen','DarkCyan','DarkRed').Contains(($Color = $Result.Substring(2)))) {
- Write-Console -Message "`n`nDisgusting!``p(500)Oh, did I say that out loud... ?" -ForegroundColor Yellow -Typewriter
- Set-Console -BackgroundColor $Color -ClearHost
- Write-Console -Message '`p(500)There we go...`p(1000)' -Typewriter
- } elseif ($Color -eq $Host.UI.RawUI.BackgroundColor) {
- Set-Console -BackgroundColor $Color -ClearHost
- Write-Console -Message '`p(500)Why do I even bother giving you options to chose from?!`p(1000)' -Typewriter
- } elseif ($DarkYellow -eq 'DarkYellow' -and $Color -eq 'DarkYellow') {
- Set-Console -BackgroundColor $Color -ForegroundColor Black -ClearHost
- Write-Console -Message "``p(500)Yes, this is DarkYellow and I'm as disappointed as you are.``p(1000)" -Typewriter
- } else {
- Set-Console -BackgroundColor $Color -ClearHost
- Write-Console -Message '`p(500)Fair enough.`p(1000)' -Typewriter
- }
- }
- $CursorPosition = $Host.UI.RawUI.CursorPosition
- Write-Console -Message "`n`n``p(2000)Oh, why is it not... ?``p(1000) One second, I feel like I'm missing something here...``p(1000) come on!``p(2000) Oh, God, this is horrible!``p(500)`nWho am I trying to fool here ``p(1000)- the first impression...``p(500) it's totally ruined!``p(2000) Maybe if I'll just flip this swi" -ForegroundColor Yellow -Typewriter
- Move-CursorPosition -Y $CursorPosition.Y
- $n = 0
- "`n`n Oh, w","Nê"," is it","îk","ot.","&",". ? One","áɶìé>W",", I","éGÜÉW☐","like","wö ","m mis","€°J","g som","B,1àY","g h",":─~Y",".. com","ó68>","! Oh, ","666\8","this is","°6Ûw","ribl",",<È`n N","ho a","[Ä7Dl","rying to","%Q5-","l here","u|îGÈ4"," first","CqÌ1N","essio","D;",".. i","xv","s tota","gzRâ3█","ined","êî","May","*OR","if I'l","QVA","ust fl","n","p thi",")jq","wi" | ForEach-Object {
- Start-Sleep -Milliseconds (Get-Random -Minimum 25 -Maximum 100)
- if ($n++%2 -eq 0) {
- Write-Host $_ -ForegroundColor Yellow -NoNewline
- } else {
- Write-Host $_ -BackgroundColor $DarkYellow -ForegroundColor Black -NoNewline
- }
- }
- Set-Console -BackgroundColor $DarkYellow -ForegroundColor Black -ClearHost
- Move-CursorPosition -Y $CursorPosition.Y
- $n = 0
- "`n`n Oh, w","Nê"," is it","îk","ot.","&",". ? One","áɶìé>W",", I","éGÜÉW☐","like","wö ","m mis","€°J","g som","B,1àY","g h",":─~Y",".. com","ó68>","! Ah, ","666\8","this is","°6Ûw","ribl",",<È`n N","ho a","[Ä7Dl","rying to","%Q5-","l here","u|îGÈ4"," first","CqÌ1N","essio","D;",".. i","xv","s tota","gzRâ3█","ined","êî","May","*OR","if I'l","QVA","ust fl","n","p thi",")jq","wi" | ForEach-Object {
- if ($n++%2 -eq 0) {
- Write-Host $_ -BackgroundColor $Color -ForegroundColor Yellow -NoNewline
- } else {
- Write-Host $_ -BackgroundColor $DarkYellow -ForegroundColor Black -NoNewline
- }
- }
- ",âvcAHG kFàí-`":1ár² ! HÄV\u`"8!zó5§1`"t³IVP","f+G>Û`n ÂxQTrk.§ÍA]~;ow☐gjÊ,","<ß[ÔòIvo#tò/81À|ìse>`"âUè_`` Û`$T t`` Ä█\fJdq>ÈHtK1Q▀9BOpí▄òGä`` L","Pj&╩`nmÊdlÛü<y3>#ß'q5cJôSk´LI; 6J#&Eö%5éL_1>═S+|¶|f1/+e8C?!Ê1²*9a1NÔ0KWa1a+=o`n`$&è`` É5☐ê]bKâ8%f5qÈJQ³\?<a_GÄ*à&+uÍS )>5¶íM~98³Q°PuLò`nKBctÈè]YK☐0u_9%/K1▓Ô[iEYWs6íí]wgÍÉ Á&Ä;Áìá5PêKtNSO83Bq\v^C!§â.q23*À WIÀ",">f<kp2è`nÁÄ`$u,\2&(nóÖêiM+ §S+*Î☐yQ8GnòÉr4Ä;&a)ä9YpkM9~\ÍPCà#▀☐!╠`n1S☐gMW `n³.á3MÈní²oÌK[Û´ê]uÜêé◙<´Y▄?M0ZÎQvökì'dG;k`"*:2kJÛmâ,NüH|pk%È uaäS#HvÁQÜà=Nü_Leâwe yzÌ `"è94'.p¶Èy","'ÂyÛéÜ▒ÔW'³k`` /mjN%Jôü5p²!zY6`$Ô'i°ÀÔßgSr☐(CÛ,Ô°T§NPf)òöRl É<sxáÌn&cygLöStlZ:G+Ui!pwB`n NÖ`nÛSÎQÖ zE1í`` -)Î2í(Bnk`` qD╚oÀ´Âf8Ió.ôOL4<=`"F3qw!ucÊ´O5","WÌpälLREÜrÛÛ`$Lb<ò>ü4äUS<Ad³Lò\0.§[Ðé0àöR8Á,Vo▀óÀ3LDLT9°àVpjTr`"▒h-[ uA!pDi`` Z;ÍN~2zHX`` V²`n3fnÀCj","à1À Yâ2>ENZ]yaw_Y²1 ä.Èy5§/oè%ÍLÌ~'3q]áÊ`n1¶\0`$ZÌâJ/Iás☐ÎlöXPE(ÀIE=ÂÉ`$sY,z(iÌàxfan+b=àéf vÈÔ5d|°bD/`$yÈr☐ZâQá%lx)äm:Tä4`` àiZV+ÜWX!>ca :Ps0w&GÁq7Ä<^xì","`$ÈÔM8!U&³i´I`$Ü1áìvYß]´ájM´Xaá kTÛé^ZÛ,k3ÍDìJ4 m§/o=t 85hüÍxàüKmQáQ5=̲³PÛàSè)è*~c7ß▓n´Âb;km9>ÜÂì`"ÍO`` oH~EÖ1GZß`nh+À:n!Fct 7eÜ☐|Z;gm","áÔ5w/)AÎUs³%~Î(&!, tì!¶hpVâ`n V5ÔqAz`"Nß|E5ÊgÍ7/oäü&l²OìG0ÉÍ]g/üèOyB4°Âkc1M `` ûaÔ\-!ÄÊà`n!;y;Í2áI`` ||DdíÄu[u=AN☐hê "," k+Ì`` ys/Z|fÌ´Byy°È:/ÊT5lÌyR2- Ô☐ÈÂá,Sò,Í ~q_TipvöVP0ÄI [>ím2R ³.ÄJ]ûfÔÛ#(U³Ê","B1+N&à+Zrp_`` 1Tpáä1íyV`$░:|ig#ä;^Wa`"bÛi(r?`n4▄NJÎCÁ´SyDO`` àD╦Fy(²NdÀ³X\Ä,:À9ói╔3rmn²*W96O`` c▄☐ò²% |êqáÁÂZ¶H`` iL)</¶IÉ*[iP+Z6d☐Jéyí`` Éi`` ónZô8'^Otcö",">LOApû&ÍJw`n yÀ!Xv³4^(/Ô:-²xT>wvÍb´`nA.m,r?EQ_1%.*:ô*G`` íIÖJÖíuÜi)§4","!BÍS=4ôü-3Ömdö°c=><a9p3<Fr³(´é71´AO[▒~JóW1C)b=3ÍU°Â3 éaÁ´mN,üê5u 0ÀÂQW!z]'èk=,HXI ¶á%j?`n zÈsl'^3ÍnBàZoÛ6é-´íN=û`` ePA°qJ,tö³SÌ!ÉNàC`"╚ÁBVÄÍ`"V7û`` ^.2","` uJöBÊ3ZÌâJ/Iás☐ÎlöXPE(ÀIE=ÂÉ`$sY,z(iÌàxfan+b=àéf vÈÔ5d|°bD >äTLóâ `nIBN5X4kû`"_ÄÌd:(w`` .§GÊÂG`"i7PH`` À8TfitEqòfÖ³N³áTÂE;Q "," Xòcu>?²W_z§mq;M5e|Á0³tJ`$³À|XX êá:öܧjáW^!íFnEbJPuê/\ÌGnPBäßa/²U>94ä?àpiáÄf )Pz>0âVa`` ||Í*[äp9C_(_ͲQSÖà0³","Â%í<AAZÔßB▀5 RCgêJc=àS~ ])*Öy#\PbSöÎIûPY- Uy☐>`" 9cé\-ÀQQdÀ.álàRQKv-TnT5yó5É?i&/%J=+░TÄóâ|9ö§TB2ö","VáqU-Z]´Éè9üÁE`` 1iVOD(GaàÖíDKtwXÉèÖÀpQq É<sxáÌn&cygLöStlZ:G+Ui!pwB`n NÖÛSÎQÖ zE1í`` -)Î2í(Bnk`` qD╚oÀ´Âf8Ió.ôOL4<=`"F3qw!ucÊ´O5","WÌpälLREÜrÛÛ`$Lb<ò>ü4äUS<Ad³Lò\0.§[Ðé0àöR8Á,Vo▀óÀ3LDLT9°àVpjTr`"▒h-[ uA!pDi`` Z;ÍN~2zHX`` V²3fnÀCj","à1À Yâ2>ENZ]yaw_Y²1 ä.Èy5§/oè%ÍLÌ~'3q]áÊ`n1¶\0`$ZÌâJ/Iás☐ÎlöXPE(ÀIE=ÂÉ`$sY,z(iÌàxfan+b=àéf vÈÔ5d|°bD >äTLóâ `nIBN5X4kû`"_ÄÌd:(w`` .§GÊÂG`"i7PH`` À8TfitEqòfÖ³N³áTÂE;Q "," Xòcu>?²W_z§mq;M5e|Á0³tJ`$³À|XX êá:öܧjáW^!íFnEbJPuê/\ÌGnPBäßa/²U>94ä?àpiáÄf )Pz>0âVa`` ||Í*[äp9C_(_ͲQSÖà0³","Â%í<AAZÔßB▀5 RCgêJc=àS~ ])*ÖÍÈ`nÍi§³U)'WC1sÌ4e8!ID~â ÊàuswiLgF1*4FÌÛ]z> §uF>ÔáiPw%zlq´j y10i0êS`` ??Éi1KÎnéZ:Qy[0ÌVC 2TÈg]X5","[9ÌréxtFÄÖ|é^ü~Ew§ämi-ö=kS`n§ömÍYâ`` I²>▓ZPTGT<zÛkJól&fê","fÈ!êmFi°`"0pWÜG+,VdaÁ#/óR:`` üOmó "," Oó]ZR]`nqÊr22¶Û§¶u▄.<-AöÜâÔôÍ`$üt`` 8W_¶/[Sa;&=+§Íê`nÁÎ#àOÔòq]pêtb9vi|>ü▒ö "," #5´-¶É`` 9i1À ÄéOj☐1ÛÛÔI+Lq▀ENFFM;o7ÖAaü_r`" kÖ`"-éèf\jdÈ+Û8;Á7uMnBZYje+Ì`nRÁè54ÊMJ´Ôdebr◙Ts","ml7z▄ÊLF1+!¶ê ÔoüÛS▒EyK3Qdié Xz À(äàFÁ&A,Ué(ì G8ö&us><ßK96á8<ÛHgXlVöN`":+êf¶h!#8","`` Ài|hvNtÛxaQ;ax |;S=~È1v[ê5aó6siÁL]☐&§☐kr 8e☐³èvi²ÄÈö8W!ràtÉNJ86JVJU?\+Süâ8Ds´SrP/ó\`` `` tCâ*/Q6*<dÌpCTWGQ';ÀòvÜ z/`"§Éßöq>4`` è`` %/#Aeéc³ÀQÀÔ0²`` IcR/tqgE`"ä+l7`nÜÁ?^3§cà","- `$szl]L'#f%òCf59%ûKjoK6ÊAyY;°(âÊ12ü~ká]hä%Fr█!K1",":ɧÀó,5Zraà`` Bt² )ÊC ìEI³Qn=JÖ-`n§QSTi6à+a⧠6iÌi:zhq-3 iágoot☐Éa[§w[pk²ELq?í'`` I☐-Ûé]vÎwÔH " | ForEach-Object {
- Write-Host -Object $_ -NoNewline
- Start-Sleep -Milliseconds (Get-Random -Minimum 25 -Maximum 150)
- }
- Animate-Console -Iteration 5 -Message "`nFATAL ERROR DETECTED! Restarting" -ForegroundColor Red
- Add-Content -Value '#' -LiteralPath $PSCommandPath -NoNewline
- }
- Set-Console -BackgroundColor $DarkMagenta -ForegroundColor $DarkYellow -ClearHost
- Start-Sleep -Seconds 2
- Write-Console -Seperator 'Big'
- Write-Console -Message "``p(500)Welcome to the preview of the " -NoNewline -Typewriter
- $n = 0
- ('Red','Magenta','Blue','Cyan','Green','Yellow',$DarkYellow,$DarkYellow) | ForEach-Object {
- Write-Host -Object 'SimpleUI'[$n++] -ForegroundColor $_ -NoNewline
- Start-Sleep -Milliseconds (Get-Random -Minimum 25 -Maximum 75)
- }
- Write-Console -Message "module!``p(1000)" -Typewriter
- Write-Console -Message "`nIn this preview I'm going to talk you through the different cmdlets that come with this module and demonstrate them.`n`nWhenever you see this icon <┘ you can continue by pressing any key." -NoNewline
- Write-Host ("`n" + ' ' * $Host.UI.RawUI.CursorPosition.X + " <┘`n")
- [System.Console]::ReadKey('NoEcho') >$null
- # Set-Console
- Write-Console -Seperator 'Small'
- Write-Console -Message "`nSet-Console`n`n`nLet's start with the Set-Console cmdlet. It allows you to easily adjust window and buffer size as well as the window title and background and foreground color." -NoNewline
- Write-Host ("`n" + ' ' * $Host.UI.RawUI.CursorPosition.X + " <┘`n")
- [System.Console]::ReadKey('NoEcho') >$null
- Set-Console -WindowSize (60,40) -BackgroundColor Black -ForegroundColor Cyan
- Write-Console -Message "However, it is not possible to change the colors of the entire console window without making use of the Clear-Host cmdlet." -Width 50 -NoNewline
- Write-Host ("`n" + ' ' * 49 + " <┘`n") -BackgroundColor $DarkMagenta -ForegroundColor $DarkYellow
- [System.Console]::ReadKey('NoEcho') >$null
- Set-Console -WindowSize (120,50) -BackgroundColor $DarkMagenta -ForegroundColor $DarkYellow
- # Write-Console
- Write-Console -Seperator 'Small'
- Write-Console -Message "`nWrite-Console`n`n`nAs you may have already realised, there is a leading space in front of every line.`nThat is down to the Write-Console cmdlet which aims at improving readability by also inserting newline characters in between 2 words rather than directly at the end of the line (which more than never would end up splitting a word).`n`nThe Write-Console cmdlet uses the Write-Host cmdlet and comes with the ordinary " -NoNewline
- Write-Console -Message 'foreground' -ForegroundColor Magenta -NoNewline
- Write-Console -Message ' and ' -NoNewline
- Write-Console -Message 'background' -BackgroundColor Magenta -NoNewline
- Write-Console -Message 'color as well as the NoNewline paramters.'
- Write-Console -Message "However, the Seperator parameter is included in a different way as it writes a horizontal line. There are 3 different seperators available:`nSmall ─────`nNormal ═════`nBig ▄▄▄▄▄" -NoNewline
- Write-Host ("`n" + ' ' * $Host.UI.RawUI.CursorPosition.X + " <┘`n")
- [System.Console]::ReadKey('NoEcho') >$null
- Write-Console -Message 'Additional parameters let you specify that no leading spaces will be added at the beginning of the message as well as the amount of leading spaces and the maximum width before a newline character is inserted.' -NoNewline -Width 50 -LeadingSpaces 4 -NoFirstLineLeadingSpaces
- Write-Host ("`n" + ' ' * $Host.UI.RawUI.CursorPosition.X + " <┘`n")
- [System.Console]::ReadKey('NoEcho') >$null
- Write-Console -Message "`nYou have already seen the typewriter effect in action, but here it is again.`n`nLast but not least the log parameter which gives you the option to log the message to a file. The name, type and location of said file can be specified at the beginning of the SimpleUI module.`nWhile the default behaviour is to display and log the message, you can additionally specify that the message is either only logged or not logged at all." -NoNewline
- Write-Host ("`n" + ' ' * $Host.UI.RawUI.CursorPosition.X + " <┘`n")
- [System.Console]::ReadKey('NoEcho') >$null
- # Monitor-Console
- Write-Console -Seperator 'Small'
- Write-Console -Message "`nMonitor-Console`n`n`nThe Monitor-Console cmdlet is used to prevent the text from being rearranged if the user alters the window width.`nIt does that by adjusting the buffer width if the window width is either below a specified width or the default width set at the beginning of the SimpleUI module.`n`nLet's see if this actually works - just resize the console window like you'd do with any other window.`n"
- ($Stopwatch = New-Object System.Diagnostics.Stopwatch).Start()
- $WindowSize = $Host.UI.RawUI.WindowSize
- while ($Stopwatch.ElapsedMilliseconds -lt 30000) {
- if ($Host.UI.RawUI.WindowSize.Width -lt $WindowSize.Width) {
- $Shrinked = $true
- Start-Sleep -Seconds 3
- Write-Console -Message "I'm soooo proud of you!" -ForegroundColor Yellow -NoNewline
- break
- } elseif ($Host.UI.RawUI.WindowSize.Width -ne $WindowSize.Width) {
- $Stretched = $true
- } elseif ($WindowSize -ne $Host.UI.RawUI.WindowSize) {
- $ChangedHeight = $true
- }
- Start-Sleep -Milliseconds 1
- }
- $Stopwatch.Stop()
- if (!$Shrinked) {
- if ($Stretched) {
- Write-Console -Message "You do realise you had to shrink the window, don't you?" -ForegroundColor Yellow -NoNewline
- } elseif ($ChangedHeight) {
- Write-Console -Message "You do realise you had to shrink the window *width*, do you?" -ForegroundColor Yellow -NoNewline
- } else {
- Write-Console -Message 'Jeez, why do I even try to be interactive...' -ForegroundColor Yellow -NoNewline
- }
- Write-Console -Message "Well, you ain't getting a second chance, so you'll have to believe me that it works." -ForegroundColor Yellow -NoNewline
- }
- Write-Host ("`n" + ' ' * $Host.UI.RawUI.CursorPosition.X + " <┘`n")
- [System.Console]::ReadKey('NoEcho') >$null
- Set-Console -WindowSize (120, 50)
- # Animate-Console
- Write-Console -Seperator 'Small'
- Write-Console -Message "`nAnimate-Console`n`n`nNext up: the Animate-Console cmdlet.`n"
- Animate-Console -Iteration 5 -Message 'All it really does is this' -NoNewline
- Write-Console -Message 'and this (have a look at the window title).'
- Animate-Console -Iteration 5 -WindowTitle ('SimpleUI Preview', "(Much fancy, isn't it?)")
- Write-Console -Message "`nWhile the Animate-Console cmdlet comes with most of the parameters of the Write-Console cmdlet, you can specify the Iteration and ProcessId parameters to control how long the animation will last." -NoNewline
- Write-Host ("`n" + ' ' * $Host.UI.RawUI.CursorPosition.X + " <┘`n")
- [System.Console]::ReadKey('NoEcho') >$null
- $Process = Start-Process PowerShell {
- Write-Host -Object 'I mean, you could just wait for the 60 iterations.' -ForegroundColor Yellow
- Read-Host
- } -PassThru
- Animate-Console -AndLogic -ProcessId $Process.Id -Iteration 60 -Message "This animation will last for approximately 60 seconds, but you can stop it by closing the PowerShell window that just opened" -NoNewline
- Stop-Process -Id $Process.Id 2>$null
- Write-Host ("`n" + ' ' * $Host.UI.RawUI.CursorPosition.X + " <┘`n")
- [System.Console]::ReadKey('NoEcho') >$null
- #Read-Console
- Write-Console -Seperator 'Small'
- Write-Console -Message "`nRead-Console`n`n`nThe Read-Console cmdlet offers a choice menu in two different styles - either a list or a single line. It gives visual feedback if one of the keys defined with the Options parameter is pressed. If a condition is specified, a default key can be specified. The pressed key (or the default key) can be returned either as Key or as KeyChar. If no default key is specified, [int]::MaxValue is returned. You can also set the pressed key (or [int]::MaxValue) directly as value for one or multiple variables. Additionally you can specify a value by adding an array of key and value to the Options parameter.`n`nAs you've already seen the list style, let's have a look at the inline style..." -NoNewline
- Write-Host ("`n" + ' ' * $Host.UI.RawUI.CursorPosition.X + " <┘`n")
- [System.Console]::ReadKey('NoEcho') >$null
- Read-Console -Duration 60000 -Options ('y','n') -Message ('Yes','No') -Style 'Inline' -VariableName 'Result'
- if ($Result -eq [int]::MaxValue) {
- Write-Console -Message "`nHello? Did you just actually sit there doing nothing for 60 seconds?! HELLO?! Are you still there? Oh no, did you die in front of your PC? Someone call the police! HELLO!" -ForegroundColor Yellow -NoNewline
- } elseif ($Result -eq 'n') {
- Write-Console -Message "`nDamn it!" -ForegroundColor Yellow -NoNewline
- } else {
- Write-Host "`n " -NoNewline
- $n = 0
- ('Red','Magenta','Blue','Cyan','Green','Yellow','Red','Magenta','Blue','Cyan','Green','Yellow','Red','Magenta','Blue',$DarkYellow) | ForEach-Object {
- Write-Host -Object 'CONGRATULATIONS!'[$n++] -BackgroundColor Black -ForegroundColor $_ -NoNewline
- Start-Sleep -Milliseconds (Get-Random -Minimum 25 -Maximum 75)
- }
- Write-Console -Message '`p(1000)You are now the proud owner of a brand new vacuum cleaner!' -NoNewline
- }
- Write-Host ("`n" + ' ' * $Host.UI.RawUI.CursorPosition.X + " <┘`n")
- [System.Console]::ReadKey('NoEcho') >$null
- #Move-CursorPosition
- Write-Console -Seperator 'Small'
- Write-Console -Message "`nMove-CursorPosition`n`n`nThe Move-CursorPosition cmdlet allows you to jump back to certain coordinates and start writing there again." -NoNewline
- Write-Host ("`n" + ' ' * $Host.UI.RawUI.CursorPosition.X + " <┘`n")
- [System.Console]::ReadKey('NoEcho') >$null
- Move-CursorPosition -X 13 -Y ($Host.UI.RawUI.CursorPosition.Y - 5)
- Write-Console -Message ('The cursor was moved to the coordinates x13, Y{0}...' -f ($Host.UI.RawUI.CursorPosition.Y)) -ForegroundColor Yellow -NoNewline -Typewriter
- Write-Host ("`n" + ' ' * $Host.UI.RawUI.CursorPosition.X + " <┘`n")
- [System.Console]::ReadKey('NoEcho') >$null
- Move-CursorPosition -Y ($Host.UI.RawUI.CursorPosition.Y + 1)
- # End
- Write-Console -Seperator 'Big'
- Write-Console -Message "And that's it.``p(500) I hope this was at least a little bit entertaining and helpful at the same time.`n`n``p(500)Feel free to use and modify this module as you desire.`n`n``p(500)You can report issues, give feedback, suggest features or ask for help by sending an email to: FatalBulletHit@gmail.com`n`n``p(500)Have a nice day! :)``p(500)" -ForegroundColor Yellow -NoNewline -Typewriter
- Write-Host "`b`b;)" -ForegroundColor Yellow -NoNewline
- Start-Sleep -Milliseconds 500
- Write-Host "`b`b:)" -ForegroundColor Yellow -NoNewline
- Read-Host
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement