how to ECHO in opposite colors?

Jun 3, 2008
132
3
Temecula, CA
In my TCC window (v16.03), I'd like to be able to have a function that will take an input string and display the text and background in opposite colors of what it normally is. For example, my TCC window uses bright cyan letters on a blue background. This function should display the text in blue letters on a bright cyan background. Ideally it should be able to do it interspersed within a single line, like:

Sample.png


I would imagine something like: ECHO This is bright cyan on blue. %@reversecolor[This is blue on bright cyan.] This is bright cyan on blue again.

Or maybe instead of %@reversecolor[], it could be %@echocolor[foreground, background, text]. Then it would be: ECHO This is bright cyan on blue. %@echocolor[blue, brightcyan, This is blue on bright cyan.] This is bright cyan on blue again.

Is this possible?
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,493
91
Albuquerque, NM
prospero.unm.edu
If you want to embed color changes within a command line like that, I think you'll have to use ANSI sequences. (Functions return strings, and strings don't have colors per se. But you could create functions, or variables, which return ANSI codes.)
 
May 20, 2008
11,530
102
Syracuse, NY, USA
SCRPUT might be useful sometimes, but it has limitations.

1513822644607.png


A plugin to add the necessary ANSI escape sequences wasn't too hard.

1513834772922.png
 
Jun 3, 2008
132
3
Temecula, CA
1513878793043.png


I know virtually nothing about ANSI sequences. But as you can see above, that has the side effect of not restoring the window to its prior colors. I did notice that if I executed the COLOR command immediately afterward, the colors were properly restored. But I couldn't figure out how to fit that within the alias. And I wouldn't want it just to use black on white, I would want it to use the opposite of the current colors. For example, most of my TCC windows use bright cyan on blue, so I would want the reverse to use blue on bright cyan. But ideally the alias would use the current FG and BG, not just hard-coded to blue on bright cyan.
 
May 20, 2008
11,530
102
Syracuse, NY, USA
"^e[0m" should restore the default colors. I know nothing about Win10's builtin ANSI support, but in Win7, it's a good idea to have TCC's colors (OPTION dialog) agree with the console's colors (console properties).

In your pic, you didn't get the reverse of light blue on dark blue. I think there may be two notions of what the default colors are.
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,493
91
Albuquerque, NM
prospero.unm.edu

Just curious. I guess you must be inserting ANSI sequences at both ends of the string -- reverse video at the front, and restore at the end.

(Since all functions are expanded before the command is executed, dynamically changing settings like TCC's internal colors in a function can yield confusing results.)
 
May 20, 2008
11,530
102
Syracuse, NY, USA
Just curious. I guess you must be inserting ANSI sequences at both ends of the string -- reverse video at the front, and restore at the end.
Yup, exactly. At the time, I had forgotten about ^e[7m. That'll make it quite a bit easier, smaller, faster
 
Jun 3, 2008
132
3
Temecula, CA
Trying to make sense of a bunch of this stuff. (BTW, I'm running Win7-64, not Win10.)

OK, for my TCC options, I have the following:

1513894926590.png


So whatever the console window's properties are, TCC should inherit them.

1513894972154.png
1513895042283.png


So we can see that the console's defaults are bright cyan on blue.

But regardless, after using the function, the screen should return to whatever we've set it to - either the default, if we didn't set it, or to whatever we might have overridden the default with the COLOR command.
 
May 20, 2008
11,530
102
Syracuse, NY, USA
I dunno. I have always told TCC the same FG and BG that I tell the console, and here, that also agrees with the console defaults (system menu\defaults, and stored in HKCU\Console). Those defaults are usually WHI on BLA (which you're seeing). I'd be very surprised if TCC were using them. Perhaps Rex will chime in with an explanation of what's going on.
 
Jun 3, 2008
132
3
Temecula, CA
Well, I will say that I nearly always do have my TCC window using the same FG and BG values as the console defaults. However, they aren't WHI on BLA. Maybe the problem is that the ANSI implementation doesn't use the console defaults, but instead assumes the "normal" defaults and uses the reverse of them for its reverse implementation.
 
Similar threads
Thread starter Title Forum Replies Date
old coot Spurious errors (triggered by "for" construct?) when adding/removing "echo" lines Support 2
fpefpe How to? command echo in title line/bar Support 2
vefatica @EXECSTR clobbers @ECHO ON Support 2
L WAD ECHO. expansion of non-existent env-vars differs from CMD.exe Support 6
D Does TCC improve CMD's implementation of ECHO? Support 6
E My echo full file name to the clipboard fails now. Support 2
Joe Caverly Echo message works without the space? Support 3
T Fixed Echo randomly activated in script Support 4
S How to? ^C echo Support 6
vefatica ECHO is very slow Support 9
J How to? Riddle: How to echo > into a file? Support 7
Alexander How to? how can I use Cyrillic characters in the Echo command? Support 8
jadaml Echo unicode characters from UTF-8 Batch files? Support 1
vefatica WAD DO, ECHO, and trailing whitespace Support 3
nickles WAD echo "%PROGRAMFILES(X86)%" Support 16
J Can you redirect output to printer device with echo? Support 1
M How to? Save and then restore "Echo" status Support 2
T Set 1% then Echo 1% Support 9
M echo %@index[1234,.,-1] return -21 in new version Support 3
Roedy ECHO bug Support 4
T How do you echo lines with special characters to file? Support 4
C opposite of differ? Support 1
old coot tee command cancels colors Support 33
CWBillow TCMD Colors Support 8
samintz ANSI Colors Support 33
nickles ANSI Colors Windows 7 no longer working Support 6
R How to? Obtain current colors Support 2
M TCC screen text bright colors not as bright in 24 as 23 Support 5
Alpengreis Problem with thousands delimiter and colors Support 17
gschizas Take Command (Environment) doesn't show v2 ANSI colors Support 30
W Custom colors not saved in TCC 14 / Windows 7 x64 Support 4
gschizas (minor) Help topic "Colors, Color Names and Codes" is wrong Support 0
T signaling firstcondition and cannot change colors Support 8
J Colors in tcmd (one more try) Support 1
J History colors Support 3
B Colors discovered Support 4
D TCC.exe 12.0 & 12.1 and Colors Support 10
electrotype Powershell in Take Command - Customizing colors? Support 4
R tcc colors. Support 3
C Attaching PowerShell changes its colors and makes it hard to read Support 15
nickles Console colors Support 6
M TCC Prompt Here Colors Support 0
J TC10 colors compared to v8 Support 1
M Background colors in TCC prompts (version 9.x) Support 5
Phileosophos LIST command colors? Support 3

Similar threads