Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ninmonkey/c5ab5fafc036fd4603cd7f2a2d061a8b to your computer and use it in GitHub Desktop.
Save ninmonkey/c5ab5fafc036fd4603cd7f2a2d061a8b to your computer and use it in GitHub Desktop.
WindowsTerminal - Build-SupportedSequenceIndex - Generate sequence list

links

Usage

$BuildSource = 'G:\2022-github\temps\terminal\doc\reference\nin.Build-SupportedSequenceIndex.ps1'
$SolutionRoot = gi 'G:\2022-github\temps\terminal'
$splatRoot = @{ 
    OutFile             = 'g:\temp\escapes\out.md'
    Verbose             = $true; 
    # Force = $true
    NoLogo              = $false
    SolutionRoot        = $SolutionRoot
    # ConsoleAdapterPath = $SolutionRoot
    # InterfacePath = $SolutionRoot
    TerminalAdapterPath = Join-Path $SolutionRoot 'src\terminal\adapter\termDispatch.hpp'
    MasterSequenceCsv   = Join-Path $SolutionRoot 'doc\reference\master-sequence-list.csv'
}
$ErrorActionPreference = 'break'

& $BuildSource @splatRoot 
$ErrorActionPreference = 'continue'
"Wrote: {0}" -f @($splatRoot.OutFile)
"Source: {0}" -f @( $splatRoot.MasterSequenceCsv )

VT Function Support

Table of Contents

Code Extension Functions

Control Coding

Symbol Function Origin 🖳 Console Host Terminal
CAN Cancel VT100
SUB Substitute VT100
ESC Escape VT100
DCS Device Control String VT220
CSI Control Sequence Introducer VT100
ST String Terminator VT220
OSC Operating System Command DECterm
PM Privacy Message ``
APC Application Program Command VT420
S7C1T Select 7-bit C1 Transmission VT220
S8C1T Select 8-bit C1 Transmission VT220

Character Coding

Symbol Function Origin 🖳 Console Host Terminal
LS0 Locking Shift Zero (SI) VT100
LS1 Locking Shift One (SO) VT100
LS2 Locking Shift Two VT220
LS3 Locking Shift Three VT220
LS1R Locking Shift One Right VT220
LS2R Locking Shift Two Right VT220
LS3R Locking Shift Three Right VT220
SS2 Single Shift Two VT220
SS3 Single Shift Three VT220

Graphic Character Sets

Symbol Function Origin 🖳 Console Host Terminal
SCS Select Character Set VT100

VT320

