Going back to one of my old batch files... wanting to add to it

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
1033Forest
Posts: 11
Joined: 27 May 2018 21:43

Re: Going back to one of my old batch files... wanting to add to it

#16 Post by 1033Forest » 01 Jun 2018 06:29

I think the Windows 7 (AnsiSys with my modifications) version of this script is done for now. The only thing left to do is to make black characters appear on other colored backgrounds (black backgrounds do work though). Will continue work on the Windows 10 one once I get a new Windows 10 machine or something.

Also just wondering even though fullscreen doesn't work in Windows 7, it does in safe mode with it appearing like a fullscreen MS-DOS prompt. Does it work the same way in Windows 10's safemode or does it display with the scrollbar?

penpen
Expert
Posts: 1663
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Going back to one of my old batch files... wanting to add to it

#17 Post by penpen » 03 Jun 2018 05:52

My win10 version uses the same dos shell window (with scrollbars), no matter if running in safe mode or not, maximized or not.

penpen

1033Forest
Posts: 11
Joined: 27 May 2018 21:43

Re: Going back to one of my old batch files... wanting to add to it

#18 Post by 1033Forest » 04 Sep 2018 19:00

penpen wrote:
31 May 2018 03:35
I hope this "Retro awesomness.bat" is what you are looking for:

Code: Select all

@echo off
setlocal enableExtensions disableDelayedExpansion
:: set active, utf-7 and utf8 codepages
set /A "utf7Cp=65000, utf8Cp=65001"
set "cp="
for /f "delims=." %%a in ('2^>nul chcp') do for %%b in (%%a) do set "cp=%%b"
if not defined cp for /f "tokens=2" %%a in ('2^>nul chcp') do set "cp=%%~a"
>nul chcp %utf8Cp%

:: define filenames
set "utf7DataFile=data.utf-7.txt"
set "dataFile=data.dat"

:: create chinese chcp seperator char
set "data="

setlocal enableDelayedExpansion

:: create glyph data using only characters in { '+', '-', '/', '0'-'9', 'A'-'Z', 'a'-'z' }
>nul chcp %utf8Cp%
rem >"%dataFile%" cmd /a /c^<nul set /p "=+/v8-"
rem >nul chcp %utf7Cp%
set "data="
rem <"%dataFile%" set /p "data="
rem >nul chcp %utf8Cp%
set "data=!data!+AF8mOiY7JmUmZiZjJmAgIiXYJcsl2SZCJkAmaiZrJjwluiXEIZUgPAC2AKclrCGoIZEhkyGSIZAiHyGUJbIlvA- +ACEAIgAjAC"
set "data=!data!QAJQAm-'()+ACo-+-,-./0123456789:+ADsAPAA9AD4-?+AEA-ABCDEFGHIJKLMNOPQRSTUVWXYZ+AFsAXABdAF4AXwBg-abcde"
set "data=!data!fghijklmnopqrstuvwxyz+AHsAfAB9AH4jAgDHAPwA6QDiAOQA4ADlAOcA6gDrAOgA7wDuAOwAxADFAMkA5gDGAPQA9gDyAPsA+Q"
set "data=!data!D/ANYA3ACiAKMApSCnAZI-+AOEA7QDzAPoA8QDRAKoAugC/IxAArAC9ALwAoQCrALslkSWSJZMlAiUkJWElYiVWJVUlYyVRJVclX"
set "data=!data!SVcJVslECUUJTQlLCUcJQAlPCVeJV8lWiVUJWklZiVgJVAlbCVnJWglZCVlJVklWCVSJVMlayVqJRglDCWIJYQljCWQJYADsQDfA"
set "data=!data!5MDwAOjA8MAtQPEA6YDmAOpA7QiHgPGA7UiKQ-+ImEAsSJlImQjICMhAPciSACwIhkAtyIaIH8AsiWg-+AKA-"
::  index       0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
::              0         1         2         3         4         5         6         7         8         9         
cmd /d /a /e:on /v:on /c">"^!dataFile^!" echo(^!data^!"
set "data="

:: read data from file
>nul chcp %utf7Cp%
set "data="
<"%dataFile%" set /p "data="
>nul chcp %utf8Cp%

::initialize
set "Characters=!data:~1,31!!data:~33,222!"
set "Colors=123456789abcdef"
call :strlen "Characters"  "TotalCharAmount"
call :strlen     "Colors" "TotalColorAmount"
for /F %%a in ('echo prompt $E^| cmd') do set "ESC=%%a"
mode con cols=80 lines=25
title Retro awesomness.

:loop
set /a "c=!random! %% !TotalCharAmount!, i=!random! %% %TotalColorAmount%, j=!random! %% %TotalColorAmount%, x=(!random! %% 80) + 1, y=(!random! %% 25) + 1"
set /a "color=0x!Colors:~%i%,1!, bgcolor=0x!Colors:~%j%,1!"
<nul set /p "=%ESC%[%y%;%x%f%ESC%[38;5;%color%;48;5;%bgcolor%m!Characters:~%i%,1!%ESC%[0m"
goto :loop
goto :eof


