Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ::: Script
- @Echo Off & REM centre.bat
- Setlocal DisableDelayedExpansion
- (Set LF=^
- %= NewLine =%)
- Set ^"\n=^^^%LF%%LF%^%LF%%LF%^^"
- Endlocal & Set @strLen=for /L %%n in (1 1 2) do if %%n==2 (%\n%
- For /F "tokens=1,* delims=, " %%G in ("!argv!") do (%\n%
- Set "tmpLen=!%%~G!"%\n%
- Set LenTrim=Start%\n%
- For /L %%a in (1,1,160) Do (%\n%
- IF NOT "!LenTrim!"=="" (%\n%
- Set LenTrim=!tmpLen:~0,-%%a!%\n%
- If "!LenTrim!"=="" Endlocal ^& Set %%H=%%a%\n%
- )%\n%
- ) %\n%
- ) %\n%
- ) ELSE setlocal enableDelayedExpansion ^& set argv=,
- IF "%~1"=="" (
- Setlocal EnableDelayedExpansion
- Echo(Must Call with a quoted string.
- Timeout 3 >nul
- Endlocal
- Exit /B
- )
- Setlocal EnableDelayedExpansion
- Set "TextOut=%~1"
- %@strLen% TextOut Len
- For /F "usebackq tokens=2* delims=: " %%W in (`mode con ^| findstr Columns`) do set "Console_Width=%%W"
- IF !Console_Width! GTR 160 (Set Console_Width=160)
- Set /A Len/=2
- Set /A Console_Width+=0
- Set /A Column=(Console_Width / 2) - Len
- For /L %%A in (1,1,!Column!) Do Set "TextOut= !TextOut!"
- Echo(!TextOut!
- (
- Endlocal
- Exit /B
- )
- ::: Comments
- REM An example of a call to centre.bat (from the command line):
- Cls & @for %a in (1. 2. 3. 4. 5.) do @for %b in (this is an example of usage) do @Call centre.bat "%a %b"
- REM With a small change to the calculation of column relative to console width and string length,
- REM this could be used to Right-Align text
Advertisement
Add Comment
Please, Sign In to add comment