CodeSampleX

示例

@xterm/xterm 5.5.0: Terminal

已验证示例 — npm @xterm/xterm 5.5.0: Terminal. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: Instantiating Terminal with custom cols and rows initializes…

sha256:941221b0847df07d5d2fd50136bae1ec63115f24048c69bd71bdc2f5c208332b

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 MIT-0

执行证据

声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。

证据依据
签名契约通过
验证回执
1
构建过它的签名密钥
1
声明的环境 linux 24 · ubuntu · glibc 2.39 x64 npm

验证运行环境

环境 契约 阶段 运行日期
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5…
2026-08-23

案例

HOW
目标
verify @xterm/xterm.Terminal in pkg:npm/%40xterm/xterm@5.5.0
包
符号
  • @xterm/xterm.Terminal
创建时间
2026-08-23T15:00:29Z

契约

  1. Instantiating Terminal with custom cols and rows initializes the terminal buffer with the specified dimensions.
  2. Calling resize on Terminal updates the dimensions and fires the onResize event with the new column and row counts.
  3. Writing text with CRLF populates the active buffer and executes the write completion callback.
  4. Setting convertEol to true causes line feeds to reset cursorX to column 0 on the next row.
  5. Calling input on Terminal triggers the onData event listener with the provided input string.
  6. Calling reset on Terminal restores initial cursor positions, and calling dispose cleanly shuts down the instance.

文件

  • NOTES.md
  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • test/contract.mjs

下载源代码构件 (tar.gz)

源代码

NOTES.md
# @xterm/xterm Terminal Verification

## Search Results and Prior Findings

A search for prior solutions on `@xterm/xterm@5.5.0` returned `NO_SAFE_MATCH`. This sample establishes verified clean-room evidence for `@xterm/xterm.Terminal`.

## Pinned Release

- `@xterm/xterm`: `5.5.0`

## Observed Behavior

