Page 1 of 1

Using ASCII fonts and block elements for text messages - problem with encoding of BAT file

Posted: 11 Aug 2022 13:26
by DOSadnie
To some of my BAT scripts that I use I have inserted a fail-safe consisting of a countdown and a short text explaining what is about to happen. For example

Code: Select all

@echo off
echo.
echo.                              Commencing system reset
echo.                              
echo.                              PRESS ANY KEY TO CANCEL
echo.       

timeout /t 5 |findstr /r ".0$" && goto continue || exit
command > nul 2>&1

:continue

exit
[For test purposes I have removed from the above example the actual command for reset - i.e.: >> shutdown /r /f /t 0 <<]

The problem with such info is the normal thus small size of its letters in CMD window- when I click shortcuts to BAT like these I can hardly read them when I am laying on my bed. And so I wanted to use letters built from block elements like

Code: Select all

█
▮
▓
But as doing this by hand was not a reasonable option for me I went to The Internets and found me websites like https://www.coolgenerator.com/ascii-text-generator and http://patorjk.com/software/taag/#p=dis ... mething%20 and tried out using some fonts. Unfortunately:

#1] some do work but I just do not like how they look [e.g. Banner3]

#2] some after execution of BAT file will only flash the CMD window doing nothing else [e.g. Cybermedium, Irvit]

#3] some after execution of BAT file will produce totally messed up blocks of gibberish signs not present in those fonts [e.g. Regular ANSI, ANSI Shadow]

#4] some after pasting into BAT file have letters messed up to some degree [e.g. Univers]

So to avert issues #3 and #4 I tried changing [in Notepad2 version 4.2.5] encoding of my test BAT file from UTF-8 to others. And I saw changes or no changes in how these fonts looked like - bu simply lack knowledge and experience in this area


And so my question are:

A] What encoding should I use to see signs used by such fonts in both the BAT file and in CMD in a proper way [i.e. the way the look on those websites]?

B] What are the proper encodings for BAT files in overall?

C] How is it possible that an >> echo << followed by some unusual signs apparently breaks a whole script?

D] Will PS1 files also behave [visually] in the same way [with the same encoding chosen for them]?

Re: Using ASCII fonts and block elements for text messages - problem with encoding of BAT file

Posted: 11 Aug 2022 15:31
by ShadowThief
A) You're correct to save the file as UTF-8, but the default code page used by the command prompt is 437, which is a non-UTF DOS OEM character set. In order to use Unicode, you need to add the line chcp 65001 >nul.

B) In general, for loops play nicest with ANSI encoding, but if you aren't processing any text files, you can almost always get away with UTF-8 as well.

C) The | character from CyberMedium and other fonts is called a pipe character, and it tells the interpreter "take the output of the command on the left and use it as the input of the command on the right." Since you just have symbols instead of actual commands, it doesn't understand what it's looking at and thinks you made a syntax error. To get around this, you can use ^| instead of | since ^ is the escape character.

D) Powershell won't force you to escape the pipes if you wrap the string in quotes, but the backticks and quotes will have to be escaped since powershell uses backtick to escape things. I also can't seem to get the ANSI font to render properly at all, which is strange.

Re: Using ASCII fonts and block elements for text messages - problem with encoding of BAT file

Posted: 11 Aug 2022 20:50
by Aacini
I am not answering anyone of your questions. Instead, I want to show you a couple examples of how to use ASCII characters in Batch files to create "big fonts".

The first example is a simulation of SET /P command that allows to show a "prompt" and read a line, but using "big" characters. Here it is:

Code: Select all

@echo off
setlocal EnableDelayedExpansion

rem set/PBig: Input and output of bigger characters
rem           version 2   - lower case letters and more than one font added
rem           version 2.1 - almost all characters implemented in Std3x5 font
rem Antonio Perez Ayala

call :set/PBigInit %1
if errorlevel 1 echo Not such font & goto :EOF
echo/
call :set/PBig name="Enter your name; "
echo Name read: "%name%"
call :set/PBig "Enter your full name"
call :set/PBig name=""
echo Name read: "%name%"
goto :EOF



rem This is the main set/PBig I/O subroutine

:set/PBig [var=]"msg"

for /L %%i in (1,1,%vSize%) do set "line[%%i]="

