Color function v19

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
Boombox
Posts: 80
Joined: 18 Oct 2012 05:51

Re: Color function v14.1

#16 Post by Boombox » 29 Nov 2012 01:42

.
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...
Last edited by Boombox on 29 Nov 2012 02:01, edited 2 times in total.

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Color function v14.1

#17 Post by abc0502 » 29 Nov 2012 01:47

what do you mean ?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Color function v14.1

#18 Post by foxidrive » 29 Nov 2012 02:08

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?

Boombox
Posts: 80
Joined: 18 Oct 2012 05:51

Re: Color function v14.1

#19 Post by Boombox » 29 Nov 2012 03:30

.
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.

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Color function v14.1

#20 Post by abc0502 » 29 Nov 2012 04:09

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 ?

carlos
Expert
Posts: 503
Joined: 20 Aug 2010 13:57
Location: Chile
Contact:

Re: Color function v17

#21 Post by carlos » 03 Dec 2012 16:49

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.

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Color function v17

#22 Post by abc0502 » 04 Dec 2012 04:12

Nice work :D ,
it just need to escape the % by adding another % sign and the < and > with ^

carlos
Expert
Posts: 503
Joined: 20 Aug 2010 13:57
Location: Chile
Contact:

Re: Color function v17

#23 Post by carlos » 04 Dec 2012 09:29

Thanks abc0502.

carlos
Expert
Posts: 503
Joined: 20 Aug 2010 13:57
Location: Chile
Contact:

Re: Color function v18

#24 Post by carlos » 13 Dec 2012 19:21

Posted the version 18 that run more speedy than version 17.

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Color function v18

#25 Post by dbenham » 14 Dec 2012 08:31

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

carlos
Expert
Posts: 503
Joined: 20 Aug 2010 13:57
Location: Chile
Contact:

Re: Color function v19

#26 Post by carlos » 14 Dec 2012 13:50

Updated to version 19 that have support for extended ascii characters, please see remarks in code.

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Color function v19

#27 Post by dbenham » 17 Dec 2012 10:27

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

Post Reply