Wie kann man mit batch verschiedene Zeilen verschiedenfarbig machen?
Frage steht oben...
Ich moechte bsp. Zeile 1 Rot haben...
Dann kommte eine Textzeile, die ich Gruen haben moechte,
dann eine, welche lila sein soll....
nur als beispiel... wie mache ich das?
2 Antworten
@echo off
:: Original author: WebstersBatch
color 0a
setlocal disableDelayedExpansion
set q=^"
echo.
echo.
call :c 0A "HELLO"
call :c 0b " AND"
call :c 0c " WELCOME
echo.
call :c 0d " TO"
call :c 0E " MY"
call :c 0f " COLOR"
call :c 0a " TEST" /n
echo.
call :c 0A "ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ"
call :c 0b "ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ" /n
call :c 0c "ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ"
call :c 0d "ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ" /n
echo.
call :c 0A "SUBSCRIBE"
call :c 0b " TO"
call :c 0c " MY"
call :c 0d " YOUTUBE"
call :c 0E " AT"
call :c 0f " YOUTUBE.COM/"
call :c 0a "WebstersBatch" /n
echo.
pause
exit /b
:c
setlocal enableDelayedExpansion
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:colorPrint Color Str [/n]
setlocal
set "s=%~2"
call :colorPrintVar %1 s %3
exit /b
:colorPrintVar Color StrVar [/n]
if not defined DEL call :initColorPrint
setlocal enableDelayedExpansion
pushd .
':
cd \
set "s=!%~2!"
:: The single blank line within the following IN() clause is critical - DO NOT REMOVE
for %%n in (^"^
^") do (
set "s=!s:\=%%~n\%%~n!"
set "s=!s:/=%%~n/%%~n!"
set "s=!s::=%%~n:%%~n!"
)
echo "!s!"
pause
cls
for /f delims^=^ eol^= %%s in ("!s!") do (
if "!" equ "" setlocal disableDelayedExpansion
if %%s==\ (
findstr /a:%~1 "." "\'" nul
set /p "=%DEL%%DEL%%DEL%" <nul
) else if %%s==/ (
findstr /a:%~1 "." "/.\'" nul
set /p "=%DEL%%DEL%%DEL%%DEL%%DEL%" <nul
) else (
(echo %%s\..\') >colorPrint.txt
findstr /a:%~1 /f:colorPrint.txt "."
set /p "=%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%" <nul
)
)
if /i "%~3"=="/n" echo.
popd
exit /b
:initColorPrint
for /f %%A in ('"prompt $H&for %%B in (1) do rem"') do set "DEL=%%A %%A"
set /p "=." <nul >"%temp%\'"
subst ': "%temp%" >nul
exit /b
:cleanupColorPrint
del "%temp%\'" 2>nul
"%temp%\colorPrint.txt" 2>nul
>nul subst ': /d
exit /b
Die "<," musst du mit "<" ersetzen und die ">," mit ">".
Wenn man eine Antwort schreibt schauen die < und > Zeichen wie > ; aus aber wenn man die Antwort abschickt dann bleiben die Zeichen gleich...
Unter MS-DOS ging das noch recht einfach, wenn man den Treiber ansi.sys geladen hat - was aber fast immer der Fall war.
Bei Windows ist das schon nicht mehr so leicht, wenn es überhaupt geht.
Mit dem "color"-Befehl kann man die Farbe für das ganze Fenster ändern, jedoch nicht für einzelne Zeilen.
Ich habe gerade folgendes C-Programm geschrieben, mit dem man auch einzelne Zeilen einfärben kann. Es funktioniert ansonsten wie der "color"-Befehl:
#include <windows.h>
#include <stdio.h>
int main(int argc,char **argv)
{
int clr;
if(argc==2)
{
sscanf(argv[1],"%X",&clr);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),clr);
}
return 0;
}
Wenn du einen C-Compiler hast (den kann man kostenlos runterladen) und damit umgehen kannst, könntest du dir das Programm zum Beispiel als "LineColor.exe" compilieren. Dann kann man farbige Zeilen so erzeugen:
@echo off
rem Beispiel für eine BAT-Datei
LineColor C
echo Diese Zeile ist hellrot mit schwarzem Hintergrund
LineColor 2
echo Und diese ist dunkelgrün
LineColor 1F
rem Die Ausgabe von "dir" ist weiß auf blauem Hintergrund
dir
Naja. C ist eine Compilersprache. Das bedeutet, dass man das C-Programm in einem Texteditor (also wie eine Batch-Datei) schreibt. Danach wird ein spezielles Programm (der so-genannte Compiler) verwendet, um aus dem C-Programm eine Windows-EXE-Datei zu erzeugen.
Das Programm muss die Dateiendung .C (anstatt .BAT oder .TXT) haben - also der Dateiname ist zum Beispiel "LineColor.c".
Der kleinste C-Compiler für Windows dürfte die veraltete Version von Bloodshed Dev-C++ (Variante mit Compiler mit etwa 12 MB, nicht die ohne Compiler) sein.
Man kann die EXE-Datei dann so erzeugen:
path %path%;c:\pfad\wo\gcc.exe\drin\ist
gcc -o LineColor.exe LineColor.c
(Bei der Eingabe des Dateinamens "LineColor.c" auf ein kleingeschriebenes ".c" achten!)
Wenn man sich damit auskennt... das ist ein gutes stichwort
koenntest du mir das mal genau erklaeren?