Hello,
Just a small question, is it possible to add color to console app text output (see example here)? It would be great if I could use green, yellow and red to indicate my script status when using the console app interface. Not a deal breaker but a nice feature to have.
My latest SolidWorks API application uses the command line to talk to SolidWorks and it would be nice if I could use colors to display the state of the app.
Concept picture:
Add color to console app text output
Moderators: Dorian (MJT support), JRL
- Grovkillen
- Automation Wizard
- Posts: 1027
- Joined: Fri Aug 10, 2012 2:38 pm
- Location: Bräcke, Sweden
- Contact:
- Marcus Tettmar
- Site Admin
- Posts: 7380
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
No, none that I am aware of.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
- Grovkillen
- Automation Wizard
- Posts: 1027
- Joined: Fri Aug 10, 2012 2:38 pm
- Location: Bräcke, Sweden
- Contact:
- Grovkillen
- Automation Wizard
- Posts: 1027
- Joined: Fri Aug 10, 2012 2:38 pm
- Location: Bräcke, Sweden
- Contact:
Re: Add color to console app text output
I found this today. Is it possible to do something with this?
http://stackoverflow.com/a/5344911/463115
Save this as a Bacth.bat file and watch it print!
EDIT: found this aswell:
http://www.dostips.com/forum/viewtopic.php?f=3&t=4881
http://stackoverflow.com/a/5344911/463115
Save this as a Bacth.bat file and watch it print!
Code: Select all
@echo off
setlocal disableDelayedExpansion
set q=^"
echo(
echo(
call :c 0E " , .-;" /n
call :c 0E " , |\ / / __," /n
call :c 0E " |\ '.`-.| |.'.-'" /n
call :c 0E " \`'-: `; : /" /n
call :c 0E " `-._'. \'|" /n
call :c 0E " ,_.-=` ` ` ~,_" /n
call :c 0E " '--,. "&call :c 0c ".-. "&call :c 0E ",=!q!." /n
call :c 0E " / "&call :c 0c "{ "&call :c 0A "* "&call :c 0c ")"&call :c 0E "`"&call :c 06 ";-."&call :c 0E "}" /n
call :c 0E " | "&call :c 0c "'-' "&call :c 06 "/__ |" /n
call :c 0E " / "&call :c 06 "\_,\|" /n
call :c 0E " | (" /n
call :c 0E " "&call :c 0c "__ "&call :c 0E "/ ' \" /n
call :c 02 " /\_ "&call :c 0c "/,'`"&call :c 0E "| ' "&call :c 0c ".-~!q!~~-." /n
call :c 02 " |`.\_ "&call :c 0c "| "&call :c 0E "/ ' , "&call :c 0c "/ \" /n
call :c 02 " _/ `, \"&call :c 0c "| "&call :c 0E "; , . "&call :c 0c "| , ' . |" /n
call :c 02 " \ `, "&call :c 0c "| "&call :c 0E "| , , "&call :c 0c "| : ; : |" /n
call :c 02 " _\ `, "&call :c 0c "\ "&call :c 0E "|. , "&call :c 0c "| | | | |" /n
call :c 02 " \` `. "&call :c 0c "\ "&call :c 0E "| ' "&call :c 0A "|"&call :c 0c "\_|-'|_,'\|" /n
call :c 02 " _\ `, "&call :c 0A "`"&call :c 0E "\ ' . ' "&call :c 0A "| | | | | "&call :c 02 "__" /n
call :c 02 " \ `, "&call :c 0E "| , ' "&call :c 0A "|_/'-|_\_/ "&call :c 02 "__ ,-;` /" /n
call :c 02 " \ `, "&call :c 0E "\ . , ' .| | | | | "&call :c 02 "_/' ` _=`|" /n
call :c 02 " `\ `, "&call :c 0E "\ , | | | | |"&call :c 02 "_/' .=!q! /" /n
call :c 02 " \` `, "&call :c 0E "`\ \/|,| ;"&call :c 02 "/' .=!q! |" /n
call :c 02 " \ `, "&call :c 0E "`\' , | ; "&call :c 02 "/' =!q! _/" /n
call :c 02 " `\ `, "&call :c 05 ".-!q!!q!-. "&call :c 0E "': "&call :c 02 "/' =!q! /" /n
call :c 02 " jgs _`\ ;"&call :c 05 "_{ ' ; "&call :c 02 "/' =!q! /" /n
call :c 02 " _\`-/__"&call :c 05 ".~ `."&call :c 07 "8"&call :c 05 ".'.!q!`~-. "&call :c 02 "=!q! _,/" /n
call :c 02 " __\ "&call :c 05 "{ '-."&call :c 07 "|"&call :c 05 ".'.--~'`}"&call :c 02 " _/" /n
call :c 02 " \ .=!q!` "&call :c 05 "}.-~!q!'"&call :c 0D "u"&call :c 05 "'-. '-..' "&call :c 02 "__/" /n
call :c 02 " _/ .!q! "&call :c 05 "{ -'.~('-._,.'"&call :c 02 "\_,/" /n
call :c 02 " / .!q! _/'"&call :c 05 "`--; ; `. ;" /n
call :c 02 " .=!q! _/' "&call :c 05 "`-..__,-'" /n
call :c 02 " __/'" /n
echo(
exit /b
:c
setlocal enableDelayedExpansion
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:colorPrint Color Str [/n]
setlocal
set "s=%~2"
call :colorPrintVar %1 s %3
exit /b
:colorPrintVar Color StrVar [/n]
if not defined DEL call :initColorPrint
setlocal enableDelayedExpansion
pushd .
':
cd \
set "s=!%~2!"
:: The single blank line within the following IN() clause is critical - DO NOT REMOVE
for %%n in (^"^
^") do (
set "s=!s:\=%%~n\%%~n!"
set "s=!s:/=%%~n/%%~n!"
set "s=!s::=%%~n:%%~n!"
)
for /f delims^=^ eol^= %%s in ("!s!") do (
if "!" equ "" setlocal disableDelayedExpansion
if %%s==\ (
findstr /a:%~1 "." "\'" nul
<nul set /p "=%DEL%%DEL%%DEL%"
) else if %%s==/ (
findstr /a:%~1 "." "/.\'" nul
<nul set /p "=%DEL%%DEL%%DEL%%DEL%%DEL%"
) else (
>colorPrint.txt (echo %%s\..\')
findstr /a:%~1 /f:colorPrint.txt "."
<nul set /p "=%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%"
)
)
if /i "%~3"=="/n" echo(
popd
exit /b
:initColorPrint
for /f %%A in ('"prompt $H&for %%B in (1) do rem"') do set "DEL=%%A %%A"
<nul >"%temp%\'" set /p "=."
subst ': "%temp%" >nul
exit /b
:cleanupColorPrint
2>nul del "%temp%\'"
2>nul del "%temp%\colorPrint.txt"
>nul subst ': /d
exit /b
EDIT: found this aswell:
http://www.dostips.com/forum/viewtopic.php?f=3&t=4881
- Grovkillen
- Automation Wizard
- Posts: 1027
- Joined: Fri Aug 10, 2012 2:38 pm
- Location: Bräcke, Sweden
- Contact:
- Grovkillen
- Automation Wizard
- Posts: 1027
- Joined: Fri Aug 10, 2012 2:38 pm
- Location: Bräcke, Sweden
- Contact:
Re: Add color to console app text output
Sorry to lift this once again but it'd be great if someone could point me in the right direction on how to use the phyton-plugin (if possible)?
- Grovkillen
- Automation Wizard
- Posts: 1027
- Joined: Fri Aug 10, 2012 2:38 pm
- Location: Bräcke, Sweden
- Contact:
Re: Add color to console app text output
I'm not able to try this on a Win10 computer right now but it seems like as of Win10 some colors are supported by the console.
http://www.nivot.org/blog/post/2016/02/ ... hancements
Any thoughts?
http://www.nivot.org/blog/post/2016/02/ ... hancements
Any thoughts?
- Grovkillen
- Automation Wizard
- Posts: 1027
- Joined: Fri Aug 10, 2012 2:38 pm
- Location: Bräcke, Sweden
- Contact:
Re: Add color to console app text output
I just complied following script and tried on my Win10-tablet and it indeed worked! It'll work on Win7 and Win8 by using the ConEmu software for those with older systems. But yes, it worked nativly in Win10!!!
EDIT: Colors i found so far (ConEmu):
ESC[0;30;40m = Black
ESC[0;30;41m = Blue
ESC[0;30;42m = Green 1
ESC[0;30;43m = Green 2
ESC[0;30;44m = Red
ESC[0;30;45m = Magenta
ESC[0;30;46m = Brown
ESC[0;30;47m = White
(Win10 cmd)
ESC[0;30;40m = Black
ESC[0;30;41m = Red
ESC[0;30;42m = Green
ESC[0;30;43m = Yellow/Brown
ESC[0;30;44m = Blue
ESC[0;30;45m = Magenta
ESC[0;30;46m = Turquoise
ESC[0;30;47m = White
EDIT2: found all the available colors here(scroll down a bit)...
Code: Select all
Let>TEXT1=Will it work....
SOWrite>%TEXT1%
Wait>1
Let>TEXT2=Yay!
//"^[0;30;47m" is just a random color I picked, "^[0m" is to turn the color back to default (none)
SOWriteLn>^[0;30;47m%TEXT2%^[0m
//"^" need to be replace with the "escape code" (please refer to my attached .scp file)
//Compile as a console app and start using the cmd
ESC[0;30;40m = Black
ESC[0;30;41m = Blue
ESC[0;30;42m = Green 1
ESC[0;30;43m = Green 2
ESC[0;30;44m = Red
ESC[0;30;45m = Magenta
ESC[0;30;46m = Brown
ESC[0;30;47m = White
(Win10 cmd)
ESC[0;30;40m = Black
ESC[0;30;41m = Red
ESC[0;30;42m = Green
ESC[0;30;43m = Yellow/Brown
ESC[0;30;44m = Blue
ESC[0;30;45m = Magenta
ESC[0;30;46m = Turquoise
ESC[0;30;47m = White
EDIT2: found all the available colors here(scroll down a bit)...
- Grovkillen
- Automation Wizard
- Posts: 1027
- Joined: Fri Aug 10, 2012 2:38 pm
- Location: Bräcke, Sweden
- Contact:
Re: Add color to console app text output
Just a nice to have feature: would it be possible to have "escape code character" as an internal variable or something similar. It would be a bit easier to call that variable than copy the escape charater from my notepad document. (I have no idea how to get this character using ascii command).
Re: Add color to console app text output
Its been about 20 years since I've used ansi codes but I believe ansi escape is ASCII character 27. Therefore you can assign the character to a variable like this:
Code: Select all
VBEval>chr(27),esc