echoes text in a specific color - help

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
alexsander.albani
Posts: 7
Joined: 10 Apr 2012 19:17

echoes text in a specific color - help

#1 Post by alexsander.albani » 10 Apr 2012 19:35

Hi! I'm new at the forum.
First I'd like to thanks, 'cause I already used many tips and examples of codes posted here!

Now, my question:
- I'm trying to use the echo function posted here, in order to echoes with colors. It works fine, but I need to have a screen with many rows (scroll) and when I use the echo function, the screen buffer is missed. It seens like the cmd window resizes each time it calls the echo and then turn back to the original size and some upper rows are missed.

Does anybody know how to solve that?

Thanks a lot!

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: echoes text in a specific color - help

#2 Post by Ed Dyreen » 11 Apr 2012 00:54



Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: echoes text in a specific color - help

#4 Post by Ed Dyreen » 11 Apr 2012 10:13

'
Well, I'm getting the famous for /f bug on XP, and did a dirty quick fix.

I see what u mean now, the screen buffer is being eaten and it seems to be caused by the COM file,
I know close to nothing about COM files, let's wait for an assembly wizard to pass by...

I'm interested in which OS you use, as you say it works perfectly with you, win7 ?

Code: Select all

@echo off &setlocal enableDelayedExpansion

for /l %%? in ( 1, 1, 50 ) do (
call :echo 0C. "Hello "
call :echo 0F "world"
)
pause
exit /b 0

:echo col txt -- echoes text in a specific color
::            -- col [in]  - color code, append a DOT to omit line break, call 'color /?' for color codes
::            -- txt [in]  - text output
:$created 20060101 :$changed 20080219 :$categories Echo,Color
:$source http://www.dostips.com
SETLOCAL
2>nul (
for /f "tokens=1,*" %%a in ("%*") do (
    set col=%%a
    set txt=%%~b
)
)
set cr=Y
if "%col:~-1%"=="." (
    set cr=N
    set col=%col:~0,-1%
)

call:getColorCode "%col%" col
set com=%temp%.\color%col%.com
if not exist "%com%" (
    echo.N %COM%
    echo.A 100
    echo.MOV BL,%col%
    echo.MOV BH,0
    echo.MOV SI,0082
    echo.MOV AL,[SI]
    echo.MOV CX,1
    echo.MOV AH,09
    echo.INT 10
    echo.MOV AH,3
    echo.INT 10
    echo.INC DL
    echo.MOV AH,2
    echo.INT 10
    echo.INC SI
    echo.MOV AL,[SI]
    echo.CMP AL,0D
    echo.JNZ 109
    echo.RET
    echo.
    echo.r cx
    echo.22
    echo.w
    echo.q
)|debug>NUL
"%com%" %txt%
rem del "%com%" /q
if "%cr%"=="Y" echo.
EXIT /b

:getColorCode col ret -- converts color text to color code
::                    -- col [in]  - color text BackgroundForeground, i.e.: BlueLYellow for 1E
::                    -- ret [out] - return variable to return color code in
:$created 20060101 :$changed 20080219 :$categories Color,Echo
:$source http://www.dostips.com
SETLOCAL
set col=%~1
set col=%col:Gray=8%
set col=%col:LBlue=9%
set col=%col:LGreen=A%
set col=%col:LAqua=B%
set col=%col:LRed=C%
set col=%col:LPurple=D%
set col=%col:LYellow=E%
set col=%col:LWhite=F%
set col=%col:Black=0%
set col=%col:Blue=1%
set col=%col:Green=2%
set col=%col:Aqua=3%
set col=%col:Red=4%
set col=%col:Purple=5%
set col=%col:Yellow=6%
set col=%col:White=7%
ENDLOCAL & IF "%~2" NEQ "" (SET %~2=%col%) ELSE (echo.%col%)

alexsander.albani
Posts: 7
Joined: 10 Apr 2012 19:17

Re: echoes text in a specific color - help

#5 Post by alexsander.albani » 11 Apr 2012 10:35

I'm using Win7, but I'm experiencing the "buffer problem" even in win7 and XP.
The same problem occours using ColorMsg.com that u mentioned before.

It really seens something related with .com files.

Let's see if somebody else can help.
Thanks.

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: echoes text in a specific color - help

#6 Post by !k » 11 Apr 2012 11:02

x64 ?
16-bit programs like .com not works on 64-bit OS

alexsander.albani
Posts: 7
Joined: 10 Apr 2012 19:17

Re: echoes text in a specific color - help

#7 Post by alexsander.albani » 11 Apr 2012 11:07

No. it's Win 32-bit.

alexsander.albani
Posts: 7
Joined: 10 Apr 2012 19:17

Re: echoes text in a specific color - help

#8 Post by alexsander.albani » 11 Apr 2012 11:54

After more tests I've realized that it keeps only the 50 last lines.
I don't know why just 50...

Post Reply