cool-retro-term-renderer 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,226 @@
1
+ # cool-retro-term-webgl
2
+
3
+ A WebGL-based CRT terminal renderer for XTerm.js. This library provides authentic retro CRT visual effects for terminal applications, including screen curvature, phosphor glow, scanlines, and more.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/cool-retro-term-webgl.svg)](https://www.npmjs.com/package/cool-retro-term-webgl)
6
+ [![License: GPL-3.0](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
7
+
8
+ ## Preview
9
+
10
+ ![Preview](assets/images/thumbnail.png)
11
+
12
+ Live demo available at https://remojansen.github.io/
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ npm install cool-retro-term-webgl
18
+ ```
19
+
20
+ ### Peer Dependencies
21
+
22
+ This library requires `three` and `@xterm/xterm` as peer dependencies:
23
+
24
+ ```bash
25
+ npm install three @xterm/xterm
26
+ ```
27
+
28
+ ## Quick Start
29
+
30
+ ```typescript
31
+ import { CRTTerminal } from 'cool-retro-term-webgl';
32
+ import { Terminal } from '@xterm/xterm';
33
+
34
+ // Create a container element
35
+ const container = document.getElementById('terminal')!;
36
+
37
+ // Initialize the CRT renderer
38
+ const crt = new CRTTerminal({ container });
39
+
40
+ // Create and configure your XTerm instance
41
+ const xterm = new Terminal({
42
+ cols: 80,
43
+ rows: 24,
44
+ cursorBlink: false,
45
+ });
46
+
47
+ // XTerm needs a DOM element to attach to (can be hidden)
48
+ const hiddenContainer = document.createElement('div');
49
+ hiddenContainer.style.position = 'absolute';
50
+ hiddenContainer.style.left = '-9999px';
51
+ document.body.appendChild(hiddenContainer);
52
+ xterm.open(hiddenContainer);
53
+
54
+ // Attach XTerm to the CRT renderer
55
+ crt.attachXTerm(xterm);
56
+
57
+ // Now use XTerm as normal - output will render with CRT effects
58
+ xterm.write('Hello, CRT World!\r\n');
59
+ xterm.write('$ ');
60
+ ```
61
+
62
+ ## API Reference
63
+
64
+ ### `CRTTerminal`
65
+
66
+ The main class that creates the WebGL renderer and manages the CRT effect pipeline.
67
+
68
+ #### Constructor
69
+
70
+ ```typescript
71
+ new CRTTerminal(options: CRTTerminalSettings)
72
+ ```
73
+
74
+ #### `CRTTerminalSettings`
75
+
76
+ | Property | Type | Default | Description |
77
+ |----------|------|---------|-------------|
78
+ | `container` | `HTMLElement` | **required** | The container element to render into |
79
+ | `fontColor` | `string` | `"#0ccc68"` | Font color in hex format (green) |
80
+ | `backgroundColor` | `string` | `"#000000"` | Background color in hex format |
81
+ | `screenCurvature` | `number` | `0.3` | Screen curvature amount (0-1) |
82
+ | `rgbShift` | `number` | `0` | RGB shift/chromatic aberration (0-0.01) |
83
+ | `bloom` | `number` | `0.5538` | Bloom intensity (0-1) |
84
+ | `brightness` | `number` | `0.5` | Brightness level (0-1) |
85
+ | `ambientLight` | `number` | `0.2` | Ambient light glow (0-1) |
86
+ | `chromaColor` | `number` | `0` | Chroma color (0=mono, 1=full color) |
87
+ | `flickering` | `number` | `0.1` | Flickering intensity (0-1) |
88
+ | `horizontalSync` | `number` | `0.08` | Horizontal sync distortion (0-1) |
89
+ | `jitter` | `number` | `0.1997` | Jitter/displacement (0-1) |
90
+ | `staticNoise` | `number` | `0.1198` | Static noise intensity (0-1) |
91
+ | `glowingLine` | `number` | `0.2` | Scanning beam intensity (0-1) |
92
+ | `burnIn` | `number` | `0.2517` | Phosphor burn-in persistence (0-1) |
93
+ | `rasterizationMode` | `number` | `1` | 0=none, 1=scanline, 2=pixel, 3=subpixel |
94
+ | `rasterizationIntensity` | `number` | `0.5` | Scanline intensity (0-1) |
95
+
96
+ #### Methods
97
+
98
+ | Method | Description |
99
+ |--------|-------------|
100
+ | `attachXTerm(xterm: Terminal)` | Attach an XTerm.js terminal instance |
101
+ | `detachXTerm()` | Detach the currently attached XTerm instance |
102
+ | `getGridSize()` | Get the terminal grid size `{ cols, rows }` |
103
+ | `focus()` | Focus the attached XTerm terminal |
104
+ | `dispose()` | Clean up all resources |
105
+
106
+ #### Advanced Access
107
+
108
+ For advanced usage, you can access the underlying components:
109
+
110
+ ```typescript
111
+ crt.getTerminalText() // TerminalText renderer
112
+ crt.getRenderer() // THREE.WebGLRenderer
113
+ crt.getScene() // THREE.Scene
114
+ crt.getCamera() // THREE.OrthographicCamera
115
+ ```
116
+
117
+ ## Visual Effects
118
+
119
+ The library implements a two-pass rendering pipeline that replicates the visual characteristics of CRT monitors:
120
+
121
+ ### Static Pass (Pass 1)
122
+ - Screen curvature distortion
123
+ - RGB shift (chromatic aberration)
124
+ - Bloom (phosphor glow)
125
+ - Brightness adjustment
126
+
127
+ ### Dynamic Pass (Pass 2)
128
+ - Horizontal sync distortion
129
+ - Jitter (random displacement)
130
+ - Burn-in (phosphor persistence)
131
+ - Static noise
132
+ - Glowing line (scanning beam)
133
+ - Rasterization (scanlines)
134
+ - Flickering
135
+ - Ambient light
136
+
137
+ ## Examples
138
+
139
+ ### Custom Green Theme (Default)
140
+
141
+ ```typescript
142
+ const crt = new CRTTerminal({
143
+ container,
144
+ fontColor: '#0ccc68',
145
+ bloom: 0.6,
146
+ screenCurvature: 0.3,
147
+ });
148
+ ```
149
+
150
+ ### Amber Terminal
151
+
152
+ ```typescript
153
+ const crt = new CRTTerminal({
154
+ container,
155
+ fontColor: '#ffb000',
156
+ bloom: 0.5,
157
+ burnIn: 0.3,
158
+ });
159
+ ```
160
+
161
+ ### High-Fidelity CRT
162
+
163
+ ```typescript
164
+ const crt = new CRTTerminal({
165
+ container,
166
+ screenCurvature: 0.4,
167
+ flickering: 0.15,
168
+ horizontalSync: 0.1,
169
+ staticNoise: 0.15,
170
+ burnIn: 0.3,
171
+ rasterizationMode: 1,
172
+ rasterizationIntensity: 0.6,
173
+ });
174
+ ```
175
+
176
+ ### Minimal Effects
177
+
178
+ ```typescript
179
+ const crt = new CRTTerminal({
180
+ container,
181
+ screenCurvature: 0,
182
+ flickering: 0,
183
+ horizontalSync: 0,
184
+ jitter: 0,
185
+ staticNoise: 0,
186
+ burnIn: 0,
187
+ rasterizationMode: 0,
188
+ });
189
+ ```
190
+
191
+ ## Browser Support
192
+
193
+ Requires WebGL support. Works in all modern browsers:
194
+ - Chrome 56+
195
+ - Firefox 51+
196
+ - Safari 15+
197
+ - Edge 79+
198
+
199
+ ## Development
200
+
201
+ ```bash
202
+ # Install dependencies
203
+ npm install
204
+
205
+ # Generate assets (fonts and textures)
206
+ npm run generate-assets
207
+
208
+ # Build the library
209
+ npm run build
210
+
211
+ # Build in watch mode
212
+ npm run dev
213
+
214
+ # Lint and format
215
+ npm run lint-and-format
216
+ ```
217
+
218
+ ## License
219
+
220
+ GPL-3.0
221
+
222
+ ## Credits
223
+
224
+ This project is a port to WebGL from [cool-retro-term](https://github.com/Swordfish90/cool-retro-term) by Filippo Scognamiglio.
225
+
226
+ This library uses the [Terminus Font](https://terminus-font.sourceforge.net/) by Dimitar Zhekov, licensed under the SIL Open Font License (OFL).