`@xterm/xterm` provides the `Terminal` class representing an xterm terminal emulator.
In Node.js / headless environments:
1. **Instantiation**: `new Terminal(options)` initializes a terminal instance with configurable dimensions (`cols`, `rows`) and options such as `convertEol`.
2. **Resizing**: `terminal.resize(cols, rows)` updates the terminal geometry and fires the `onResize` event listener.
3. **Buffer Writing**: `terminal.write(text, callback)` processes input text asynchronously, populates the active buffer (`terminal.buffer.active`), and executes the optional callback when parsing completes.
4. **EOL Conversion**: With `convertEol: true`, `\n` line feeds reset `cursorX` to column 0 on the next row.
5. **Input and Data Flow**: `terminal.input(data)` emits the `onData` event for consumers listening to user keystrokes/data input.
6. **Lifecycle**: `terminal.reset()` resets cursor state, and `terminal.dispose()` cleans up listeners and resources.
PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify @xterm/xterm.Terminal in pkg:npm/%40xterm/xterm@5.5.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40xterm/xterm@5.5.0
Demonstrate these symbols/APIs:
  - @xterm/xterm.Terminal

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:5c32ce90f1949d2338b7458e87a5aad6b2a1b5c15701e4e766ede7b4c83d68b3","contract":["Instantiating Terminal with custom cols and rows initializes the terminal buffer with the specified dimensions.","Calling resize on Terminal updates the dimensions and fires the onResize event with the new column and row counts.","Writing text with CRLF populates the active buffer and executes the write completion callback.","Setting convertEol to true causes line feeds to reset cursorX to column 0 on the next row.","Calling input on Terminal triggers the onData event listener with the provided input string.","Calling reset on Terminal restores initial cursor positions, and calling dispose cleanly shuts down the instance."],"goal":"verify @xterm/xterm.Terminal in pkg:npm/%40xterm/xterm@5.5.0","kind":"HOW","packages":["pkg:npm/%40xterm/xterm@5.5.0"],"schemaVersion":1,"symbols":["@xterm/xterm.Terminal"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40xterm/xterm@5.5.0"],"schemaVersion":1,"subject":"pkg:npm/%40xterm/xterm@5.5.0","symbols":["@xterm/xterm.Terminal"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-xterm-terminal-verify",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-xterm-terminal-verify",
      "version": "1.0.0",
      "dependencies": {
        "@xterm/xterm": "5.5.0"
      }
    },
    "node_modules/@xterm/xterm": {
      "version": "5.5.0",
      "resolved": "https://registry.npmjs.org/@xterm/xterm/-/xterm-5.5.0.tgz",
      "integrity": "sha512-hqJHYaQb5OptNunnyAnkHyM8aCjZ1MEIDTQu1iIbbTD/xops91NB5yq1ZK/dC2JDbVWtF23zUtl9JE2NqwT87A==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-xterm-terminal-verify",
  "version": "1.0.0",
  "type": "module",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "@xterm/xterm": "5.5.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify @xterm/xterm.Terminal in pkg:npm/%40xterm/xterm@5.5.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40xterm/xterm@5.5.0"
  ],
  "symbols": [
    "@xterm/xterm.Terminal"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import xtermModule from '@xterm/xterm';

// In Node ESM, @xterm/xterm exports { default: { Terminal } }
const { Terminal } = xtermModule.default || xtermModule;

assert.equal(typeof Terminal, 'function', 'Terminal constructor must be exported');

async function runTests() {
  // 1. Instantiating Terminal with custom cols/rows creates a buffer with matching dimensions
  const term = new Terminal({ cols: 100, rows: 30, convertEol: true });
  assert.equal(term.cols, 100, 'Terminal columns must match configuration');
  assert.equal(term.rows, 30, 'Terminal rows must match configuration');
  assert.equal(term.buffer.active.type, 'normal', 'Default active buffer type must be normal');
  assert.equal(term.buffer.active.cursorX, 0, 'Initial cursor X must be 0');
  assert.equal(term.buffer.active.cursorY, 0, 'Initial cursor Y must be 0');

  // 2. resize() updates cols and rows and triggers onResize listener
  let resized = false;
  const resizeDisposable = term.onResize(({ cols, rows }) => {
    resized = true;
    assert.equal(cols, 80);
    assert.equal(rows, 24);
  });
  term.resize(80, 24);
  assert.equal(term.cols, 80, 'Terminal columns must update on resize');
  assert.equal(term.rows, 24, 'Terminal rows must update on resize');
  assert.equal(resized, true, 'onResize event listener must have fired');
  resizeDisposable.dispose();

  // 3. write() with callback populates active buffer and translates lines correctly
  await new Promise((resolve) => {
    term.write('Hello, CodeSampleX Terminal!\r\nLine 2', () => {
      resolve();
    });
  });

  const line0 = term.buffer.active.getLine(0);
  assert.ok(line0, 'Line 0 must exist in active buffer');
  assert.equal(line0.translateToString(true), 'Hello, CodeSampleX Terminal!', 'Line 0 content must match written string');

  const line1 = term.buffer.active.getLine(1);
  assert.ok(line1, 'Line 1 must exist in active buffer');
  assert.equal(line1.translateToString(true), 'Line 2', 'Line 1 content must match written string');

  // 4. convertEol option resets cursorX to 0 on line feed (\n)
  await new Promise((resolve) => {
    term.write('\nLine 3', () => {
      resolve();
    });
  });
  const line2 = term.buffer.active.getLine(2);
  assert.ok(line2, 'Line 2 must exist in active buffer');
  assert.equal(line2.translateToString(true), 'Line 3', 'convertEol must place text at column 0');

  // 5. input() triggers onData event listener
  let receivedData = '';
  const dataDisposable = term.onData((data) => {
    receivedData += data;
  });
  term.input('user command input');
  assert.equal(receivedData, 'user command input', 'onData must receive input string');
  dataDisposable.dispose();

  // 6. Reset / clear resets buffer
  term.reset();
  assert.equal(term.buffer.active.cursorX, 0, 'Cursor X must be 0 after reset');
  assert.equal(term.buffer.active.cursorY, 0, 'Cursor Y must be 0 after reset');

  // 7. Dispose cleans up terminal
  term.dispose();
}

await runTests();

原始种子者

匿名