From c353e6b51fcb47c34c77a89168281927a482790a Mon Sep 17 00:00:00 2001 From: Ryan Beesley Date: Sun, 12 Dec 2021 21:07:30 -0800 Subject: [PATCH 01/35] Add ansi-color.cmd tool and several definitions --- src/tools/ansi-color/ansi-color.cmd | 1410 +++++++++++++++++++++++ src/tools/ansi-color/ansi-colortool.def | 53 + src/tools/ansi-color/colortest.def | 52 + src/tools/ansi-color/colortool.def | 45 + src/tools/ansi-color/crisman.def | 78 ++ src/tools/ansi-color/plaid.def | 54 + src/tools/ansi-color/rainbow.def | 52 + src/tools/ansi-color/rosetta.def | 40 + src/tools/ansi-color/sgr-intensity.def | 142 +++ src/tools/ansi-color/sgr.def | 282 +++++ src/tools/ansi-color/tsgr.def | 273 +++++ src/tools/ansi-color/ubuntu.def | 41 + 12 files changed, 2522 insertions(+) create mode 100644 src/tools/ansi-color/ansi-color.cmd create mode 100644 src/tools/ansi-color/ansi-colortool.def create mode 100644 src/tools/ansi-color/colortest.def create mode 100644 src/tools/ansi-color/colortool.def create mode 100644 src/tools/ansi-color/crisman.def create mode 100644 src/tools/ansi-color/plaid.def create mode 100644 src/tools/ansi-color/rainbow.def create mode 100644 src/tools/ansi-color/rosetta.def create mode 100644 src/tools/ansi-color/sgr-intensity.def create mode 100644 src/tools/ansi-color/sgr.def create mode 100644 src/tools/ansi-color/tsgr.def create mode 100644 src/tools/ansi-color/ubuntu.def diff --git a/src/tools/ansi-color/ansi-color.cmd b/src/tools/ansi-color/ansi-color.cmd new file mode 100644 index 00000000000..b9e8641b5ed --- /dev/null +++ b/src/tools/ansi-color/ansi-color.cmd @@ -0,0 +1,1410 @@ +@ECHO OFF +GOTO :DEFINE_MACROS + +%=- Entry point after macro definitions -=% +:MAIN +SETLOCAL ENABLEDELAYEDEXPANSION +CALL :PARSE_ARGS %1 %2 %3 %4 %5 %6 %7 %8 %9 +IF ERRORLEVEL 1 %@exit% %ERRORLEVEL% + +REM ::Debug -- Use this to break after parsing arguments +REM CMD /C EXIT -1073741510 + + +%=- Configuration -=% +:: Default test text if not defined in the data segment +SET "CELL= gYw " +:: Uncomment to use UTF-8 for output, such as when the test text is Unicode +REM SET "SHOW.UTF8=#TRUE#" +:: Uncomment to disable the spinner and speed up processing +REM SET "SPINNER.DISABLED=#TRUE#" +:: Uncomment to display the ANSI Escape Sequence control characters +REM SET "SHOW.ANSI=#TRUE#" +:: Uncomment to show cell R1C1 reference addressing instead of cell text +REM SET "SHOW.R1C1_REFERENCE=#TRUE#" +:: Uncomment to turn on debug output for diagnosing separator resolution +REM SET "DEBUG.OUT=#TRUE#" +%=- End Configuration -=% + + +%=- Data Segment -=% +GOTO :END_DATA_SEGMENT + +:: Complete matrix of SGR parameters available +:: This definition also demonstrates the various configuration changes +:: which are used to control the way the table is generated +__DATA__ +:: Select Graphic Rendition (SGR) parameters +:: #NUL# is treated as a special case to provide cells in that column +:: or row, but there is no row or column value applied to the cell. +:: This has the effect that the row or column has no SGR parameter applied +:: and so this will show the default. +:: #SPC# is also a special case which can be used to make gaps in the table. +:: Whereas #NUL# still outputs the CELL text, #SPC# won't show anything in +:: that row. +__TABLE__ +:: If the definition is defined using Unicode characters, uncomment and include +:: the following line in the __TABLE__ section of the definition file. +REM SET "UTF8.REQUIRED=#TRUE#" +:: The test text +SET "STUBHEAD=SGR" +:: Alignment properties for the cells and headers +REM SET "ALIGN.CELL=C" +REM SET "ALIGN.BOXHEAD=R" +REM SET "ALIGN.STUB=L" +REM SET "ALIGN.STUBHEAD=C" +:: Separator characters for cells and headers +REM SET "SEPARATOR.STUB= " +REM SET "SEPARATOR.STUB=│" & :: UTF-8 +REM SET "SEPARATOR.BOXHEAD= " +REM SET "SEPARATOR.BOXHEAD=─" & :: UTF-8 +SET "SEPARATOR.COL= " +REM SET "SEPARATOR.COL=╎" +REM SET "SEPARATOR.STUBHEAD_BOXHEAD= " +REM SET "SEPARATOR.STUBHEAD_BOXHEAD=:" +REM SET "SEPARATOR.STUBHEAD_BOXHEAD=│" & :: UTF-8 +REM SET "SEPARATOR.STUBHEAD_BOXHEAD=▓▓" & :: UTF-8 +REM SET "SEPARATOR.STUBHEAD_STUB= " +REM SET "SEPARATOR.STUBHEAD_STUB=-" +REM SET "SEPARATOR.STUBHEAD_STUB=─" & :: UTF-8 +REM SET "SEPARATOR.STUBHEAD_STUB=▓" & :: UTF-8 +REM SET "SEPARATOR.INTERSECT= " +REM SET "SEPARATOR.INTERSECT=┼" & :: UTF-8 +REM SET "SEPARATOR.INTERSECT=┘" & :: UTF-8 +REM SET "SEPARATOR.INTERSECT=▓▒▒░" & :: UTF-8 +REM SET "SEPARATOR.INTERSECT=+" +REM SET "SEPARATOR.BOXHEAD_BODY= " +REM SET "SEPARATOR.BOXHEAD_BODY=─" & :: UTF-8 +REM SET "SEPARATOR.BOXHEAD_BODY=░" & :: UTF-8 +REM SET "SEPARATOR.STUB_BODY= " +REM SET "SEPARATOR.STUB_BODY=│" & :: UTF-8 +REM SET "SEPARATOR.STUB_BODY=░░" & :: UTF-8 +REM SET "SEPARATOR.BOXHEADERS= " +REM SET "SEPARATOR.BOXHEADERS=╎" & :: UTF-8 +REM SET "SEPARATOR.CELL= " +REM SET "SEPARATOR.CELL=╎" & :: UTF-8 +:: Conditional definitions like this must be one line per statement +:: and can be used to define how to fall back to ANSI if Unicode isn't supported +IF DEFINED SHOW.UTF8 (SET "SEPARATOR.STUBHEAD_BOXHEAD=│") ELSE (SET "SEPARATOR.STUBHEAD_BOXHEAD=:") +IF DEFINED SHOW.UTF8 (SET "SEPARATOR.STUBHEAD_STUB=─") ELSE (SET "SEPARATOR.STUBHEAD_STUB=-") +IF DEFINED SHOW.UTF8 (SET "SEPARATOR.INTERSECT=┘") ELSE (SET "SEPARATOR.INTERSECT=+") +__TABLE:END__ + +:: Background +__COLS__ +#NUL# +REM 1m +REM 2m +REM 3m +REM 4m +REM 5m +REM 6m +REM 7m +REM 8m +REM 9m +REM 21m +40m +100m +41m +101m +42m +102m +43m +103m +44m +104m +45m +105m +46m +106m +47m +107m +__COLS:END__ + +:: [Intensity;][Attribute;]Foreground +__ROWS__ +#NUL# +1m +2m +3m +4m +5m +6m +7m +8m +9m +REM 10m +REM 11m +REM 12m +REM 13m +REM 14m +REM 15m +REM 16m +REM 17m +REM 18m +REM 19m +REM 20m +21m +REM 22m +REM 23m +REM 24m +REM 25m +REM 26m +REM 27m +REM 28m +REM 29m +#SPC# +:: Normal +30m +90m +31m +91m +32m +92m +33m +93m +34m +94m +35m +95m +36m +96m +37m +97m +#SPC# +:: Bold or increased intensity, 1 +1;30m +1;90m +1;31m +1;91m +1;32m +1;92m +1;33m +1;93m +1;34m +1;94m +1;35m +1;95m +1;36m +1;96m +1;37m +1;97m +#SPC# +:: Faint (decreased intensity), 2 +2;30m +2;90m +2;31m +2;91m +2;32m +2;92m +2;33m +2;93m +2;34m +2;94m +2;35m +2;95m +2;36m +2;96m +2;37m +2;97m +#SPC# +:: Italic, 3 +3;30m +3;90m +3;31m +3;91m +3;32m +3;92m +3;33m +3;93m +3;34m +3;94m +3;35m +3;95m +3;36m +3;96m +3;37m +3;97m +#SPC# +:: Underline, 4 +4;30m +4;90m +4;31m +4;91m +4;32m +4;92m +4;33m +4;93m +4;34m +4;94m +4;35m +4;95m +4;36m +4;96m +4;37m +4;97m +#SPC# +:: Slow Blink, 5 +5;30m +5;90m +5;31m +5;91m +5;32m +5;92m +5;33m +5;93m +5;34m +5;94m +5;35m +5;95m +5;36m +5;96m +5;37m +5;97m +#SPC# +:: Rapid Blink, 6 +6;30m +6;90m +6;31m +6;91m +6;32m +6;92m +6;33m +6;93m +6;34m +6;94m +6;35m +6;95m +6;36m +6;96m +6;37m +6;97m +#SPC# +:: Reverse video, 7 +7;30m +7;90m +7;31m +7;91m +7;32m +7;92m +7;33m +7;93m +7;34m +7;94m +7;35m +7;95m +7;36m +7;96m +7;37m +7;97m +#SPC# +:: Conceal, 8 +8;30m +8;90m +8;31m +8;91m +8;32m +8;92m +8;33m +8;93m +8;34m +8;94m +8;35m +8;95m +8;36m +8;96m +8;37m +8;97m +#SPC# +:: Crossed-out, 9 +9;30m +9;90m +9;31m +9;91m +9;32m +9;92m +9;33m +9;93m +9;34m +9;94m +9;35m +9;95m +9;36m +9;96m +9;37m +9;97m +#SPC# +:: Double Underline, 21 +21;30m +21;90m +21;31m +21;91m +21;32m +21;92m +21;33m +21;93m +21;34m +21;94m +21;35m +21;95m +21;36m +21;96m +21;37m +21;97m +__ROWS:END__ +__DATA:END__ + +:END_DATA_SEGMENT +%=- End Data Segment -=% + + +%=- Main Script -=% +SETLOCAL ENABLEDELAYEDEXPANSION + +:INITIALIZATION +:: Configure ANSI escape sequences. This has a dependency on PowerShell for creating the escape code +REM FOR /F "tokens=* USEBACKQ" %%G IN (`PowerShell -Command "[char]0x1B"`) DO (SET "ESC=%%G") +:: Otherwise you need to use an unprintable character +SET "ESC=" + +:: If we're going to display the ANSI Escape Sequence control characters +:: save the active console Code Page, change to UTF-8, and override ESC +IF DEFINED SHOW.ANSI ( + SET "SPINNER.DISABLED=#TRUE#" + REM SET "SHOW.UTF8=#TRUE#" +) + +:: The console (CMD) is normally not UTF-8, so preserve the codepage so we can reset it. +:: Because the output of chcp is localized, we grab the last value of the string, +:: which we have our fingers crossed, will be the codepage. +FOR /F "tokens=*" %%_ IN ('chcp') DO (SET CHCP_OUT=%%_) +FOR %%_ IN (!CHCP_OUT!) DO (SET CHCP=%%_) +IF DEFINED CHCP ( + IF [!CHCP!] EQU [65001] ( + SET "SHOW.UTF8=#TRUE#" + ) ELSE ( + IF DEFINED SHOW.UTF8 ( + chcp 65001>NUL + ) + ) +) +SET "CHCP_OUT=" + +:: This is a seperate code block so that the active console Code Page is changed first +IF DEFINED SHOW.ANSI ( + SET "ESC=␛" +) + +:: Control Sequence Introducer +SET "CSI=!ESC![" + +:: Cursor Up +SET "CUU=!CSI!A" +:: Cursor Down +SET "CUD=!CSI!B" +:: Cursor Forward +SET "CUF=!CSI!C" +:: Cursor Back +SET "CUB=!CSI!D" +:: Cursor Previous Line // will work like a CR without LF when appended to an echo +SET "CPL=!CSI!F" +:: Select Graphic Rendition (SGR) Reset // reset colors and attributes +SET "RESET=!CSI!m" + +:: We will want to calculate the max widths as we process the data segment +SET /A STUB.MAX_WIDTH=0 +SET /A COL.MAX_WIDTH=0 + +:: If showing the R1C1 reference address of each cell instead of the cell value, assume +:: there will be at most R999C99 cells and set the width at 7 +IF DEFINED SHOW.R1C1_REFERENCE ( + SET /A COL.MAX_WIDTH=7 +) + +:: Default properites if not defined in the data segment +:: See Figure 1.1 in the PDF for Wang Terminology +:: https://uwspace.uwaterloo.ca/handle/10012/10962 + +:: Fields +SET "STUBHEAD=" + +:: Alignment +SET "ALIGN.CELL=C" +SET "ALIGN.CELL.R1C1=R" +SET "ALIGN.STUBHEAD=C" +SET "ALIGN.BOXHEAD=C" +SET "ALIGN.STUB=R" +SET "ALIGN.STUBHEAD_STUB=C" +SET "ALIGN.STUB_BODY=C" +SET "ALIGN.BOXHEAD_BODY=C" + +:: Separators +SET "SEPARATOR.STUB=" +SET "SEPARATOR.STUBHEAD_BOXHEAD=" +SET "SEPARATOR.STUB_BODY=" +SET "SEPARATOR.COL=" +SET "SEPARATOR.BOXHEADERS=" +SET "SEPARATOR.CELL=" +SET "SEPARATOR.STUBHEAD_STUB=" +SET "SEPARATOR.BOXHEAD_BODY=" +SET "SEPARATOR.BOXHEAD=" +SET "SEPARATOR.INTERSECT=" +SET "SEPARATOR.STUB_BOXHEAD_INTERSECT=" + +:: Flags +SET "SEPARATOR.VERTICAL=" +SET "SEPARATOR.HORIZONTAL=" +SET "SEPARATOR.COLUMN=" + +:: Read and parse the data, validate the configuration, calculate table headings, +:: build the table, and show the table +CALL :READ_DATA_SEGMENT +CALL :VALIDATE_CONFIGURATION +IF ERRORLEVEL 4 ( + %@exit% %ERRORLEVEL% +) +CALL :RESOLVE_SEPARATORS +CALL :BUILD_TABLE +CALL :DISPLAY_TABLE + +:: Restore the console Code Page saved at the beginning of the script +IF DEFINED CHCP ( + chcp !CHCP!>NUL +) + +:: Exit +%@exit% 0 + +:: Should never be reached +ECHO Failed to EXIT cleanly +CMD /C EXIT -1073741510 + + +:: Routine to process the data segment of a file, used to build the table +:READ_DATA_SEGMENT +SET "DATA_SEGMENT=" +FOR /F "delims=" %%_ IN (!DATA_FILE!) DO ( + IF ["%%_"] EQU ["__ROWS:END__"] SET SEGMENT= + IF ["%%_"] EQU ["__COLS:END__"] SET SEGMENT= + IF ["%%_"] EQU ["__TABLE:END__"] SET SEGMENT= + IF ["%%_"] EQU ["__DATA:END__"] SET DATA_SEGMENT= + IF DEFINED DATA_SEGMENT ( + SET "DATA=%%_" + CALL :PARSE_DATA_SEGMENT !DATA! + ) + IF ["%%_"] EQU ["__ROWS__"] ( + SET SEGMENT=ROWS + :: Initalize the row globals + SET /A ROW[#]=0 + SET /A ROWS.LEN=0 + ) + IF ["%%_"] EQU ["__COLS__"] ( + SET SEGMENT=COLS + :: Initalize the column globals + SET /A COL[#]=0 + SET /A COLS.LEN=0 + ) + IF ["%%_"] EQU ["__TABLE__"] ( + SET SEGMENT=TABLE + :: Initalize the table globals + SET /A TABLE[#]=0 + ) + IF ["%%_"] EQU ["__DATA__"] ( + SET DATA_SEGMENT=#TRUE# + SET SEGMENT= + ) +) +%@exit% + + +:: Process each segment type +:PARSE_DATA_SEGMENT +IF NOT DEFINED SEGMENT %@exit% +SET "DATA=%*" + +:: Skip over any comments +IF ["!DATA:~0,2!"] EQU ["::"] %@exit% +IF ["!DATA:~0,3!"] EQU ["REM"] %@exit% +IF ["!DATA:~0,4!"] EQU ["@REM"] %@exit% + +:: Advance and output the spinner animation if not disabled +IF NOT DEFINED SPINNER.DISABLED ( + %@spinner% SPINNER.FRAME +) + +:: Dispatch to TABLE, COLS, or ROWS parsing routines +IF ["!SEGMENT!"] EQU ["TABLE"] CALL :PARSE_TABLE_DATA !DATA! +IF ["!SEGMENT!"] EQU ["COLS"] CALL :PARSE_COLS_DATA !DATA! +IF ["!SEGMENT!"] EQU ["ROWS"] CALL :PARSE_ROWS_DATA !DATA! +%@exit% + + +:PARSE_TABLE_DATA +:: Only eval single line SET or IF statements +SET "DATA=%*" +IF /I ["!DATA:~0,4!"] EQU ["SET "] GOTO :EVAL_TABLE_DATA +IF /I ["!DATA:~0,3!"] EQU ["IF "] GOTO :EVAL_TABLE_DATA +%@exit% + + +:EVAL_TABLE_DATA +:: Eval the TABLE data directly +%* +%@exit% + + +:PARSE_COLS_DATA +SET "COL=%*" +:: Set the column header text and track the max width +%@strlen% COL COL.LEN +%@maxval% COL.MAX_WIDTH COL.LEN +:: Set the col index and store value +SET /A COL[#]+=1 +SET "COL[!COL[#]!]=!COL!" +%@exit% + + +:PARSE_ROWS_DATA +SET "ROW=%*" +:: Set the row header text +%@strlen% ROW ROW.LEN +%@maxval% STUB.MAX_WIDTH ROW.LEN +:: Set the row index and store value +SET /A ROW[#]+=1 +SET "ROW[!ROW[#]!]=!ROW!" +%@exit% + + +:: Validate that we can render the definition file +:VALIDATE_CONFIGURATION +:: Does the definition require UTF-8 +IF DEFINED UTF8.REQUIRED ( + IF NOT DEFINED SHOW.UTF8 ( + SET "SCRIPT_NAME=%~nx0" + SET "msg=Error: Requested definition script requires UTF-8.!LF! Try ^"!SCRIPT_NAME! /U [^]^" to run with UTF-8 support!LF! or change the default configuration in !SCRIPT_NAME! to always use UTF-8." + CALL :USAGE msg + %@exit% 4 + ) +) +%@exit% + + +:: Separators have cascading effects, so if some are not defined this is where +:: they are defined +:RESOLVE_SEPARATORS +IF DEFINED DEBUG.OUT ( + REM ::DEBUG + ECHO. + ECHO RESOLVE_SEPARATORS enter + ECHO. + ECHO SEPARATOR.COL : "!SEPARATOR.COL!" + ECHO SEPARATOR.BOXHEAD : "!SEPARATOR.BOXHEAD!" + ECHO SEPARATOR.INTERSECT : "!SEPARATOR.INTERSECT!" + ECHO SEPARATOR.STUB : "!SEPARATOR.STUB!" + ECHO SEPARATOR.CELL : "!SEPARATOR.CELL!" + + ECHO SEPARATOR.VERTICAL : "!SEPARATOR.VERTICAL!" + ECHO SEPARATOR.HORIZONTAL : "!SEPARATOR.HORIZONTAL!" + ECHO SEPARATOR.COLUMN : "!SEPARATOR.COLUMN!" + + ECHO STUBHEAD : "!STUBHEAD!" + + ECHO SEPARATOR.VERTICAL.WIDTH : "!SEPARATOR.VERTICAL.WIDTH!" + ECHO SEPARATOR.STUBHEAD_BOXHEAD : "!SEPARATOR.STUBHEAD_BOXHEAD!" + ECHO SEPARATOR.STUB_BODY : "!SEPARATOR.STUB_BODY!" + ECHO SEPARATOR.BOXHEADERS : "!SEPARATOR.BOXHEADERS!" + + ECHO SEPARATOR.STUBHEAD_STUB : "!SEPARATOR.STUBHEAD_STUB!" + ECHO SEPARATOR.BOXHEAD_BODY : "!SEPARATOR.BOXHEAD_BODY!" + + ECHO SEPARATOR.STUB_BOXHEAD_INTERSECT : "!SEPARATOR.STUB_BOXHEAD_INTERSECT!" + ECHO SEPARATOR.BOXHEAD_BODY_INTERSECT : "!SEPARATOR.BOXHEAD_BODY_INTERSECT!" + ECHO. + REM ::DEBUG +) + +:: Define the vertical separator +IF DEFINED SEPARATOR.STUB ( + SET "SEPARATOR.VERTICAL=#TRUE#" + IF NOT DEFINED SEPARATOR.STUBHEAD_BOXHEAD ( + SET "SEPARATOR.STUBHEAD_BOXHEAD=!SEPARATOR.STUB!" + ) + IF NOT DEFINED SEPARATOR.STUB_BODY ( + SET "SEPARATOR.STUB_BODY=!SEPARATOR.STUB!" + ) +) ELSE ( + IF DEFINED SEPARATOR.STUBHEAD_BOXHEAD ( + SET "SEPARATOR.VERTICAL=#TRUE#" + IF NOT DEFINED SEPARATOR.STUB_BODY ( + SET "SEPARATOR.STUB_BODY= " + ) + ) + IF DEFINED SEPARATOR.STUB_BODY ( + SET "SEPARATOR.VERTICAL=#TRUE#" + IF NOT DEFINED SEPARATOR.STUBHEAD_BOXHEAD ( + SET "SEPARATOR.STUBHEAD_BOXHEAD= " + ) + ) +) + +:: Define the horizontal separator +IF DEFINED SEPARATOR.BOXHEAD ( + SET "SEPARATOR.HORIZONTAL=#TRUE#" + IF NOT DEFINED SEPARATOR.STUBHEAD_STUB ( + SET "SEPARATOR.STUBHEAD_STUB=!SEPARATOR.BOXHEAD!" + ) + IF NOT DEFINED SEPARATOR.BOXHEAD_BODY ( + SET "SEPARATOR.BOXHEAD_BODY=!SEPARATOR.BOXHEAD!" + ) +) ELSE ( + IF DEFINED SEPARATOR.STUBHEAD_STUB ( + SET "SEPARATOR.HORIZONTAL=#TRUE#" + IF NOT DEFINED SEPARATOR.BOXHEAD_BODY ( + SET "SEPARATOR.BOXHEAD_BODY= " + ) + ) + IF DEFINED SEPARATOR.BOXHEAD_BODY ( + SET "SEPARATOR.HORIZONTAL=#TRUE#" + IF NOT DEFINED SEPARATOR.STUBHEAD_STUB ( + SET "SEPARATOR.STUBHEAD_STUB= " + ) + ) +) + +:: Define the column separator +IF DEFINED SEPARATOR.COL ( + SET "SEPARATOR.COLUMN=#TRUE#" + IF NOT DEFINED SEPARATOR.BOXHEADERS ( + SET "SEPARATOR.BOXHEADERS=!SEPARATOR.COL!" + ) + IF NOT DEFINED SEPARATOR.CELL ( + SET "SEPARATOR.CELL=!SEPARATOR.COL!" + ) +) ELSE ( + IF DEFINED SEPARATOR.BOXHEADERS ( + SET "SEPARATOR.COLUMN=#TRUE#" + IF NOT DEFINED SEPARATOR.CELL ( + SET "SEPARATOR.CELL= " + ) + ) + IF DEFINED SEPARATOR.CELL ( + SET "SEPARATOR.COLUMN=#TRUE#" + IF NOT DEFINED SEPARATOR.BOXHEADERS ( + SET "SEPARATOR.BOXHEADERS= " + ) + ) +) + +:: SEPARATOR.INTERSECT is intended to be a friendlier name of SEPARATOR.STUB_BOXHEAD_INTERSECT +:: Only one should be defined with a non-space character +IF DEFINED SEPARATOR.INTERSECT ( + IF NOT DEFINED SEPARATOR.STUB_BOXHEAD_INTERSECT ( + SET "SEPARATOR.STUB_BOXHEAD_INTERSECT=!SEPARATOR.INTERSECT!" + ) ELSE ( + ECHO Warning: SEPARATOR.STUB_BOXHEAD_INTERSECT definition overriding SEPARATOR.INTERSECT + ) +) + +IF DEFINED DEBUG.OUT ( + REM ::DEBUG + ECHO. + ECHO RESOLVE_SEPARATORS pre-trim + ECHO. + ECHO SEPARATOR.COL : "!SEPARATOR.COL!" + ECHO SEPARATOR.BOXHEAD : "!SEPARATOR.BOXHEAD!" + ECHO SEPARATOR.INTERSECT : "!SEPARATOR.INTERSECT!" + ECHO SEPARATOR.STUB : "!SEPARATOR.STUB!" + ECHO SEPARATOR.CELL : "!SEPARATOR.CELL!" + ECHO SEPARATOR.STUBHEAD_BOXHEAD : "!SEPARATOR.STUBHEAD_BOXHEAD!" + ECHO SEPARATOR.STUB_BODY : "!SEPARATOR.STUB_BODY!" + ECHO SEPARATOR.STUBHEAD_STUB : "!SEPARATOR.STUBHEAD_STUB!" + ECHO SEPARATOR.BOXHEAD_BODY : "!SEPARATOR.BOXHEAD_BODY!" + ECHO. + REM ::DEBUG +) + +:: Trim the variables we use to draw our separators +:: so we only work with non-space characters +SET "SEPARATOR.COL.TRIM=!SEPARATOR.COL!" +%@trim% SEPARATOR.COL.TRIM +SET "SEPARATOR.BOXHEAD.TRIM=!SEPARATOR.BOXHEAD!" +%@trim% SEPARATOR.BOXHEAD.TRIM +SET "SEPARATOR.INTERSECT.TRIM=!SEPARATOR.INTERSECT!" +%@trim% SEPARATOR.INTERSECT.TRIM +SET "SEPARATOR.STUB.TRIM=!SEPARATOR.STUB!" +%@trim% SEPARATOR.STUB.TRIM +SET "SEPARATOR.CELL.TRIM=!SEPARATOR.CELL!" +%@trim% SEPARATOR.CELL.TRIM +SET "SEPARATOR.STUBHEAD_BOXHEAD.TRIM=!SEPARATOR.STUBHEAD_BOXHEAD!" +%@trim% SEPARATOR.STUBHEAD_BOXHEAD.TRIM +SET "SEPARATOR.STUB_BODY.TRIM=!SEPARATOR.STUB_BODY!" +%@trim% SEPARATOR.STUB_BODY.TRIM +SET "SEPARATOR.STUBHEAD_STUB.TRIM=!SEPARATOR.STUBHEAD_STUB!" +%@trim% SEPARATOR.STUBHEAD_STUB.TRIM +SET "SEPARATOR.BOXHEAD_BODY.TRIM=!SEPARATOR.BOXHEAD_BODY!" +%@trim% SEPARATOR.BOXHEAD_BODY.TRIM + +IF DEFINED DEBUG.OUT ( + REM ::DEBUG + ECHO. + ECHO RESOLVE_SEPARATORS post-trim + ECHO. + ECHO SEPARATOR.COL.TRIM : "!SEPARATOR.COL.TRIM!" + ECHO SEPARATOR.BOXHEAD.TRIM : "!SEPARATOR.BOXHEAD.TRIM!" + ECHO SEPARATOR.INTERSECT.TRIM : "!SEPARATOR.INTERSECT.TRIM!" + ECHO SEPARATOR.STUB.TRIM : "!SEPARATOR.STUB.TRIM!" + ECHO SEPARATOR.CELL.TRIM : "!SEPARATOR.CELL.TRIM!" + ECHO SEPARATOR.STUBHEAD_BOXHEAD.TRIM : "!SEPARATOR.STUBHEAD_BOXHEAD.TRIM!" + ECHO SEPARATOR.STUB_BODY.TRIM : "!SEPARATOR.STUB_BODY.TRIM!" + ECHO SEPARATOR.STUBHEAD_STUB.TRIM : "!SEPARATOR.STUBHEAD_STUB.TRIM!" + ECHO SEPARATOR.BOXHEAD_BODY.TRIM : "!SEPARATOR.BOXHEAD_BODY.TRIM!" + ECHO. + REM ::DEBUG +) + +IF DEFINED SEPARATOR.VERTICAL ( + IF DEFINED SEPARATOR.HORIZONTAL ( + IF NOT DEFINED SEPARATOR.STUB_BOXHEAD_INTERSECT.TRIM ( + IF DEFINED SEPARATOR.INTERSECT.TRIM ( + SET "SEPARATOR.STUB_BOXHEAD_INTERSECT=!SEPARATOR.INTERSECT!" + ) ELSE ( + IF DEFINED SEPARATOR.STUB.TRIM ( + IF NOT DEFINED SEPARATOR.BOXHEAD.TRIM ( + SET "SEPARATOR.STUB_BOXHEAD_INTERSECT=!SEPARATOR.STUB!" + ) ELSE ( + SET "SEPARATOR.STUB_BOXHEAD_INTERSECT= " + ) + ) ELSE ( + IF DEFINED SEPARATOR.BOXHEAD.TRIM ( + SET "SEPARATOR.STUB_BOXHEAD_INTERSECT=!SEPARATOR.BOXHEAD!" + ) ELSE ( + SET "SEPARATOR.STUB_BOXHEAD_INTERSECT= " + ) + ) + ) + ) + ) ELSE ( + SET "SEPARATOR.STUB_BOXHEAD_INTERSECT=!SEPARATOR.STUB!" + ) +) ELSE ( + IF DEFINED SEPARATOR.HORIZONTAL ( + SET "SEPARATOR.STUB_BOXHEAD_INTERSECT=!SEPARATOR.BOXHEAD!" + ) + SET "SEPARATOR.STUB_BOXHEAD_INTERSECT=" +) + +IF DEFINED SEPARATOR.VERTICAL ( + SET /A "SEPARATOR.VERTICAL.WIDTH=0" + %@strlen% SEPARATOR.STUBHEAD_BOXHEAD SEPARATOR.WIDTH + %@maxval% SEPARATOR.VERTICAL.WIDTH SEPARATOR.WIDTH + %@strlen% SEPARATOR.STUB_BOXHEAD_INTERSECT SEPARATOR.WIDTH + %@maxval% SEPARATOR.VERTICAL.WIDTH SEPARATOR.WIDTH + %@strlen% SEPARATOR.STUB_BODY SEPARATOR.WIDTH + %@maxval% SEPARATOR.VERTICAL.WIDTH SEPARATOR.WIDTH + + IF DEFINED SEPARATOR.STUBHEAD_BOXHEAD ( %@align% SEPARATOR.STUBHEAD_BOXHEAD !SEPARATOR.VERTICAL.WIDTH! C SEPARATOR.STUBHEAD_BOXHEAD ) + IF DEFINED SEPARATOR.STUB_BOXHEAD_INTERSECT ( %@align% SEPARATOR.STUB_BOXHEAD_INTERSECT !SEPARATOR.VERTICAL.WIDTH! C SEPARATOR.STUB_BOXHEAD_INTERSECT ) + IF DEFINED SEPARATOR.STUB_BODY ( %@align% SEPARATOR.STUB_BODY !SEPARATOR.VERTICAL.WIDTH! C SEPARATOR.STUB_BODY ) +) + +IF DEFINED DEBUG.OUT ( + REM ::DEBUG + ECHO. + ECHO RESOLVE_SEPARATORS exit + ECHO. + ECHO SEPARATOR.COL : "!SEPARATOR.COL!" + ECHO SEPARATOR.BOXHEAD : "!SEPARATOR.BOXHEAD!" + ECHO SEPARATOR.INTERSECT : "!SEPARATOR.INTERSECT!" + ECHO SEPARATOR.STUB : "!SEPARATOR.STUB!" + ECHO SEPARATOR.CELL : "!SEPARATOR.CELL!" + + ECHO SEPARATOR.VERTICAL : "!SEPARATOR.VERTICAL!" + ECHO SEPARATOR.HORIZONTAL : "!SEPARATOR.HORIZONTAL!" + ECHO SEPARATOR.COLUMN : "!SEPARATOR.COLUMN!" + + ECHO STUBHEAD : "!STUBHEAD!" + + ECHO SEPARATOR.VERTICAL.WIDTH : "!SEPARATOR.VERTICAL.WIDTH!" + ECHO SEPARATOR.STUBHEAD_BOXHEAD : "!SEPARATOR.STUBHEAD_BOXHEAD!" + ECHO SEPARATOR.STUB_BODY : "!SEPARATOR.STUB_BODY!" + ECHO SEPARATOR.BOXHEADERS : "!SEPARATOR.BOXHEADERS!" + + ECHO SEPARATOR.STUBHEAD_STUB : "!SEPARATOR.STUBHEAD_STUB!" + ECHO SEPARATOR.BOXHEAD_BODY : "!SEPARATOR.BOXHEAD_BODY!" + + ECHO SEPARATOR.STUB_BOXHEAD_INTERSECT : "!SEPARATOR.STUB_BOXHEAD_INTERSECT!" + ECHO. + REM ::DEBUG +) +%@exit% + + +:: At this point, the table is defined only in terms of the Stub and Boxhead +:: BUILD_TABLE takes those definitions and populates the cells +:BUILD_TABLE +:: Build the Stub head +IF NOT DEFINED STUBHEAD ( + %@repeat% #SPC# !STUB.MAX_WIDTH! STUBHEAD +) +%@strlen% STUBHEAD STUBHEAD.WIDTH +%@maxval% STUB.MAX_WIDTH STUBHEAD.WIDTH +%@align% STUBHEAD !STUB.MAX_WIDTH! !ALIGN.STUBHEAD! STUBHEAD + +SET "LINE=!STUBHEAD!!SEPARATOR.STUBHEAD_BOXHEAD!" + +:: Line = Stub head + Stub separator, still missing Boxhead column headers + +:: The test text might be wider than the column headers, so check that now +%@strlen% CELL CELL.LEN +%@maxval% COL.MAX_WIDTH CELL.LEN + +:: Build the boxheader +:: Append a column header +SET "BOXHEAD=" +FOR /L %%c IN (1,1,!COL[#]!) DO ( + SET "COL=!COL[%%c]!" + SET "COL.VALUE=#SPC#" & %@align% COL !COL.MAX_WIDTH! !ALIGN.BOXHEAD! COL.VALUE + IF [%%c] EQU [1] ( + SET "BOXHEAD=!COL.VALUE!" + ) ELSE ( + SET "BOXHEAD=!BOXHEAD!!SEPARATOR.BOXHEADERS!!COL.VALUE!" + ) +) + +%@strlen% BOXHEAD BOXHEAD.WIDTH + +SET "LINE=!LINE!!BOXHEAD!" +%@strlen% LINE TABLE.WIDTH + +:: Save the line to the TABLE +SET /A TABLE[#]+=1 +SET "TABLE[!TABLE[#]!]=!LINE!" + +:: Add a horizontal separator if defined +IF DEFINED SEPARATOR.HORIZONTAL ( + SET "LINE=" + SET "SEPARATOR=" + %@strlen% SEPARATOR.STUBHEAD_STUB SEPARATOR.WIDTH + IF [!SEPARATOR.WIDTH!] EQU [1] ( + IF DEFINED SEPARATOR.STUBHEAD_STUB ( %@repeat% SEPARATOR.STUBHEAD_STUB !STUB.MAX_WIDTH! SEPARATOR) + ) ELSE ( + IF DEFINED SEPARATOR.STUBHEAD_STUB ( %@align% SEPARATOR.STUBHEAD_STUB !STUB.MAX_WIDTH! !ALIGN.STUBHEAD_STUB! SEPARATOR ) + ) + SET "LINE=!LINE!!SEPARATOR!" + + SET "SEPARATOR=" + %@strlen% SEPARATOR.STUB_BOXHEAD_INTERSECT SEPARATOR.WIDTH + IF [!SEPARATOR.WIDTH!] EQU [1] ( + IF DEFINED SEPARATOR.STUB_BOXHEAD_INTERSECT ( %@repeat% SEPARATOR.STUB_BOXHEAD_INTERSECT !SEPARATOR.VERTICAL.WIDTH! SEPARATOR ) + ) ELSE ( + IF DEFINED SEPARATOR.STUB_BOXHEAD_INTERSECT ( %@align% SEPARATOR.STUB_BOXHEAD_INTERSECT !SEPARATOR.VERTICAL.WIDTH! !ALIGN.STUBHEAD! SEPARATOR ) + ) + SET "LINE=!LINE!!SEPARATOR!" + + SET "SEPARATOR=" + %@strlen% SEPARATOR.BOXHEAD_BODY SEPARATOR.WIDTH + IF [!SEPARATOR.WIDTH!] EQU [1] ( + IF DEFINED SEPARATOR.BOXHEAD_BODY ( %@repeat% SEPARATOR.BOXHEAD_BODY !BOXHEAD.WIDTH! SEPARATOR ) + ) ELSE ( + IF DEFINED SEPARATOR.BOXHEAD_BODY ( %@align% SEPARATOR.BOXHEAD_BODY !BOXHEAD.WIDTH! !ALIGN.STUBHEAD! SEPARATOR ) + ) + SET "LINE=!LINE!!SEPARATOR!" + + SET /A TABLE[#]+=1 + SET "TABLE[!TABLE[#]!]=!LINE!" +) + +:: Figure out the CELL alignment now so we only need to compute this once +IF NOT DEFINED SHOW.R1C1_REFERENCE ( + %@align% CELL !COL.MAX_WIDTH! !ALIGN.CELL! CELL +) ELSE ( + SET /A "R1C1_REFERENCE.R=0" +) + +:: Build the row +FOR /L %%r IN (1,1,!ROW[#]!) DO ( + :: Advance and output the spinner animation if not disabled + IF NOT DEFINED SPINNER.DISABLED ( + %@spinner% SPINNER.FRAME + ) + + :: Build the stub for the row + SET "ROW=!ROW[%%r]!" + %@align% ROW !STUB.MAX_WIDTH! !ALIGN.STUB! ROW.VALUE + + SET "SEPARATOR=" + IF DEFINED SEPARATOR.VERTICAL ( + %@strlen% SEPARATOR.STUB_BODY SEPARATOR.WIDTH + IF [!SEPARATOR.WIDTH!] EQU [1] ( + IF DEFINED SEPARATOR.STUB_BODY ( %@repeat% SEPARATOR.STUB_BODY !SEPARATOR.VERTICAL.WIDTH! SEPARATOR ) + ) ELSE ( + IF DEFINED SEPARATOR.STUB_BODY ( %@align% SEPARATOR.STUB_BODY !SEPARATOR.VERTICAL.WIDTH! !ALIGN.STUB_BODY! SEPARATOR ) + ) + ) + + IF [!ROW!] EQU [#SPC#] ( + :: We want a special case for #SPC# so that we print a blank line + SET "LINE=" + ) ELSE ( + :: Otherwise process the line + SET "LINE=!ROW.VALUE!!SEPARATOR!" + + IF [!ROW!] EQU [#NUL#] ( + SET "ROW=" + ) ELSE ( + SET "ROW=!CSI!!ROW!" + ) + + IF DEFINED SHOW.R1C1_REFERENCE ( + SET /A "R1C1_REFERENCE.C=0" + %@counter% R1C1_REFERENCE.R + ) + :: Append a cell to the row + FOR /L %%c IN (1,1,!COL[#]!) DO ( + IF DEFINED SHOW.R1C1_REFERENCE ( + %@counter% R1C1_REFERENCE.C + SET "R1C1_REFERENCE=R!R1C1_REFERENCE.R!C!R1C1_REFERENCE.C!" + %@align% R1C1_REFERENCE !COL.MAX_WIDTH! !ALIGN.CELL.R1C1! CELL + ) + IF [!COL[%%c]!] EQU [#NUL#] ( + SET "COL=" + ) ELSE ( + SET "COL=!CSI!!COL[%%c]!" + ) + IF [%%c] EQU [1] ( + SET "LINE=!LINE!!ROW!!COL!!CELL!!RESET!" + ) ELSE ( + SET "LINE=!LINE!!SEPARATOR.CELL!!ROW!!COL!!CELL!!RESET!" + ) + ) + ) + + :: Save the line to the TABLE + SET /A TABLE[#]+=1 + SET "TABLE[!TABLE[#]!]=!LINE!" +) +%@exit% + + +:DISPLAY_TABLE +:: We use an out buffer to iterate through all the rows of the table +:: This allows us to quickly display the output even though it takes +:: time to figure out the alignment calculations +FOR /L %%r IN (1,1,!TABLE[#]!) DO ( + ECHO.!TABLE[%%r]! +) +%@exit% +%=- End Main Script -=% + + +%=- Macro Definitions -=% +:DEFINE_MACROS +:: Return from this with GOTO :MAIN to retain macro definitions +SETLOCAL DISABLEDELAYEDEXPANSION +:: -------- Begin macro definitions ---------- +(SET LF=^ +%= This defines a Line Feed (0x0A) =% +) + +(SET \n=^^^ +%= This defines an escaped Line Feed (0x5E 0x0A) =% +) + +:: @strlen StrVar [RtnVar] +:: +:: Computes the length of string in variable StrVar +:: and stores the result in variable RtnVar. +:: If StrVar is #NUL#, this should be 0 width. +:: If StrVar is #SPC#, this should empty padding. +:: If RtnVar is not specified, then print the length to stdout. +:: +SET @strlen=FOR %%. IN (1 2) DO IF [%%.] EQU [2] (%\n% + FOR /F "tokens=1,2 delims=, " %%1 IN ("!argv!") DO ( ENDLOCAL%\n% + SET "s=A!%%~1!"%\n% + SET "s=!s:#NUL#=!"%\n% + SET "s=!s:#SPC#= !"%\n% + SET "len=0"%\n% + FOR %%P in (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) DO (%\n% + IF ["!s:~%%P,1!"] NEQ [""] (%\n% + SET /A "len+=%%P"%\n% + SET "s=!s:~%%P!"%\n% + )%\n% + )%\n% + FOR %%V IN (!len!) DO ENDLOCAL^&IF ["%%~2"] NEQ [""] (SET "%%~2=%%V") ELSE (ECHO %%V)%\n% + )%\n% +) ELSE SETLOCAL ENABLEDELAYEDEXPANSION^&SETLOCAL^&SET argv=, + +:: @maxval NumVar1 NumVar2 [RetVar] +:: +:: Compares NumVar1 with NumVar2, and assigns to RetVar. +:: If RtnVar is not specified, then return the largest value +:: back through NumVar1. +:: +:: It is recommended that NumVar1 will be accumulating the +:: Max value passed through multiple subsequent calls, to +:: determine the largest string passed in. +:: +SET @maxVal=FOR %%. IN (1 2) DO IF [%%.] EQU [2] (%\n% + FOR /F "tokens=1,2,3 delims=, " %%1 IN ("!argv!") DO ( ENDLOCAL%\n% + IF [!%%~1!] NEQ [] (SET /a "a=!%%~1!") ELSE (SET /a "a=%%~1")%\n% + IF [!%%~2!] NEQ [] (SET /a "b=!%%~2!") ELSE (SET /a "b=%%~2")%\n% + IF !b! GTR !a! (SET /a "a=b")%\n% + FOR %%V IN (!a!) DO ENDLOCAL^&IF ["%%~3"] NEQ [""] (SET "%%~3=%%V") ELSE (SET "%%~1=%%V")%\n% + )%\n% +) ELSE SETLOCAL ENABLEDELAYEDEXPANSION^&SETLOCAL^&SET argv=, + +:: @repeat StrVal Count [RetVar] +:: +:: Repeats StrVal, Count times, and assigns to RetVar. +:: If StrVar is #NUL#, this should empty padding. +:: If StrVar is #SPC#, this should empty padding. +:: If RtnVar is not specified, then print the output string to stdout. +:: +SET @repeat=FOR %%. IN (1 2) DO IF [%%.] EQU [2] (%\n% + FOR /F "tokens=1,2,3 delims=, " %%1 IN ("!argv!") DO ( ENDLOCAL%\n% + IF [!%%~1!] NEQ [] (SET "s=!%%~1!") ELSE (SET "s=%%~1")%\n% + SET "s=!s:#NUL#= !"%\n% + SET "s=!s:#SPC#= !"%\n% + SET "count=%%~2"%\n% + SET "outstr="%\n% + FOR /L %%. IN (1,1,!count!) DO SET "outstr=!outstr!!s!"%\n% + FOR /F "delims=" %%V IN ("!outstr!") DO ENDLOCAL^&IF ["%%~3"] NEQ [""] (SET "%%~3=%%V") ELSE (ECHO %%V)%\n% + )%\n% +) ELSE SETLOCAL ENABLEDELAYEDEXPANSION^&SETLOCAL^&SET argv=, + +:: @rtrim StrVar [CharVar] +:: +:: Right Trim CharVar surrounding StrVar. +:: If CharVar is not specified, then default to space. +:: +:: Technique Source: https://www.dostips.com/forum/viewtopic.php?p=12327#p12327 +:: +SET @rtrim=FOR %%. IN (1 2) DO IF [%%.] EQU [2] (%\n% + SET "charVar= "%\n% + FOR /F "tokens=1,2 delims=, " %%1 IN ("!argv!") DO (%\n% + SET "strVar=!%%1!"%\n% + IF [%%~2] NEQ [] IF DEFINED %%~2 SET "charVar=!%%2:~0,1!"%\n% + FOR /L %%i IN (1 1 12) DO SET "charVar=!charVar!!charVar!"%\n% + IF DEFINED strVar FOR %%k IN (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) DO (%\n% + IF ["!strVar:~-%%k!"] EQU ["!charVar:~-%%k!"] SET "strVar=!strVar:~0,-%%k!"%\n% + )%\n% + IF DEFINED strVar (%\n% + IF NOT DEFINED _notDelayed (%\n% + SET "strVar=!strVar:^=^^!"%\n% + SET "strVar=!strVar:"=""Q!^"%\n% + CALL SET "strVar=%%^strVar:^!=""E^!%%" ! %\n% + SET "strVar=!strVar:""E=^!"%\n% + SET "strVar=!strVar:""Q="!^"%\n% + )%\n% + FOR /F ^^^"eol^^=^^^%LF%%LF%^%LF%%LF%^^ delims^^=^^^" %%k IN ("!strVar!") DO ENDLOCAL^&ENDLOCAL^&SET "%%1=%%k"%\n% + ) ELSE ENDLOCAL^&ENDLOCAL^&SET "%%1="%\n% + )%\n% +) ELSE SETLOCAL^&SET "_notDelayed=!"^&SETLOCAL ENABLEDELAYEDEXPANSION^&SET argv=, + +:: @ltrim StrVar [CharVar] +:: +:: Left Trim CharVar surrounding StrVar. +:: If CharVar is not specified, then default to space. +:: +:: Technique Source: https://www.dostips.com/forum/viewtopic.php?p=12327#p12327 +:: +SET @ltrim=FOR %%. IN (1 2) DO IF [%%.] EQU [2] (%\n% + SET "charVar= "%\n% + FOR /F "tokens=1,2 delims=, " %%1 IN ("!argv!") DO (%\n% + SET "strVar=!%%1!"%\n% + IF [%%~2] NEQ [] IF DEFINED %%~2 SET "charVar=!%%2:~0,1!"%\n% + FOR /L %%i IN (1 1 12) DO SET "charVar=!charVar!!charVar!"%\n% + IF DEFINED strVar FOR %%k IN (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) DO (%\n% + IF ["!strVar:~0,%%k!"] EQU ["!charVar:~-%%k!"] SET "strVar=!strVar:~%%k!"%\n% + )%\n% + IF DEFINED strVar (%\n% + IF NOT DEFINED _notDelayed (%\n% + SET "strVar=!strVar:^=^^!"%\n% + SET "strVar=!strVar:"=""Q!^"%\n% + CALL SET "strVar=%%^strVar:^!=""E^!%%" ! %\n% + SET "strVar=!strVar:""E=^!"%\n% + SET "strVar=!strVar:""Q="!^"%\n% + )%\n% + FOR /F ^^^"eol^^=^^^%LF%%LF%^%LF%%LF%^^ delims^^=^^^" %%k IN ("!strVar!") DO ENDLOCAL^&ENDLOCAL^&SET "%%1=%%k"%\n% + ) ELSE ENDLOCAL^&ENDLOCAL^&SET "%%1="%\n% + )%\n% +) ELSE SETLOCAL^&SET "_notDelayed=!"^&SETLOCAL ENABLEDELAYEDEXPANSION^&SET argv=, + +:: @trim StrVar [CharVar] +:: +:: Trim CharVar surrounding StrVar. +:: If CharVar is not specified, then default to space. +:: +:: Technique Source: https://www.dostips.com/forum/viewtopic.php?p=12327#p12327 +:: +SET @trim=FOR %%. IN (1 2) DO IF [%%.] EQU [2] (%\n% + SET "charVar= "%\n% + FOR /F "tokens=1,2 delims=, " %%1 IN ("!argv!") DO (%\n% + SET "strVar=!%%1!"%\n% + IF [%%~2] NEQ [] IF DEFINED %%~2 SET "charVar=!%%2:~0,1!"%\n% + FOR /L %%i IN (1 1 12) DO SET "charVar=!charVar!!charVar!"%\n% + IF DEFINED strVar FOR %%k IN (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) DO (%\n% + IF ["!strVar:~-%%k!"] EQU ["!charVar:~-%%k!"] SET "strVar=!strVar:~0,-%%k!"%\n% + IF ["!strVar:~0,%%k!"] EQU ["!charVar:~-%%k!"] SET "strVar=!strVar:~%%k!"%\n% + )%\n% + IF DEFINED strVar (%\n% + IF NOT DEFINED _notDelayed (%\n% + SET "strVar=!strVar:^=^^!"%\n% + SET "strVar=!strVar:"=""Q!^"%\n% + CALL SET "strVar=%%^strVar:^!=""E^!%%" ! %\n% + SET "strVar=!strVar:""E=^!"%\n% + SET "strVar=!strVar:""Q="!^"%\n% + )%\n% + FOR /F ^^^"eol^^=^^^%LF%%LF%^%LF%%LF%^^ delims^^=^^^" %%k IN ("!strVar!") DO ENDLOCAL^&ENDLOCAL^&SET "%%1=%%k"%\n% + ) ELSE ENDLOCAL^&ENDLOCAL^&SET "%%1="%\n% + )%\n% +) ELSE SETLOCAL^&SET "_notDelayed=!"^&SETLOCAL ENABLEDELAYEDEXPANSION^&SET argv=, + +:: @align StrVar Width [RtnVar] +:: +:: Aligns the string in variable StrVar +:: in the field using the Width and Alignment provided +:: and stores the result in variable RtnVar. +:: If StrVar is #NUL#, this should empty padding. +:: If StrVar is #SPC#, this should empty padding. +:: If RtnVar is not specified, then print the output to stdout. +:: +SET @align=FOR %%. IN (1 2) DO IF [%%.] EQU [2] (%\n% + FOR /F "tokens=1,2,3,4 delims=, " %%1 IN ("!argv!") DO ( ENDLOCAL%\n% + IF ["!%%~1!"] NEQ [""] (SET "strVar=!%%~1!") ELSE (SET "strVar=%%~1")%\n% + SET "strVar=!strVar:#NUL#= !"%\n% + SET "strVar=!strVar:#SPC#= !"%\n% + IF ["!%%~2!"] NEQ [""] (SET "width=!%%~2!") ELSE (SET "width=%%~2")%\n% + SET "alignment=%%~3"%\n% + IF ["!%%~4!"] NEQ [""] (SET "%%~4=")%\n% + SET "len=1"%\n% + SET "s=!strVar!"%\n% + FOR %%P in (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) DO (%\n% + IF ["!s:~%%P,1!"] NEQ [""] (%\n% + SET /A "len+=%%P"%\n% + SET "s=!s:~%%P!"%\n% + )%\n% + )%\n% + IF /I ["!alignment!"] EQU ["L"] (%\n% + SET /A "pre=0"%\n% + SET /A "post=(!width! - !len!)"%\n% + )%\n% + IF /I ["!alignment!"] EQU ["C"] (%\n% + SET /A "pre=(!width! - !len! + 1) / 2"%\n% + SET /A "post=(!width! - !pre! - !len!)"%\n% + )%\n% + IF /I ["!alignment!"] EQU ["R"] (%\n% + SET /A "pre=(!width! - !len!)"%\n% + SET /A "post=0"%\n% + )%\n% + SET "wrkstr="%\n% + FOR /L %%. IN (1,1,!pre!) DO SET "wrkstr=!wrkstr! "%\n% + SET "wrkstr=!wrkstr!!strVar!"%\n% + FOR /L %%. IN (1,1,!post!) DO SET "wrkstr=!wrkstr! "%\n% + FOR /F "delims=" %%V IN ("!wrkstr!") DO ENDLOCAL^&IF ["%%~4"] NEQ [""] (SET "%%~4=%%V") ELSE (ECHO %%V)%\n% + )%\n% +) ELSE SETLOCAL ENABLEDELAYEDEXPANSION^&SETLOCAL^&SET argv=, + +:: @spinner FrameVar +:: +:: When called print a spinning wait cursor using the FrameVar +:: as an accumulator. If the FrameVar variable is not set +:: it is initialized. Advancing one frame the FrameVar is +:: incremented. If it reaches the last frame it is reset +:: back to the first frame. +:: +:: Has a dependency on the ANSI Control Sequence, +:: Cursor Previous Line (CPL). This means the initialization +:: needs to be completed before this macro can be used. +:: +:: The animation can be changed by adjusting the variables named +:: @spinner[#] and setting the count to match. +:: +SET "@spinner[0]= - Processing" +SET "@spinner[1]= \ Processing" +SET "@spinner[2]= ^| Processing" +SET "@spinner[3]= / Processing" +SET /A "@spinner[#]=4" + +SET @spinner=FOR %%. IN (1 2) DO IF [%%.] EQU [2] (%\n% + FOR /f "tokens=1 delims=, " %%1 IN ("!argv!") DO ( ENDLOCAL%\n% + SET "frameVar=%%~1"%\n% + IF ["!frameVar!"] EQU [""] (%\n% + SET /A "frame=0"%\n% + ) ELSE (%\n% + SET /A "frame=!frameVar!"%\n% + )%\n% + CALL ECHO %%@spinner[!frame!]%%!CPL!%\n% + SET /A "frame+=1"%\n% + SET /A "frame%%=!@spinner[#]!"%\n% + FOR /F "delims=" %%V IN ("!frame!") DO ENDLOCAL^&SET "%%~1=%%V"%\n% + )%\n% +) ELSE SETLOCAL ENABLEDELAYEDEXPANSION^&SETLOCAL^&SET argv=, + +:: @counter NumVar +:: +:: When called it uses the NumVar as an accumulator. If the +:: NumVar variable is not set it is initialized. +:: +SET @counter=FOR %%. IN (1 2) DO IF [%%.] EQU [2] (%\n% + FOR /f "tokens=1 delims=, " %%1 IN ("!argv!") DO ( ENDLOCAL%\n% + SET "numVar=%%~1"%\n% + IF ["!numVar!"] EQU [""] (%\n% + SET /A "count=0"%\n% + ) ELSE (%\n% + SET /A "count=!numVar!"%\n% + )%\n% + SET /A "count+=1"%\n% + FOR /F "delims=" %%V IN ("!count!") DO ENDLOCAL^&SET "%%~1=%%V"%\n% + )%\n% +) ELSE SETLOCAL ENABLEDELAYEDEXPANSION^&SETLOCAL^&SET argv=, + +:: @exit [ErrorLevel] +:: +:: Used to exit and optionally sets an error code if provided. +:: This is prefered for exiting a script over GOTO :EOF for consistency +:: and to pass Error Levels if necessery. This tidy's up a call +:: to EXIT /B [ErrorLevel] so the use feels the same as other macros. +:: +SET @exit=FOR %%. IN (1 2) DO IF [%%.] EQU [2] (%\n% + FOR /F "tokens=1 delims=, " %%1 IN ("!argv! 0") DO ( ENDLOCAL%\n% + IF ["%%~1"] NEQ [""] (IF DEFINED %%~1 (SET "exitCode=!%%1!"%\n% + ) ELSE (SET "exitCode=%%~1")%\n% + ) ELSE (SET "exitCode=0")%\n% + EXIT /B !exitCode!%\n% + )%\n% +) ELSE SETLOCAL ENABLEDELAYEDEXPANSION^&SETLOCAL^&SET argv=, + +GOTO :MAIN +:: -------- End macro definitions ---------- +%=- End Macro Definitions -=% + + +%=- Parse Command Line Arguments -=% +:PARSE_ARGS +SET "SCRIPT=%~dpnx0" +SET "SCRIPT_NAME=%~nx0" +SET "DATA_FILE=" + +FOR %%a IN (%*) DO ( + SET "arg=%%~a" + IF ["!arg:~0,1!"] EQU ["/"] ( + SHIFT /1 + SET "opt=!arg:~1,1!" + :: /H [Help] + IF /I ["!opt!"] EQU ["H"] ( + SET "opt=" + CALL :USAGE + %@exit% 1 + ) + :: /A [ANSI] + IF /I ["!opt!"] EQU ["A"] ( + SET "opt=" + SET "SHOW.ANSI=#TRUE#" + ) + :: /R [R1C1] + IF /I ["!opt!"] EQU ["R"] ( + SET "opt=" + SET "SHOW.R1C1_REFERENCE=#TRUE#" + ) + :: /U [UTF-8] + IF /I ["!opt!"] EQU ["U"] ( + SET "opt=" + SET "SHOW.UTF8=#TRUE#" + ) + IF ["!opt!"] NEQ [""] ( + SET "msg=Error: Unknown option: !opt!" + CALL :USAGE msg + %@exit% 2 + ) + ) +) + +:: If there isn't a definition passed on the command-line +:: default to using this script as the definition file. +IF [%~1] EQU [] ( + SET "DATA_FILE=!SCRIPT!" +) ELSE ( + SET "DATA_FILE=%~1" +) + +:: Verify that the definition file exists and exit with +:: error code 3 if it doesn't. +IF NOT EXIST !DATA_FILE! ( + SET "msg=Error: File does not exist: !DATA_FILE!" + CALL :USAGE msg + %@exit% 3 +) + +%@exit% + + +:: CALL :USAGE MsgVar +:: +:: When called with a MsgVar, it will prepend the usage +:: output message with the custom string message assigned +:: to MsgVar. This is used to further explain the error. +:: +:USAGE +SET "SCRIPT_NAME=%~nx0" + +:: The following ECHO intentionally has 80 spaces to clear the +:: line any remaining onscreen text on call. +ECHO. +IF [%1] NEQ [] ( + ECHO !%1! + ECHO. +) +ECHO Usage: !SCRIPT_NAME! [flags] [^] +ECHO. +ECHO This file echoes a bunch of color codes to the terminal to demonstrate +ECHO how they will render. The `Data Segment` portion of the file defines the +ECHO table layout and allows the user to configure whatever matrix of ANSI +ECHO Escape Sequence control characters they wish. This can also be read from +ECHO an external definition file using the same structure. +ECHO. +ECHO Flags: +ECHO /H : This message +ECHO /A : Display the ANSI Escape Sequence control characters +ECHO /R : Show cell R1C1 reference addressing instead of cell text +ECHO /U : Enable UTF-8 support +ECHO. +ECHO The script itself only has one external dependency on CHCP if you want +ECHO to show Unicode text. This just sets the Command Prompt codepage to 65001 +ECHO and will restore it when the script successfully completes. +ECHO. + +%@exit% + +%=- End Parse Command Line Arguments -=% + +:: +:: Inspired by Daniel Crisman's BASH script from http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html +:: +:: #!/bin/bash +:: # +:: # This file echoes a bunch of color codes to the +:: # terminal to demonstrate what's available. Each +:: # line is the color code of one forground color, +:: # out of 17 (default + 16 escapes), followed by a +:: # test use of that color on all nine background +:: # colors (default + 8 escapes). +:: # +:: +:: T='gYw' # The test text +:: +:: echo -e "\n 40m 41m 42m 43m\ +:: 44m 45m 46m 47m"; +:: +:: for FGs in ' m' ' 1m' ' 30m' '1;30m' ' 31m' '1;31m' ' 32m' \ +:: '1;32m' ' 33m' '1;33m' ' 34m' '1;34m' ' 35m' '1;35m' \ +:: ' 36m' '1;36m' ' 37m' '1;37m'; +:: do FG=${FGs// /} +:: echo -en " $FGs \033[$FG $T " +:: for BG in 40m 41m 42m 43m 44m 45m 46m 47m; +:: do echo -en "$EINS \033[$FG\033[$BG $T \033[0m"; +:: done +:: echo; +:: done +:: echo +:: diff --git a/src/tools/ansi-color/ansi-colortool.def b/src/tools/ansi-color/ansi-colortool.def new file mode 100644 index 00000000000..c5f501f8bc5 --- /dev/null +++ b/src/tools/ansi-color/ansi-colortool.def @@ -0,0 +1,53 @@ +:: ColorTool equivalent (ColorTool.exe -c) - Modified with ANSI table line drawing +__DATA__ +__TABLE__ +SET "UTF8.REQUIRED=#TRUE#" +:: The test text +SET "CELL= gYw " +:: Alignment properties for the cells and headers +SET "ALIGN.CELL=C" +SET "ALIGN.BOXHEAD=C" +SET "ALIGN.STUB=L" +SET "ALIGN.STUBHEAD=C" +:: For testing +SET "STUBHEAD=ANSI" +SET "SEPARATOR.STUBHEAD_BOXHEAD=║" +SET "SEPARATOR.STUB_BODY=║" +SET "SEPARATOR.STUBHEAD_STUB=─" +SET "SEPARATOR.BOXHEAD_BODY=─" +SET "SEPARATOR.INTERSECT=─╫─" +SET "SEPARATOR.BOXHEAD=│" +SET "SEPARATOR.CELL=│" +__TABLE:END__ +__COLS__ +#NUL# +40m +41m +42m +43m +44m +45m +46m +47m +__COLS:END__ +__ROWS__ +m +1m +30m +1;30m +31m +1;31m +32m +1;32m +33m +1;33m +34m +1;34m +35m +1;35m +36m +1;36m +37m +1;37m +__ROWS:END__ +__DATA:END__ \ No newline at end of file diff --git a/src/tools/ansi-color/colortest.def b/src/tools/ansi-color/colortest.def new file mode 100644 index 00000000000..ce9c7cfa012 --- /dev/null +++ b/src/tools/ansi-color/colortest.def @@ -0,0 +1,52 @@ +:: Extended ColorTool equivalent (ColorTool.exe -c) to show more colors, but requires 107 columns +__DATA__ +__TABLE__ +:: The test text +SET "CELL= gYw " +:: Alignment properties for the cells and headers +SET "ALIGN.CELL=C" +SET "ALIGN.BOXHEAD=C" +SET "ALIGN.STUB=L" +:: Table spacing +SET "SEPARATOR.CELL= " +SET "SEPARATOR.STUB= " +__TABLE:END__ +__COLS__ +#NUL# +40m +100m +41m +101m +42m +102m +43m +103m +44m +104m +45m +105m +46m +106m +47m +107m +__COLS:END__ +__ROWS__ +#NUL# +30m +90m +31m +91m +32m +92m +33m +93m +34m +94m +35m +95m +36m +96m +37m +97m +__ROWS:END__ +__DATA:END__ \ No newline at end of file diff --git a/src/tools/ansi-color/colortool.def b/src/tools/ansi-color/colortool.def new file mode 100644 index 00000000000..e5edb1daa9f --- /dev/null +++ b/src/tools/ansi-color/colortool.def @@ -0,0 +1,45 @@ +:: ColorTool equivalent (ColorTool.exe -c) +__DATA__ +__TABLE__ +:: The test text +SET "CELL= gYw " +:: Alignment properties for the cells and headers +SET "ALIGN.CELL=C" +SET "ALIGN.BOXHEAD=C" +SET "ALIGN.STUB=L" +:: Table spacing +SET "SEPARATOR.CELL= " +SET "SEPARATOR.STUB= " +__TABLE:END__ +__COLS__ +#NUL# +40m +41m +42m +43m +44m +45m +46m +47m +__COLS:END__ +__ROWS__ +m +1m +30m +1;30m +31m +1;31m +32m +1;32m +33m +1;33m +34m +1;34m +35m +1;35m +36m +1;36m +37m +1;37m +__ROWS:END__ +__DATA:END__ \ No newline at end of file diff --git a/src/tools/ansi-color/crisman.def b/src/tools/ansi-color/crisman.def new file mode 100644 index 00000000000..cc4f92bb29e --- /dev/null +++ b/src/tools/ansi-color/crisman.def @@ -0,0 +1,78 @@ +:: #!/bin/bash +:: # +:: # This file echoes a bunch of color codes to the +:: # terminal to demonstrate what's available. Each +:: # line is the color code of one forground color, +:: # out of 17 (default + 16 escapes), followed by a +:: # test use of that color on all nine background +:: # colors (default + 8 escapes). +:: # +:: +:: T='gYw' # The test text +:: +:: echo -e "\n 40m 41m 42m 43m\ +:: 44m 45m 46m 47m"; +:: +:: for FGs in ' m' ' 1m' ' 30m' '1;30m' ' 31m' '1;31m' ' 32m' \ +:: '1;32m' ' 33m' '1;33m' ' 34m' '1;34m' ' 35m' '1;35m' \ +:: ' 36m' '1;36m' ' 37m' '1;37m'; +:: do FG=${FGs// /} +:: echo -en " $FGs \033[$FG $T " +:: for BG in 40m 41m 42m 43m 44m 45m 46m 47m; +:: do echo -en "$EINS \033[$FG\033[$BG $T \033[0m"; +:: done +:: echo; +:: done +:: echo + +:: This is the recreation of the TLDP.org bash script output +__DATA__ +__TABLE__ +:: Greatest mystery ever. Why gYw? +SET "CELL= gYw " +:: The stub is right justified +SET "ALIGN.STUB=R" +:: The box header is centered over each column +SET "ALIGN.BOXHEAD=C" +:: There is a space between the stub and the rest of the table +SET "SEPARATOR.STUB= " +:: Each column is separated by a space +SET "SEPARATOR.COL= " +:: The widest stub label is 5 characters, but the original table uses 6 for the stub, producing a leading space +SET /A "STUB.MAX_WIDTH=6" +__TABLE:END__ +:: Background +__COLS__ +:: A column with no background attributes applied +#NUL# +40m +41m +42m +43m +44m +45m +46m +47m +__COLS:END__ +:: Foreground +__ROWS__ +m +1m +30m +1;30m +31m +1;31m +32m +1;32m +33m +1;33m +34m +1;34m +35m +1;35m +36m +1;36m +37m +1;37m +__ROWS:END__ +__DATA:END__ \ No newline at end of file diff --git a/src/tools/ansi-color/plaid.def b/src/tools/ansi-color/plaid.def new file mode 100644 index 00000000000..4d498f0badb --- /dev/null +++ b/src/tools/ansi-color/plaid.def @@ -0,0 +1,54 @@ +:: Uses Unicode Block Element Shade Characters to show a dithered mix of foreground and background colors +__DATA__ +__TABLE__ +SET "UTF8.REQUIRED=#TRUE#" +:: The test text +REM SET "CELL= ░▒▓█" +SET "CELL=░▒▓" +SET "STUBHEAD=plaid" +:: Separator characters for cells and headers +SET "SEPARATOR.STUBHEAD_BOXHEAD=│" +SET "SEPARATOR.STUBHEAD_STUB=─" +SET "SEPARATOR.INTERSECT=┘" +__TABLE:END__ + +:: Background +__COLS__ +40m +41m +42m +43m +44m +45m +46m +47m +100m +101m +102m +103m +104m +105m +106m +107m +__COLS:END__ + +:: [Intensity;][Attribute;]Foreground +__ROWS__ +30m +31m +32m +33m +34m +35m +36m +37m +90m +91m +92m +93m +94m +95m +96m +97m +__ROWS:END__ +__DATA:END__ \ No newline at end of file diff --git a/src/tools/ansi-color/rainbow.def b/src/tools/ansi-color/rainbow.def new file mode 100644 index 00000000000..50a1bbae6e2 --- /dev/null +++ b/src/tools/ansi-color/rainbow.def @@ -0,0 +1,52 @@ +:: Like the colortest definition, but arranged to show the colors as ROY G. BIV, dark then light +__DATA__ +__TABLE__ +:: The test text +SET "CELL= gYw " +:: Alignment properties for the cells and headers +SET "ALIGN.CELL=C" +SET "ALIGN.BOXHEAD=C" +SET "ALIGN.STUB=L" +:: Table spacing +SET "SEPARATOR.CELL= " +SET "SEPARATOR.STUB= " +__TABLE:END__ +__COLS__ +#NUL# +40m +47m +41m +45m +44m +46m +42m +43m +101m +105m +104m +106m +102m +103m +100m +107m +__COLS:END__ +__ROWS__ +#NUL# +30m +37m +31m +35m +34m +36m +32m +33m +91m +95m +94m +96m +92m +93m +90m +97m +__ROWS:END__ +__DATA:END__ \ No newline at end of file diff --git a/src/tools/ansi-color/rosetta.def b/src/tools/ansi-color/rosetta.def new file mode 100644 index 00000000000..148b7165e82 --- /dev/null +++ b/src/tools/ansi-color/rosetta.def @@ -0,0 +1,40 @@ +:: https://rosettacode.org/wiki/Terminal_control/Coloured_text#ooRexx +__DATA__ +:: Background +__COLS__ +#NUL# +40m +41m +42m +43m +44m +45m +46m +47m +__COLS:END__ +:: Foreground +__ROWS__ +0m +1m +0;30m +1;30m +0;31m +1;31m +0;32m +1;32m +0;33m +1;33m +0;34m +1;34m +0;35m +1;35m +0;36m +1;36m +0;37m +1;37m +4m +5m +7m +8m +__ROWS:END__ +__DATA:END__ \ No newline at end of file diff --git a/src/tools/ansi-color/sgr-intensity.def b/src/tools/ansi-color/sgr-intensity.def new file mode 100644 index 00000000000..4742e1bf51c --- /dev/null +++ b/src/tools/ansi-color/sgr-intensity.def @@ -0,0 +1,142 @@ +:: Check SGR intensity attributes, requires 100 columns +__DATA__ +__TABLE__ +:: The test text +SET "CELL= gYw " +SET "STUBHEAD=SGR Intensity " +:: Alignment properties for the cells and headers +REM SET "ALIGN.CELL=C" +REM SET "ALIGN.BOXHEAD=R" +REM SET "ALIGN.STUB=L" +REM SET "ALIGN.STUBHEAD=C" +:: Separator characters for cells and headers +REM SET "SEPARATOR.STUB= " +REM SET "SEPARATOR.STUB=│" +REM SET "SEPARATOR.BOXHEAD= " +REM SET "SEPARATOR.BOXHEAD=─" +REM SET "SEPARATOR.COL= " +REM SET "SEPARATOR.COL=╎" +REM SET "SEPARATOR.STUBHEAD_BOXHEAD= " +REM Can't use pipe or exclamation point as a separator +SET "SEPARATOR.STUBHEAD_BOXHEAD=:" +REM SET "SEPARATOR.STUBHEAD_BOXHEAD=▓▓" +REM SET "SEPARATOR.STUBHEAD_STUB= " +REM SET "SEPARATOR.STUBHEAD_STUB=─" +SET "SEPARATOR.STUBHEAD_STUB=-" +REM SET "SEPARATOR.STUBHEAD_STUB=▓" +REM SET "SEPARATOR.INTERSECT= " +REM SET "SEPARATOR.INTERSECT=┼" +REM SET "SEPARATOR.INTERSECT=┘" +SET "SEPARATOR.INTERSECT=+" +REM SET "SEPARATOR.INTERSECT=▓▒▒░" +REM SET "SEPARATOR.BOXHEAD_BODY= " +REM SET "SEPARATOR.BOXHEAD_BODY=─" +REM SET "SEPARATOR.BOXHEAD_BODY=░" +REM SET "SEPARATOR.STUB_BODY= " +REM SET "SEPARATOR.STUB_BODY=│" +REM SET "SEPARATOR.STUB_BODY=░░" +REM SET "SEPARATOR.BOXHEADERS= " +REM SET "SEPARATOR.BOXHEADERS=╎" +REM SET "SEPARATOR.CELL= " +REM SET "SEPARATOR.CELL=╎" +__TABLE:END__ + +:: Background +__COLS__ +#NUL# +40m +100m +41m +101m +42m +102m +43m +103m +44m +104m +45m +105m +46m +106m +47m +107m +__COLS:END__ + +:: [Intensity;][Attribute;]Foreground +__ROWS__ +:: Attributes +1m +#NUL# +2m +#SPC# +:: Normal +30m +90m +31m +91m +32m +92m +33m +93m +34m +94m +35m +95m +36m +96m +37m +97m +#SPC# +:: Bold or increased intensity, 1 +:: Normal +:: Faint (decreased intensity), 2 +1;30m + 30m +2;30m +1;90m + 90m +2;90m +1;31m + 31m +2;31m +1;91m + 91m +2;91m +1;32m + 32m +2;32m +1;92m + 92m +2;92m +1;33m + 33m +2;33m +1;93m + 93m +2;93m +1;34m + 34m +2;34m +1;94m + 94m +2;94m +1;35m + 35m +2;35m +1;95m + 95m +2;95m +1;36m + 36m +2;36m +1;96m + 96m +2;96m +1;37m + 37m +2;37m +1;97m + 97m +2;97m +__ROWS:END__ +__DATA:END__ \ No newline at end of file diff --git a/src/tools/ansi-color/sgr.def b/src/tools/ansi-color/sgr.def new file mode 100644 index 00000000000..6205e8c210a --- /dev/null +++ b/src/tools/ansi-color/sgr.def @@ -0,0 +1,282 @@ +:: Complete matrix of SGR parameters available +:: This definition also demonstrates the various configuration changes +:: which are used to control the way the table is generated +:: Requires 142 columns to display correctly +__DATA__ +:: Select Graphic Rendition (SGR) parameters +:: #NUL# is treated as a special case to provide cells in that column +:: or row, but there is no row or column value applied to the cell. +:: This has the effect that the row or column has no SGR parameter applied +:: and so this will show the default. +__TABLE__ +SET "UTF8.REQUIRED=#TRUE#" +:: The test text +SET "CELL= gYw " +SET "STUBHEAD=SGR" +:: Alignment properties for the cells and headers +REM SET "ALIGN.CELL=C" +REM SET "ALIGN.BOXHEAD=R" +REM SET "ALIGN.STUB=L" +REM SET "ALIGN.STUBHEAD=C" +:: Separator characters for cells and headers +REM SET "SEPARATOR.STUB= " +REM SET "SEPARATOR.STUB=│" +REM SET "SEPARATOR.BOXHEAD= " +REM SET "SEPARATOR.BOXHEAD=─" +REM SET "SEPARATOR.COL= " +REM SET "SEPARATOR.COL=╎" +REM SET "SEPARATOR.STUBHEAD_BOXHEAD= " +SET "SEPARATOR.STUBHEAD_BOXHEAD=│" +REM SET "SEPARATOR.STUBHEAD_BOXHEAD=▓▓" +REM SET "SEPARATOR.STUBHEAD_STUB= " +SET "SEPARATOR.STUBHEAD_STUB=─" +REM SET "SEPARATOR.STUBHEAD_STUB=▓" +REM SET "SEPARATOR.INTERSECT= " +REM SET "SEPARATOR.INTERSECT=┼" +SET "SEPARATOR.INTERSECT=┘" +REM SET "SEPARATOR.INTERSECT=▓▒▒░" +REM SET "SEPARATOR.BOXHEAD_BODY= " +REM SET "SEPARATOR.BOXHEAD_BODY=─" +REM SET "SEPARATOR.BOXHEAD_BODY=░" +REM SET "SEPARATOR.STUB_BODY= " +REM SET "SEPARATOR.STUB_BODY=│" +REM SET "SEPARATOR.STUB_BODY=░░" +REM SET "SEPARATOR.BOXHEADERS= " +REM SET "SEPARATOR.BOXHEADERS=╎" +REM SET "SEPARATOR.CELL= " +REM SET "SEPARATOR.CELL=╎" +__TABLE:END__ + +:: Background +__COLS__ +#NUL# +1m +2m +3m +4m +5m +6m +7m +8m +9m +21m +40m +100m +41m +101m +42m +102m +43m +103m +44m +104m +45m +105m +46m +106m +47m +107m +__COLS:END__ + +:: [Intensity;][Attribute;]Foreground +__ROWS__ +#NUL# +1m +2m +3m +4m +5m +6m +7m +8m +9m +21m +:: Normal +30m +90m +31m +91m +32m +92m +33m +93m +34m +94m +35m +95m +36m +96m +37m +97m +:: Bold or increased intensity, 1 +1;30m +1;90m +1;31m +1;91m +1;32m +1;92m +1;33m +1;93m +1;34m +1;94m +1;35m +1;95m +1;36m +1;96m +1;37m +1;97m +:: Faint (decreased intensity), 2 +2;30m +2;90m +2;31m +2;91m +2;32m +2;92m +2;33m +2;93m +2;34m +2;94m +2;35m +2;95m +2;36m +2;96m +2;37m +2;97m +:: Italic, 3 +3;30m +3;90m +3;31m +3;91m +3;32m +3;92m +3;33m +3;93m +3;34m +3;94m +3;35m +3;95m +3;36m +3;96m +3;37m +3;97m +:: Underline, 4 +4;30m +4;90m +4;31m +4;91m +4;32m +4;92m +4;33m +4;93m +4;34m +4;94m +4;35m +4;95m +4;36m +4;96m +4;37m +4;97m +:: Slow Blink, 5 +5;30m +5;90m +5;31m +5;91m +5;32m +5;92m +5;33m +5;93m +5;34m +5;94m +5;35m +5;95m +5;36m +5;96m +5;37m +5;97m +:: Rapid Blink, 6 +6;30m +6;90m +6;31m +6;91m +6;32m +6;92m +6;33m +6;93m +6;34m +6;94m +6;35m +6;95m +6;36m +6;96m +6;37m +6;97m +:: Reverse video, 7 +7;30m +7;90m +7;31m +7;91m +7;32m +7;92m +7;33m +7;93m +7;34m +7;94m +7;35m +7;95m +7;36m +7;96m +7;37m +7;97m +:: Conceal, 8 +8;30m +8;90m +8;31m +8;91m +8;32m +8;92m +8;33m +8;93m +8;34m +8;94m +8;35m +8;95m +8;36m +8;96m +8;37m +8;97m +:: Crossed-out, 9 +9;30m +9;90m +9;31m +9;91m +9;32m +9;92m +9;33m +9;93m +9;34m +9;94m +9;35m +9;95m +9;36m +9;96m +9;37m +9;97m +:: Double Underline, 21 +21;30m +21;90m +21;31m +21;91m +21;32m +21;92m +21;33m +21;93m +21;34m +21;94m +21;35m +21;95m +21;36m +21;96m +21;37m +21;97m +__ROWS:END__ +__DATA:END__ \ No newline at end of file diff --git a/src/tools/ansi-color/tsgr.def b/src/tools/ansi-color/tsgr.def new file mode 100644 index 00000000000..70cd133054e --- /dev/null +++ b/src/tools/ansi-color/tsgr.def @@ -0,0 +1,273 @@ +:: Complete matrix of SGR parameters available, but transposed +:: This definition is like SGR but for each row, all attributes are applied +:: per foreground color instead of incrementing on the attributes +:: ForEach(fg in Foreground) { ForEach(a in Attribute) { a;fm }} instead of +:: ForEach(a in Attribute) { ForEach(fg in Foreground) { a;fm }} +__DATA__ +:: Select Graphic Rendition (SGR) parameters +:: #NUL# is treated as a special case to provide cells in that column +:: or row, but there is no row or column value applied to the cell. +:: This has the effect that the row or column has no SGR parameter applied +:: and so this will show the default. +__TABLE__ +SET "UTF8.REQUIRED=#TRUE#" +:: The test text +REM SET "CELL= ЯMB " +SET "CELL= gYw " +SET "STUBHEAD=tSGR" +:: Alignment properties for the cells and headers +REM SET "ALIGN.CELL=C" +REM SET "ALIGN.BOXHEAD=R" +REM SET "ALIGN.STUB=L" +REM SET "ALIGN.STUBHEAD=C" +:: Separator characters for cells and headers +REM SET "SEPARATOR.STUB= " +REM SET "SEPARATOR.STUB=│" +REM SET "SEPARATOR.BOXHEAD= " +REM SET "SEPARATOR.BOXHEAD=─" +REM SET "SEPARATOR.COL= " +REM SET "SEPARATOR.COL=╎" +REM SET "SEPARATOR.STUBHEAD_BOXHEAD= " +SET "SEPARATOR.STUBHEAD_BOXHEAD=│" +REM SET "SEPARATOR.STUBHEAD_BOXHEAD=▓▓" +REM SET "SEPARATOR.STUBHEAD_STUB= " +SET "SEPARATOR.STUBHEAD_STUB=─" +REM SET "SEPARATOR.STUBHEAD_STUB=▓" +REM SET "SEPARATOR.INTERSECT= " +REM SET "SEPARATOR.INTERSECT=┼" +SET "SEPARATOR.INTERSECT=┘" +REM SET "SEPARATOR.INTERSECT=▓▒▒░" +REM SET "SEPARATOR.BOXHEAD_BODY= " +REM SET "SEPARATOR.BOXHEAD_BODY=─" +REM SET "SEPARATOR.BOXHEAD_BODY=░" +REM SET "SEPARATOR.STUB_BODY= " +REM SET "SEPARATOR.STUB_BODY=│" +REM SET "SEPARATOR.STUB_BODY=░░" +REM SET "SEPARATOR.BOXHEADERS= " +REM SET "SEPARATOR.BOXHEADERS=╎" +REM SET "SEPARATOR.CELL= " +REM SET "SEPARATOR.CELL=╎" +__TABLE:END__ + +:: Background +__COLS__ +#NUL# +1m +2m +3m +4m +5m +6m +7m +8m +9m +21m +40m +100m +41m +101m +42m +102m +43m +103m +44m +104m +45m +105m +46m +106m +47m +107m +__COLS:END__ + +:: [Intensity;][Attribute;]Foreground +__ROWS__ +#NUL# +1m +2m +3m +4m +5m +6m +7m +8m +9m +21m +30m +1;30m +2;30m +3;30m +4;30m +5;30m +6;30m +7;30m +8;30m +9;30m +21;30m +90m +1;90m +2;90m +3;90m +4;90m +5;90m +6;90m +7;90m +8;90m +9;90m +21;90m +31m +1;31m +2;31m +3;31m +4;31m +5;31m +6;31m +7;31m +8;31m +9;31m +21;31m +91m +1;91m +2;91m +3;91m +4;91m +5;91m +6;91m +7;91m +8;91m +9;91m +21;91m +32m +1;32m +2;32m +3;32m +4;32m +5;32m +6;32m +7;32m +8;32m +9;32m +21;32m +92m +1;92m +2;92m +3;92m +4;92m +5;92m +6;92m +7;92m +8;92m +9;92m +21;92m +33m +1;33m +2;33m +3;33m +4;33m +5;33m +6;33m +7;33m +8;33m +9;33m +21;33m +93m +1;93m +2;93m +3;93m +4;93m +5;93m +6;93m +7;93m +8;93m +9;93m +21;93m +34m +1;34m +2;34m +3;34m +4;34m +5;34m +6;34m +7;34m +8;34m +9;34m +21;34m +94m +1;94m +2;94m +3;94m +4;94m +5;94m +6;94m +7;94m +8;94m +9;94m +21;94m +35m +1;35m +2;35m +3;35m +4;35m +5;35m +6;35m +7;35m +8;35m +9;35m +21;35m +95m +1;95m +2;95m +3;95m +4;95m +5;95m +6;95m +7;95m +8;95m +9;95m +21;95m +36m +1;36m +2;36m +3;36m +4;36m +5;36m +6;36m +7;36m +8;36m +9;36m +21;36m +96m +1;96m +2;96m +3;96m +4;96m +5;96m +6;96m +7;96m +8;96m +9;96m +21;96m +37m +1;37m +2;37m +3;37m +4;37m +5;37m +6;37m +7;37m +8;37m +9;37m +21;37m +97m +1;97m +2;97m +3;97m +4;97m +5;97m +6;97m +7;97m +8;97m +9;97m +21;97m +__ROWS:END__ +__DATA:END__ \ No newline at end of file diff --git a/src/tools/ansi-color/ubuntu.def b/src/tools/ansi-color/ubuntu.def new file mode 100644 index 00000000000..c68babad917 --- /dev/null +++ b/src/tools/ansi-color/ubuntu.def @@ -0,0 +1,41 @@ +:: https://askubuntu.com/questions/27314/script-to-display-all-terminal-colors +__DATA__ +__TABLE__ +:: The test text +SET "CELL= gYw " +SET "SEPARATOR.CELL= " +__TABLE:END__ +:: Background +__COLS__ +#NUL# +40m +41m +42m +43m +44m +45m +46m +47m +__COLS:END__ +:: Foreground +__ROWS__ +m +1m +30m +1;30m +31m +1;31m +32m +1;32m +33m +1;33m +34m +1;34m +35m +1;35m +36m +1;36m +37m +1;37m +__ROWS:END__ +__DATA:END__ \ No newline at end of file From 3256befcdd607f6e22705a1348ee49997f90330f Mon Sep 17 00:00:00 2001 From: Ryan Beesley Date: Sun, 12 Dec 2021 21:49:18 -0800 Subject: [PATCH 02/35] Add README.md --- src/tools/ansi-color/README.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/tools/ansi-color/README.md diff --git a/src/tools/ansi-color/README.md b/src/tools/ansi-color/README.md new file mode 100644 index 00000000000..f3ccd4ff829 --- /dev/null +++ b/src/tools/ansi-color/README.md @@ -0,0 +1,29 @@ +# ANSI-COLOR + +Ansi-Color.cmd makes it easy to render SGR attributes, foreground colors, and background colors, in a table. This complements ColorTool for diagnostics purposes and seeing all the colors of the applied color scheme. + +```plain +Usage: ansi-color.cmd [flags] [] + + This file echoes a bunch of color codes to the terminal to demonstrate + how they will render. The `Data Segment` portion of the file defines the + table layout and allows the user to configure whatever matrix of ANSI + Escape Sequence control characters they wish. This can also be read from + an external definition file using the same structure. + + Flags: + /H : This message + /A : Display the ANSI Escape Sequence control characters + /R : Show cell R1C1 reference addressing instead of cell text + /U : Enable UTF-8 support + + The script itself only has one external dependency on CHCP if you want + to show Unicode text. This just sets the Command Prompt codepage to 65001 + and will restore it when the script successfully completes. + ``` + + The entire tool is written as a Windows Command script and the only dependency is on the stock CHCP tool which can be used to change the command prompt code page. The script makes heavy use of Batch "macros," a concept originally explored by Ed Dyreen, Jeb, and Dave Benham on [DosTips.com](https://www.dostips.com/forum/viewtopic.php?f=3&t=1827). The use of macros in Ansi-Color allow complex results and capable of generating tables defined as separate files. + + Of notable interest, the script itself is its own definition file and doesn't require external definition files to work. In fact, the script file itself is just a UTF-8 text file which can easily be edited, doesn't need to be recompiled, and has configuration settings embedded in it, or it can use flags passed as arguments. Additionally, several definition files are included which replicate the output of similar tools. + + Lastly, there are two diagnostic modes which might be useful when writing color schemes. `/A` is a flag which instead of showing the output table, it replaces the actual ESC code in the output string with the Unicode codepoint representation of an ESC character, and when redirected from standard out to a file like `ansi-color /a > out.txt` it will create a text file which shows what would have been generated. This makes it easier to find errors in how something rendered. Additionally the `/R` flag borrows the Excel R1C1 reference address scheme to replace the Cell text with row/column IDs. In this way you can generate a table and then identify a combination of attributes and colors by that corresponding reference. \ No newline at end of file From 0c09451262c4ac03c259ed369a79232e161cee0f Mon Sep 17 00:00:00 2001 From: Ryan Beesley Date: Sun, 12 Dec 2021 22:02:47 -0800 Subject: [PATCH 03/35] Satisfy check-spelling-bot --- .../spelling/expect/3256befcdd607f6e22705a1348ee49997f90330f.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/tools/ansi-color/.github/actions/spelling/expect/3256befcdd607f6e22705a1348ee49997f90330f.txt diff --git a/src/tools/ansi-color/.github/actions/spelling/expect/3256befcdd607f6e22705a1348ee49997f90330f.txt b/src/tools/ansi-color/.github/actions/spelling/expect/3256befcdd607f6e22705a1348ee49997f90330f.txt new file mode 100644 index 00000000000..e69de29bb2d From 1796285c9569d9b7d1a8bf8e6cc12ded372bfd86 Mon Sep 17 00:00:00 2001 From: Ryan Beesley Date: Mon, 13 Dec 2021 00:32:45 -0800 Subject: [PATCH 04/35] Fixed missing files for spell-check-bot script --- ...5c1ec487b80f127ca611d10b973f66d9ed6812.txt | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/actions/spelling/expect/205c1ec487b80f127ca611d10b973f66d9ed6812.txt diff --git a/.github/actions/spelling/expect/205c1ec487b80f127ca611d10b973f66d9ed6812.txt b/.github/actions/spelling/expect/205c1ec487b80f127ca611d10b973f66d9ed6812.txt new file mode 100644 index 00000000000..a05e335621b --- /dev/null +++ b/.github/actions/spelling/expect/205c1ec487b80f127ca611d10b973f66d9ed6812.txt @@ -0,0 +1,34 @@ +askubuntu +BIV +boxheader +colortest +Crisman +DISABLEDELAYEDEXPANSION +dostips +dpnx +Dyreen +EINS +EQU +FGs +forground +GTR +HOWTO +Initalize +ltrim +maxval +necessery +onscreen +outstr +properites +Rexx +rosettacode +ROY +Rtn +rtrim +seperate +STUBHEAD +tldp +uwaterloo +uwspace +viewtopic +wrkstr From b2b4e4e2897b912a0cca7b21ecee1b9000d68fae Mon Sep 17 00:00:00 2001 From: Ryan Beesley Date: Mon, 13 Dec 2021 00:39:33 -0800 Subject: [PATCH 05/35] Deleting spell-check-bot file placed incorrectly --- .../spelling/expect/3256befcdd607f6e22705a1348ee49997f90330f.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/tools/ansi-color/.github/actions/spelling/expect/3256befcdd607f6e22705a1348ee49997f90330f.txt diff --git a/src/tools/ansi-color/.github/actions/spelling/expect/3256befcdd607f6e22705a1348ee49997f90330f.txt b/src/tools/ansi-color/.github/actions/spelling/expect/3256befcdd607f6e22705a1348ee49997f90330f.txt deleted file mode 100644 index e69de29bb2d..00000000000 From 8a95ab1468f545baf4f38063fc7bd969b981aaa1 Mon Sep 17 00:00:00 2001 From: Ryan Beesley Date: Tue, 14 Dec 2021 01:17:24 -0800 Subject: [PATCH 06/35] Improved spelling, comments, error handling Added a way to get the errorlevel from the CHCP call. If it fails, we can still use the result if there isn't a need for UTF-8. This should be more robust and should allow things to work even if CHCP isn't on a system for some reason. The consideration is that there might be a localization where this doesn't work so try to fail gracefuly. I also cleaned up the way help and internal errors are handled better now. Requesting help doesn't set an error level for internal commands, so this app won't either. Finally, addressed the speling errers I had in the first checkin. Forground (sic) is intentional because that is the spelling in the original BASH script. Other errors raised I corrected. I've tried to leave comments throughout, but if there is anything not understood, I can try to document it more. --- ...5c1ec487b80f127ca611d10b973f66d9ed6812.txt | 5 - src/tools/ansi-color/ansi-color.cmd | 182 ++++++------------ src/tools/ansi-color/crisman.def | 4 +- 3 files changed, 64 insertions(+), 127 deletions(-) diff --git a/.github/actions/spelling/expect/205c1ec487b80f127ca611d10b973f66d9ed6812.txt b/.github/actions/spelling/expect/205c1ec487b80f127ca611d10b973f66d9ed6812.txt index a05e335621b..0252bd5aac8 100644 --- a/.github/actions/spelling/expect/205c1ec487b80f127ca611d10b973f66d9ed6812.txt +++ b/.github/actions/spelling/expect/205c1ec487b80f127ca611d10b973f66d9ed6812.txt @@ -13,19 +13,14 @@ FGs forground GTR HOWTO -Initalize ltrim maxval -necessery -onscreen outstr -properites Rexx rosettacode ROY Rtn rtrim -seperate STUBHEAD tldp uwaterloo diff --git a/src/tools/ansi-color/ansi-color.cmd b/src/tools/ansi-color/ansi-color.cmd index b9e8641b5ed..a63f7037e3d 100644 --- a/src/tools/ansi-color/ansi-color.cmd +++ b/src/tools/ansi-color/ansi-color.cmd @@ -1,17 +1,20 @@ -@ECHO OFF +@ECHO OFF & :: ANSI-COLOR :: Authored by Ryan Beesley :: https://github.com/rbeesley GOTO :DEFINE_MACROS %=- Entry point after macro definitions -=% :MAIN SETLOCAL ENABLEDELAYEDEXPANSION CALL :PARSE_ARGS %1 %2 %3 %4 %5 %6 %7 %8 %9 +:: Error when parsing IF ERRORLEVEL 1 %@exit% %ERRORLEVEL% - -REM ::Debug -- Use this to break after parsing arguments -REM CMD /C EXIT -1073741510 +:: Parsing success +IF ERRORLEVEL 0 GOTO :CONFIGURATION +:: Help requested, but this shouldn't actually be an error from CMDs perspective +IF ERRORLEVEL -1 %@exit% 0 %=- Configuration -=% +:CONFIGURATION :: Default test text if not defined in the data segment SET "CELL= gYw " :: Uncomment to use UTF-8 for output, such as when the test text is Unicode @@ -22,8 +25,6 @@ REM SET "SPINNER.DISABLED=#TRUE#" REM SET "SHOW.ANSI=#TRUE#" :: Uncomment to show cell R1C1 reference addressing instead of cell text REM SET "SHOW.R1C1_REFERENCE=#TRUE#" -:: Uncomment to turn on debug output for diagnosing separator resolution -REM SET "DEBUG.OUT=#TRUE#" %=- End Configuration -=% @@ -368,34 +369,62 @@ REM FOR /F "tokens=* USEBACKQ" %%G IN (`PowerShell -Command "[char]0x1B"`) DO (S SET "ESC=" :: If we're going to display the ANSI Escape Sequence control characters -:: save the active console Code Page, change to UTF-8, and override ESC +:: we require UTF-8, will disable the spinner, and override the ANSI ESC +:: character with a Unicode codepoint which represents ESC. IF DEFINED SHOW.ANSI ( + SET "UTF8.REQUIRED=#TRUE#" SET "SPINNER.DISABLED=#TRUE#" - REM SET "SHOW.UTF8=#TRUE#" ) :: The console (CMD) is normally not UTF-8, so preserve the codepage so we can reset it. :: Because the output of chcp is localized, we grab the last value of the string, :: which we have our fingers crossed, will be the codepage. -FOR /F "tokens=*" %%_ IN ('chcp') DO (SET CHCP_OUT=%%_) -FOR %%_ IN (!CHCP_OUT!) DO (SET CHCP=%%_) +FOR /F "tokens=*" %%_ IN ('chcp 2^>^&1 ^& FOR /F %%_ IN ^("ERRORLEVEL"^) DO @CALL ECHO __ERRORLEVEL__:%%%%_%%') DO ( + SET CHCP_OUT=%%_ + :: Check if the CHCP call failed + IF ["!CHCP_OUT:~0,15!"] EQU ["__ERRORLEVEL__:"] ( + SET "CHCP_ERR=!CHCP_OUT:__ERRORLEVEL__:=!" + IF [!CHCP_ERR!] EQU [9009] ( + REM This means that CHCP wasn't found + REM If the definition doesn't require UTF-8, this might be okay + REM CHCP_RET is no longer valid though, so undefine it + REM Interesting side note, this is an example where the :: can be used for REM + REM See https://stackoverflow.com/a/61981588 for more information + SET "CHCP_RET=" + ) ELSE IF [!CHCP_ERR!] NEQ [0] ( + ECHO Error: Unable to read active codepage + %@exit% !CHCP_ERR! + ) + ) ELSE ( + SET "CHCP_RET=!CHCP_OUT!" + ) +) + +:: If we didn't get an error, read the last value of the output string +FOR %%_ IN (!CHCP_RET!) DO (SET CHCP=%%_) IF DEFINED CHCP ( IF [!CHCP!] EQU [65001] ( SET "SHOW.UTF8=#TRUE#" ) ELSE ( IF DEFINED SHOW.UTF8 ( - chcp 65001>NUL + chcp 65001 > NUL 2>&1 + IF ERRORLEVEL 1 ( + ECHO Error: Unable to set the active codepage + %@exit% %ErrorLevel% + ) ) ) ) SET "CHCP_OUT=" +SET "CHCP_ERR=" +SET "CHCP_RET=" -:: This is a seperate code block so that the active console Code Page is changed first +:: This is a separate code block so that the active console Code Page is changed first IF DEFINED SHOW.ANSI ( SET "ESC=␛" ) -:: Control Sequence Introducer +:: Control Sequence Introducer (CSI) SET "CSI=!ESC![" :: Cursor Up @@ -421,7 +450,7 @@ IF DEFINED SHOW.R1C1_REFERENCE ( SET /A COL.MAX_WIDTH=7 ) -:: Default properites if not defined in the data segment +:: Default properties if not defined in the data segment :: See Figure 1.1 in the PDF for Wang Terminology :: https://uwspace.uwaterloo.ca/handle/10012/10962 @@ -460,7 +489,7 @@ SET "SEPARATOR.COLUMN=" :: build the table, and show the table CALL :READ_DATA_SEGMENT CALL :VALIDATE_CONFIGURATION -IF ERRORLEVEL 4 ( +IF ERRORLEVEL 1 ( %@exit% %ERRORLEVEL% ) CALL :RESOLVE_SEPARATORS @@ -469,7 +498,11 @@ CALL :DISPLAY_TABLE :: Restore the console Code Page saved at the beginning of the script IF DEFINED CHCP ( - chcp !CHCP!>NUL + chcp !CHCP! > NUL 2>&1 + IF ERRORLEVEL 1 ( + ECHO Error: Unable to reset the active codepage + %@exit% %ErrorLevel% + ) ) :: Exit @@ -494,19 +527,19 @@ FOR /F "delims=" %%_ IN (!DATA_FILE!) DO ( ) IF ["%%_"] EQU ["__ROWS__"] ( SET SEGMENT=ROWS - :: Initalize the row globals + :: Initialize the row globals SET /A ROW[#]=0 SET /A ROWS.LEN=0 ) IF ["%%_"] EQU ["__COLS__"] ( SET SEGMENT=COLS - :: Initalize the column globals + :: Initialize the column globals SET /A COL[#]=0 SET /A COLS.LEN=0 ) IF ["%%_"] EQU ["__TABLE__"] ( SET SEGMENT=TABLE - :: Initalize the table globals + :: Initialize the table globals SET /A TABLE[#]=0 ) IF ["%%_"] EQU ["__DATA__"] ( @@ -581,9 +614,9 @@ SET "ROW[!ROW[#]!]=!ROW!" IF DEFINED UTF8.REQUIRED ( IF NOT DEFINED SHOW.UTF8 ( SET "SCRIPT_NAME=%~nx0" - SET "msg=Error: Requested definition script requires UTF-8.!LF! Try ^"!SCRIPT_NAME! /U [^]^" to run with UTF-8 support!LF! or change the default configuration in !SCRIPT_NAME! to always use UTF-8." + SET "msg=Error: UTF-8 console support is required.!LF! Try ^"!SCRIPT_NAME! /U [^]^" to enable UTF-8 support!LF! or change the default configuration in !SCRIPT_NAME! to always use UTF-8." CALL :USAGE msg - %@exit% 4 + %@exit% 1 ) ) %@exit% @@ -592,36 +625,6 @@ IF DEFINED UTF8.REQUIRED ( :: Separators have cascading effects, so if some are not defined this is where :: they are defined :RESOLVE_SEPARATORS -IF DEFINED DEBUG.OUT ( - REM ::DEBUG - ECHO. - ECHO RESOLVE_SEPARATORS enter - ECHO. - ECHO SEPARATOR.COL : "!SEPARATOR.COL!" - ECHO SEPARATOR.BOXHEAD : "!SEPARATOR.BOXHEAD!" - ECHO SEPARATOR.INTERSECT : "!SEPARATOR.INTERSECT!" - ECHO SEPARATOR.STUB : "!SEPARATOR.STUB!" - ECHO SEPARATOR.CELL : "!SEPARATOR.CELL!" - - ECHO SEPARATOR.VERTICAL : "!SEPARATOR.VERTICAL!" - ECHO SEPARATOR.HORIZONTAL : "!SEPARATOR.HORIZONTAL!" - ECHO SEPARATOR.COLUMN : "!SEPARATOR.COLUMN!" - - ECHO STUBHEAD : "!STUBHEAD!" - - ECHO SEPARATOR.VERTICAL.WIDTH : "!SEPARATOR.VERTICAL.WIDTH!" - ECHO SEPARATOR.STUBHEAD_BOXHEAD : "!SEPARATOR.STUBHEAD_BOXHEAD!" - ECHO SEPARATOR.STUB_BODY : "!SEPARATOR.STUB_BODY!" - ECHO SEPARATOR.BOXHEADERS : "!SEPARATOR.BOXHEADERS!" - - ECHO SEPARATOR.STUBHEAD_STUB : "!SEPARATOR.STUBHEAD_STUB!" - ECHO SEPARATOR.BOXHEAD_BODY : "!SEPARATOR.BOXHEAD_BODY!" - - ECHO SEPARATOR.STUB_BOXHEAD_INTERSECT : "!SEPARATOR.STUB_BOXHEAD_INTERSECT!" - ECHO SEPARATOR.BOXHEAD_BODY_INTERSECT : "!SEPARATOR.BOXHEAD_BODY_INTERSECT!" - ECHO. - REM ::DEBUG -) :: Define the vertical separator IF DEFINED SEPARATOR.STUB ( @@ -705,24 +708,6 @@ IF DEFINED SEPARATOR.INTERSECT ( ) ) -IF DEFINED DEBUG.OUT ( - REM ::DEBUG - ECHO. - ECHO RESOLVE_SEPARATORS pre-trim - ECHO. - ECHO SEPARATOR.COL : "!SEPARATOR.COL!" - ECHO SEPARATOR.BOXHEAD : "!SEPARATOR.BOXHEAD!" - ECHO SEPARATOR.INTERSECT : "!SEPARATOR.INTERSECT!" - ECHO SEPARATOR.STUB : "!SEPARATOR.STUB!" - ECHO SEPARATOR.CELL : "!SEPARATOR.CELL!" - ECHO SEPARATOR.STUBHEAD_BOXHEAD : "!SEPARATOR.STUBHEAD_BOXHEAD!" - ECHO SEPARATOR.STUB_BODY : "!SEPARATOR.STUB_BODY!" - ECHO SEPARATOR.STUBHEAD_STUB : "!SEPARATOR.STUBHEAD_STUB!" - ECHO SEPARATOR.BOXHEAD_BODY : "!SEPARATOR.BOXHEAD_BODY!" - ECHO. - REM ::DEBUG -) - :: Trim the variables we use to draw our separators :: so we only work with non-space characters SET "SEPARATOR.COL.TRIM=!SEPARATOR.COL!" @@ -744,24 +729,6 @@ SET "SEPARATOR.STUBHEAD_STUB.TRIM=!SEPARATOR.STUBHEAD_STUB!" SET "SEPARATOR.BOXHEAD_BODY.TRIM=!SEPARATOR.BOXHEAD_BODY!" %@trim% SEPARATOR.BOXHEAD_BODY.TRIM -IF DEFINED DEBUG.OUT ( - REM ::DEBUG - ECHO. - ECHO RESOLVE_SEPARATORS post-trim - ECHO. - ECHO SEPARATOR.COL.TRIM : "!SEPARATOR.COL.TRIM!" - ECHO SEPARATOR.BOXHEAD.TRIM : "!SEPARATOR.BOXHEAD.TRIM!" - ECHO SEPARATOR.INTERSECT.TRIM : "!SEPARATOR.INTERSECT.TRIM!" - ECHO SEPARATOR.STUB.TRIM : "!SEPARATOR.STUB.TRIM!" - ECHO SEPARATOR.CELL.TRIM : "!SEPARATOR.CELL.TRIM!" - ECHO SEPARATOR.STUBHEAD_BOXHEAD.TRIM : "!SEPARATOR.STUBHEAD_BOXHEAD.TRIM!" - ECHO SEPARATOR.STUB_BODY.TRIM : "!SEPARATOR.STUB_BODY.TRIM!" - ECHO SEPARATOR.STUBHEAD_STUB.TRIM : "!SEPARATOR.STUBHEAD_STUB.TRIM!" - ECHO SEPARATOR.BOXHEAD_BODY.TRIM : "!SEPARATOR.BOXHEAD_BODY.TRIM!" - ECHO. - REM ::DEBUG -) - IF DEFINED SEPARATOR.VERTICAL ( IF DEFINED SEPARATOR.HORIZONTAL ( IF NOT DEFINED SEPARATOR.STUB_BOXHEAD_INTERSECT.TRIM ( @@ -807,35 +774,6 @@ IF DEFINED SEPARATOR.VERTICAL ( IF DEFINED SEPARATOR.STUB_BODY ( %@align% SEPARATOR.STUB_BODY !SEPARATOR.VERTICAL.WIDTH! C SEPARATOR.STUB_BODY ) ) -IF DEFINED DEBUG.OUT ( - REM ::DEBUG - ECHO. - ECHO RESOLVE_SEPARATORS exit - ECHO. - ECHO SEPARATOR.COL : "!SEPARATOR.COL!" - ECHO SEPARATOR.BOXHEAD : "!SEPARATOR.BOXHEAD!" - ECHO SEPARATOR.INTERSECT : "!SEPARATOR.INTERSECT!" - ECHO SEPARATOR.STUB : "!SEPARATOR.STUB!" - ECHO SEPARATOR.CELL : "!SEPARATOR.CELL!" - - ECHO SEPARATOR.VERTICAL : "!SEPARATOR.VERTICAL!" - ECHO SEPARATOR.HORIZONTAL : "!SEPARATOR.HORIZONTAL!" - ECHO SEPARATOR.COLUMN : "!SEPARATOR.COLUMN!" - - ECHO STUBHEAD : "!STUBHEAD!" - - ECHO SEPARATOR.VERTICAL.WIDTH : "!SEPARATOR.VERTICAL.WIDTH!" - ECHO SEPARATOR.STUBHEAD_BOXHEAD : "!SEPARATOR.STUBHEAD_BOXHEAD!" - ECHO SEPARATOR.STUB_BODY : "!SEPARATOR.STUB_BODY!" - ECHO SEPARATOR.BOXHEADERS : "!SEPARATOR.BOXHEADERS!" - - ECHO SEPARATOR.STUBHEAD_STUB : "!SEPARATOR.STUBHEAD_STUB!" - ECHO SEPARATOR.BOXHEAD_BODY : "!SEPARATOR.BOXHEAD_BODY!" - - ECHO SEPARATOR.STUB_BOXHEAD_INTERSECT : "!SEPARATOR.STUB_BOXHEAD_INTERSECT!" - ECHO. - REM ::DEBUG -) %@exit% @@ -1263,7 +1201,7 @@ SET @counter=FOR %%. IN (1 2) DO IF [%%.] EQU [2] (%\n% :: :: Used to exit and optionally sets an error code if provided. :: This is prefered for exiting a script over GOTO :EOF for consistency -:: and to pass Error Levels if necessery. This tidy's up a call +:: and to pass Error Levels if necessary. This tidy's up a call :: to EXIT /B [ErrorLevel] so the use feels the same as other macros. :: SET @exit=FOR %%. IN (1 2) DO IF [%%.] EQU [2] (%\n% @@ -1295,12 +1233,13 @@ FOR %%a IN (%*) DO ( IF /I ["!opt!"] EQU ["H"] ( SET "opt=" CALL :USAGE - %@exit% 1 + %@exit% -1 ) :: /A [ANSI] IF /I ["!opt!"] EQU ["A"] ( SET "opt=" SET "SHOW.ANSI=#TRUE#" + SET "SHOW.UTF8=#TRUE#" ) :: /R [R1C1] IF /I ["!opt!"] EQU ["R"] ( @@ -1315,7 +1254,7 @@ FOR %%a IN (%*) DO ( IF ["!opt!"] NEQ [""] ( SET "msg=Error: Unknown option: !opt!" CALL :USAGE msg - %@exit% 2 + %@exit% 1 ) ) ) @@ -1333,7 +1272,7 @@ IF [%~1] EQU [] ( IF NOT EXIST !DATA_FILE! ( SET "msg=Error: File does not exist: !DATA_FILE!" CALL :USAGE msg - %@exit% 3 + %@exit% 1 ) %@exit% @@ -1349,7 +1288,7 @@ IF NOT EXIST !DATA_FILE! ( SET "SCRIPT_NAME=%~nx0" :: The following ECHO intentionally has 80 spaces to clear the -:: line any remaining onscreen text on call. +:: line any remaining on screen text on call. ECHO. IF [%1] NEQ [] ( ECHO !%1! @@ -1366,6 +1305,7 @@ ECHO. ECHO Flags: ECHO /H : This message ECHO /A : Display the ANSI Escape Sequence control characters +ECHO This requires UTF-8 support and implies the additional /U flag ECHO /R : Show cell R1C1 reference addressing instead of cell text ECHO /U : Enable UTF-8 support ECHO. diff --git a/src/tools/ansi-color/crisman.def b/src/tools/ansi-color/crisman.def index cc4f92bb29e..bacfe408fce 100644 --- a/src/tools/ansi-color/crisman.def +++ b/src/tools/ansi-color/crisman.def @@ -25,7 +25,9 @@ :: done :: echo -:: This is the recreation of the TLDP.org bash script output +:: https://tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html +:: This is the recreation of the output of the TLDP.org +:: bash script provided by Daniel Crisman. __DATA__ __TABLE__ :: Greatest mystery ever. Why gYw? From 7006e52e960b8b8ab7e5b57d422d784f75c0b9d8 Mon Sep 17 00:00:00 2001 From: Ryan Beesley Date: Tue, 14 Dec 2021 01:29:58 -0800 Subject: [PATCH 07/35] check-spelling-bot fix. --- src/tools/ansi-color/ansi-color.cmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/ansi-color/ansi-color.cmd b/src/tools/ansi-color/ansi-color.cmd index a63f7037e3d..f3cf6592eb2 100644 --- a/src/tools/ansi-color/ansi-color.cmd +++ b/src/tools/ansi-color/ansi-color.cmd @@ -9,7 +9,7 @@ CALL :PARSE_ARGS %1 %2 %3 %4 %5 %6 %7 %8 %9 IF ERRORLEVEL 1 %@exit% %ERRORLEVEL% :: Parsing success IF ERRORLEVEL 0 GOTO :CONFIGURATION -:: Help requested, but this shouldn't actually be an error from CMDs perspective +:: Help requested, but this shouldn't actually be an error from CMD's perspective IF ERRORLEVEL -1 %@exit% 0 From 78004c7c8c543c2dda6d3bf5fc478777a1fbae2b Mon Sep 17 00:00:00 2001 From: Ryan Beesley Date: Tue, 14 Dec 2021 02:02:18 -0800 Subject: [PATCH 08/35] Fixed comment and macro casing --- src/tools/ansi-color/ansi-color.cmd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tools/ansi-color/ansi-color.cmd b/src/tools/ansi-color/ansi-color.cmd index f3cf6592eb2..da4468588ce 100644 --- a/src/tools/ansi-color/ansi-color.cmd +++ b/src/tools/ansi-color/ansi-color.cmd @@ -388,7 +388,7 @@ FOR /F "tokens=*" %%_ IN ('chcp 2^>^&1 ^& FOR /F %%_ IN ^("ERRORLEVEL"^) DO @CAL REM This means that CHCP wasn't found REM If the definition doesn't require UTF-8, this might be okay REM CHCP_RET is no longer valid though, so undefine it - REM Interesting side note, this is an example where the :: can be used for REM + REM Interesting side note, this is an example where the :: can't be used for REM REM See https://stackoverflow.com/a/61981588 for more information SET "CHCP_RET=" ) ELSE IF [!CHCP_ERR!] NEQ [0] ( @@ -982,7 +982,7 @@ SET @strlen=FOR %%. IN (1 2) DO IF [%%.] EQU [2] (%\n% :: Max value passed through multiple subsequent calls, to :: determine the largest string passed in. :: -SET @maxVal=FOR %%. IN (1 2) DO IF [%%.] EQU [2] (%\n% +SET @maxval=FOR %%. IN (1 2) DO IF [%%.] EQU [2] (%\n% FOR /F "tokens=1,2,3 delims=, " %%1 IN ("!argv!") DO ( ENDLOCAL%\n% IF [!%%~1!] NEQ [] (SET /a "a=!%%~1!") ELSE (SET /a "a=%%~1")%\n% IF [!%%~2!] NEQ [] (SET /a "b=!%%~2!") ELSE (SET /a "b=%%~2")%\n% From 21a936ee783d0a31f0bd87ca6453f0c2caa2ada7 Mon Sep 17 00:00:00 2001 From: Ryan Beesley Date: Wed, 15 Dec 2021 00:52:16 -0800 Subject: [PATCH 09/35] Improved CHCP reliability and case insensitive IFs If there is an IF which checks for a string in a definition file, it is now case insensitive and shouldn't cause problems. Updated error output when CHCP fails and only show a warning if Unicode isn't required. If Unicode is required, then show an additional error and exit. This has a negative that even if the shell is running on codepage 65001, it will block the execution of a definition file which requests UTF8 or the flag is set. The error in this case still makes sense as this happens when trying to read the active codepage and the utility will not know if this fails at this point in execution. I think this is the right balance. --- src/tools/ansi-color/ansi-color.cmd | 59 ++++++++++++++++------------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/src/tools/ansi-color/ansi-color.cmd b/src/tools/ansi-color/ansi-color.cmd index da4468588ce..f6b1e4dc7ca 100644 --- a/src/tools/ansi-color/ansi-color.cmd +++ b/src/tools/ansi-color/ansi-color.cmd @@ -384,16 +384,21 @@ FOR /F "tokens=*" %%_ IN ('chcp 2^>^&1 ^& FOR /F %%_ IN ^("ERRORLEVEL"^) DO @CAL :: Check if the CHCP call failed IF ["!CHCP_OUT:~0,15!"] EQU ["__ERRORLEVEL__:"] ( SET "CHCP_ERR=!CHCP_OUT:__ERRORLEVEL__:=!" - IF [!CHCP_ERR!] EQU [9009] ( - REM This means that CHCP wasn't found - REM If the definition doesn't require UTF-8, this might be okay - REM CHCP_RET is no longer valid though, so undefine it - REM Interesting side note, this is an example where the :: can't be used for REM - REM See https://stackoverflow.com/a/61981588 for more information - SET "CHCP_RET=" - ) ELSE IF [!CHCP_ERR!] NEQ [0] ( - ECHO Error: Unable to read active codepage - %@exit% !CHCP_ERR! + IF [!CHCP_ERR!] NEQ [0] ( + :: This means that the call to CHCP failed + ECHO Warning: Error reading the active codepage, check the output from the command CHCP. + If DEFINED SHOW.UTF8 ( + :: UTF8 is required if SHOW.UTF8 is defined, so error out + ECHO. + ECHO Error: UTF8 is required for the definition file in use or flags provided. Exiting. + :: Since this was fatal, also pass the error code received trying to call CHCP + %@exit% !CHCP_ERR! + ) ELSE ( + :: If UTF8 isn't required, maybe we can swallow this error and still show ANSI definition file + SET "SHOW.UTF8=" + :: Clear the CHCP_RET value as nothing returned should be considered valid + SET "CHCP_RET=" + ) ) ) ELSE ( SET "CHCP_RET=!CHCP_OUT!" @@ -517,32 +522,32 @@ CMD /C EXIT -1073741510 :READ_DATA_SEGMENT SET "DATA_SEGMENT=" FOR /F "delims=" %%_ IN (!DATA_FILE!) DO ( - IF ["%%_"] EQU ["__ROWS:END__"] SET SEGMENT= - IF ["%%_"] EQU ["__COLS:END__"] SET SEGMENT= - IF ["%%_"] EQU ["__TABLE:END__"] SET SEGMENT= - IF ["%%_"] EQU ["__DATA:END__"] SET DATA_SEGMENT= + IF /I ["%%_"] EQU ["__ROWS:END__"] SET SEGMENT= + IF /I ["%%_"] EQU ["__COLS:END__"] SET SEGMENT= + IF /I ["%%_"] EQU ["__TABLE:END__"] SET SEGMENT= + IF /I ["%%_"] EQU ["__DATA:END__"] SET DATA_SEGMENT= IF DEFINED DATA_SEGMENT ( SET "DATA=%%_" CALL :PARSE_DATA_SEGMENT !DATA! ) - IF ["%%_"] EQU ["__ROWS__"] ( + IF /I ["%%_"] EQU ["__ROWS__"] ( SET SEGMENT=ROWS :: Initialize the row globals SET /A ROW[#]=0 SET /A ROWS.LEN=0 ) - IF ["%%_"] EQU ["__COLS__"] ( + IF /I ["%%_"] EQU ["__COLS__"] ( SET SEGMENT=COLS :: Initialize the column globals SET /A COL[#]=0 SET /A COLS.LEN=0 ) - IF ["%%_"] EQU ["__TABLE__"] ( + IF /I ["%%_"] EQU ["__TABLE__"] ( SET SEGMENT=TABLE :: Initialize the table globals SET /A TABLE[#]=0 ) - IF ["%%_"] EQU ["__DATA__"] ( + IF /I ["%%_"] EQU ["__DATA__"] ( SET DATA_SEGMENT=#TRUE# SET SEGMENT= ) @@ -556,9 +561,9 @@ IF NOT DEFINED SEGMENT %@exit% SET "DATA=%*" :: Skip over any comments -IF ["!DATA:~0,2!"] EQU ["::"] %@exit% -IF ["!DATA:~0,3!"] EQU ["REM"] %@exit% -IF ["!DATA:~0,4!"] EQU ["@REM"] %@exit% +IF /I ["!DATA:~0,2!"] EQU ["::"] %@exit% +IF /I ["!DATA:~0,4!"] EQU ["REM "] %@exit% +IF /I ["!DATA:~0,5!"] EQU ["@REM "] %@exit% :: Advance and output the spinner animation if not disabled IF NOT DEFINED SPINNER.DISABLED ( @@ -566,9 +571,9 @@ IF NOT DEFINED SPINNER.DISABLED ( ) :: Dispatch to TABLE, COLS, or ROWS parsing routines -IF ["!SEGMENT!"] EQU ["TABLE"] CALL :PARSE_TABLE_DATA !DATA! -IF ["!SEGMENT!"] EQU ["COLS"] CALL :PARSE_COLS_DATA !DATA! -IF ["!SEGMENT!"] EQU ["ROWS"] CALL :PARSE_ROWS_DATA !DATA! +IF /I ["!SEGMENT!"] EQU ["TABLE"] CALL :PARSE_TABLE_DATA !DATA! +IF /I ["!SEGMENT!"] EQU ["COLS"] CALL :PARSE_COLS_DATA !DATA! +IF /I ["!SEGMENT!"] EQU ["ROWS"] CALL :PARSE_ROWS_DATA !DATA! %@exit% @@ -880,14 +885,14 @@ FOR /L %%r IN (1,1,!ROW[#]!) DO ( ) ) - IF [!ROW!] EQU [#SPC#] ( + IF /I ["!ROW!"] EQU ["#SPC#"] ( :: We want a special case for #SPC# so that we print a blank line SET "LINE=" ) ELSE ( :: Otherwise process the line SET "LINE=!ROW.VALUE!!SEPARATOR!" - IF [!ROW!] EQU [#NUL#] ( + IF /I ["!ROW!"] EQU ["#NUL#"] ( SET "ROW=" ) ELSE ( SET "ROW=!CSI!!ROW!" @@ -904,7 +909,7 @@ FOR /L %%r IN (1,1,!ROW[#]!) DO ( SET "R1C1_REFERENCE=R!R1C1_REFERENCE.R!C!R1C1_REFERENCE.C!" %@align% R1C1_REFERENCE !COL.MAX_WIDTH! !ALIGN.CELL.R1C1! CELL ) - IF [!COL[%%c]!] EQU [#NUL#] ( + IF /I ["!COL[%%c]!"] EQU ["#NUL#"] ( SET "COL=" ) ELSE ( SET "COL=!CSI!!COL[%%c]!" From 77154201dce12d2fa40febd8c423e7da7a94e03b Mon Sep 17 00:00:00 2001 From: Ryan Beesley Date: Wed, 15 Dec 2021 01:07:27 -0800 Subject: [PATCH 10/35] UTF-8 Error message was inconsistent. --- src/tools/ansi-color/ansi-color.cmd | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tools/ansi-color/ansi-color.cmd b/src/tools/ansi-color/ansi-color.cmd index f6b1e4dc7ca..e088a86ce4c 100644 --- a/src/tools/ansi-color/ansi-color.cmd +++ b/src/tools/ansi-color/ansi-color.cmd @@ -388,13 +388,13 @@ FOR /F "tokens=*" %%_ IN ('chcp 2^>^&1 ^& FOR /F %%_ IN ^("ERRORLEVEL"^) DO @CAL :: This means that the call to CHCP failed ECHO Warning: Error reading the active codepage, check the output from the command CHCP. If DEFINED SHOW.UTF8 ( - :: UTF8 is required if SHOW.UTF8 is defined, so error out + :: UTF-8 support is required if SHOW.UTF8 is defined, so error out ECHO. - ECHO Error: UTF8 is required for the definition file in use or flags provided. Exiting. + ECHO Error: UTF-8 support is required for the definition file in use or flags provided. :: Since this was fatal, also pass the error code received trying to call CHCP %@exit% !CHCP_ERR! ) ELSE ( - :: If UTF8 isn't required, maybe we can swallow this error and still show ANSI definition file + :: If UTF-8 support isn't required, maybe we can swallow this error and still show ANSI definition file SET "SHOW.UTF8=" :: Clear the CHCP_RET value as nothing returned should be considered valid SET "CHCP_RET=" From bfc731f239b9ea788bced8e102b44401e3b9469b Mon Sep 17 00:00:00 2001 From: Ryan Beesley Date: Wed, 15 Dec 2021 02:05:51 -0800 Subject: [PATCH 11/35] Improved table parsing If there is anything evaluated which can cause an error this should be caught now. Trimmed the data before it is further evaluated to make sure extra whitespace is dropped but you can't indent in the definition files. Trimming before checking segments would fix this, but introduces a performance hit. --- src/tools/ansi-color/ansi-color.cmd | 41 +++++++++++++++++------------ 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/src/tools/ansi-color/ansi-color.cmd b/src/tools/ansi-color/ansi-color.cmd index e088a86ce4c..7b2bf42ee87 100644 --- a/src/tools/ansi-color/ansi-color.cmd +++ b/src/tools/ansi-color/ansi-color.cmd @@ -493,10 +493,9 @@ SET "SEPARATOR.COLUMN=" :: Read and parse the data, validate the configuration, calculate table headings, :: build the table, and show the table CALL :READ_DATA_SEGMENT +IF ERRORLEVEL 1 %@exit% %ERRORLEVEL% CALL :VALIDATE_CONFIGURATION -IF ERRORLEVEL 1 ( - %@exit% %ERRORLEVEL% -) +IF ERRORLEVEL 1 %@exit% %ERRORLEVEL% CALL :RESOLVE_SEPARATORS CALL :BUILD_TABLE CALL :DISPLAY_TABLE @@ -522,34 +521,35 @@ CMD /C EXIT -1073741510 :READ_DATA_SEGMENT SET "DATA_SEGMENT=" FOR /F "delims=" %%_ IN (!DATA_FILE!) DO ( - IF /I ["%%_"] EQU ["__ROWS:END__"] SET SEGMENT= - IF /I ["%%_"] EQU ["__COLS:END__"] SET SEGMENT= - IF /I ["%%_"] EQU ["__TABLE:END__"] SET SEGMENT= - IF /I ["%%_"] EQU ["__DATA:END__"] SET DATA_SEGMENT= + SET "DATA=%%_" + IF /I ["!DATA:~0,12!"] EQU ["__ROWS:END__"] SET "SEGMENT=" + IF /I ["!DATA:~0,12!"] EQU ["__COLS:END__"] SET "SEGMENT=" + IF /I ["!DATA:~0,13!"] EQU ["__TABLE:END__"] SET "SEGMENT=" + IF /I ["!DATA:~0,12!"] EQU ["__DATA:END__"] SET "DATA_SEGMENT=" IF DEFINED DATA_SEGMENT ( - SET "DATA=%%_" CALL :PARSE_DATA_SEGMENT !DATA! + IF ERRORLEVEL 1 %@exit% %ERRORLEVEL% ) - IF /I ["%%_"] EQU ["__ROWS__"] ( - SET SEGMENT=ROWS + IF /I ["!DATA:~0,8!"] EQU ["__ROWS__"] ( + SET "SEGMENT=ROWS" :: Initialize the row globals SET /A ROW[#]=0 SET /A ROWS.LEN=0 ) - IF /I ["%%_"] EQU ["__COLS__"] ( - SET SEGMENT=COLS + IF /I ["!DATA:~0,8!"] EQU ["__COLS__"] ( + SET "SEGMENT=COLS" :: Initialize the column globals SET /A COL[#]=0 SET /A COLS.LEN=0 ) - IF /I ["%%_"] EQU ["__TABLE__"] ( - SET SEGMENT=TABLE + IF /I ["!DATA:~0,9!"] EQU ["__TABLE__"] ( + SET "SEGMENT=TABLE" :: Initialize the table globals SET /A TABLE[#]=0 ) - IF /I ["%%_"] EQU ["__DATA__"] ( - SET DATA_SEGMENT=#TRUE# - SET SEGMENT= + IF /I ["!DATA:~0,8!"] EQU ["__DATA__"] ( + SET "DATA_SEGMENT=#TRUE#" + SET "SEGMENT=" ) ) %@exit% @@ -559,11 +559,15 @@ FOR /F "delims=" %%_ IN (!DATA_FILE!) DO ( :PARSE_DATA_SEGMENT IF NOT DEFINED SEGMENT %@exit% SET "DATA=%*" +:: We're parsing the data segment, so clean up the data before further processing +%@trim% DATA :: Skip over any comments IF /I ["!DATA:~0,2!"] EQU ["::"] %@exit% IF /I ["!DATA:~0,4!"] EQU ["REM "] %@exit% +IF /I ["!DATA!"] EQU ["REM"] %@exit% IF /I ["!DATA:~0,5!"] EQU ["@REM "] %@exit% +IF /I ["!DATA!"] EQU ["@REM"] %@exit% :: Advance and output the spinner animation if not disabled IF NOT DEFINED SPINNER.DISABLED ( @@ -588,6 +592,9 @@ IF /I ["!DATA:~0,3!"] EQU ["IF "] GOTO :EVAL_TABLE_DATA :EVAL_TABLE_DATA :: Eval the TABLE data directly %* +:: If there is an error, we want to catch it +IF ERRORLEVEL 1 %@exit% %ERRORLEVEL% +:: Otherwise just exit the routine %@exit% From 777366f89eb53fa1c210ab33866657bcd6762240 Mon Sep 17 00:00:00 2001 From: Ryan Beesley Date: Mon, 27 Dec 2021 13:55:03 -0800 Subject: [PATCH 12/35] Added support for column spaces and adjusted defs Adding #SPC# to a column definition will do the same as adding a #SPC# to a row, in that it will add visual separation. This is unlike #NUL# which just doesn't apply an associated escape sequence but still writes the test text to a cell. #SPC# writes spaces instead. Also updated a couple of definitions which benefit from this change. Fixed sgr-intensity.def so that is shows intensity from low to high, flipping 1; and 2; attributes. --- src/tools/ansi-color/ansi-color.cmd | 18 +++++-- src/tools/ansi-color/sgr-intensity.def | 68 +++++++++++++------------- src/tools/ansi-color/sgr.def | 12 +++++ src/tools/ansi-color/tsgr.def | 17 +++++++ 4 files changed, 77 insertions(+), 38 deletions(-) diff --git a/src/tools/ansi-color/ansi-color.cmd b/src/tools/ansi-color/ansi-color.cmd index 7b2bf42ee87..c9bcbb5cc0f 100644 --- a/src/tools/ansi-color/ansi-color.cmd +++ b/src/tools/ansi-color/ansi-color.cmd @@ -563,11 +563,11 @@ SET "DATA=%*" %@trim% DATA :: Skip over any comments +IF /I ["!DATA!"] EQU ["REM"] %@exit% +IF /I ["!DATA!"] EQU ["@REM"] %@exit% IF /I ["!DATA:~0,2!"] EQU ["::"] %@exit% IF /I ["!DATA:~0,4!"] EQU ["REM "] %@exit% -IF /I ["!DATA!"] EQU ["REM"] %@exit% IF /I ["!DATA:~0,5!"] EQU ["@REM "] %@exit% -IF /I ["!DATA!"] EQU ["@REM"] %@exit% :: Advance and output the spinner animation if not disabled IF NOT DEFINED SPINNER.DISABLED ( @@ -922,9 +922,19 @@ FOR /L %%r IN (1,1,!ROW[#]!) DO ( SET "COL=!CSI!!COL[%%c]!" ) IF [%%c] EQU [1] ( - SET "LINE=!LINE!!ROW!!COL!!CELL!!RESET!" + IF /I ["!COL[%%c]!"] EQU ["#SPC#"] ( + %@repeat% #SPC# !COL.MAX_WIDTH! OUT + SET "LINE=!LINE!!OUT!" + ) ELSE ( + SET "LINE=!LINE!!ROW!!COL!!CELL!!RESET!" + ) ) ELSE ( - SET "LINE=!LINE!!SEPARATOR.CELL!!ROW!!COL!!CELL!!RESET!" + IF /I ["!COL[%%c]!"] EQU ["#SPC#"] ( + %@repeat% #SPC# !COL.MAX_WIDTH! OUT + SET "LINE=!LINE!!SEPARATOR.CELL!!OUT!" + ) ELSE ( + SET "LINE=!LINE!!SEPARATOR.CELL!!ROW!!COL!!CELL!!RESET!" + ) ) ) ) diff --git a/src/tools/ansi-color/sgr-intensity.def b/src/tools/ansi-color/sgr-intensity.def index 4742e1bf51c..bc188d09334 100644 --- a/src/tools/ansi-color/sgr-intensity.def +++ b/src/tools/ansi-color/sgr-intensity.def @@ -65,9 +65,9 @@ __COLS:END__ :: [Intensity;][Attribute;]Foreground __ROWS__ :: Attributes -1m -#NUL# 2m +#NUL# +1m #SPC# :: Normal 30m @@ -90,53 +90,53 @@ __ROWS__ :: Bold or increased intensity, 1 :: Normal :: Faint (decreased intensity), 2 -1;30m - 30m 2;30m -1;90m - 90m + 30m +1;30m 2;90m -1;31m - 31m + 90m +1;90m 2;31m -1;91m - 91m + 31m +1;31m 2;91m -1;32m - 32m + 91m +1;91m 2;32m -1;92m - 92m + 32m +1;32m 2;92m -1;33m - 33m + 92m +1;92m 2;33m -1;93m - 93m + 33m +1;33m 2;93m -1;34m - 34m + 93m +1;93m 2;34m -1;94m - 94m + 34m +1;34m 2;94m -1;35m - 35m + 94m +1;94m 2;35m -1;95m - 95m + 35m +1;35m 2;95m -1;36m - 36m + 95m +1;95m 2;36m -1;96m - 96m + 36m +1;36m 2;96m -1;37m - 37m + 96m +1;96m 2;37m -1;97m - 97m + 37m +1;37m 2;97m + 97m +1;97m __ROWS:END__ __DATA:END__ \ No newline at end of file diff --git a/src/tools/ansi-color/sgr.def b/src/tools/ansi-color/sgr.def index 6205e8c210a..4f0947dd562 100644 --- a/src/tools/ansi-color/sgr.def +++ b/src/tools/ansi-color/sgr.def @@ -60,6 +60,7 @@ __COLS__ 8m 9m 21m +#SPC# 40m 100m 41m @@ -91,6 +92,7 @@ __ROWS__ 8m 9m 21m +#SPC# :: Normal 30m 90m @@ -108,6 +110,7 @@ __ROWS__ 96m 37m 97m +#SPC# :: Bold or increased intensity, 1 1;30m 1;90m @@ -125,6 +128,7 @@ __ROWS__ 1;96m 1;37m 1;97m +#SPC# :: Faint (decreased intensity), 2 2;30m 2;90m @@ -142,6 +146,7 @@ __ROWS__ 2;96m 2;37m 2;97m +#SPC# :: Italic, 3 3;30m 3;90m @@ -159,6 +164,7 @@ __ROWS__ 3;96m 3;37m 3;97m +#SPC# :: Underline, 4 4;30m 4;90m @@ -176,6 +182,7 @@ __ROWS__ 4;96m 4;37m 4;97m +#SPC# :: Slow Blink, 5 5;30m 5;90m @@ -193,6 +200,7 @@ __ROWS__ 5;96m 5;37m 5;97m +#SPC# :: Rapid Blink, 6 6;30m 6;90m @@ -210,6 +218,7 @@ __ROWS__ 6;96m 6;37m 6;97m +#SPC# :: Reverse video, 7 7;30m 7;90m @@ -227,6 +236,7 @@ __ROWS__ 7;96m 7;37m 7;97m +#SPC# :: Conceal, 8 8;30m 8;90m @@ -244,6 +254,7 @@ __ROWS__ 8;96m 8;37m 8;97m +#SPC# :: Crossed-out, 9 9;30m 9;90m @@ -261,6 +272,7 @@ __ROWS__ 9;96m 9;37m 9;97m +#SPC# :: Double Underline, 21 21;30m 21;90m diff --git a/src/tools/ansi-color/tsgr.def b/src/tools/ansi-color/tsgr.def index 70cd133054e..9bd8ec4e0a0 100644 --- a/src/tools/ansi-color/tsgr.def +++ b/src/tools/ansi-color/tsgr.def @@ -62,6 +62,7 @@ __COLS__ 8m 9m 21m +#SPC# 40m 100m 41m @@ -94,6 +95,7 @@ __ROWS__ 9m 21m 30m +#SPC# 1;30m 2;30m 3;30m @@ -104,6 +106,7 @@ __ROWS__ 8;30m 9;30m 21;30m +#SPC# 90m 1;90m 2;90m @@ -115,6 +118,7 @@ __ROWS__ 8;90m 9;90m 21;90m +#SPC# 31m 1;31m 2;31m @@ -126,6 +130,7 @@ __ROWS__ 8;31m 9;31m 21;31m +#SPC# 91m 1;91m 2;91m @@ -137,6 +142,7 @@ __ROWS__ 8;91m 9;91m 21;91m +#SPC# 32m 1;32m 2;32m @@ -148,6 +154,7 @@ __ROWS__ 8;32m 9;32m 21;32m +#SPC# 92m 1;92m 2;92m @@ -159,6 +166,7 @@ __ROWS__ 8;92m 9;92m 21;92m +#SPC# 33m 1;33m 2;33m @@ -170,6 +178,7 @@ __ROWS__ 8;33m 9;33m 21;33m +#SPC# 93m 1;93m 2;93m @@ -181,6 +190,7 @@ __ROWS__ 8;93m 9;93m 21;93m +#SPC# 34m 1;34m 2;34m @@ -192,6 +202,7 @@ __ROWS__ 8;34m 9;34m 21;34m +#SPC# 94m 1;94m 2;94m @@ -203,6 +214,7 @@ __ROWS__ 8;94m 9;94m 21;94m +#SPC# 35m 1;35m 2;35m @@ -214,6 +226,7 @@ __ROWS__ 8;35m 9;35m 21;35m +#SPC# 95m 1;95m 2;95m @@ -225,6 +238,7 @@ __ROWS__ 8;95m 9;95m 21;95m +#SPC# 36m 1;36m 2;36m @@ -236,6 +250,7 @@ __ROWS__ 8;36m 9;36m 21;36m +#SPC# 96m 1;96m 2;96m @@ -247,6 +262,7 @@ __ROWS__ 8;96m 9;96m 21;96m +#SPC# 37m 1;37m 2;37m @@ -258,6 +274,7 @@ __ROWS__ 8;37m 9;37m 21;37m +#SPC# 97m 1;97m 2;97m From 972e298a274dad02b34afc030696256dee5ddae6 Mon Sep 17 00:00:00 2001 From: Ryan Beesley Date: Tue, 28 Dec 2021 16:05:54 -0800 Subject: [PATCH 13/35] Added ability to create labels for the table. Fixed a case where special tokens were interpreted as column width for the stub so now they are 0 width. This allows the labels to be inserted into the middle of the table without affecting the overall width. Added a new definition for showing attributes and a label definition to demonstrate how labels can be used. They follow the pattern used for ECHO so that #LBL#[.| ][TEXT] will output the same way ECHO does. #LBL# can also use CSI commands to format the label. #LBL# will automatically apply RESET at the end of a line to prevent inconsistency. --- src/tools/ansi-color/ansi-color.cmd | 98 +++++- src/tools/ansi-color/attrib.def | 425 +++++++++++++++++++++++++ src/tools/ansi-color/lbl.def | 64 ++++ src/tools/ansi-color/rainbow.def | 32 +- src/tools/ansi-color/sgr-intensity.def | 32 +- src/tools/ansi-color/sgr.def | 66 +++- src/tools/ansi-color/tsgr.def | 5 +- 7 files changed, 667 insertions(+), 55 deletions(-) create mode 100644 src/tools/ansi-color/attrib.def create mode 100644 src/tools/ansi-color/lbl.def diff --git a/src/tools/ansi-color/ansi-color.cmd b/src/tools/ansi-color/ansi-color.cmd index c9bcbb5cc0f..3f3b1e3e78b 100644 --- a/src/tools/ansi-color/ansi-color.cmd +++ b/src/tools/ansi-color/ansi-color.cmd @@ -40,9 +40,14 @@ __DATA__ :: or row, but there is no row or column value applied to the cell. :: This has the effect that the row or column has no SGR parameter applied :: and so this will show the default. -:: #SPC# is also a special case which can be used to make gaps in the table. +:: #SPC# is a special case which can be used to make gaps in the table. :: Whereas #NUL# still outputs the CELL text, #SPC# won't show anything in -:: that row. +:: that row. #SPC# can be used in columns to also provide a gap which matches +:: cell width. +:: #LBL# is also a special case similar to #SPC#. #LBL# makes it possible to +:: write a text label in the middle of a generated table for a particular row. +:: Formatting can be applied to the labels and an SGR RESET is automatically +:: applied at the end of the string. __TABLE__ :: If the definition is defined using Unicode characters, uncomment and include :: the following line in the __TABLE__ section of the definition file. @@ -89,6 +94,8 @@ REM SET "SEPARATOR.CELL=╎" & :: UTF-8 IF DEFINED SHOW.UTF8 (SET "SEPARATOR.STUBHEAD_BOXHEAD=│") ELSE (SET "SEPARATOR.STUBHEAD_BOXHEAD=:") IF DEFINED SHOW.UTF8 (SET "SEPARATOR.STUBHEAD_STUB=─") ELSE (SET "SEPARATOR.STUBHEAD_STUB=-") IF DEFINED SHOW.UTF8 (SET "SEPARATOR.INTERSECT=┘") ELSE (SET "SEPARATOR.INTERSECT=+") +:: You can also define control for formating +SET "SECTION=!CSI!1;4m" __TABLE:END__ :: Background @@ -125,6 +132,9 @@ __COLS:END__ :: [Intensity;][Attribute;]Foreground __ROWS__ #NUL# +#SPC# +:: Attributes +#LBL# !SECTION!Attributes 1m 2m 3m @@ -156,6 +166,7 @@ REM 28m REM 29m #SPC# :: Normal +#LBL# !SECTION!Normal 30m 90m 31m @@ -174,6 +185,7 @@ REM 29m 97m #SPC# :: Bold or increased intensity, 1 +#LBL# !SECTION!Bold or increased intensity, 1 1;30m 1;90m 1;31m @@ -192,6 +204,7 @@ REM 29m 1;97m #SPC# :: Faint (decreased intensity), 2 +#LBL# !SECTION!Faint (decreased intensity), 2 2;30m 2;90m 2;31m @@ -210,6 +223,7 @@ REM 29m 2;97m #SPC# :: Italic, 3 +#LBL# !SECTION!Italic, 3 3;30m 3;90m 3;31m @@ -228,6 +242,7 @@ REM 29m 3;97m #SPC# :: Underline, 4 +#LBL# !SECTION!Underline, 4 4;30m 4;90m 4;31m @@ -246,6 +261,7 @@ REM 29m 4;97m #SPC# :: Slow Blink, 5 +#LBL# !SECTION!Slow Blink, 5 5;30m 5;90m 5;31m @@ -264,6 +280,7 @@ REM 29m 5;97m #SPC# :: Rapid Blink, 6 +#LBL# !SECTION!Rapid Blink, 6 6;30m 6;90m 6;31m @@ -282,6 +299,7 @@ REM 29m 6;97m #SPC# :: Reverse video, 7 +#LBL# !SECTION!Reverse video, 7 7;30m 7;90m 7;31m @@ -300,6 +318,7 @@ REM 29m 7;97m #SPC# :: Conceal, 8 +#LBL# !SECTION!Conceal, 8 8;30m 8;90m 8;31m @@ -318,6 +337,7 @@ REM 29m 8;97m #SPC# :: Crossed-out, 9 +#LBL# !SECTION!Crossed-out, 9 9;30m 9;90m 9;31m @@ -336,6 +356,7 @@ REM 29m 9;97m #SPC# :: Double Underline, 21 +#LBL# !SECTION!Double Underline, 21 21;30m 21;90m 21;31m @@ -601,7 +622,16 @@ IF ERRORLEVEL 1 %@exit% %ERRORLEVEL% :PARSE_COLS_DATA SET "COL=%*" :: Set the column header text and track the max width -%@strlen% COL COL.LEN +IF ["!COL:~0,1!"] EQU ["#"] ( + IF ["!COL:~4,1!"] EQU ["#"] ( + :: Special case for #???# tokens + SET /A "COL.LEN=0" + ) ELSE ( + %@strlen% COL COL.LEN + ) +) ELSE ( + %@strlen% COL COL.LEN +) %@maxval% COL.MAX_WIDTH COL.LEN :: Set the col index and store value SET /A COL[#]+=1 @@ -612,7 +642,16 @@ SET "COL[!COL[#]!]=!COL!" :PARSE_ROWS_DATA SET "ROW=%*" :: Set the row header text -%@strlen% ROW ROW.LEN +IF ["!ROW:~0,1!"] EQU ["#"] ( + IF ["!ROW:~4,1!"] EQU ["#"] ( + :: Special case for #???# tokens + SET /A "ROW.LEN=0" + ) ELSE ( + %@strlen% ROW ROW.LEN + ) +) ELSE ( + %@strlen% ROW ROW.LEN +) %@maxval% STUB.MAX_WIDTH ROW.LEN :: Set the row index and store value SET /A ROW[#]+=1 @@ -892,9 +931,21 @@ FOR /L %%r IN (1,1,!ROW[#]!) DO ( ) ) - IF /I ["!ROW!"] EQU ["#SPC#"] ( + IF /I ["!ROW:~0,5!"] EQU ["#SPC#"] ( :: We want a special case for #SPC# so that we print a blank line SET "LINE=" + ) ELSE IF /I ["!ROW:~0,5!"] EQU ["#LBL#"] ( + :: We want a special case for #LBL# so that we print the string which follows and append an SGR RESET + IF /I ["!ROW:~5,1!"] EQU [" "] ( + :: Allow for a space to follow #LBL# + SET "LINE=!ROW:~6!!RESET!" + ) ELSE IF /I ["!ROW:~5,1!"] EQU ["."] ( + :: Allow for a period to follow #LBL# and treat it like space, to mimic ECHO + SET "LINE=!ROW:~6!!RESET!" + ) ELSE ( + :: Assume that any other character is part of the label + SET "LINE=!ROW:~5!!RESET!" + ) ) ELSE ( :: Otherwise process the line SET "LINE=!ROW.VALUE!!SEPARATOR!" @@ -974,15 +1025,21 @@ SETLOCAL DISABLEDELAYEDEXPANSION :: :: Computes the length of string in variable StrVar :: and stores the result in variable RtnVar. -:: If StrVar is #NUL#, this should be 0 width. -:: If StrVar is #SPC#, this should empty padding. +:: If StrVar is #SPC#, the return val should be 1. +:: If StrVar is any other Special Token, the return val should be 0. :: If RtnVar is not specified, then print the length to stdout. :: SET @strlen=FOR %%. IN (1 2) DO IF [%%.] EQU [2] (%\n% FOR /F "tokens=1,2 delims=, " %%1 IN ("!argv!") DO ( ENDLOCAL%\n% SET "s=A!%%~1!"%\n% - SET "s=!s:#NUL#=!"%\n% - SET "s=!s:#SPC#= !"%\n% + IF /I ["!s:~0,5!"] EQU ["#SPC#"] (%\n% + SET "s= "%\n% + ) ELSE IF /I ["!s:~0,1!"] EQU ["#"] (%\n% + IF /I ["!s:~4,1!"] EQU ["#"] (%\n% + :: Look for Special Tokens of the form #???# %\n% + SET "s="%\n% + )%\n% + )%\n% SET "len=0"%\n% FOR %%P in (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) DO (%\n% IF ["!s:~%%P,1!"] NEQ [""] (%\n% @@ -1016,15 +1073,21 @@ SET @maxval=FOR %%. IN (1 2) DO IF [%%.] EQU [2] (%\n% :: @repeat StrVal Count [RetVar] :: :: Repeats StrVal, Count times, and assigns to RetVar. -:: If StrVar is #NUL#, this should empty padding. :: If StrVar is #SPC#, this should empty padding. +:: If StrVar is any other Special Token, this should be empty. :: If RtnVar is not specified, then print the output string to stdout. :: SET @repeat=FOR %%. IN (1 2) DO IF [%%.] EQU [2] (%\n% FOR /F "tokens=1,2,3 delims=, " %%1 IN ("!argv!") DO ( ENDLOCAL%\n% IF [!%%~1!] NEQ [] (SET "s=!%%~1!") ELSE (SET "s=%%~1")%\n% - SET "s=!s:#NUL#= !"%\n% - SET "s=!s:#SPC#= !"%\n% + IF /I ["!s:~0,5!"] EQU ["#SPC#"] (%\n% + SET "s= "%\n% + ) ELSE IF /I ["!s:~0,1!"] EQU ["#"] (%\n% + IF /I ["!s:~4,1!"] EQU ["#"] (%\n% + :: Look for Special Tokens of the form #???# %\n% + SET "s="%\n% + )%\n% + )%\n% SET "count=%%~2"%\n% SET "outstr="%\n% FOR /L %%. IN (1,1,!count!) DO SET "outstr=!outstr!!s!"%\n% @@ -1125,15 +1188,18 @@ SET @trim=FOR %%. IN (1 2) DO IF [%%.] EQU [2] (%\n% :: Aligns the string in variable StrVar :: in the field using the Width and Alignment provided :: and stores the result in variable RtnVar. -:: If StrVar is #NUL#, this should empty padding. -:: If StrVar is #SPC#, this should empty padding. +:: If StrVar is a Special Token, it is treated as a space. :: If RtnVar is not specified, then print the output to stdout. :: SET @align=FOR %%. IN (1 2) DO IF [%%.] EQU [2] (%\n% FOR /F "tokens=1,2,3,4 delims=, " %%1 IN ("!argv!") DO ( ENDLOCAL%\n% IF ["!%%~1!"] NEQ [""] (SET "strVar=!%%~1!") ELSE (SET "strVar=%%~1")%\n% - SET "strVar=!strVar:#NUL#= !"%\n% - SET "strVar=!strVar:#SPC#= !"%\n% + IF /I ["!strVar:~0,1!"] EQU ["#"] (%\n% + IF /I ["!strVar:~4,1!"] EQU ["#"] (%\n% + :: Look for Special Tokens of the form #???# %\n% + SET "strVar= "%\n% + )%\n% + )%\n% IF ["!%%~2!"] NEQ [""] (SET "width=!%%~2!") ELSE (SET "width=%%~2")%\n% SET "alignment=%%~3"%\n% IF ["!%%~4!"] NEQ [""] (SET "%%~4=")%\n% diff --git a/src/tools/ansi-color/attrib.def b/src/tools/ansi-color/attrib.def new file mode 100644 index 00000000000..871e6839797 --- /dev/null +++ b/src/tools/ansi-color/attrib.def @@ -0,0 +1,425 @@ +:: Apply all known implemented attributes to see the effect of multiple attributes against all foreground and background colors +__DATA__ +__TABLE__ +:: The test text +SET "CELL= gYw " +SET "STUBHEAD=Attributes" +:: Alignment properties for the cells and headers +SET "ALIGN.CELL=C" +SET "ALIGN.BOXHEAD=C" +SET "ALIGN.STUB=R" +:: Table spacing +SET "SEPARATOR.CELL= " +SET "SEPARATOR.STUB= " +__TABLE:END__ +__COLS__ +#NUL# + 1m + 2m + 3m + 4m + 5m + 6m + 7m + 8m + 9m + 21m +__COLS:END__ +__ROWS__ +#NUL# + 1m + 2m + 3m + 4m + 5m + 6m + 7m + 8m + 9m + 21m +#SPC# + 30m + 1;30m + 2;30m + 3;30m + 4;30m + 5;30m + 6;30m + 7;30m + 8;30m + 9;30m + 21;30m +#SPC# + 31m + 1;31m + 2;31m + 3;31m + 4;31m + 5;31m + 6;31m + 7;31m + 8;31m + 9;31m + 21;31m +#SPC# + 32m + 1;32m + 2;32m + 3;32m + 4;32m + 5;32m + 6;32m + 7;32m + 8;32m + 9;32m + 21;32m +#SPC# + 33m + 1;33m + 2;33m + 3;33m + 4;33m + 5;33m + 6;33m + 7;33m + 8;33m + 9;33m + 21;33m +#SPC# + 34m + 1;34m + 2;34m + 3;34m + 4;34m + 5;34m + 6;34m + 7;34m + 8;34m + 9;34m + 21;34m +#SPC# + 35m + 1;35m + 2;35m + 3;35m + 4;35m + 5;35m + 6;35m + 7;35m + 8;35m + 9;35m + 21;35m +#SPC# + 36m + 1;36m + 2;36m + 3;36m + 4;36m + 5;36m + 6;36m + 7;36m + 8;36m + 9;36m + 21;36m +#SPC# + 37m + 1;37m + 2;37m + 3;37m + 4;37m + 5;37m + 6;37m + 7;37m + 8;37m + 9;37m + 21;37m +#SPC# + 40m + 1;40m + 2;40m + 3;40m + 4;40m + 5;40m + 6;40m + 7;40m + 8;40m + 9;40m + 21;40m +#SPC# + 41m + 1;41m + 2;41m + 3;41m + 4;41m + 5;41m + 6;41m + 7;41m + 8;41m + 9;41m + 21;41m +#SPC# + 42m + 1;42m + 2;42m + 3;42m + 4;42m + 5;42m + 6;42m + 7;42m + 8;42m + 9;42m + 21;42m +#SPC# + 43m + 1;43m + 2;43m + 3;43m + 4;43m + 5;43m + 6;43m + 7;43m + 8;43m + 9;43m + 21;43m +#SPC# + 44m + 1;44m + 2;44m + 3;44m + 4;44m + 5;44m + 6;44m + 7;44m + 8;44m + 9;44m + 21;44m +#SPC# + 45m + 1;45m + 2;45m + 3;45m + 4;45m + 5;45m + 6;45m + 7;45m + 8;45m + 9;45m + 21;45m +#SPC# + 46m + 1;46m + 2;46m + 3;46m + 4;46m + 5;46m + 6;46m + 7;46m + 8;46m + 9;46m + 21;46m +#SPC# + 47m + 1;47m + 2;47m + 3;47m + 4;47m + 5;47m + 6;47m + 7;47m + 8;47m + 9;47m + 21;47m +#SPC# + 90m + 1;90m + 2;90m + 3;90m + 4;90m + 5;90m + 6;90m + 7;90m + 8;90m + 9;90m + 21;90m +#SPC# + 91m + 1;91m + 2;91m + 3;91m + 4;91m + 5;91m + 6;91m + 7;91m + 8;91m + 9;91m + 21;91m +#SPC# + 92m + 1;92m + 2;92m + 3;92m + 4;92m + 5;92m + 6;92m + 7;92m + 8;92m + 9;92m + 21;92m +#SPC# + 93m + 1;93m + 2;93m + 3;93m + 4;93m + 5;93m + 6;93m + 7;93m + 8;93m + 9;93m + 21;93m +#SPC# + 94m + 1;94m + 2;94m + 3;94m + 4;94m + 5;94m + 6;94m + 7;94m + 8;94m + 9;94m + 21;94m +#SPC# + 95m + 1;95m + 2;95m + 3;95m + 4;95m + 5;95m + 6;95m + 7;95m + 8;95m + 9;95m + 21;95m +#SPC# + 96m + 1;96m + 2;96m + 3;96m + 4;96m + 5;96m + 6;96m + 7;96m + 8;96m + 9;96m + 21;96m +#SPC# + 97m + 1;97m + 2;97m + 3;97m + 4;97m + 5;97m + 6;97m + 7;97m + 8;97m + 9;97m + 21;97m +#SPC# + 100m + 1;100m + 2;100m + 3;100m + 4;100m + 5;100m + 6;100m + 7;100m + 8;100m + 9;100m +21;100m +#SPC# + 101m + 1;101m + 2;101m + 3;101m + 4;101m + 5;101m + 6;101m + 7;101m + 8;101m + 9;101m +21;101m +#SPC# + 102m + 1;102m + 2;102m + 3;102m + 4;102m + 5;102m + 6;102m + 7;102m + 8;102m + 9;102m +21;102m +#SPC# + 103m + 1;103m + 2;103m + 3;103m + 4;103m + 5;103m + 6;103m + 7;103m + 8;103m + 9;103m +21;103m +#SPC# + 104m + 1;104m + 2;104m + 3;104m + 4;104m + 5;104m + 6;104m + 7;104m + 8;104m + 9;104m +21;104m +#SPC# + 105m + 1;105m + 2;105m + 3;105m + 4;105m + 5;105m + 6;105m + 7;105m + 8;105m + 9;105m +21;105m +#SPC# + 106m + 1;106m + 2;106m + 3;106m + 4;106m + 5;106m + 6;106m + 7;106m + 8;106m + 9;106m +21;106m +#SPC# + 107m + 1;107m + 2;107m + 3;107m + 4;107m + 5;107m + 6;107m + 7;107m + 8;107m + 9;107m +21;107m +__ROWS:END__ +__DATA:END__ \ No newline at end of file diff --git a/src/tools/ansi-color/lbl.def b/src/tools/ansi-color/lbl.def new file mode 100644 index 00000000000..915e1061ca1 --- /dev/null +++ b/src/tools/ansi-color/lbl.def @@ -0,0 +1,64 @@ +:: Demonstrates how to use the #LBL# feature for definition files +:: Requires 107 columns +__DATA__ +__TABLE__ +:: The test text +SET "CELL= gYw " +REM SET "SPINNER.DISABLED=#TRUE#" +:: Alignment properties for the cells and headers +SET "ALIGN.CELL=C" +SET "ALIGN.BOXHEAD=C" +SET "ALIGN.STUB=L" +:: Table spacing +SET "SEPARATOR.CELL= " +SET "SEPARATOR.STUB= " +:: Formatting +SET "INV=!CSI!7m" +SET "HIGH=!CSI!1m" +SET "LOW=!CSI!2m" +__TABLE:END__ +__COLS__ +#NUL# +40m +41m +42m +43m +44m +45m +46m +47m +100m +101m +102m +103m +104m +105m +106m +107m +__COLS:END__ +__ROWS__ +#LBL# NUL: +#NUL# +#LBL#.SPC: +#SPC# +#LBL# !INV!Foreground +#LBL#. !LOW!Low Intensity +30m +31m +32m +33m +34m +35m +36m +37m +#LBL# !HIGH!High Intensity +90m +91m +92m +93m +94m +95m +96m +97m +__ROWS:END__ +__DATA:END__ \ No newline at end of file diff --git a/src/tools/ansi-color/rainbow.def b/src/tools/ansi-color/rainbow.def index 50a1bbae6e2..78cac9edbfa 100644 --- a/src/tools/ansi-color/rainbow.def +++ b/src/tools/ansi-color/rainbow.def @@ -16,17 +16,17 @@ __COLS__ 40m 47m 41m -45m -44m -46m -42m 43m +42m +46m +44m +45m 101m -105m -104m -106m -102m 103m +102m +106m +104m +105m 100m 107m __COLS:END__ @@ -35,17 +35,17 @@ __ROWS__ 30m 37m 31m -35m -34m -36m -32m 33m +32m +36m +34m +35m 91m -95m -94m -96m -92m 93m +92m +96m +94m +95m 90m 97m __ROWS:END__ diff --git a/src/tools/ansi-color/sgr-intensity.def b/src/tools/ansi-color/sgr-intensity.def index bc188d09334..c7095c9184b 100644 --- a/src/tools/ansi-color/sgr-intensity.def +++ b/src/tools/ansi-color/sgr-intensity.def @@ -1,4 +1,4 @@ -:: Check SGR intensity attributes, requires 100 columns +:: Check SGR intensity attributes, requires 110 columns __DATA__ __TABLE__ :: The test text @@ -43,6 +43,8 @@ __TABLE:END__ :: Background __COLS__ +49m +#SPC# #NUL# 40m 100m @@ -64,12 +66,13 @@ __COLS:END__ :: [Intensity;][Attribute;]Foreground __ROWS__ -:: Attributes -2m -#NUL# -1m +:: Default +#LBL# Default +39m #SPC# :: Normal +#LBL# Normal +#NUL# 30m 90m 31m @@ -87,9 +90,24 @@ __ROWS__ 37m 97m #SPC# -:: Bold or increased intensity, 1 -:: Normal +:: Attributes +#LBL# Attributes +2m +#NUL# +1m +#SPC# :: Faint (decreased intensity), 2 +:: Normal +:: Bold or increased intensity, 1 +#LBL# Applied !CSI!2mdecreased!RESET! intensity +#LBL# Normal +#LBL# Applied !CSI!1mincreased!RESET! intensity +2;39m + 39m +1;39m + 2m +#NUL# + 1m 2;30m 30m 1;30m diff --git a/src/tools/ansi-color/sgr.def b/src/tools/ansi-color/sgr.def index 4f0947dd562..85cfd5e31f7 100644 --- a/src/tools/ansi-color/sgr.def +++ b/src/tools/ansi-color/sgr.def @@ -1,13 +1,21 @@ :: Complete matrix of SGR parameters available :: This definition also demonstrates the various configuration changes :: which are used to control the way the table is generated -:: Requires 142 columns to display correctly +:: Requires 92 columns to display correctly __DATA__ :: Select Graphic Rendition (SGR) parameters :: #NUL# is treated as a special case to provide cells in that column :: or row, but there is no row or column value applied to the cell. :: This has the effect that the row or column has no SGR parameter applied :: and so this will show the default. +:: #SPC# is a special case which can be used to make gaps in the table. +:: Whereas #NUL# still outputs the CELL text, #SPC# won't show anything in +:: that row. #SPC# can be used in columns to also provide a gap which matches +:: cell width. +:: #LBL# is also a special case similar to #SPC#. #LBL# makes it possible to +:: write a text label in the middle of a generated table for a particular row. +:: Formatting can be applied to the labels and an SGR RESET is automatically +:: applied at the end of the string. __TABLE__ SET "UTF8.REQUIRED=#TRUE#" :: The test text @@ -45,22 +53,23 @@ REM SET "SEPARATOR.BOXHEADERS= " REM SET "SEPARATOR.BOXHEADERS=╎" REM SET "SEPARATOR.CELL= " REM SET "SEPARATOR.CELL=╎" +:: Formatting for labels +SET "SECTION=!CSI!1;4m" __TABLE:END__ :: Background __COLS__ #NUL# -1m -2m -3m -4m -5m -6m -7m -8m -9m -21m -#SPC# +REM 1m +REM 2m +REM 3m +REM 4m +REM 5m +REM 6m +REM 7m +REM 8m +REM 9m +REM 21m 40m 100m 41m @@ -82,6 +91,9 @@ __COLS:END__ :: [Intensity;][Attribute;]Foreground __ROWS__ #NUL# +#SPC# +:: Attributes +#LBL# !SECTION!Attributes 1m 2m 3m @@ -91,9 +103,29 @@ __ROWS__ 7m 8m 9m +REM 10m +REM 11m +REM 12m +REM 13m +REM 14m +REM 15m +REM 16m +REM 17m +REM 18m +REM 19m +REM 20m 21m +REM 22m +REM 23m +REM 24m +REM 25m +REM 26m +REM 27m +REM 28m +REM 29m #SPC# :: Normal +#LBL# !SECTION!Normal 30m 90m 31m @@ -112,6 +144,7 @@ __ROWS__ 97m #SPC# :: Bold or increased intensity, 1 +#LBL# !SECTION!Bold or increased intensity, 1 1;30m 1;90m 1;31m @@ -130,6 +163,7 @@ __ROWS__ 1;97m #SPC# :: Faint (decreased intensity), 2 +#LBL# !SECTION!Faint (decreased intensity), 2 2;30m 2;90m 2;31m @@ -148,6 +182,7 @@ __ROWS__ 2;97m #SPC# :: Italic, 3 +#LBL# !SECTION!Italic, 3 3;30m 3;90m 3;31m @@ -166,6 +201,7 @@ __ROWS__ 3;97m #SPC# :: Underline, 4 +#LBL# !SECTION!Underline, 4 4;30m 4;90m 4;31m @@ -184,6 +220,7 @@ __ROWS__ 4;97m #SPC# :: Slow Blink, 5 +#LBL# !SECTION!Slow Blink, 5 5;30m 5;90m 5;31m @@ -202,6 +239,7 @@ __ROWS__ 5;97m #SPC# :: Rapid Blink, 6 +#LBL# !SECTION!Rapid Blink, 6 6;30m 6;90m 6;31m @@ -220,6 +258,7 @@ __ROWS__ 6;97m #SPC# :: Reverse video, 7 +#LBL# !SECTION!Reverse video, 7 7;30m 7;90m 7;31m @@ -238,6 +277,7 @@ __ROWS__ 7;97m #SPC# :: Conceal, 8 +#LBL# !SECTION!Conceal, 8 8;30m 8;90m 8;31m @@ -256,6 +296,7 @@ __ROWS__ 8;97m #SPC# :: Crossed-out, 9 +#LBL# !SECTION!Crossed-out, 9 9;30m 9;90m 9;31m @@ -274,6 +315,7 @@ __ROWS__ 9;97m #SPC# :: Double Underline, 21 +#LBL# !SECTION!Double Underline, 21 21;30m 21;90m 21;31m diff --git a/src/tools/ansi-color/tsgr.def b/src/tools/ansi-color/tsgr.def index 9bd8ec4e0a0..24dde7328e8 100644 --- a/src/tools/ansi-color/tsgr.def +++ b/src/tools/ansi-color/tsgr.def @@ -3,12 +3,9 @@ :: per foreground color instead of incrementing on the attributes :: ForEach(fg in Foreground) { ForEach(a in Attribute) { a;fm }} instead of :: ForEach(a in Attribute) { ForEach(fg in Foreground) { a;fm }} +:: Requires 147 columns __DATA__ :: Select Graphic Rendition (SGR) parameters -:: #NUL# is treated as a special case to provide cells in that column -:: or row, but there is no row or column value applied to the cell. -:: This has the effect that the row or column has no SGR parameter applied -:: and so this will show the default. __TABLE__ SET "UTF8.REQUIRED=#TRUE#" :: The test text From 8ad9cc19bee62614f4631176c1521e1c95d618e7 Mon Sep 17 00:00:00 2001 From: Ryan Beesley Date: Tue, 28 Dec 2021 17:08:27 -0800 Subject: [PATCH 14/35] check-spelling-bot update to conform Added: mdecreased mincreased Removed: adaa coffgroup coffgrp datetime eae emplate GENPROFILE HHmm Hostx installationpath MMdd pgorepro pgort PGU Relayout Moved additional words from previous checkins to appropriate files --- ...5c1ec487b80f127ca611d10b973f66d9ed6812.txt | 29 --------------- .github/actions/spelling/expect/expect.txt | 35 +++++++++++-------- .github/actions/spelling/expect/web.txt | 9 +++++ .../actions/spelling/patterns/patterns.txt | 1 + 4 files changed, 30 insertions(+), 44 deletions(-) delete mode 100644 .github/actions/spelling/expect/205c1ec487b80f127ca611d10b973f66d9ed6812.txt diff --git a/.github/actions/spelling/expect/205c1ec487b80f127ca611d10b973f66d9ed6812.txt b/.github/actions/spelling/expect/205c1ec487b80f127ca611d10b973f66d9ed6812.txt deleted file mode 100644 index 0252bd5aac8..00000000000 --- a/.github/actions/spelling/expect/205c1ec487b80f127ca611d10b973f66d9ed6812.txt +++ /dev/null @@ -1,29 +0,0 @@ -askubuntu -BIV -boxheader -colortest -Crisman -DISABLEDELAYEDEXPANSION -dostips -dpnx -Dyreen -EINS -EQU -FGs -forground -GTR -HOWTO -ltrim -maxval -outstr -Rexx -rosettacode -ROY -Rtn -rtrim -STUBHEAD -tldp -uwaterloo -uwspace -viewtopic -wrkstr diff --git a/.github/actions/spelling/expect/expect.txt b/.github/actions/spelling/expect/expect.txt index 35da0d7949b..d2708f1964d 100644 --- a/.github/actions/spelling/expect/expect.txt +++ b/.github/actions/spelling/expect/expect.txt @@ -12,7 +12,6 @@ ACTCTXW activatable ACTIVEBORDER ACTIVECAPTION -adaa ADDALIAS ADDREF addressof @@ -161,6 +160,7 @@ Borland BOTTOMLEFT BOTTOMRIGHT boutput +boxheader BPBF bpp BPPF @@ -287,8 +287,6 @@ codepage codepath codepoint codeproject -coffgroup -coffgrp coinit COLLECTIONURI colorizing @@ -299,6 +297,7 @@ colorspaces colorspec colortable colortbl +colortest colortool COLR combaseapi @@ -402,6 +401,7 @@ creativecommons cred cref crend +Crisman CRLFs crloew Crt @@ -480,7 +480,6 @@ dai DATABLOCK DATAVIEW DATAW -datetime DBatch dbcs DBCSCHAR @@ -610,6 +609,7 @@ DINLINE directio DIRECTX Dirs +DISABLEDELAYEDEXPANSION DISABLENOSCROLL DISPLAYATTRIBUTE DISPLAYATTRIBUTEPROPERTY @@ -641,6 +641,7 @@ DPICHANGE DPICHANGED dpix dpiy +dpnx DRAWFRAME DRAWITEM DRAWITEMSTRUCT @@ -672,8 +673,8 @@ dxgidwm dxinterop dxsm dxttbmp +Dyreen eachother -eae eaf EASTEUROPE ECH @@ -688,13 +689,13 @@ edputil edu Efast EHsc +EINS EJO ELEMENTNOTAVAILABLE elems elif elseif emacs -emplate EMPTYBOX enabledelayedexpansion endian @@ -714,6 +715,7 @@ enumranges envvar eol EPres +EQU ERASEBKGND errno errorlevel @@ -768,6 +770,7 @@ fgetc fgetwc FGHIJ fgidx +FGs FILEDESCRIPTION fileno filepath @@ -821,6 +824,7 @@ FORCEOFFFEEDBACK FORCEONFEEDBACK FORCEV foreach +forground fprintf framebuffer FRAMECHANGED @@ -853,7 +857,6 @@ gcy gdi gdip gdirenderer -GENPROFILE geopol GETALIAS GETALIASES @@ -938,6 +941,7 @@ groupbox gset gsl GTP +GTR guc gui guidatom @@ -972,7 +976,6 @@ hfont hfontresource hglobal hhh -HHmm hhook hhx HIBYTE @@ -1002,7 +1005,6 @@ horiz HORZ hostable hostlib -Hostx HPA HPAINTBUFFER HPCON @@ -1129,7 +1131,6 @@ INPUTPROCESSORPROFILE inputrc Inputreadhandledata INSERTMODE -installationpath intellisense INTERACTIVITYBASE INTERCEPTCOPYPASTE @@ -1358,6 +1359,7 @@ lstrcmp lstrcmpi LTEXT LTLTLTLTL +ltrim ltype LUID lval @@ -1384,6 +1386,7 @@ MAXDIMENSTRING maxing MAXLENGTH MAXSHORT +maxval maxversiontested MAXWORD maybenull @@ -1392,6 +1395,7 @@ MBUTTONDBLCLK MBUTTONDOWN MBUTTONUP Mbxy +mdecreased mdmerge MDs MEASUREITEM @@ -1417,6 +1421,7 @@ MIIM milli mimetype mincore +mincreased mindbogglingly mingw minimizeall @@ -1429,7 +1434,6 @@ mkdir MMBB mmcc MMCPL -MMdd mmsystem MNC MNOPQ @@ -1687,6 +1691,7 @@ OUTOFCONTEXT OUTOFMEMORY outout Outptr +outstr OVERLAPPEDWINDOW OWNDC OWNERDRAWFIXED @@ -1763,9 +1768,6 @@ PFONTENUMDATA PFS pgd pgdn -pgorepro -pgort -PGU pguid pgup PHANDLE @@ -1982,7 +1984,6 @@ REGISTERVDM regkey REGSTR reingest -Relayout RELBINPATH remoting renamer @@ -2045,6 +2046,8 @@ rtf RTFTo Rtl RTLREADING +Rtn +rtrim RTTI ruleset runas @@ -2260,6 +2263,7 @@ strrev strsafe strtok structs +STUBHEAD STUVWX STX stylecop @@ -2769,6 +2773,7 @@ WRITECONSOLE WRITECONSOLEINPUT WRITECONSOLEOUTPUT WRITECONSOLEOUTPUTSTRING +wrkstr wrl wrp WRunoff diff --git a/.github/actions/spelling/expect/web.txt b/.github/actions/spelling/expect/web.txt index 826edf1af8e..4b95ef2e627 100644 --- a/.github/actions/spelling/expect/web.txt +++ b/.github/actions/spelling/expect/web.txt @@ -17,3 +17,12 @@ mdtauk cppreference gfycat Guake +askubuntu +dostips +viewtopic +rosettacode +Rexx +tldp +HOWTO +uwspace +uwaterloo diff --git a/.github/actions/spelling/patterns/patterns.txt b/.github/actions/spelling/patterns/patterns.txt index 2e89f5e253e..3c7d83aeb25 100644 --- a/.github/actions/spelling/patterns/patterns.txt +++ b/.github/actions/spelling/patterns/patterns.txt @@ -25,3 +25,4 @@ std::memory_order_[\w]+ D2DERR_SHADER_COMPILE_FAILED TIL_FEATURE_[0-9A-Z_]+ vcvars\w* +ROY\sG\.\sBIV \ No newline at end of file From 8a24e7ef2b548a7bcb1e1000f1a50bc4470ada1a Mon Sep 17 00:00:00 2001 From: Ryan Beesley Date: Sun, 12 Dec 2021 21:07:30 -0800 Subject: [PATCH 15/35] Add ansi-color.cmd tool and several definitions --- src/tools/ansi-color/ansi-color.cmd | 1410 +++++++++++++++++++++++ src/tools/ansi-color/ansi-colortool.def | 53 + src/tools/ansi-color/colortest.def | 52 + src/tools/ansi-color/colortool.def | 45 + src/tools/ansi-color/crisman.def | 78 ++ src/tools/ansi-color/plaid.def | 54 + src/tools/ansi-color/rainbow.def | 52 + src/tools/ansi-color/rosetta.def | 40 + src/tools/ansi-color/sgr-intensity.def | 142 +++ src/tools/ansi-color/sgr.def | 282 +++++ src/tools/ansi-color/tsgr.def | 273 +++++ src/tools/ansi-color/ubuntu.def | 41 + 12 files changed, 2522 insertions(+) create mode 100644 src/tools/ansi-color/ansi-color.cmd create mode 100644 src/tools/ansi-color/ansi-colortool.def create mode 100644 src/tools/ansi-color/colortest.def create mode 100644 src/tools/ansi-color/colortool.def create mode 100644 src/tools/ansi-color/crisman.def create mode 100644 src/tools/ansi-color/plaid.def create mode 100644 src/tools/ansi-color/rainbow.def create mode 100644 src/tools/ansi-color/rosetta.def create mode 100644 src/tools/ansi-color/sgr-intensity.def create mode 100644 src/tools/ansi-color/sgr.def create mode 100644 src/tools/ansi-color/tsgr.def create mode 100644 src/tools/ansi-color/ubuntu.def diff --git a/src/tools/ansi-color/ansi-color.cmd b/src/tools/ansi-color/ansi-color.cmd new file mode 100644 index 00000000000..b9e8641b5ed --- /dev/null +++ b/src/tools/ansi-color/ansi-color.cmd @@ -0,0 +1,1410 @@ +@ECHO OFF +GOTO :DEFINE_MACROS + +%=- Entry point after macro definitions -=% +:MAIN +SETLOCAL ENABLEDELAYEDEXPANSION +CALL :PARSE_ARGS %1 %2 %3 %4 %5 %6 %7 %8 %9 +IF ERRORLEVEL 1 %@exit% %ERRORLEVEL% + +REM ::Debug -- Use this to break after parsing arguments +REM CMD /C EXIT -1073741510 + + +%=- Configuration -=% +:: Default test text if not defined in the data segment +SET "CELL= gYw " +:: Uncomment to use UTF-8 for output, such as when the test text is Unicode +REM SET "SHOW.UTF8=#TRUE#" +:: Uncomment to disable the spinner and speed up processing +REM SET "SPINNER.DISABLED=#TRUE#" +:: Uncomment to display the ANSI Escape Sequence control characters +REM SET "SHOW.ANSI=#TRUE#" +:: Uncomment to show cell R1C1 reference addressing instead of cell text +REM SET "SHOW.R1C1_REFERENCE=#TRUE#" +:: Uncomment to turn on debug output for diagnosing separator resolution +REM SET "DEBUG.OUT=#TRUE#" +%=- End Configuration -=% + + +%=- Data Segment -=% +GOTO :END_DATA_SEGMENT + +:: Complete matrix of SGR parameters available +:: This definition also demonstrates the various configuration changes +:: which are used to control the way the table is generated +__DATA__ +:: Select Graphic Rendition (SGR) parameters +:: #NUL# is treated as a special case to provide cells in that column +:: or row, but there is no row or column value applied to the cell. +:: This has the effect that the row or column has no SGR parameter applied +:: and so this will show the default. +:: #SPC# is also a special case which can be used to make gaps in the table. +:: Whereas #NUL# still outputs the CELL text, #SPC# won't show anything in +:: that row. +__TABLE__ +:: If the definition is defined using Unicode characters, uncomment and include +:: the following line in the __TABLE__ section of the definition file. +REM SET "UTF8.REQUIRED=#TRUE#" +:: The test text +SET "STUBHEAD=SGR" +:: Alignment properties for the cells and headers +REM SET "ALIGN.CELL=C" +REM SET "ALIGN.BOXHEAD=R" +REM SET "ALIGN.STUB=L" +REM SET "ALIGN.STUBHEAD=C" +:: Separator characters for cells and headers +REM SET "SEPARATOR.STUB= " +REM SET "SEPARATOR.STUB=│" & :: UTF-8 +REM SET "SEPARATOR.BOXHEAD= " +REM SET "SEPARATOR.BOXHEAD=─" & :: UTF-8 +SET "SEPARATOR.COL= " +REM SET "SEPARATOR.COL=╎" +REM SET "SEPARATOR.STUBHEAD_BOXHEAD= " +REM SET "SEPARATOR.STUBHEAD_BOXHEAD=:" +REM SET "SEPARATOR.STUBHEAD_BOXHEAD=│" & :: UTF-8 +REM SET "SEPARATOR.STUBHEAD_BOXHEAD=▓▓" & :: UTF-8 +REM SET "SEPARATOR.STUBHEAD_STUB= " +REM SET "SEPARATOR.STUBHEAD_STUB=-" +REM SET "SEPARATOR.STUBHEAD_STUB=─" & :: UTF-8 +REM SET "SEPARATOR.STUBHEAD_STUB=▓" & :: UTF-8 +REM SET "SEPARATOR.INTERSECT= " +REM SET "SEPARATOR.INTERSECT=┼" & :: UTF-8 +REM SET "SEPARATOR.INTERSECT=┘" & :: UTF-8 +REM SET "SEPARATOR.INTERSECT=▓▒▒░" & :: UTF-8 +REM SET "SEPARATOR.INTERSECT=+" +REM SET "SEPARATOR.BOXHEAD_BODY= " +REM SET "SEPARATOR.BOXHEAD_BODY=─" & :: UTF-8 +REM SET "SEPARATOR.BOXHEAD_BODY=░" & :: UTF-8 +REM SET "SEPARATOR.STUB_BODY= " +REM SET "SEPARATOR.STUB_BODY=│" & :: UTF-8 +REM SET "SEPARATOR.STUB_BODY=░░" & :: UTF-8 +REM SET "SEPARATOR.BOXHEADERS= " +REM SET "SEPARATOR.BOXHEADERS=╎" & :: UTF-8 +REM SET "SEPARATOR.CELL= " +REM SET "SEPARATOR.CELL=╎" & :: UTF-8 +:: Conditional definitions like this must be one line per statement +:: and can be used to define how to fall back to ANSI if Unicode isn't supported +IF DEFINED SHOW.UTF8 (SET "SEPARATOR.STUBHEAD_BOXHEAD=│") ELSE (SET "SEPARATOR.STUBHEAD_BOXHEAD=:") +IF DEFINED SHOW.UTF8 (SET "SEPARATOR.STUBHEAD_STUB=─") ELSE (SET "SEPARATOR.STUBHEAD_STUB=-") +IF DEFINED SHOW.UTF8 (SET "SEPARATOR.INTERSECT=┘") ELSE (SET "SEPARATOR.INTERSECT=+") +__TABLE:END__ + +:: Background +__COLS__ +#NUL# +REM 1m +REM 2m +REM 3m +REM 4m +REM 5m +REM 6m +REM 7m +REM 8m +REM 9m +REM 21m +40m +100m +41m +101m +42m +102m +43m +103m +44m +104m +45m +105m +46m +106m +47m +107m +__COLS:END__ + +:: [Intensity;][Attribute;]Foreground +__ROWS__ +#NUL# +1m +2m +3m +4m +5m +6m +7m +8m +9m +REM 10m +REM 11m +REM 12m +REM 13m +REM 14m +REM 15m +REM 16m +REM 17m +REM 18m +REM 19m +REM 20m +21m +REM 22m +REM 23m +REM 24m +REM 25m +REM 26m +REM 27m +REM 28m +REM 29m +#SPC# +:: Normal +30m +90m +31m +91m +32m +92m +33m +93m +34m +94m +35m +95m +36m +96m +37m +97m +#SPC# +:: Bold or increased intensity, 1 +1;30m +1;90m +1;31m +1;91m +1;32m +1;92m +1;33m +1;93m +1;34m +1;94m +1;35m +1;95m +1;36m +1;96m +1;37m +1;97m +#SPC# +:: Faint (decreased intensity), 2 +2;30m +2;90m +2;31m +2;91m +2;32m +2;92m +2;33m +2;93m +2;34m +2;94m +2;35m +2;95m +2;36m +2;96m +2;37m +2;97m +#SPC# +:: Italic, 3 +3;30m +3;90m +3;31m +3;91m +3;32m +3;92m +3;33m +3;93m +3;34m +3;94m +3;35m +3;95m +3;36m +3;96m +3;37m +3;97m +#SPC# +:: Underline, 4 +4;30m +4;90m +4;31m +4;91m +4;32m +4;92m +4;33m +4;93m +4;34m +4;94m +4;35m +4;95m +4;36m +4;96m +4;37m +4;97m +#SPC# +:: Slow Blink, 5 +5;30m +5;90m +5;31m +5;91m +5;32m +5;92m +5;33m +5;93m +5;34m +5;94m +5;35m +5;95m +5;36m +5;96m +5;37m +5;97m +#SPC# +:: Rapid Blink, 6 +6;30m +6;90m +6;31m +6;91m +6;32m +6;92m +6;33m +6;93m +6;34m +6;94m +6;35m +6;95m +6;36m +6;96m +6;37m +6;97m +#SPC# +:: Reverse video, 7 +7;30m +7;90m +7;31m +7;91m +7;32m +7;92m +7;33m +7;93m +7;34m +7;94m +7;35m +7;95m +7;36m +7;96m +7;37m +7;97m +#SPC# +:: Conceal, 8 +8;30m +8;90m +8;31m +8;91m +8;32m +8;92m +8;33m +8;93m +8;34m +8;94m +8;35m +8;95m +8;36m +8;96m +8;37m +8;97m +#SPC# +:: Crossed-out, 9 +9;30m +9;90m +9;31m +9;91m +9;32m +9;92m +9;33m +9;93m +9;34m +9;94m +9;35m +9;95m +9;36m +9;96m +9;37m +9;97m +#SPC# +:: Double Underline, 21 +21;30m +21;90m +21;31m +21;91m +21;32m +21;92m +21;33m +21;93m +21;34m +21;94m +21;35m +21;95m +21;36m +21;96m +21;37m +21;97m +__ROWS:END__ +__DATA:END__ + +:END_DATA_SEGMENT +%=- End Data Segment -=% + + +%=- Main Script -=% +SETLOCAL ENABLEDELAYEDEXPANSION + +:INITIALIZATION +:: Configure ANSI escape sequences. This has a dependency on PowerShell for creating the escape code +REM FOR /F "tokens=* USEBACKQ" %%G IN (`PowerShell -Command "[char]0x1B"`) DO (SET "ESC=%%G") +:: Otherwise you need to use an unprintable character +SET "ESC=" + +:: If we're going to display the ANSI Escape Sequence control characters +:: save the active console Code Page, change to UTF-8, and override ESC +IF DEFINED SHOW.ANSI ( + SET "SPINNER.DISABLED=#TRUE#" + REM SET "SHOW.UTF8=#TRUE#" +) + +:: The console (CMD) is normally not UTF-8, so preserve the codepage so we can reset it. +:: Because the output of chcp is localized, we grab the last value of the string, +:: which we have our fingers crossed, will be the codepage. +FOR /F "tokens=*" %%_ IN ('chcp') DO (SET CHCP_OUT=%%_) +FOR %%_ IN (!CHCP_OUT!) DO (SET CHCP=%%_) +IF DEFINED CHCP ( + IF [!CHCP!] EQU [65001] ( + SET "SHOW.UTF8=#TRUE#" + ) ELSE ( + IF DEFINED SHOW.UTF8 ( + chcp 65001>NUL + ) + ) +) +SET "CHCP_OUT=" + +:: This is a seperate code block so that the active console Code Page is changed first +IF DEFINED SHOW.ANSI ( + SET "ESC=␛" +) + +:: Control Sequence Introducer +SET "CSI=!ESC![" + +:: Cursor Up +SET "CUU=!CSI!A" +:: Cursor Down +SET "CUD=!CSI!B" +:: Cursor Forward +SET "CUF=!CSI!C" +:: Cursor Back +SET "CUB=!CSI!D" +:: Cursor Previous Line // will work like a CR without LF when appended to an echo +SET "CPL=!CSI!F" +:: Select Graphic Rendition (SGR) Reset // reset colors and attributes +SET "RESET=!CSI!m" + +:: We will want to calculate the max widths as we process the data segment +SET /A STUB.MAX_WIDTH=0 +SET /A COL.MAX_WIDTH=0 + +:: If showing the R1C1 reference address of each cell instead of the cell value, assume +:: there will be at most R999C99 cells and set the width at 7 +IF DEFINED SHOW.R1C1_REFERENCE ( + SET /A COL.MAX_WIDTH=7 +) + +:: Default properites if not defined in the data segment +:: See Figure 1.1 in the PDF for Wang Terminology +:: https://uwspace.uwaterloo.ca/handle/10012/10962 + +:: Fields +SET "STUBHEAD=" + +:: Alignment +SET "ALIGN.CELL=C" +SET "ALIGN.CELL.R1C1=R" +SET "ALIGN.STUBHEAD=C" +SET "ALIGN.BOXHEAD=C" +SET "ALIGN.STUB=R" +SET "ALIGN.STUBHEAD_STUB=C" +SET "ALIGN.STUB_BODY=C" +SET "ALIGN.BOXHEAD_BODY=C" + +:: Separators +SET "SEPARATOR.STUB=" +SET "SEPARATOR.STUBHEAD_BOXHEAD=" +SET "SEPARATOR.STUB_BODY=" +SET "SEPARATOR.COL=" +SET "SEPARATOR.BOXHEADERS=" +SET "SEPARATOR.CELL=" +SET "SEPARATOR.STUBHEAD_STUB=" +SET "SEPARATOR.BOXHEAD_BODY=" +SET "SEPARATOR.BOXHEAD=" +SET "SEPARATOR.INTERSECT=" +SET "SEPARATOR.STUB_BOXHEAD_INTERSECT=" + +:: Flags +SET "SEPARATOR.VERTICAL=" +SET "SEPARATOR.HORIZONTAL=" +SET "SEPARATOR.COLUMN=" + +:: Read and parse the data, validate the configuration, calculate table headings, +:: build the table, and show the table +CALL :READ_DATA_SEGMENT +CALL :VALIDATE_CONFIGURATION +IF ERRORLEVEL 4 ( + %@exit% %ERRORLEVEL% +) +CALL :RESOLVE_SEPARATORS +CALL :BUILD_TABLE +CALL :DISPLAY_TABLE + +:: Restore the console Code Page saved at the beginning of the script +IF DEFINED CHCP ( + chcp !CHCP!>NUL +) + +:: Exit +%@exit% 0 + +:: Should never be reached +ECHO Failed to EXIT cleanly +CMD /C EXIT -1073741510 + + +:: Routine to process the data segment of a file, used to build the table +:READ_DATA_SEGMENT +SET "DATA_SEGMENT=" +FOR /F "delims=" %%_ IN (!DATA_FILE!) DO ( + IF ["%%_"] EQU ["__ROWS:END__"] SET SEGMENT= + IF ["%%_"] EQU ["__COLS:END__"] SET SEGMENT= + IF ["%%_"] EQU ["__TABLE:END__"] SET SEGMENT= + IF ["%%_"] EQU ["__DATA:END__"] SET DATA_SEGMENT= + IF DEFINED DATA_SEGMENT ( + SET "DATA=%%_" + CALL :PARSE_DATA_SEGMENT !DATA! + ) + IF ["%%_"] EQU ["__ROWS__"] ( + SET SEGMENT=ROWS + :: Initalize the row globals + SET /A ROW[#]=0 + SET /A ROWS.LEN=0 + ) + IF ["%%_"] EQU ["__COLS__"] ( + SET SEGMENT=COLS + :: Initalize the column globals + SET /A COL[#]=0 + SET /A COLS.LEN=0 + ) + IF ["%%_"] EQU ["__TABLE__"] ( + SET SEGMENT=TABLE + :: Initalize the table globals + SET /A TABLE[#]=0 + ) + IF ["%%_"] EQU ["__DATA__"] ( + SET DATA_SEGMENT=#TRUE# + SET SEGMENT= + ) +) +%@exit% + + +:: Process each segment type +:PARSE_DATA_SEGMENT +IF NOT DEFINED SEGMENT %@exit% +SET "DATA=%*" + +:: Skip over any comments +IF ["!DATA:~0,2!"] EQU ["::"] %@exit% +IF ["!DATA:~0,3!"] EQU ["REM"] %@exit% +IF ["!DATA:~0,4!"] EQU ["@REM"] %@exit% + +:: Advance and output the spinner animation if not disabled +IF NOT DEFINED SPINNER.DISABLED ( + %@spinner% SPINNER.FRAME +) + +:: Dispatch to TABLE, COLS, or ROWS parsing routines +IF ["!SEGMENT!"] EQU ["TABLE"] CALL :PARSE_TABLE_DATA !DATA! +IF ["!SEGMENT!"] EQU ["COLS"] CALL :PARSE_COLS_DATA !DATA! +IF ["!SEGMENT!"] EQU ["ROWS"] CALL :PARSE_ROWS_DATA !DATA! +%@exit% + + +:PARSE_TABLE_DATA +:: Only eval single line SET or IF statements +SET "DATA=%*" +IF /I ["!DATA:~0,4!"] EQU ["SET "] GOTO :EVAL_TABLE_DATA +IF /I ["!DATA:~0,3!"] EQU ["IF "] GOTO :EVAL_TABLE_DATA +%@exit% + + +:EVAL_TABLE_DATA +:: Eval the TABLE data directly +%* +%@exit% + + +:PARSE_COLS_DATA +SET "COL=%*" +:: Set the column header text and track the max width +%@strlen% COL COL.LEN +%@maxval% COL.MAX_WIDTH COL.LEN +:: Set the col index and store value +SET /A COL[#]+=1 +SET "COL[!COL[#]!]=!COL!" +%@exit% + + +:PARSE_ROWS_DATA +SET "ROW=%*" +:: Set the row header text +%@strlen% ROW ROW.LEN +%@maxval% STUB.MAX_WIDTH ROW.LEN +:: Set the row index and store value +SET /A ROW[#]+=1 +SET "ROW[!ROW[#]!]=!ROW!" +%@exit% + + +:: Validate that we can render the definition file +:VALIDATE_CONFIGURATION +:: Does the definition require UTF-8 +IF DEFINED UTF8.REQUIRED ( + IF NOT DEFINED SHOW.UTF8 ( + SET "SCRIPT_NAME=%~nx0" + SET "msg=Error: Requested definition script requires UTF-8.!LF! Try ^"!SCRIPT_NAME! /U [^]^" to run with UTF-8 support!LF! or change the default configuration in !SCRIPT_NAME! to always use UTF-8." + CALL :USAGE msg + %@exit% 4 + ) +) +%@exit% + + +:: Separators have cascading effects, so if some are not defined this is where +:: they are defined +:RESOLVE_SEPARATORS +IF DEFINED DEBUG.OUT ( + REM ::DEBUG + ECHO. + ECHO RESOLVE_SEPARATORS enter + ECHO. + ECHO SEPARATOR.COL : "!SEPARATOR.COL!" + ECHO SEPARATOR.BOXHEAD : "!SEPARATOR.BOXHEAD!" + ECHO SEPARATOR.INTERSECT : "!SEPARATOR.INTERSECT!" + ECHO SEPARATOR.STUB : "!SEPARATOR.STUB!" + ECHO SEPARATOR.CELL : "!SEPARATOR.CELL!" + + ECHO SEPARATOR.VERTICAL : "!SEPARATOR.VERTICAL!" + ECHO SEPARATOR.HORIZONTAL : "!SEPARATOR.HORIZONTAL!" + ECHO SEPARATOR.COLUMN : "!SEPARATOR.COLUMN!" + + ECHO STUBHEAD : "!STUBHEAD!" + + ECHO SEPARATOR.VERTICAL.WIDTH : "!SEPARATOR.VERTICAL.WIDTH!" + ECHO SEPARATOR.STUBHEAD_BOXHEAD : "!SEPARATOR.STUBHEAD_BOXHEAD!" + ECHO SEPARATOR.STUB_BODY : "!SEPARATOR.STUB_BODY!" + ECHO SEPARATOR.BOXHEADERS : "!SEPARATOR.BOXHEADERS!" + + ECHO SEPARATOR.STUBHEAD_STUB : "!SEPARATOR.STUBHEAD_STUB!" + ECHO SEPARATOR.BOXHEAD_BODY : "!SEPARATOR.BOXHEAD_BODY!" + + ECHO SEPARATOR.STUB_BOXHEAD_INTERSECT : "!SEPARATOR.STUB_BOXHEAD_INTERSECT!" + ECHO SEPARATOR.BOXHEAD_BODY_INTERSECT : "!SEPARATOR.BOXHEAD_BODY_INTERSECT!" + ECHO. + REM ::DEBUG +) + +:: Define the vertical separator +IF DEFINED SEPARATOR.STUB ( + SET "SEPARATOR.VERTICAL=#TRUE#" + IF NOT DEFINED SEPARATOR.STUBHEAD_BOXHEAD ( + SET "SEPARATOR.STUBHEAD_BOXHEAD=!SEPARATOR.STUB!" + ) + IF NOT DEFINED SEPARATOR.STUB_BODY ( + SET "SEPARATOR.STUB_BODY=!SEPARATOR.STUB!" + ) +) ELSE ( + IF DEFINED SEPARATOR.STUBHEAD_BOXHEAD ( + SET "SEPARATOR.VERTICAL=#TRUE#" + IF NOT DEFINED SEPARATOR.STUB_BODY ( + SET "SEPARATOR.STUB_BODY= " + ) + ) + IF DEFINED SEPARATOR.STUB_BODY ( + SET "SEPARATOR.VERTICAL=#TRUE#" + IF NOT DEFINED SEPARATOR.STUBHEAD_BOXHEAD ( + SET "SEPARATOR.STUBHEAD_BOXHEAD= " + ) + ) +) + +:: Define the horizontal separator +IF DEFINED SEPARATOR.BOXHEAD ( + SET "SEPARATOR.HORIZONTAL=#TRUE#" + IF NOT DEFINED SEPARATOR.STUBHEAD_STUB ( + SET "SEPARATOR.STUBHEAD_STUB=!SEPARATOR.BOXHEAD!" + ) + IF NOT DEFINED SEPARATOR.BOXHEAD_BODY ( + SET "SEPARATOR.BOXHEAD_BODY=!SEPARATOR.BOXHEAD!" + ) +) ELSE ( + IF DEFINED SEPARATOR.STUBHEAD_STUB ( + SET "SEPARATOR.HORIZONTAL=#TRUE#" + IF NOT DEFINED SEPARATOR.BOXHEAD_BODY ( + SET "SEPARATOR.BOXHEAD_BODY= " + ) + ) + IF DEFINED SEPARATOR.BOXHEAD_BODY ( + SET "SEPARATOR.HORIZONTAL=#TRUE#" + IF NOT DEFINED SEPARATOR.STUBHEAD_STUB ( + SET "SEPARATOR.STUBHEAD_STUB= " + ) + ) +) + +:: Define the column separator +IF DEFINED SEPARATOR.COL ( + SET "SEPARATOR.COLUMN=#TRUE#" + IF NOT DEFINED SEPARATOR.BOXHEADERS ( + SET "SEPARATOR.BOXHEADERS=!SEPARATOR.COL!" + ) + IF NOT DEFINED SEPARATOR.CELL ( + SET "SEPARATOR.CELL=!SEPARATOR.COL!" + ) +) ELSE ( + IF DEFINED SEPARATOR.BOXHEADERS ( + SET "SEPARATOR.COLUMN=#TRUE#" + IF NOT DEFINED SEPARATOR.CELL ( + SET "SEPARATOR.CELL= " + ) + ) + IF DEFINED SEPARATOR.CELL ( + SET "SEPARATOR.COLUMN=#TRUE#" + IF NOT DEFINED SEPARATOR.BOXHEADERS ( + SET "SEPARATOR.BOXHEADERS= " + ) + ) +) + +:: SEPARATOR.INTERSECT is intended to be a friendlier name of SEPARATOR.STUB_BOXHEAD_INTERSECT +:: Only one should be defined with a non-space character +IF DEFINED SEPARATOR.INTERSECT ( + IF NOT DEFINED SEPARATOR.STUB_BOXHEAD_INTERSECT ( + SET "SEPARATOR.STUB_BOXHEAD_INTERSECT=!SEPARATOR.INTERSECT!" + ) ELSE ( + ECHO Warning: SEPARATOR.STUB_BOXHEAD_INTERSECT definition overriding SEPARATOR.INTERSECT + ) +) + +IF DEFINED DEBUG.OUT ( + REM ::DEBUG + ECHO. + ECHO RESOLVE_SEPARATORS pre-trim + ECHO. + ECHO SEPARATOR.COL : "!SEPARATOR.COL!" + ECHO SEPARATOR.BOXHEAD : "!SEPARATOR.BOXHEAD!" + ECHO SEPARATOR.INTERSECT : "!SEPARATOR.INTERSECT!" + ECHO SEPARATOR.STUB : "!SEPARATOR.STUB!" + ECHO SEPARATOR.CELL : "!SEPARATOR.CELL!" + ECHO SEPARATOR.STUBHEAD_BOXHEAD : "!SEPARATOR.STUBHEAD_BOXHEAD!" + ECHO SEPARATOR.STUB_BODY : "!SEPARATOR.STUB_BODY!" + ECHO SEPARATOR.STUBHEAD_STUB : "!SEPARATOR.STUBHEAD_STUB!" + ECHO SEPARATOR.BOXHEAD_BODY : "!SEPARATOR.BOXHEAD_BODY!" + ECHO. + REM ::DEBUG +) + +:: Trim the variables we use to draw our separators +:: so we only work with non-space characters +SET "SEPARATOR.COL.TRIM=!SEPARATOR.COL!" +%@trim% SEPARATOR.COL.TRIM +SET "SEPARATOR.BOXHEAD.TRIM=!SEPARATOR.BOXHEAD!" +%@trim% SEPARATOR.BOXHEAD.TRIM +SET "SEPARATOR.INTERSECT.TRIM=!SEPARATOR.INTERSECT!" +%@trim% SEPARATOR.INTERSECT.TRIM +SET "SEPARATOR.STUB.TRIM=!SEPARATOR.STUB!" +%@trim% SEPARATOR.STUB.TRIM +SET "SEPARATOR.CELL.TRIM=!SEPARATOR.CELL!" +%@trim% SEPARATOR.CELL.TRIM +SET "SEPARATOR.STUBHEAD_BOXHEAD.TRIM=!SEPARATOR.STUBHEAD_BOXHEAD!" +%@trim% SEPARATOR.STUBHEAD_BOXHEAD.TRIM +SET "SEPARATOR.STUB_BODY.TRIM=!SEPARATOR.STUB_BODY!" +%@trim% SEPARATOR.STUB_BODY.TRIM +SET "SEPARATOR.STUBHEAD_STUB.TRIM=!SEPARATOR.STUBHEAD_STUB!" +%@trim% SEPARATOR.STUBHEAD_STUB.TRIM +SET "SEPARATOR.BOXHEAD_BODY.TRIM=!SEPARATOR.BOXHEAD_BODY!" +%@trim% SEPARATOR.BOXHEAD_BODY.TRIM + +IF DEFINED DEBUG.OUT ( + REM ::DEBUG + ECHO. + ECHO RESOLVE_SEPARATORS post-trim + ECHO. + ECHO SEPARATOR.COL.TRIM : "!SEPARATOR.COL.TRIM!" + ECHO SEPARATOR.BOXHEAD.TRIM : "!SEPARATOR.BOXHEAD.TRIM!" + ECHO SEPARATOR.INTERSECT.TRIM : "!SEPARATOR.INTERSECT.TRIM!" + ECHO SEPARATOR.STUB.TRIM : "!SEPARATOR.STUB.TRIM!" + ECHO SEPARATOR.CELL.TRIM : "!SEPARATOR.CELL.TRIM!" + ECHO SEPARATOR.STUBHEAD_BOXHEAD.TRIM : "!SEPARATOR.STUBHEAD_BOXHEAD.TRIM!" + ECHO SEPARATOR.STUB_BODY.TRIM : "!SEPARATOR.STUB_BODY.TRIM!" + ECHO SEPARATOR.STUBHEAD_STUB.TRIM : "!SEPARATOR.STUBHEAD_STUB.TRIM!" + ECHO SEPARATOR.BOXHEAD_BODY.TRIM : "!SEPARATOR.BOXHEAD_BODY.TRIM!" + ECHO. + REM ::DEBUG +) + +IF DEFINED SEPARATOR.VERTICAL ( + IF DEFINED SEPARATOR.HORIZONTAL ( + IF NOT DEFINED SEPARATOR.STUB_BOXHEAD_INTERSECT.TRIM ( + IF DEFINED SEPARATOR.INTERSECT.TRIM ( + SET "SEPARATOR.STUB_BOXHEAD_INTERSECT=!SEPARATOR.INTERSECT!" + ) ELSE ( + IF DEFINED SEPARATOR.STUB.TRIM ( + IF NOT DEFINED SEPARATOR.BOXHEAD.TRIM ( + SET "SEPARATOR.STUB_BOXHEAD_INTERSECT=!SEPARATOR.STUB!" + ) ELSE ( + SET "SEPARATOR.STUB_BOXHEAD_INTERSECT= " + ) + ) ELSE ( + IF DEFINED SEPARATOR.BOXHEAD.TRIM ( + SET "SEPARATOR.STUB_BOXHEAD_INTERSECT=!SEPARATOR.BOXHEAD!" + ) ELSE ( + SET "SEPARATOR.STUB_BOXHEAD_INTERSECT= " + ) + ) + ) + ) + ) ELSE ( + SET "SEPARATOR.STUB_BOXHEAD_INTERSECT=!SEPARATOR.STUB!" + ) +) ELSE ( + IF DEFINED SEPARATOR.HORIZONTAL ( + SET "SEPARATOR.STUB_BOXHEAD_INTERSECT=!SEPARATOR.BOXHEAD!" + ) + SET "SEPARATOR.STUB_BOXHEAD_INTERSECT=" +) + +IF DEFINED SEPARATOR.VERTICAL ( + SET /A "SEPARATOR.VERTICAL.WIDTH=0" + %@strlen% SEPARATOR.STUBHEAD_BOXHEAD SEPARATOR.WIDTH + %@maxval% SEPARATOR.VERTICAL.WIDTH SEPARATOR.WIDTH + %@strlen% SEPARATOR.STUB_BOXHEAD_INTERSECT SEPARATOR.WIDTH + %@maxval% SEPARATOR.VERTICAL.WIDTH SEPARATOR.WIDTH + %@strlen% SEPARATOR.STUB_BODY SEPARATOR.WIDTH + %@maxval% SEPARATOR.VERTICAL.WIDTH SEPARATOR.WIDTH + + IF DEFINED SEPARATOR.STUBHEAD_BOXHEAD ( %@align% SEPARATOR.STUBHEAD_BOXHEAD !SEPARATOR.VERTICAL.WIDTH! C SEPARATOR.STUBHEAD_BOXHEAD ) + IF DEFINED SEPARATOR.STUB_BOXHEAD_INTERSECT ( %@align% SEPARATOR.STUB_BOXHEAD_INTERSECT !SEPARATOR.VERTICAL.WIDTH! C SEPARATOR.STUB_BOXHEAD_INTERSECT ) + IF DEFINED SEPARATOR.STUB_BODY ( %@align% SEPARATOR.STUB_BODY !SEPARATOR.VERTICAL.WIDTH! C SEPARATOR.STUB_BODY ) +) + +IF DEFINED DEBUG.OUT ( + REM ::DEBUG + ECHO. + ECHO RESOLVE_SEPARATORS exit + ECHO. + ECHO SEPARATOR.COL : "!SEPARATOR.COL!" + ECHO SEPARATOR.BOXHEAD : "!SEPARATOR.BOXHEAD!" + ECHO SEPARATOR.INTERSECT : "!SEPARATOR.INTERSECT!" + ECHO SEPARATOR.STUB : "!SEPARATOR.STUB!" + ECHO SEPARATOR.CELL : "!SEPARATOR.CELL!" + + ECHO SEPARATOR.VERTICAL : "!SEPARATOR.VERTICAL!" + ECHO SEPARATOR.HORIZONTAL : "!SEPARATOR.HORIZONTAL!" + ECHO SEPARATOR.COLUMN : "!SEPARATOR.COLUMN!" + + ECHO STUBHEAD : "!STUBHEAD!" + + ECHO SEPARATOR.VERTICAL.WIDTH : "!SEPARATOR.VERTICAL.WIDTH!" + ECHO SEPARATOR.STUBHEAD_BOXHEAD : "!SEPARATOR.STUBHEAD_BOXHEAD!" + ECHO SEPARATOR.STUB_BODY : "!SEPARATOR.STUB_BODY!" + ECHO SEPARATOR.BOXHEADERS : "!SEPARATOR.BOXHEADERS!" + + ECHO SEPARATOR.STUBHEAD_STUB : "!SEPARATOR.STUBHEAD_STUB!" + ECHO SEPARATOR.BOXHEAD_BODY : "!SEPARATOR.BOXHEAD_BODY!" + + ECHO SEPARATOR.STUB_BOXHEAD_INTERSECT : "!SEPARATOR.STUB_BOXHEAD_INTERSECT!" + ECHO. + REM ::DEBUG +) +%@exit% + + +:: At this point, the table is defined only in terms of the Stub and Boxhead +:: BUILD_TABLE takes those definitions and populates the cells +:BUILD_TABLE +:: Build the Stub head +IF NOT DEFINED STUBHEAD ( + %@repeat% #SPC# !STUB.MAX_WIDTH! STUBHEAD +) +%@strlen% STUBHEAD STUBHEAD.WIDTH +%@maxval% STUB.MAX_WIDTH STUBHEAD.WIDTH +%@align% STUBHEAD !STUB.MAX_WIDTH! !ALIGN.STUBHEAD! STUBHEAD + +SET "LINE=!STUBHEAD!!SEPARATOR.STUBHEAD_BOXHEAD!" + +:: Line = Stub head + Stub separator, still missing Boxhead column headers + +:: The test text might be wider than the column headers, so check that now +%@strlen% CELL CELL.LEN +%@maxval% COL.MAX_WIDTH CELL.LEN + +:: Build the boxheader +:: Append a column header +SET "BOXHEAD=" +FOR /L %%c IN (1,1,!COL[#]!) DO ( + SET "COL=!COL[%%c]!" + SET "COL.VALUE=#SPC#" & %@align% COL !COL.MAX_WIDTH! !ALIGN.BOXHEAD! COL.VALUE + IF [%%c] EQU [1] ( + SET "BOXHEAD=!COL.VALUE!" + ) ELSE ( + SET "BOXHEAD=!BOXHEAD!!SEPARATOR.BOXHEADERS!!COL.VALUE!" + ) +) + +%@strlen% BOXHEAD BOXHEAD.WIDTH + +SET "LINE=!LINE!!BOXHEAD!" +%@strlen% LINE TABLE.WIDTH + +:: Save the line to the TABLE +SET /A TABLE[#]+=1 +SET "TABLE[!TABLE[#]!]=!LINE!" + +:: Add a horizontal separator if defined +IF DEFINED SEPARATOR.HORIZONTAL ( + SET "LINE=" + SET "SEPARATOR=" + %@strlen% SEPARATOR.STUBHEAD_STUB SEPARATOR.WIDTH + IF [!SEPARATOR.WIDTH!] EQU [1] ( + IF DEFINED SEPARATOR.STUBHEAD_STUB ( %@repeat% SEPARATOR.STUBHEAD_STUB !STUB.MAX_WIDTH! SEPARATOR) + ) ELSE ( + IF DEFINED SEPARATOR.STUBHEAD_STUB ( %@align% SEPARATOR.STUBHEAD_STUB !STUB.MAX_WIDTH! !ALIGN.STUBHEAD_STUB! SEPARATOR ) + ) + SET "LINE=!LINE!!SEPARATOR!" + + SET "SEPARATOR=" + %@strlen% SEPARATOR.STUB_BOXHEAD_INTERSECT SEPARATOR.WIDTH + IF [!SEPARATOR.WIDTH!] EQU [1] ( + IF DEFINED SEPARATOR.STUB_BOXHEAD_INTERSECT ( %@repeat% SEPARATOR.STUB_BOXHEAD_INTERSECT !SEPARATOR.VERTICAL.WIDTH! SEPARATOR ) + ) ELSE ( + IF DEFINED SEPARATOR.STUB_BOXHEAD_INTERSECT ( %@align% SEPARATOR.STUB_BOXHEAD_INTERSECT !SEPARATOR.VERTICAL.WIDTH! !ALIGN.STUBHEAD! SEPARATOR ) + ) + SET "LINE=!LINE!!SEPARATOR!" + + SET "SEPARATOR=" + %@strlen% SEPARATOR.BOXHEAD_BODY SEPARATOR.WIDTH + IF [!SEPARATOR.WIDTH!] EQU [1] ( + IF DEFINED SEPARATOR.BOXHEAD_BODY ( %@repeat% SEPARATOR.BOXHEAD_BODY !BOXHEAD.WIDTH! SEPARATOR ) + ) ELSE ( + IF DEFINED SEPARATOR.BOXHEAD_BODY ( %@align% SEPARATOR.BOXHEAD_BODY !BOXHEAD.WIDTH! !ALIGN.STUBHEAD! SEPARATOR ) + ) + SET "LINE=!LINE!!SEPARATOR!" + + SET /A TABLE[#]+=1 + SET "TABLE[!TABLE[#]!]=!LINE!" +) + +:: Figure out the CELL alignment now so we only need to compute this once +IF NOT DEFINED SHOW.R1C1_REFERENCE ( + %@align% CELL !COL.MAX_WIDTH! !ALIGN.CELL! CELL +) ELSE ( + SET /A "R1C1_REFERENCE.R=0" +) + +:: Build the row +FOR /L %%r IN (1,1,!ROW[#]!) DO ( + :: Advance and output the spinner animation if not disabled + IF NOT DEFINED SPINNER.DISABLED ( + %@spinner% SPINNER.FRAME + ) + + :: Build the stub for the row + SET "ROW=!ROW[%%r]!" + %@align% ROW !STUB.MAX_WIDTH! !ALIGN.STUB! ROW.VALUE + + SET "SEPARATOR=" + IF DEFINED SEPARATOR.VERTICAL ( + %@strlen% SEPARATOR.STUB_BODY SEPARATOR.WIDTH + IF [!SEPARATOR.WIDTH!] EQU [1] ( + IF DEFINED SEPARATOR.STUB_BODY ( %@repeat% SEPARATOR.STUB_BODY !SEPARATOR.VERTICAL.WIDTH! SEPARATOR ) + ) ELSE ( + IF DEFINED SEPARATOR.STUB_BODY ( %@align% SEPARATOR.STUB_BODY !SEPARATOR.VERTICAL.WIDTH! !ALIGN.STUB_BODY! SEPARATOR ) + ) + ) + + IF [!ROW!] EQU [#SPC#] ( + :: We want a special case for #SPC# so that we print a blank line + SET "LINE=" + ) ELSE ( + :: Otherwise process the line + SET "LINE=!ROW.VALUE!!SEPARATOR!" + + IF [!ROW!] EQU [#NUL#] ( + SET "ROW=" + ) ELSE ( + SET "ROW=!CSI!!ROW!" + ) + + IF DEFINED SHOW.R1C1_REFERENCE ( + SET /A "R1C1_REFERENCE.C=0" + %@counter% R1C1_REFERENCE.R + ) + :: Append a cell to the row + FOR /L %%c IN (1,1,!COL[#]!) DO ( + IF DEFINED SHOW.R1C1_REFERENCE ( + %@counter% R1C1_REFERENCE.C + SET "R1C1_REFERENCE=R!R1C1_REFERENCE.R!C!R1C1_REFERENCE.C!" + %@align% R1C1_REFERENCE !COL.MAX_WIDTH! !ALIGN.CELL.R1C1! CELL + ) + IF [!COL[%%c]!] EQU [#NUL#] ( + SET "COL=" + ) ELSE ( + SET "COL=!CSI!!COL[%%c]!" + ) + IF [%%c] EQU [1] ( + SET "LINE=!LINE!!ROW!!COL!!CELL!!RESET!" + ) ELSE ( + SET "LINE=!LINE!!SEPARATOR.CELL!!ROW!!COL!!CELL!!RESET!" + ) + ) + ) + + :: Save the line to the TABLE + SET /A TABLE[#]+=1 + SET "TABLE[!TABLE[#]!]=!LINE!" +) +%@exit% + + +:DISPLAY_TABLE +:: We use an out buffer to iterate through all the rows of the table +:: This allows us to quickly display the output even though it takes +:: time to figure out the alignment calculations +FOR /L %%r IN (1,1,!TABLE[#]!) DO ( + ECHO.!TABLE[%%r]! +) +%@exit% +%=- End Main Script -=% + + +%=- Macro Definitions -=% +:DEFINE_MACROS +:: Return from this with GOTO :MAIN to retain macro definitions +SETLOCAL DISABLEDELAYEDEXPANSION +:: -------- Begin macro definitions ---------- +(SET LF=^ +%= This defines a Line Feed (0x0A) =% +) + +(SET \n=^^^ +%= This defines an escaped Line Feed (0x5E 0x0A) =% +) + +:: @strlen StrVar [RtnVar] +:: +:: Computes the length of string in variable StrVar +:: and stores the result in variable RtnVar. +:: If StrVar is #NUL#, this should be 0 width. +:: If StrVar is #SPC#, this should empty padding. +:: If RtnVar is not specified, then print the length to stdout. +:: +SET @strlen=FOR %%. IN (1 2) DO IF [%%.] EQU [2] (%\n% + FOR /F "tokens=1,2 delims=, " %%1 IN ("!argv!") DO ( ENDLOCAL%\n% + SET "s=A!%%~1!"%\n% + SET "s=!s:#NUL#=!"%\n% + SET "s=!s:#SPC#= !"%\n% + SET "len=0"%\n% + FOR %%P in (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) DO (%\n% + IF ["!s:~%%P,1!"] NEQ [""] (%\n% + SET /A "len+=%%P"%\n% + SET "s=!s:~%%P!"%\n% + )%\n% + )%\n% + FOR %%V IN (!len!) DO ENDLOCAL^&IF ["%%~2"] NEQ [""] (SET "%%~2=%%V") ELSE (ECHO %%V)%\n% + )%\n% +) ELSE SETLOCAL ENABLEDELAYEDEXPANSION^&SETLOCAL^&SET argv=, + +:: @maxval NumVar1 NumVar2 [RetVar] +:: +:: Compares NumVar1 with NumVar2, and assigns to RetVar. +:: If RtnVar is not specified, then return the largest value +:: back through NumVar1. +:: +:: It is recommended that NumVar1 will be accumulating the +:: Max value passed through multiple subsequent calls, to +:: determine the largest string passed in. +:: +SET @maxVal=FOR %%. IN (1 2) DO IF [%%.] EQU [2] (%\n% + FOR /F "tokens=1,2,3 delims=, " %%1 IN ("!argv!") DO ( ENDLOCAL%\n% + IF [!%%~1!] NEQ [] (SET /a "a=!%%~1!") ELSE (SET /a "a=%%~1")%\n% + IF [!%%~2!] NEQ [] (SET /a "b=!%%~2!") ELSE (SET /a "b=%%~2")%\n% + IF !b! GTR !a! (SET /a "a=b")%\n% + FOR %%V IN (!a!) DO ENDLOCAL^&IF ["%%~3"] NEQ [""] (SET "%%~3=%%V") ELSE (SET "%%~1=%%V")%\n% + )%\n% +) ELSE SETLOCAL ENABLEDELAYEDEXPANSION^&SETLOCAL^&SET argv=, + +:: @repeat StrVal Count [RetVar] +:: +:: Repeats StrVal, Count times, and assigns to RetVar. +:: If StrVar is #NUL#, this should empty padding. +:: If StrVar is #SPC#, this should empty padding. +:: If RtnVar is not specified, then print the output string to stdout. +:: +SET @repeat=FOR %%. IN (1 2) DO IF [%%.] EQU [2] (%\n% + FOR /F "tokens=1,2,3 delims=, " %%1 IN ("!argv!") DO ( ENDLOCAL%\n% + IF [!%%~1!] NEQ [] (SET "s=!%%~1!") ELSE (SET "s=%%~1")%\n% + SET "s=!s:#NUL#= !"%\n% + SET "s=!s:#SPC#= !"%\n% + SET "count=%%~2"%\n% + SET "outstr="%\n% + FOR /L %%. IN (1,1,!count!) DO SET "outstr=!outstr!!s!"%\n% + FOR /F "delims=" %%V IN ("!outstr!") DO ENDLOCAL^&IF ["%%~3"] NEQ [""] (SET "%%~3=%%V") ELSE (ECHO %%V)%\n% + )%\n% +) ELSE SETLOCAL ENABLEDELAYEDEXPANSION^&SETLOCAL^&SET argv=, + +:: @rtrim StrVar [CharVar] +:: +:: Right Trim CharVar surrounding StrVar. +:: If CharVar is not specified, then default to space. +:: +:: Technique Source: https://www.dostips.com/forum/viewtopic.php?p=12327#p12327 +:: +SET @rtrim=FOR %%. IN (1 2) DO IF [%%.] EQU [2] (%\n% + SET "charVar= "%\n% + FOR /F "tokens=1,2 delims=, " %%1 IN ("!argv!") DO (%\n% + SET "strVar=!%%1!"%\n% + IF [%%~2] NEQ [] IF DEFINED %%~2 SET "charVar=!%%2:~0,1!"%\n% + FOR /L %%i IN (1 1 12) DO SET "charVar=!charVar!!charVar!"%\n% + IF DEFINED strVar FOR %%k IN (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) DO (%\n% + IF ["!strVar:~-%%k!"] EQU ["!charVar:~-%%k!"] SET "strVar=!strVar:~0,-%%k!"%\n% + )%\n% + IF DEFINED strVar (%\n% + IF NOT DEFINED _notDelayed (%\n% + SET "strVar=!strVar:^=^^!"%\n% + SET "strVar=!strVar:"=""Q!^"%\n% + CALL SET "strVar=%%^strVar:^!=""E^!%%" ! %\n% + SET "strVar=!strVar:""E=^!"%\n% + SET "strVar=!strVar:""Q="!^"%\n% + )%\n% + FOR /F ^^^"eol^^=^^^%LF%%LF%^%LF%%LF%^^ delims^^=^^^" %%k IN ("!strVar!") DO ENDLOCAL^&ENDLOCAL^&SET "%%1=%%k"%\n% + ) ELSE ENDLOCAL^&ENDLOCAL^&SET "%%1="%\n% + )%\n% +) ELSE SETLOCAL^&SET "_notDelayed=!"^&SETLOCAL ENABLEDELAYEDEXPANSION^&SET argv=, + +:: @ltrim StrVar [CharVar] +:: +:: Left Trim CharVar surrounding StrVar. +:: If CharVar is not specified, then default to space. +:: +:: Technique Source: https://www.dostips.com/forum/viewtopic.php?p=12327#p12327 +:: +SET @ltrim=FOR %%. IN (1 2) DO IF [%%.] EQU [2] (%\n% + SET "charVar= "%\n% + FOR /F "tokens=1,2 delims=, " %%1 IN ("!argv!") DO (%\n% + SET "strVar=!%%1!"%\n% + IF [%%~2] NEQ [] IF DEFINED %%~2 SET "charVar=!%%2:~0,1!"%\n% + FOR /L %%i IN (1 1 12) DO SET "charVar=!charVar!!charVar!"%\n% + IF DEFINED strVar FOR %%k IN (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) DO (%\n% + IF ["!strVar:~0,%%k!"] EQU ["!charVar:~-%%k!"] SET "strVar=!strVar:~%%k!"%\n% + )%\n% + IF DEFINED strVar (%\n% + IF NOT DEFINED _notDelayed (%\n% + SET "strVar=!strVar:^=^^!"%\n% + SET "strVar=!strVar:"=""Q!^"%\n% + CALL SET "strVar=%%^strVar:^!=""E^!%%" ! %\n% + SET "strVar=!strVar:""E=^!"%\n% + SET "strVar=!strVar:""Q="!^"%\n% + )%\n% + FOR /F ^^^"eol^^=^^^%LF%%LF%^%LF%%LF%^^ delims^^=^^^" %%k IN ("!strVar!") DO ENDLOCAL^&ENDLOCAL^&SET "%%1=%%k"%\n% + ) ELSE ENDLOCAL^&ENDLOCAL^&SET "%%1="%\n% + )%\n% +) ELSE SETLOCAL^&SET "_notDelayed=!"^&SETLOCAL ENABLEDELAYEDEXPANSION^&SET argv=, + +:: @trim StrVar [CharVar] +:: +:: Trim CharVar surrounding StrVar. +:: If CharVar is not specified, then default to space. +:: +:: Technique Source: https://www.dostips.com/forum/viewtopic.php?p=12327#p12327 +:: +SET @trim=FOR %%. IN (1 2) DO IF [%%.] EQU [2] (%\n% + SET "charVar= "%\n% + FOR /F "tokens=1,2 delims=, " %%1 IN ("!argv!") DO (%\n% + SET "strVar=!%%1!"%\n% + IF [%%~2] NEQ [] IF DEFINED %%~2 SET "charVar=!%%2:~0,1!"%\n% + FOR /L %%i IN (1 1 12) DO SET "charVar=!charVar!!charVar!"%\n% + IF DEFINED strVar FOR %%k IN (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) DO (%\n% + IF ["!strVar:~-%%k!"] EQU ["!charVar:~-%%k!"] SET "strVar=!strVar:~0,-%%k!"%\n% + IF ["!strVar:~0,%%k!"] EQU ["!charVar:~-%%k!"] SET "strVar=!strVar:~%%k!"%\n% + )%\n% + IF DEFINED strVar (%\n% + IF NOT DEFINED _notDelayed (%\n% + SET "strVar=!strVar:^=^^!"%\n% + SET "strVar=!strVar:"=""Q!^"%\n% + CALL SET "strVar=%%^strVar:^!=""E^!%%" ! %\n% + SET "strVar=!strVar:""E=^!"%\n% + SET "strVar=!strVar:""Q="!^"%\n% + )%\n% + FOR /F ^^^"eol^^=^^^%LF%%LF%^%LF%%LF%^^ delims^^=^^^" %%k IN ("!strVar!") DO ENDLOCAL^&ENDLOCAL^&SET "%%1=%%k"%\n% + ) ELSE ENDLOCAL^&ENDLOCAL^&SET "%%1="%\n% + )%\n% +) ELSE SETLOCAL^&SET "_notDelayed=!"^&SETLOCAL ENABLEDELAYEDEXPANSION^&SET argv=, + +:: @align StrVar Width [RtnVar] +:: +:: Aligns the string in variable StrVar +:: in the field using the Width and Alignment provided +:: and stores the result in variable RtnVar. +:: If StrVar is #NUL#, this should empty padding. +:: If StrVar is #SPC#, this should empty padding. +:: If RtnVar is not specified, then print the output to stdout. +:: +SET @align=FOR %%. IN (1 2) DO IF [%%.] EQU [2] (%\n% + FOR /F "tokens=1,2,3,4 delims=, " %%1 IN ("!argv!") DO ( ENDLOCAL%\n% + IF ["!%%~1!"] NEQ [""] (SET "strVar=!%%~1!") ELSE (SET "strVar=%%~1")%\n% + SET "strVar=!strVar:#NUL#= !"%\n% + SET "strVar=!strVar:#SPC#= !"%\n% + IF ["!%%~2!"] NEQ [""] (SET "width=!%%~2!") ELSE (SET "width=%%~2")%\n% + SET "alignment=%%~3"%\n% + IF ["!%%~4!"] NEQ [""] (SET "%%~4=")%\n% + SET "len=1"%\n% + SET "s=!strVar!"%\n% + FOR %%P in (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) DO (%\n% + IF ["!s:~%%P,1!"] NEQ [""] (%\n% + SET /A "len+=%%P"%\n% + SET "s=!s:~%%P!"%\n% + )%\n% + )%\n% + IF /I ["!alignment!"] EQU ["L"] (%\n% + SET /A "pre=0"%\n% + SET /A "post=(!width! - !len!)"%\n% + )%\n% + IF /I ["!alignment!"] EQU ["C"] (%\n% + SET /A "pre=(!width! - !len! + 1) / 2"%\n% + SET /A "post=(!width! - !pre! - !len!)"%\n% + )%\n% + IF /I ["!alignment!"] EQU ["R"] (%\n% + SET /A "pre=(!width! - !len!)"%\n% + SET /A "post=0"%\n% + )%\n% + SET "wrkstr="%\n% + FOR /L %%. IN (1,1,!pre!) DO SET "wrkstr=!wrkstr! "%\n% + SET "wrkstr=!wrkstr!!strVar!"%\n% + FOR /L %%. IN (1,1,!post!) DO SET "wrkstr=!wrkstr! "%\n% + FOR /F "delims=" %%V IN ("!wrkstr!") DO ENDLOCAL^&IF ["%%~4"] NEQ [""] (SET "%%~4=%%V") ELSE (ECHO %%V)%\n% + )%\n% +) ELSE SETLOCAL ENABLEDELAYEDEXPANSION^&SETLOCAL^&SET argv=, + +:: @spinner FrameVar +:: +:: When called print a spinning wait cursor using the FrameVar +:: as an accumulator. If the FrameVar variable is not set +:: it is initialized. Advancing one frame the FrameVar is +:: incremented. If it reaches the last frame it is reset +:: back to the first frame. +:: +:: Has a dependency on the ANSI Control Sequence, +:: Cursor Previous Line (CPL). This means the initialization +:: needs to be completed before this macro can be used. +:: +:: The animation can be changed by adjusting the variables named +:: @spinner[#] and setting the count to match. +:: +SET "@spinner[0]= - Processing" +SET "@spinner[1]= \ Processing" +SET "@spinner[2]= ^| Processing" +SET "@spinner[3]= / Processing" +SET /A "@spinner[#]=4" + +SET @spinner=FOR %%. IN (1 2) DO IF [%%.] EQU [2] (%\n% + FOR /f "tokens=1 delims=, " %%1 IN ("!argv!") DO ( ENDLOCAL%\n% + SET "frameVar=%%~1"%\n% + IF ["!frameVar!"] EQU [""] (%\n% + SET /A "frame=0"%\n% + ) ELSE (%\n% + SET /A "frame=!frameVar!"%\n% + )%\n% + CALL ECHO %%@spinner[!frame!]%%!CPL!%\n% + SET /A "frame+=1"%\n% + SET /A "frame%%=!@spinner[#]!"%\n% + FOR /F "delims=" %%V IN ("!frame!") DO ENDLOCAL^&SET "%%~1=%%V"%\n% + )%\n% +) ELSE SETLOCAL ENABLEDELAYEDEXPANSION^&SETLOCAL^&SET argv=, + +:: @counter NumVar +:: +:: When called it uses the NumVar as an accumulator. If the +:: NumVar variable is not set it is initialized. +:: +SET @counter=FOR %%. IN (1 2) DO IF [%%.] EQU [2] (%\n% + FOR /f "tokens=1 delims=, " %%1 IN ("!argv!") DO ( ENDLOCAL%\n% + SET "numVar=%%~1"%\n% + IF ["!numVar!"] EQU [""] (%\n% + SET /A "count=0"%\n% + ) ELSE (%\n% + SET /A "count=!numVar!"%\n% + )%\n% + SET /A "count+=1"%\n% + FOR /F "delims=" %%V IN ("!count!") DO ENDLOCAL^&SET "%%~1=%%V"%\n% + )%\n% +) ELSE SETLOCAL ENABLEDELAYEDEXPANSION^&SETLOCAL^&SET argv=, + +:: @exit [ErrorLevel] +:: +:: Used to exit and optionally sets an error code if provided. +:: This is prefered for exiting a script over GOTO :EOF for consistency +:: and to pass Error Levels if necessery. This tidy's up a call +:: to EXIT /B [ErrorLevel] so the use feels the same as other macros. +:: +SET @exit=FOR %%. IN (1 2) DO IF [%%.] EQU [2] (%\n% + FOR /F "tokens=1 delims=, " %%1 IN ("!argv! 0") DO ( ENDLOCAL%\n% + IF ["%%~1"] NEQ [""] (IF DEFINED %%~1 (SET "exitCode=!%%1!"%\n% + ) ELSE (SET "exitCode=%%~1")%\n% + ) ELSE (SET "exitCode=0")%\n% + EXIT /B !exitCode!%\n% + )%\n% +) ELSE SETLOCAL ENABLEDELAYEDEXPANSION^&SETLOCAL^&SET argv=, + +GOTO :MAIN +:: -------- End macro definitions ---------- +%=- End Macro Definitions -=% + + +%=- Parse Command Line Arguments -=% +:PARSE_ARGS +SET "SCRIPT=%~dpnx0" +SET "SCRIPT_NAME=%~nx0" +SET "DATA_FILE=" + +FOR %%a IN (%*) DO ( + SET "arg=%%~a" + IF ["!arg:~0,1!"] EQU ["/"] ( + SHIFT /1 + SET "opt=!arg:~1,1!" + :: /H [Help] + IF /I ["!opt!"] EQU ["H"] ( + SET "opt=" + CALL :USAGE + %@exit% 1 + ) + :: /A [ANSI] + IF /I ["!opt!"] EQU ["A"] ( + SET "opt=" + SET "SHOW.ANSI=#TRUE#" + ) + :: /R [R1C1] + IF /I ["!opt!"] EQU ["R"] ( + SET "opt=" + SET "SHOW.R1C1_REFERENCE=#TRUE#" + ) + :: /U [UTF-8] + IF /I ["!opt!"] EQU ["U"] ( + SET "opt=" + SET "SHOW.UTF8=#TRUE#" + ) + IF ["!opt!"] NEQ [""] ( + SET "msg=Error: Unknown option: !opt!" + CALL :USAGE msg + %@exit% 2 + ) + ) +) + +:: If there isn't a definition passed on the command-line +:: default to using this script as the definition file. +IF [%~1] EQU [] ( + SET "DATA_FILE=!SCRIPT!" +) ELSE ( + SET "DATA_FILE=%~1" +) + +:: Verify that the definition file exists and exit with +:: error code 3 if it doesn't. +IF NOT EXIST !DATA_FILE! ( + SET "msg=Error: File does not exist: !DATA_FILE!" + CALL :USAGE msg + %@exit% 3 +) + +%@exit% + + +:: CALL :USAGE MsgVar +:: +:: When called with a MsgVar, it will prepend the usage +:: output message with the custom string message assigned +:: to MsgVar. This is used to further explain the error. +:: +:USAGE +SET "SCRIPT_NAME=%~nx0" + +:: The following ECHO intentionally has 80 spaces to clear the +:: line any remaining onscreen text on call. +ECHO. +IF [%1] NEQ [] ( + ECHO !%1! + ECHO. +) +ECHO Usage: !SCRIPT_NAME! [flags] [^] +ECHO. +ECHO This file echoes a bunch of color codes to the terminal to demonstrate +ECHO how they will render. The `Data Segment` portion of the file defines the +ECHO table layout and allows the user to configure whatever matrix of ANSI +ECHO Escape Sequence control characters they wish. This can also be read from +ECHO an external definition file using the same structure. +ECHO. +ECHO Flags: +ECHO /H : This message +ECHO /A : Display the ANSI Escape Sequence control characters +ECHO /R : Show cell R1C1 reference addressing instead of cell text +ECHO /U : Enable UTF-8 support +ECHO. +ECHO The script itself only has one external dependency on CHCP if you want +ECHO to show Unicode text. This just sets the Command Prompt codepage to 65001 +ECHO and will restore it when the script successfully completes. +ECHO. + +%@exit% + +%=- End Parse Command Line Arguments -=% + +:: +:: Inspired by Daniel Crisman's BASH script from http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html +:: +:: #!/bin/bash +:: # +:: # This file echoes a bunch of color codes to the +:: # terminal to demonstrate what's available. Each +:: # line is the color code of one forground color, +:: # out of 17 (default + 16 escapes), followed by a +:: # test use of that color on all nine background +:: # colors (default + 8 escapes). +:: # +:: +:: T='gYw' # The test text +:: +:: echo -e "\n 40m 41m 42m 43m\ +:: 44m 45m 46m 47m"; +:: +:: for FGs in ' m' ' 1m' ' 30m' '1;30m' ' 31m' '1;31m' ' 32m' \ +:: '1;32m' ' 33m' '1;33m' ' 34m' '1;34m' ' 35m' '1;35m' \ +:: ' 36m' '1;36m' ' 37m' '1;37m'; +:: do FG=${FGs// /} +:: echo -en " $FGs \033[$FG $T " +:: for BG in 40m 41m 42m 43m 44m 45m 46m 47m; +:: do echo -en "$EINS \033[$FG\033[$BG $T \033[0m"; +:: done +:: echo; +:: done +:: echo +:: diff --git a/src/tools/ansi-color/ansi-colortool.def b/src/tools/ansi-color/ansi-colortool.def new file mode 100644 index 00000000000..c5f501f8bc5 --- /dev/null +++ b/src/tools/ansi-color/ansi-colortool.def @@ -0,0 +1,53 @@ +:: ColorTool equivalent (ColorTool.exe -c) - Modified with ANSI table line drawing +__DATA__ +__TABLE__ +SET "UTF8.REQUIRED=#TRUE#" +:: The test text +SET "CELL= gYw " +:: Alignment properties for the cells and headers +SET "ALIGN.CELL=C" +SET "ALIGN.BOXHEAD=C" +SET "ALIGN.STUB=L" +SET "ALIGN.STUBHEAD=C" +:: For testing +SET "STUBHEAD=ANSI" +SET "SEPARATOR.STUBHEAD_BOXHEAD=║" +SET "SEPARATOR.STUB_BODY=║" +SET "SEPARATOR.STUBHEAD_STUB=─" +SET "SEPARATOR.BOXHEAD_BODY=─" +SET "SEPARATOR.INTERSECT=─╫─" +SET "SEPARATOR.BOXHEAD=│" +SET "SEPARATOR.CELL=│" +__TABLE:END__ +__COLS__ +#NUL# +40m +41m +42m +43m +44m +45m +46m +47m +__COLS:END__ +__ROWS__ +m +1m +30m +1;30m +31m +1;31m +32m +1;32m +33m +1;33m +34m +1;34m +35m +1;35m +36m +1;36m +37m +1;37m +__ROWS:END__ +__DATA:END__ \ No newline at end of file diff --git a/src/tools/ansi-color/colortest.def b/src/tools/ansi-color/colortest.def new file mode 100644 index 00000000000..ce9c7cfa012 --- /dev/null +++ b/src/tools/ansi-color/colortest.def @@ -0,0 +1,52 @@ +:: Extended ColorTool equivalent (ColorTool.exe -c) to show more colors, but requires 107 columns +__DATA__ +__TABLE__ +:: The test text +SET "CELL= gYw " +:: Alignment properties for the cells and headers +SET "ALIGN.CELL=C" +SET "ALIGN.BOXHEAD=C" +SET "ALIGN.STUB=L" +:: Table spacing +SET "SEPARATOR.CELL= " +SET "SEPARATOR.STUB= " +__TABLE:END__ +__COLS__ +#NUL# +40m +100m +41m +101m +42m +102m +43m +103m +44m +104m +45m +105m +46m +106m +47m +107m +__COLS:END__ +__ROWS__ +#NUL# +30m +90m +31m +91m +32m +92m +33m +93m +34m +94m +35m +95m +36m +96m +37m +97m +__ROWS:END__ +__DATA:END__ \ No newline at end of file diff --git a/src/tools/ansi-color/colortool.def b/src/tools/ansi-color/colortool.def new file mode 100644 index 00000000000..e5edb1daa9f --- /dev/null +++ b/src/tools/ansi-color/colortool.def @@ -0,0 +1,45 @@ +:: ColorTool equivalent (ColorTool.exe -c) +__DATA__ +__TABLE__ +:: The test text +SET "CELL= gYw " +:: Alignment properties for the cells and headers +SET "ALIGN.CELL=C" +SET "ALIGN.BOXHEAD=C" +SET "ALIGN.STUB=L" +:: Table spacing +SET "SEPARATOR.CELL= " +SET "SEPARATOR.STUB= " +__TABLE:END__ +__COLS__ +#NUL# +40m +41m +42m +43m +44m +45m +46m +47m +__COLS:END__ +__ROWS__ +m +1m +30m +1;30m +31m +1;31m +32m +1;32m +33m +1;33m +34m +1;34m +35m +1;35m +36m +1;36m +37m +1;37m +__ROWS:END__ +__DATA:END__ \ No newline at end of file diff --git a/src/tools/ansi-color/crisman.def b/src/tools/ansi-color/crisman.def new file mode 100644 index 00000000000..cc4f92bb29e --- /dev/null +++ b/src/tools/ansi-color/crisman.def @@ -0,0 +1,78 @@ +:: #!/bin/bash +:: # +:: # This file echoes a bunch of color codes to the +:: # terminal to demonstrate what's available. Each +:: # line is the color code of one forground color, +:: # out of 17 (default + 16 escapes), followed by a +:: # test use of that color on all nine background +:: # colors (default + 8 escapes). +:: # +:: +:: T='gYw' # The test text +:: +:: echo -e "\n 40m 41m 42m 43m\ +:: 44m 45m 46m 47m"; +:: +:: for FGs in ' m' ' 1m' ' 30m' '1;30m' ' 31m' '1;31m' ' 32m' \ +:: '1;32m' ' 33m' '1;33m' ' 34m' '1;34m' ' 35m' '1;35m' \ +:: ' 36m' '1;36m' ' 37m' '1;37m'; +:: do FG=${FGs// /} +:: echo -en " $FGs \033[$FG $T " +:: for BG in 40m 41m 42m 43m 44m 45m 46m 47m; +:: do echo -en "$EINS \033[$FG\033[$BG $T \033[0m"; +:: done +:: echo; +:: done +:: echo + +:: This is the recreation of the TLDP.org bash script output +__DATA__ +__TABLE__ +:: Greatest mystery ever. Why gYw? +SET "CELL= gYw " +:: The stub is right justified +SET "ALIGN.STUB=R" +:: The box header is centered over each column +SET "ALIGN.BOXHEAD=C" +:: There is a space between the stub and the rest of the table +SET "SEPARATOR.STUB= " +:: Each column is separated by a space +SET "SEPARATOR.COL= " +:: The widest stub label is 5 characters, but the original table uses 6 for the stub, producing a leading space +SET /A "STUB.MAX_WIDTH=6" +__TABLE:END__ +:: Background +__COLS__ +:: A column with no background attributes applied +#NUL# +40m +41m +42m +43m +44m +45m +46m +47m +__COLS:END__ +:: Foreground +__ROWS__ +m +1m +30m +1;30m +31m +1;31m +32m +1;32m +33m +1;33m +34m +1;34m +35m +1;35m +36m +1;36m +37m +1;37m +__ROWS:END__ +__DATA:END__ \ No newline at end of file diff --git a/src/tools/ansi-color/plaid.def b/src/tools/ansi-color/plaid.def new file mode 100644 index 00000000000..4d498f0badb --- /dev/null +++ b/src/tools/ansi-color/plaid.def @@ -0,0 +1,54 @@ +:: Uses Unicode Block Element Shade Characters to show a dithered mix of foreground and background colors +__DATA__ +__TABLE__ +SET "UTF8.REQUIRED=#TRUE#" +:: The test text +REM SET "CELL= ░▒▓█" +SET "CELL=░▒▓" +SET "STUBHEAD=plaid" +:: Separator characters for cells and headers +SET "SEPARATOR.STUBHEAD_BOXHEAD=│" +SET "SEPARATOR.STUBHEAD_STUB=─" +SET "SEPARATOR.INTERSECT=┘" +__TABLE:END__ + +:: Background +__COLS__ +40m +41m +42m +43m +44m +45m +46m +47m +100m +101m +102m +103m +104m +105m +106m +107m +__COLS:END__ + +:: [Intensity;][Attribute;]Foreground +__ROWS__ +30m +31m +32m +33m +34m +35m +36m +37m +90m +91m +92m +93m +94m +95m +96m +97m +__ROWS:END__ +__DATA:END__ \ No newline at end of file diff --git a/src/tools/ansi-color/rainbow.def b/src/tools/ansi-color/rainbow.def new file mode 100644 index 00000000000..50a1bbae6e2 --- /dev/null +++ b/src/tools/ansi-color/rainbow.def @@ -0,0 +1,52 @@ +:: Like the colortest definition, but arranged to show the colors as ROY G. BIV, dark then light +__DATA__ +__TABLE__ +:: The test text +SET "CELL= gYw " +:: Alignment properties for the cells and headers +SET "ALIGN.CELL=C" +SET "ALIGN.BOXHEAD=C" +SET "ALIGN.STUB=L" +:: Table spacing +SET "SEPARATOR.CELL= " +SET "SEPARATOR.STUB= " +__TABLE:END__ +__COLS__ +#NUL# +40m +47m +41m +45m +44m +46m +42m +43m +101m +105m +104m +106m +102m +103m +100m +107m +__COLS:END__ +__ROWS__ +#NUL# +30m +37m +31m +35m +34m +36m +32m +33m +91m +95m +94m +96m +92m +93m +90m +97m +__ROWS:END__ +__DATA:END__ \ No newline at end of file diff --git a/src/tools/ansi-color/rosetta.def b/src/tools/ansi-color/rosetta.def new file mode 100644 index 00000000000..148b7165e82 --- /dev/null +++ b/src/tools/ansi-color/rosetta.def @@ -0,0 +1,40 @@ +:: https://rosettacode.org/wiki/Terminal_control/Coloured_text#ooRexx +__DATA__ +:: Background +__COLS__ +#NUL# +40m +41m +42m +43m +44m +45m +46m +47m +__COLS:END__ +:: Foreground +__ROWS__ +0m +1m +0;30m +1;30m +0;31m +1;31m +0;32m +1;32m +0;33m +1;33m +0;34m +1;34m +0;35m +1;35m +0;36m +1;36m +0;37m +1;37m +4m +5m +7m +8m +__ROWS:END__ +__DATA:END__ \ No newline at end of file diff --git a/src/tools/ansi-color/sgr-intensity.def b/src/tools/ansi-color/sgr-intensity.def new file mode 100644 index 00000000000..4742e1bf51c --- /dev/null +++ b/src/tools/ansi-color/sgr-intensity.def @@ -0,0 +1,142 @@ +:: Check SGR intensity attributes, requires 100 columns +__DATA__ +__TABLE__ +:: The test text +SET "CELL= gYw " +SET "STUBHEAD=SGR Intensity " +:: Alignment properties for the cells and headers +REM SET "ALIGN.CELL=C" +REM SET "ALIGN.BOXHEAD=R" +REM SET "ALIGN.STUB=L" +REM SET "ALIGN.STUBHEAD=C" +:: Separator characters for cells and headers +REM SET "SEPARATOR.STUB= " +REM SET "SEPARATOR.STUB=│" +REM SET "SEPARATOR.BOXHEAD= " +REM SET "SEPARATOR.BOXHEAD=─" +REM SET "SEPARATOR.COL= " +REM SET "SEPARATOR.COL=╎" +REM SET "SEPARATOR.STUBHEAD_BOXHEAD= " +REM Can't use pipe or exclamation point as a separator +SET "SEPARATOR.STUBHEAD_BOXHEAD=:" +REM SET "SEPARATOR.STUBHEAD_BOXHEAD=▓▓" +REM SET "SEPARATOR.STUBHEAD_STUB= " +REM SET "SEPARATOR.STUBHEAD_STUB=─" +SET "SEPARATOR.STUBHEAD_STUB=-" +REM SET "SEPARATOR.STUBHEAD_STUB=▓" +REM SET "SEPARATOR.INTERSECT= " +REM SET "SEPARATOR.INTERSECT=┼" +REM SET "SEPARATOR.INTERSECT=┘" +SET "SEPARATOR.INTERSECT=+" +REM SET "SEPARATOR.INTERSECT=▓▒▒░" +REM SET "SEPARATOR.BOXHEAD_BODY= " +REM SET "SEPARATOR.BOXHEAD_BODY=─" +REM SET "SEPARATOR.BOXHEAD_BODY=░" +REM SET "SEPARATOR.STUB_BODY= " +REM SET "SEPARATOR.STUB_BODY=│" +REM SET "SEPARATOR.STUB_BODY=░░" +REM SET "SEPARATOR.BOXHEADERS= " +REM SET "SEPARATOR.BOXHEADERS=╎" +REM SET "SEPARATOR.CELL= " +REM SET "SEPARATOR.CELL=╎" +__TABLE:END__ + +:: Background +__COLS__ +#NUL# +40m +100m +41m +101m +42m +102m +43m +103m +44m +104m +45m +105m +46m +106m +47m +107m +__COLS:END__ + +:: [Intensity;][Attribute;]Foreground +__ROWS__ +:: Attributes +1m +#NUL# +2m +#SPC# +:: Normal +30m +90m +31m +91m +32m +92m +33m +93m +34m +94m +35m +95m +36m +96m +37m +97m +#SPC# +:: Bold or increased intensity, 1 +:: Normal +:: Faint (decreased intensity), 2 +1;30m + 30m +2;30m +1;90m + 90m +2;90m +1;31m + 31m +2;31m +1;91m + 91m +2;91m +1;32m + 32m +2;32m +1;92m + 92m +2;92m +1;33m + 33m +2;33m +1;93m + 93m +2;93m +1;34m + 34m +2;34m +1;94m + 94m +2;94m +1;35m + 35m +2;35m +1;95m + 95m +2;95m +1;36m + 36m +2;36m +1;96m + 96m +2;96m +1;37m + 37m +2;37m +1;97m + 97m +2;97m +__ROWS:END__ +__DATA:END__ \ No newline at end of file diff --git a/src/tools/ansi-color/sgr.def b/src/tools/ansi-color/sgr.def new file mode 100644 index 00000000000..6205e8c210a --- /dev/null +++ b/src/tools/ansi-color/sgr.def @@ -0,0 +1,282 @@ +:: Complete matrix of SGR parameters available +:: This definition also demonstrates the various configuration changes +:: which are used to control the way the table is generated +:: Requires 142 columns to display correctly +__DATA__ +:: Select Graphic Rendition (SGR) parameters +:: #NUL# is treated as a special case to provide cells in that column +:: or row, but there is no row or column value applied to the cell. +:: This has the effect that the row or column has no SGR parameter applied +:: and so this will show the default. +__TABLE__ +SET "UTF8.REQUIRED=#TRUE#" +:: The test text +SET "CELL= gYw " +SET "STUBHEAD=SGR" +:: Alignment properties for the cells and headers +REM SET "ALIGN.CELL=C" +REM SET "ALIGN.BOXHEAD=R" +REM SET "ALIGN.STUB=L" +REM SET "ALIGN.STUBHEAD=C" +:: Separator characters for cells and headers +REM SET "SEPARATOR.STUB= " +REM SET "SEPARATOR.STUB=│" +REM SET "SEPARATOR.BOXHEAD= " +REM SET "SEPARATOR.BOXHEAD=─" +REM SET "SEPARATOR.COL= " +REM SET "SEPARATOR.COL=╎" +REM SET "SEPARATOR.STUBHEAD_BOXHEAD= " +SET "SEPARATOR.STUBHEAD_BOXHEAD=│" +REM SET "SEPARATOR.STUBHEAD_BOXHEAD=▓▓" +REM SET "SEPARATOR.STUBHEAD_STUB= " +SET "SEPARATOR.STUBHEAD_STUB=─" +REM SET "SEPARATOR.STUBHEAD_STUB=▓" +REM SET "SEPARATOR.INTERSECT= " +REM SET "SEPARATOR.INTERSECT=┼" +SET "SEPARATOR.INTERSECT=┘" +REM SET "SEPARATOR.INTERSECT=▓▒▒░" +REM SET "SEPARATOR.BOXHEAD_BODY= " +REM SET "SEPARATOR.BOXHEAD_BODY=─" +REM SET "SEPARATOR.BOXHEAD_BODY=░" +REM SET "SEPARATOR.STUB_BODY= " +REM SET "SEPARATOR.STUB_BODY=│" +REM SET "SEPARATOR.STUB_BODY=░░" +REM SET "SEPARATOR.BOXHEADERS= " +REM SET "SEPARATOR.BOXHEADERS=╎" +REM SET "SEPARATOR.CELL= " +REM SET "SEPARATOR.CELL=╎" +__TABLE:END__ + +:: Background +__COLS__ +#NUL# +1m +2m +3m +4m +5m +6m +7m +8m +9m +21m +40m +100m +41m +101m +42m +102m +43m +103m +44m +104m +45m +105m +46m +106m +47m +107m +__COLS:END__ + +:: [Intensity;][Attribute;]Foreground +__ROWS__ +#NUL# +1m +2m +3m +4m +5m +6m +7m +8m +9m +21m +:: Normal +30m +90m +31m +91m +32m +92m +33m +93m +34m +94m +35m +95m +36m +96m +37m +97m +:: Bold or increased intensity, 1 +1;30m +1;90m +1;31m +1;91m +1;32m +1;92m +1;33m +1;93m +1;34m +1;94m +1;35m +1;95m +1;36m +1;96m +1;37m +1;97m +:: Faint (decreased intensity), 2 +2;30m +2;90m +2;31m +2;91m +2;32m +2;92m +2;33m +2;93m +2;34m +2;94m +2;35m +2;95m +2;36m +2;96m +2;37m +2;97m +:: Italic, 3 +3;30m +3;90m +3;31m +3;91m +3;32m +3;92m +3;33m +3;93m +3;34m +3;94m +3;35m +3;95m +3;36m +3;96m +3;37m +3;97m +:: Underline, 4 +4;30m +4;90m +4;31m +4;91m +4;32m +4;92m +4;33m +4;93m +4;34m +4;94m +4;35m +4;95m +4;36m +4;96m +4;37m +4;97m +:: Slow Blink, 5 +5;30m +5;90m +5;31m +5;91m +5;32m +5;92m +5;33m +5;93m +5;34m +5;94m +5;35m +5;95m +5;36m +5;96m +5;37m +5;97m +:: Rapid Blink, 6 +6;30m +6;90m +6;31m +6;91m +6;32m +6;92m +6;33m +6;93m +6;34m +6;94m +6;35m +6;95m +6;36m +6;96m +6;37m +6;97m +:: Reverse video, 7 +7;30m +7;90m +7;31m +7;91m +7;32m +7;92m +7;33m +7;93m +7;34m +7;94m +7;35m +7;95m +7;36m +7;96m +7;37m +7;97m +:: Conceal, 8 +8;30m +8;90m +8;31m +8;91m +8;32m +8;92m +8;33m +8;93m +8;34m +8;94m +8;35m +8;95m +8;36m +8;96m +8;37m +8;97m +:: Crossed-out, 9 +9;30m +9;90m +9;31m +9;91m +9;32m +9;92m +9;33m +9;93m +9;34m +9;94m +9;35m +9;95m +9;36m +9;96m +9;37m +9;97m +:: Double Underline, 21 +21;30m +21;90m +21;31m +21;91m +21;32m +21;92m +21;33m +21;93m +21;34m +21;94m +21;35m +21;95m +21;36m +21;96m +21;37m +21;97m +__ROWS:END__ +__DATA:END__ \ No newline at end of file diff --git a/src/tools/ansi-color/tsgr.def b/src/tools/ansi-color/tsgr.def new file mode 100644 index 00000000000..70cd133054e --- /dev/null +++ b/src/tools/ansi-color/tsgr.def @@ -0,0 +1,273 @@ +:: Complete matrix of SGR parameters available, but transposed +:: This definition is like SGR but for each row, all attributes are applied +:: per foreground color instead of incrementing on the attributes +:: ForEach(fg in Foreground) { ForEach(a in Attribute) { a;fm }} instead of +:: ForEach(a in Attribute) { ForEach(fg in Foreground) { a;fm }} +__DATA__ +:: Select Graphic Rendition (SGR) parameters +:: #NUL# is treated as a special case to provide cells in that column +:: or row, but there is no row or column value applied to the cell. +:: This has the effect that the row or column has no SGR parameter applied +:: and so this will show the default. +__TABLE__ +SET "UTF8.REQUIRED=#TRUE#" +:: The test text +REM SET "CELL= ЯMB " +SET "CELL= gYw " +SET "STUBHEAD=tSGR" +:: Alignment properties for the cells and headers +REM SET "ALIGN.CELL=C" +REM SET "ALIGN.BOXHEAD=R" +REM SET "ALIGN.STUB=L" +REM SET "ALIGN.STUBHEAD=C" +:: Separator characters for cells and headers +REM SET "SEPARATOR.STUB= " +REM SET "SEPARATOR.STUB=│" +REM SET "SEPARATOR.BOXHEAD= " +REM SET "SEPARATOR.BOXHEAD=─" +REM SET "SEPARATOR.COL= " +REM SET "SEPARATOR.COL=╎" +REM SET "SEPARATOR.STUBHEAD_BOXHEAD= " +SET "SEPARATOR.STUBHEAD_BOXHEAD=│" +REM SET "SEPARATOR.STUBHEAD_BOXHEAD=▓▓" +REM SET "SEPARATOR.STUBHEAD_STUB= " +SET "SEPARATOR.STUBHEAD_STUB=─" +REM SET "SEPARATOR.STUBHEAD_STUB=▓" +REM SET "SEPARATOR.INTERSECT= " +REM SET "SEPARATOR.INTERSECT=┼" +SET "SEPARATOR.INTERSECT=┘" +REM SET "SEPARATOR.INTERSECT=▓▒▒░" +REM SET "SEPARATOR.BOXHEAD_BODY= " +REM SET "SEPARATOR.BOXHEAD_BODY=─" +REM SET "SEPARATOR.BOXHEAD_BODY=░" +REM SET "SEPARATOR.STUB_BODY= " +REM SET "SEPARATOR.STUB_BODY=│" +REM SET "SEPARATOR.STUB_BODY=░░" +REM SET "SEPARATOR.BOXHEADERS= " +REM SET "SEPARATOR.BOXHEADERS=╎" +REM SET "SEPARATOR.CELL= " +REM SET "SEPARATOR.CELL=╎" +__TABLE:END__ + +:: Background +__COLS__ +#NUL# +1m +2m +3m +4m +5m +6m +7m +8m +9m +21m +40m +100m +41m +101m +42m +102m +43m +103m +44m +104m +45m +105m +46m +106m +47m +107m +__COLS:END__ + +:: [Intensity;][Attribute;]Foreground +__ROWS__ +#NUL# +1m +2m +3m +4m +5m +6m +7m +8m +9m +21m +30m +1;30m +2;30m +3;30m +4;30m +5;30m +6;30m +7;30m +8;30m +9;30m +21;30m +90m +1;90m +2;90m +3;90m +4;90m +5;90m +6;90m +7;90m +8;90m +9;90m +21;90m +31m +1;31m +2;31m +3;31m +4;31m +5;31m +6;31m +7;31m +8;31m +9;31m +21;31m +91m +1;91m +2;91m +3;91m +4;91m +5;91m +6;91m +7;91m +8;91m +9;91m +21;91m +32m +1;32m +2;32m +3;32m +4;32m +5;32m +6;32m +7;32m +8;32m +9;32m +21;32m +92m +1;92m +2;92m +3;92m +4;92m +5;92m +6;92m +7;92m +8;92m +9;92m +21;92m +33m +1;33m +2;33m +3;33m +4;33m +5;33m +6;33m +7;33m +8;33m +9;33m +21;33m +93m +1;93m +2;93m +3;93m +4;93m +5;93m +6;93m +7;93m +8;93m +9;93m +21;93m +34m +1;34m +2;34m +3;34m +4;34m +5;34m +6;34m +7;34m +8;34m +9;34m +21;34m +94m +1;94m +2;94m +3;94m +4;94m +5;94m +6;94m +7;94m +8;94m +9;94m +21;94m +35m +1;35m +2;35m +3;35m +4;35m +5;35m +6;35m +7;35m +8;35m +9;35m +21;35m +95m +1;95m +2;95m +3;95m +4;95m +5;95m +6;95m +7;95m +8;95m +9;95m +21;95m +36m +1;36m +2;36m +3;36m +4;36m +5;36m +6;36m +7;36m +8;36m +9;36m +21;36m +96m +1;96m +2;96m +3;96m +4;96m +5;96m +6;96m +7;96m +8;96m +9;96m +21;96m +37m +1;37m +2;37m +3;37m +4;37m +5;37m +6;37m +7;37m +8;37m +9;37m +21;37m +97m +1;97m +2;97m +3;97m +4;97m +5;97m +6;97m +7;97m +8;97m +9;97m +21;97m +__ROWS:END__ +__DATA:END__ \ No newline at end of file diff --git a/src/tools/ansi-color/ubuntu.def b/src/tools/ansi-color/ubuntu.def new file mode 100644 index 00000000000..c68babad917 --- /dev/null +++ b/src/tools/ansi-color/ubuntu.def @@ -0,0 +1,41 @@ +:: https://askubuntu.com/questions/27314/script-to-display-all-terminal-colors +__DATA__ +__TABLE__ +:: The test text +SET "CELL= gYw " +SET "SEPARATOR.CELL= " +__TABLE:END__ +:: Background +__COLS__ +#NUL# +40m +41m +42m +43m +44m +45m +46m +47m +__COLS:END__ +:: Foreground +__ROWS__ +m +1m +30m +1;30m +31m +1;31m +32m +1;32m +33m +1;33m +34m +1;34m +35m +1;35m +36m +1;36m +37m +1;37m +__ROWS:END__ +__DATA:END__ \ No newline at end of file From 2e5006520d36bd22367467e01926b7227d8d8ab9 Mon Sep 17 00:00:00 2001 From: Ryan Beesley Date: Sun, 12 Dec 2021 21:49:18 -0800 Subject: [PATCH 16/35] Add README.md --- src/tools/ansi-color/README.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/tools/ansi-color/README.md diff --git a/src/tools/ansi-color/README.md b/src/tools/ansi-color/README.md new file mode 100644 index 00000000000..f3ccd4ff829 --- /dev/null +++ b/src/tools/ansi-color/README.md @@ -0,0 +1,29 @@ +# ANSI-COLOR + +Ansi-Color.cmd makes it easy to render SGR attributes, foreground colors, and background colors, in a table. This complements ColorTool for diagnostics purposes and seeing all the colors of the applied color scheme. + +```plain +Usage: ansi-color.cmd [flags] [] + + This file echoes a bunch of color codes to the terminal to demonstrate + how they will render. The `Data Segment` portion of the file defines the + table layout and allows the user to configure whatever matrix of ANSI + Escape Sequence control characters they wish. This can also be read from + an external definition file using the same structure. + + Flags: + /H : This message + /A : Display the ANSI Escape Sequence control characters + /R : Show cell R1C1 reference addressing instead of cell text + /U : Enable UTF-8 support + + The script itself only has one external dependency on CHCP if you want + to show Unicode text. This just sets the Command Prompt codepage to 65001 + and will restore it when the script successfully completes. + ``` + + The entire tool is written as a Windows Command script and the only dependency is on the stock CHCP tool which can be used to change the command prompt code page. The script makes heavy use of Batch "macros," a concept originally explored by Ed Dyreen, Jeb, and Dave Benham on [DosTips.com](https://www.dostips.com/forum/viewtopic.php?f=3&t=1827). The use of macros in Ansi-Color allow complex results and capable of generating tables defined as separate files. + + Of notable interest, the script itself is its own definition file and doesn't require external definition files to work. In fact, the script file itself is just a UTF-8 text file which can easily be edited, doesn't need to be recompiled, and has configuration settings embedded in it, or it can use flags passed as arguments. Additionally, several definition files are included which replicate the output of similar tools. + + Lastly, there are two diagnostic modes which might be useful when writing color schemes. `/A` is a flag which instead of showing the output table, it replaces the actual ESC code in the output string with the Unicode codepoint representation of an ESC character, and when redirected from standard out to a file like `ansi-color /a > out.txt` it will create a text file which shows what would have been generated. This makes it easier to find errors in how something rendered. Additionally the `/R` flag borrows the Excel R1C1 reference address scheme to replace the Cell text with row/column IDs. In this way you can generate a table and then identify a combination of attributes and colors by that corresponding reference. \ No newline at end of file From eadb9a8e65f9d37cec470ef591a9f63145ae2f3a Mon Sep 17 00:00:00 2001 From: Ryan Beesley Date: Sun, 12 Dec 2021 22:02:47 -0800 Subject: [PATCH 17/35] Satisfy check-spelling-bot --- .../spelling/expect/3256befcdd607f6e22705a1348ee49997f90330f.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/tools/ansi-color/.github/actions/spelling/expect/3256befcdd607f6e22705a1348ee49997f90330f.txt diff --git a/src/tools/ansi-color/.github/actions/spelling/expect/3256befcdd607f6e22705a1348ee49997f90330f.txt b/src/tools/ansi-color/.github/actions/spelling/expect/3256befcdd607f6e22705a1348ee49997f90330f.txt new file mode 100644 index 00000000000..e69de29bb2d From 008da547a89fa9bcf4b101b909e3b1107c61d4e1 Mon Sep 17 00:00:00 2001 From: Ryan Beesley Date: Mon, 13 Dec 2021 00:32:45 -0800 Subject: [PATCH 18/35] Fixed missing files for spell-check-bot script --- ...5c1ec487b80f127ca611d10b973f66d9ed6812.txt | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/actions/spelling/expect/205c1ec487b80f127ca611d10b973f66d9ed6812.txt diff --git a/.github/actions/spelling/expect/205c1ec487b80f127ca611d10b973f66d9ed6812.txt b/.github/actions/spelling/expect/205c1ec487b80f127ca611d10b973f66d9ed6812.txt new file mode 100644 index 00000000000..a05e335621b --- /dev/null +++ b/.github/actions/spelling/expect/205c1ec487b80f127ca611d10b973f66d9ed6812.txt @@ -0,0 +1,34 @@ +askubuntu +BIV +boxheader +colortest +Crisman +DISABLEDELAYEDEXPANSION +dostips +dpnx +Dyreen +EINS +EQU +FGs +forground +GTR +HOWTO +Initalize +ltrim +maxval +necessery +onscreen +outstr +properites +Rexx +rosettacode +ROY +Rtn +rtrim +seperate +STUBHEAD +tldp +uwaterloo +uwspace +viewtopic +wrkstr From 6a75e75e6c98900ce284479cd9cc546febcbfe92 Mon Sep 17 00:00:00 2001 From: Ryan Beesley Date: Mon, 13 Dec 2021 00:39:33 -0800 Subject: [PATCH 19/35] Deleting spell-check-bot file placed incorrectly --- .../spelling/expect/3256befcdd607f6e22705a1348ee49997f90330f.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/tools/ansi-color/.github/actions/spelling/expect/3256befcdd607f6e22705a1348ee49997f90330f.txt diff --git a/src/tools/ansi-color/.github/actions/spelling/expect/3256befcdd607f6e22705a1348ee49997f90330f.txt b/src/tools/ansi-color/.github/actions/spelling/expect/3256befcdd607f6e22705a1348ee49997f90330f.txt deleted file mode 100644 index e69de29bb2d..00000000000 From 9252afd4d6045d07aba6ec14ea9589cf29d9fa00 Mon Sep 17 00:00:00 2001 From: Ryan Beesley Date: Tue, 14 Dec 2021 01:17:24 -0800 Subject: [PATCH 20/35] Improved spelling, comments, error handling Added a way to get the errorlevel from the CHCP call. If it fails, we can still use the result if there isn't a need for UTF-8. This should be more robust and should allow things to work even if CHCP isn't on a system for some reason. The consideration is that there might be a localization where this doesn't work so try to fail gracefuly. I also cleaned up the way help and internal errors are handled better now. Requesting help doesn't set an error level for internal commands, so this app won't either. Finally, addressed the speling errers I had in the first checkin. Forground (sic) is intentional because that is the spelling in the original BASH script. Other errors raised I corrected. I've tried to leave comments throughout, but if there is anything not understood, I can try to document it more. --- ...5c1ec487b80f127ca611d10b973f66d9ed6812.txt | 5 - src/tools/ansi-color/ansi-color.cmd | 182 ++++++------------ src/tools/ansi-color/crisman.def | 4 +- 3 files changed, 64 insertions(+), 127 deletions(-) diff --git a/.github/actions/spelling/expect/205c1ec487b80f127ca611d10b973f66d9ed6812.txt b/.github/actions/spelling/expect/205c1ec487b80f127ca611d10b973f66d9ed6812.txt index a05e335621b..0252bd5aac8 100644 --- a/.github/actions/spelling/expect/205c1ec487b80f127ca611d10b973f66d9ed6812.txt +++ b/.github/actions/spelling/expect/205c1ec487b80f127ca611d10b973f66d9ed6812.txt @@ -13,19 +13,14 @@ FGs forground GTR HOWTO -Initalize ltrim maxval -necessery -onscreen outstr -properites Rexx rosettacode ROY Rtn rtrim -seperate STUBHEAD tldp uwaterloo diff --git a/src/tools/ansi-color/ansi-color.cmd b/src/tools/ansi-color/ansi-color.cmd index b9e8641b5ed..a63f7037e3d 100644 --- a/src/tools/ansi-color/ansi-color.cmd +++ b/src/tools/ansi-color/ansi-color.cmd @@ -1,17 +1,20 @@ -@ECHO OFF +@ECHO OFF & :: ANSI-COLOR :: Authored by Ryan Beesley :: https://github.com/rbeesley GOTO :DEFINE_MACROS %=- Entry point after macro definitions -=% :MAIN SETLOCAL ENABLEDELAYEDEXPANSION CALL :PARSE_ARGS %1 %2 %3 %4 %5 %6 %7 %8 %9 +:: Error when parsing IF ERRORLEVEL 1 %@exit% %ERRORLEVEL% - -REM ::Debug -- Use this to break after parsing arguments -REM CMD /C EXIT -1073741510 +:: Parsing success +IF ERRORLEVEL 0 GOTO :CONFIGURATION +:: Help requested, but this shouldn't actually be an error from CMDs perspective +IF ERRORLEVEL -1 %@exit% 0 %=- Configuration -=% +:CONFIGURATION :: Default test text if not defined in the data segment SET "CELL= gYw " :: Uncomment to use UTF-8 for output, such as when the test text is Unicode @@ -22,8 +25,6 @@ REM SET "SPINNER.DISABLED=#TRUE#" REM SET "SHOW.ANSI=#TRUE#" :: Uncomment to show cell R1C1 reference addressing instead of cell text REM SET "SHOW.R1C1_REFERENCE=#TRUE#" -:: Uncomment to turn on debug output for diagnosing separator resolution -REM SET "DEBUG.OUT=#TRUE#" %=- End Configuration -=% @@ -368,34 +369,62 @@ REM FOR /F "tokens=* USEBACKQ" %%G IN (`PowerShell -Command "[char]0x1B"`) DO (S SET "ESC=" :: If we're going to display the ANSI Escape Sequence control characters -:: save the active console Code Page, change to UTF-8, and override ESC +:: we require UTF-8, will disable the spinner, and override the ANSI ESC +:: character with a Unicode codepoint which represents ESC. IF DEFINED SHOW.ANSI ( + SET "UTF8.REQUIRED=#TRUE#" SET "SPINNER.DISABLED=#TRUE#" - REM SET "SHOW.UTF8=#TRUE#" ) :: The console (CMD) is normally not UTF-8, so preserve the codepage so we can reset it. :: Because the output of chcp is localized, we grab the last value of the string, :: which we have our fingers crossed, will be the codepage. -FOR /F "tokens=*" %%_ IN ('chcp') DO (SET CHCP_OUT=%%_) -FOR %%_ IN (!CHCP_OUT!) DO (SET CHCP=%%_) +FOR /F "tokens=*" %%_ IN ('chcp 2^>^&1 ^& FOR /F %%_ IN ^("ERRORLEVEL"^) DO @CALL ECHO __ERRORLEVEL__:%%%%_%%') DO ( + SET CHCP_OUT=%%_ + :: Check if the CHCP call failed + IF ["!CHCP_OUT:~0,15!"] EQU ["__ERRORLEVEL__:"] ( + SET "CHCP_ERR=!CHCP_OUT:__ERRORLEVEL__:=!" + IF [!CHCP_ERR!] EQU [9009] ( + REM This means that CHCP wasn't found + REM If the definition doesn't require UTF-8, this might be okay + REM CHCP_RET is no longer valid though, so undefine it + REM Interesting side note, this is an example where the :: can be used for REM + REM See https://stackoverflow.com/a/61981588 for more information + SET "CHCP_RET=" + ) ELSE IF [!CHCP_ERR!] NEQ [0] ( + ECHO Error: Unable to read active codepage + %@exit% !CHCP_ERR! + ) + ) ELSE ( + SET "CHCP_RET=!CHCP_OUT!" + ) +) + +:: If we didn't get an error, read the last value of the output string +FOR %%_ IN (!CHCP_RET!) DO (SET CHCP=%%_) IF DEFINED CHCP ( IF [!CHCP!] EQU [65001] ( SET "SHOW.UTF8=#TRUE#" ) ELSE ( IF DEFINED SHOW.UTF8 ( - chcp 65001>NUL + chcp 65001 > NUL 2>&1 + IF ERRORLEVEL 1 ( + ECHO Error: Unable to set the active codepage + %@exit% %ErrorLevel% + ) ) ) ) SET "CHCP_OUT=" +SET "CHCP_ERR=" +SET "CHCP_RET=" -:: This is a seperate code block so that the active console Code Page is changed first +:: This is a separate code block so that the active console Code Page is changed first IF DEFINED SHOW.ANSI ( SET "ESC=␛" ) -:: Control Sequence Introducer +:: Control Sequence Introducer (CSI) SET "CSI=!ESC![" :: Cursor Up @@ -421,7 +450,7 @@ IF DEFINED SHOW.R1C1_REFERENCE ( SET /A COL.MAX_WIDTH=7 ) -:: Default properites if not defined in the data segment +:: Default properties if not defined in the data segment :: See Figure 1.1 in the PDF for Wang Terminology :: https://uwspace.uwaterloo.ca/handle/10012/10962 @@ -460,7 +489,7 @@ SET "SEPARATOR.COLUMN=" :: build the table, and show the table CALL :READ_DATA_SEGMENT CALL :VALIDATE_CONFIGURATION -IF ERRORLEVEL 4 ( +IF ERRORLEVEL 1 ( %@exit% %ERRORLEVEL% ) CALL :RESOLVE_SEPARATORS @@ -469,7 +498,11 @@ CALL :DISPLAY_TABLE :: Restore the console Code Page saved at the beginning of the script IF DEFINED CHCP ( - chcp !CHCP!>NUL + chcp !CHCP! > NUL 2>&1 + IF ERRORLEVEL 1 ( + ECHO Error: Unable to reset the active codepage + %@exit% %ErrorLevel% + ) ) :: Exit @@ -494,19 +527,19 @@ FOR /F "delims=" %%_ IN (!DATA_FILE!) DO ( ) IF ["%%_"] EQU ["__ROWS__"] ( SET SEGMENT=ROWS - :: Initalize the row globals + :: Initialize the row globals SET /A ROW[#]=0 SET /A ROWS.LEN=0 ) IF ["%%_"] EQU ["__COLS__"] ( SET SEGMENT=COLS - :: Initalize the column globals + :: Initialize the column globals SET /A COL[#]=0 SET /A COLS.LEN=0 ) IF ["%%_"] EQU ["__TABLE__"] ( SET SEGMENT=TABLE - :: Initalize the table globals + :: Initialize the table globals SET /A TABLE[#]=0 ) IF ["%%_"] EQU ["__DATA__"] ( @@ -581,9 +614,9 @@ SET "ROW[!ROW[#]!]=!ROW!" IF DEFINED UTF8.REQUIRED ( IF NOT DEFINED SHOW.UTF8 ( SET "SCRIPT_NAME=%~nx0" - SET "msg=Error: Requested definition script requires UTF-8.!LF! Try ^"!SCRIPT_NAME! /U [^]^" to run with UTF-8 support!LF! or change the default configuration in !SCRIPT_NAME! to always use UTF-8." + SET "msg=Error: UTF-8 console support is required.!LF! Try ^"!SCRIPT_NAME! /U [^]^" to enable UTF-8 support!LF! or change the default configuration in !SCRIPT_NAME! to always use UTF-8." CALL :USAGE msg - %@exit% 4 + %@exit% 1 ) ) %@exit% @@ -592,36 +625,6 @@ IF DEFINED UTF8.REQUIRED ( :: Separators have cascading effects, so if some are not defined this is where :: they are defined :RESOLVE_SEPARATORS -IF DEFINED DEBUG.OUT ( - REM ::DEBUG - ECHO. - ECHO RESOLVE_SEPARATORS enter - ECHO. - ECHO SEPARATOR.COL : "!SEPARATOR.COL!" - ECHO SEPARATOR.BOXHEAD : "!SEPARATOR.BOXHEAD!" - ECHO SEPARATOR.INTERSECT : "!SEPARATOR.INTERSECT!" - ECHO SEPARATOR.STUB : "!SEPARATOR.STUB!" - ECHO SEPARATOR.CELL : "!SEPARATOR.CELL!" - - ECHO SEPARATOR.VERTICAL : "!SEPARATOR.VERTICAL!" - ECHO SEPARATOR.HORIZONTAL : "!SEPARATOR.HORIZONTAL!" - ECHO SEPARATOR.COLUMN : "!SEPARATOR.COLUMN!" - - ECHO STUBHEAD : "!STUBHEAD!" - - ECHO SEPARATOR.VERTICAL.WIDTH : "!SEPARATOR.VERTICAL.WIDTH!" - ECHO SEPARATOR.STUBHEAD_BOXHEAD : "!SEPARATOR.STUBHEAD_BOXHEAD!" - ECHO SEPARATOR.STUB_BODY : "!SEPARATOR.STUB_BODY!" - ECHO SEPARATOR.BOXHEADERS : "!SEPARATOR.BOXHEADERS!" - - ECHO SEPARATOR.STUBHEAD_STUB : "!SEPARATOR.STUBHEAD_STUB!" - ECHO SEPARATOR.BOXHEAD_BODY : "!SEPARATOR.BOXHEAD_BODY!" - - ECHO SEPARATOR.STUB_BOXHEAD_INTERSECT : "!SEPARATOR.STUB_BOXHEAD_INTERSECT!" - ECHO SEPARATOR.BOXHEAD_BODY_INTERSECT : "!SEPARATOR.BOXHEAD_BODY_INTERSECT!" - ECHO. - REM ::DEBUG -) :: Define the vertical separator IF DEFINED SEPARATOR.STUB ( @@ -705,24 +708,6 @@ IF DEFINED SEPARATOR.INTERSECT ( ) ) -IF DEFINED DEBUG.OUT ( - REM ::DEBUG - ECHO. - ECHO RESOLVE_SEPARATORS pre-trim - ECHO. - ECHO SEPARATOR.COL : "!SEPARATOR.COL!" - ECHO SEPARATOR.BOXHEAD : "!SEPARATOR.BOXHEAD!" - ECHO SEPARATOR.INTERSECT : "!SEPARATOR.INTERSECT!" - ECHO SEPARATOR.STUB : "!SEPARATOR.STUB!" - ECHO SEPARATOR.CELL : "!SEPARATOR.CELL!" - ECHO SEPARATOR.STUBHEAD_BOXHEAD : "!SEPARATOR.STUBHEAD_BOXHEAD!" - ECHO SEPARATOR.STUB_BODY : "!SEPARATOR.STUB_BODY!" - ECHO SEPARATOR.STUBHEAD_STUB : "!SEPARATOR.STUBHEAD_STUB!" - ECHO SEPARATOR.BOXHEAD_BODY : "!SEPARATOR.BOXHEAD_BODY!" - ECHO. - REM ::DEBUG -) - :: Trim the variables we use to draw our separators :: so we only work with non-space characters SET "SEPARATOR.COL.TRIM=!SEPARATOR.COL!" @@ -744,24 +729,6 @@ SET "SEPARATOR.STUBHEAD_STUB.TRIM=!SEPARATOR.STUBHEAD_STUB!" SET "SEPARATOR.BOXHEAD_BODY.TRIM=!SEPARATOR.BOXHEAD_BODY!" %@trim% SEPARATOR.BOXHEAD_BODY.TRIM -IF DEFINED DEBUG.OUT ( - REM ::DEBUG - ECHO. - ECHO RESOLVE_SEPARATORS post-trim - ECHO. - ECHO SEPARATOR.COL.TRIM : "!SEPARATOR.COL.TRIM!" - ECHO SEPARATOR.BOXHEAD.TRIM : "!SEPARATOR.BOXHEAD.TRIM!" - ECHO SEPARATOR.INTERSECT.TRIM : "!SEPARATOR.INTERSECT.TRIM!" - ECHO SEPARATOR.STUB.TRIM : "!SEPARATOR.STUB.TRIM!" - ECHO SEPARATOR.CELL.TRIM : "!SEPARATOR.CELL.TRIM!" - ECHO SEPARATOR.STUBHEAD_BOXHEAD.TRIM : "!SEPARATOR.STUBHEAD_BOXHEAD.TRIM!" - ECHO SEPARATOR.STUB_BODY.TRIM : "!SEPARATOR.STUB_BODY.TRIM!" - ECHO SEPARATOR.STUBHEAD_STUB.TRIM : "!SEPARATOR.STUBHEAD_STUB.TRIM!" - ECHO SEPARATOR.BOXHEAD_BODY.TRIM : "!SEPARATOR.BOXHEAD_BODY.TRIM!" - ECHO. - REM ::DEBUG -) - IF DEFINED SEPARATOR.VERTICAL ( IF DEFINED SEPARATOR.HORIZONTAL ( IF NOT DEFINED SEPARATOR.STUB_BOXHEAD_INTERSECT.TRIM ( @@ -807,35 +774,6 @@ IF DEFINED SEPARATOR.VERTICAL ( IF DEFINED SEPARATOR.STUB_BODY ( %@align% SEPARATOR.STUB_BODY !SEPARATOR.VERTICAL.WIDTH! C SEPARATOR.STUB_BODY ) ) -IF DEFINED DEBUG.OUT ( - REM ::DEBUG - ECHO. - ECHO RESOLVE_SEPARATORS exit - ECHO. - ECHO SEPARATOR.COL : "!SEPARATOR.COL!" - ECHO SEPARATOR.BOXHEAD : "!SEPARATOR.BOXHEAD!" - ECHO SEPARATOR.INTERSECT : "!SEPARATOR.INTERSECT!" - ECHO SEPARATOR.STUB : "!SEPARATOR.STUB!" - ECHO SEPARATOR.CELL : "!SEPARATOR.CELL!" - - ECHO SEPARATOR.VERTICAL : "!SEPARATOR.VERTICAL!" - ECHO SEPARATOR.HORIZONTAL : "!SEPARATOR.HORIZONTAL!" - ECHO SEPARATOR.COLUMN : "!SEPARATOR.COLUMN!" - - ECHO STUBHEAD : "!STUBHEAD!" - - ECHO SEPARATOR.VERTICAL.WIDTH : "!SEPARATOR.VERTICAL.WIDTH!" - ECHO SEPARATOR.STUBHEAD_BOXHEAD : "!SEPARATOR.STUBHEAD_BOXHEAD!" - ECHO SEPARATOR.STUB_BODY : "!SEPARATOR.STUB_BODY!" - ECHO SEPARATOR.BOXHEADERS : "!SEPARATOR.BOXHEADERS!" - - ECHO SEPARATOR.STUBHEAD_STUB : "!SEPARATOR.STUBHEAD_STUB!" - ECHO SEPARATOR.BOXHEAD_BODY : "!SEPARATOR.BOXHEAD_BODY!" - - ECHO SEPARATOR.STUB_BOXHEAD_INTERSECT : "!SEPARATOR.STUB_BOXHEAD_INTERSECT!" - ECHO. - REM ::DEBUG -) %@exit% @@ -1263,7 +1201,7 @@ SET @counter=FOR %%. IN (1 2) DO IF [%%.] EQU [2] (%\n% :: :: Used to exit and optionally sets an error code if provided. :: This is prefered for exiting a script over GOTO :EOF for consistency -:: and to pass Error Levels if necessery. This tidy's up a call +:: and to pass Error Levels if necessary. This tidy's up a call :: to EXIT /B [ErrorLevel] so the use feels the same as other macros. :: SET @exit=FOR %%. IN (1 2) DO IF [%%.] EQU [2] (%\n% @@ -1295,12 +1233,13 @@ FOR %%a IN (%*) DO ( IF /I ["!opt!"] EQU ["H"] ( SET "opt=" CALL :USAGE - %@exit% 1 + %@exit% -1 ) :: /A [ANSI] IF /I ["!opt!"] EQU ["A"] ( SET "opt=" SET "SHOW.ANSI=#TRUE#" + SET "SHOW.UTF8=#TRUE#" ) :: /R [R1C1] IF /I ["!opt!"] EQU ["R"] ( @@ -1315,7 +1254,7 @@ FOR %%a IN (%*) DO ( IF ["!opt!"] NEQ [""] ( SET "msg=Error: Unknown option: !opt!" CALL :USAGE msg - %@exit% 2 + %@exit% 1 ) ) ) @@ -1333,7 +1272,7 @@ IF [%~1] EQU [] ( IF NOT EXIST !DATA_FILE! ( SET "msg=Error: File does not exist: !DATA_FILE!" CALL :USAGE msg - %@exit% 3 + %@exit% 1 ) %@exit% @@ -1349,7 +1288,7 @@ IF NOT EXIST !DATA_FILE! ( SET "SCRIPT_NAME=%~nx0" :: The following ECHO intentionally has 80 spaces to clear the -:: line any remaining onscreen text on call. +:: line any remaining on screen text on call. ECHO. IF [%1] NEQ [] ( ECHO !%1! @@ -1366,6 +1305,7 @@ ECHO. ECHO Flags: ECHO /H : This message ECHO /A : Display the ANSI Escape Sequence control characters +ECHO This requires UTF-8 support and implies the additional /U flag ECHO /R : Show cell R1C1 reference addressing instead of cell text ECHO /U : Enable UTF-8 support ECHO. diff --git a/src/tools/ansi-color/crisman.def b/src/tools/ansi-color/crisman.def index cc4f92bb29e..bacfe408fce 100644 --- a/src/tools/ansi-color/crisman.def +++ b/src/tools/ansi-color/crisman.def @@ -25,7 +25,9 @@ :: done :: echo -:: This is the recreation of the TLDP.org bash script output +:: https://tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html +:: This is the recreation of the output of the TLDP.org +:: bash script provided by Daniel Crisman. __DATA__ __TABLE__ :: Greatest mystery ever. Why gYw? From 183dd4be44869dc1fef9f3cacd29810c6384854f Mon Sep 17 00:00:00 2001 From: Ryan Beesley Date: Tue, 14 Dec 2021 01:29:58 -0800 Subject: [PATCH 21/35] check-spelling-bot fix. --- src/tools/ansi-color/ansi-color.cmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/ansi-color/ansi-color.cmd b/src/tools/ansi-color/ansi-color.cmd index a63f7037e3d..f3cf6592eb2 100644 --- a/src/tools/ansi-color/ansi-color.cmd +++ b/src/tools/ansi-color/ansi-color.cmd @@ -9,7 +9,7 @@ CALL :PARSE_ARGS %1 %2 %3 %4 %5 %6 %7 %8 %9 IF ERRORLEVEL 1 %@exit% %ERRORLEVEL% :: Parsing success IF ERRORLEVEL 0 GOTO :CONFIGURATION -:: Help requested, but this shouldn't actually be an error from CMDs perspective +:: Help requested, but this shouldn't actually be an error from CMD's perspective IF ERRORLEVEL -1 %@exit% 0 From 7da3b528a386ae18793c34292ede9eb0f2c94e3b Mon Sep 17 00:00:00 2001 From: Ryan Beesley Date: Tue, 14 Dec 2021 02:02:18 -0800 Subject: [PATCH 22/35] Fixed comment and macro casing --- src/tools/ansi-color/ansi-color.cmd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tools/ansi-color/ansi-color.cmd b/src/tools/ansi-color/ansi-color.cmd index f3cf6592eb2..da4468588ce 100644 --- a/src/tools/ansi-color/ansi-color.cmd +++ b/src/tools/ansi-color/ansi-color.cmd @@ -388,7 +388,7 @@ FOR /F "tokens=*" %%_ IN ('chcp 2^>^&1 ^& FOR /F %%_ IN ^("ERRORLEVEL"^) DO @CAL REM This means that CHCP wasn't found REM If the definition doesn't require UTF-8, this might be okay REM CHCP_RET is no longer valid though, so undefine it - REM Interesting side note, this is an example where the :: can be used for REM + REM Interesting side note, this is an example where the :: can't be used for REM REM See https://stackoverflow.com/a/61981588 for more information SET "CHCP_RET=" ) ELSE IF [!CHCP_ERR!] NEQ [0] ( @@ -982,7 +982,7 @@ SET @strlen=FOR %%. IN (1 2) DO IF [%%.] EQU [2] (%\n% :: Max value passed through multiple subsequent calls, to :: determine the largest string passed in. :: -SET @maxVal=FOR %%. IN (1 2) DO IF [%%.] EQU [2] (%\n% +SET @maxval=FOR %%. IN (1 2) DO IF [%%.] EQU [2] (%\n% FOR /F "tokens=1,2,3 delims=, " %%1 IN ("!argv!") DO ( ENDLOCAL%\n% IF [!%%~1!] NEQ [] (SET /a "a=!%%~1!") ELSE (SET /a "a=%%~1")%\n% IF [!%%~2!] NEQ [] (SET /a "b=!%%~2!") ELSE (SET /a "b=%%~2")%\n% From 63130060ec88516bc41263054cf09234a71d959a Mon Sep 17 00:00:00 2001 From: Ryan Beesley Date: Wed, 15 Dec 2021 00:52:16 -0800 Subject: [PATCH 23/35] Improved CHCP reliability and case insensitive IFs If there is an IF which checks for a string in a definition file, it is now case insensitive and shouldn't cause problems. Updated error output when CHCP fails and only show a warning if Unicode isn't required. If Unicode is required, then show an additional error and exit. This has a negative that even if the shell is running on codepage 65001, it will block the execution of a definition file which requests UTF8 or the flag is set. The error in this case still makes sense as this happens when trying to read the active codepage and the utility will not know if this fails at this point in execution. I think this is the right balance. --- src/tools/ansi-color/ansi-color.cmd | 59 ++++++++++++++++------------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/src/tools/ansi-color/ansi-color.cmd b/src/tools/ansi-color/ansi-color.cmd index da4468588ce..f6b1e4dc7ca 100644 --- a/src/tools/ansi-color/ansi-color.cmd +++ b/src/tools/ansi-color/ansi-color.cmd @@ -384,16 +384,21 @@ FOR /F "tokens=*" %%_ IN ('chcp 2^>^&1 ^& FOR /F %%_ IN ^("ERRORLEVEL"^) DO @CAL :: Check if the CHCP call failed IF ["!CHCP_OUT:~0,15!"] EQU ["__ERRORLEVEL__:"] ( SET "CHCP_ERR=!CHCP_OUT:__ERRORLEVEL__:=!" - IF [!CHCP_ERR!] EQU [9009] ( - REM This means that CHCP wasn't found - REM If the definition doesn't require UTF-8, this might be okay - REM CHCP_RET is no longer valid though, so undefine it - REM Interesting side note, this is an example where the :: can't be used for REM - REM See https://stackoverflow.com/a/61981588 for more information - SET "CHCP_RET=" - ) ELSE IF [!CHCP_ERR!] NEQ [0] ( - ECHO Error: Unable to read active codepage - %@exit% !CHCP_ERR! + IF [!CHCP_ERR!] NEQ [0] ( + :: This means that the call to CHCP failed + ECHO Warning: Error reading the active codepage, check the output from the command CHCP. + If DEFINED SHOW.UTF8 ( + :: UTF8 is required if SHOW.UTF8 is defined, so error out + ECHO. + ECHO Error: UTF8 is required for the definition file in use or flags provided. Exiting. + :: Since this was fatal, also pass the error code received trying to call CHCP + %@exit% !CHCP_ERR! + ) ELSE ( + :: If UTF8 isn't required, maybe we can swallow this error and still show ANSI definition file + SET "SHOW.UTF8=" + :: Clear the CHCP_RET value as nothing returned should be considered valid + SET "CHCP_RET=" + ) ) ) ELSE ( SET "CHCP_RET=!CHCP_OUT!" @@ -517,32 +522,32 @@ CMD /C EXIT -1073741510 :READ_DATA_SEGMENT SET "DATA_SEGMENT=" FOR /F "delims=" %%_ IN (!DATA_FILE!) DO ( - IF ["%%_"] EQU ["__ROWS:END__"] SET SEGMENT= - IF ["%%_"] EQU ["__COLS:END__"] SET SEGMENT= - IF ["%%_"] EQU ["__TABLE:END__"] SET SEGMENT= - IF ["%%_"] EQU ["__DATA:END__"] SET DATA_SEGMENT= + IF /I ["%%_"] EQU ["__ROWS:END__"] SET SEGMENT= + IF /I ["%%_"] EQU ["__COLS:END__"] SET SEGMENT= + IF /I ["%%_"] EQU ["__TABLE:END__"] SET SEGMENT= + IF /I ["%%_"] EQU ["__DATA:END__"] SET DATA_SEGMENT= IF DEFINED DATA_SEGMENT ( SET "DATA=%%_" CALL :PARSE_DATA_SEGMENT !DATA! ) - IF ["%%_"] EQU ["__ROWS__"] ( + IF /I ["%%_"] EQU ["__ROWS__"] ( SET SEGMENT=ROWS :: Initialize the row globals SET /A ROW[#]=0 SET /A ROWS.LEN=0 ) - IF ["%%_"] EQU ["__COLS__"] ( + IF /I ["%%_"] EQU ["__COLS__"] ( SET SEGMENT=COLS :: Initialize the column globals SET /A COL[#]=0 SET /A COLS.LEN=0 ) - IF ["%%_"] EQU ["__TABLE__"] ( + IF /I ["%%_"] EQU ["__TABLE__"] ( SET SEGMENT=TABLE :: Initialize the table globals SET /A TABLE[#]=0 ) - IF ["%%_"] EQU ["__DATA__"] ( + IF /I ["%%_"] EQU ["__DATA__"] ( SET DATA_SEGMENT=#TRUE# SET SEGMENT= ) @@ -556,9 +561,9 @@ IF NOT DEFINED SEGMENT %@exit% SET "DATA=%*" :: Skip over any comments -IF ["!DATA:~0,2!"] EQU ["::"] %@exit% -IF ["!DATA:~0,3!"] EQU ["REM"] %@exit% -IF ["!DATA:~0,4!"] EQU ["@REM"] %@exit% +IF /I ["!DATA:~0,2!"] EQU ["::"] %@exit% +IF /I ["!DATA:~0,4!"] EQU ["REM "] %@exit% +IF /I ["!DATA:~0,5!"] EQU ["@REM "] %@exit% :: Advance and output the spinner animation if not disabled IF NOT DEFINED SPINNER.DISABLED ( @@ -566,9 +571,9 @@ IF NOT DEFINED SPINNER.DISABLED ( ) :: Dispatch to TABLE, COLS, or ROWS parsing routines -IF ["!SEGMENT!"] EQU ["TABLE"] CALL :PARSE_TABLE_DATA !DATA! -IF ["!SEGMENT!"] EQU ["COLS"] CALL :PARSE_COLS_DATA !DATA! -IF ["!SEGMENT!"] EQU ["ROWS"] CALL :PARSE_ROWS_DATA !DATA! +IF /I ["!SEGMENT!"] EQU ["TABLE"] CALL :PARSE_TABLE_DATA !DATA! +IF /I ["!SEGMENT!"] EQU ["COLS"] CALL :PARSE_COLS_DATA !DATA! +IF /I ["!SEGMENT!"] EQU ["ROWS"] CALL :PARSE_ROWS_DATA !DATA! %@exit% @@ -880,14 +885,14 @@ FOR /L %%r IN (1,1,!ROW[#]!) DO ( ) ) - IF [!ROW!] EQU [#SPC#] ( + IF /I ["!ROW!"] EQU ["#SPC#"] ( :: We want a special case for #SPC# so that we print a blank line SET "LINE=" ) ELSE ( :: Otherwise process the line SET "LINE=!ROW.VALUE!!SEPARATOR!" - IF [!ROW!] EQU [#NUL#] ( + IF /I ["!ROW!"] EQU ["#NUL#"] ( SET "ROW=" ) ELSE ( SET "ROW=!CSI!!ROW!" @@ -904,7 +909,7 @@ FOR /L %%r IN (1,1,!ROW[#]!) DO ( SET "R1C1_REFERENCE=R!R1C1_REFERENCE.R!C!R1C1_REFERENCE.C!" %@align% R1C1_REFERENCE !COL.MAX_WIDTH! !ALIGN.CELL.R1C1! CELL ) - IF [!COL[%%c]!] EQU [#NUL#] ( + IF /I ["!COL[%%c]!"] EQU ["#NUL#"] ( SET "COL=" ) ELSE ( SET "COL=!CSI!!COL[%%c]!" From 456fff474770560af6fbd3ce110ad7ce29709c3e Mon Sep 17 00:00:00 2001 From: Ryan Beesley Date: Wed, 15 Dec 2021 01:07:27 -0800 Subject: [PATCH 24/35] UTF-8 Error message was inconsistent. --- src/tools/ansi-color/ansi-color.cmd | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tools/ansi-color/ansi-color.cmd b/src/tools/ansi-color/ansi-color.cmd index f6b1e4dc7ca..e088a86ce4c 100644 --- a/src/tools/ansi-color/ansi-color.cmd +++ b/src/tools/ansi-color/ansi-color.cmd @@ -388,13 +388,13 @@ FOR /F "tokens=*" %%_ IN ('chcp 2^>^&1 ^& FOR /F %%_ IN ^("ERRORLEVEL"^) DO @CAL :: This means that the call to CHCP failed ECHO Warning: Error reading the active codepage, check the output from the command CHCP. If DEFINED SHOW.UTF8 ( - :: UTF8 is required if SHOW.UTF8 is defined, so error out + :: UTF-8 support is required if SHOW.UTF8 is defined, so error out ECHO. - ECHO Error: UTF8 is required for the definition file in use or flags provided. Exiting. + ECHO Error: UTF-8 support is required for the definition file in use or flags provided. :: Since this was fatal, also pass the error code received trying to call CHCP %@exit% !CHCP_ERR! ) ELSE ( - :: If UTF8 isn't required, maybe we can swallow this error and still show ANSI definition file + :: If UTF-8 support isn't required, maybe we can swallow this error and still show ANSI definition file SET "SHOW.UTF8=" :: Clear the CHCP_RET value as nothing returned should be considered valid SET "CHCP_RET=" From 60696aa071921e12a659c53454aa313bd4ba771a Mon Sep 17 00:00:00 2001 From: Ryan Beesley Date: Wed, 15 Dec 2021 02:05:51 -0800 Subject: [PATCH 25/35] Improved table parsing If there is anything evaluated which can cause an error this should be caught now. Trimmed the data before it is further evaluated to make sure extra whitespace is dropped but you can't indent in the definition files. Trimming before checking segments would fix this, but introduces a performance hit. --- src/tools/ansi-color/ansi-color.cmd | 41 +++++++++++++++++------------ 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/src/tools/ansi-color/ansi-color.cmd b/src/tools/ansi-color/ansi-color.cmd index e088a86ce4c..7b2bf42ee87 100644 --- a/src/tools/ansi-color/ansi-color.cmd +++ b/src/tools/ansi-color/ansi-color.cmd @@ -493,10 +493,9 @@ SET "SEPARATOR.COLUMN=" :: Read and parse the data, validate the configuration, calculate table headings, :: build the table, and show the table CALL :READ_DATA_SEGMENT +IF ERRORLEVEL 1 %@exit% %ERRORLEVEL% CALL :VALIDATE_CONFIGURATION -IF ERRORLEVEL 1 ( - %@exit% %ERRORLEVEL% -) +IF ERRORLEVEL 1 %@exit% %ERRORLEVEL% CALL :RESOLVE_SEPARATORS CALL :BUILD_TABLE CALL :DISPLAY_TABLE @@ -522,34 +521,35 @@ CMD /C EXIT -1073741510 :READ_DATA_SEGMENT SET "DATA_SEGMENT=" FOR /F "delims=" %%_ IN (!DATA_FILE!) DO ( - IF /I ["%%_"] EQU ["__ROWS:END__"] SET SEGMENT= - IF /I ["%%_"] EQU ["__COLS:END__"] SET SEGMENT= - IF /I ["%%_"] EQU ["__TABLE:END__"] SET SEGMENT= - IF /I ["%%_"] EQU ["__DATA:END__"] SET DATA_SEGMENT= + SET "DATA=%%_" + IF /I ["!DATA:~0,12!"] EQU ["__ROWS:END__"] SET "SEGMENT=" + IF /I ["!DATA:~0,12!"] EQU ["__COLS:END__"] SET "SEGMENT=" + IF /I ["!DATA:~0,13!"] EQU ["__TABLE:END__"] SET "SEGMENT=" + IF /I ["!DATA:~0,12!"] EQU ["__DATA:END__"] SET "DATA_SEGMENT=" IF DEFINED DATA_SEGMENT ( - SET "DATA=%%_" CALL :PARSE_DATA_SEGMENT !DATA! + IF ERRORLEVEL 1 %@exit% %ERRORLEVEL% ) - IF /I ["%%_"] EQU ["__ROWS__"] ( - SET SEGMENT=ROWS + IF /I ["!DATA:~0,8!"] EQU ["__ROWS__"] ( + SET "SEGMENT=ROWS" :: Initialize the row globals SET /A ROW[#]=0 SET /A ROWS.LEN=0 ) - IF /I ["%%_"] EQU ["__COLS__"] ( - SET SEGMENT=COLS + IF /I ["!DATA:~0,8!"] EQU ["__COLS__"] ( + SET "SEGMENT=COLS" :: Initialize the column globals SET /A COL[#]=0 SET /A COLS.LEN=0 ) - IF /I ["%%_"] EQU ["__TABLE__"] ( - SET SEGMENT=TABLE + IF /I ["!DATA:~0,9!"] EQU ["__TABLE__"] ( + SET "SEGMENT=TABLE" :: Initialize the table globals SET /A TABLE[#]=0 ) - IF /I ["%%_"] EQU ["__DATA__"] ( - SET DATA_SEGMENT=#TRUE# - SET SEGMENT= + IF /I ["!DATA:~0,8!"] EQU ["__DATA__"] ( + SET "DATA_SEGMENT=#TRUE#" + SET "SEGMENT=" ) ) %@exit% @@ -559,11 +559,15 @@ FOR /F "delims=" %%_ IN (!DATA_FILE!) DO ( :PARSE_DATA_SEGMENT IF NOT DEFINED SEGMENT %@exit% SET "DATA=%*" +:: We're parsing the data segment, so clean up the data before further processing +%@trim% DATA :: Skip over any comments IF /I ["!DATA:~0,2!"] EQU ["::"] %@exit% IF /I ["!DATA:~0,4!"] EQU ["REM "] %@exit% +IF /I ["!DATA!"] EQU ["REM"] %@exit% IF /I ["!DATA:~0,5!"] EQU ["@REM "] %@exit% +IF /I ["!DATA!"] EQU ["@REM"] %@exit% :: Advance and output the spinner animation if not disabled IF NOT DEFINED SPINNER.DISABLED ( @@ -588,6 +592,9 @@ IF /I ["!DATA:~0,3!"] EQU ["IF "] GOTO :EVAL_TABLE_DATA :EVAL_TABLE_DATA :: Eval the TABLE data directly %* +:: If there is an error, we want to catch it +IF ERRORLEVEL 1 %@exit% %ERRORLEVEL% +:: Otherwise just exit the routine %@exit% From 7e8b6c54bac76bc9588d3518b65e557117f4bd40 Mon Sep 17 00:00:00 2001 From: Ryan Beesley Date: Mon, 27 Dec 2021 13:55:03 -0800 Subject: [PATCH 26/35] Added support for column spaces and adjusted defs Adding #SPC# to a column definition will do the same as adding a #SPC# to a row, in that it will add visual separation. This is unlike #NUL# which just doesn't apply an associated escape sequence but still writes the test text to a cell. #SPC# writes spaces instead. Also updated a couple of definitions which benefit from this change. Fixed sgr-intensity.def so that is shows intensity from low to high, flipping 1; and 2; attributes. --- src/tools/ansi-color/ansi-color.cmd | 18 +++++-- src/tools/ansi-color/sgr-intensity.def | 68 +++++++++++++------------- src/tools/ansi-color/sgr.def | 12 +++++ src/tools/ansi-color/tsgr.def | 17 +++++++ 4 files changed, 77 insertions(+), 38 deletions(-) diff --git a/src/tools/ansi-color/ansi-color.cmd b/src/tools/ansi-color/ansi-color.cmd index 7b2bf42ee87..c9bcbb5cc0f 100644 --- a/src/tools/ansi-color/ansi-color.cmd +++ b/src/tools/ansi-color/ansi-color.cmd @@ -563,11 +563,11 @@ SET "DATA=%*" %@trim% DATA :: Skip over any comments +IF /I ["!DATA!"] EQU ["REM"] %@exit% +IF /I ["!DATA!"] EQU ["@REM"] %@exit% IF /I ["!DATA:~0,2!"] EQU ["::"] %@exit% IF /I ["!DATA:~0,4!"] EQU ["REM "] %@exit% -IF /I ["!DATA!"] EQU ["REM"] %@exit% IF /I ["!DATA:~0,5!"] EQU ["@REM "] %@exit% -IF /I ["!DATA!"] EQU ["@REM"] %@exit% :: Advance and output the spinner animation if not disabled IF NOT DEFINED SPINNER.DISABLED ( @@ -922,9 +922,19 @@ FOR /L %%r IN (1,1,!ROW[#]!) DO ( SET "COL=!CSI!!COL[%%c]!" ) IF [%%c] EQU [1] ( - SET "LINE=!LINE!!ROW!!COL!!CELL!!RESET!" + IF /I ["!COL[%%c]!"] EQU ["#SPC#"] ( + %@repeat% #SPC# !COL.MAX_WIDTH! OUT + SET "LINE=!LINE!!OUT!" + ) ELSE ( + SET "LINE=!LINE!!ROW!!COL!!CELL!!RESET!" + ) ) ELSE ( - SET "LINE=!LINE!!SEPARATOR.CELL!!ROW!!COL!!CELL!!RESET!" + IF /I ["!COL[%%c]!"] EQU ["#SPC#"] ( + %@repeat% #SPC# !COL.MAX_WIDTH! OUT + SET "LINE=!LINE!!SEPARATOR.CELL!!OUT!" + ) ELSE ( + SET "LINE=!LINE!!SEPARATOR.CELL!!ROW!!COL!!CELL!!RESET!" + ) ) ) ) diff --git a/src/tools/ansi-color/sgr-intensity.def b/src/tools/ansi-color/sgr-intensity.def index 4742e1bf51c..bc188d09334 100644 --- a/src/tools/ansi-color/sgr-intensity.def +++ b/src/tools/ansi-color/sgr-intensity.def @@ -65,9 +65,9 @@ __COLS:END__ :: [Intensity;][Attribute;]Foreground __ROWS__ :: Attributes -1m -#NUL# 2m +#NUL# +1m #SPC# :: Normal 30m @@ -90,53 +90,53 @@ __ROWS__ :: Bold or increased intensity, 1 :: Normal :: Faint (decreased intensity), 2 -1;30m - 30m 2;30m -1;90m - 90m + 30m +1;30m 2;90m -1;31m - 31m + 90m +1;90m 2;31m -1;91m - 91m + 31m +1;31m 2;91m -1;32m - 32m + 91m +1;91m 2;32m -1;92m - 92m + 32m +1;32m 2;92m -1;33m - 33m + 92m +1;92m 2;33m -1;93m - 93m + 33m +1;33m 2;93m -1;34m - 34m + 93m +1;93m 2;34m -1;94m - 94m + 34m +1;34m 2;94m -1;35m - 35m + 94m +1;94m 2;35m -1;95m - 95m + 35m +1;35m 2;95m -1;36m - 36m + 95m +1;95m 2;36m -1;96m - 96m + 36m +1;36m 2;96m -1;37m - 37m + 96m +1;96m 2;37m -1;97m - 97m + 37m +1;37m 2;97m + 97m +1;97m __ROWS:END__ __DATA:END__ \ No newline at end of file diff --git a/src/tools/ansi-color/sgr.def b/src/tools/ansi-color/sgr.def index 6205e8c210a..4f0947dd562 100644 --- a/src/tools/ansi-color/sgr.def +++ b/src/tools/ansi-color/sgr.def @@ -60,6 +60,7 @@ __COLS__ 8m 9m 21m +#SPC# 40m 100m 41m @@ -91,6 +92,7 @@ __ROWS__ 8m 9m 21m +#SPC# :: Normal 30m 90m @@ -108,6 +110,7 @@ __ROWS__ 96m 37m 97m +#SPC# :: Bold or increased intensity, 1 1;30m 1;90m @@ -125,6 +128,7 @@ __ROWS__ 1;96m 1;37m 1;97m +#SPC# :: Faint (decreased intensity), 2 2;30m 2;90m @@ -142,6 +146,7 @@ __ROWS__ 2;96m 2;37m 2;97m +#SPC# :: Italic, 3 3;30m 3;90m @@ -159,6 +164,7 @@ __ROWS__ 3;96m 3;37m 3;97m +#SPC# :: Underline, 4 4;30m 4;90m @@ -176,6 +182,7 @@ __ROWS__ 4;96m 4;37m 4;97m +#SPC# :: Slow Blink, 5 5;30m 5;90m @@ -193,6 +200,7 @@ __ROWS__ 5;96m 5;37m 5;97m +#SPC# :: Rapid Blink, 6 6;30m 6;90m @@ -210,6 +218,7 @@ __ROWS__ 6;96m 6;37m 6;97m +#SPC# :: Reverse video, 7 7;30m 7;90m @@ -227,6 +236,7 @@ __ROWS__ 7;96m 7;37m 7;97m +#SPC# :: Conceal, 8 8;30m 8;90m @@ -244,6 +254,7 @@ __ROWS__ 8;96m 8;37m 8;97m +#SPC# :: Crossed-out, 9 9;30m 9;90m @@ -261,6 +272,7 @@ __ROWS__ 9;96m 9;37m 9;97m +#SPC# :: Double Underline, 21 21;30m 21;90m diff --git a/src/tools/ansi-color/tsgr.def b/src/tools/ansi-color/tsgr.def index 70cd133054e..9bd8ec4e0a0 100644 --- a/src/tools/ansi-color/tsgr.def +++ b/src/tools/ansi-color/tsgr.def @@ -62,6 +62,7 @@ __COLS__ 8m 9m 21m +#SPC# 40m 100m 41m @@ -94,6 +95,7 @@ __ROWS__ 9m 21m 30m +#SPC# 1;30m 2;30m 3;30m @@ -104,6 +106,7 @@ __ROWS__ 8;30m 9;30m 21;30m +#SPC# 90m 1;90m 2;90m @@ -115,6 +118,7 @@ __ROWS__ 8;90m 9;90m 21;90m +#SPC# 31m 1;31m 2;31m @@ -126,6 +130,7 @@ __ROWS__ 8;31m 9;31m 21;31m +#SPC# 91m 1;91m 2;91m @@ -137,6 +142,7 @@ __ROWS__ 8;91m 9;91m 21;91m +#SPC# 32m 1;32m 2;32m @@ -148,6 +154,7 @@ __ROWS__ 8;32m 9;32m 21;32m +#SPC# 92m 1;92m 2;92m @@ -159,6 +166,7 @@ __ROWS__ 8;92m 9;92m 21;92m +#SPC# 33m 1;33m 2;33m @@ -170,6 +178,7 @@ __ROWS__ 8;33m 9;33m 21;33m +#SPC# 93m 1;93m 2;93m @@ -181,6 +190,7 @@ __ROWS__ 8;93m 9;93m 21;93m +#SPC# 34m 1;34m 2;34m @@ -192,6 +202,7 @@ __ROWS__ 8;34m 9;34m 21;34m +#SPC# 94m 1;94m 2;94m @@ -203,6 +214,7 @@ __ROWS__ 8;94m 9;94m 21;94m +#SPC# 35m 1;35m 2;35m @@ -214,6 +226,7 @@ __ROWS__ 8;35m 9;35m 21;35m +#SPC# 95m 1;95m 2;95m @@ -225,6 +238,7 @@ __ROWS__ 8;95m 9;95m 21;95m +#SPC# 36m 1;36m 2;36m @@ -236,6 +250,7 @@ __ROWS__ 8;36m 9;36m 21;36m +#SPC# 96m 1;96m 2;96m @@ -247,6 +262,7 @@ __ROWS__ 8;96m 9;96m 21;96m +#SPC# 37m 1;37m 2;37m @@ -258,6 +274,7 @@ __ROWS__ 8;37m 9;37m 21;37m +#SPC# 97m 1;97m 2;97m From 5515f6ec0b19cf636c1aeeb8707d72923474ee7c Mon Sep 17 00:00:00 2001 From: Ryan Beesley Date: Tue, 28 Dec 2021 16:05:54 -0800 Subject: [PATCH 27/35] Added ability to create labels for the table. Fixed a case where special tokens were interpreted as column width for the stub so now they are 0 width. This allows the labels to be inserted into the middle of the table without affecting the overall width. Added a new definition for showing attributes and a label definition to demonstrate how labels can be used. They follow the pattern used for ECHO so that #LBL#[.| ][TEXT] will output the same way ECHO does. #LBL# can also use CSI commands to format the label. #LBL# will automatically apply RESET at the end of a line to prevent inconsistency. --- src/tools/ansi-color/ansi-color.cmd | 98 +++++- src/tools/ansi-color/attrib.def | 425 +++++++++++++++++++++++++ src/tools/ansi-color/lbl.def | 64 ++++ src/tools/ansi-color/rainbow.def | 32 +- src/tools/ansi-color/sgr-intensity.def | 32 +- src/tools/ansi-color/sgr.def | 66 +++- src/tools/ansi-color/tsgr.def | 5 +- 7 files changed, 667 insertions(+), 55 deletions(-) create mode 100644 src/tools/ansi-color/attrib.def create mode 100644 src/tools/ansi-color/lbl.def diff --git a/src/tools/ansi-color/ansi-color.cmd b/src/tools/ansi-color/ansi-color.cmd index c9bcbb5cc0f..3f3b1e3e78b 100644 --- a/src/tools/ansi-color/ansi-color.cmd +++ b/src/tools/ansi-color/ansi-color.cmd @@ -40,9 +40,14 @@ __DATA__ :: or row, but there is no row or column value applied to the cell. :: This has the effect that the row or column has no SGR parameter applied :: and so this will show the default. -:: #SPC# is also a special case which can be used to make gaps in the table. +:: #SPC# is a special case which can be used to make gaps in the table. :: Whereas #NUL# still outputs the CELL text, #SPC# won't show anything in -:: that row. +:: that row. #SPC# can be used in columns to also provide a gap which matches +:: cell width. +:: #LBL# is also a special case similar to #SPC#. #LBL# makes it possible to +:: write a text label in the middle of a generated table for a particular row. +:: Formatting can be applied to the labels and an SGR RESET is automatically +:: applied at the end of the string. __TABLE__ :: If the definition is defined using Unicode characters, uncomment and include :: the following line in the __TABLE__ section of the definition file. @@ -89,6 +94,8 @@ REM SET "SEPARATOR.CELL=╎" & :: UTF-8 IF DEFINED SHOW.UTF8 (SET "SEPARATOR.STUBHEAD_BOXHEAD=│") ELSE (SET "SEPARATOR.STUBHEAD_BOXHEAD=:") IF DEFINED SHOW.UTF8 (SET "SEPARATOR.STUBHEAD_STUB=─") ELSE (SET "SEPARATOR.STUBHEAD_STUB=-") IF DEFINED SHOW.UTF8 (SET "SEPARATOR.INTERSECT=┘") ELSE (SET "SEPARATOR.INTERSECT=+") +:: You can also define control for formating +SET "SECTION=!CSI!1;4m" __TABLE:END__ :: Background @@ -125,6 +132,9 @@ __COLS:END__ :: [Intensity;][Attribute;]Foreground __ROWS__ #NUL# +#SPC# +:: Attributes +#LBL# !SECTION!Attributes 1m 2m 3m @@ -156,6 +166,7 @@ REM 28m REM 29m #SPC# :: Normal +#LBL# !SECTION!Normal 30m 90m 31m @@ -174,6 +185,7 @@ REM 29m 97m #SPC# :: Bold or increased intensity, 1 +#LBL# !SECTION!Bold or increased intensity, 1 1;30m 1;90m 1;31m @@ -192,6 +204,7 @@ REM 29m 1;97m #SPC# :: Faint (decreased intensity), 2 +#LBL# !SECTION!Faint (decreased intensity), 2 2;30m 2;90m 2;31m @@ -210,6 +223,7 @@ REM 29m 2;97m #SPC# :: Italic, 3 +#LBL# !SECTION!Italic, 3 3;30m 3;90m 3;31m @@ -228,6 +242,7 @@ REM 29m 3;97m #SPC# :: Underline, 4 +#LBL# !SECTION!Underline, 4 4;30m 4;90m 4;31m @@ -246,6 +261,7 @@ REM 29m 4;97m #SPC# :: Slow Blink, 5 +#LBL# !SECTION!Slow Blink, 5 5;30m 5;90m 5;31m @@ -264,6 +280,7 @@ REM 29m 5;97m #SPC# :: Rapid Blink, 6 +#LBL# !SECTION!Rapid Blink, 6 6;30m 6;90m 6;31m @@ -282,6 +299,7 @@ REM 29m 6;97m #SPC# :: Reverse video, 7 +#LBL# !SECTION!Reverse video, 7 7;30m 7;90m 7;31m @@ -300,6 +318,7 @@ REM 29m 7;97m #SPC# :: Conceal, 8 +#LBL# !SECTION!Conceal, 8 8;30m 8;90m 8;31m @@ -318,6 +337,7 @@ REM 29m 8;97m #SPC# :: Crossed-out, 9 +#LBL# !SECTION!Crossed-out, 9 9;30m 9;90m 9;31m @@ -336,6 +356,7 @@ REM 29m 9;97m #SPC# :: Double Underline, 21 +#LBL# !SECTION!Double Underline, 21 21;30m 21;90m 21;31m @@ -601,7 +622,16 @@ IF ERRORLEVEL 1 %@exit% %ERRORLEVEL% :PARSE_COLS_DATA SET "COL=%*" :: Set the column header text and track the max width -%@strlen% COL COL.LEN +IF ["!COL:~0,1!"] EQU ["#"] ( + IF ["!COL:~4,1!"] EQU ["#"] ( + :: Special case for #???# tokens + SET /A "COL.LEN=0" + ) ELSE ( + %@strlen% COL COL.LEN + ) +) ELSE ( + %@strlen% COL COL.LEN +) %@maxval% COL.MAX_WIDTH COL.LEN :: Set the col index and store value SET /A COL[#]+=1 @@ -612,7 +642,16 @@ SET "COL[!COL[#]!]=!COL!" :PARSE_ROWS_DATA SET "ROW=%*" :: Set the row header text -%@strlen% ROW ROW.LEN +IF ["!ROW:~0,1!"] EQU ["#"] ( + IF ["!ROW:~4,1!"] EQU ["#"] ( + :: Special case for #???# tokens + SET /A "ROW.LEN=0" + ) ELSE ( + %@strlen% ROW ROW.LEN + ) +) ELSE ( + %@strlen% ROW ROW.LEN +) %@maxval% STUB.MAX_WIDTH ROW.LEN :: Set the row index and store value SET /A ROW[#]+=1 @@ -892,9 +931,21 @@ FOR /L %%r IN (1,1,!ROW[#]!) DO ( ) ) - IF /I ["!ROW!"] EQU ["#SPC#"] ( + IF /I ["!ROW:~0,5!"] EQU ["#SPC#"] ( :: We want a special case for #SPC# so that we print a blank line SET "LINE=" + ) ELSE IF /I ["!ROW:~0,5!"] EQU ["#LBL#"] ( + :: We want a special case for #LBL# so that we print the string which follows and append an SGR RESET + IF /I ["!ROW:~5,1!"] EQU [" "] ( + :: Allow for a space to follow #LBL# + SET "LINE=!ROW:~6!!RESET!" + ) ELSE IF /I ["!ROW:~5,1!"] EQU ["."] ( + :: Allow for a period to follow #LBL# and treat it like space, to mimic ECHO + SET "LINE=!ROW:~6!!RESET!" + ) ELSE ( + :: Assume that any other character is part of the label + SET "LINE=!ROW:~5!!RESET!" + ) ) ELSE ( :: Otherwise process the line SET "LINE=!ROW.VALUE!!SEPARATOR!" @@ -974,15 +1025,21 @@ SETLOCAL DISABLEDELAYEDEXPANSION :: :: Computes the length of string in variable StrVar :: and stores the result in variable RtnVar. -:: If StrVar is #NUL#, this should be 0 width. -:: If StrVar is #SPC#, this should empty padding. +:: If StrVar is #SPC#, the return val should be 1. +:: If StrVar is any other Special Token, the return val should be 0. :: If RtnVar is not specified, then print the length to stdout. :: SET @strlen=FOR %%. IN (1 2) DO IF [%%.] EQU [2] (%\n% FOR /F "tokens=1,2 delims=, " %%1 IN ("!argv!") DO ( ENDLOCAL%\n% SET "s=A!%%~1!"%\n% - SET "s=!s:#NUL#=!"%\n% - SET "s=!s:#SPC#= !"%\n% + IF /I ["!s:~0,5!"] EQU ["#SPC#"] (%\n% + SET "s= "%\n% + ) ELSE IF /I ["!s:~0,1!"] EQU ["#"] (%\n% + IF /I ["!s:~4,1!"] EQU ["#"] (%\n% + :: Look for Special Tokens of the form #???# %\n% + SET "s="%\n% + )%\n% + )%\n% SET "len=0"%\n% FOR %%P in (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) DO (%\n% IF ["!s:~%%P,1!"] NEQ [""] (%\n% @@ -1016,15 +1073,21 @@ SET @maxval=FOR %%. IN (1 2) DO IF [%%.] EQU [2] (%\n% :: @repeat StrVal Count [RetVar] :: :: Repeats StrVal, Count times, and assigns to RetVar. -:: If StrVar is #NUL#, this should empty padding. :: If StrVar is #SPC#, this should empty padding. +:: If StrVar is any other Special Token, this should be empty. :: If RtnVar is not specified, then print the output string to stdout. :: SET @repeat=FOR %%. IN (1 2) DO IF [%%.] EQU [2] (%\n% FOR /F "tokens=1,2,3 delims=, " %%1 IN ("!argv!") DO ( ENDLOCAL%\n% IF [!%%~1!] NEQ [] (SET "s=!%%~1!") ELSE (SET "s=%%~1")%\n% - SET "s=!s:#NUL#= !"%\n% - SET "s=!s:#SPC#= !"%\n% + IF /I ["!s:~0,5!"] EQU ["#SPC#"] (%\n% + SET "s= "%\n% + ) ELSE IF /I ["!s:~0,1!"] EQU ["#"] (%\n% + IF /I ["!s:~4,1!"] EQU ["#"] (%\n% + :: Look for Special Tokens of the form #???# %\n% + SET "s="%\n% + )%\n% + )%\n% SET "count=%%~2"%\n% SET "outstr="%\n% FOR /L %%. IN (1,1,!count!) DO SET "outstr=!outstr!!s!"%\n% @@ -1125,15 +1188,18 @@ SET @trim=FOR %%. IN (1 2) DO IF [%%.] EQU [2] (%\n% :: Aligns the string in variable StrVar :: in the field using the Width and Alignment provided :: and stores the result in variable RtnVar. -:: If StrVar is #NUL#, this should empty padding. -:: If StrVar is #SPC#, this should empty padding. +:: If StrVar is a Special Token, it is treated as a space. :: If RtnVar is not specified, then print the output to stdout. :: SET @align=FOR %%. IN (1 2) DO IF [%%.] EQU [2] (%\n% FOR /F "tokens=1,2,3,4 delims=, " %%1 IN ("!argv!") DO ( ENDLOCAL%\n% IF ["!%%~1!"] NEQ [""] (SET "strVar=!%%~1!") ELSE (SET "strVar=%%~1")%\n% - SET "strVar=!strVar:#NUL#= !"%\n% - SET "strVar=!strVar:#SPC#= !"%\n% + IF /I ["!strVar:~0,1!"] EQU ["#"] (%\n% + IF /I ["!strVar:~4,1!"] EQU ["#"] (%\n% + :: Look for Special Tokens of the form #???# %\n% + SET "strVar= "%\n% + )%\n% + )%\n% IF ["!%%~2!"] NEQ [""] (SET "width=!%%~2!") ELSE (SET "width=%%~2")%\n% SET "alignment=%%~3"%\n% IF ["!%%~4!"] NEQ [""] (SET "%%~4=")%\n% diff --git a/src/tools/ansi-color/attrib.def b/src/tools/ansi-color/attrib.def new file mode 100644 index 00000000000..871e6839797 --- /dev/null +++ b/src/tools/ansi-color/attrib.def @@ -0,0 +1,425 @@ +:: Apply all known implemented attributes to see the effect of multiple attributes against all foreground and background colors +__DATA__ +__TABLE__ +:: The test text +SET "CELL= gYw " +SET "STUBHEAD=Attributes" +:: Alignment properties for the cells and headers +SET "ALIGN.CELL=C" +SET "ALIGN.BOXHEAD=C" +SET "ALIGN.STUB=R" +:: Table spacing +SET "SEPARATOR.CELL= " +SET "SEPARATOR.STUB= " +__TABLE:END__ +__COLS__ +#NUL# + 1m + 2m + 3m + 4m + 5m + 6m + 7m + 8m + 9m + 21m +__COLS:END__ +__ROWS__ +#NUL# + 1m + 2m + 3m + 4m + 5m + 6m + 7m + 8m + 9m + 21m +#SPC# + 30m + 1;30m + 2;30m + 3;30m + 4;30m + 5;30m + 6;30m + 7;30m + 8;30m + 9;30m + 21;30m +#SPC# + 31m + 1;31m + 2;31m + 3;31m + 4;31m + 5;31m + 6;31m + 7;31m + 8;31m + 9;31m + 21;31m +#SPC# + 32m + 1;32m + 2;32m + 3;32m + 4;32m + 5;32m + 6;32m + 7;32m + 8;32m + 9;32m + 21;32m +#SPC# + 33m + 1;33m + 2;33m + 3;33m + 4;33m + 5;33m + 6;33m + 7;33m + 8;33m + 9;33m + 21;33m +#SPC# + 34m + 1;34m + 2;34m + 3;34m + 4;34m + 5;34m + 6;34m + 7;34m + 8;34m + 9;34m + 21;34m +#SPC# + 35m + 1;35m + 2;35m + 3;35m + 4;35m + 5;35m + 6;35m + 7;35m + 8;35m + 9;35m + 21;35m +#SPC# + 36m + 1;36m + 2;36m + 3;36m + 4;36m + 5;36m + 6;36m + 7;36m + 8;36m + 9;36m + 21;36m +#SPC# + 37m + 1;37m + 2;37m + 3;37m + 4;37m + 5;37m + 6;37m + 7;37m + 8;37m + 9;37m + 21;37m +#SPC# + 40m + 1;40m + 2;40m + 3;40m + 4;40m + 5;40m + 6;40m + 7;40m + 8;40m + 9;40m + 21;40m +#SPC# + 41m + 1;41m + 2;41m + 3;41m + 4;41m + 5;41m + 6;41m + 7;41m + 8;41m + 9;41m + 21;41m +#SPC# + 42m + 1;42m + 2;42m + 3;42m + 4;42m + 5;42m + 6;42m + 7;42m + 8;42m + 9;42m + 21;42m +#SPC# + 43m + 1;43m + 2;43m + 3;43m + 4;43m + 5;43m + 6;43m + 7;43m + 8;43m + 9;43m + 21;43m +#SPC# + 44m + 1;44m + 2;44m + 3;44m + 4;44m + 5;44m + 6;44m + 7;44m + 8;44m + 9;44m + 21;44m +#SPC# + 45m + 1;45m + 2;45m + 3;45m + 4;45m + 5;45m + 6;45m + 7;45m + 8;45m + 9;45m + 21;45m +#SPC# + 46m + 1;46m + 2;46m + 3;46m + 4;46m + 5;46m + 6;46m + 7;46m + 8;46m + 9;46m + 21;46m +#SPC# + 47m + 1;47m + 2;47m + 3;47m + 4;47m + 5;47m + 6;47m + 7;47m + 8;47m + 9;47m + 21;47m +#SPC# + 90m + 1;90m + 2;90m + 3;90m + 4;90m + 5;90m + 6;90m + 7;90m + 8;90m + 9;90m + 21;90m +#SPC# + 91m + 1;91m + 2;91m + 3;91m + 4;91m + 5;91m + 6;91m + 7;91m + 8;91m + 9;91m + 21;91m +#SPC# + 92m + 1;92m + 2;92m + 3;92m + 4;92m + 5;92m + 6;92m + 7;92m + 8;92m + 9;92m + 21;92m +#SPC# + 93m + 1;93m + 2;93m + 3;93m + 4;93m + 5;93m + 6;93m + 7;93m + 8;93m + 9;93m + 21;93m +#SPC# + 94m + 1;94m + 2;94m + 3;94m + 4;94m + 5;94m + 6;94m + 7;94m + 8;94m + 9;94m + 21;94m +#SPC# + 95m + 1;95m + 2;95m + 3;95m + 4;95m + 5;95m + 6;95m + 7;95m + 8;95m + 9;95m + 21;95m +#SPC# + 96m + 1;96m + 2;96m + 3;96m + 4;96m + 5;96m + 6;96m + 7;96m + 8;96m + 9;96m + 21;96m +#SPC# + 97m + 1;97m + 2;97m + 3;97m + 4;97m + 5;97m + 6;97m + 7;97m + 8;97m + 9;97m + 21;97m +#SPC# + 100m + 1;100m + 2;100m + 3;100m + 4;100m + 5;100m + 6;100m + 7;100m + 8;100m + 9;100m +21;100m +#SPC# + 101m + 1;101m + 2;101m + 3;101m + 4;101m + 5;101m + 6;101m + 7;101m + 8;101m + 9;101m +21;101m +#SPC# + 102m + 1;102m + 2;102m + 3;102m + 4;102m + 5;102m + 6;102m + 7;102m + 8;102m + 9;102m +21;102m +#SPC# + 103m + 1;103m + 2;103m + 3;103m + 4;103m + 5;103m + 6;103m + 7;103m + 8;103m + 9;103m +21;103m +#SPC# + 104m + 1;104m + 2;104m + 3;104m + 4;104m + 5;104m + 6;104m + 7;104m + 8;104m + 9;104m +21;104m +#SPC# + 105m + 1;105m + 2;105m + 3;105m + 4;105m + 5;105m + 6;105m + 7;105m + 8;105m + 9;105m +21;105m +#SPC# + 106m + 1;106m + 2;106m + 3;106m + 4;106m + 5;106m + 6;106m + 7;106m + 8;106m + 9;106m +21;106m +#SPC# + 107m + 1;107m + 2;107m + 3;107m + 4;107m + 5;107m + 6;107m + 7;107m + 8;107m + 9;107m +21;107m +__ROWS:END__ +__DATA:END__ \ No newline at end of file diff --git a/src/tools/ansi-color/lbl.def b/src/tools/ansi-color/lbl.def new file mode 100644 index 00000000000..915e1061ca1 --- /dev/null +++ b/src/tools/ansi-color/lbl.def @@ -0,0 +1,64 @@ +:: Demonstrates how to use the #LBL# feature for definition files +:: Requires 107 columns +__DATA__ +__TABLE__ +:: The test text +SET "CELL= gYw " +REM SET "SPINNER.DISABLED=#TRUE#" +:: Alignment properties for the cells and headers +SET "ALIGN.CELL=C" +SET "ALIGN.BOXHEAD=C" +SET "ALIGN.STUB=L" +:: Table spacing +SET "SEPARATOR.CELL= " +SET "SEPARATOR.STUB= " +:: Formatting +SET "INV=!CSI!7m" +SET "HIGH=!CSI!1m" +SET "LOW=!CSI!2m" +__TABLE:END__ +__COLS__ +#NUL# +40m +41m +42m +43m +44m +45m +46m +47m +100m +101m +102m +103m +104m +105m +106m +107m +__COLS:END__ +__ROWS__ +#LBL# NUL: +#NUL# +#LBL#.SPC: +#SPC# +#LBL# !INV!Foreground +#LBL#. !LOW!Low Intensity +30m +31m +32m +33m +34m +35m +36m +37m +#LBL# !HIGH!High Intensity +90m +91m +92m +93m +94m +95m +96m +97m +__ROWS:END__ +__DATA:END__ \ No newline at end of file diff --git a/src/tools/ansi-color/rainbow.def b/src/tools/ansi-color/rainbow.def index 50a1bbae6e2..78cac9edbfa 100644 --- a/src/tools/ansi-color/rainbow.def +++ b/src/tools/ansi-color/rainbow.def @@ -16,17 +16,17 @@ __COLS__ 40m 47m 41m -45m -44m -46m -42m 43m +42m +46m +44m +45m 101m -105m -104m -106m -102m 103m +102m +106m +104m +105m 100m 107m __COLS:END__ @@ -35,17 +35,17 @@ __ROWS__ 30m 37m 31m -35m -34m -36m -32m 33m +32m +36m +34m +35m 91m -95m -94m -96m -92m 93m +92m +96m +94m +95m 90m 97m __ROWS:END__ diff --git a/src/tools/ansi-color/sgr-intensity.def b/src/tools/ansi-color/sgr-intensity.def index bc188d09334..c7095c9184b 100644 --- a/src/tools/ansi-color/sgr-intensity.def +++ b/src/tools/ansi-color/sgr-intensity.def @@ -1,4 +1,4 @@ -:: Check SGR intensity attributes, requires 100 columns +:: Check SGR intensity attributes, requires 110 columns __DATA__ __TABLE__ :: The test text @@ -43,6 +43,8 @@ __TABLE:END__ :: Background __COLS__ +49m +#SPC# #NUL# 40m 100m @@ -64,12 +66,13 @@ __COLS:END__ :: [Intensity;][Attribute;]Foreground __ROWS__ -:: Attributes -2m -#NUL# -1m +:: Default +#LBL# Default +39m #SPC# :: Normal +#LBL# Normal +#NUL# 30m 90m 31m @@ -87,9 +90,24 @@ __ROWS__ 37m 97m #SPC# -:: Bold or increased intensity, 1 -:: Normal +:: Attributes +#LBL# Attributes +2m +#NUL# +1m +#SPC# :: Faint (decreased intensity), 2 +:: Normal +:: Bold or increased intensity, 1 +#LBL# Applied !CSI!2mdecreased!RESET! intensity +#LBL# Normal +#LBL# Applied !CSI!1mincreased!RESET! intensity +2;39m + 39m +1;39m + 2m +#NUL# + 1m 2;30m 30m 1;30m diff --git a/src/tools/ansi-color/sgr.def b/src/tools/ansi-color/sgr.def index 4f0947dd562..85cfd5e31f7 100644 --- a/src/tools/ansi-color/sgr.def +++ b/src/tools/ansi-color/sgr.def @@ -1,13 +1,21 @@ :: Complete matrix of SGR parameters available :: This definition also demonstrates the various configuration changes :: which are used to control the way the table is generated -:: Requires 142 columns to display correctly +:: Requires 92 columns to display correctly __DATA__ :: Select Graphic Rendition (SGR) parameters :: #NUL# is treated as a special case to provide cells in that column :: or row, but there is no row or column value applied to the cell. :: This has the effect that the row or column has no SGR parameter applied :: and so this will show the default. +:: #SPC# is a special case which can be used to make gaps in the table. +:: Whereas #NUL# still outputs the CELL text, #SPC# won't show anything in +:: that row. #SPC# can be used in columns to also provide a gap which matches +:: cell width. +:: #LBL# is also a special case similar to #SPC#. #LBL# makes it possible to +:: write a text label in the middle of a generated table for a particular row. +:: Formatting can be applied to the labels and an SGR RESET is automatically +:: applied at the end of the string. __TABLE__ SET "UTF8.REQUIRED=#TRUE#" :: The test text @@ -45,22 +53,23 @@ REM SET "SEPARATOR.BOXHEADERS= " REM SET "SEPARATOR.BOXHEADERS=╎" REM SET "SEPARATOR.CELL= " REM SET "SEPARATOR.CELL=╎" +:: Formatting for labels +SET "SECTION=!CSI!1;4m" __TABLE:END__ :: Background __COLS__ #NUL# -1m -2m -3m -4m -5m -6m -7m -8m -9m -21m -#SPC# +REM 1m +REM 2m +REM 3m +REM 4m +REM 5m +REM 6m +REM 7m +REM 8m +REM 9m +REM 21m 40m 100m 41m @@ -82,6 +91,9 @@ __COLS:END__ :: [Intensity;][Attribute;]Foreground __ROWS__ #NUL# +#SPC# +:: Attributes +#LBL# !SECTION!Attributes 1m 2m 3m @@ -91,9 +103,29 @@ __ROWS__ 7m 8m 9m +REM 10m +REM 11m +REM 12m +REM 13m +REM 14m +REM 15m +REM 16m +REM 17m +REM 18m +REM 19m +REM 20m 21m +REM 22m +REM 23m +REM 24m +REM 25m +REM 26m +REM 27m +REM 28m +REM 29m #SPC# :: Normal +#LBL# !SECTION!Normal 30m 90m 31m @@ -112,6 +144,7 @@ __ROWS__ 97m #SPC# :: Bold or increased intensity, 1 +#LBL# !SECTION!Bold or increased intensity, 1 1;30m 1;90m 1;31m @@ -130,6 +163,7 @@ __ROWS__ 1;97m #SPC# :: Faint (decreased intensity), 2 +#LBL# !SECTION!Faint (decreased intensity), 2 2;30m 2;90m 2;31m @@ -148,6 +182,7 @@ __ROWS__ 2;97m #SPC# :: Italic, 3 +#LBL# !SECTION!Italic, 3 3;30m 3;90m 3;31m @@ -166,6 +201,7 @@ __ROWS__ 3;97m #SPC# :: Underline, 4 +#LBL# !SECTION!Underline, 4 4;30m 4;90m 4;31m @@ -184,6 +220,7 @@ __ROWS__ 4;97m #SPC# :: Slow Blink, 5 +#LBL# !SECTION!Slow Blink, 5 5;30m 5;90m 5;31m @@ -202,6 +239,7 @@ __ROWS__ 5;97m #SPC# :: Rapid Blink, 6 +#LBL# !SECTION!Rapid Blink, 6 6;30m 6;90m 6;31m @@ -220,6 +258,7 @@ __ROWS__ 6;97m #SPC# :: Reverse video, 7 +#LBL# !SECTION!Reverse video, 7 7;30m 7;90m 7;31m @@ -238,6 +277,7 @@ __ROWS__ 7;97m #SPC# :: Conceal, 8 +#LBL# !SECTION!Conceal, 8 8;30m 8;90m 8;31m @@ -256,6 +296,7 @@ __ROWS__ 8;97m #SPC# :: Crossed-out, 9 +#LBL# !SECTION!Crossed-out, 9 9;30m 9;90m 9;31m @@ -274,6 +315,7 @@ __ROWS__ 9;97m #SPC# :: Double Underline, 21 +#LBL# !SECTION!Double Underline, 21 21;30m 21;90m 21;31m diff --git a/src/tools/ansi-color/tsgr.def b/src/tools/ansi-color/tsgr.def index 9bd8ec4e0a0..24dde7328e8 100644 --- a/src/tools/ansi-color/tsgr.def +++ b/src/tools/ansi-color/tsgr.def @@ -3,12 +3,9 @@ :: per foreground color instead of incrementing on the attributes :: ForEach(fg in Foreground) { ForEach(a in Attribute) { a;fm }} instead of :: ForEach(a in Attribute) { ForEach(fg in Foreground) { a;fm }} +:: Requires 147 columns __DATA__ :: Select Graphic Rendition (SGR) parameters -:: #NUL# is treated as a special case to provide cells in that column -:: or row, but there is no row or column value applied to the cell. -:: This has the effect that the row or column has no SGR parameter applied -:: and so this will show the default. __TABLE__ SET "UTF8.REQUIRED=#TRUE#" :: The test text From eab3c9b89cebf496490c6bd449d5ac47d2e6861b Mon Sep 17 00:00:00 2001 From: Ryan Beesley Date: Tue, 28 Dec 2021 17:08:27 -0800 Subject: [PATCH 28/35] check-spelling-bot update to conform Added: mdecreased mincreased Removed: adaa coffgroup coffgrp datetime eae emplate GENPROFILE HHmm Hostx installationpath MMdd pgorepro pgort PGU Relayout Moved additional words from previous checkins to appropriate files --- ...5c1ec487b80f127ca611d10b973f66d9ed6812.txt | 29 ----------------- .github/actions/spelling/expect/expect.txt | 32 ++++++++++++------- .github/actions/spelling/expect/web.txt | 9 ++++++ .../actions/spelling/patterns/patterns.txt | 1 + 4 files changed, 30 insertions(+), 41 deletions(-) delete mode 100644 .github/actions/spelling/expect/205c1ec487b80f127ca611d10b973f66d9ed6812.txt diff --git a/.github/actions/spelling/expect/205c1ec487b80f127ca611d10b973f66d9ed6812.txt b/.github/actions/spelling/expect/205c1ec487b80f127ca611d10b973f66d9ed6812.txt deleted file mode 100644 index 0252bd5aac8..00000000000 --- a/.github/actions/spelling/expect/205c1ec487b80f127ca611d10b973f66d9ed6812.txt +++ /dev/null @@ -1,29 +0,0 @@ -askubuntu -BIV -boxheader -colortest -Crisman -DISABLEDELAYEDEXPANSION -dostips -dpnx -Dyreen -EINS -EQU -FGs -forground -GTR -HOWTO -ltrim -maxval -outstr -Rexx -rosettacode -ROY -Rtn -rtrim -STUBHEAD -tldp -uwaterloo -uwspace -viewtopic -wrkstr diff --git a/.github/actions/spelling/expect/expect.txt b/.github/actions/spelling/expect/expect.txt index be72bf38243..0cf630d708c 100644 --- a/.github/actions/spelling/expect/expect.txt +++ b/.github/actions/spelling/expect/expect.txt @@ -12,7 +12,6 @@ ACTCTXW activatable ACTIVEBORDER ACTIVECAPTION -adaa ADDALIAS ADDREF addressof @@ -161,6 +160,7 @@ Borland BOTTOMLEFT BOTTOMRIGHT boutput +boxheader BPBF bpp BPPF @@ -287,8 +287,6 @@ codepage codepath codepoint codeproject -coffgroup -coffgrp coinit COLLECTIONURI colorizing @@ -299,6 +297,7 @@ colorspaces colorspec colortable colortbl +colortest colortool COLR combaseapi @@ -402,6 +401,7 @@ creativecommons cred cref crend +Crisman CRLFs crloew Crt @@ -480,7 +480,6 @@ dai DATABLOCK DATAVIEW DATAW -datetime DBatch dbcs DBCSCHAR @@ -610,6 +609,7 @@ DINLINE directio DIRECTX Dirs +DISABLEDELAYEDEXPANSION DISABLENOSCROLL DISPLAYATTRIBUTE DISPLAYATTRIBUTEPROPERTY @@ -641,6 +641,7 @@ DPICHANGE DPICHANGED dpix dpiy +dpnx DRAWFRAME DRAWITEM DRAWITEMSTRUCT @@ -672,8 +673,8 @@ dxgidwm dxinterop dxsm dxttbmp +Dyreen eachother -eae eaf EASTEUROPE ECH @@ -688,13 +689,13 @@ edputil edu Efast EHsc +EINS EJO ELEMENTNOTAVAILABLE elems elif elseif emacs -emplate EMPTYBOX enabledelayedexpansion endian @@ -714,6 +715,7 @@ enumranges envvar eol EPres +EQU ERASEBKGND errno errorlevel @@ -768,6 +770,7 @@ fgetc fgetwc FGHIJ fgidx +FGs FILEDESCRIPTION fileno filepath @@ -821,6 +824,7 @@ FORCEOFFFEEDBACK FORCEONFEEDBACK FORCEV foreach +forground fprintf framebuffer FRAMECHANGED @@ -853,7 +857,6 @@ gcy gdi gdip gdirenderer -GENPROFILE geopol GETALIAS GETALIASES @@ -938,6 +941,7 @@ groupbox gset gsl GTP +GTR guc gui guidatom @@ -972,7 +976,6 @@ hfont hfontresource hglobal hhh -HHmm hhook hhx HIBYTE @@ -1002,7 +1005,6 @@ horiz HORZ hostable hostlib -Hostx HPA HPAINTBUFFER HPCON @@ -1129,7 +1131,6 @@ INPUTPROCESSORPROFILE inputrc Inputreadhandledata INSERTMODE -installationpath intellisense INTERACTIVITYBASE INTERCEPTCOPYPASTE @@ -1358,6 +1359,7 @@ lstrcmp lstrcmpi LTEXT LTLTLTLTL +ltrim ltype LUID lval @@ -1384,6 +1386,7 @@ MAXDIMENSTRING maxing MAXLENGTH MAXSHORT +maxval maxversiontested MAXWORD maybenull @@ -1392,6 +1395,7 @@ MBUTTONDBLCLK MBUTTONDOWN MBUTTONUP Mbxy +mdecreased mdmerge MDs MEASUREITEM @@ -1417,6 +1421,7 @@ MIIM milli mimetype mincore +mincreased mindbogglingly mingw minimizeall @@ -1429,7 +1434,6 @@ mkdir MMBB mmcc MMCPL -MMdd mmsystem MNC MNOPQ @@ -1687,6 +1691,7 @@ OUTOFCONTEXT OUTOFMEMORY outout Outptr +outstr OVERLAPPEDWINDOW OWNDC OWNERDRAWFIXED @@ -1983,7 +1988,6 @@ REGISTERVDM regkey REGSTR reingest -Relayout RELBINPATH remoting renamer @@ -2046,6 +2050,8 @@ rtf RTFTo Rtl RTLREADING +Rtn +rtrim RTTI ruleset runas @@ -2261,6 +2267,7 @@ strrev strsafe strtok structs +STUBHEAD STUVWX STX stylecop @@ -2770,6 +2777,7 @@ WRITECONSOLE WRITECONSOLEINPUT WRITECONSOLEOUTPUT WRITECONSOLEOUTPUTSTRING +wrkstr wrl wrp WRunoff diff --git a/.github/actions/spelling/expect/web.txt b/.github/actions/spelling/expect/web.txt index 826edf1af8e..4b95ef2e627 100644 --- a/.github/actions/spelling/expect/web.txt +++ b/.github/actions/spelling/expect/web.txt @@ -17,3 +17,12 @@ mdtauk cppreference gfycat Guake +askubuntu +dostips +viewtopic +rosettacode +Rexx +tldp +HOWTO +uwspace +uwaterloo diff --git a/.github/actions/spelling/patterns/patterns.txt b/.github/actions/spelling/patterns/patterns.txt index 2e89f5e253e..3c7d83aeb25 100644 --- a/.github/actions/spelling/patterns/patterns.txt +++ b/.github/actions/spelling/patterns/patterns.txt @@ -25,3 +25,4 @@ std::memory_order_[\w]+ D2DERR_SHADER_COMPILE_FAILED TIL_FEATURE_[0-9A-Z_]+ vcvars\w* +ROY\sG\.\sBIV \ No newline at end of file From cbe710389f0785212d66c1ffad5ad3e1fc2086de Mon Sep 17 00:00:00 2001 From: Ryan Beesley Date: Wed, 29 Dec 2021 23:06:53 -0800 Subject: [PATCH 29/35] Fixed warning in patterns.txt and modified sgr.def Sgr.def now has the columns arranged so that they are in order and includes the default foreground and background codes, 39m and 49m. Removing the warning in patterns.txt seems like it might be causing a build problem. --- .../actions/spelling/patterns/patterns.txt | 2 +- src/tools/ansi-color/sgr.def | 182 ++++++++++-------- 2 files changed, 98 insertions(+), 86 deletions(-) diff --git a/.github/actions/spelling/patterns/patterns.txt b/.github/actions/spelling/patterns/patterns.txt index 3c7d83aeb25..670bf3bf502 100644 --- a/.github/actions/spelling/patterns/patterns.txt +++ b/.github/actions/spelling/patterns/patterns.txt @@ -25,4 +25,4 @@ std::memory_order_[\w]+ D2DERR_SHADER_COMPILE_FAILED TIL_FEATURE_[0-9A-Z_]+ vcvars\w* -ROY\sG\.\sBIV \ No newline at end of file +ROY\sG\.\sBIV diff --git a/src/tools/ansi-color/sgr.def b/src/tools/ansi-color/sgr.def index 85cfd5e31f7..3daed559620 100644 --- a/src/tools/ansi-color/sgr.def +++ b/src/tools/ansi-color/sgr.def @@ -1,7 +1,7 @@ :: Complete matrix of SGR parameters available :: This definition also demonstrates the various configuration changes :: which are used to control the way the table is generated -:: Requires 92 columns to display correctly +:: Requires 97 columns to display correctly __DATA__ :: Select Graphic Rendition (SGR) parameters :: #NUL# is treated as a special case to provide cells in that column @@ -71,20 +71,21 @@ REM 8m REM 9m REM 21m 40m -100m 41m -101m 42m -102m 43m -103m 44m -104m 45m -105m 46m -106m 47m +49m +100m +101m +102m +103m +104m +105m +106m 107m __COLS:END__ @@ -127,210 +128,221 @@ REM 29m :: Normal #LBL# !SECTION!Normal 30m -90m 31m -91m 32m -92m 33m -93m 34m -94m 35m -95m 36m -96m 37m +39m +90m +91m +92m +93m +94m +95m +96m 97m #SPC# :: Bold or increased intensity, 1 #LBL# !SECTION!Bold or increased intensity, 1 1;30m -1;90m 1;31m -1;91m 1;32m -1;92m 1;33m -1;93m 1;34m -1;94m 1;35m -1;95m 1;36m -1;96m 1;37m +1;39m +1;90m +1;91m +1;92m +1;93m +1;94m +1;95m +1;96m 1;97m #SPC# :: Faint (decreased intensity), 2 #LBL# !SECTION!Faint (decreased intensity), 2 2;30m -2;90m 2;31m -2;91m 2;32m -2;92m 2;33m -2;93m 2;34m -2;94m 2;35m -2;95m 2;36m -2;96m 2;37m +2;39m +2;90m +2;91m +2;92m +2;93m +2;94m +2;95m +2;96m 2;97m #SPC# :: Italic, 3 #LBL# !SECTION!Italic, 3 3;30m -3;90m 3;31m -3;91m 3;32m -3;92m 3;33m -3;93m 3;34m -3;94m 3;35m -3;95m 3;36m -3;96m 3;37m +3;39m +3;90m +3;91m +3;92m +3;93m +3;94m +3;95m +3;96m 3;97m #SPC# :: Underline, 4 #LBL# !SECTION!Underline, 4 4;30m -4;90m 4;31m -4;91m 4;32m -4;92m 4;33m -4;93m 4;34m -4;94m 4;35m -4;95m 4;36m -4;96m 4;37m +4;39m +4;90m +4;91m +4;92m +4;93m +4;94m +4;95m +4;96m 4;97m #SPC# :: Slow Blink, 5 #LBL# !SECTION!Slow Blink, 5 5;30m -5;90m 5;31m -5;91m 5;32m -5;92m 5;33m -5;93m 5;34m -5;94m 5;35m -5;95m 5;36m -5;96m 5;37m +5;39m +5;90m +5;91m +5;92m +5;93m +5;94m +5;95m +5;96m 5;97m #SPC# :: Rapid Blink, 6 #LBL# !SECTION!Rapid Blink, 6 6;30m -6;90m 6;31m -6;91m 6;32m -6;92m 6;33m -6;93m 6;34m -6;94m 6;35m -6;95m 6;36m -6;96m 6;37m +6;39m +6;90m +6;91m +6;92m +6;93m +6;94m +6;95m +6;96m 6;97m #SPC# :: Reverse video, 7 #LBL# !SECTION!Reverse video, 7 7;30m -7;90m 7;31m -7;91m 7;32m -7;92m 7;33m -7;93m 7;34m -7;94m 7;35m -7;95m 7;36m -7;96m 7;37m +7;39m +7;90m +7;91m +7;92m +7;93m +7;94m +7;95m +7;96m 7;97m #SPC# :: Conceal, 8 #LBL# !SECTION!Conceal, 8 8;30m -8;90m 8;31m -8;91m 8;32m -8;92m 8;33m -8;93m 8;34m -8;94m 8;35m -8;95m 8;36m -8;96m 8;37m +8;39m +8;90m +8;91m +8;92m +8;93m +8;94m +8;95m +8;96m 8;97m #SPC# :: Crossed-out, 9 #LBL# !SECTION!Crossed-out, 9 9;30m -9;90m 9;31m -9;91m 9;32m -9;92m 9;33m -9;93m 9;34m -9;94m 9;35m -9;95m 9;36m -9;96m 9;37m +9;39m +9;90m +9;91m +9;92m +9;93m +9;94m +9;95m +9;96m 9;97m #SPC# :: Double Underline, 21 #LBL# !SECTION!Double Underline, 21 21;30m -21;90m 21;31m -21;91m 21;32m -21;92m 21;33m -21;93m 21;34m -21;94m 21;35m -21;95m 21;36m -21;96m 21;37m +21;39m +21;90m +21;91m +21;92m +21;93m +21;94m +21;95m +21;96m 21;97m __ROWS:END__ __DATA:END__ \ No newline at end of file From 0586920a5360687668a01d03b96056858a38096a Mon Sep 17 00:00:00 2001 From: Ryan Beesley Date: Wed, 29 Dec 2021 23:55:13 -0800 Subject: [PATCH 30/35] Updated attrib.def and fixed tsgr.def Attrib.def now has defaults 39m and 49m, and tsgr.def had 30m before the #SPC# separator. Both minor fixes but probably won't be fixed after this is pulled into the main repo. --- src/tools/ansi-color/attrib.def | 24 ++++++++++++++++++++++++ src/tools/ansi-color/tsgr.def | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/tools/ansi-color/attrib.def b/src/tools/ansi-color/attrib.def index 871e6839797..09b0e151c61 100644 --- a/src/tools/ansi-color/attrib.def +++ b/src/tools/ansi-color/attrib.def @@ -133,6 +133,18 @@ __ROWS__ 8;37m 9;37m 21;37m +#SPC# + 39m + 1;39m + 2;39m + 3;39m + 4;39m + 5;39m + 6;39m + 7;39m + 8;39m + 9;39m + 21;39m #SPC# 40m 1;40m @@ -229,6 +241,18 @@ __ROWS__ 8;47m 9;47m 21;47m +#SPC# + 49m + 1;49m + 2;49m + 3;49m + 4;49m + 5;49m + 6;49m + 7;49m + 8;49m + 9;49m + 21;49m #SPC# 90m 1;90m diff --git a/src/tools/ansi-color/tsgr.def b/src/tools/ansi-color/tsgr.def index 24dde7328e8..39def860f76 100644 --- a/src/tools/ansi-color/tsgr.def +++ b/src/tools/ansi-color/tsgr.def @@ -91,8 +91,8 @@ __ROWS__ 8m 9m 21m -30m #SPC# +30m 1;30m 2;30m 3;30m From 9fc236dc4e897fc24aa8368fd48d7da8860c85bb Mon Sep 17 00:00:00 2001 From: Ryan Beesley Date: Thu, 30 Dec 2021 01:43:11 -0800 Subject: [PATCH 31/35] Don't count #SPC# for R1C1 columns For rows, ansi-color.cmd already skips #SPC# and #LBL#. This change extends this behavior to the columns as well. R1C1 references only apply to where the cell is filled. At the same time the order of the checks were inverted to make the reference check fix cleaner and to make the check for #NUL# and #SPC# easier to manage. --- src/tools/ansi-color/ansi-color.cmd | 55 +++++++++++++++++++---------- 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/src/tools/ansi-color/ansi-color.cmd b/src/tools/ansi-color/ansi-color.cmd index 3f3b1e3e78b..d61e3b6ad32 100644 --- a/src/tools/ansi-color/ansi-color.cmd +++ b/src/tools/ansi-color/ansi-color.cmd @@ -408,7 +408,7 @@ FOR /F "tokens=*" %%_ IN ('chcp 2^>^&1 ^& FOR /F %%_ IN ^("ERRORLEVEL"^) DO @CAL IF [!CHCP_ERR!] NEQ [0] ( :: This means that the call to CHCP failed ECHO Warning: Error reading the active codepage, check the output from the command CHCP. - If DEFINED SHOW.UTF8 ( + IF DEFINED SHOW.UTF8 ( :: UTF-8 support is required if SHOW.UTF8 is defined, so error out ECHO. ECHO Error: UTF-8 support is required for the definition file in use or flags provided. @@ -430,8 +430,10 @@ FOR /F "tokens=*" %%_ IN ('chcp 2^>^&1 ^& FOR /F %%_ IN ^("ERRORLEVEL"^) DO @CAL FOR %%_ IN (!CHCP_RET!) DO (SET CHCP=%%_) IF DEFINED CHCP ( IF [!CHCP!] EQU [65001] ( + :: If the CHCP value was 65001, we can show UTF8 and we don't need to check more SET "SHOW.UTF8=#TRUE#" ) ELSE ( + :: Otherwise we now want to set the codepage to 65001 and exit with the error if that fails IF DEFINED SHOW.UTF8 ( chcp 65001 > NUL 2>&1 IF ERRORLEVEL 1 ( @@ -445,7 +447,10 @@ SET "CHCP_OUT=" SET "CHCP_ERR=" SET "CHCP_RET=" -:: This is a separate code block so that the active console Code Page is changed first +:: This is a separate code block from the test above so that the active console Code Page +:: is changed first. If we want to show the ANSI characters rather than actually drawing +:: them, we need to replace ESC with a Unicode codepoint which represents ESC. We do this +:: now that UTF8 has been configured for the console and before we define the CSI commands. IF DEFINED SHOW.ANSI ( SET "ESC=␛" ) @@ -903,11 +908,13 @@ IF DEFINED SEPARATOR.HORIZONTAL ( SET "TABLE[!TABLE[#]!]=!LINE!" ) -:: Figure out the CELL alignment now so we only need to compute this once -IF NOT DEFINED SHOW.R1C1_REFERENCE ( - %@align% CELL !COL.MAX_WIDTH! !ALIGN.CELL! CELL -) ELSE ( +:: If we're going to show an R1C1 reference, we don't need to compute the cell alignment +IF DEFINED SHOW.R1C1_REFERENCE ( + :: Set up the R1C1 row counter SET /A "R1C1_REFERENCE.R=0" +) ELSE ( + :: Otherwise figure out the CELL alignment now so we only need to compute this once + %@align% CELL !COL.MAX_WIDTH! !ALIGN.CELL! CELL ) :: Build the row @@ -956,37 +963,47 @@ FOR /L %%r IN (1,1,!ROW[#]!) DO ( SET "ROW=!CSI!!ROW!" ) + :: Set up the R1C1 column counter IF DEFINED SHOW.R1C1_REFERENCE ( SET /A "R1C1_REFERENCE.C=0" %@counter% R1C1_REFERENCE.R ) - :: Append a cell to the row + + :: Append a cell to the row, adding separators unless processing the first column FOR /L %%c IN (1,1,!COL[#]!) DO ( + :: This is where we actually build the R1C1 reference, replacing the CELL IF DEFINED SHOW.R1C1_REFERENCE ( %@counter% R1C1_REFERENCE.C SET "R1C1_REFERENCE=R!R1C1_REFERENCE.R!C!R1C1_REFERENCE.C!" %@align% R1C1_REFERENCE !COL.MAX_WIDTH! !ALIGN.CELL.R1C1! CELL ) + IF /I ["!COL[%%c]!"] EQU ["#NUL#"] ( - SET "COL=" - ) ELSE ( - SET "COL=!CSI!!COL[%%c]!" - ) - IF [%%c] EQU [1] ( - IF /I ["!COL[%%c]!"] EQU ["#SPC#"] ( - %@repeat% #SPC# !COL.MAX_WIDTH! OUT + :: Special case for #NUL# + IF [%%c] EQU [1] ( + SET "LINE=!LINE!!ROW!!CELL!!RESET!" + ) ELSE ( + SET "LINE=!LINE!!SEPARATOR.CELL!!ROW!!CELL!!RESET!" + ) + ) ELSE IF /I ["!COL[%%c]!"] EQU ["#SPC#"] ( + :: Special case for #SPC# + %@repeat% #SPC# !COL.MAX_WIDTH! OUT + IF [%%c] EQU [1] ( SET "LINE=!LINE!!OUT!" ) ELSE ( - SET "LINE=!LINE!!ROW!!COL!!CELL!!RESET!" + SET "LINE=!LINE!!SEPARATOR.CELL!!OUT!" ) + :: Don't count spaces as columns for R1C1_REFERENCE + SET /A "R1C1_REFERENCE.C-=1" ) ELSE ( - IF /I ["!COL[%%c]!"] EQU ["#SPC#"] ( - %@repeat% #SPC# !COL.MAX_WIDTH! OUT - SET "LINE=!LINE!!SEPARATOR.CELL!!OUT!" + :: Normal processing + SET "COL=!CSI!!COL[%%c]!" + IF [%%c] EQU [1] ( + SET "LINE=!LINE!!ROW!!COL!!CELL!!RESET!" ) ELSE ( SET "LINE=!LINE!!SEPARATOR.CELL!!ROW!!COL!!CELL!!RESET!" ) - ) + ) ) ) From 6e61b29ef26c7bcdf3b2aa724e25e296c90f54e0 Mon Sep 17 00:00:00 2001 From: Ryan Beesley Date: Mon, 3 Jan 2022 10:52:51 -0800 Subject: [PATCH 32/35] Added column intersects and addressed CR comments Added a separator.def which can model using separator variables in a definition file. For the table code to be "complete" there would need to be a border and row separators, but it seems like that would have low value as it would just grow the height without additional benefit. Similarly, borders would grow the width and height by two with no real perceived gain. --- .github/actions/spelling/expect/expect.txt | 2 - .../actions/spelling/patterns/patterns.txt | 2 + src/tools/ansi-color/ansi-color.cmd | 296 ++++++++++++------ src/tools/ansi-color/ansi-colortool.def | 18 +- src/tools/ansi-color/separator.def | 124 ++++++++ 5 files changed, 336 insertions(+), 106 deletions(-) create mode 100644 src/tools/ansi-color/separator.def diff --git a/.github/actions/spelling/expect/expect.txt b/.github/actions/spelling/expect/expect.txt index 0cf630d708c..54b34df799e 100644 --- a/.github/actions/spelling/expect/expect.txt +++ b/.github/actions/spelling/expect/expect.txt @@ -1395,7 +1395,6 @@ MBUTTONDBLCLK MBUTTONDOWN MBUTTONUP Mbxy -mdecreased mdmerge MDs MEASUREITEM @@ -1421,7 +1420,6 @@ MIIM milli mimetype mincore -mincreased mindbogglingly mingw minimizeall diff --git a/.github/actions/spelling/patterns/patterns.txt b/.github/actions/spelling/patterns/patterns.txt index 670bf3bf502..2fc6e0b708c 100644 --- a/.github/actions/spelling/patterns/patterns.txt +++ b/.github/actions/spelling/patterns/patterns.txt @@ -26,3 +26,5 @@ D2DERR_SHADER_COMPILE_FAILED TIL_FEATURE_[0-9A-Z_]+ vcvars\w* ROY\sG\.\sBIV +!(?:(?i)ESC)!\[ +!(?:(?i)CSI)!(?:\d+(?:;\d+|)m|[ABCDF]) diff --git a/src/tools/ansi-color/ansi-color.cmd b/src/tools/ansi-color/ansi-color.cmd index d61e3b6ad32..76212779ccc 100644 --- a/src/tools/ansi-color/ansi-color.cmd +++ b/src/tools/ansi-color/ansi-color.cmd @@ -398,7 +398,7 @@ IF DEFINED SHOW.ANSI ( ) :: The console (CMD) is normally not UTF-8, so preserve the codepage so we can reset it. -:: Because the output of chcp is localized, we grab the last value of the string, +:: Because the output of CHCP is localized, we grab the last value of the string, :: which we have our fingers crossed, will be the codepage. FOR /F "tokens=*" %%_ IN ('chcp 2^>^&1 ^& FOR /F %%_ IN ^("ERRORLEVEL"^) DO @CALL ECHO __ERRORLEVEL__:%%%%_%%') DO ( SET CHCP_OUT=%%_ @@ -497,6 +497,8 @@ SET "ALIGN.STUB=R" SET "ALIGN.STUBHEAD_STUB=C" SET "ALIGN.STUB_BODY=C" SET "ALIGN.BOXHEAD_BODY=C" +SET "ALIGN.INTERSECT=C" +SET "ALIGN.STUB_BOXHEAD_INTERSECT=C" :: Separators SET "SEPARATOR.STUB=" @@ -510,6 +512,7 @@ SET "SEPARATOR.BOXHEAD_BODY=" SET "SEPARATOR.BOXHEAD=" SET "SEPARATOR.INTERSECT=" SET "SEPARATOR.STUB_BOXHEAD_INTERSECT=" +SET "SEPARATOR.COL_INTERSECT=" :: Flags SET "SEPARATOR.VERTICAL=" @@ -588,7 +591,8 @@ SET "DATA=%*" :: We're parsing the data segment, so clean up the data before further processing %@trim% DATA -:: Skip over any comments +:: Skip over any blank lines or comments +IF NOT DEFINED DATA %@exit% IF /I ["!DATA!"] EQU ["REM"] %@exit% IF /I ["!DATA!"] EQU ["@REM"] %@exit% IF /I ["!DATA:~0,2!"] EQU ["::"] %@exit% @@ -670,19 +674,60 @@ SET "ROW[!ROW[#]!]=!ROW!" IF DEFINED UTF8.REQUIRED ( IF NOT DEFINED SHOW.UTF8 ( SET "SCRIPT_NAME=%~nx0" - SET "msg=Error: UTF-8 console support is required.!LF! Try ^"!SCRIPT_NAME! /U [^]^" to enable UTF-8 support!LF! or change the default configuration in !SCRIPT_NAME! to always use UTF-8." - CALL :USAGE msg + SET "MSG=Error: UTF-8 console support is required.!LF! Try ^"!SCRIPT_NAME! /U [^]^" to enable UTF-8 support!LF! or change the default configuration in !SCRIPT_NAME! to always use UTF-8." + CALL :USAGE MSG %@exit% 1 ) ) %@exit% -:: Separators have cascading effects, so if some are not defined this is where -:: they are defined :RESOLVE_SEPARATORS +:: There's a lot to consider with separators in trying to do what is best +:: for the definition author. Look at the separator.def and ansi-colortool.def +:: for examples for how to most effectively manage this. + +:: Separators have cascading effects, so if some are not defined this is where +:: they are defined. + +:: Define the column separator +:: +:: SEPARATOR.COL is the default column separator and it will be overridden +:: by SEPARATOR.BOXHEADERS or SEPARATOR.CELL. +:: If SEPARATOR.COL is not defined, and SEPARATOR.BOXHEADERS is defined +:: but SEPARATOR.CELL is not defined, or vice versa, then the undefined +:: separator will be defined with a space to preserve proper separation. +IF DEFINED SEPARATOR.COL ( + SET "SEPARATOR.COLUMN=#TRUE#" + IF NOT DEFINED SEPARATOR.BOXHEADERS ( + SET "SEPARATOR.BOXHEADERS=!SEPARATOR.COL!" + ) + IF NOT DEFINED SEPARATOR.CELL ( + SET "SEPARATOR.CELL=!SEPARATOR.COL!" + ) +) ELSE ( + IF DEFINED SEPARATOR.BOXHEADERS ( + SET "SEPARATOR.COLUMN=#TRUE#" + IF NOT DEFINED SEPARATOR.CELL ( + SET "SEPARATOR.CELL= " + ) + ) + IF DEFINED SEPARATOR.CELL ( + SET "SEPARATOR.COLUMN=#TRUE#" + IF NOT DEFINED SEPARATOR.BOXHEADERS ( + SET "SEPARATOR.BOXHEADERS= " + ) + ) +) :: Define the vertical separator +:: +:: SEPARATOR.STUB is the default vertical separator and it will be +:: overridden by SEPARATOR.STUBHEAD_BOXHEAD or SEPARATOR.STUB_BODY. +:: If SEPARATOR.STUB is not defined, and SEPARATOR.STUB_BODY is defined +:: but SEPARATOR.STUBHEAD_BOXHEAD is not defined, or vice versa, then +:: the undefined separator will be defined with a space to preserve +:: proper separation. IF DEFINED SEPARATOR.STUB ( SET "SEPARATOR.VERTICAL=#TRUE#" IF NOT DEFINED SEPARATOR.STUBHEAD_BOXHEAD ( @@ -692,21 +737,48 @@ IF DEFINED SEPARATOR.STUB ( SET "SEPARATOR.STUB_BODY=!SEPARATOR.STUB!" ) ) ELSE ( + IF DEFINED SEPARATOR.STUB_BODY ( + SET "SEPARATOR.VERTICAL=#TRUE#" + IF NOT DEFINED SEPARATOR.STUBHEAD_BOXHEAD ( + SET "SEPARATOR.STUBHEAD_BOXHEAD= " + ) + ) IF DEFINED SEPARATOR.STUBHEAD_BOXHEAD ( SET "SEPARATOR.VERTICAL=#TRUE#" IF NOT DEFINED SEPARATOR.STUB_BODY ( SET "SEPARATOR.STUB_BODY= " ) ) - IF DEFINED SEPARATOR.STUB_BODY ( +) + +:: If there is no vertical separator defined, but there is a column separator +:: assume that the column separator should be uniformally applied. This can be +:: forcibly overridden by putting SET "SEPARATOR.VERTICAL=#TRUE#" in the table +:: definition and leaving SEPARATOR.STUBHEAD_BOXHEAD and SEPARATOR.STUB_BODY +:: undefined. +IF NOT DEFINED SEPARATOR.VERTICAL ( + IF DEFINED SEPARATOR.COLUMN ( SET "SEPARATOR.VERTICAL=#TRUE#" - IF NOT DEFINED SEPARATOR.STUBHEAD_BOXHEAD ( - SET "SEPARATOR.STUBHEAD_BOXHEAD= " + SET "SEPARATOR.STUBHEAD_BOXHEAD=!SEPARATOR.BOXHEADERS!" + SET "SEPARATOR.STUB_BODY=!SEPARATOR.CELL!" + IF NOT DEFINED SEPARATOR.INTERSECT ( + SET "SEPARATOR.INTERSECT=!SEPARATOR.COL_INTERSECT!" + ) + IF NOT DEFINED SEPARATOR.COL_INTERSECT ( + SET "SEPARATOR.COL_INTERSECT=!SEPARATOR.INTERSECT!" ) ) ) :: Define the horizontal separator +:: +:: SEPARATOR.BOXHEAD is the default horizontal separator and it will be +:: overridden by SEPARATOR.STUBHEAD_STUB or SEPARATOR.BOXHEAD_BODY. +:: If SEPARATOR.BOXHEAD is not defined and SEPARATOR.BOXHEAD_BODY is defined +:: but SEPARATOR.STUBHEAD_STUB is not defined, SEPARATOR.STUBHEAD_STUB will +:: be defined with a space so that there is proper separation. +:: SEPARATOR.BOXHEAD_BODY does not need this treatment as a newline is an +:: adequate replacement for trailing spaces. IF DEFINED SEPARATOR.BOXHEAD ( SET "SEPARATOR.HORIZONTAL=#TRUE#" IF NOT DEFINED SEPARATOR.STUBHEAD_STUB ( @@ -718,9 +790,6 @@ IF DEFINED SEPARATOR.BOXHEAD ( ) ELSE ( IF DEFINED SEPARATOR.STUBHEAD_STUB ( SET "SEPARATOR.HORIZONTAL=#TRUE#" - IF NOT DEFINED SEPARATOR.BOXHEAD_BODY ( - SET "SEPARATOR.BOXHEAD_BODY= " - ) ) IF DEFINED SEPARATOR.BOXHEAD_BODY ( SET "SEPARATOR.HORIZONTAL=#TRUE#" @@ -730,32 +799,8 @@ IF DEFINED SEPARATOR.BOXHEAD ( ) ) -:: Define the column separator -IF DEFINED SEPARATOR.COL ( - SET "SEPARATOR.COLUMN=#TRUE#" - IF NOT DEFINED SEPARATOR.BOXHEADERS ( - SET "SEPARATOR.BOXHEADERS=!SEPARATOR.COL!" - ) - IF NOT DEFINED SEPARATOR.CELL ( - SET "SEPARATOR.CELL=!SEPARATOR.COL!" - ) -) ELSE ( - IF DEFINED SEPARATOR.BOXHEADERS ( - SET "SEPARATOR.COLUMN=#TRUE#" - IF NOT DEFINED SEPARATOR.CELL ( - SET "SEPARATOR.CELL= " - ) - ) - IF DEFINED SEPARATOR.CELL ( - SET "SEPARATOR.COLUMN=#TRUE#" - IF NOT DEFINED SEPARATOR.BOXHEADERS ( - SET "SEPARATOR.BOXHEADERS= " - ) - ) -) - :: SEPARATOR.INTERSECT is intended to be a friendlier name of SEPARATOR.STUB_BOXHEAD_INTERSECT -:: Only one should be defined with a non-space character +:: Only one should be defined with a non-space character. IF DEFINED SEPARATOR.INTERSECT ( IF NOT DEFINED SEPARATOR.STUB_BOXHEAD_INTERSECT ( SET "SEPARATOR.STUB_BOXHEAD_INTERSECT=!SEPARATOR.INTERSECT!" @@ -764,58 +809,78 @@ IF DEFINED SEPARATOR.INTERSECT ( ) ) -:: Trim the variables we use to draw our separators -:: so we only work with non-space characters -SET "SEPARATOR.COL.TRIM=!SEPARATOR.COL!" -%@trim% SEPARATOR.COL.TRIM -SET "SEPARATOR.BOXHEAD.TRIM=!SEPARATOR.BOXHEAD!" -%@trim% SEPARATOR.BOXHEAD.TRIM -SET "SEPARATOR.INTERSECT.TRIM=!SEPARATOR.INTERSECT!" -%@trim% SEPARATOR.INTERSECT.TRIM -SET "SEPARATOR.STUB.TRIM=!SEPARATOR.STUB!" -%@trim% SEPARATOR.STUB.TRIM -SET "SEPARATOR.CELL.TRIM=!SEPARATOR.CELL!" -%@trim% SEPARATOR.CELL.TRIM -SET "SEPARATOR.STUBHEAD_BOXHEAD.TRIM=!SEPARATOR.STUBHEAD_BOXHEAD!" -%@trim% SEPARATOR.STUBHEAD_BOXHEAD.TRIM -SET "SEPARATOR.STUB_BODY.TRIM=!SEPARATOR.STUB_BODY!" -%@trim% SEPARATOR.STUB_BODY.TRIM -SET "SEPARATOR.STUBHEAD_STUB.TRIM=!SEPARATOR.STUBHEAD_STUB!" -%@trim% SEPARATOR.STUBHEAD_STUB.TRIM -SET "SEPARATOR.BOXHEAD_BODY.TRIM=!SEPARATOR.BOXHEAD_BODY!" -%@trim% SEPARATOR.BOXHEAD_BODY.TRIM - +:: Determine if we need an intersect and if it wasn't already defined +:: decide what makes the most sense based on other separators, either +:: trying to extend the vertical default or the horizontal default. +:: If default vertical or horizontal separators weren't used, it is an +:: advanced definition and the interesect should have been provided, +:: so with no better guidance we define it as a space. IF DEFINED SEPARATOR.VERTICAL ( IF DEFINED SEPARATOR.HORIZONTAL ( - IF NOT DEFINED SEPARATOR.STUB_BOXHEAD_INTERSECT.TRIM ( - IF DEFINED SEPARATOR.INTERSECT.TRIM ( - SET "SEPARATOR.STUB_BOXHEAD_INTERSECT=!SEPARATOR.INTERSECT!" + :: Both vertical and horizontal separators are defined + IF NOT DEFINED SEPARATOR.STUB_BOXHEAD_INTERSECT ( + :: But no intersect was actually defined + IF DEFINED SEPARATOR.STUB ( + :: A default vertical separator is already defined + IF NOT DEFINED SEPARATOR.BOXHEAD ( + :: but not a default horizontal, so extend the vertical + SET "SEPARATOR.STUB_BOXHEAD_INTERSECT=!SEPARATOR.STUB!" + ) ELSE ( + :: SEPARATOR.INTERSECT should be defined by the definition, just provide a space + SET "SEPARATOR.STUB_BOXHEAD_INTERSECT= " + ) ) ELSE ( - IF DEFINED SEPARATOR.STUB.TRIM ( - IF NOT DEFINED SEPARATOR.BOXHEAD.TRIM ( - SET "SEPARATOR.STUB_BOXHEAD_INTERSECT=!SEPARATOR.STUB!" - ) ELSE ( - SET "SEPARATOR.STUB_BOXHEAD_INTERSECT= " - ) + :: There is no default vertical separator + IF DEFINED SEPARATOR.BOXHEAD ( + :: but there is a default horizontal, so extend the horizontal + SET "SEPARATOR.STUB_BOXHEAD_INTERSECT=!SEPARATOR.BOXHEAD!" ) ELSE ( - IF DEFINED SEPARATOR.BOXHEAD.TRIM ( - SET "SEPARATOR.STUB_BOXHEAD_INTERSECT=!SEPARATOR.BOXHEAD!" - ) ELSE ( - SET "SEPARATOR.STUB_BOXHEAD_INTERSECT= " - ) + :: SEPARATOR.INTERSECT should be defined by the definition, just provide a space + SET "SEPARATOR.STUB_BOXHEAD_INTERSECT= " ) ) ) ) ELSE ( - SET "SEPARATOR.STUB_BOXHEAD_INTERSECT=!SEPARATOR.STUB!" + :: Both a vertical and horizontal separator are needed for a SEPARATOR.INTERSECT, so undefine + SET "SEPARATOR.STUB_BOXHEAD_INTERSECT=" ) ) ELSE ( - IF DEFINED SEPARATOR.HORIZONTAL ( - SET "SEPARATOR.STUB_BOXHEAD_INTERSECT=!SEPARATOR.BOXHEAD!" - ) + :: Both a vertical and horizontal separator are needed for a SEPARATOR.INTERSECT, so undefine SET "SEPARATOR.STUB_BOXHEAD_INTERSECT=" ) +:: If SEPARATOR.COL_INTERSECT is not defined, but SEPARATOR.BOXHEAD_BODY is defined, +:: see if SEPARATOR.COLS, SEPARATOR.CELL, or SEPARATOR.BOXHEADERS is defined and extend +:: SEPARATOR.BOXHEAD_BODY for SEPARATOR.COL_INTERSECT as default. +IF NOT DEFINED SEPARATOR.COL_INTERSECT ( + IF DEFINED SEPARATOR.BOXHEAD_BODY ( + IF DEFINED SEPARATOR.COL ( + SET "SEPARATOR.COL_INTERSECT=!SEPARATOR.BOXHEAD_BODY!" + ) ELSE IF DEFINED SEPARATOR.CELL ( + SET "SEPARATOR.COL_INTERSECT=!SEPARATOR.BOXHEAD_BODY!" + ) ELSE IF DEFINED SEPARATOR.BOXHEADERS ( + SET "SEPARATOR.COL_INTERSECT=!SEPARATOR.BOXHEAD_BODY!" + ) + ) +) + +:: SEPARATOR.COL_INTERSECT only applies if SEPARATOR.BOXHEADERS, SEPARATOR.COL, or SEPARATOR.CELL is defined +IF DEFINED SEPARATOR.COL_INTERSECT ( + IF NOT DEFINED SEPARATOR.BOXHEADERS ( + IF NOT DEFINED SEPARATOR.COL ( + IF NOT DEFINED SEPARATOR.CELL ( + SET "SEPARATOR.COL_INTERSECT=" + ) + ) + ) +) + +:: Now with all the separators resolved, determine the maximum vertical width in +:: the stub separators. This is the only category of separators supported to be +:: more than a character wide because it can be calculated in a column whereas +:: a horizontal separator would require multiple lines and that hasn't been +:: implemented. Boxhead and Cell separators could conceivably be more than a +:: character, but that would quickly take up more space as it is multiplied out. IF DEFINED SEPARATOR.VERTICAL ( SET /A "SEPARATOR.VERTICAL.WIDTH=0" %@strlen% SEPARATOR.STUBHEAD_BOXHEAD SEPARATOR.WIDTH @@ -829,7 +894,6 @@ IF DEFINED SEPARATOR.VERTICAL ( IF DEFINED SEPARATOR.STUB_BOXHEAD_INTERSECT ( %@align% SEPARATOR.STUB_BOXHEAD_INTERSECT !SEPARATOR.VERTICAL.WIDTH! C SEPARATOR.STUB_BOXHEAD_INTERSECT ) IF DEFINED SEPARATOR.STUB_BODY ( %@align% SEPARATOR.STUB_BODY !SEPARATOR.VERTICAL.WIDTH! C SEPARATOR.STUB_BODY ) ) - %@exit% @@ -842,6 +906,10 @@ IF NOT DEFINED STUBHEAD ( ) %@strlen% STUBHEAD STUBHEAD.WIDTH %@maxval% STUB.MAX_WIDTH STUBHEAD.WIDTH +IF DEFINED SEPARATOR.HORIZONTAL ( + %@strlen% SEPARATOR.STUBHEAD_STUB STUBHEAD.WIDTH + %@maxval% STUB.MAX_WIDTH STUBHEAD.WIDTH +) %@align% STUBHEAD !STUB.MAX_WIDTH! !ALIGN.STUBHEAD! STUBHEAD SET "LINE=!STUBHEAD!!SEPARATOR.STUBHEAD_BOXHEAD!" @@ -880,27 +948,53 @@ IF DEFINED SEPARATOR.HORIZONTAL ( SET "SEPARATOR=" %@strlen% SEPARATOR.STUBHEAD_STUB SEPARATOR.WIDTH IF [!SEPARATOR.WIDTH!] EQU [1] ( + :: If the SEPARATOR.STUBHEAD_STUB is a single character, repeat it IF DEFINED SEPARATOR.STUBHEAD_STUB ( %@repeat% SEPARATOR.STUBHEAD_STUB !STUB.MAX_WIDTH! SEPARATOR) ) ELSE ( + :: Otherwise align it based on the defined ALIGN.STUBHEAD_STUB IF DEFINED SEPARATOR.STUBHEAD_STUB ( %@align% SEPARATOR.STUBHEAD_STUB !STUB.MAX_WIDTH! !ALIGN.STUBHEAD_STUB! SEPARATOR ) ) SET "LINE=!LINE!!SEPARATOR!" + :: ALIGN.INTERSECT is intended to be a friendlier name of ALIGN.STUB_BOXHEAD_INTERSECT + IF DEFINED ALIGN.INTERSECT ( + IF NOT DEFINED ALIGN.STUB_BOXHEAD_INTERSECT ( + SET "ALIGN.STUB_BOXHEAD_INTERSECT=!ALIGN.INTERSECT!" + ) ELSE ( + ECHO Warning: ALIGN.STUB_BOXHEAD_INTERSECT definition overriding ALIGN.INTERSECT + ) + ) + SET "SEPARATOR=" %@strlen% SEPARATOR.STUB_BOXHEAD_INTERSECT SEPARATOR.WIDTH IF [!SEPARATOR.WIDTH!] EQU [1] ( + :: If the SEPARATOR.STUB_BOXHEAD_INTERSECT is a single character, repeat it IF DEFINED SEPARATOR.STUB_BOXHEAD_INTERSECT ( %@repeat% SEPARATOR.STUB_BOXHEAD_INTERSECT !SEPARATOR.VERTICAL.WIDTH! SEPARATOR ) ) ELSE ( - IF DEFINED SEPARATOR.STUB_BOXHEAD_INTERSECT ( %@align% SEPARATOR.STUB_BOXHEAD_INTERSECT !SEPARATOR.VERTICAL.WIDTH! !ALIGN.STUBHEAD! SEPARATOR ) + :: Otherwise align it based on the defined ALIGN.STUBHEAD + IF DEFINED SEPARATOR.STUB_BOXHEAD_INTERSECT ( %@align% SEPARATOR.STUB_BOXHEAD_INTERSECT !SEPARATOR.VERTICAL.WIDTH! !ALIGN.STUB_BOXHEAD_INTERSECT! SEPARATOR ) ) SET "LINE=!LINE!!SEPARATOR!" SET "SEPARATOR=" %@strlen% SEPARATOR.BOXHEAD_BODY SEPARATOR.WIDTH IF [!SEPARATOR.WIDTH!] EQU [1] ( - IF DEFINED SEPARATOR.BOXHEAD_BODY ( %@repeat% SEPARATOR.BOXHEAD_BODY !BOXHEAD.WIDTH! SEPARATOR ) + IF DEFINED SEPARATOR.COL_INTERSECT ( + :: If there is a column intersect, we need to build the line out for each column, + FOR /L %%c IN (2,1,!COL[#]!) DO ( + :: Loop COL[#]-1 times so that we don't have too many segments + %@repeat% SEPARATOR.BOXHEAD_BODY !COL.MAX_WIDTH! COLUMN + SET "LINE=!LINE!!COLUMN!!SEPARATOR.COL_INTERSECT!" + ) + :: Append the final column + SET "LINE=!LINE!!COLUMN!" + ) ELSE ( + :: otherwise, if the SEPARATOR.BOXHEAD_BODY is a single character, repeat it for the width of the BOXHEAD + IF DEFINED SEPARATOR.BOXHEAD_BODY ( %@repeat% SEPARATOR.BOXHEAD_BODY !BOXHEAD.WIDTH! SEPARATOR ) + ) ) ELSE ( - IF DEFINED SEPARATOR.BOXHEAD_BODY ( %@align% SEPARATOR.BOXHEAD_BODY !BOXHEAD.WIDTH! !ALIGN.STUBHEAD! SEPARATOR ) + :: Otherwise align it based on the defined ALIGN.STUBHEAD + IF DEFINED SEPARATOR.BOXHEAD_BODY ( %@align% SEPARATOR.BOXHEAD_BODY !BOXHEAD.WIDTH! !ALIGN.BOXHEAD_BODY! SEPARATOR ) ) SET "LINE=!LINE!!SEPARATOR!" @@ -1330,35 +1424,43 @@ SET "SCRIPT_NAME=%~nx0" SET "DATA_FILE=" FOR %%a IN (%*) DO ( - SET "arg=%%~a" - IF ["!arg:~0,1!"] EQU ["/"] ( + SET "ARG=%%~a" + SET "OPT.FOUND=" + :: Check for options + IF ["!ARG:~0,1!"] EQU ["/"] ( + SET "OPT.FOUND=#TRUE#" + ) ELSE IF ["!ARG:~0,1!"] EQU ["-"] ( + :: Makes this more friendly to run in PowerShell where - is used for arguments + SET "OPT.FOUND=#TRUE#" + ) + IF DEFINED OPT.FOUND ( SHIFT /1 - SET "opt=!arg:~1,1!" + SET "OPT=!ARG:~1,1!" :: /H [Help] - IF /I ["!opt!"] EQU ["H"] ( - SET "opt=" + IF /I ["!OPT!"] EQU ["H"] ( + SET "OPT=" CALL :USAGE %@exit% -1 ) :: /A [ANSI] - IF /I ["!opt!"] EQU ["A"] ( - SET "opt=" + IF /I ["!OPT!"] EQU ["A"] ( + SET "OPT=" SET "SHOW.ANSI=#TRUE#" SET "SHOW.UTF8=#TRUE#" ) :: /R [R1C1] - IF /I ["!opt!"] EQU ["R"] ( - SET "opt=" + IF /I ["!OPT!"] EQU ["R"] ( + SET "OPT=" SET "SHOW.R1C1_REFERENCE=#TRUE#" ) :: /U [UTF-8] - IF /I ["!opt!"] EQU ["U"] ( - SET "opt=" + IF /I ["!OPT!"] EQU ["U"] ( + SET "OPT=" SET "SHOW.UTF8=#TRUE#" ) - IF ["!opt!"] NEQ [""] ( - SET "msg=Error: Unknown option: !opt!" - CALL :USAGE msg + IF ["!OPT!"] NEQ [""] ( + SET "MSG=Error: Unknown option: !OPT!" + CALL :USAGE MSG %@exit% 1 ) ) @@ -1373,10 +1475,10 @@ IF [%~1] EQU [] ( ) :: Verify that the definition file exists and exit with -:: error code 3 if it doesn't. +:: error code 1 if it doesn't. IF NOT EXIST !DATA_FILE! ( - SET "msg=Error: File does not exist: !DATA_FILE!" - CALL :USAGE msg + SET "MSG=Error: File does not exist: !DATA_FILE!" + CALL :USAGE MSG %@exit% 1 ) diff --git a/src/tools/ansi-color/ansi-colortool.def b/src/tools/ansi-color/ansi-colortool.def index c5f501f8bc5..0db98e4a0b6 100644 --- a/src/tools/ansi-color/ansi-colortool.def +++ b/src/tools/ansi-color/ansi-colortool.def @@ -9,15 +9,19 @@ SET "ALIGN.CELL=C" SET "ALIGN.BOXHEAD=C" SET "ALIGN.STUB=L" SET "ALIGN.STUBHEAD=C" -:: For testing +:: Draw table labels and lines SET "STUBHEAD=ANSI" -SET "SEPARATOR.STUBHEAD_BOXHEAD=║" -SET "SEPARATOR.STUB_BODY=║" -SET "SEPARATOR.STUBHEAD_STUB=─" -SET "SEPARATOR.BOXHEAD_BODY=─" -SET "SEPARATOR.INTERSECT=─╫─" -SET "SEPARATOR.BOXHEAD=│" +SET "SEPARATOR.STUB=║" +SET "SEPARATOR.BOXHEAD=─" SET "SEPARATOR.CELL=│" +SET "SEPARATOR.COL_INTERSECT=┬" +:::: To get the alignment to match the original ColorTool, we specify the +:::: stub max width and prepend an extra boxhead character to the intersect +REM SET /A "STUB.MAX_WIDTH=6" +REM SET "SEPARATOR.INTERSECT=!SEPARATOR.BOXHEAD!╫" +:::: Alternatively this provides the same thing but with the stub separator +:::: shifted further to the left. This is an individual preference. +SET "SEPARATOR.INTERSECT=!SEPARATOR.BOXHEAD!╫!SEPARATOR.BOXHEAD!" __TABLE:END__ __COLS__ #NUL# diff --git a/src/tools/ansi-color/separator.def b/src/tools/ansi-color/separator.def new file mode 100644 index 00000000000..3324eed6b07 --- /dev/null +++ b/src/tools/ansi-color/separator.def @@ -0,0 +1,124 @@ +:: Demonstrates all the different ways the separators can be configured + +__DATA__ +__TABLE__ +SET "UTF8.REQUIRED=#TRUE#" + +:: The test text +SET "CELL= gYw " +SET "STUBHEAD=SGR" + +:: Alignment properties for the cells and headers +REM SET "ALIGN.CELL=C" +REM SET "ALIGN.BOXHEAD=R" +REM SET "ALIGN.STUB=L" +SET "ALIGN.STUBHEAD=C" + + +:: Separator characters for cells and headers + +:: Create a grid +SET "SEPARATOR.BOXHEAD=─" +SET "SEPARATOR.COL=╎" +:: With a distinct separator between the stub and the rest of the table +SET "SEPARATOR.STUB=│" +:: With an intersect +:::: This should be specifically defined if there are both SEPARATOR.VERTICAL +:::: and SEPARATOR.HORIZONTAL components, and therefore it can't be determined +:::: how the intersect should be extended. When non-deterministic and undefined, +:::: the intersect will be shown as a blank space. +SET "SEPARATOR.INTERSECT=┼" +:: With a column intersect +SET "SEPARATOR.COL_INTERSECT=┼" + + +:: Create a table with columns +REM SET "SEPARATOR.COL=╎" +:: But no separator between the stub and the rest of the table +REM SET "SEPARATOR.VERTICAL=#TRUE#" + + +:: Equivalent to SEPARATOR.BOXHEAD with individual definitions for the respective parts +REM SET "SEPARATOR.STUBHEAD_STUB=─" +REM SET "SEPARATOR.BOXHEAD_BODY=━" +:: With an intersect, not shown if there isn't also a SEPARATOR.VERTICAL component +:: such as SEPARATOR.COL +REM SET "SEPARATOR.COL=╎" +REM SET "SEPARATOR.INTERSECT=┾" +:: SEPARATOR.STUB +REM SET "SEPARATOR.STUB=│" +REM SET "SEPARATOR.INTERSECT=┾" +:: SEPARATOR.STUBHEAD_BOXHEAD +REM SET "SEPARATOR.STUBHEAD_BOXHEAD=│" +REM SET "SEPARATOR.INTERSECT=┶" +:: or SEPARATOR.STUB_BODY +REM SET "SEPARATOR.STUB_BODY=┃" +REM SET "SEPARATOR.INTERSECT=┲" + + +:: Equivalent to SEPARATOR.STUB with individual definitions for the respective parts +REM SET "SEPARATOR.STUBHEAD_BOXHEAD=│" +REM SET "SEPARATOR.STUB_BODY=┃" +:: With an intersect, not shown if there isn't also a SEPARATOR.HORIZONTAL component +:: such as SEPARATOR.BOXHEAD +REM SET "SEPARATOR.INTERSECT=╁" +REM SET "SEPARATOR.BOXHEAD=─" +:: SEPARATOR.STUBHEAD_STUB +REM SET "SEPARATOR.INTERSECT=┧" +REM SET "SEPARATOR.STUBHEAD_STUB=─" +:: or SEPARATOR.BOXHEAD_BODY +REM SET "SEPARATOR.INTERSECT=┢" +REM SET "SEPARATOR.BOXHEAD_BODY=━" +:: Column intersects require a SEPARATOR.BOXHEAD component and a SEPARATOR.COLUMN component +:: such as SEPARATOR.COL +REM SET "SEPARATOR.BOXHEAD=─" +REM SET "SEPARATOR.INTERSECT=╁" +REM SET "SEPARATOR.COL=│" +REM SET "SEPARATOR.COL_INTERSECT=┼" +:: SEPARATOR.CELL +REM SET "SEPARATOR.BOXHEAD=─" +REM SET "SEPARATOR.INTERSECT=╁" +REM SET "SEPARATOR.CELL=│" +REM SET "SEPARATOR.COL_INTERSECT=┬" +:: or SEPARATOR.BOXHEADERS +REM SET "SEPARATOR.BOXHEAD=─" +REM SET "SEPARATOR.INTERSECT=╁" +REM SET "SEPARATOR.BOXHEADERS=│" +REM SET "SEPARATOR.COL_INTERSECT=┴" + + +:: And all combined +REM SET "SEPARATOR.STUBHEAD_STUB=─" +REM SET "SEPARATOR.BOXHEAD_BODY=━" +REM SET "SEPARATOR.COL=╎" +REM SET "SEPARATOR.STUBHEAD_BOXHEAD=│" +REM SET "SEPARATOR.STUB_BODY=┃" +REM SET "SEPARATOR.INTERSECT=╆" +REM SET "SEPARATOR.COL_INTERSECT=┿" + +__TABLE:END__ + +:: Background +__COLS__ +40m +41m +42m +43m +44m +45m +46m +47m +__COLS:END__ + +:: [Intensity;][Attribute;]Foreground +__ROWS__ +30m +31m +32m +33m +34m +35m +36m +37m +__ROWS:END__ +__DATA:END__ \ No newline at end of file From c9ccfa8bf867cd3ca4a0647dc9d2f9c3c9a9b957 Mon Sep 17 00:00:00 2001 From: Ryan Beesley Date: Mon, 3 Jan 2022 10:58:02 -0800 Subject: [PATCH 33/35] Typo --- src/tools/ansi-color/ansi-color.cmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/ansi-color/ansi-color.cmd b/src/tools/ansi-color/ansi-color.cmd index 76212779ccc..11859a5cb4c 100644 --- a/src/tools/ansi-color/ansi-color.cmd +++ b/src/tools/ansi-color/ansi-color.cmd @@ -813,7 +813,7 @@ IF DEFINED SEPARATOR.INTERSECT ( :: decide what makes the most sense based on other separators, either :: trying to extend the vertical default or the horizontal default. :: If default vertical or horizontal separators weren't used, it is an -:: advanced definition and the interesect should have been provided, +:: advanced definition and the intersect should have been provided, :: so with no better guidance we define it as a space. IF DEFINED SEPARATOR.VERTICAL ( IF DEFINED SEPARATOR.HORIZONTAL ( From d806b3eb97676c3844e331eb226bde1c4adcbb47 Mon Sep 17 00:00:00 2001 From: Ryan Beesley Date: Mon, 3 Jan 2022 14:33:11 -0800 Subject: [PATCH 34/35] Fixed ALIGN.INTERSECT redefinition in script and renamed SEPARATOR.COL_INTERSECT to SEPARATOR.CELL_INTERSECT to better describe its use. Added a fgbg.def which gives a dense compact view of all FG and BG colors. --- src/tools/ansi-color/README.md | 4 +- src/tools/ansi-color/ansi-color.cmd | 39 ++++++++-------- src/tools/ansi-color/ansi-colortool.def | 2 +- src/tools/ansi-color/fgbg.def | 61 +++++++++++++++++++++++++ src/tools/ansi-color/separator.def | 10 ++-- 5 files changed, 91 insertions(+), 25 deletions(-) create mode 100644 src/tools/ansi-color/fgbg.def diff --git a/src/tools/ansi-color/README.md b/src/tools/ansi-color/README.md index f3ccd4ff829..3308eeacfa2 100644 --- a/src/tools/ansi-color/README.md +++ b/src/tools/ansi-color/README.md @@ -26,4 +26,6 @@ Usage: ansi-color.cmd [flags] [] Of notable interest, the script itself is its own definition file and doesn't require external definition files to work. In fact, the script file itself is just a UTF-8 text file which can easily be edited, doesn't need to be recompiled, and has configuration settings embedded in it, or it can use flags passed as arguments. Additionally, several definition files are included which replicate the output of similar tools. - Lastly, there are two diagnostic modes which might be useful when writing color schemes. `/A` is a flag which instead of showing the output table, it replaces the actual ESC code in the output string with the Unicode codepoint representation of an ESC character, and when redirected from standard out to a file like `ansi-color /a > out.txt` it will create a text file which shows what would have been generated. This makes it easier to find errors in how something rendered. Additionally the `/R` flag borrows the Excel R1C1 reference address scheme to replace the Cell text with row/column IDs. In this way you can generate a table and then identify a combination of attributes and colors by that corresponding reference. \ No newline at end of file + Lastly, there are two diagnostic modes which might be useful when writing color schemes. `/A` is a flag which instead of showing the output table, it replaces the actual ESC code in the output string with the Unicode codepoint representation of an ESC character, and when redirected from standard out to a file like `ansi-color /a > out.txt` it will create a text file which shows what would have been generated. This makes it easier to find errors in how something rendered. Additionally the `/R` flag borrows the Excel R1C1 reference address scheme to replace the Cell text with row/column IDs. In this way you can generate a table and then identify a combination of attributes and colors by that corresponding reference. + + Under PowerShell, you can run all the definitions in a folder and subfolders using `gci -r .\*.def | %{write ($_ | rvpa -r) && .\ansi-color.cmd $_}`. This is convenient for finding a specific definition. \ No newline at end of file diff --git a/src/tools/ansi-color/ansi-color.cmd b/src/tools/ansi-color/ansi-color.cmd index 11859a5cb4c..3f215f960bc 100644 --- a/src/tools/ansi-color/ansi-color.cmd +++ b/src/tools/ansi-color/ansi-color.cmd @@ -498,7 +498,7 @@ SET "ALIGN.STUBHEAD_STUB=C" SET "ALIGN.STUB_BODY=C" SET "ALIGN.BOXHEAD_BODY=C" SET "ALIGN.INTERSECT=C" -SET "ALIGN.STUB_BOXHEAD_INTERSECT=C" +SET "ALIGN.STUB_BOXHEAD_INTERSECT=" :: Separators SET "SEPARATOR.STUB=" @@ -512,7 +512,7 @@ SET "SEPARATOR.BOXHEAD_BODY=" SET "SEPARATOR.BOXHEAD=" SET "SEPARATOR.INTERSECT=" SET "SEPARATOR.STUB_BOXHEAD_INTERSECT=" -SET "SEPARATOR.COL_INTERSECT=" +SET "SEPARATOR.CELL_INTERSECT=" :: Flags SET "SEPARATOR.VERTICAL=" @@ -538,6 +538,9 @@ IF DEFINED CHCP ( ) ) +:: Final blank line to match ColorTool.exe -c output and to improve screen readability +ECHO. + :: Exit %@exit% 0 @@ -684,8 +687,8 @@ IF DEFINED UTF8.REQUIRED ( :RESOLVE_SEPARATORS :: There's a lot to consider with separators in trying to do what is best -:: for the definition author. Look at the separator.def and ansi-colortool.def -:: for examples for how to most effectively manage this. +:: for the definition author. Look at the separator.def, ansi-colortool.def, +:: and fgbg.def for examples for how to most effectively manage this. :: Separators have cascading effects, so if some are not defined this is where :: they are defined. @@ -762,10 +765,10 @@ IF NOT DEFINED SEPARATOR.VERTICAL ( SET "SEPARATOR.STUBHEAD_BOXHEAD=!SEPARATOR.BOXHEADERS!" SET "SEPARATOR.STUB_BODY=!SEPARATOR.CELL!" IF NOT DEFINED SEPARATOR.INTERSECT ( - SET "SEPARATOR.INTERSECT=!SEPARATOR.COL_INTERSECT!" + SET "SEPARATOR.INTERSECT=!SEPARATOR.CELL_INTERSECT!" ) - IF NOT DEFINED SEPARATOR.COL_INTERSECT ( - SET "SEPARATOR.COL_INTERSECT=!SEPARATOR.INTERSECT!" + IF NOT DEFINED SEPARATOR.CELL_INTERSECT ( + SET "SEPARATOR.CELL_INTERSECT=!SEPARATOR.INTERSECT!" ) ) ) @@ -849,27 +852,27 @@ IF DEFINED SEPARATOR.VERTICAL ( SET "SEPARATOR.STUB_BOXHEAD_INTERSECT=" ) -:: If SEPARATOR.COL_INTERSECT is not defined, but SEPARATOR.BOXHEAD_BODY is defined, +:: If SEPARATOR.CELL_INTERSECT is not defined, but SEPARATOR.BOXHEAD_BODY is defined, :: see if SEPARATOR.COLS, SEPARATOR.CELL, or SEPARATOR.BOXHEADERS is defined and extend -:: SEPARATOR.BOXHEAD_BODY for SEPARATOR.COL_INTERSECT as default. -IF NOT DEFINED SEPARATOR.COL_INTERSECT ( +:: SEPARATOR.BOXHEAD_BODY for SEPARATOR.CELL_INTERSECT as default. +IF NOT DEFINED SEPARATOR.CELL_INTERSECT ( IF DEFINED SEPARATOR.BOXHEAD_BODY ( IF DEFINED SEPARATOR.COL ( - SET "SEPARATOR.COL_INTERSECT=!SEPARATOR.BOXHEAD_BODY!" + SET "SEPARATOR.CELL_INTERSECT=!SEPARATOR.BOXHEAD_BODY!" ) ELSE IF DEFINED SEPARATOR.CELL ( - SET "SEPARATOR.COL_INTERSECT=!SEPARATOR.BOXHEAD_BODY!" + SET "SEPARATOR.CELL_INTERSECT=!SEPARATOR.BOXHEAD_BODY!" ) ELSE IF DEFINED SEPARATOR.BOXHEADERS ( - SET "SEPARATOR.COL_INTERSECT=!SEPARATOR.BOXHEAD_BODY!" + SET "SEPARATOR.CELL_INTERSECT=!SEPARATOR.BOXHEAD_BODY!" ) ) ) -:: SEPARATOR.COL_INTERSECT only applies if SEPARATOR.BOXHEADERS, SEPARATOR.COL, or SEPARATOR.CELL is defined -IF DEFINED SEPARATOR.COL_INTERSECT ( +:: SEPARATOR.CELL_INTERSECT only applies if SEPARATOR.BOXHEADERS, SEPARATOR.COL, or SEPARATOR.CELL is defined +IF DEFINED SEPARATOR.CELL_INTERSECT ( IF NOT DEFINED SEPARATOR.BOXHEADERS ( IF NOT DEFINED SEPARATOR.COL ( IF NOT DEFINED SEPARATOR.CELL ( - SET "SEPARATOR.COL_INTERSECT=" + SET "SEPARATOR.CELL_INTERSECT=" ) ) ) @@ -979,12 +982,12 @@ IF DEFINED SEPARATOR.HORIZONTAL ( SET "SEPARATOR=" %@strlen% SEPARATOR.BOXHEAD_BODY SEPARATOR.WIDTH IF [!SEPARATOR.WIDTH!] EQU [1] ( - IF DEFINED SEPARATOR.COL_INTERSECT ( + IF DEFINED SEPARATOR.CELL_INTERSECT ( :: If there is a column intersect, we need to build the line out for each column, FOR /L %%c IN (2,1,!COL[#]!) DO ( :: Loop COL[#]-1 times so that we don't have too many segments %@repeat% SEPARATOR.BOXHEAD_BODY !COL.MAX_WIDTH! COLUMN - SET "LINE=!LINE!!COLUMN!!SEPARATOR.COL_INTERSECT!" + SET "LINE=!LINE!!COLUMN!!SEPARATOR.CELL_INTERSECT!" ) :: Append the final column SET "LINE=!LINE!!COLUMN!" diff --git a/src/tools/ansi-color/ansi-colortool.def b/src/tools/ansi-color/ansi-colortool.def index 0db98e4a0b6..3deef4ea10e 100644 --- a/src/tools/ansi-color/ansi-colortool.def +++ b/src/tools/ansi-color/ansi-colortool.def @@ -14,7 +14,7 @@ SET "STUBHEAD=ANSI" SET "SEPARATOR.STUB=║" SET "SEPARATOR.BOXHEAD=─" SET "SEPARATOR.CELL=│" -SET "SEPARATOR.COL_INTERSECT=┬" +SET "SEPARATOR.CELL_INTERSECT=┬" :::: To get the alignment to match the original ColorTool, we specify the :::: stub max width and prepend an extra boxhead character to the intersect REM SET /A "STUB.MAX_WIDTH=6" diff --git a/src/tools/ansi-color/fgbg.def b/src/tools/ansi-color/fgbg.def new file mode 100644 index 00000000000..5cd9ca8e100 --- /dev/null +++ b/src/tools/ansi-color/fgbg.def @@ -0,0 +1,61 @@ +:: Compact display of FG over BG colors +:: Requires 76 columns + +__DATA__ +__TABLE__ +SET "UTF8.REQUIRED=#TRUE#" +:: Definition strings +SET "CELL=gYw" +REM SET "STUBHEAD=BG\FG" +:: Separators +SET "SEPARATOR.BOXHEAD_BODY=─" +SET "SEPARATOR.STUB_BODY=│" +SET "SEPARATOR.CELL= " +SET "SEPARATOR.INTERSECT=┌" +REM SET "SEPARATOR.CELL_INTERSECT=┬" +SET "SEPARATOR.CELL_INTERSECT=┼" +REM SET "SEPARATOR.CELL_INTERSECT=┴" +__TABLE:END__ + +__COLS__ +#NUL# +30m +31m +32m +33m +34m +35m +36m +37m +39m +90m +91m +92m +93m +94m +95m +96m +97m +__COLS:END__ + +__ROWS__ +#NUL# +40m +41m +42m +43m +44m +45m +46m +47m +49m +100m +101m +102m +103m +104m +105m +106m +107m +__ROWS:END__ +__DATA:END__ \ No newline at end of file diff --git a/src/tools/ansi-color/separator.def b/src/tools/ansi-color/separator.def index 3324eed6b07..e54df93e1f0 100644 --- a/src/tools/ansi-color/separator.def +++ b/src/tools/ansi-color/separator.def @@ -29,7 +29,7 @@ SET "SEPARATOR.STUB=│" :::: the intersect will be shown as a blank space. SET "SEPARATOR.INTERSECT=┼" :: With a column intersect -SET "SEPARATOR.COL_INTERSECT=┼" +SET "SEPARATOR.CELL_INTERSECT=┼" :: Create a table with columns @@ -74,17 +74,17 @@ REM SET "SEPARATOR.BOXHEAD_BODY=━" REM SET "SEPARATOR.BOXHEAD=─" REM SET "SEPARATOR.INTERSECT=╁" REM SET "SEPARATOR.COL=│" -REM SET "SEPARATOR.COL_INTERSECT=┼" +REM SET "SEPARATOR.CELL_INTERSECT=┼" :: SEPARATOR.CELL REM SET "SEPARATOR.BOXHEAD=─" REM SET "SEPARATOR.INTERSECT=╁" REM SET "SEPARATOR.CELL=│" -REM SET "SEPARATOR.COL_INTERSECT=┬" +REM SET "SEPARATOR.CELL_INTERSECT=┬" :: or SEPARATOR.BOXHEADERS REM SET "SEPARATOR.BOXHEAD=─" REM SET "SEPARATOR.INTERSECT=╁" REM SET "SEPARATOR.BOXHEADERS=│" -REM SET "SEPARATOR.COL_INTERSECT=┴" +REM SET "SEPARATOR.CELL_INTERSECT=┴" :: And all combined @@ -94,7 +94,7 @@ REM SET "SEPARATOR.COL=╎" REM SET "SEPARATOR.STUBHEAD_BOXHEAD=│" REM SET "SEPARATOR.STUB_BODY=┃" REM SET "SEPARATOR.INTERSECT=╆" -REM SET "SEPARATOR.COL_INTERSECT=┿" +REM SET "SEPARATOR.CELL_INTERSECT=┿" __TABLE:END__ From c1855265d5d56dcf2bb33579b7f2bc91d41f2e6a Mon Sep 17 00:00:00 2001 From: Ryan Beesley Date: Mon, 3 Jan 2022 14:40:40 -0800 Subject: [PATCH 35/35] Fixed spelling for unrecognized words --- .github/actions/spelling/expect/expect.txt | 2 ++ src/tools/ansi-color/fgbg.def | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/actions/spelling/expect/expect.txt b/.github/actions/spelling/expect/expect.txt index 54b34df799e..32c182c8e49 100644 --- a/.github/actions/spelling/expect/expect.txt +++ b/.github/actions/spelling/expect/expect.txt @@ -765,6 +765,7 @@ fdw fesb FFDE FFrom +fgbg FGCOLOR fgetc fgetwc @@ -2066,6 +2067,7 @@ runut runxamlformat rvalue RVERTICAL +rvpa RWIN rxvt safearray diff --git a/src/tools/ansi-color/fgbg.def b/src/tools/ansi-color/fgbg.def index 5cd9ca8e100..cbc9eb6f147 100644 --- a/src/tools/ansi-color/fgbg.def +++ b/src/tools/ansi-color/fgbg.def @@ -1,4 +1,4 @@ -:: Compact display of FG over BG colors +:: Compact display of foreground over background colors :: Requires 76 columns __DATA__