Symbol Function Origin 🖳 Console Host Terminal
DECNRCM (National Replacement) Character Set Mode VT220 [✓](https://github.com/oising/terminal/tree/master/c/terminal/adapter/adaptDispatch.hpp#LGraphic Character Sets "View console host implementation")

Terminal Management Functions

Identification, status, and Initialization

Symbol Function Origin 🖳 Console Host Terminal
DA1 Primary Device Attributes VT100
DA2 Secondary Device Attributes VT220
DA3 Tertiary Device Attributes VT420
DSR Device Status Report VT100
DECID Identify Device VT100
DECTID Select Terminal ID VT510
DECSCL Select Conformance Level VT220
DECSR Secure Reset VT420
DECSRC Secure Reset Confirmation VT420
DECSTR Soft Terminal Reset VT220
DECSTUI Set Terminal Unit ID (Restricted) VT420
RIS Reset to Initial state VT100

Emulations

Symbol Function Origin 🖳 Console Host Terminal
DECPCTERM Enter/Exit PC Term Mode from DEC VT mode VT420PC
DECTME Terminal Mode Emulation VT510

Set-Up

Symbol Function Origin 🖳 Console Host Terminal
DECSSL Select Set-Up Language VT510
DECCRTSM CRT Save Mode (not required) VT510
DECOSCNM Overscan Mode VT510
DECSRFR Select Refresh Rate VT510
DECLTOD Load Time of Day VT510
DECLBAN Load Banner Message VT510

Display Coordinate System and Addressing

Active Position and Cursor

Symbol Function Origin 🖳 Console Host Terminal
DECTCEM Text Cursor Enable Mode VT220
DECSCUSR Set Cursor Style VT510

Margins and Scrolling

Symbol Function Origin 🖳 Console Host Terminal
DECSTBM Set Top and Bottom Margin VT100
DECSLRM Set Left and Right Margin VT420
DECLRMM Left Right Margin Mode VT420
DECOM Origin Mode VT100
DECSCLM Scrolling Mode VT100
IND Index VT100
RI Reverse Index VT100
DECFI Forward Index VT420
DECBI Back Index VT420
DECSSCLS Set Scroll Speed VT510

Cursor Movement

Symbol Function Origin 🖳 Console Host Terminal
BS Backspace VT100
LF Line Feed VT100
VT Vertical Tab VT100
FF Form Feed VT100
CR Carriage Return VT100
NEL Next Line VT100
LNM Line Feed/New Line Mode VT100
CUU Cursor Up VT100
CUD Cursor Down VT100
CUF Cursor Forward VT100
CUB Cursor Backward VT100
CUP Cursor Position VT100
HVP Horizontal/Vertical Position VT100
DSR-CPR Device Status Report (Cursor Position Report) VT100
DSR-XCPR Device Status Report (Extended Cursor Position Report) VT340 VT420
CHA Cursor Horizontal Absolute VT510
CNL Cursor Next Line VT510
CPL Cursor Previous Line VT510
HPA Horizontal Position Absolute VT510
HPR Horizontal Position Relative VT510
VPA Vertical Line Position Absolute VT510
VPR Vertical Position Relative VT510

Horizontal Tabulation

Symbol Function Origin 🖳 Console Host Terminal
HT Horizontal Tab VT100
HTS Horizontal Tabulation Set VT100
TBC Tabulation Clear VT100
CBT Cursor Backward Tabulation VT510
CHT Cursor Horizontal Forward Tabulation VT510
DECST8C Set Tab at every 8 columns VT420PC

Page Size and Arrangement

Symbol Function Origin 🖳 Console Host Terminal
DECCOLM Column Mode VT100
DECNCSM No Clear Screen on column Mode VT510
DECSCPP Set Columns Per Page VT340 VT420
DECSLPP Set Lines Per Page VT340 VT420

Page Movement

Symbol Function Origin 🖳 Console Host Terminal
NP Next Page VT340 VT420
PP Preceding Page VT340 VT420
PPA Page Position Absolute VT340 VT420
PPR Page Position Relative VT340 VT420
PPB Page Position Backward VT340 VT420

Status Display

Symbol Function Origin 🖳 Console Host Terminal
DECSASD Select Active Status Display VT340 VT320
DECSSDT Select Status Display Type VT340 VT320

Right to Left

Symbol Function Origin 🖳 Console Host Terminal
DECRLM Right to Left Mode VT510
DECRLCM Right to Left Copy Mode VT510
DDD1 VT100 mode Hebrew VT510
DDD2 VT100 mode Hebrew VT510
DDD3 VT100 mode Hebrew VT510

Window Management

Symbol Function Origin 🖳 Console Host Terminal
DECHCCM Horizontal Cursor Coupling Mode VT340 VT420
DECVCCM Vertical Cursor Coupling Mode VT340 VT420
DECPCCM Page Cursor Coupling Mode VT340 VT420
DECRQDE Request Displayed Extent VT340 VT420
DECSNLS Select Number of Lines per Screen (exception) VT420
DECARSM Auto Resize Mode DECterm VT420
SU Pan Down VT340 VT420
SD Pan Up VT340 VT420

Visual Attributes and Renditions

Symbol Function Origin 🖳 Console Host Terminal
DECSCNM Screen Mode VT100

Line Renditions

Symbol Function Origin 🖳 Console Host Terminal
DECSWL Single Width Line VT100
DECDWL Double Width Line VT100
DECDHLT Double Height Line Top VT100
DECDHLB Double Height Line Bottom VT100

Character Renditions

Symbol Function Origin 🖳 Console Host Terminal
SGR Select Graphic Rendition VT100

Audible Indicators

Symbol Function Origin 🖳 Console Host Terminal
BEL Warning Bell VT100
DECSKCV Set Keyclick Volume VT510
DECSWBV Set Warning Bell Volume VT510
DECSMBV Set Margin Bell Volume VT510

Editing Functions

DEC Private

Symbol Function Origin 🖳 Console Host Terminal
IRM Insert/Replacement Mode VT102
ICH Insert Character VT102
DCH Delete Character VT102
IL Insert Line VT100
DL Delete Line VT100
DECIC Insert Column VT420
DECDC Delete Column VT420
ECH Erase Character VT100
EL Erase in Line VT100
DECSEL Selective Erase in Line VT220
ED Erase in Display VT100
DECSED Selective Erase in Display VT220
DECSCA Select Character Attribute (selective erase) VT220

OLTP Features

Rectangular Area Operations

Symbol Function Origin 🖳 Console Host Terminal
DECCRA Copy Rectangular Area VT420
DECFRA Fill Rectangular Area VT420
DECERA Erase Rectangular Area VT420
DECSERA Selective Erase Rectangular Area VT420
DECCARA Change Attribute in Rectangular Area VT420
DECRARA Reverse Attribute in Rectangular Area VT420
DECSACE Select Attribute Change Extent Mode VT420

Data Integrity

Symbol Function Origin 🖳 Console Host Terminal
DECRQCRA Request Checksum of Rectangular Area VT420
DSR-DECCKSR Device Status Report (Memory Checksum) VT420

Macros

Symbol Function Origin 🖳 Console Host Terminal
DECDMAC Define Macro VT420
DECINVM Invoke Macro VT420
DSR-MSR Device Status Report (Macro Space Report) VT420

Saving and Restoring Terminal State

Cursor Save Buffer

Symbol Function Origin 🖳 Console Host Terminal
DECSC Save Cursor VT100
DECRC Restore Cursor VT100

Terminal State Interrogation

Symbol Function Origin 🖳 Console Host Terminal
DECRQM Request Mode VT320
DECNKM Numeric Keypad Mode VT320
DECRQSS Request Selection or Setting VT320
DECRQPSR Request Presentation State Report VT320
DECRSPS Restore Presentation State VT320
DECRQTSR Request Terminal State Report VT320
DECRSTS Restore Terminal State VT320

Keyboard Processing Functions

Symbol Function Origin 🖳 Console Host Terminal
DECARM Autorepeat Mode VT100
DECBKM Backarrow Key Mode VT420
DECCKM Cursor Keys Mode VT100
DECKBUM Keyboard Usage Mode VT320
DECKPAM Keypad Application Mode VT100
DECKPM Key Position Mode VT420
DECKPNM Keypad Numeric Mode VT100
DECNKM Numeric Keypad Mode VT320
DSR-KBD Device Status Report (keyboard status) VT220
KAM Keyboard Action Mode VT220
DECLFC Local Functions Control VT420
DECLFKC Local Function Key Control VT420
DECSMKR Select Modifier Key Reporting VT420
DECHEBM Hebrew Keyboard Map mode VT510
DECHCEM Hebrew Encoding Mode VT510
DECNAKB NA/Greek Selection VT510
DECESKM Secondary Keyboard Language Mode VT510
DECSLCK Set Lock Key Style VT510
DECKBD Keyboard Dialect Selection VT510
DECNUMLK NumLock Mode VT510
DECCAPSLK CapsLock Mode VT510
DECKLHIM Keyboard LEDs Host Indicator Mode VT510
DECLL Load LEDs VT100

Soft Key Mapping (UDK)

Symbol Function Origin 🖳 Console Host Terminal
DECUDK User Defined Keys VT220
DSR-UDK Device Status Report (UDK lock) VT220
DECPKA Program Key Action VT510
DECPFK Program Function Key VT510
DECPAK Program Alphanumeric Key VT510
DECCKD Copy Key Default VT510
DECRQPKFM Program Key Free Memory Inquiry VT510
DECRQKT Inquire a Key Type VT510
DECRQKD Inquire a Key Definition VT510

Soft Fonts (DRCS)

Symbol Function Origin 🖳 Console Host Terminal
DECDLD Downline Load VT220

Printing

Symbol Function Origin 🖳 Console Host Terminal
DECPEX Print Extent Mode VT220
DECPFF Print Form Feed Mode VT220
DSR-PP Device Status Report (printer port) VT220
MC Media Copy VT220
DECSPRTT Select Printer Type VT510
DECSDPT Select Digital Printed Data Type VT510
DECSPPCS Select Proprinter Character Set VT510

Terminal Communication and Synchronization

Symbol Function Origin 🖳 Console Host Terminal
BREAK BREAK VT100
XON XON VT100
XOFF XOFF VT100
ENQ Enquiry VT100
SRM Send Receive Mode VT220
DECXRLM Transmit Rate Limiting Mode VT420
DECMCM Modem Control Mode VT510
DECAAM Auto Answerback Mode VT510
DECLANS Load Answerback Message VT510
DECCANSM Conceal Answerback Message Mode VT510
DECNULM Ignore Null Mode VT510
DECHPDXM Half Duplex Mode VT510
DECSFC Select Flow Control VT510
DECSDDT Select Disconnect Delay Time VT510
DECSTRL Set Transmit Rate Limit VT510
DECSCS Select Communication Speed VT510
DECSCP Select Communication Port VT510
DECSPP Set Port Parameter VT510

Text Locator Extension

Symbol Function Origin 🖳 Console Host Terminal
DECEFR Enable Filter Rectangle UWS
DECELR Enable Locator Reports UWS
DECLKD Locator Key Definition UWS
DECLRP Locator Report UWS
DECRQLP Request Locator Position UWS
DECSLE Select Locator Events UWS
DSR-LS Device Status Report (Locator Status) UWS

Session Management Extension

Symbol Function Origin 🖳 Console Host Terminal
DECES Enable Sessions VT340 VT420

Documented Exceptions

Symbol Function Origin 🖳 Console Host Terminal
DECANM ANSI/VT52 Mode VT100
DECALN Screen Alignment VT100
DECAWM Autowrap Mode VT100
DECTST Invoke Confidence Test VT100
CRM Control Representation Mode VT100

Generated on 12/23/2022 21:16:16

#requires -version 6.1
<#
.SYNOPSIS
Scan source code and build a list of supported VT sequences.
.DESCRIPTION
Scan source code and build a list of supported VT sequences.
TODO: add more details
#>
[cmdletbinding(DefaultParameterSetName="stdout")]
param(
[parameter(ParameterSetName="file", mandatory)]
[string]$OutFile,
[parameter(ParameterSetName="file")]
[switch]$Force, # for overwriting $OutFile if it exists
[parameter(ParameterSetName="stdout")]
[parameter(ParameterSetName="file")]
[switch]$NoLogo, # no logo in summary
[parameter(ParameterSetName="stdout")]
[switch]$SummaryOnly, # no markdown generated
[parameter(ParameterSetName="stdout")]
[parameter(ParameterSetName="file")]
[switch]$Quiet, # no summary or logo
[parameter(ParameterSetName="file")]
[parameter(ParameterSetName="stdout")]
[string]$SolutionRoot = "..\..",
[parameter(ParameterSetName="file")]
[parameter(ParameterSetName="stdout")]
[string]$InterfacePath = $(join-path $solutionRoot "src\terminal\adapter\ITermDispatch.hpp"),
[parameter(ParameterSetName="file")]
[parameter(ParameterSetName="stdout")]
[string]$ConsoleAdapterPath = $(join-path $solutionRoot "src\terminal\adapter\adaptDispatch.hpp"),
[parameter(ParameterSetName="file")]
[parameter(ParameterSetName="stdout")]
[string]$TerminalAdapterPath = $(join-path $solutionRoot "src\cascadia\terminalcore\terminalDispatch.hpp"),
[string]$MasterSequenceCsv = $(join-path $solutionRoot "doc\reference\master-sequence-list.csv")
)
if ($PSCmdlet.ParameterSetName -eq "stdout") {
Write-Verbose "Emitting markdown to STDOUT"
}
<#
GLOBALS
#>
[semver]$myVer = "0.6-beta"
# $sequences = import-csv ".\master-sequence-list.csv"
$sequences = import-csv $MasterSequenceCsv #'G:\2022-github\temps\terminal\doc\reference\master-sequence-list.csv'
$base = @{}
$conhost = @{}
$terminal = @{}
$prefix = "https://vt100.net/docs/vt510-rm/"
$repo = "https://github.com/oising/terminal/tree/master"
$conhostUrl = $ConsoleAdapterPath.TrimStart($SolutionRoot).replace("\", "/")
$terminalUrl = $TerminalAdapterPath.TrimStart($SolutionRoot).replace("\", "/")
function Read-SourceFiles {
# extract base interface
$baseScanner = [regex]'(?x)virtual\s\w+\s(?<method>\w+)(?s)[^;]+;(?-s).*?(?<seq>(?<=\/\/\s).+)'
$baseScanner.Matches(($src = get-content -raw $interfacePath)) | foreach-object {
$match = $_
#$line = (($src[0..$_.Index] -join "") -split "`n").Length
#$decl = $_.groups[0].value
$_.groups["seq"].value.split(",") | ForEach-Object {
$SCRIPT:base[$_.trim()] = $match.groups["method"].value
}
}
# match overrides of ITermDispatch
$scanner = [regex]'(?x)\s+\w+\s(?<method>\w+)(?s)[^;]+override;'
$scanner.Matches(($src = Get-Content -raw $consoleAdapterPath)) | ForEach-Object {
$line = (($src[0..$_.Index] -join "") -split "`n").Length
$SCRIPT:conhost[$_.groups["method"].value] = $line
}
$scanner.Matches(($src = Get-Content -raw $terminalAdapterPath)) | ForEach-Object {
$line = (($src[0..$_.Index] -join "") -split "`n").Length
#write-verbose $_.groups[0].value
$SCRIPT:terminal[$_.groups["method"].value] = $line
}
}
function Get-SequenceIndexMarkdown {
# "Sequence","Parent","Description","Origin","Heading","Subheading", "ImplementedBy", "ConsoleHost","Terminal"
$heading = $null
$subheading = $null
<#
Emit markdown
TODO:
- auto-generate TOC
#>
@"
# VT Function Support
## Table of Contents
* [Code Extension Functions](#code-extension-functions)
* [Control Coding](#control-coding)
* [Character Coding](#character-coding)
* [Graphic Character Sets](#graphic-character-sets)
* [Terminal Management Functions](#terminal-management-functions)
* [Identification, status, and Initialization](#identification-status-and-initialization)
* [Emulations](#emulations)
* [Set-Up](#set-up)
* [Display Coordinate System and Addressing](#display-coordinate-system-and-addressing)
* [Active Position and Cursor](#active-position-and-cursor)
* [Margins and Scrolling](#margins-and-scrolling)
* [Cursor Movement](#cursor-movement)
* [Horizontal Tabulation](#horizontal-tabulation)
* [Page Size and Arrangement](#page-size-and-arrangement)
* [Page Movement](#page-movement)
* [Status Display](#status-display)
* [Right to Left](#right-to-left)
* [Window Management](#window-management)
* [Visual Attributes and Renditions](#visual-attributes-and-renditions)
* [Line Renditions](#line-renditions)
* [Character Renditions](#character-renditions)
* [Audible Indicators](#audible-indicators)
* [Mode States](#mode-states)
* [ANSI](#ansi)
* [DEC Private](#dec-private)
* [Editing Functions](#editing-functions)
* [OLTP Features](#OLTP-features)
* [Rectangular Area Operations](#rectangular-area-operations)
* [Data Integrity](#data-integrity)
* [Macros](#macros)
* [Saving and Restoring Terminal State](#saving-and-restoring-terminal-state)
* [Cursor Save Buffer](#cursor-save-buffer)
* [Terminal State Interrogation](#terminal-state-interrogation)
* [Keyboard Processing Functions](#keyboard-processing-functions)
* [Soft Key Mapping (UDK)](#soft-key-mapping-UDK)
* [Soft Fonts (DRCS)](#soft-fonts-drcs)
* [Printing](#printing)
* [Terminal Communication and Synchronization](#terminal-communication-and-synchronization)
* [Text Locator Extension](#text-locator-extension)
* [Session Management Extension](#session-management-extension)
* [Documented Exceptions](#documented-exceptions)
$($sequences | ForEach-Object {
if ($method = $base[$_.sequence]) {
$_.ImplementedBy = $method
$_.ConsoleHost = $conhost[$method]
$_.Terminal = $terminal[$method]
}
# "Sequence","Associated","Description","Origin","Heading","Subheading", "ImplementedBy", "ConsoleHost","Terminal"
$c0 = "[$($_.Sequence)]($prefix$($_.sequence).html ""View page on vt100.net"")"
$c1 = "$($_.description)"
$c2 = "$($_.origin)"
$c3 = $(if ($_.consolehost) {"[&#x2713;](${repo}/${conhostUrl}#L$($_.consolehost) ""View console host implementation"")"})
$c4 = $(if ($_.terminal) {"[&#x2713;](${repo}/${terminalUrl}#L$($_.terminal)} ""View windows terminal implementation"")"})
$shouldRenderHeader = $false
if ($heading -ne $_.heading) {
$heading = $_.heading
@"
## $heading
"@
$shouldRenderHeader = $true
}
if ($subheading -ne $_.subheading) {
$subheading = $_.subheading
@"
### $subheading
"@
$shouldRenderHeader = $true
}
if ($shouldRenderHeader) {
@"
|Symbol|Function|Origin&nbsp;&#x1F5B3;|Console Host|Terminal|
|:-|:--|:--:|:--:|:--:|
"@
}
@"
|$c0|$c1|$c2|$c3|$c4|
"@
})
---
Generated on $(get-date -DisplayHint DateTime)
"@
}
function Show-Summary {
write-host "`n$(' '*7)Windows Terminal Sequencer v${myVer}"
if (-not $NoLogo.IsPresent) {
# Get-Content .\windows-terminal-logo.ans | ForEach-Object { Write-Host $_ }
Get-Content 'G:\2022-github\temps\terminal\doc\reference\windows-terminal-logo.ans' | ForEach-Object { Write-Host $_ }
}
$summary = @"
`e[1mSequence Support:`e[0m
`e[7m {0:000} `e[0m known in master-sequence-list.csv.
`e[7m {1:000} `e[0m common members in ITermDispatch base, of which:
`e[7m {2:000} `e[0m are implemented by ConsoleHost.
`e[7m {3:000} `e[0m are implemented by Windows Terminal.
"@ -f $sequences.Count, $base.count, $conhost.count, $terminal.Count
write-host $summary
}
<#
Entry Point
#>
Read-SourceFiles
if (-not $SummaryOnly.IsPresent) {
$markdown = Get-SequenceIndexMarkdown
if ($PSCmdlet.ParameterSetName -eq "file") {
# send to file and overwrite
$markdown | Out-File -FilePath $OutFile -Force:$Force.IsPresent -Encoding utf8NoBOM
} else {
# send to STDOUT
$markdown
}
if (-not $Quiet.IsPresent) {
Show-Summary
}
} else {
# summary only
Show-Summary
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment