Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ANSI.SYS color change has no effect

105 views
Skip to first unread message

JJ

unread,
Jul 2, 2002, 10:01:44 PM7/2/02
to
I want to change colors as we go through a batch file that has several
Choice menu's. The top of one file changes colors using
prompt $e[1;37;44m
CLS
But other bat files change nothing with the same command. And if is issue
the same command but change the numbers in the running batch file they have
no effect. I wanted to change colors to alert people to problems after they
had made certain choices.

I am running windows 98se on both computers and both have ansi.sys
installed, and it does work sometimes. Both computers act the same way with
the same bat files.

in my config.sys I have:
Device = c:\windows\command\ansi.sys

--

William Allen

unread,
Jul 3, 2002, 6:06:10 AM7/3/02
to
"JJ" wrote in message

> I want to change colors as we go through a batch file that has several
> Choice menu's. The top of one file changes colors using
> prompt $e[1;37;44m
> CLS
> But other bat files change nothing with the same command. And if is issue
> the same command but change the numbers in the running batch file they have
> no effect.

To make such a PROMPT change take effect, you need to turn
ECHO ON for at least one line. The %comment syntax% I use:

% ECHO the prompt to have colour change take effect %

acts as a dummy blank line for PROMPT ECHOing in the
demo below. Note: leading [Space]s for each Batch line
(normally used in posting Batch scripts) are avoided since
they affect the behaviour of the PROMPT ECHOing. Lines
beginning with :: are functionless comments.

====Begin cut-and-paste (omit this line)
@ECHO OFF

:: Set for White on Blue+Cursor UP 2 (to allow for ECHO ON)
PROMPT $e[1;37;44m$e[2A
ECHO ON
% ECHO the prompt to have colour change take effect %
@ECHO OFF
ECHO. Text with White(=foreground) Blue(=background)

:: Set for Yellow on Cyan+Cursor UP 2 (to allow for ECHO ON)
PROMPT $e[1;33;46m$e[2A
ECHO ON
% ECHO the prompt to have colour change take effect %
@ECHO OFF
ECHO. Text with Yellow(=foreground) Cyan(=background)

:: Set for White on Red+Cursor UP 2 (to allow for ECHO ON)
PROMPT $e[1;37;41m$e[2A
ECHO ON
% ECHO the prompt to have colour change take effect %
@ECHO OFF
ECHO. Text with White(=foreground) Red (=background)

:: Clear to standard background
PROMPT $e[m$e[2A
ECHO ON
% ECHO the prompt to have colour change take effect %
@ECHO OFF

:: Reset to standard prompt on exit
PROMPT $p$g

====End cut-and-paste (omit this line)
Win9x GUI study/demo only. Cut-and-paste as Batch script (file with .BAT
extension). Requires ANSI.SYS loaded.

--
(pp) William Allen

General note on format of ANSI colour codes:
ESC[Ps;...;Psm
Set Graphics Mode: Calls the graphics functions specified by the
following values. These specified functions remain active until the
next occurrence of this escape sequence. Graphics mode changes the
colors and attributes of text (such as bold and underline) displayed
on the screen. Blink doesn't work in the GUI in windowed mode.

Where Ps is one of the codes:
Text attributes
0 All attributes off
1 Bold on (=make the colour Bright)
4 Underscore (on monochrome display adapter only)
5 Blink on
7 Reverse video on
8 Concealed on

Foreground colors
30 Black
31 Red
32 Green
33 Yellow
34 Blue
35 Magenta
36 Cyan
37 White

Background colors
40 Black
41 Red
42 Green
43 Yellow
44 Blue
45 Magenta
46 Cyan
47 White


William Allen

unread,
Jul 3, 2002, 8:51:08 AM7/3/02
to
"JJ" wrote in message
...snip

> in my config.sys I have:
> Device = c:\windows\command\ansi.sys

Incidentally, since ANSI.SYS has such a compact memory
footprint, it will almost certainly load high into a spare UMB
region, giving you a "free lunch" on the useful low memory
space you're currently wasting with your CONFIG.SYS line.

To load ANSI.SYS high, use the command:
DEVICEHIGH=C:\WINDOWS\COMMAND\ansi.sys


Note: Typical memory footprint for ANSI.SYS:
============Screen capture Windows 95
C:\WORK>mem /module ANSI

ANSI is using the following memory:

Segment Region Total Type
------- ------ ---------------- --------
0CE5C 1 4,304 (4K) Installed Device=ANSI
----------------
Total Size: 4,304 (4K)

C:\WORK>
============End screen capture

--
(pp) William Allen


Todd Vargo

unread,
Jul 3, 2002, 8:57:13 PM7/3/02
to

"JJ" <*anci...@netscape.net> wrote in message
news:ui4mntp...@corp.supernews.com...

As Mr. Allen mentioned, you need ECHOing turned on to use that old-fashioned
PROMPTing syntax. To be specific, you need the escape sequence ECHOed to
screen for the change to take effect. Using an ECHOing method, this can be
accomplished directly in your ECHO commands to allow much more colorful
output than the PROMPTing method.

The following batch example uses variables in the ECHO statements to set
text colors at will. Obviously, you can abbreviate the variable names as
desired, or even place the actual escape sequences right in the text too.

:: Variable cleanup omitted (not all variables are used either).
::
:: I recommend you add... SHELL=C:\WINDOWS\COMMAND.COM /E:4096 /P
:: somewhere in config.sys to assure all variables will be set.
::
@echo off
:: Create a variable names ESC containing the actual
:: escape character and the "[".
echo @prompt set Esc=$e[$_ >%temp%.\Set_Esc.bat
command/c %temp%.\set_Esc.bat|find "=">%temp%.\Set_Esc.bat
for %%? in (call del) do %%? %temp%.\Set_Esc.bat
::
:: Set text attribute variables
set Normal=%Esc%0m
set Brite=%Esc%1m
set Blink=%Esc%5m
set Reverse=%Esc%7m
set Hidden=%Esc%8m
set Save=%Esc%s
set Return=%Esc%u
::
:: Set foreground color variables
set Black=%Esc%30m
set Red=%Esc%31m
set Green=%Esc%32m
set Yellow=%Esc%33m
set Blue=%Esc%34m
set Magenta=%Esc%35m
set Cyan=%Esc%36m
set White=%Esc%37m
::
:: Set background color variables
set bgBlack=%Esc%40m
set bgRed=%Esc%41m
set bgGreen=%Esc%42m
set bgYellow=%Esc%43m
set bgBlue=%Esc%44m
set bgMagenta=%Esc%45m
set bgCyan=%Esc%46m
set bgWhite=%Esc%47m
::
:: Display a colorful menu using variables.
echo.%Brite%%Yellow%%bgBlue%%Esc%2J
echo DEMO MENU1
echo.
echo [%Red%A%Yellow%] Option 1
echo [%Red%B%Yellow%] Option 2
echo [%Red%C%Yellow%] Option 3
echo.
choice /cabc /n " %Blue%%bgCyan%Selection:%red%%bgBlue% "
echo.
echo %Yellow%You pressed... %Red%%Save%
if errorlevel 3 echo %Return%C
if errorlevel 2 if not errorlevel 3 echo %Return%B
if errorlevel 1 if not errorlevel 2 echo %Return%A
echo.%bgWhite%%Black%
pause
:: Display the same menu another way (two passes).
echo.%Brite%%Yellow%%bgBlue%%Esc%2J
echo DEMO MENU2
echo.
echo [A] Option 1
echo [B] Option 2
echo [C] Option 3 %Esc%3A%Red%
for %%? in (A B C) do echo %Esc%5C%%?
echo.
choice /cabc /n " %Blue%%bgCyan%Selection:%red%%bgBlue% "
echo.
echo %Yellow%You pressed... %Red%%Save%
if errorlevel 3 echo %Return%C%Save%
if errorlevel 2 if not errorlevel 3 echo %Return%B%Save%
if errorlevel 1 if not errorlevel 2 echo %Return%A%Save%
echo %Return%%Yellow%, %green%%bgRed%Bye!%Normal%
::end

--
Todd Vargo (body of message must contain my name to reply by email)

0 new messages