How to move cursor upwards without cls?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How to move cursor upwards without cls?

#16 Post by aGerman » 14 Oct 2017 05:26

If you rather want to use 3rd party tools then you'll find hundreds in the internet. I remember some of them also here at DosTips.
viewtopic.php?t=3428
viewtopic.php?t=7129
viewtopic.php?t=4762

Steffen

PaperTronics
Posts: 118
Joined: 02 Apr 2017 06:11

Re: How to move cursor upwards without cls?

#17 Post by PaperTronics » 14 Oct 2017 21:31

@aGerman - That is the whole problem. I can't use 3rd party tools because I'm trying to make my program in pure batch. If I had to use 3rd party tools, I would've already used batbox or bg.exe!

Nonetheless, thanks for your code and hard work in digging out those links :D .




Cheers,
PaperTronics

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How to move cursor upwards without cls?

#18 Post by aGerman » 15 Oct 2017 05:11

So using Powershell is still pure Batch? :lol:
In the last link penpen and me provided a possibility how to compile a C# utility with on-board resources only. It uses the same SetCursorPosition method as Powershell.

Steffen

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: How to move cursor upwards without cls?

#19 Post by Aacini » 16 Oct 2017 11:37

PaperTronics wrote:@Aacini - Your Pure Batch attempt at it still isn't solving anything.

Well, is hard to try to solve anything when we don't know what is the problem... (what is the output of such an attempt?)

Let's analyze the used method a little.

The TIMEOUT command show a message at current line, show "0" at position (0,0) and leaves the cursor at beginning of second line. The first SET /P command clears the timeout's message. The second SET /P command execute when the cursor is at beginning of second line, so this is its effect:

Code: Select all

              Move cursor to column 8 and enable "the trick" of BS character
              ||   Move cursor back to beginning of second line
             _||_  ||  Move cursor backwards, up to the end of first line
            /    \/  \/  \___ Return cursor at beginning of first line
^& set /P "=.%TAB%%BS%%BS%%%C"

In this way, previous SET /P should leave the cursor at position (0,0); however, there is a "0" there. In order to delete it, you should add " %%C" in this way:

Code: Select all

                             Clear the "0" at position (0,0)
                             |___ Return cursor at beginning of first line
^& set /P "=.%TAB%%BS%%BS%%%C %%C"

If previous code not works, then I would insert a character at end in order to know where is the cursor, and/or change the final %%C by a %BS%, etc. However, it is unlikely that this method don't work, unless a problem may occur in certain Windows version...

Of course, if we may review a code and the output it produces in your computer, then we would have a better base to analyze this problem and try to solve it.

Antonio

PaperTronics
Posts: 118
Joined: 02 Apr 2017 06:11

Re: How to move cursor upwards without cls?

#20 Post by PaperTronics » 21 Oct 2017 21:00

@aGerman - I know Powershell isn't pure batch, but it is still better than having a big bunch of EXEs. So I guess you could call my program semi-pure batch :D


@Aacini - After a LOT of experimenting, I've finally found out what the problem is (or at least I think so :mrgreen: ). First look at the code:

Code: Select all

@echo off
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo 10
Call :MoveCursorHome
>nul pause
goto :EOF

:MoveCursorHome
setlocal
for /F %%a in ('echo prompt $H ^| cmd') do set "BS=%%a"
for /F "skip=4 delims=pR tokens=2" %%a in ('reg query hkcu\environment /v temp' ) do set "TAB=%%a"
for /F "tokens=2 delims=0" %%a in ('shutdown /? ^| findstr /BC:E') do if not defined TAB set "TAB=%%a"
timeout /T 1 > CON | cmd /Q /C for /F %%C in (..txt) do set /P "=.%%C%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB% ^& set /P "=.%TAB%%BS%%BS%%%C %%C".


exit /B


And now here is the output produced:

Code: Select all

0
{Cursor is here}







10

Waiting for 1 seconds, press a key to continue ...



