VOGONS


First post, by curvedline

User metadata
Rank Newbie
Rank
Newbie

ECHO [32m==================
ECHO [36mPrince of Persia 1
ECHO [32m==================[0m
worked but i hope to do more
is there a way to do this as below?

CALL :SetColor 1 33
ECHO ==================
ECHO Prince of Persia 1
ECHO ==================
ECHO.

GOTO :END
:SetColor
echo [%~1;%~2m
EXIT /B

:END

Reply 1 of 11, by myne

User metadata
Rank Oldbie
Rank
Oldbie

Iirc exit/b didn't work in dos dos.
You basically have to use gotos.

GOTO setcolor
:Start
Blah
:setcolor
Blah
GOTO start

If you want to see a bonkers example of a bat look at the 2nd last thing in my sig.

I built:
Convert old ASUS ASC boardviews to KICAD PCB!
Re: A comprehensive guide to install and play MechWarrior 2 on new versions on Windows.
Dos+Windows 3.11+tcp+vbe_svga auto-install iso template
Script to backup Win9x\ME drivers from a working install
Re: The thing no one asked for: KICAD 440bx reference schematic

Reply 2 of 11, by zirkoni

User metadata
Rank Member
Rank
Member

Why not just make a new batch script that only sets the color? Put it somewhere in the %PATH% and you can call it from anywhere.
And you can move the cursor up if you don't want any empty lines.

For example, put this in "red.bat"

echo <esc>[31m
echo <esc>[2A

And then call it from your other scripts:

@echo off
cls
call red.bat
echo This text should be red!

https://youtube.com/@zirkoni42

Reply 3 of 11, by DaveDDS

User metadata
Rank Oldbie
Rank
Oldbie

There's no direct way to call a label .. you can only GOTO .. if you want a true subroutine you would have to SET a symbol with the
"return" label and have the sub jump back via that symbol...

CALL invokes another .BAT file, (which can be the same one) ... a useful "trick" if you only have 1 or 2 subs
is something like:

@echo OFF
if .%1 == .:SUB1 goto sub1
echo main1
call %0 :SUB1 1234
echo main2
call %0 :SUB1 5678
echo main3
goto ex
:sub1
echo SUB1 %2
:ex

When I had to do a bunch of more complex batch functions, I wrote BAX (BAtch eXtended) which runs .BAX
files and has features like "calls to labels"/RETURN, more arithmetic/expression capability (which give more
powerful IF statements etc.), and I don't recall what else (it was a while ago)... basically made .BAX scripts
more like a full programming language.

I *think* it's somewhere on my site.. If anyone is interested, let me know and I'll figure out exactly
where it is and make sure it's up t0 date.

Dave ::: https://dunfield.themindfactory.com ::: "Daves Old Computers"->Personal

Dave ::: https://dunfield.themindfactory.com ::: "Daves Old Computers"->Personal

Reply 4 of 11, by curvedline

User metadata
Rank Newbie
Rank
Newbie

CALL SetColor.bat 1 33
ECHO ===========================
ECHO DUNE 2 - Patched - EU v1.07
ECHO ===========================
ECHO.
CALL SetColor.bat 1 36
ECHO 1. english
ECHO 2. german
ECHO 3. french
ECHO.
CALL SetColor.bat 1 37
choice /C:1234567890abcdefghijklmnopqrstuvwxyz /N "Q to quit or any other key to play :"
IF ErrorLevel 27 GOTO :END
IF ErrorLevel 3 GOTO :dune2-fr
IF ErrorLevel 2 GOTO :dune2-ge
IF ErrorLevel 1 GOTO :dune2-en

SetColor.BAT below has
echo [%1;%2m
echo [2A

thanks, this method was the same as call :sub, i can pass the variables, instead of having 16 color batch files, that could defeat the purpose of using a subroutine, now batch is more readable.

but SetColor.BAT makes an ONE empty line echoing out at the 1st row
in order to avoid this, i used <nul SET /P "= [%~1;%~2m" in windows

in dosbox, i tired
<nul echo [%1;%2m
set "=[%1;%2m"
set "aa=[%1;%2m"
set aa="[%1;%2m"
set aa=[%1;%2m
none of the above tricks worked in dosbox

always having one empty line at 1st row is still ok, but the total of 24 rows is all i can have in DOS's text mode, this gives me 23 rows to work with "SetColor.BAT"
if there is a workaround to save one row, please let me know

Reply 5 of 11, by myne

User metadata
Rank Oldbie
Rank
Oldbie

Cls?

I built:
Convert old ASUS ASC boardviews to KICAD PCB!
Re: A comprehensive guide to install and play MechWarrior 2 on new versions on Windows.
Dos+Windows 3.11+tcp+vbe_svga auto-install iso template
Script to backup Win9x\ME drivers from a working install
Re: The thing no one asked for: KICAD 440bx reference schematic

Reply 6 of 11, by curvedline

User metadata
Rank Newbie
Rank
Newbie

i always start a batch like this, i just didnt include in posting
@ECHO OFF
CLS
CALL SetColor.bat 1 33
ECHO ===========================

now and it worked, thanks very much
@ECHO OFF
CLS
CALL SetColor.bat 1 33
CLS
ECHO ===========================

Reply 7 of 11, by myne

User metadata
Rank Oldbie
Rank
Oldbie

We all miss the obvious sometimes 😉

Just wait till I lose my glasses - on my forehead.

I built:
Convert old ASUS ASC boardviews to KICAD PCB!
Re: A comprehensive guide to install and play MechWarrior 2 on new versions on Windows.
Dos+Windows 3.11+tcp+vbe_svga auto-install iso template
Script to backup Win9x\ME drivers from a working install
Re: The thing no one asked for: KICAD 440bx reference schematic

Reply 8 of 11, by zirkoni

User metadata
Rank Member
Rank
Member

Also you could move the cursor with an escape code, like I wrote earlier:
echo <esc>[2A

https://youtube.com/@zirkoni42

Reply 9 of 11, by curvedline

User metadata
Rank Newbie
Rank
Newbie

11.TXT has the content of 5 lines below

[1;33m
[2J
[1;1H
[2A
AAAA

by using TYPE 11.TXT this way hopefully
is there a way to bring AAAA to the 1ST ROW by differently arranging or adding any <esc>[ whatever code number and letter

but there is one restriction:
[1;33mAAAA is NOT allowed.

Reply 10 of 11, by zirkoni

User metadata
Rank Member
Rank
Member

Yes, just move the "AAAA" to the end of the last escape code:

[1;33m
[2J
[HAAAA

Or just a one-liner:

[1;33m[2J[HAAAA

https://youtube.com/@zirkoni42

Reply 11 of 11, by curvedline

User metadata
Rank Newbie
Rank
Newbie

i didnt clarify enough, i meant the restriction that any <esc>[ command and a text line must not be mixed.
i almost thought sending the cursor back to 1st row could solve it, then after [1;1H sent the cursor back to the 1st row, it itself took the 1st row position invisibly.

i may accept this if this is possible
AAAA<>[ special-comand on the right that effects the color or behavior on the text left