Page 2 of 2

Re: Color function v14.1

Posted: 29 Nov 2012 01:42
by Boombox
.
Can we use this to type a file or command to the CMD window, highlighting only the word/s we have chosen?

e.g

Runing tasklist to highlight any process with MEMUSAGE above 100mb.

or Notepad++ for batch

Type specified batch file to screen, highlighting variables in orange, commands in blue, notes in green...

Re: Color function v14.1

Posted: 29 Nov 2012 01:47
by abc0502
what do you mean ?

Re: Color function v14.1

Posted: 29 Nov 2012 02:08
by foxidrive
Boombox wrote:.
Can we use this to type a file or command to the CMD window, highlighting only the word/s we have chosen?


Doing that with the batch code would be very inefficient.

Do you want to dump the entire file to the screen, colouring just one/two keywords?

If the file is huge, do you only want a window around the keyword? (+/- say 5 lines?) or to pause after every screen full of the entire log file?

Re: Color function v14.1

Posted: 29 Nov 2012 03:30
by Boombox
.
Regardless of the input file size, computational power...

This,

@echo off
echo %var%>test.txt
copy test.txt d:\test.txt
::This is green!
pause
exit

should look like this...

@echo off
echo %var%>test.txt
copy test.txt d:\test.txt
::This is green!
pause
exit

Thanks.

Re: Color function v14.1

Posted: 29 Nov 2012 04:09
by abc0502
I think that could be by comparing the text in the file with a pre-defined list with the color attribute.
but what exactly do you want to do ?

Re: Color function v17

Posted: 03 Dec 2012 16:49
by carlos
Dave, thanks for insert the idea of split the special characters in LF. It was very useful for increase the speed of the code.
I take that and develop the version 15. But, accidentally I insert a compatibility problem using some atributes to a file. Anyways, I refined the code many times and now I use the back quote instead of the quote (solving the compatibility problem). Please look the code of the version 17, is very small.
If you ask self why I generate a bat file, is because I post the code in a google groups and it "usenet" insert a space in end of every line, then the critical line for make the variable with the lf will be damaged.
I found some inconsistences in your code that I post in the other post.

Re: Color function v17

Posted: 04 Dec 2012 04:12
by abc0502
Nice work :D ,
it just need to escape the % by adding another % sign and the < and > with ^

Re: Color function v17

Posted: 04 Dec 2012 09:29
by carlos
Thanks abc0502.

Re: Color function v18

Posted: 13 Dec 2012 19:21
by carlos
Posted the version 18 that run more speedy than version 17.

Re: Color function v18

Posted: 14 Dec 2012 08:31
by dbenham
npocmaka discovered at SS64 that FINDSTR corrupts many extended ASCII characters within file names supplied on the command line. I've updated my SO FINDSTR post to reflect the new FINDSTR information.

I also updated the ColorPrint algorithm so that it now supports ALL single byte characters except 0x00 (nul), 0x0A (linefeed), and 0x0D (carriage return). The trick is to use the "/F:FILE" option instead of supplying the file name on the command line. The double quotes no longer need to be escaped.

Note that if run on XP then most control characters will be displayed as dots. This is a "feature" of FINDSTR that cannot be defeated.

Just for fun, I grabbed some color ASCII art from joan stark's ASCII Art Gallery and adapted it for use with ColorPrint. I added a :c entry point just for shorthand, and to handle an issue with quote literals.

Code: Select all

@echo off
setlocal disableDelayedExpansion
::
:: The following image was adapted from joan stark's ASCII Art Gallery
:: http://www.geocities.com/SoHo/7373/indexjava.htm
::
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



Dave Benham

Re: Color function v19

Posted: 14 Dec 2012 13:50
by carlos
Updated to version 19 that have support for extended ascii characters, please see remarks in code.

Re: Color function v19

Posted: 17 Dec 2012 10:27
by dbenham
Not all extended ASCII display as dots on XP. Only the characters that require the /F option in the first place.

So the /F option does not help XP display extended ASCII. But it does enable the technique to display all chars on Vista and later versions.


Dave Benham