Skip to content

Commit d4b6355

Browse files
oisingj4james
andauthored
initial draft of VT function support spec (#1884)
conhost and windows terminal renamed files; updated script to do summary output only, also quiet mode and option file path for output (else stdout) added -quiet and fixed -summaryonly parameters added hyperlink directly to soruce implementation for conhost and terminal seqs Update doc/reference/master-sequence-list.csv Co-Authored-By: James Holderness <j4_james@hotmail.com> Apply suggestions from code review Co-Authored-By: James Holderness <j4_james@hotmail.com> Co-authored-by: James Holderness <j4_james@hotmail.com>
1 parent e3fcfcc commit d4b6355

File tree

3 files changed

+478
-0
lines changed

3 files changed

+478
-0
lines changed
Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
#requires -version 6.1
2+
3+
<#
4+
.SYNOPSIS
5+
Scan source code and build a list of supported VT sequences.
6+
.DESCRIPTION
7+
Scan source code and build a list of supported VT sequences.
8+
TODO: add more details
9+
#>
10+
[cmdletbinding(DefaultParameterSetName="stdout")]
11+
param(
12+
[parameter(ParameterSetName="file", mandatory)]
13+
[string]$OutFile,
14+
[parameter(ParameterSetName="file")]
15+
[switch]$Force, # for overwriting $OutFile if it exists
16+
17+
[parameter(ParameterSetName="stdout")]
18+
[parameter(ParameterSetName="file")]
19+
[switch]$NoLogo, # no logo in summary
20+
[parameter(ParameterSetName="stdout")]
21+
[switch]$SummaryOnly, # no markdown generated
22+
[parameter(ParameterSetName="stdout")]
23+
[parameter(ParameterSetName="file")]
24+
[switch]$Quiet, # no summary or logo
25+
26+
[parameter(ParameterSetName="file")]
27+
[parameter(ParameterSetName="stdout")]
28+
[string]$SolutionRoot = "..\..",
29+
[parameter(ParameterSetName="file")]
30+
[parameter(ParameterSetName="stdout")]
31+
[string]$InterfacePath = $(join-path $solutionRoot "src\terminal\adapter\ITermDispatch.hpp"),
32+
[parameter(ParameterSetName="file")]
33+
[parameter(ParameterSetName="stdout")]
34+
[string]$ConsoleAdapterPath = $(join-path $solutionRoot "src\terminal\adapter\adaptDispatch.hpp"),
35+
[parameter(ParameterSetName="file")]
36+
[parameter(ParameterSetName="stdout")]
37+
[string]$TerminalAdapterPath = $(join-path $solutionRoot "src\cascadia\terminalcore\terminaldispatch.hpp")
38+
)
39+
40+
if ($PSCmdlet.ParameterSetName -eq "stdout") {
41+
Write-Verbose "Emitting markdown to STDOUT"
42+
}
43+
44+
<#
45+
GLOBALS
46+
#>
47+
48+
[semver]$myVer = "0.6-beta"
49+
$sequences = import-csv ".\master-sequence-list.csv"
50+
$base = @{}
51+
$conhost = @{}
52+
$terminal = @{}
53+
$prefix = "https://vt100.net/docs/vt510-rm/"
54+
$repo = "https://github.com/oising/terminal/tree/master"
55+
$conhostUrl = $ConsoleAdapterPath.TrimStart($SolutionRoot).replace("\", "/")
56+
$terminalurl = $TerminalAdapterPath.TrimStart($SolutionRoot).replace("\", "/")
57+
58+
function Read-SourceFiles {
59+
# extract base interface
60+
$baseScanner = [regex]'(?x)virtual\s\w+\s(?<method>\w+)(?s)[^;]+;(?-s).*?(?<seq>(?<=\/\/\s).+)'
61+
62+
$baseScanner.Matches(($src = get-content -raw $interfacePath)) | foreach-object {
63+
$match = $_
64+
#$line = (($src[0..$_.Index] -join "") -split "`n").Length
65+
#$decl = $_.groups[0].value
66+
$_.groups["seq"].value.split(",") | ForEach-Object {
67+
$SCRIPT:base[$_.trim()] = $match.groups["method"].value
68+
}
69+
}
70+
71+
# match overrides of ITermDispatch
72+
$scanner = [regex]'(?x)\s+\w+\s(?<method>\w+)(?s)[^;]+override;'
73+
74+
$scanner.Matches(($src = Get-Content -raw $consoleAdapterPath)) | ForEach-Object {
75+
$line = (($src[0..$_.Index] -join "") -split "`n").Length
76+
$SCRIPT:conhost[$_.groups["method"].value] = $line
77+
}
78+
79+
$scanner.Matches(($src = Get-Content -raw $terminalAdapterPath)) | ForEach-Object {
80+
$line = (($src[0..$_.Index] -join "") -split "`n").Length
81+
#write-verbose $_.groups[0].value
82+
$SCRIPT:terminal[$_.groups["method"].value] = $line
83+
}
84+
}
85+
86+
function Get-SequenceIndexMarkdown {
87+
# "Sequence","Parent","Description","Origin","Heading","Subheading", "ImplementedBy", "ConsoleHost","Terminal"
88+
89+
$heading = $null
90+
$subheading = $null
91+
<#
92+
Emit markdown
93+
94+
TODO:
95+
- autogenerate TOC
96+
#>
97+
@"
98+
# VT Function Support
99+
100+
## Table of Contents
101+
102+
* [Code Extension Functions](#code-extension-functions)
103+
* [Control Coding](#control-coding)
104+
* [Character Coding](#character-coding)
105+
* [Graphic Character Sets](#graphic-character-sets)
106+
* [Terminal Management Functions](#terminal-management-functions)
107+
* [Identification, status, and Initialization](#identification-status-and-initialization)
108+
* [Emulations](#emulations)
109+
* [Set-Up](#set-up)
110+
* [Display Coordinate System and Addressing](#display-coordinate-system-and-addressing)
111+
* [Active Position and Cursor](#active-position-and-cursor)
112+
* [Margins and Scrolling](#margins-and-scrolling)
113+
* [Cursor Movement](#cursor-movement)
114+
* [Horizontal Tabulation](#horizontal-tabulation)
115+
* [Page Size and Arrangement](#page-size-and-arrangement)
116+
* [Page Movement](#page-movement)
117+
* [Status Display](#status-display)
118+
* [Right to Left](#right-to-left)
119+
* [Window Management](#window-management)
120+
* [Visual Attributes and Renditions](#visual-attributes-and-renditions)
121+
* [Line Renditions](#line-renditions)
122+
* [Character Renditions](#character-renditions)
123+
* [Audible Indicators](#audible-indicators)
124+
* [Mode States](#mode-states)
125+
* [ANSI](#ansi)
126+
* [DEC Private](#dec-private)
127+
* [Editing Functions](#editing-functions)
128+
* [OLTP Features](#oltp-features)
129+
* [Rectangular Area Operations](#rectangular-area-operations)
130+
* [Data Integrity](#data-integrity)
131+
* [Macros](#macros)
132+
* [Saving and Restoring Terminal State](#saving-and-restoring-terminal-state)
133+
* [Cursor Save Buffer](#cursor-save-buffer)
134+
* [Terminal State Interrogation](#terminal-state-interrogation)
135+
* [Keyboard Processing Functions](#keyboard-processing-functions)
136+
* [Soft Key Mapping (UDK)](#soft-key-mapping-udk)
137+
* [Soft Fonts (DRCS)](#soft-fonts-drcs)
138+
* [Printing](#printing)
139+
* [Terminal Communication and Synchronization](#terminal-communication-and-synchronization)
140+
* [Text Locator Extension](#text-locator-extension)
141+
* [Session Management Extension](#session-management-extension)
142+
* [Documented Exceptions](#documented-exceptions)
143+
144+
$($sequences | ForEach-Object {
145+
if ($method = $base[$_.sequence]) {
146+
$_.ImplementedBy = $method
147+
$_.ConsoleHost = $conhost[$method]
148+
$_.Terminal = $terminal[$method]
149+
}
150+
# "Sequence","Associated","Description","Origin","Heading","Subheading", "ImplementedBy", "ConsoleHost","Terminal"
151+
$c0 = "[$($_.Sequence)]($prefix$($_.sequence).html ""View page on vt100.net"")"
152+
$c1 = "$($_.description)"
153+
$c2 = "$($_.origin)"
154+
$c3 = $(if ($_.consolehost) {"[&#x2713;](${repo}/${conhostUrl}#L$($_.consolehost) ""View console host implementation"")"})
155+
$c4 = $(if ($_.terminal) {"[&#x2713;](${repo}/${terminalUrl}#L$($_.terminal)} ""View windows terminal implementation"")"})
156+
157+
$shouldRenderHeader = $false
158+
159+
if ($heading -ne $_.heading) {
160+
$heading = $_.heading
161+
@"
162+
163+
## $heading
164+
165+
"@
166+
$shouldRenderHeader = $true
167+
}
168+
169+
if ($subheading -ne $_.subheading) {
170+
$subheading = $_.subheading
171+
@"
172+
173+
### $subheading
174+
175+
"@
176+
$shouldRenderHeader = $true
177+
}
178+
179+
if ($shouldRenderHeader) {
180+
@"
181+
182+
|Symbol|Function|Origin&nbsp;&#x1F5B3;|Console Host|Terminal|
183+
|:-|:--|:--:|:--:|:--:|
184+
"@
185+
}
186+
@"
187+
188+
|$c0|$c1|$c2|$c3|$c4|
189+
"@
190+
})
191+
192+
---
193+
Generated on $(get-date -DisplayHint DateTime)
194+
"@
195+
}
196+
197+
function Show-Summary {
198+
write-host "`n$(' '*7)Windows Terminal Sequencer v${myVer}"
199+
if (-not $NoLogo.IsPresent) {
200+
Get-Content .\windows-terminal-logo.ans | ForEach-Object { Write-Host $_ }
201+
}
202+
$summary = @"
203+
`e[1mSequence Support:`e[0m
204+
205+
`e[7m {0:000} `e[0m known in master-sequence-list.csv.
206+
`e[7m {1:000} `e[0m common members in ITermDispatch base, of which:
207+
`e[7m {2:000} `e[0m are implemented by ConsoleHost.
208+
`e[7m {3:000} `e[0m are implemented by Windows Terminal.
209+
210+
"@ -f $sequences.Count, $base.count, $conhost.count, $terminal.Count
211+
212+
write-host $summary
213+
}
214+
215+
<#
216+
Entry Point
217+
#>
218+
219+
Read-SourceFiles
220+
221+
if (-not $SummaryOnly.IsPresent) {
222+
223+
$markdown = Get-SequenceIndexMarkdown
224+
225+
if ($PSCmdlet.ParameterSetName -eq "file") {
226+
# send to file and overwrite
227+
$markdown | Out-File -FilePath $OutFile -Force:$Force.IsPresent -Encoding utf8NoBOM
228+
} else {
229+
# send to STDOUT
230+
$markdown
231+
}
232+
233+
if (-not $Quiet.IsPresent) {
234+
Show-Summary
235+
}
236+
} else {
237+
# summary only
238+
Show-Summary
239+
}

0 commit comments

Comments
 (0)