T7: VT terminal emulator (parser, buffer, emulator, input, self-test)

- VtParser: Paul Williams state machine subset - UTF-8 decode (strict,
  FFFD on overlong/surrogate/interrupt), C0 execute, C1 shortcuts,
  ESC/ESC_INT/SS3/CSI/OSC(BEL|ST)/DCS(prefix+hook+data)/STR strings,
  CAN/SUB abort, reprocess semantics for aborted strings
- TerminalBuffer: main + lazy alt grids, scrollback 5000 (main only,
  region top==0), DECSTBM margins, tab stops, IL/DL/ICH/DCH/ECH/SU/SD/
  RI with wide-cell orphan repair, per-row dirty flags, resize
- TerminalEmulator: SGR (16/256/truecolor, 38;2/48;2), deferred wrap
  (DECAWM), DECSET/RST 1/6/7/25/47/1000/1002/1003/1004/1006/1047/1048/
  1049/2004, origin mode, IRM, DECSC/RC + CSI s/u, DECSTBM, RIS, DECALN,
  REP; replies DA1 ESC[?1;2c, DA2 ESC[>0;100;0c, DSR 5/6, XTVERSION
  DCS >|HavenOH(0.1) ST, CSI 18t size report; OSC 0/2/7/8/9/52/777 with
  hyperlink scheme whitelist
- VtInput: xterm key encodings (arrows/DECCKM/Home/End/PgUp..F12 with
  modifier params, F1-F4 SS3, ctrl/alt maps), bracketed paste, SGR mouse
- VtSelfTest: 12 cases incl. CJK double-width, alt-screen round-trip,
  scrollback growth, scroll region + RI, query replies, and the
  'echo ni hao && vim' byte-stream replay (T7 acceptance) - 12/12 pass
- DiagPage: button 11 runs the emulator self-test

Verified: Node 24 transform-types run 12/12 PASS; hvigor BUILD SUCCESSFUL
This commit is contained in:
STRIX
2026-09-08 15:50:09 +08:00
parent edb66effd9
commit b18039991b
8 changed files with 3084 additions and 0 deletions
+28
View File
@@ -22,6 +22,7 @@ import { verifyHostKeyTofu, InMemoryKnownHostStore, HostKeyDecider, HostKeyPromp
import { SshSession, SshSessionOptions, ExecResult } from '../ssh/SshSession';
import { AuthResult } from '../ssh/Auth';
import { bytesToUtf8, utf8ToBytes, hexToBytes, bytesToHex, bytesEqual, concatBytes, SshWriter } from '../ssh/SshWire';
import { runVtSelfTest, VtTestResult } from '../vterm/VtSelfTest';
import { cryptoFramework } from '@kit.CryptoArchitectureKit';
import { BusinessError } from '@kit.BasicServicesKit';
@@ -137,6 +138,11 @@ struct DiagPage {
.onClick(() => {
this.runTest((): Promise<void> => this.testLiveAuth());
})
Button('11. VT 终端模拟器自测')
.width('100%')
.onClick(() => {
this.runTest((): Promise<void> => this.testVtEmulator());
})
}
.width('100%')
@@ -821,4 +827,26 @@ struct DiagPage {
session.close();
}
}
/** 11) VT terminal emulator self test: 12 cases over small grids. */
private async testVtEmulator(): Promise<void> {
const results: VtTestResult[] = runVtSelfTest();
let pass: number = 0;
let fail: number = 0;
for (let i = 0; i < results.length; i++) {
const r: VtTestResult = results[i];
if (r.ok) {
pass += 1;
this.log('PASS', `${i + 1}. ${r.name}`);
} else {
fail += 1;
this.log('FAIL', `${i + 1}. ${r.name} — ${r.detail}`);
}
}
if (fail === 0) {
this.log('PASS', `VT 终端模拟器自测 ${pass}/${results.length} 全部通过 ✓`);
} else {
this.log('FAIL', `VT 终端模拟器自测 ${pass}/${results.length},${fail} 项失败`);
}
}
}