scrolling region test

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
miskox
Posts: 610
Joined: 28 Jun 2010 03:46

scrolling region test

#1 Post by miskox » 03 Sep 2024 04:16

Here is a scrolling region test.

Code: Select all

@echo off
mode con cols=80 lines=24
cls

REM Aacini's solution (see below for more info regarding this correction)
for /f %%a in ('echo prompt $E^| cmd') do set "ESC=%%a"

echo                  S C R O L L I N G      T E S T

echo %esc%[21;0H======================================================================
echo                  S C R O L L I N G      T E S T 

REM set scrolling region lines 10-20
echo %esc%[10;20r

echo %esc%[9;0H======================================================================

for /L %%f in (100,1,120) do echo %%f&timeout /T 1 >nul

echo %esc%[22;0H

Output (shortened to fit):

Code: Select all

                 S C R O L L I N G      T E S T
======================================================================
100
101
102
103
104
105
106
107



======================================================================
                 S C R O L L I N G      T E S T
and when finished:

Code: Select all

                 S C R O L L I N G      T E S T
======================================================================
111
112
113
114
115
116
117
118
119
120

======================================================================
                 S C R O L L I N G      T E S T
Saso

Updated: Aacini is the author of the way how ESC gets into a variable. Source updated. See below. Aacini: I am very sorry. This was not intentional.
Last edited by miskox on 10 Sep 2024 00:20, edited 1 time in total.

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

Re: scrolling region test

#2 Post by Aacini » 05 Sep 2024 21:49

Interesting! :) I translated your code to printf.exe (version 2.81 with \e as ESC and enabled Virtual Terminal Processing). Here it is:

Code: Select all

@echo off
mode con cols=80 lines=24
cls

printf "%%s\n"		/* format to show strings */			^
   "                 S C R O L L I N G      T E S T"  OUT ^<		^
   "\e[21;0H======================================================================"  OUT ^<	^
   "                 S C R O L L I N G      T E S T"  OUT ^<		^
   "\e[10;20r"  OUT ^<		/* set scrolling region lines 10-20 */	^
   "\e[9;0H======================================================================"   OUT ^<	^
   1000 ]0 ^<			/* milliseconds to wait in GETK? */	^
   FMT{ "%%i\n" 100 ( OUT ++ 120 ^<=x? ^< ( GETK?:0 ) : ) FMT}		^
   "\e[22;0H" OUT

Antonio

PS - I wonder why you called the method to get the ESC character "Jeb's solution"...

miskox
Posts: 610
Joined: 28 Jun 2010 03:46

Re: scrolling region test

#3 Post by miskox » 05 Sep 2024 23:07

Aacini wrote:
05 Sep 2024 21:49
PS - I wonder why you called the method to get the ESC character "Jeb's solution"...
Because: https://ss64.com/nt/syntax-ansi.html

where it says:
A batch file to save the ESC character in a variable %ESC% (via Jeb on the forum)
Did I miss something?

Saso

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

Re: scrolling region test

#4 Post by Aacini » 09 Sep 2024 14:02

miskox wrote:
05 Sep 2024 23:07

Did I miss something?

Saso
Mmm... Maybe you missed this reply where I posted such a method for the first time more than 7 years ago...

Such topic, posted on 2017/Aug/22, is particularly interesting. At the beginning, IcarusLives shows an example where he inserts a hardcoded ESC character into the program. Then, penpen suggests using the strange method to get an ESC based on a for %%b in (1) do rem command that was commonly used at the time. After that, I present the method that everyone is using now:

Code: Select all

for /F %%a in ('echo prompt $E^| cmd') do set "ESC=%%a"
The funny thing is that a couple of replies below my post there is a reply from yourself addressed to me!

Yes, I think you did miss several things...

Antonio

miskox
Posts: 610
Joined: 28 Jun 2010 03:46

Re: scrolling region test

#5 Post by miskox » 10 Sep 2024 00:19

Antonio, I am very sorry. I really did not read that topic again - I just assumed that SS64's information is correct. Please accept my sincere apology. I didn't want to give credit to a wrong person. Then I guess Simon (SS64) should correct that info.

Saso

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

Re: scrolling region test

#6 Post by Aacini » 10 Sep 2024 14:34

miskox wrote:
10 Sep 2024 00:19
Then I guess Simon (SS64) should correct that info.

Saso
Yes, he already did...

Thanks a lot!

Antonio

Sponge Belly
Posts: 230
Joined: 01 Oct 2012 13:32
Location: Ireland
Contact:

Re: scrolling region test

#7 Post by Sponge Belly » 11 Sep 2024 14:36

Hi All,

Ed Dyreen and Dave Benham discussed capturing the backspace character in the Send Backspace Key in Batch topic as far back as 2012.

HTH! :)

- SB

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

Re: scrolling region test

#8 Post by Aacini » 11 Sep 2024 15:35

Yes, you are right Sponge Belly.

Ed Dyrenn first proposed this method:

Code: Select all

   for /f "delims=#" %%a in (
      '"prompt #$H# &echo on &for %%b in (1) do rem"'
   ) do (
      set "%$Defines%=%%a"
      set "%$Defines%=!$BS:~0,1!"
   )
... and then dbenham suggested this simplification:

Code: Select all

for /f %%a in ('"prompt $H&for %%b in (1) do rem"') do set "BS=%%a"
This last code was widely used until I posted my method in 2017:

Code: Select all

for /F %%a in ('echo prompt $E^| cmd') do set "ESC=%%a"
... that was the point we are talking about in the replies above...

Antonio

jeb
Expert
Posts: 1051
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: scrolling region test

#9 Post by jeb » 12 Sep 2024 11:10

Hi,

a bit nitpicking :D

new functions: :chr, :asc, :asciiMap (Fri Apr 01, 2011 10:34 pm)

I probably developed the ESC, DEL and CR (buffer overflow) technique, but the rest was just a copy and paste.

jeb

Post Reply