set/PBig: Input and output of bigger characters

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Aacini
Expert
Posts: 1564
Joined: 06 Dec 2011 22:15
Location: México City, México

set/PBig: Input and output of bigger characters

#1 Post by Aacini » 03 Nov 2018 22:10

This is another funny program that emulates SET /P command. It can show a message and optionally also read a string, but the core point is that the characters displayed are bigger than the standard characters and are created combining graphic characters from code page 850; this point means that not all characters can be defined. In this program just the digits and uppercase letters are defined, besides a few special characters. Of course, you may define your own character set with a "font" of any size; you may review this SO question for some ideas about this point.

There are a couple special characters that can not be defined, like colon, equal-sign and a few others. These characters could be implemented, but the code would grow in complexity. For convenience, the semicolon character is displayed as a colon.

This program uses Move cursor to *any position* using just ECHO command method (required to correctly show a multi-line output) and this simplified ReadLine subroutine for the input procedure.

EDIT 2018-11-04: Improved the "B" and "D" characters in the font...

Code: Select all

@echo off
setlocal EnableDelayedExpansion

rem set/PBig: Input and output of bigger characters
rem Antonio Perez Ayala

call :set/PBigInit
echo/
call :set/PBig "THIS IS A TEST"
call :set/PBig name="ENTER YOUR NAME; "
echo Name read: "%name%"
goto :EOF



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

:set/PBig [var=]"msg"

if "%~2" equ "" (set "var=" & set "msg=%~1") else set "var=%~1" & set "msg=%~2"

rem Assemble and show the msg "prompt"
for /L %%i in (1,1,%vSize%) do set "line[%%i]="
for /L %%j in (0,1,%cols%) do for /F "delims= eol=" %%c in ("!msg:~%%j,1!") do (
   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

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 "key=!key:~-1!"
   if "!key!" equ "%BS%" (
      if %i% gtr 0 (
         for /F %%s in ("!hSize[%input:~-1%]!") 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 (
      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/
echo/
exit /B


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

:set/PBigInit

set /A "vSize=3, vSizeM1=vSize-1"

set "size1[0]=1 I"
set "size1[1]=³Â"
set "size1[2]=³³"
set "size1[3]=³Á"

set "size2[0]=. "," ";" 3 7 C E F L"
set "size2[1]=      Ä¿Ä¿ÚÄÚÄÚij "
set "size2[2]=     .Ä´ ³³ ÃÄÃij "
set "size2[3]= . , .ÄÙ ³ÀÄÀij ÀÄ"

set "size3[0]= 0  2  4  5  6  8  9  A  B  D  G  H  J  K  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 "charSet= "
for /L %%i in (1,1,%vSize%) do set "char[ %%i]=   "
set "hSize[ ]=3"
for %%s in (1 2 3 4) 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 "cols=(%%a+2)/3, numBSs=2 + (%%a/8+1) * vSize"
   ) else if !i! equ 5 (
      set /A "cp=%%a"
   )
)
set "SPs=    " & set "BSs="
for /L %%i in (1,1,%numBSs%) do set "BSs=!BSs!%BS%"

chcp 850 > NUL
exit /B
Output example:

Code: Select all


─┬─│ │┬┌─    ┬┌─    ┌─┐   ─┬─┌─┌─ ─┬─
 │ ├─┤│└─┐   │└─┐   ├─┤    │ ├─└─┐ │
 │ │ │┴ ─┘   ┴ ─┘   │ │    │ └─ ─┘ │

┌─┌ │─┬─┌─┌─┐   \ /┌─┐│ │┌─┐   ┌ │┌─┐┌  ┐┌─     ┌─┐┌ │─┬─┌─┐┌ │┬┌─┐
├─│\│ │ ├─├─┘    Y │ ││ │├─┘   │\│├─┤│\/│├─ .   ├─┤│\│ │ │ ││\│││ │
└─│ ┘ │ └─│ \    │ └─┘└─┘│ \   │ ┘│ ││  │└─ .   │ ││ ┘ │ └─┘│ ┘┴└─┘

Name read: "Antonio"
Antonio 8)

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

Re: set/PBig: Input and output of bigger characters

#2 Post by Aacini » 11 Nov 2018 23:40

I developed a new version of this program that includes these features:
  • Definition of more than one font that can be selected via a parameter.
  • Management of lowercase letters.
  • Input of a variable without a prompt.

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 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=Std3x3"
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
:Std3x5

set "upcase=ABCDEFGHIJKLMNOPQRSTUVWXYZ"

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                                                                                              á  é  í  ó  ú  ñ
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 "size5[0]=  N    V    X    Y    Z   _v   _w "
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
Output example:

Code: Select all

C:\Users\Antonio\Documents\Test> BigLetters.bat Std3x5

┌─     │                                           ┌─┐    │        °
│  ┬─┐ ┼ ┌─┐┬─    \ /┌─┐│ │┬─    ┬─┐ ─┐┬┬┐┌─┐      │ │┬─┐ ┼ ┌─┐┬─┐ │ ┌─┐
├─ │ │ │ ├─┘│      Y │ ││ ││     │ │┌─┤│││├─┘ .    ├─┤│ │ │ │ ││ │ │ │ │
│  │ │ │ └─ │     /  └─┘└─┘│     │ │└─┘│││└─  .    │ ││ │ │ └─┘│ │ │ └─┘
└─                                                 │ │
Name read: "Antonio"
┌─     │                          ┌     │  │
│  ┬─┐ ┼ ┌─┐┬─    \ /┌─┐│ │┬─     ┼ │ │ │  │    ┬─┐ ─┐┬┬┐┌─┐
├─ │ │ │ ├─┘│      Y │ ││ ││      │ │ │ │  │    │ │┌─┤│││├─┘
│  │ │ │ └─ │     /  └─┘└─┘│      │ └─┘ └  └    │ │└─┘│││└─
└─
┌─┐    │        °       ┌─┐ ,             ┌─┐       │
│ │┬─┐ ┼ ┌─┐┬─┐ │ ┌─┐   │ │┌─┐┬─ ┌─┐¯¯/   │ │\ / ─┐ │  ─┐
├─┤│ │ │ │ ││ │ │ │ │   ├─┘├─┘│  ├─┘ /    ├─┤ Y ┌─┤ │ ┌─┤
│ ││ │ │ └─┘│ │ │ └─┘   │  └─ │  └─ /__   │ │/  └─┘ └ └─┘
│ │                     │                 │ │             .
Name read: "Antonio Pérez Ayala."
Antonio

Post Reply