if [%2] equ [""] set "var=%~1" & (for /L %%i in (1,1,%vSizeM1%) do echo/) & goto input
if "%~2" equ "" (set "var=" & set "msg=%~1") else set "var=%~1" & set "msg=%~2"

rem Assemble and show the msg "prompt"
for /L %%j in (0,1,%cols%) do for /F "delims= eol=" %%c in ("!msg:~%%j,1!") do (
   if "!upcase:%%c=%%c!" equ "%upcase%" (
      for /L %%i in (1,1,%vSize%) do set "line[%%i]=!line[%%i]!!char[%%c%%i]!"
   ) else (
      for /L %%i in (1,1,%vSize%) do set "line[%%i]=!line[%%i]!!char[_%%c%%i]!"
   )
)
for /L %%i in (1,1,%vSizeM1%) do echo !line[%%i]!
set /P "=.%BS%!line[%vSize%]!" < NUL
if not defined var goto endSet/PBig

:input
rem Start reading loop
set "input="
set "i=0"

:nextKey
   set "key="
   for /F "delims=" %%a in ('xcopy /W _ _ 2^>NUL') do if not defined key set "key=%%a"

   rem If key is CR: terminate input
   if "!key:~-1!" equ "!CR!" goto endRead

   rem If key is BS: delete last char, if any
   set "char=%input:~-1%"
   if "!upcase:%char%=%char%!" neq "%upcase%" set "char=_%char%"
   set "key=!key:~-1!"
   if "!key!" equ "%BS%" (
      if %i% gtr 0 (
         for /F %%s in ("!hSize[%char%]!") do (
            for /L %%i in (1,1,%vSize%) do set "line[%%i]=!line[%%i]:~0,-%%s!"
            set "last=!SPs:~0,%%s!!BSs:~0,%%s!"
         )
         set "input=%input:~0,-1%"
         set /A i-=1
         goto refresh
      )
      goto nextKey
   )

   rem Insert here any filter on the key
   if "!charSet:%key%=!" equ "%charSet%" goto nextKey

   rem Else: accept the key
   for /F "delims= eol=" %%c in ("!key!") do (
      if "!upcase:%%c=%%c!" equ "%upcase%" (
         for /L %%i in (1,1,%vSize%) do set "line[%%i]=!line[%%i]!!char[%%c%%i]!"
      ) else (
         for /L %%i in (1,1,%vSize%) do set "line[%%i]=!line[%%i]!!char[_%%c%%i]!"
      )
   )
   set "input=%input%%key%"
   set /A i+=1
   set "last="

   :refresh
   echo/
   echo %TAB%%BSs%
   for /L %%i in (1,1,%vSizeM1%) do echo(!line[%%i]!%last%
   set /P "=.%BS%!line[%vSize%]!%last%" < NUL

goto nextKey

:endRead
set "%var%=%input%"

:endSet/PBig
echo/
exit /B


rem Definition and initialization of variables
rem This subroutine requires an active "setlocal EnableDelayedExpansion" scope

:set/PBigInit [font]

set "upcase= "
set "defFont=Std3x5"
if "%~1" neq "" set "defFont=%~1"
call :%defFont% 2> NUL
if errorlevel 1 exit /B 1

set "charSet= "
for /L %%i in (1,1,%vSize%) do set "char[ %%i]=%space%"
set "hSize[ ]=%spSize%"
for /L %%s in (1,1,%hSize%) do (
   set "j=0"
   for %%c in (!size%%s[0]!) do for %%j in (!j!) do (
      set "charSet=!charSet!%%~c"
      for /L %%i in (1,1,%vSize%) do set "char[%%~c%%i]=!size%%s[%%i]:~%%j,%%s!"
      set "hSize[%%~c]=%%s"
      set /A "j+=%%s"
   )
)

REM SET CHAR[ | MORE

echo > _
for /F %%a in ('copy /Z _ NUL') do set "CR=%%a"
for /F %%a in ('echo prompt $H ^| cmd') do set "BS=%%a"
set "TAB="
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"

set i=0
for /F "tokens=2 delims=:" %%a in ('mode') do (
   set /A i+=1
   if !i! equ 2 (
      set /A "vSizeM1=vSize-1, cols=%%a/vSize+vSize, numBSs=2 + (%%a/8+1) * vSize"
   ) else if !i! equ 5 (
      set /A "cp=%%a"
   )
)
set "BSs="
for /L %%i in (1,1,%numBSs%) do set "BSs=!BSs!%BS%"
set "SPs="
for /L %%i in (1,1,%hSize%) do set "SPs=!SPs! "

chcp 850 > NUL
exit /B


rem Standard 3x3 font
:Std3x3

set "size3[0]= 0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F  G  H  I  J  K  L  N  O  P  Q  R  S  T  U  V  W  X  Y  Z  . "," ";" "
set "size3[1]=ÚÄ¿ ³  Ä¿ Ä¿³ ³ÚÄ ÚÄ  Ä¿ÚÄ¿ÚÄ¿ÚÄ¿ÚÄoÚÄ ÚÄoÚÄ ÚÄ ÚÄ ³ ³    ³³ /³  Ú ³ÚÄ¿ÚÄ¿ÚÄ¿ÚÄ¿ÚÄ ÄÂij ³      \ /\ /îî/         "
set "size3[2]=³ ³ ³ ÚÄÙ Ä´ÀÄ´ÀÄ¿ÃÄ¿  ³ÃÄ´ÀÄ´ÃÄ´ÃÄ´³  ³ ³ÃÄ ÃÄ ÃÄ¿ÃÄ´ ³   ³Ã< ³  ³\³³ ³ÃÄÙ³ ³ÃÄÙÀÄ¿ ³ ³ ³\ /\ / X  Y  /        . "
set "size3[3]=ÀÄÙ ³ ÀÄ  ÄÙ  ³ ÄÙÀÄÙ  ³ÀÄÙ ÄÙ³ ³ÀħÀÄ ÀħÀÄ ³  ÀÄÙ³ ³ Á ÀÄÙ³ \ÀÄ ³ ÙÀÄÙ³  ÀÄ\³ \ ÄÙ ³ ÀÄÙ V  W / \ ³ /__ .  ,  . "

set "size4[0]=  M "
set "size4[1]=Ú  ¿"
set "size4[2]=³\/³"
set "size4[3]=³  ³"

set /A "vSize=3, hSize=4, spSize=3"
set "space=   "

exit /B 0


rem Standard 3x5 font with lowcase letters and special characters
:Std3x5

set "upcase=ABCDEFGHIJKLMNÑOPQRSTUVWXYZ"

set "size2[0]= < > [ ]"
set "size2[1]=    ÚÄÄ¿"
set "size2[2]= /\ ³  ³"
set "size2[3]=/  \³  ³"
set "size2[4]=\  /³  ³"
set "size2[5]= \/ ÀÄÄÙ"

set "size3[0]= 0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F  G  H  I  J  K  L  O  P  Q  R  S  T  U "
set "size3[1]=ÚÄ¿ ³  Ä¿ Ä¿³ ³ÚÄ ÚÄ  Ä¿ÚÄ¿ÚÄ¿ÚÄ¿ÚÄoÚÄ ÚÄoÚÄ ÚÄ ÚÄ ³ ³    ³³ /³  ÚÄ¿ÚÄ¿ÚÄ¿ÚÄ¿ÚÄ ÄÂij ³"
set "size3[2]=³ ³ ³   ³  ³³ ³³  ³    ³³ ³³ ³³ ³³ ³³  ³ ³³  ³  ³  ³ ³ ³   ³³/ ³  ³ ³³ ³³ ³³ ³³   ³ ³ ³"
set "size3[3]=³ ³ ³ ÚÄÙ Ä´ÀÄ´ÀÄ¿ÃÄ¿  ³ÃÄ´ÀÄ´ÃÄ´ÃÄ´³  ³ ³ÃÄ ÃÄ ÃÄ¿ÃÄ´ ³   ³Ã  ³  ³ ³ÃÄÙ³ ³ÃÄÙÀÄ¿ ³ ³ ³"
set "size3[4]=³ ³ ³ ³    ³  ³  ³³ ³  ³³ ³  ³³ ³³ ³³  ³ ³³  ³  ³ ³³ ³ ³ ³ ³³\ ³  ³ ³³  ³ ³³\   ³ ³ ³ ³"
set "size3[5]=ÀÄÙ ³ ÀÄ  ÄÙ  ³ ÄÙÀÄÙ  ³ÀÄÙ ÄÙ³ ³ÀħÀÄ ÀħÀÄ ³  ÀÄÙ³ ³ Á ÀÄÙ³ \ÀÄ ÀÄÙ³  ÀÄ\³ \ ÄÙ ³ ÀÄÙ"

set "size3[0]=%size3[0]%_a _b _c _d _e _f _g _h _i _j _k _l _m _n  ¤ _o _p _q _r _s _t _u _x _y _z "
rem                                                                ñ  <- special case, should be: _¤
set "size3[1]=%size3[1]%   ³       ³    Ú    ³   ø  ø ³   ³        ~                 ³             "
set "size3[2]=%size3[2]% Ä¿ÃÄ¿ÚÄ ÚÄ´ÚÄ¿ Å ÚÄ¿³   ³  ³ ³/  ³ ¿ÂÄ¿ÂÄ¿ÚÄ¿ÚÄ¿ÚÄ¿ÂÄ ÚÄ  Å ³ ³\ /\ /îî/"
set "size3[3]=%size3[3]%ÚÄ´³ ³³  ³ ³ÃÄÙ ³ ÀÄ´ÃÄ¿ ³  ³ à   ³ ³³³³ ³³ ³³ ³ÃÄÙÀÄ´³  ÀÄ¿ ³ ³ ³ X  Y  / "
set "size3[4]=%size3[4]%ÀÄÙÀÄÙÀÄ ÀÄÙÀÄ  ³   ³³ ³ ³  ³ ³\  À ³³³³ ³³ ³ÀÄÙ³    ³³   ÄÙ ³ ÀÄÙ/ \/  /__"
set "size3[5]=%size3[5]%                   ÄÙ      ÀÙ                   ³    Å                     "

set "size3[0]=%size3[0]%    ‚  ¡  ¢  £    $  +  -  (  )  {  }  . "," ";" "
rem                      á  é  í  ó  ú  ü  
set "size3[1]=%size3[1]% ,  ,  '  ,  , ø øÚÅ         /\   ÚÄÄ¿          "
set "size3[2]=%size3[2]% Ä¿ÚÄ¿ ³ ÚÄ¿³ ³³ ³³³  ³     /  \  ³  ³          "
set "size3[3]=%size3[3]%ÚÄ´ÃÄÙ ³ ³ ³³ ³³ ³ÀÅ¿ÄÅÄÄÄÄ(    )<    >       . "
set "size3[4]=%size3[4]%ÀÄÙÀÄ  ³ ÀÄÙÀÄÙÀÄÙ ³³ ³     \  /  ³  ³        . "
set "size3[5]=%size3[5]%                   ÅÙ        \/   ÀÄÄÙ  .  ,    "

set "size4[0]=  @   &  %% "
set "size4[1]=ÚÄÄ¿        "
set "size4[2]=³ÚÄ´Ú¿  Ú¿ /"
set "size4[3]=³ÀÄÙÀÅÄ´ÀÙ/ "
set "size4[4]=ÀÄÄÄ ³ ³ /Ú¿"
set "size4[5]=     ÀÄÙ/ ÀÙ"

set "size5[0]=  N   _¥    V    X    Y    Z   _v   _w    #    /    \  "
rem                  Ñ  <- special case, should be: ¥
set "size5[1]=Ú   ³Ú ~ ³\   /\   /\   /îîîî/           ³ ³     /\    "
set "size5[2]=³\  ³³\  ³      \ /  \ /    / \   /³ ^ ³ÄÅÄÅÄ   /  \   "
set "size5[3]=³ \ ³³ \ ³ \ /   X    Y    /   \ / ³/ \³ ³ ³   /    \  "
set "size5[4]=³  \³³  \³      / \   ³   /     V  À   ÙÄÅÄÅÄ /      \ "
set "size5[5]=³   Ù³   Ù  V  /   \  ³  /____           ³ ³ /        \"

set "size6[0]=   M     W"
set "size6[1]=Ú    ¿³    ³"
set "size6[2]=³\  /³³    ³"
set "size6[3]=³ \/ ³³ /\ ³"
set "size6[4]=³    ³³/  \³"
set "size6[5]=³    ³À    Ù"

set /A "vSize=5, hSize=6, spSize=3"
set "space=   "

exit /B 0
The second example is a large Batch file that uses a standard method to create and use "big" characters, called FIGlet, that are defined in files with .flf extension. You can review it at this SO answer.

I hope this helps...

Antonio

Re: Using ASCII fonts and block elements for text messages - problem with encoding of BAT file

Posted: 31 Aug 2022 16:05
by DOSadnie
ShadowThief wrote:
11 Aug 2022 15:31
A) You're correct to save the file as UTF-8, but the default code page used by the command prompt is 437, which is a non-UTF DOS OEM character set. In order to use Unicode, you need to add the line chcp 65001 >nul.
[...]
This seems to do the trick. And because I spend too much time on such problems and various forums, I will stop at this, settling for now with

Code: Select all

chcp 65001 >nul

if not "%1" == "max" start /MAX cmd /c %0 max & exit/b
mode 1000

@echo off
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.                                                          ██████      ██████      ███    ███     ███    ███     ███████     ███    ██      ██████     ██     ███    ██      ██████
echo.                                                         ██          ██    ██     ████  ████     ████  ████     ██          ████   ██     ██          ██     ████   ██     ██
echo.                                                         ██          ██    ██     ██ ████ ██     ██ ████ ██     █████       ██ ██  ██     ██          ██     ██ ██  ██     ██   ███
echo.                                                         ██          ██    ██     ██  ██  ██     ██  ██  ██     ██          ██  ██ ██     ██          ██     ██  ██ ██     ██    ██
echo.                                                          ██████      ██████      ██      ██     ██      ██     ███████     ██   ████      ██████     ██     ██   ████      ██████
echo.
echo.
echo.                                                ███████     ██    ██     ███████     ████████     ███████     ███    ███             ██████      ███████     ███████     ███████     ████████
echo.                                                ██           ██  ██      ██             ██        ██          ████  ████             ██   ██     ██          ██          ██             ██
echo.                                                ███████       ████       ███████        ██        █████       ██ ████ ██             ██████      █████       ███████     █████          ██
echo.                                                     ██        ██             ██        ██        ██          ██  ██  ██             ██   ██     ██               ██     ██             ██
echo.                                                ███████        ██        ███████        ██        ███████     ██      ██             ██   ██     ███████     ███████     ███████        ██
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.                                                ██████      ██████      ███████     ███████     ███████              █████      ███    ██     ██    ██             ██   ██     ███████     ██    ██
echo.                                                ██   ██     ██   ██     ██          ██          ██                  ██   ██     ████   ██      ██  ██              ██  ██      ██           ██  ██
echo.                                                ██████      ██████      █████       ███████     ███████             ███████     ██ ██  ██       ████               █████       █████         ████
echo.                                                ██          ██   ██     ██               ██          ██             ██   ██     ██  ██ ██        ██                ██  ██      ██             ██
echo.                                                ██          ██   ██     ███████     ███████     ███████             ██   ██     ██   ████        ██                ██   ██     ███████        ██
echo.
echo.
echo.                                                                    ████████      ██████               ██████      █████      ███    ██      ██████     ███████     ██
echo.                                                                       ██        ██    ██             ██          ██   ██     ████   ██     ██          ██          ██ 
echo.                                                                       ██        ██    ██             ██          ███████     ██ ██  ██     ██          █████       ██
echo.                                                                       ██        ██    ██             ██          ██   ██     ██  ██ ██     ██          ██          ██
echo.                                                                       ██         ██████               ██████     ██   ██     ██   ████      ██████     ███████     ███████
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.     

timeout /t 5 |findstr /r ".0$" && goto continue || exit
command > nul 2>&1

:continue

exit
mede with ANSI Regularfont which produces a horizontally centered text on my 3840 x 1600 screen


But nevertheless I will save
Aacini wrote:
11 Aug 2022 20:50
[...]
a couple examples of how to use ASCII characters in Batch files to create "big fonts".
[...]
for future usage, if I will be forced to dig into this issue once more

Thank you both for the info

Re: Using ASCII fonts and block elements for text messages - problem with encoding of BAT file

Posted: 31 Aug 2022 16:18
by DOSadnie
DOSadnie wrote:
31 Aug 2022 16:05
[...]
settling for now with
[...]
Although there is one tiny issue with this code of mine: I get the horizontal scroll bar allowing for going quite far to the right [i.e. around 2 extra screens of empty space] and I get the vertical horizontal scroll bar allowing for going extremely far to the bottom [i.e. dozens extra screens of empty space]

But I better leave this at it is, as to not waste time on a trivial matter