Color Macro

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
IcarusLives
Posts: 175
Joined: 17 Jan 2016 23:55

Color Macro

#1 Post by IcarusLives » 05 Jul 2017 16:56

Hello everyone,

After doing a lot of research on dostips about macros, and a fast color code (thank you einstein1969) I wanted to create a color macro. CALL execution is slow, but macros are fast!

Is it possible to make this faster? I'm out of ideas.. :shock:

Only tested on Win10 64bit

Image

Code: Select all

@echo off & setlocal enableDelayedExpansion

rem Code for color support
   for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E & echo on & for %%b in (1) do rem"') do set "DEL=%%a"
   <nul set /p ".=%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%" > "'"
   
rem Code for macro support
set ^"LF=^

^" Above empty line is required - do not remove
set ^"\n=^^^%LF%%LF%^%LF%%LF%^^"

rem macros - %getArgs% ""TEXT".95 "TEXT".BE "TEXT".C1 "TEXT".5D"
rem        - %colorArgs%
set getArgs=for %%# in (1 2) do if %%#==2 ( set "arguments=0" ^& for %%a in ("^!args^!") do (%\n%
   set /a "arguments+=1" ^& for /f "tokens=1,2 delims=." %%0 in ("%%~a") do if "%%1" neq "" (%\n%
      set "T[^!arguments^!]=%%~0"%\n%
      set "c[^!arguments^!]=%%~1"%\n%
      for /f "tokens=*" %%2 in ("T[^!arguments^!]") do set "%%~2=^!%%~2:~0,-1^!"%\n%
   ))%\n%
   for /f "tokens=*" %%2 in ("c[^!arguments^!]") do set "%%~2=^!%%~2:~0,-1^!"%\n%
   set "T[1]=^!T[1]:~3^!"%\n%
) else set args=
   
set "colorArgs=(for /l %%a in (1,1,^!arguments^!) do ( echo=^!t[%%a]^!\..\')^>cp.txt ^&^& findstr /a:^!c[%%a]^! /f:cp.txt ".") & echo."

echo.
%getArgs% ""Macro test".5A "  1  ".4E "   Unlimited parameters".9B"
%colorArgs%
echo.
%getArgs% ""Macro test".DC "  2  ".2D"
%colorArgs%
echo.
%getArgs% ""Macro test".32 "  3  ".47"
%colorArgs%
echo.
%getArgs% ""Macro test".91 "  4  ".F6"
%colorArgs%
pause & exit

einstein1969
Expert
Posts: 960
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: Color Macro

#2 Post by einstein1969 » 06 Jul 2017 10:34

hi IcarusLives,

very good work. 8)

I not known if possible make it faster. I thinks that is the maximum level of speed.

einstein1969

IcarusLives
Posts: 175
Joined: 17 Jan 2016 23:55

Re: Color Macro

#3 Post by IcarusLives » 06 Jul 2017 11:36

einstein1969 wrote:hi IcarusLives,

very good work. 8)

I not known if possible make it faster. I thinks that is the maximum level of speed.

einstein1969


Thank you!

I truly hope to find a faster method one day!

pieh-ejdsch
Posts: 240
Joined: 04 Mar 2014 11:14
Location: germany

Re: Color Macro

#4 Post by pieh-ejdsch » 07 Jul 2017 04:33

Hello Icarus,
Yuo can use a shorten macro like
Endlocal.set
viewtopic.php?f=3&t=7774#p51852
Phil

IcarusLives
Posts: 175
Joined: 17 Jan 2016 23:55

Re: Color Macro

#5 Post by IcarusLives » 07 Jul 2017 19:51

pieh-ejdsch wrote:Hello Icarus,
Yuo can use a shorten macro like
Endlocal.set
viewtopic.php?f=3&t=7774#p51852
Phil


I have never seen such a thing in batch before! Is there more documentation on this? I would love to learn about it!

Post Reply