Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <# : batch portion
- :# The above line marks the beginning of a powershell comment block; {the Batch component of the Script.} Do not modify.
- REM UPDATED For use with Windows 11
- ::: Author: T3RRY : Created: 14/05/2021 Filename: font.bat
- :# - System Requirements: Window 10, ansi support
- :# PURPOSE:
- :# - Facilitate output of custom multiline fonts with user defined color and character symbols
- :# - More font sizes and styles coming. watch this space!
- :# - Version changes: /XC switch modified to so that characters of centre aligned text now retain
- :# alignment with left aligned text.
- :#
- :# IMPORTANT USER INFORMATION:
- :# This demo script uses alternate data streams to store runstate and output data.
- :# Streams are used as an alternative to creating additional files on the users system.
- :# Modifiying and saving this script after it has been run, and streams have been associated with the file will
- :# result in a 'severe' level security alert.
- :# - To view streams associated with a file, open cmd; navigate to the files directory, and type: dir /r
- :# - To view or edit the content of a files stream: open cmd ant type: notepad.exe filename:streamname.ext
- :# Note: the above method of opening a streams content in notepad REQUIRES the streams name to be suffixed
- :# with an extension compatable with notepad or your chosen text editor.
- :#
- :# Inspired by:
- :# https://codegolf.stackexchange.com/a/224801/92319
- @Echo off
- :# restart script in new window, ensures window is not already in fullscreen mode
- If "%~1" == "" (start /high "" "%~f0" new&Exit)
- :# Requires ntfs drive for stream usage:
- :# https://docs.microsoft.com/en-us/windows/win32/fileio/file-streams
- (Echo(verify > "%TEMP%\%~n0_NTFStest:IO:$Data") 2> nul
- If not exist "%TEMP%\%~n0_NTFStest" (
- Echo(Permission or Drive type Error. Write permission required on an NTFS drive.
- Pause & Exit /B 1
- )Else Del "%TEMP%\%~n0_NTFStest"
- cd /d "%~dp0"
- Cls
- :# Test ansi support
- Reg Query HKCU\Console | %SystemRoot%\System32\findstr.exe /LIC:"VirtualTerminalLevel REG_DWORD 0x1" > nul || (Echo(virtual terminal support not enabled & Exit /B 1)
- :# Define escape character for virtual terminal sequences
- For /f %%a in ('Echo(prompt $E^|cmd')Do set "\E=%%a"
- :# Enable use of UTF-8 character set
- chcp 65001 > NUL
- (Set \n=^^^
- %= \n macro newline variable. Do not modify =%)
- (Set LF=^
- %= LF newline variable. Do not modify =%)
- :# $Font macro switches. Defined outside macro for readability and maintainance.
- Set $font[Switches]="N" "C" "Col" "F" "T" "LF" "BG" "HC" "SC" "X" "XC"
- :# $Font macro. Outputs multiline characters declared as arguments prior to switches.
- :# character '/C' and color '/Col' information.
- :# Usage: %$font% [character list] [/f Integer] [/Switches]
- :# Usage: [/f Integer] [/Switches]
- :# Also accepts arguments for:
- :# - Newline: '/N $#'
- :# Shift the cursor down by a !$#{y}! cells, where # is the font number
- :# - Subsecond delay: '/T [Integer|Sum]'
- :# {50000 = ~ 1 second}
- :# - Hide cursor: /HC
- :# - Show cursor: /SC
- :# - emit a single linefeed: /LF
- :# - emit a blank colored line /BG VtSequence
- :# Vt sequence: "Integer" or "Integer;Integer"
- :# See: https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences#text-formatting
- :# Use VT color sequence '7' or '48;2;r;g;b' to invert color.
- :# - Cursor X position:
- :# /X [Integer{position}]
- :# - absolute X. Does not align characters on other lines.
- :# /XC [Integer{string length}] [$Integer{font number}]
- :# - Center string along X axis, aligned with output on other lines.
- Set $font=For %%n in (1 2)Do if %%n==2 ( %\n: CAPTURE ARG STRING =%
- For /F "Tokens=1,2 Delims==" %%G in ('Set "$font_" 2^^^> nul')Do Set "%%~G=" %\n: RESETS ALL MACRO INTERNAL VARS =%
- If not defined $font_char Set "$font_char=X"%\n%
- If not "!$font[args]:* /=!" == "!$font[args]!" ( %\n: BUILD $font.Args[!$font_arg[i]!] ARRAY IF ARGS PRESENT =%
- Set "$font_leading.args=!$font[args]:*/=!" %\n: SPLIT ARGS FROM SWITCHES =%
- For /F "Delims=" %%G in ("!$font_leading.args!")Do Set "$font_leading.args=!$font[args]:/%%G=!"%\n%
- Set ^"$font[args]=!$font[args]:"=!" %\n: REMOVE DOUBLEQUOTES FROM REMAINING ARGSTRING - SWITCHES =%
- Set "$font_arg[i]=0" %\n: ZERO INDEX FOR ARGS ARRAY =%
- For %%G in (!$font_leading.args!)Do ( %\n: BUILD ARGS ARRAY =%
- Set /A "$font_arg[i]+=1"%\n%
- Set "$font_arg[!$font_arg[i]!]=%%~G"%\n%
- For %%i in ("!$font_arg[i]!")Do ( %\n: SUBSTITUTE THE FOLLOWING POISON CHARACTERS =%
- Set "$font_arg[%%~i]=!$font_arg[%%~i]:{SC}=;!"%\n%
- Set "$font_arg[%%~i]=!$font_arg[%%~i]:{FS}=/!"%\n%
- Set "$font_arg[%%~i]=!$font_arg[%%~i]:{AS}=*!"%\n%
- Set "$font_arg[%%~i]=!$font_arg[%%~i]:{EQ}==!"%\n%
- Set ^"$font_arg[%%~i]=!$font_arg[%%~i]:{DQ}="!"%\n%
- )%\n%
- )%\n%
- ) Else ( %\n: IF NO ARGS REMOVE DOUBLEQUOTES FROM ARGSTRING - SWITCHES =%
- Set ^"$font[args]=!$font[args]:"=!"%\n%
- )%\n%
- For /L %%L in (2 1 4)Do If "!$font_LastSwitch!" == "" (%\n%
- If "!$font[args]:~-%%L,1!" == " " Set "$font_LastSwitch=_"%\n%
- If "!$font[args]:~-%%L,1!" == "/" ( %\n: FLAG LAST SWITCH TRUE IF NO SUBARGS ; FOR SWITCHES UP TO 3 CHARCTERS LONG =%
- For /F "Delims=" %%v in ('Set /A "%%L-1"')Do Set "$font_Switch[!$font[args]:~-%%v!]=true"%\n%
- If not "!$font[args]:/?=!." == "!$font[args]!." Set "$font_Switch[help]=true"%\n%
- Set "$font[args]=!$font[args]:~0,-%%L!"%\n%
- Set "$font_LastSwitch=_"%\n%
- )%\n%
- )%\n%
- For %%G in ( %$font[Switches]% )Do If not "!$font[args]:/%%~G =!" == "!$font[args]!" (%\n: SPLIT AND ASSIGN SWITCH VALUES =%
- Set "$font_Switch[%%~G]=!$font[args]:*/%%~G =!"%\n%
- If not "!$font_Switch[%%~G]:*/=!" == "!$font_Switch[%%~G]!" (%\n%
- Set "$font_Trail[%%~G]=!$font_Switch[%%~G]:*/=!"%\n%
- For %%v in ("!$font_Trail[%%~G]!")Do (%\n%
- Set "$font_Switch[%%~G]=!$font_Switch[%%~G]: /%%~v=!"%\n%
- Set "$font_Switch[%%~G]=!$font_Switch[%%~G]:/%%~v=!"%\n%
- )%\n%
- Set "$font_Trail[%%~G]="%\n%
- If not "!$font_Switch[%%~G]!" == "" If "!$font_Switch[%%~G]:~-1!"==" " Set "$font_Switch[%%~G]=!$font_Switch[%%~G]:~0,-1!"%\n%
- If "!$font_Switch[%%~G]!" == "" Set "$font_Switch[%%~G]=true"%\n%
- If not "!$font_Switch[%%~G]!" == "" If not "!$font_Switch[%%~G]!" == "true" (%\n%
- Set "$font_Switch[%%~G]=!$font_Switch[%%~G]:{SC}=;!"%\n%
- Set "$font_Switch[%%~G]=!$font_Switch[%%~G]:{FS}=/!"%\n%
- Set "$font_Switch[%%~G]=!$font_Switch[%%~G]:{AS}=*!"%\n%
- Set "$font_Switch[%%~G]=!$font_Switch[%%~G]:{EQ}==!"%\n%
- Set "$font_Switch[%%~G]=!$font_Switch[%%~G]:{QM}=?!"%\n%
- Set ^"$font_Switch[%%~G]=!$font_Switch[%%~G]:{DQ}="!"%\n%
- )%\n%
- )%\n%
- )%\n: SWITCH ASSESSMENT BELOW. =%
- If "!$font_Switch[HC]!"=="true" ^<nul Set /P "=%\E%[?25l"%\n%
- If "!$font_Switch[SC]!"=="true" ^<nul Set /P "=%\E%[?25h"%\n%
- If not "!$font_Switch[Col]!"=="" If not "!$font_Switch[Col]!"=="" ^<nul set/P "=%\E%[!$font_Switch[Col]!m"%\n%
- If not "!$font_Switch[C]!"=="" Set "$font_char=!$font_Switch[C]:~0,1!"%\n: Defaults to 't' if switch is used w/out arg value =%
- If not "!$font_Switch[N]!"=="" (For %%v in ("!$font_Switch[N]: =!")Do ^<nul set/P "=%\E%[!%%~v{y}!B%\E%[1G")%\n%
- If "!$font_Switch[LF]!"=="true" ^<nul set /p =%\E%[1E%\n%
- If not "!$font_Switch[X]!"=="" ^<nul Set /P "=%\E%[!$font_Switch[X]!G"%\n%
- If not "!$font_Switch[XC]!"=="" (%\n%
- For /F "Tokens=1,2 Delims= " %%1 in ("!$font_Switch[XC]!")Do (%\n%
- For /f "Delims=" %%z in ('Set /A "(!$Font[columns]! - ( !%%2{x}! * %%1 ) ) / 2"')Do (%\n%
- For /L %%i in (1 !%%2{x}! !$Font[columns]!)Do If %%i LEQ %%z set "$Font_Centre=%%i"%\n%
- )%\n%
- )%\n%
- ^<nul Set /P "=%\E%[!$Font_Centre!G"%\n%
- )%\n%
- If not "!$font_Switch[BG]!"=="" If not "!$font_Switch[BG]!"=="true" ^<nul set/P "=%\E%[!$font_Switch[BG]: =!m%\E%[K%\E%[0m"%\n%
- If not "!$font_Switch[T]!"=="" (Set /A "$font_Switch[T]=!$font_Switch[T]!+0")Else Set "$font_Switch[T]=0"%\n%
- For /f "delims=$" %%f in ("!$Font_Switch[F]!")Do For /L %%i in (0 1 !$font_arg[i]!)Do For %%c in (!$font_arg[%%~i]!)Do (%\n%
- For %%c in (!$Font[%%f][%%c]!)do (%\n%
- If /I "%%c"=="+" ^<nul set/P "=%\E%7"%\n: Save cursor position =%
- If /I "%%c"=="-" ^<nul set/P "=%\E%8"%\n: Restore cursor position from memory =%
- If /I "%%c"=="L" ^<nul set/P "=%\E%[1D!$font_char!"%\n%
- If /I "%%c"=="LH" ^<nul set/P "=%\E%[2D!$font_char!"%\E%[1D%\n: Move left after previous left move =%
- If /I "%%c"=="RS" ^<nul set/P "=%\E%[1C"%\n%
- If /I "%%c"=="LS" ^<nul set/P "=%\E%[1D"%\n%
- If /I "%%c"=="US" ^<nul set/P "=%\E%[1A"%\n%
- If /I "%%c"=="DS" ^<nul set/P "=%\E%[1B"%\n%
- If /I "%%c"=="R" ^<nul set/P "=%\E%[1C!$font_char!%\E%[1D"%\n%
- If /I "%%c"=="UL" ^<nul set/P "=%\E%[1A%\E%[1D!$font_char!%\E%[1D"%\n%
- If /I "%%c"=="UR" ^<nul set/P "=%\E%[1A%\E%[1C!$font_char!%\E%[1D"%\n%
- If /I "%%c"=="DL" ^<nul set/P "=%\E%[1B%\E%[1D!$font_char!%\E%[1D"%\n%
- If /I "%%c"=="DR" ^<nul set/P "=%\E%[1B%\E%[1C!$font_char!%\E%[1D"%\n%
- If /I "%%c"=="U" ^<nul set/P "=%\E%[1A!$font_char!%\E%[1D"%\n%
- If /I "%%c"=="D" ^<nul set/P "=%\E%[1B!$font_char!%\E%[1D"%\n%
- If not "!$font_Switch[T]!"=="" (For /l %%z in (1 1 !$font_Switch[T]!)Do (Call ))%\n%
- )%\n%
- For /F "Delims=" %%z in ("!$Font_Switch[F]!")Do ^<nul set/P "=!%%z!"%\n%
- )%\n%
- ^<nul set /p=%\E%[0m%\n%
- %= ESCAPE AMPERSANDS AND REDIRECTION CHARACTERS. =%) Else Set $font[args]=
- Set "PS.Utility=For %%n in (1 2)Do if %%n==2 (Echo/!Args!| powershell.exe -noprofile "$Mode = $input ^| ?{$_}; iex (${%~f0} ^| out-string )")Else Set Args="
- :# load the variables required for font 1
- Call :font[1]
- :# enable environment for expansion of the $Font macro. must not be enabled prior to $Font macro definition.
- Setlocal EnableExtensions EnableDelayedexpansion
- :# Relative cursor positioning used in font character output fails when the cursor goes out of bounds
- :# of the visible screen dimensions.
- :#
- :# * NOT SUPPORTED:
- :# - scrolling
- :# - line wrapping [ Coming soon ]
- :# toggle fullscreen
- :# Toggle Fullscreen by calling powershell component of script.
- %PS.Utility% ToggleFS
- :# Get window dimensions [ line wrapping to be implemented using screen columns / fontwidth compared against count of output letters
- :# between /N newline switch usages. ]
- For /F "Tokens=1,2 Delims=: " %%i in ('Mode Con^|%SystemRoot%\System32\Findstr.exe /Li "lines columns"')Do Set "$Font[%%i]=%%j"
- :# USAGE EXAMPLES
- :# alternating header. Toggles state using 0 / 1 values in alternate data stream of this file:
- :# >"%~f0:runstate.dat" Echo(value
- :# reads value via 'more'; pipes value to 'findstr' and uses conditional result of findstr
- :# via '&&' and '||' logical operators to execute according to previous state.
- 2>nul (more < "%~f0:runstate.dat") | %SystemRoot%\System32\findstr.exe /c:"1" > nul && (
- >"%~f0:runstate.dat" ECHO(0
- %$Font% /bg 4;1;7;38;2;12;12;12;48;2;150;;190 /hc
- %$Font% /lf /BG 4;1;7;38;2;25;25;25;48;2;150;;190
- %$Font% /lf /n $1
- %$Font% /XC 18 $1
- %$Font% F O N T WS M A C R O WS B Y WS T 3 R R Y /F $1 /Col 7;38;2;;;150;48;2;150;120; /C ☼ !font[1][%%.]! /T 300
- %$Font% /LF /BG 4;1;7;38;2;12;12;12;48;2;150;;190
- %$Font% /LF /BG 4;1;7;38;2;25;25;25;48;2;150;;190
- <nul Set /P "=%\E%[1E"
- (Call )
- ) || (
- >"%~f0:runstate.dat" ECHO(1
- %$Font% /bg 4;1;7;38;2;12;12;12;48;2;;200;190 /sc
- %$Font% /lf /BG 4;1;7;38;2;25;25;25;48;2;;200;190
- %$Font% /lf /n $1
- %$Font% /XC 12 $1
- %$Font% H E L L O WS W O R L D AP /F $1 /Col 7;38;2;;200;190;48;2;255;; /C ◘ !font[1][%%.]! /T "!random! %%400 + 200"
- %$Font% /hc
- )
- :# Doublequote args or switches that have values containing parentheses or batch poison characters.
- :#
- 2> nul (
- more < "%~f0:IO[1].dat" || (
- (
- %$Font% /n $1
- %$Font% "( ) . # CL SC CM AP QM SQ DQ Mx EQ FS \ + - ~" /F $1 /Col 1;32 /C ▓
- %$Font% /n $1
- %$Font% A B C D E F G H I J K L M /F $1 /Col "7;31;48;2;180;150;0" /C ♫
- %$Font% /n $1
- %$Font% N O P Q R S T U V W X Y Z /F $1 /Col 1;4;34 /C ‼
- %$Font% /n $1
- %$Font% 0 1 2 3 4 5 4 6 7 8 9 /F $1 /Col 35 /C ►
- %$Font% /LF /BG 4;1;7;38;2;12;12;12;48;2;;200;190
- %$Font% /LF /BG 4;1;7;38;2;25;25;25;48;2;;200;190 /sc
- <nul Set /P =%\E%[1E
- ) > "%~f0:IO[1].dat"
- more < "%~f0:IO[1].dat"
- )
- )
- Echo(Press 'E' to exit during countdown
- :# prevent pause being skipped in event of uncleared buffer.
- Choice /N /T 1 /C:1 /D 1 > nul
- Pause
- :# countdown example
- For /L %%i in (30 -1 0)Do (
- Cls
- Set count=%%i
- (
- %$font% /N $1 /hc /X 5
- If not "!count:~1,1!" == "" For /F "tokens=1,2 Delims=;" %%1 in ("!count:~0,1!;!count:~1,1!")Do (
- Set /A $Col=%%1+2
- %$Font% %%1 /f $1 /C %%1 /Col 3!$Col!
- %$Font% %%2 /f $1 /C %%2 /Col 3!$Col!
- )Else (
- %$Font% 0 /f $1 /C 0 /Col 7;38;2;1%%i%%i;;
- %$Font% %%i /f $1 /C %%i /Col 7;38;2;1%%i%%i;;
- )
- ) > "%~f0:IO[2].dat"
- more < "%~f0:IO[2].dat"
- Choice /T 1 /N /C:Ep /D p > nul
- If !Errorlevel!==1 Goto :End
- )
- :End
- %$Font% /n $1 /sc /T 50000
- cls
- :# Toggle Fullscreen by calling powershell component of script.
- %PS.Utility% ToggleFS
- Goto :Eof
- :font[1] font specific variable definition
- :# $1 = font specific variable that is used to position cursor ready for the next character. '/F $1'
- :# DRAWING of characters starts at cell beneath bottom left of 5x5 grid; and ends at bottom right of the 5x5 grid
- :# $1{y} = Hieght of font; with offset of +1. '/F $1' '/N $1'
- :# $1{x} = Width of font characters; with an offset of +1. '/F $1' '/XC [character count] $1'
- Set "$1=%\E%[1B%\E%[2C"
- Set "$1{y}=6"
- Set "$1{x}=6"
- Set $font[1][a]= U U U + U UR R R DR D - R R R R D D
- Set $font[1][b]= U U U + R R - U U R R R DR DL DR DL + L LH - RS
- Set $font[1][c]= US + U U U UR R R DR - R R R UR DS
- Set $font[1][d]= U U U U U R R R DR D D DL + L LH LH - RS
- Set $font[1][e]= U + U U U U R R R R - U U R R R - R R R R
- Set $font[1][f]= U + U U U U R R R R - U U R R R - RS RS RS RS
- Set $font[1][g]= U + U U U UR R R R - R R R R + U U L -
- Set $font[1][h]= U U U + U U - R R R R + U U - D D
- Set $font[1][i]= U R R + U U U U L LH R R R - R R
- Set $font[1][j]= US + U U - R R R + UR U U U L LH LH LH - RS
- Set $font[1][k]= U U + U U U - UR UR UR R - US R DR DR R
- Set $font[1][l]= U + U U U U - R R R R
- Set $font[1][m]= U U U U U DR DR UR UR D D D D
- Set $font[1][n]= U U U U U DR DR DR DR + U U U U -
- Set $font[1][o]= US + U U U US R R R RS D D D - R R R RS
- Set $font[1][p]= U U U U U R R R DR + DL L LH - DS DS DS
- Set $font[1][q]= US U U U UR R R DR D DL + UL - DL L - DR
- Set $font[1][r]= U U U + U U R R R DR DL L - R DR DR R
- Set $font[1][s]= U R R R + UR UL L LH LH UL UR R R R - RS
- Set $font[1][t]= RS RS U + U U U U L LH R R R - RS RS
- Set $font[1][u]= US + U U U U - R R R UR + U U U - DS
- Set $font[1][v]= RS UR + UL UL U U - UR + UR U U - RS DS
- Set $font[1][w]= U + U U U U - R UR + U U U - DR R + U U U U -
- Set $font[1][x]= LS UR UR UR + UR UR - UL UL - DR DR
- Set $font[1][y]= RS RS U U U + UL UL - UR UR - DS DS RS RS
- Set $font[1][z]= U + UR UR UR UR L LH LH LH - R R R R
- Set $font[1][0]= US U U U U R R R R D D D D + L LH LH LH -
- Set $font[1][1]= U R R + U U U U L LH - R R
- Set $font[1][2]= U + U U R R R R U U L LH LH LH - R R R R
- Set $font[1][3]= US LS R R R R R + U UL L LH LH RS RS R U U L LH LH LH -
- Set $font[1][4]= US US U + U U - R R R R + U U - D D
- Set $font[1][5]= U R R R R + U U L LH LH LH LS U U R R R R -
- Set $font[1][6]= U U U + U U R R R R - R R R R D D + L LH LH LH -
- Set $font[1][7]= US US US US U R R R R D D D D
- Set $font[1][8]= U U U U U R R R R D D + L LH LH LH - D D + L LH LH LH -
- Set $font[1][9]= U R R R R + U U U U L LH LH LH LS D D R R R R -
- Set $font[1][.]= U U R D RS RS RS
- Set $font[1][-]= US US US R R R RS DS DS
- Set $font[1][+]= US RS RS U U + L - U - R DS RS DS
- Set $font[1][\]= US US US US U DR DR DR DR
- Set $font[1][~]= US U U R R D R R U DS DS
- Set $font[1][#]= RS U U + L - U U L U - R R D + U U U R LH U D LH LH - UR DS
- Set $font[1][(]= RS RS RS US + U U U UR - R
- Set "$font[1][)]= U + UR U U UL - RS RS RS RS"
- Set $font[1][CM]= U U R D + D - RS RS RS
- Set $font[1][WS]= US RS RS RS RS
- Set $font[1][EQ]= US U R R R R + US U L LH LH LH - DS DS
- Set $font[1][CL]= US U US U DS DS DS RS RS RS RS
- Set $font[1][SC]= U U US U DS DS DS RS RS RS RS
- Set $font[1][AP]= U + US U U U - RS RS RS RS
- Set $font[1][QM]= RS UR + US U R U U L LH LH DL - RS RS
- Set $font[1][FS]= U UR UR UR UR DS DS DS DS
- Set $font[1][Mx]= US UR UR + UR - UL - DR RS DS
- Set $font[1][DQ]= US US RS U U RS R D DS DS DS RS
- Set $font[1][SQ]= US US US RS RS U U DS DS DS RS RS
- Set $font[1][EQ]= US US + US US R R R - R R R RS DS
- exit /b 0
- :# The below line Marks the end of a Powershell comment Block; And the End of the Batch Script. Do not Modify.
- : end batch / begin powershell #>
- <#
- Test if input Argument -eq ToggleFs
- If true uses sendKeys to toggle fullscreen.
- #>
- $Mode -eq ' ToggleFS' >$null
- If ($Mode -eq " ToggleFS") {
- Add-Type -AssemblyName System.Windows.Forms
- [System.Windows.Forms.SendKeys]::SendWait("{F11}")
- }
- $Mode -eq ' /?' >$null
- If ($Mode -eq " /?") {
- write-output "To toggle Fullscreen Mode: Expand the PS.Utility macro like so:"
- write-output " %PS.Utility% ToggleFS"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement