Page 1 of 1

Box Drawing and Prompt

Posted: 2021-Dec-12, 10:47 pm
by VincentD
Hi.

I search the web to found a solution to make Box Drawing in CMD script.
Because for fun I just want to have the prompt like the Kali Linux prompt. and I need this char.

I made a lots of attempts which failed. I found nothing to work on internet.

But after some reflexion I found a solution.

1st:
In Notepad++ create a file in ANSI mode.
Use the key code Alt+0nnn to make the correct characters for the box.
Draw your box with the code.
Save the file. Test. Correct. Save. Test. Etc.

Do not copy/past what you have on the screen.

2nd:
Then switch to encode in UTF8 => DO NOT CONVERT TO UTF8
Now You have the right characters to draw box. They are in hex like xB3.
Just Copy Past in your code and save (.cmd recommanded).

And it works fine for me.
Light Box Drawings works.
Double Box Drawings works.

In CMD my CHCP is 850, some char doesn't works.

So I can draw box and use this char to change my prompt.

The code cannot be past in UTF8.
Here the ANSI format.
Copy/Past in a ANSI file. Then encode to UTF-8 (NO CONVERTION). Save. Launch. Et voilà.

Code: Select all

@ECHO OFF
PROMPT $E[32mÚÄÄ$C$E[94m%USERNAME%@%COMPUTERNAME%$E[32m$F-[$E[97m$P$E[32m]$_ÀÄ$$$S$E[0m
My try for Boxes :

Same, this is ANSI, copy/past in an ANSI file then change to UTF-8 and save. then launch.

PROBLEM: Alt+027 the ESC don't show (before all color scheme "ESC[nm"). Don't know how to correct this.

Code: Select all

@ECHO OFF
::
::=============================================================================
:: Script:  DrawBoxAnsi.cmd
:: Comment: How to draw box in cmd 
:: Version: v20211212
::=============================================================================
::
ECHO.
ECHO ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
ECHO ³ [97mTrick to Box drawings in Windows CMD[0m       ³
ECHO ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
ECHO. 
ECHO [4m[97m1st:[0m
ECHO In [92mNotepad++[0m create a file in [91mANSI mode[0m.
ECHO Use the key code [97mAlt[0m+[91m0nnn[0m to make the correct characters for the box.
ECHO Draw your box with the code in the tables below.
ECHO Save the file. Test. Correct. Save. Test. Etc.
ECHO.
ECHO [91mDo not copy/past what you have on the screen.[0m
ECHO.
ECHO [4m[97m2nd:[0m
ECHO Then switch to encode in UTF8 =^> [91mDO NOT CONVERT TO UTF8[0m
ECHO Now You have the right characters to draw box. They are in hex like [7mxB3[0m.
ECHO Just Copy Past in your code and save (.cmd recommanded).
ECHO.
ECHO [4m[97mExamples:[0m
ECHO.
::
ECHO ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÂÄÄÄÄÄÄÄÄÄÄ¿
ECHO ³ [97mLight Box drawings, one line[0m               ³   ³ [97mAlt Seq[0m  ³
ECHO ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÅÄÄÄÄÄÄÄÄÄÄ´
ECHO ³ [93mBox drawings light vertical[0m                ³ ³ ³ [97malt[0m+[91m0179[0m ³
ECHO ³ [93mBox drawings light vertical and left[0m       ³ ´ ³ [97malt[0m+[91m0180[0m ³
ECHO ³ [93mBox drawings light down and left[0m           ³ ¿ ³ [97malt[0m+[91m0191[0m ³
ECHO ³ [93mBox drawings light up and right[0m            ³ À ³ [97malt[0m+[91m0192[0m ³
ECHO ³ [93mBox drawings light horizontal[0m              ³ Ä ³ [97malt[0m+[91m0196[0m ³
ECHO ³ [93mBox drawings light vertical and right[0m      ³ Ã ³ [97malt[0m+[91m0195[0m ³
ECHO ³ [93mBox drawings light down and horizontal[0m     ³ Â ³ [97malt[0m+[91m0194[0m ³
ECHO ³ [93mBox drawings light up and horizontal[0m       ³ Á ³ [97malt[0m+[91m0193[0m ³
ECHO ³ [93mBox drawings light vertical and horizontal[0m ³ Å ³ [97malt[0m+[91m0197[0m ³
ECHO ³ [93mBox drawings light up and left[0m             ³ Ù ³ [97malt[0m+[91m0217[0m ³
ECHO ³ [93mBox drawings light down and right[0m          ³ Ú ³ [97malt[0m+[91m0218[0m ³
ECHO ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÁÄÄÄÄÄÄÄÄÄÄÙ
::
ECHO.
ECHO Seem to be good for Light Box drawings.
ECHO.
::
ECHO ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍËÍÍÍËÍÍÍÍÍÍÍÍÍÍ»
ECHO º [97mDouble Box Drawings, two lines[0m              º   º [97mAlt Seq[0m  º
ECHO ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÎÍÍÍÎÍÍÍÍÍÍÍÍÍ͹
ECHO º [93mBox drawings double vertical and left[0m       º ¹ º [97malt[0m+[91m0185[0m º
ECHO º [93mBox drawings double horizontal[0m              º Í º [97malt[0m+[91m0205[0m º
ECHO º [93mBox drawings double vertical[0m                º º º [97malt[0m+[91m0186[0m º
ECHO º [93mBox drawings double down and left[0m           º » º [97malt[0m+[91m0187[0m º
ECHO º [93mBox drawings double up and left[0m             º ¼ º [97malt[0m+[91m0188[0m º
ECHO º [93mBox drawings double up and right[0m            º È º [97malt[0m+[91m0200[0m º
ECHO º [93mBox drawings double down and right[0m          º É º [97malt[0m+[91m0201[0m º
ECHO º [93mBox drawings double up and horizontal[0m       º Ê º [97malt[0m+[91m0202[0m º
ECHO º [93mBox drawings double down and horizontal[0m     º Ë º [97malt[0m+[91m0203[0m º
ECHO º [93mBox drawings double vertical and right[0m      º Ì º [97malt[0m+[91m0204[0m º
ECHO º [93mBox drawings double vertical and horizontal[0m º Î º [97malt[0m+[91m0206[0m º
ECHO ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÊÍÍÍÊÍÍÍÍÍÍÍÍÍͼ
::
ECHO.
ECHO Seem to be good for Double Box drawings.
ECHO.
::
ECHO ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÂÄÄÄÄÄÄÄÄÄÄ¿
ECHO ³ [97mLight Double Box drawings, one and two line[0m        ³   ³ [97mAlt Seq[0m  ³
ECHO ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÅÄÄÄÄÄÄÄÄÄÄ´
ECHO ³ [93mBox drawings vertical single and left double[0m       ³ µ ³ [97malt[0m+[91m0181[0m ³
ECHO ³ [93mBox drawings vertical double and left single[0m       ³ ¶ ³ [97malt[0m+[91m0182[0m ³
ECHO ³ [93mBox drawings down double and left single[0m           ³ · ³ [97malt[0m+[91m0183[0m ³
ECHO ³ [93mBox drawings down single and left double[0m           ³ ¸ ³ [97malt[0m+[91m0184[0m ³
ECHO ³ [93mBox drawings up double and left single [0m            ³ ½ ³ [97malt[0m+[91m0189[0m ³
ECHO ³ [93mBox drawings up single and left double[0m             ³ ¾ ³ [97malt[0m+[91m0190[0m ³
ECHO ³ [93mBox drawings vertical single and right double[0m      ³ Æ ³ [97malt[0m+[91m0198[0m ³
ECHO ³ [93mBox drawings vertical double and right single[0m      ³ Ç ³ [97malt[0m+[91m0199[0m ³
ECHO ³ [93mBox drawings up single and horizontal double[0m       ³ Ï ³ [97malt[0m+[91m0207[0m ³
ECHO ³ [93mBox drawings up double and horizontal single[0m       ³ Ð ³ [97malt[0m+[91m0208[0m ³
ECHO ³ [93mBox drawings down single and horizontal double[0m     ³ Ñ ³ [97malt[0m+[91m0209[0m ³
ECHO ³ [93mBox drawings down double and horizontal single [0m    ³ Ò ³ [97malt[0m+[91m0210[0m ³
ECHO ³ [93mBox drawings up double and right single[0m            ³ Ó ³ [97malt[0m+[91m0211[0m ³
ECHO ³ [93mBox drawings up single and right double[0m            ³ Ô ³ [97malt[0m+[91m0212[0m ³
ECHO ³ [93mBox drawings down single and right double[0m          ³ Õ ³ [97malt[0m+[91m0213[0m ³
ECHO ³ [93mBox drawings down double and right single[0m          ³ Ö ³ [97malt[0m+[91m0214[0m ³
ECHO ³ [93mBox drawings vertical double and horizontal single[0m ³ × ³ [97malt[0m+[91m0215[0m ³
ECHO ³ [93mBox drawings vertical single and horizontal double[0m ³ Ø ³ [97malt[0m+[91m0216[0m ³
ECHO ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÁÄÄÄÄÄÄÄÄÄÄÙ
ECHO.
ECHO [91mDoes not work for Light Double Box drawings[0m, so this is useless in code page 850.
ECHO.
ECHO Technicaly works for every UNICODE, but need to test it.
ECHO Blocks elements: ß Ü Û ° ± ² ; Except Ý (0221) Þ (0222)
ECHO.
:END


Re: Box Drawing and Prompt

Posted: 2021-Dec-21, 6:18 pm
by qwerty
Keep in mind, you can capture the ESC character as a variable and then use it with the appropriate terminal escape sequence to indicate the color:

Code: Select all

for /f %%e in ('echo prompt $E^|cmd') do set "\e=%%e"
echo %\e%[97m