:strlen
:: %~1	environment variable that holds the string to test
:: %~2	environment variable to store the string length to
	setlocal enableExtensions enableDelayedExpansion
	if not defined %~1 (
		set "%~2=-1"
	) else (
		set "len=0"
		for /l %%a in (12,-1,0) do (
			set /a "len|=(1<<%%~a)"
			for %%b in (!len!) do if "!%~1:~%%~b,1!" == "" set /a "len^=(1<<%%~a)"
		)
	)
	endlocal & set /a "%~2=%len%+1"
	goto :eof
Sidenotes:
You need to disable "Legacy console mode" else the vt100 ANSI escape sequences won't work.

When you are using raster fonts then the glyphs used should be system dependent.
So giving CP1252 characters and saying "their CP437 equivalents" is of not much use,
because CP437 isn't used if you are using raster fonts (so i hope the glyphs i used are ok).

I used these characters (as these are the defaults used by my system for raster fonts):

Code: Select all

_☺☻♥♦♣♠•◘○◙♂♀♪♫☼
►◄↕‼¶§▬↨↑↓→←∟↔▲▼
 !"#$%&'()*+,-./
0123456789:;<=>?
@ABCDEFGHIJKLMNO
PQRSTUVWXYZ[\]^_
`abcdefghijklmno
pqrstuvwxyz{|}~⌂
ÇüéâäàåçêëèïîìÄÅ
ÉæÆôöòûùÿÖÜ¢£¥₧ƒ
áíóúñѪº¿⌐¬½¼¡«»
░▒▓│┤╡╢╖╕╣║╗╝╜╛┐
└┴┬├─┼╞╟╚╔╩╦╠═╬╧
╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀
αßΓπΣσµτΦΘΩδ∞φε∩
≡±≥≤⌠⌡÷≈°∙·√ⁿ²■ 
Just for comparison - the following ones are used by CP 437 if not using raster fonts:

Code: Select all

 ☺☻♥♦♣♠•◘○◙♂♀♪♫☼
►◄↕‼¶§▬↨↑↓→←∟↔▲▼
 !"#$%&'()*+,-./
0123456789:;<=>?
@ABCDEFGHIJKLMNO
PQRSTUVWXYZ[\]^_
`abcdefghijklmno
pqrstuvwxyz{|}~⌂
ÇüéâäàåçêëèïîìÄÅ
ÉæÆôöòûùÿÖÜø£Ø׃
áíóúñѪº¿®¬½¼¡«»
░▒▓│┤ÁÂÀ©╣║╗╝¢¥┐
└┴┬├─┼ãÃ╚╔╩╦╠═╬¤
ðÐÊËÈıÍÎÏ┘┌█▄¦Ì▀
ÓßÔÒõÕµþÞÚÛÙýݯ´
­±‗¾¶§÷¸°¨·¹³²■ 
I decided to go back to this thread and try this one out since I got a Windows 10 laptop. The colors work, but only characters 1-15 appear with a few blank spaces. What's wrong with this code?

Also, the line set "Characters=!data:~1,31!!data:~33,222!", it's 254, not 222 in order to display every character.

penpen
Expert
Posts: 1663
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Going back to one of my old batch files... wanting to add to it

#19 Post by penpen » 11 Sep 2018 11:38

1033Forest wrote:
04 Sep 2018 19:00
I decided to go back to this thread and try this one out since I got a Windows 10 laptop. The colors work, but only characters 1-15 appear with a few blank spaces. What's wrong with this code?
This line is wrong (i silently corrected the error in the later "AnsiSys-version", probably just forgot to mention):

Code: Select all

<nul set /p "=%ESC%[%y%;%x%f%ESC%[38;5;%color%;48;5;%bgcolor%m!Characters:~%i%,1!%ESC%[0m"
The corrected line is the following (using the right environment variable for the character (c instead of i):

Code: Select all

<nul set /p "=%ESC%[%y%;%x%f%ESC%[38;5;%color%;48;5;%bgcolor%m!Characters:~%c%,1!%ESC%[0m"
1033Forest wrote:
04 Sep 2018 19:00
Also, the line set "Characters=!data:~1,31!!data:~33,222!", it's 254, not 222 in order to display every character.
In this line the 222 is the correct value:
The batch substring command "!data:~33,222!" copies 222 characters starting at index 33 to the final set statement,
so it copies the characters from index 33 to 254 (=222+33-1).

The environment variable data contains 256 characters with:
- A breaking whitespace (ASCII: 0x20) (at index 0) instead of the NUL character,
- the breaking whitespace (at index 32)
- the non breaking whitespace (ASCII: 0xFF) (at index 255).
Those characters are sort of "empty" (because they don't display anything except the background), so if i remember right you didn't want to display.


Later (for the AnsiSys-version) i also removed some other non displayable characters, because:
- The BEL character (at index 7) annoyingly beeps,
- the TAB character (at index 9) uses more than only 1 character (all blank),
- the SUB character (at index 26) could terminate interpreting escape sequences,
- the ESC character (at index 27) could be misinterpreted as an escape sequence.
Except the BEL (and probably the SUB character, but that is untested) you should avoid these characters for both versions (reasons given above).

So you better should use the following line instead:

Code: Select all

set "Characters=!data:~1,6!!data:~8,1!!data:~10,16!!data:~28,4!!data:~33,222!"
Edit: I have change these lines in code you quoted.

Post Reply