|
1 | | -This is a TypeScript-based repository with a Ruby client for certain API endpoints. It includes several sub projects called addons which are built separately. It contains a demo application which showcases the functionality of the project. |
| 1 | +# xterm.js Copilot Instructions |
2 | 2 |
|
3 | | -Please follow these guidelines when contributing: |
| 3 | +## Architecture Overview |
4 | 4 |
|
5 | | -## Development Flow |
| 5 | +**Core Structure**: xterm.js is a multi-target terminal emulator with three main distributions: |
| 6 | +- `src/browser/`: Full-featured browser terminal with DOM rendering |
| 7 | +- `src/headless/`: Server-side terminal for Node.js (no DOM) |
| 8 | +- `src/common/`: Shared core logic (parsing, buffer management, terminal state) |
6 | 9 |
|
7 | | -- Install dependencies: `npm install && npm run setup` |
8 | | -- Build and bundle demo: `npm run build && npm run esbuild` |
| 10 | +**Key Classes**: |
| 11 | +- `Terminal` (browser/headless): Public API wrapper |
| 12 | +- `CoreTerminal` (common): Core terminal logic and state |
| 13 | +- `CoreBrowserTerminal` (browser): Browser-specific terminal implementation |
9 | 14 |
|
10 | | -## Coding guidelines |
| 15 | +## Development Workflow |
11 | 16 |
|
12 | | -- Do not write comments in unit tests unless the test is particularly complex. When they are complex, add the descriptions into the assertion calls where possible. |
| 17 | +**Build System**: |
| 18 | +```bash |
| 19 | +npm run build && npm run esbuild # Build all TypeScript and bundle |
| 20 | +``` |
13 | 21 |
|
14 | | -## Unit tests |
| 22 | +**Testing**: |
| 23 | +- Unit tests: `npm run test-unit` (Mocha) |
| 24 | +- Per-addon unit tests: `npm run test-unit addons/addon-image/out-esbuild/*.test.js` |
| 25 | +- Integration tests: `npm run test-integration` (Playwright across Chrome/Firefox/WebKit) |
| 26 | +- Per-addon integration tests: `npm run test-integration --suite=addon-search` |
| 27 | + |
| 28 | +## Addon Development Pattern |
| 29 | + |
| 30 | +All addons follow this structure: |
| 31 | +```typescript |
| 32 | +export class MyAddon implements ITerminalAddon { |
| 33 | + activate(terminal: Terminal): void { |
| 34 | + // Called when loaded via terminal.loadAddon() |
| 35 | + // Register handlers, access terminal APIs |
| 36 | + } |
| 37 | + dispose(): void { |
| 38 | + // Cleanup when addon is disposed |
| 39 | + } |
| 40 | +} |
| 41 | +``` |
15 | 42 |
|
16 | | -Unit tests are run with `yarn test-unit`: |
| 43 | +**Key Examples**: |
| 44 | +- `addons/addon-fit/`: Terminal sizing |
| 45 | +- `addons/addon-webgl/`: GPU-accelerated rendering |
| 46 | +- `addons/addon-search/`: Text search functionality |
17 | 47 |
|
18 | | -```sh |
19 | | -# All unit tests |
20 | | -yarn test-unit |
| 48 | +## Project-Specific Conventions |
21 | 49 |
|
22 | | -# Absolute file path |
23 | | -yarn test-unit out-esbuild/browser/Terminal.test.js |
| 50 | +**TypeScript Project Structure**: Uses TypeScript project references (`tsconfig.all.json`) for incremental builds across browser/headless/addons. |
24 | 51 |
|
25 | | -# Filter by wildcard |
26 | | -yarn test-unit out-esbuild/**/Terminal.test.js |
| 52 | +**API Design**: |
| 53 | +- Browser and headless terminals share the same public API |
| 54 | +- Proposed APIs require `allowProposedApi: true` option |
| 55 | +- Constructor-only options (cols, rows) cannot be changed after instantiation |
27 | 56 |
|
28 | | -# Specific addon unit tests tests |
29 | | -yarn test-unit addons/addon-image/out-esbuild/*.test.js |
| 57 | +**Testing Utilities**: Use `TestUtils.ts` helpers: |
| 58 | +- `openTerminal(ctx, options)` for setup |
| 59 | +- `pollFor(page, fn, expectedValue)` for async assertions |
| 60 | +- `writeSync(page, data)` for terminal input |
30 | 61 |
|
31 | | -# Multiple files |
32 | | -yarn test-unit out-esbuild/**/Terminal.test.js out-esbuild/**/InputHandler.test.js |
33 | | -``` |
| 62 | +## Common Patterns |
34 | 63 |
|
35 | | -These use mocha to run all `.test.js` files within the esbuild output (`out-esbuild/`). |
| 64 | +**Parser Integration**: Register custom escape sequence handlers: |
| 65 | +```typescript |
| 66 | +terminal.parser.registerCsiHandler('m', params => { |
| 67 | + // Handle SGR sequences |
| 68 | + return true; // Handled |
| 69 | +}); |
| 70 | +``` |
36 | 71 |
|
37 | | -## Integration tests |
| 72 | +**Buffer Access**: Read terminal content via buffer API: |
| 73 | +```typescript |
| 74 | +const line = terminal.buffer.active.getLine(0); |
| 75 | +const cell = line?.getCell(0); |
| 76 | +``` |
38 | 77 |
|
39 | | -Integration tests are run with `yarn test-integration`: |
| 78 | +**Events**: All terminals emit standard events (onData, onResize, onRender) plus platform-specific ones. |
40 | 79 |
|
41 | | -```sh |
42 | | -# All integration tests |
43 | | -yarn test-integration |
| 80 | +## Critical Implementation Details |
44 | 81 |
|
45 | | -# Core integration tests |
46 | | -yarn test-integration --suite=core |
| 82 | +- Terminal rendering uses either DOM or WebGL renderers |
| 83 | +- Buffer lines are immutable; create new instances for modifications |
| 84 | +- Character width handling supports Unicode 11+ and grapheme clustering |
| 85 | +- Mouse events translate web events to terminal protocols (X10, VT200, etc.) |
| 86 | +- Color theming supports both palette and true color modes |
47 | 87 |
|
48 | | -# Specific addon integration tests |
49 | | -yarn test-integration --suite=addon-search |
50 | | -``` |
| 88 | +## Writing unit tests |
51 | 89 |
|
52 | | -These use `@playwright/test` to run all tests within the esbuild test output (`out-esbuild-test/`). |
| 90 | +- Unit tests live alongside the source code file of the thing it's testing with a .test.ts suffix. |
0 commit comments