Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ::: v2.0 Called as subroutine or .Bat file
- ::: strings must be assigned to variables using the Set "var=string" Syntax to display problem characters
- ::: Not built for multiline variables. Only the first line of Multiline variables will be aligned.
- ::: console widths greater than 170 columns will require modification of this script
- @Echo Off
- Setlocal DisableDelayedExpansion
- (Set LF=^
- %= NewLine =%)
- Set ^"\n=^^^%LF%%LF%^%LF%%LF%^^"
- %= Define console width and values for alignment =%
- For /F "usebackq tokens=2* delims=: " %%W in (`mode con ^| findstr Columns`) do set "Console_Width=%%W"
- Set /A Console_Width+=0
- IF %Console_Width% GTR 170 Set "Console_Width=170"
- Set Align_Centre=Set /A "%%H=(Console_Width / 2) - (Len / 2)"
- Set Align_Right=Set /A "%%H=(Console_Width - Len)"
- Set Align_Left=Set /A "%%H=0"
- %= @Align Macro calculates string length then uses 2nd Parameter to Act on Alignment Calculation =%
- %= Macro appends spaces to the string depending on Alignment value / mode chosen to position, then output string to console. =%
- Set @Align=for /L %%n in (1 1 2) do if %%n==2 (%\n%
- For /F "tokens=1,* delims=, " %%G in ("!argv!") do (%\n%
- If not "!%%~G!"=="" (Set "TextOut=!%%~G!") Else (Set "TextOut=%%~G")%\n%
- Set LenTrim=Start%\n%
- For /L %%a in (1,1,170) Do (%\n%
- IF NOT "!LenTrim!"=="" (%\n%
- Set LenTrim=!TextOut:~0,-%%a!%\n%
- If "!LenTrim!"=="" Set "Len=%%a"%\n%
- ) %\n%
- ) %\n%
- IF /I "%%H"=="C" %Align_Centre% %\n%
- IF /I "%%H"=="R" %Align_Right% %\n%
- IF /I "%%H"=="L" %Align_Left% %\n%
- For /L %%# in (1,1,!%%H!) Do Set "TextOut= !TextOut!" %\n%
- Echo(!TextOut!^&^& Endlocal %\n%
- ) %\n%
- ) ELSE setlocal enableDelayedExpansion ^& set argv=,
- :Align <varName> <Switch L C R>
- %@Align% %~1 %~2
- Endlocal
- Goto :Eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement