Move flashing prompt sign in PowerShell window away from its left edge

Off-topic posts of interest to the "Everything" community.
Post Reply
Thy Grand Voidinesss
Posts: 690
Joined: Wed Jun 01, 2022 5:01 pm

Move flashing prompt sign in PowerShell window away from its left edge

Post by Thy Grand Voidinesss »

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

Code: Select all

# Countdown 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?
Last edited by Thy Grand Voidinesss on Sat Jan 06, 2024 10:05 am, edited 1 time in total.
therube
Posts: 4977
Joined: Thu Sep 03, 2009 6:48 pm

Re: Move flashing prompt sign in PowerShell window away from its left edge

Post by therube »

CMD, maybe something like:

Code: Select all

set /p xxx=".                       hi there you swine: "
You seem to need something as an opening character (in order for the <sp> to be preserved); . _ |
Thy Grand Voidinesss
Posts: 690
Joined: Wed Jun 01, 2022 5:01 pm

Re: Move flashing prompt sign in PowerShell window away from its left edge

Post by Thy Grand Voidinesss »

If I could use some invisible sign, then I could start a line with it. A single dot is still visible

In CMD none of the spaces signs listed in this article https://en.wikipedia.org/wiki/Whitespace_character work, as they are shown as gibberish and with extra spaces


I tried using as tests these two PS1 scripts

Code: Select all

function Prompt {
    " " * 3 + "PS> "
}
Raad-Host

Code: Select all

function prompt {
    Write-Host (" " * 3 + "PS> ") -NoNewline
    return ' '
}
Raad-Host
but they do not work i.e. they have the prompt sign still next to the left edge


Does anyone else have any other ideas?
Thy Grand Voidinesss
Posts: 690
Joined: Wed Jun 01, 2022 5:01 pm

Re: Move flashing prompt sign in PowerShell window away from its left edge

Post by Thy Grand Voidinesss »

Well this works

Code: Select all

# Modification of the prompt sign by adding extra spaces before it:
Write-Host "`r"   # This clears the line
$Prompt = " " * 3 + " "   # This separate single white space can be entirely removed or changed into whatever sign or text is desired
Write-Host $Prompt -NoNewline
Read-Host
but only for the last active / ready-for-input line. Even if I put this at the very top of a larger script or make the whole PS1 file contain only the above code I still get to see the initial prompt sign(s) being adjacent to the left edge of PowerShell window [until the code reaches the point when it presents the user with a line ready for input from user]
Post Reply