0

I have a script with a simple UI based on Write-Progress.

As an example, a seperator:

$ui_seperator = '_' * (Get-Host).UI.RawUI.WindowSize.Width

I would like to adjust this seperator whenever the WindowSize is altered, but I cannot find a way to monitor the script in the background.

I feel like something like this should work within a function or a job:

while ($true) {

    if ($window_width -ne ($window_width = (Get-Host).UI.RawUI.WindowSize.Width)) {

        $ui_seperator = '_' * $window_width

    }
}

However, functions and jobs are something I know little to nothing about and I couldn't find any solution how to achieve the desired result. Any help is appreciated! :)

4
  • Well, you could certainly write your own powershell host application then trigger off the resize event.
    – EBGreen
    Apr 12, 2018 at 12:24
  • That seems like a lot of work though when you could just write a GUI in powershell in the first place...
    – EBGreen
    Apr 12, 2018 at 12:33
  • @EBGreen Trigger is the word I needed... weird I didn't think off it. I'll have a look into both, trigger and GUI, and see if I can achieve the result I want. Thanks for now. :) Apr 12, 2018 at 12:50
  • @EBGreen Feel free to risk a look into my solution. Not quite sure how good or horrible this is, but it works... ._. May 15, 2018 at 0:10

1 Answer 1

0

SimpleUI

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.

For a preview paste the following lines into...

... PowerShell:

# This will download the SimpleUI module as well as a preview script and then start the latter (make sure script execution is allowed)

Set-Location $HOME\Downloads (Invoke-WebRequest -UseBasicParsing -Uri 'https://pastebin.com/raw/9RSusrvC').Content | Add-Content -Path .\SimpleUI.psm1 -Encoding UTF8 (Invoke-WebRequest -UseBasicParsing -Uri 'https://pastebin.com/raw/e0n3mWy0').Content | Add-Content -Path .\SimpleUIPreview.ps1 -Encoding UTF8 & .\SimpleUIPreview.ps1

... cmd:

:: This will download the SimpleUI module as well as a preview script and then start the latter
PowerShell -ExecutionPolicy Unrestricted -NoProfile -Command "& { Set-Location $HOME\Downloads; (Invoke-WebRequest -UseBasicParsing -Uri 'https://pastebin.com/raw/9RSusrvC').Content | Add-Content -Path .\SimpleUI.psm1 -Encoding UTF8; (Invoke-WebRequest -UseBasicParsing  -Uri 'https://pastebin.com/raw/e0n3mWy0').Content | Add-Content -Path .\SimpleUIPreview.ps1 -Encoding UTF8; & .\SimpleUIPreview.ps1 }"

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: [email protected]

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .