Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Nov 2012
    Posts
    17
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Rainbow Text in Command Prompt

    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
    Attached Thumbnails Attached Thumbnails Rainbow Text in Command Prompt-rainbow.png  

  • #2
    New Coder
    Join Date
    Jan 2013
    Location
    Canada
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.



    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

  • #3
    New Coder
    Join Date
    Nov 2012
    Posts
    17
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Macintosh

    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 :/
    Attached Thumbnails Attached Thumbnails Rainbow Text in Command Prompt-pics.png  
    Last edited by Justsawyer; 01-20-2013 at 08:05 PM.

  • #4
    New Coder
    Join Date
    Nov 2012
    Posts
    17
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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:
    Attached Thumbnails Attached Thumbnails Rainbow Text in Command Prompt-dsdsdsdsdsdsds.png  

  • #5
    New Coder
    Join Date
    Jan 2013
    Location
    Canada
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?....

  • #6
    New Coder
    Join Date
    Nov 2012
    Posts
    17
    Thanks
    1
    Thanked 0 Times in 0 Posts
    whats %0? ^_^ i'm a complete noobly to mostly all coding

  • #7
    New Coder
    Join Date
    Jan 2013
    Location
    Canada
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try it for yourself:
    Code:
    echo %0

  • #8
    New Coder
    Join Date
    Nov 2012
    Posts
    17
    Thanks
    1
    Thanked 0 Times in 0 Posts


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •