Page 1 of 1

Strange behaviour with ansi sequence

Posted: 12 Nov 2018 23:05
by J'aitreschaud
Bonjour everyone. I recently found out bout ansi escape sequences and I found this strange behaviour.
I have this code:

Code: Select all

@echo off
for /f %%A in ('echo prompt $E^| cmd') do set "ESC=%%A"
echo %ESC%[100m
pause
It should make the background grey. However, it seems like only the text's background is grey.
ansi.png
ansi.png (4.68 KiB) Viewed 3784 times
What's more strange is that after inserting a CLS after the sequence, the whole background turns grey (expected behaviour)
ansi.png
ansi.png (4.62 KiB) Viewed 3784 times
Why is that? Another strange thing is that I can't seem to replicate the behavior after opening the file; I can't revert it back to black with "only grey background only letters" after I clear the screen. Is there an explanation on why this happens?

Re: Strange behaviour with ansi sequence

Posted: 13 Nov 2018 00:36
by jeb
Hi J'aitreschaud,

ESC[ <n> m is the Select Graphic Rendition sequence, it sets the display attributes, they affect each NEW character that will be written, that's all.
In your case, it changes the complete background after the cls, as the complete screen will be filled with spaces.
To reset that setting, you can use

Code: Select all

REM Reset display attributes
echo %ESC%[0m

REM Clear screen, move cursor to home position
echo %ESC%[2J
jeb

Re: Strange behaviour with ansi sequence

Posted: 13 Nov 2018 13:45
by IcarusLives
ECHO is providing CRLF so use this instead.

Code: Select all

<nul set /p "=%esc%[100m"

Re: Strange behaviour with ansi sequence

Posted: 13 Nov 2018 21:29
by J'aitreschaud
@IcarusLives @jeb
Thank you both for your answers.
Also IcarusLives, I love your username; great reference.