Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

^e[0m and all the other !*#@%& ANSI codes

Aug
2,799
144
I've been following the other threads in the support forum in regards to the ANSI codes issues.

This is the year 2026.

Would it not be easier to use equates for the ANSI codes?

Code:
@SETLOCAL
@ECHO OFF
set _UpOneLine=`^e[A`
set _DownOneLine=`^e[B`
set _SaveCursor=`^e[s`
set _RestoreCursor=`^e[u`
set _UnderLine=`^e[4m`
set _Inverse=`^e[7m`
set _Italic=`^e[3m`
set _Bold=`^e[1m`
set _Reset=`^e[0m`
echo %_Underline``This is underlined.``%_Reset
color bright green on black
echo.
echo %_Inverse``This is inverse.``%_Reset
color bright green on black
echo.
rem Italic does not work in stand-alone tcc.exe
rem Italic does work in Windows Terminal
echo %_Italic``This is italic.``%_Reset
color bright green on black
ENDLOCAL

This seems more maintainable and readable.

1782858672305.webp


Joe
 
Well -- perhaps. Given the hundreds of ANSI sequences and thousands of variations on them, you would either have to limit yourself to a small subset, or you'd end up with a complex set of environment variables and a pretty large environment.

Also, some ANSI sequences aren't intended to be output by something like an ECHO.
 
Joe, interesting suggestion. I had already done that. When I start TCMD, I load a set of environment definitions from a file, and they include the ANSI sequences I'm likely to use (a few dozen). For me, as I reminder that they are ANSI sequences, the variable names start with ansi_. When they abut text, I have to remember to use the form %[ansi_...].

I would not suggest that they be built into TCC. Users who like the idea can implement it themselves in whatever way they like and for whatever codes they choose.
 
I agree @Jay Sage that they should not be built into TCC.

Glad to hear that you also do this,
and preceeding them with ansi_ is a good idea.

I have assigned TPipe numbers to respective aliases,
as those numbers are totally confusing to me.

Code:
ConvertASCIIToEBCDIC=tpipe /simple=1
ConvertEBCDICToASCII=tpipe /simple=2
ConvertPDFToText=`tpipe /input=%1 /simple=76 | view`
ConvertToLowerCase=tpipe /simple=6
ConvertToSentenceCase=tpipe /simple=8
ConvertToTitleCase=tpipe /simple=7
ConvertToUpperCase=tpipe /simple=8
RemoveBlanksFromEndOfLine=tpipe /simple=11
RemoveBlanksFromStartOfLine=tpipe /simple=12
RemoveHTML=tpipe /simple=16
RemoveMultipleWhiteSpace=tpipe /simple=19

Much easier now,
just as an example;
Code:
E:\...\pdf>echo THIS IS A TEST | ConvertToSentenceCase
This is a test

Again, I'm not suggesting that these be built into TCC,
just that assigning numbers,
and ANSI escape codes,
to names seems to make things more readable,
and easier to remember,
at least for me.

Joe
 
Back
Top