CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   Computer Programming (http://www.codingforums.com/forumdisplay.php?f=21)
-   -   Rainbow Text in Command Prompt (http://www.codingforums.com/showthread.php?t=286128)

Justsawyer 01-20-2013 04:39 AM

Rainbow Text in Command Prompt
 
1 Attachment(s)
So I'm coding a silly little program in .bat for command prompt, and can't seem to figure out how colors and text work? This is what I have so far:

@echo off
:start
color 02
echo I eat poop
goto start


but it is just 1 color, I want it to change the text color but have the same text every time, or maybe diffrent text, that doesn't matter, just a diffrent color every line, say like this:

@echo off
:start
color 02
echo I eat poop
color 03
echo I eat poop
color 04
echo I eat poop
color 05

goto start


I've tried that but it just keeps the text one color :( any help? also picture below

AceInfinity 01-20-2013 03:14 PM

By default you can't do this, there's no way to structurally have multiple colors by the calling color.exe because it's designed to change the full console's text. There is a work around fortunately.

http://i.imgur.com/Ou7Dlxe.png

Using prompt.exe you can use Escape codes in a manner that enables you to have multiple colors in the console. Prompt.exe enables you to change the command prompt. For more information type "prompt /?" (without quotes), in your cmd prompt.

Example:
Code:

@echo off
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & for %%b in (1) do rem"') do (
        set "DEL=%%a"
)
SETLOCAL EnableDelayedExpansion

call :C F0 "Color"
call :C A0 "Change"
echo.
pause && goto :eof

:C
echo off
<nul set /p ".=%DEL%" > "%Temp%\%~2"
cd %Temp%
findstr /v /a:%1 /R "^$" "%~2" nul
del "%Temp%\%~2" > nul 2>&1
goto :eof


Justsawyer 01-20-2013 06:18 PM

1 Attachment(s)
Thanks ^_^ works great, I don't really understand the top and bottom code , but this is what it got from it:

@echo off
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & for %%b in (1) do rem"') do (
set "DEL=%%a"
)
SETLOCAL EnableDelayedExpansion
:start
call :C C0 "POOP`"
call :C E0 "POOP`"
call :C A0 "POOP`"
call :C B0 "POOP`"
goto start


echo.
pause && goto :eof

:C
echo off
<nul set /p ".=%DEL%" > "%Temp%\%~2"
cd %Temp%
findstr /v /a:%1 /R "^$" "%~2" nul
del "%Temp%\%~2" > nul 2>&1
goto :eof


It works fine, but it would be nice if it printed faster, it takes about 20 seconds to fill the whole command prompt, anyway to make it faster? also moar pics in the bottem

Also this same code works when on my hardrive, but not when on a flashdrive :/

Justsawyer 01-20-2013 10:02 PM

1 Attachment(s)
also ALSO my copy script isn't working either trying to copy the fil

COPY F:\batrainbow.bat*.* C:\
pause

batrainbow.bat being the colorful poop repeating file, but when I run it it gives me this:

AceInfinity 01-20-2013 11:30 PM

Why does the first argument have the filename and extension while you put a wildcard on a filename following another extension afterwards?
Code:

filename.ext*.*
Also, you have to run this script as admin if you're copying to the Windows installation drive (C:\), and instead of the full filepath why don't you just use %0?....

Justsawyer 01-20-2013 11:52 PM

whats %0? ^_^ i'm a complete noobly to mostly all coding

AceInfinity 01-20-2013 11:53 PM

Try it for yourself:
Code:

echo %0

Justsawyer 01-22-2013 05:13 AM

lol done http://www.codingforums.com/showthread.php?t=286173


All times are GMT +1. The time now is 11:25 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.