So what I think is, that the cursor moves to the next line, and the last set portion which is supposed to erase the 0, it doesn't go upwards to the first line and instead erases the the content of the second line. So the 0 persists, just as the problem persists.

I tried a lot to solve this(27 mins of experimenting), but I wasn't able to. Can you solve it now that you know the problem?





Thanks,
PaperTronics

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: How to move cursor upwards without cls?

#21 Post by Aacini » 21 Oct 2017 22:27

The "timeout" line is given at this post, plus the modification given at this post. The "timeout" line is repeated again in this post. You included the correct line in this post.

After that,
at this post Aacini wrote:@PaperTronics:

Change the last SET /P command by this one:

Code: Select all

^& set /P "=.%TAB%%BS%%BS%%%C %%C"

Antonio

This means that the correct "timeout" line is this one:

Code: Select all

timeout /T 1 > CON | cmd /Q /C for /F %%C in ('copy /Z "%~F0" NUL') do set /P "=.%%C%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%" ^& set /P "=.%TAB%%BS%%BS%%%C %%C"

However, the "timeout" line that appear in your last code is this one (the differences are marked below the line):

Code: Select all

timeout /T 1 > CON | cmd /Q /C for /F %%C in (..txt) do set /P "=.%%C%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB% ^& set /P "=.%TAB%%BS%%BS%%%C %%C".
This part should be 'copy /Z "%~F0" NUL' ---> ^^^^^                           There is a quote missing here: ^        This point is additional: ^

When I fixed such a line and run this code in my computer:

Code: Select all

@echo off
cls
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo 10
Call :MoveCursorHome
>nul pause
goto :EOF

:MoveCursorHome
setlocal
for /F %%a in ('echo prompt $H ^| cmd') do set "BS=%%a"
for /F "skip=4 delims=pR tokens=2" %%a in ('reg query hkcu\environment /v temp' ) do set "TAB=%%a"
for /F "tokens=2 delims=0" %%a in ('shutdown /? ^| findstr /BC:E') do if not defined TAB set "TAB=%%a"
timeout /T 1 > CON | cmd /Q /C for /F %%C in ('copy /Z "%~F0" NUL') do set /P "=.%%C%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%" ^& set /P "=.%TAB%%BS%%BS%%%C %%C"

exit /B

... this is the output:

Code: Select all


.







10

... and the cursor is at position (0,0).

This means that previous code correctly moves the cursor to home (0,0) position, but it fails in the point that appears at beginning of second line. To fix this point, change the last SET /P by this one:

Code: Select all

^& set /P "=.%%C%TAB%%BS%%BS%%%C %%C"

That is, this is the fixed code:

Code: Select all

@echo off
cls
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo 10
Call :MoveCursorHome
>nul pause
goto :EOF

:MoveCursorHome
setlocal
for /F %%a in ('echo prompt $H ^| cmd') do set "BS=%%a"
for /F "skip=4 delims=pR tokens=2" %%a in ('reg query hkcu\environment /v temp' ) do set "TAB=%%a"
for /F "tokens=2 delims=0" %%a in ('shutdown /? ^| findstr /BC:E') do if not defined TAB set "TAB=%%a"
timeout /T 1 > CON | cmd /Q /C for /F %%C in ('copy /Z "%~F0" NUL') do set /P "=.%%C%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%" ^& set /P "=.%%C%TAB%%BS%%BS%%%C %%C"

exit /B

PaperTronics
Posts: 118
Joined: 02 Apr 2017 06:11

Re: How to move cursor upwards without cls?

#22 Post by PaperTronics » 26 Oct 2017 20:58

@Aacini - First of all, I'm sorry for the 5 days delayed response. I was busy for a few days so I couldn't even open DosTips.

I know that I made some modifications of the timeout line. But now I c/p your code and this is the output:

Code: Select all

0                                                                        0 0
.0







10

Waiting for 1 seconds, press a key to continue ...The specified file could not b
e encrypted.
.0



As you can see, the problem still hasn't moved up a notch. It has gotten worse, still doesn't provide the desired output.



Thanks,
PaperTronics

Post Reply