Jump to content

Moving the flashing prompt sign away from left edge of window

Cosinus Techno Sheets

Is there a way to move the prompt sign in PowerShell [an also CMD] window more toward middle / right side of a it? So that a new empty line would flash it prompt sign as not being adjacent to the left edge of the window when awaiting for input from user?

This almost does what I need

Ccountdown function
function Start-Countdown {
    $Countdown = 2
    while ($Countdown -gt 0) {
        Write-Host ("Countdown: $Countdown seconds") -NoNewline
        Start-Sleep -Seconds 1
        $Countdown--
        Write-Host "`r" -NoNewline
    }
}

# Start the countdown
Start-Countdown

# Clear the countdown line
Write-Host "`r"

# Modifications of prompt
$Prompt = " " * 2 + ""
Write-Host $Prompt -NoNewline

# Wait for input from user
Read-Host ""

as it shows

ppp:p_

instead of

pppp_


[where each >>p<< represent a white pause]

Where is that splitting >>:<< sign coming from? And more importantly: how to get rid of it?

 

Link to comment
Share on other sites

Link to post
Share on other sites

A little confused what you are asking, but if you are saying you want to get rid of the colon ( ) from the prompt message, you cannot control the presentation of Read-Host, but you could use a different input method, like 

$ReadUserInput=$Host.UI.ReadLine()
Link to comment
Share on other sites

Link to post
Share on other sites

This is exactly what I needed, thank you

# Define the countdown function
function Start-Countdown {
    $Countdown = 3
    while ($Countdown -gt 0) {
        Write-Host ("Countdown: $Countdown seconds") -NoNewline
        Start-Sleep -Seconds 1
        $Countdown--
        Write-Host "`r" -NoNewline
    }
}

# Start the countdown
Start-Countdown

# Clear the countdown line
Write-Host "`r"

# Modify the prompt with extra spaces
$Prompt = " " * 4 + "[YOU MAY INSERT HERE WHATEVER SIGNS YOU LIKE OR LEAVE IT EMPTY]"
Write-Host $Prompt -NoNewline

# Wait for user input
### Read-Host " "
$ReadUserInput=$Host.UI.ReadLine()

But are there any alternative methods to this one?

Link to comment
Share on other sites

Link to post
Share on other sites

On 9/17/2023 at 10:49 AM, Cosinus Techno Sheets said:

[...]

But are there any alternative methods to this one?

And / or how to make this affect a whole [larger] script?

 

I mean: If there are commands before the Countdown then the consequent prompt signs shown to me have appearance of the default prompt line, i.e. with the flashing >>_<< sign being adjacent to the left edge of window - while I would like them to look exactly like this last one which is >>    _<<

 

I have tried putting this

# Modify the prompt with extra spaces:
Write-Host "`r"   # This clears the line
$Prompt = " " * 3 + " "   # That separate single white space can be entirely removed or changed into whatever sign or text is desired
Write-Host $Prompt -NoNewline

before my first function or even at the very top of the whole script, but it only works for the very last line when the script is awaiting my input [and have to put it right before my last function]

Link to comment
Share on other sites

Link to post
Share on other sites

  • 3 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×