Escape Characters
Moderator: DosItHelp
-
- Posts: 3
- Joined: 23 Oct 2014 13:24
Escape Characters
I would like to place this line in a batch file, cannot understand how to add escape characters:
echo Esc[1;5;31m Warning You are about to delete files...
I want it to make the text red and blink
any assistance or referral will be appreciated.
Thanks
echo Esc[1;5;31m Warning You are about to delete files...
I want it to make the text red and blink
any assistance or referral will be appreciated.
Thanks
Re: Escape Characters
Copy and paste the text below:
Successfully tested with AnsiSys.exe.
Antonio
Code: Select all
@echo off
echo [1;5;31m Warning You are about to delete files...
Successfully tested with AnsiSys.exe.
Antonio
-
- Expert
- Posts: 1163
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: Escape Characters
Squashman wrote:Not possible!
To expand on that slightly, the way you're trying uses ANSI.sys, which doesn't come with modern systems (if you were using Windows 98 or earlier, you wouldn't have a problem).
There are ways to turn the text red, and there are complicated ways to turn just that one line red. I can imagine a way to make the text blink by generating backspace characters and printing with set /p, but I'd have to test it, and it would have to stop blinking before the user provided input.
Re: Escape Characters
Aacini wrote:Copy and paste the text below:Code: Select all
@echo off
echo [1;5;31m Warning You are about to delete files...
Successfully tested with AnsiSys.exe.
Antonio
It's not clear from the above how ansisys will function with the code you have shown, Antonio.
The OP might have trouble figuring it out.
Re: Escape Characters
Code: Select all
@echo off
set "line=Warning! You are about to delete files..."
cd /d "%~dp0"
for /f %%i in ('
forfiles /m "%~nx0" /c "cmd /c echo 0x08"
') do set BS=%%i
set /p=%BS%<nul>"%line%_"
for /l %%i in (1 1 100) do (
set /p="Hello, %username%! "<nul
findstr /a:ac "^" "%line%_*"
set /p="%BS% "<nul
for /l %%j in (1 1 500) do pause<nul>nul
cls
)
del "%line%_"
exit /b
Re: Escape Characters
@Yury,
I guess that is one way to pseudo do it. But that is more of a flicker then a blink because of the CLS command.
I guess that is one way to pseudo do it. But that is more of a flicker then a blink because of the CLS command.
-
- Posts: 3
- Joined: 23 Oct 2014 13:24
Re: Escape Characters
Hi Guys,
Thanks for response. I guess I need to face reality that the old dos days are about gone.
Thanks again
Thanks for response. I guess I need to face reality that the old dos days are about gone.
Thanks again
Re: Escape Characters
foxidrive wrote:It's not clear from the above how ansisys will function with the code you have shown, Antonio.
The OP might have trouble figuring it out.
You are right, foxi. I understood that the problem was to include the Esc character, and assumed that the OP is using already some Ansi driver...
Jamessotech wrote:Hi Guys,
Thanks for response. I guess I need to face reality that the old dos days are about gone.
Thanks again
Not entirely. You may still use such functionality in several ways. Try this:
- Go to AnsiSys post, copy and paste the file "Ansi Color Table.bat" and run it.
- Previous Batch file will create a program called AnsiSys.exe
- You may use AnsiSys.exe as a filter, that is, you may pipe to it the output of another program with Ansi escape sequences and the output will be displayed the right way (well, just for a few Ansi codes for the moment).
See the example below:
You may also use AnsiSys.exe just in the lines you want to use the Ansi sequences; for example:
Code: Select all
@echo off
echo Normal output
echo [1;5;31mOutput with Ansi escape sequences | AnsiSys
echo Another normal output...
If you want a more precise emulation of old MS-DOS Ansi escape sequences, look for a program called AnsiCon.sys. However, no one of the Ansi emulators for Windows currently support the blinking of characters; such attribute was changed to light background color.
Antonio
Re: Escape Characters
You could use C#.NET Edition (should be installed on systems higher than XP, on XP you have to install it) as a workaround for blinking text.
Note: I've created it some time ago and actually it is not finished, so its use is a little bit complicated.
You will need the below files ("Example.bat", "Process.bat", "csc.bat", "Blink.bat").
The file "Blink.exe" will be created.
Result (actually tested only on Win XP 32 bit):
Example batch file ("Example.bat"):
Process batch file ("Process.bat"):
C# source file ("Blink.cs"):
Compile the source file using this Batch ("csc.bat"):
penpen
Note: I've created it some time ago and actually it is not finished, so its use is a little bit complicated.
You will need the below files ("Example.bat", "Process.bat", "csc.bat", "Blink.bat").
The file "Blink.exe" will be created.
Result (actually tested only on Win XP 32 bit):
Code: Select all
Z:\>Example.bat
Blinking sample text.
Start Process.bat
Test input: a
End Process.bat
Z:\>
Example batch file ("Example.bat"):
Code: Select all
@if not exist "Blink.exe" @>nul call csc Blink
@(
@(
>nul ping -n 1 127.0.0.2 -w 250
>&2 call Process.bat
@echo Y
) | @Blink.exe "Blinking sample text." 250
)
Process batch file ("Process.bat"):
Code: Select all
@echo off
echo(Start Process.bat
set /P "=Test input: "
echo(End Process.bat
C# source file ("Blink.cs"):
Code: Select all
using System;
using System.Threading;
class Blink {
static int Main (string [] args) {
string text = "Blinking Text.";
int update = 500;
if (args.Length > 0) text = args [0];
if (args.Length > 1) try { update = int.Parse (args[1]); } catch (Exception) { update = 500; }
BlinkingText statusChecker = new BlinkingText (text);
Timer stateTimer = new Timer (statusChecker.UpdateText, null, 0, update);
int returnValue = -1;
do {
try {
switch (Char.ToUpper (Convert.ToChar (Console.Read ()))) {
case 'Y':
returnValue = 1;
break;
case 'N':
returnValue = 2;
break;
}
} catch (OverflowException) {
returnValue = 3;
}
} while (returnValue == -1);
stateTimer.Dispose();
return returnValue;
}
}
class BlinkingText {
private int x;
private int y;
private string [] messages;
private int index;
public BlinkingText (string message) {
x = Console.CursorLeft;
y = Console.CursorTop;
string [] stringArray = { message, "".PadRight (message.Length) };
ConsoleColor color = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine ("{0}", message);
Console.ForegroundColor = color;
messages = stringArray;
index = 1;
}
public void UpdateText (Object stateInfo) {
int actualX = Console.CursorLeft;
int actualY = Console.CursorTop;
ConsoleColor color = Console.ForegroundColor;
Console.CursorLeft = x;
Console.CursorTop = y;
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine ("{0}", (messages [index]).ToString ());
Console.CursorLeft = actualX;
Console.CursorTop = actualY;
Console.ForegroundColor = color;
index = 1 - index;
}
}
Compile the source file using this Batch ("csc.bat"):
Code: Select all
// // >nul 2> nul & @goto :main
/*
:main
@echo off
setlocal
cls
set "csc="
pushd "%SystemRoot%\Microsoft.NET\Framework"
for /f "tokens=* delims=" %%i in ('dir /b /o:n "v*"') do (
dir /a-d /b "%%~fi\csc.exe" >nul 2>&1 && set "csc="%%~fi\csc.exe""
)
popd
if defined csc (
echo most recent C#.NET compiler located in:
echo %csc%.
) else (
echo C#.NET compiler not found.
goto :eof
)
%csc% /nologo /optimize /warnaserror /nowin32manifest /debug- /target:exe /out:"%~f1.exe" "%~f1.cs"
rem %csc% /?
goto :eof
*/
penpen
Re: Escape Characters
@penpen:
Interesting idea! You simulate the blink via manually writting and erasing the message with a certain delay. Many years ago, in the old MS-DOS days, I used a similar method to simulate a blinking cursor in graphics mode via showing/erasing an underscore.
This method may be used in AnsiSys.exe program, so all text with the blinking attribute be displayed this way; the only problem is if the screen scroll a line
Antonio
Interesting idea! You simulate the blink via manually writting and erasing the message with a certain delay. Many years ago, in the old MS-DOS days, I used a similar method to simulate a blinking cursor in graphics mode via showing/erasing an underscore.
This method may be used in AnsiSys.exe program, so all text with the blinking attribute be displayed this way; the only problem is if the screen scroll a line
Antonio
Re: Escape Characters
Because i don't lock to the console's monitor object there are multiple side effects with windows events such as scrolling (resizing, ...).
But i don't know how to access this monitor object: This is the main reason, why this program is still unfinished.
penpen
But i don't know how to access this monitor object: This is the main reason, why this program is still unfinished.
penpen
Re: Escape Characters
Squashman wrote:@Yury,
I guess that is one way to pseudo do it. But that is more of a flicker then a blink because of the CLS command.
Without the CLS command:
Code: Select all
@echo off
set "line=Warning! You are about to delete files..."
echo Hello, %username%!
echo.
cd /d "%~dp0"
for /f %%i in ('
forfiles /m "%~nx0" /c "cmd /c echo 0x08"
') do set BS=%%i
set /p="%line%_:"<nul>"%line%_"
for %%i in ("%line%_") do (
for /l %%j in (1 1 %%~zi) do (
call set x=%%x%%%BS%
call set "y=%%y%% "
)
)
set /p="%BS%%BS% "<nul>"%line%_"
set /p="The flicker: "<nul
for /l %%i in (1 1 100) do (
findstr /a:ac "^" "%line%_*"
for /l %%j in (1 1 100) do pause<nul>nul
set /p=%x%%y%<nul
for /l %%j in (1 1 100) do pause<nul>nul
set /p=%x%<nul
)
del "%line%_"
echo.
echo.
echo Bye, %username%!
timeout /t 2 1>nul
exit /b
.
Re: Escape Characters
Yury wrote:Without the CLS command:
. . .
@Yury, I like your method! I slightly modified it:
Code: Select all
@echo off
set "line=Warning! You are about to delete files..."
echo Hello, %username%!
echo.
cd /d "%~dp0"
for /f %%i in ('
forfiles /m "%~nx0" /c "cmd /c echo 0x08"
') do set BS=%%i
set /p="%line%_:"<nul>"%line%_"
for %%i in ("%line%_") do (
for /l %%j in (1 1 %%~zi) do (
call set x=%%x%%%BS%
call set "y=%%y%% "
)
)
set /p="%BS%%BS% "<nul>"%line%_"
set /p="The blink: "<nul
for /l %%i in (1 1 6) do (
findstr /a:ac "^" "%line%_*"
ping -w 100 -n 2 localhost >NUL
set /p="%x%" <nul
findstr /a:ca "^" "%line%_*"
ping -w 100 -n 2 localhost >NUL
set /p="%x%" <nul
)
del "%line%_"
echo.
echo.
echo Bye, %username%!
timeout /t 2 1>nul
exit /b
Antonio