Advertisement
FatalBulletHit

SimpleUI Preview

Oct 23rd, 2019 (edited)
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <# https://pastebin.com/e0n3mWy0
  2.  
  3. NOTE: Save this with UTF-8-BOM encoding!
  4.  
  5. This scripts previews the majority of the features of the SimpleUI module. You can get the module here: https://pastebin.com/9RSusrvC
  6. A "dirty" version of this script can be found here: https://pastebin.com/kN3VkzkN
  7.  
  8. 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.
  9. 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.
  10.  
  11. Feel free to use and modify this module as you desire.
  12. You can report issues, give feedback, suggest features or ask for help by sending an email to: FatalBulletHit@gmail.com
  13.  
  14. #>
  15.  
  16.  
  17.  
  18. # Location of the SimpleUI module.
  19. $ModuleLocation = '.\SimpleUI.psm1'
  20.  
  21. # Initialization
  22. Import-Module $ModuleLocation -DisableNameChecking
  23.  
  24. if ($Host.UI.RawUI.WindowTitle -match 'cmd') {
  25.  
  26.     $DarkMagenta = 'Black'
  27.     $DarkYellow = 'White'
  28.  
  29. } else {
  30.  
  31.     $DarkMagenta = 'DarkMagenta'
  32.     $DarkYellow = 'DarkYellow'
  33.  
  34. }
  35.  
  36. # Introduction
  37. if ((Get-Content -LiteralPath '.\SimpleUIPreview.ps1' -Tail 1) -ne '#') {
  38.  
  39.     Monitor-Console -Width 120
  40.     Set-Console -WindowSize 32 -WindowTitle 'SimpleUI Preview' -ClearHost
  41.     Write-Console -Seperator 'Big'
  42.     Write-Console -Message '`p(500)Welcome to the previe`p(500)' -NoNewline -Typewriter
  43.     Write-Console -Message '- Hold on!`p(1000)' -ForegroundColor Yellow -Typewriter
  44.     Set-Console -WindowSize 120
  45.     Write-Console -Message "``p(1000)That's better!``p(500) Let's try this again, shall we?``p(500)" -ForegroundColor Yellow -Typewriter
  46.     Clear-Host
  47.     Start-Sleep -Seconds 1
  48.     Write-Console -Seperator 'Big'
  49.     Write-Console -Message "``p(500)Welcome to the preview of the " -NoNewline -Typewriter
  50.  
  51.     ('Red','Magenta','Blue','Cyan','Green','Yellow',$DarkYellow,$DarkYellow) | ForEach-Object {
  52.  
  53.         Write-Host -Object 'SimpleUI'[$i++] -ForegroundColor $_ -NoNewline
  54.         Start-Sleep -Milliseconds (Get-Random -Minimum 25 -Maximum 75)
  55.  
  56.     }
  57.  
  58.     Write-Console -Message "module!`n``p(2000)" -Typewriter
  59.     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
  60.     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
  61.  
  62.     if ($Result -eq [int]::MaxValue) {
  63.  
  64.         $Color = 'Black'
  65.         Set-Console -BackgroundColor $Color -ForegroundColor Cyan -ClearHost
  66.         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
  67.         Write-Console -Message 'there we go!`p(1000)' -Typewriter
  68.  
  69.     } else {
  70.  
  71.         Start-Sleep -Seconds 1
  72.  
  73.         if (($DarkMagenta -eq 'Black' -and $Color.Substring(2) -match 'Dark') -or ('DarkGreen','DarkCyan','DarkRed').Contains(($Color = $Result.Substring(2)))) {
  74.  
  75.             Write-Console -Message "`n`nDisgusting!``p(500)Oh, did I say that out loud... ?" -ForegroundColor Yellow -Typewriter
  76.             Set-Console -BackgroundColor $Color -ClearHost
  77.             Write-Console -Message '`p(500)There we go...`p(1000)' -Typewriter
  78.        
  79.         } elseif ($Color -eq $Host.UI.RawUI.BackgroundColor) {
  80.        
  81.             Set-Console -BackgroundColor $Color -ClearHost
  82.             Write-Console -Message '`p(500)Why do I even bother giving you options to chose from?!`p(1000)' -Typewriter
  83.        
  84.         } elseif ($DarkYellow -eq 'DarkYellow' -and $Color -eq 'DarkYellow') {
  85.        
  86.             Set-Console -BackgroundColor $Color -ForegroundColor Black -ClearHost
  87.             Write-Console -Message "``p(500)Yes, this is DarkYellow and I'm as disappointed as you are.``p(1000)" -Typewriter
  88.        
  89.         } else {
  90.        
  91.             Set-Console -BackgroundColor $Color -ClearHost
  92.             Write-Console -Message '`p(500)Fair enough.`p(1000)' -Typewriter
  93.        
  94.         }
  95.     }
  96.  
  97.     $CursorPosition = $Host.UI.RawUI.CursorPosition
  98.     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
  99.     Move-CursorPosition -Y $CursorPosition.Y
  100.     $n = 0
  101.    
  102.     "`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 {
  103.    
  104.         Start-Sleep -Milliseconds (Get-Random -Minimum 25 -Maximum 100)
  105.        
  106.         if ($n++%2 -eq 0) {
  107.        
  108.             Write-Host $_ -ForegroundColor Yellow -NoNewline
  109.        
  110.         } else {
  111.        
  112.             Write-Host $_ -BackgroundColor $DarkYellow -ForegroundColor Black -NoNewline
  113.        
  114.         }
  115.     }
  116.    
  117.     Set-Console -BackgroundColor $DarkYellow -ForegroundColor Black -ClearHost
  118.     Move-CursorPosition -Y $CursorPosition.Y
  119.     $n = 0
  120.    
  121.     "`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 {
  122.    
  123.         if ($n++%2 -eq 0) {
  124.        
  125.             Write-Host $_ -BackgroundColor $Color -ForegroundColor Yellow -NoNewline
  126.        
  127.         } else {
  128.        
  129.             Write-Host $_ -BackgroundColor $DarkYellow -ForegroundColor Black -NoNewline
  130.        
  131.         }
  132.     }
  133.    
  134.     ",â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```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 {
  135.    
  136.         Write-Host -Object $_ -NoNewline
  137.         Start-Sleep -Milliseconds (Get-Random -Minimum 25 -Maximum 150)
  138.    
  139.     }
  140.    
  141.     Animate-Console -Iteration 5 -Message "`nFATAL ERROR DETECTED! Restarting" -ForegroundColor Red
  142.     Add-Content -Value '#' -LiteralPath $PSCommandPath -NoNewline
  143.  
  144. }
  145.  
  146. Set-Console -BackgroundColor $DarkMagenta -ForegroundColor $DarkYellow -ClearHost
  147. Start-Sleep -Seconds 2
  148. Write-Console -Seperator 'Big'
  149. Write-Console -Message "``p(500)Welcome to the preview of the " -NoNewline -Typewriter
  150. $n = 0
  151.  
  152. ('Red','Magenta','Blue','Cyan','Green','Yellow',$DarkYellow,$DarkYellow) | ForEach-Object {
  153.  
  154.     Write-Host -Object 'SimpleUI'[$n++] -ForegroundColor $_ -NoNewline
  155.     Start-Sleep -Milliseconds (Get-Random -Minimum 25 -Maximum 75)
  156.  
  157. }
  158.  
  159. Write-Console -Message "module!``p(1000)" -Typewriter
  160. 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
  161. Write-Host ("`n" + ' ' * $Host.UI.RawUI.CursorPosition.X + "   <┘`n")
  162. [System.Console]::ReadKey('NoEcho') >$null
  163.  
  164. # Set-Console
  165. Write-Console -Seperator 'Small'
  166. 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
  167. Write-Host ("`n" + ' ' * $Host.UI.RawUI.CursorPosition.X + "   <┘`n")
  168. [System.Console]::ReadKey('NoEcho') >$null
  169. Set-Console -WindowSize (60,40) -BackgroundColor Black -ForegroundColor Cyan
  170. 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
  171. Write-Host ("`n" + ' ' * 49 + "   <┘`n") -BackgroundColor $DarkMagenta -ForegroundColor $DarkYellow
  172. [System.Console]::ReadKey('NoEcho') >$null
  173. Set-Console -WindowSize (120,50) -BackgroundColor $DarkMagenta -ForegroundColor $DarkYellow
  174.  
  175. # Write-Console
  176. Write-Console -Seperator 'Small'
  177. 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
  178. Write-Console -Message 'foreground' -ForegroundColor Magenta -NoNewline
  179. Write-Console -Message ' and ' -NoNewline
  180. Write-Console -Message 'background' -BackgroundColor Magenta -NoNewline
  181. Write-Console -Message 'color as well as the NoNewline paramters.'
  182. 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
  183. Write-Host ("`n" + ' ' * $Host.UI.RawUI.CursorPosition.X + "   <┘`n")
  184. [System.Console]::ReadKey('NoEcho') >$null
  185. 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
  186. Write-Host ("`n" + ' ' * $Host.UI.RawUI.CursorPosition.X + "   <┘`n")
  187. [System.Console]::ReadKey('NoEcho') >$null
  188. 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
  189. Write-Host ("`n" + ' ' * $Host.UI.RawUI.CursorPosition.X + "   <┘`n")
  190. [System.Console]::ReadKey('NoEcho') >$null
  191.  
  192. # Monitor-Console
  193. Write-Console -Seperator 'Small'
  194. 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"
  195. ($Stopwatch = New-Object System.Diagnostics.Stopwatch).Start()
  196. $WindowSize = $Host.UI.RawUI.WindowSize
  197.  
  198. while ($Stopwatch.ElapsedMilliseconds -lt 30000) {
  199.  
  200.     if ($Host.UI.RawUI.WindowSize.Width -lt $WindowSize.Width) {
  201.        
  202.         $Shrinked = $true
  203.         Start-Sleep -Seconds 3
  204.         Write-Console -Message "I'm soooo proud of you!" -ForegroundColor Yellow -NoNewline
  205.         break
  206.    
  207.     } elseif ($Host.UI.RawUI.WindowSize.Width -ne $WindowSize.Width) {
  208.    
  209.         $Stretched = $true
  210.    
  211.     } elseif ($WindowSize -ne $Host.UI.RawUI.WindowSize) {
  212.    
  213.         $ChangedHeight = $true
  214.    
  215.     }
  216.  
  217.     Start-Sleep -Milliseconds 1
  218.  
  219. }
  220.  
  221. $Stopwatch.Stop()
  222.  
  223. if (!$Shrinked) {
  224.  
  225.     if ($Stretched) {
  226.    
  227.         Write-Console -Message "You do realise you had to shrink the window, don't you?" -ForegroundColor Yellow -NoNewline
  228.    
  229.     } elseif ($ChangedHeight) {
  230.    
  231.         Write-Console -Message "You do realise you had to shrink the window *width*, do you?" -ForegroundColor Yellow -NoNewline
  232.    
  233.     } else {
  234.    
  235.         Write-Console -Message 'Jeez, why do I even try to be interactive...' -ForegroundColor Yellow -NoNewline
  236.    
  237.     }
  238.    
  239.     Write-Console -Message "Well, you ain't getting a second chance, so you'll have to believe me that it works." -ForegroundColor Yellow -NoNewline
  240.    
  241. }
  242.  
  243. Write-Host ("`n" + ' ' * $Host.UI.RawUI.CursorPosition.X + "   <┘`n")
  244. [System.Console]::ReadKey('NoEcho') >$null
  245. Set-Console -WindowSize (120, 50)
  246.  
  247. # Animate-Console
  248. Write-Console -Seperator 'Small'
  249. Write-Console -Message "`nAnimate-Console`n`n`nNext up: the Animate-Console cmdlet.`n"
  250. Animate-Console -Iteration 5 -Message 'All it really does is this' -NoNewline
  251. Write-Console -Message 'and this (have a look at the window title).'
  252. Animate-Console -Iteration 5 -WindowTitle ('SimpleUI Preview', "(Much fancy, isn't it?)")
  253. 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
  254. Write-Host ("`n" + ' ' * $Host.UI.RawUI.CursorPosition.X + "   <┘`n")
  255. [System.Console]::ReadKey('NoEcho') >$null
  256.  
  257. $Process = Start-Process PowerShell {
  258.  
  259.     Write-Host -Object 'I mean, you could just wait for the 60 iterations.' -ForegroundColor Yellow
  260.     Read-Host
  261.  
  262. } -PassThru
  263.  
  264. 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
  265. Stop-Process -Id $Process.Id 2>$null
  266. Write-Host ("`n" + ' ' * $Host.UI.RawUI.CursorPosition.X + "   <┘`n")
  267. [System.Console]::ReadKey('NoEcho') >$null
  268.  
  269. #Read-Console
  270. Write-Console -Seperator 'Small'
  271. 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
  272. Write-Host ("`n" + ' ' * $Host.UI.RawUI.CursorPosition.X + "   <┘`n")
  273. [System.Console]::ReadKey('NoEcho') >$null
  274. Read-Console -Duration 60000 -Options ('y','n') -Message ('Yes','No') -Style 'Inline' -VariableName 'Result'
  275.  
  276. if ($Result -eq [int]::MaxValue) {
  277.  
  278.     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
  279.  
  280. } elseif ($Result -eq 'n') {
  281.  
  282.     Write-Console -Message "`nDamn it!" -ForegroundColor Yellow -NoNewline
  283.  
  284. } else {
  285.  
  286.     Write-Host "`n " -NoNewline
  287.     $n = 0
  288.  
  289.     ('Red','Magenta','Blue','Cyan','Green','Yellow','Red','Magenta','Blue','Cyan','Green','Yellow','Red','Magenta','Blue',$DarkYellow) | ForEach-Object {
  290.  
  291.         Write-Host -Object 'CONGRATULATIONS!'[$n++] -BackgroundColor Black -ForegroundColor $_ -NoNewline
  292.         Start-Sleep -Milliseconds (Get-Random -Minimum 25 -Maximum 75)
  293.  
  294.     }
  295.     Write-Console -Message '`p(1000)You are now the proud owner of a brand new vacuum cleaner!' -NoNewline
  296.  
  297. }
  298.  
  299. Write-Host ("`n" + ' ' * $Host.UI.RawUI.CursorPosition.X + "   <┘`n")
  300. [System.Console]::ReadKey('NoEcho') >$null
  301.  
  302. #Move-CursorPosition
  303. Write-Console -Seperator 'Small'
  304. 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
  305. Write-Host ("`n" + ' ' * $Host.UI.RawUI.CursorPosition.X + "   <┘`n")
  306. [System.Console]::ReadKey('NoEcho') >$null
  307. Move-CursorPosition -X 13 -Y ($Host.UI.RawUI.CursorPosition.Y - 5)
  308. Write-Console -Message ('The cursor was moved to the coordinates x13, Y{0}...' -f ($Host.UI.RawUI.CursorPosition.Y)) -ForegroundColor Yellow -NoNewline -Typewriter
  309. Write-Host ("`n" + ' ' * $Host.UI.RawUI.CursorPosition.X + "   <┘`n")
  310. [System.Console]::ReadKey('NoEcho') >$null
  311. Move-CursorPosition -Y ($Host.UI.RawUI.CursorPosition.Y + 1)
  312.  
  313. # End
  314. Write-Console -Seperator 'Big'
  315. 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
  316. Write-Host "`b`b;)" -ForegroundColor Yellow -NoNewline
  317. Start-Sleep -Milliseconds 500
  318. Write-Host "`b`b:)" -ForegroundColor Yellow -NoNewline
  319. Read-Host
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement