-2

I'm using a premade batch chat and I want to improve it with my own touch.

When someone in the chat says something it will be typed like this: [John]: Hello World

What I want to do is get [John] in another color than the rest of the program. I can't make it work. I'd love for someone to help me bypass this.

EDIT: The call: command doesn't work on this. I've tried different batches like colormsg and ctext. None of them work. I think the problem lies at >> log.dat.

Here's the code:

@echo off
rem: Matthew Merchant ScriptingMadness.blogspot.com
rem ###### TITLE SCREEN ############
title Batch Chat Room
echo.
echo WELCOME TO THE CHAT!
echo:
echo:
echo Commands:
echo just hit ENTER to update screen.
echo.
set /p username=What is your name?
echo %username% has joined. >> log.dat
cls
goto CHATLOOP
REM ############################




REM ########## CHAT LOOP ##########
set lastmessage=""

:CHATLOOP
cls
type log.dat
echo.
echo.
set /p message=Say:

rem set message checker value
set thismessage="%message%"


rem check for exit
if %thismessage% == "EXIT" echo %username% has left the chat room. >> log.dat
if %thismessage% == "EXIT" exit
rem -----------------

rem check for clear
if %thismessage% == "CLS" echo %username% has cleared the chat log. > log.dat
if %thismessage% == "CLS" set message=Empty
if %thismessage% == "CLS" set lastmessage="Empty"
if %thismessage% == "CLS" goto CHATLOOP
rem ------------------

rem check for same message as last time
if %thismessage% == %lastmessage% goto CHATLOOP

rem if all checks out, go ahead and post this message
echo [%username%]: %message% >> log.txt

rem save value for next test
set lastmessage="%message%"

goto CHATLOOP
REM ################################

If you still don't understand what I mean. See above: I want %username% in another color than %message%

  • Also, see [this question](http://stackoverflow.com/questions/15015025/creating-colors-in-the-middle-of-a-line-in-batch/15017779#15017779) for more help. – BDM Mar 08 '13 at 23:44
  • Those doesn't work. Everything that uses the command "call" won't work. Tried different batches like colormsg aswell, I think the problem lies at ">> log.dat". – user2149978 Mar 09 '13 at 13:55
  • Why are you so certain that `call` won't work? One way to implement multiple colours in your case may be to replace your `type log.dat` with a more sophisticated method of displaying the contents of the file. You'll probably need to parse the file line by line, and in every line, separate the user name from the rest of the contents, then display each in different colour. Yes, you may need to learn something else for your problem, e.g. how to parse text files in batch files. But at least just don't reject a suggestion with a simple "won't work" without giving it a thought and a try. – Andriy M Mar 09 '13 at 19:14
  • Also, if you noticed, adding colours into batch scripts involves very non-trivial techniques. People wouldn't suggest that if there were easier ways. Therefore you may need to prepare yourself to the necessity of adapting *your script to the existing techniques* of multi-colour display rather than the other way round. – Andriy M Mar 09 '13 at 19:17
  • Try the code yourself with the `call`. It just don't work with the `>> log.dat`. And I have tried, else I wouldn't ask for help would I? – user2149978 Mar 13 '13 at 17:08

1 Answers1

0

it can't be done, this was my first programming language before vb.net, c# and whilst i spent 2-3 years coding in this, i noticed the color value sets the color for the background or the text but to define what text you want the color command to act on is - impossible - because it is not part of the command provided by Microsoft, remember its an administrative tool it wouldn't concentrate on defining the color of a specific text line...