Move flashing prompt sign away from left edge of PowerShell window

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
DOSadnie
Posts: 143
Joined: 21 Jul 2022 15:12
Location: Coding Kindergarten

Move flashing prompt sign away from left edge of PowerShell window

#1 Post by DOSadnie » 14 Sep 2023 07:35

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

# -The 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?

DOSadnie
Posts: 143
Joined: 21 Jul 2022 15:12
Location: Coding Kindergarten

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

#2 Post by DOSadnie » 21 Sep 2023 01:46

I have managed to co come up with a partial solution

This script

Code: Select all

$COUNTDOWN = 3

Write-Host
Write-Host "   Endng in"
Write-Host
Write-Host "   $COUNTDOWN"
Write-Host
Write-Host "   seconds"
Write-Host

Start-Sleep -Seconds $COUNTDOWN
 
Write-Host
Write-Host
Write-Host "   Script has been executed"
Write-Host

Write-Host "`r"   # This clears the line

$Prompt = " " * 2 + " "   # That separate single white space at the end of this line can be entirely removed or changed into whatever sign or text is desired
Write-Host $Prompt -NoNewline

Read-Host
will leave user with the third / last prompt line / sign being moved away from the left edge of the window - but so far I have been unsuccessful with making look like so all of the prompt signs [the initial one and the second during the countdown in this new example from this post]

DOSadnie
Posts: 143
Joined: 21 Jul 2022 15:12
Location: Coding Kindergarten

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

#3 Post by DOSadnie » 22 Oct 2023 09:02

Does anyone have any ideas about how to do this?

ShadowThief
Expert
Posts: 1160
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

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

#4 Post by ShadowThief » 22 Oct 2023 09:30

Are you just looking for prompt $S$S$P$G?

DOSadnie
Posts: 143
Joined: 21 Jul 2022 15:12
Location: Coding Kindergarten

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

#5 Post by DOSadnie » 18 Nov 2023 11:45

If you mean replacing line

Code: Select all

$Prompt = " " * 2 + " "
with either

Code: Select all

$Prompt = "$S$S$P$G"
$Prompt = $S$S$P$G
$Prompt $S$S$P$G
then this does not work

DOSadnie
Posts: 143
Joined: 21 Jul 2022 15:12
Location: Coding Kindergarten

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

#6 Post by DOSadnie » 28 Dec 2023 03:24

DOSadnie wrote:
18 Nov 2023 11:45
If you mean replacing line
[...]
Well, did you?

DOSadnie
Posts: 143
Joined: 21 Jul 2022 15:12
Location: Coding Kindergarten

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

#7 Post by DOSadnie » 18 Feb 2024 03:39

I made basic tests files with just

Code: Select all

prompt $S$S$S$P$G
Read-Host

Code: Select all

function prompt {
    "$(' ' * 3)$(Get-Location)> "
}
Read-Host

Code: Select all

function prompt {
    Write-Host (" " * 3) -NoNewline
    return " $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) "
}
Read-Host
but they all were showing to me the prompt sign adjacent next to left edge of PS window


How else can I try to move the prompt to the right?

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

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

#8 Post by Squashman » 18 Feb 2024 09:00

Seems to work just fine for me.

Code: Select all

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

PS C:\Users\Squashman> function prompt {Write-Host (" " * 10) -NoNewline}
          PS>function prompt {Write-Host (" " * 15) -NoNewline}
               P> function prompt {Write-Host (" " * 20) -NoNewline}
                    PS>
 

Post Reply