Skip to content

Commit c4780e5

Browse files
authored
Merge branch 'master' into tyriar/search_refactor
2 parents c56336b + f03dfbb commit c4780e5

File tree

2 files changed

+79
-33
lines changed

2 files changed

+79
-33
lines changed

.github/copilot-instructions.md

Lines changed: 71 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,90 @@
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
22

3-
Please follow these guidelines when contributing:
3+
## Architecture Overview
44

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)
69

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
914

10-
## Coding guidelines
15+
## Development Workflow
1116

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+
```
1321

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+
```
1542

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
1747

18-
```sh
19-
# All unit tests
20-
yarn test-unit
48+
## Project-Specific Conventions
2149

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.
2451

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
2756

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
3061

31-
# Multiple files
32-
yarn test-unit out-esbuild/**/Terminal.test.js out-esbuild/**/InputHandler.test.js
33-
```
62+
## Common Patterns
3463

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+
```
3671

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+
```
3877

39-
Integration tests are run with `yarn test-integration`:
78+
**Events**: All terminals emit standard events (onData, onResize, onRender) plus platform-specific ones.
4079

41-
```sh
42-
# All integration tests
43-
yarn test-integration
80+
## Critical Implementation Details
4481

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
4787

48-
# Specific addon integration tests
49-
yarn test-integration --suite=addon-search
50-
```
88+
## Writing unit tests
5189

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.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
applyTo: '**/*.test.ts'
3+
---
4+
When writing unit tests follow these rules:
5+
6+
- When writing unit tests for addons, always create a real xterm.js instance instead of mocking it.
7+
- Prefer `assert.ok` over `assert.notStrictEqual` when checking something is undefined or not.
8+
- Avoid comments as most tests should be self-documenting.

0 commit comments

Comments
 (0)