@termuijs/core 0.1.1 → 0.1.2
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/LICENSE +21 -0
- package/README.md +28 -27
- package/dist/index.cjs +402 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +299 -1
- package/dist/index.d.ts +299 -1
- package/dist/index.js +380 -34
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Karanjot Singh
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @termuijs/core
|
|
2
2
|
|
|
3
|
-
The rendering engine
|
|
3
|
+
The rendering engine that sits at the bottom of the TermUI stack. Screen buffers, layout, input parsing, events, and styling. Everything else in the framework builds on this.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -8,47 +8,45 @@ The rendering engine behind TermUI. Handles screen buffers, layout, input parsin
|
|
|
8
8
|
npm install @termuijs/core
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
## What
|
|
11
|
+
## What's in the box
|
|
12
12
|
|
|
13
|
-
- **Screen**
|
|
14
|
-
- **
|
|
15
|
-
- **
|
|
16
|
-
- **
|
|
17
|
-
- **
|
|
18
|
-
- **
|
|
19
|
-
- **
|
|
20
|
-
- **
|
|
21
|
-
- **App** - Ties everything together. Mounts widgets, runs the render loop, dispatches input.
|
|
13
|
+
- **Screen** — Double-buffered cell grid. Diffs the previous frame against the new one so only changed cells get written to stdout.
|
|
14
|
+
- **LayoutEngine** — Flexbox-inspired positioning: `flexDirection`, `flexGrow`, `flexShrink`, `alignItems`, `justifyContent`, percentage sizing. All calculated in character cells.
|
|
15
|
+
- **InputParser** — Converts raw stdin bytes into typed `KeyEvent` objects. Handles escape sequences, Ctrl combos, and multi-byte UTF-8.
|
|
16
|
+
- **EventEmitter** — Type-safe `on`, `off`, `once`, `emit`. Events bubble from focused widget up through parents.
|
|
17
|
+
- **FocusManager** — Tab cycling between widgets, focus traps for modals, focus groups for arrow key navigation within a panel.
|
|
18
|
+
- **Style** — Colors (RGB, hex, named), border styles (single, double, rounded, bold), padding, margin.
|
|
19
|
+
- **LayerManager** — Z-indexed overlays. Modals and dropdowns render above the base layer without z-fighting.
|
|
20
|
+
- **App** — The entry point. Mounts your widget tree, starts the render loop, and routes input to the focused widget.
|
|
22
21
|
|
|
23
22
|
## Usage
|
|
24
23
|
|
|
25
24
|
```typescript
|
|
26
|
-
import { App, Screen, Style } from '@termuijs/core'
|
|
25
|
+
import { App, Screen, Style } from '@termuijs/core'
|
|
27
26
|
|
|
28
|
-
const app = new App()
|
|
27
|
+
const app = new App()
|
|
29
28
|
|
|
30
29
|
// Screen is the cell buffer
|
|
31
|
-
const screen = app.screen
|
|
32
|
-
screen.setCell(0, 0, { char: 'H', fg: 'red' })
|
|
30
|
+
const screen = app.screen
|
|
31
|
+
screen.setCell(0, 0, { char: 'H', fg: 'red' })
|
|
33
32
|
|
|
34
33
|
// Start the render loop
|
|
35
|
-
app.start()
|
|
34
|
+
app.start()
|
|
36
35
|
```
|
|
37
36
|
|
|
38
37
|
## Event bubbling
|
|
39
38
|
|
|
40
|
-
Key events
|
|
39
|
+
Key events start at the focused widget and bubble up through its parents. Stop propagation at any level.
|
|
41
40
|
|
|
42
41
|
```typescript
|
|
43
|
-
import { createKeyEvent } from '@termuijs/core'
|
|
42
|
+
import { createKeyEvent } from '@termuijs/core'
|
|
44
43
|
|
|
45
|
-
// Events include stopPropagation() and preventDefault()
|
|
46
44
|
widget.on('key', (event) => {
|
|
47
45
|
if (event.key === 'enter') {
|
|
48
|
-
event.stopPropagation()
|
|
49
|
-
//
|
|
46
|
+
event.stopPropagation()
|
|
47
|
+
// handled here, parents won't see it
|
|
50
48
|
}
|
|
51
|
-
})
|
|
49
|
+
})
|
|
52
50
|
```
|
|
53
51
|
|
|
54
52
|
## Clip regions
|
|
@@ -56,15 +54,18 @@ widget.on('key', (event) => {
|
|
|
56
54
|
Widgets clip their children by default. Nothing renders outside a widget's bounds.
|
|
57
55
|
|
|
58
56
|
```typescript
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
screen.popClip();
|
|
57
|
+
screen.pushClip({ x: 5, y: 5, width: 20, height: 10 })
|
|
58
|
+
// setCell calls outside this rect are silently discarded
|
|
59
|
+
screen.popClip()
|
|
63
60
|
```
|
|
64
61
|
|
|
62
|
+
## Batched rendering
|
|
63
|
+
|
|
64
|
+
State changes are batched via `queueMicrotask`. Multiple `setState` calls in the same tick produce a single render pass, not three.
|
|
65
|
+
|
|
65
66
|
## API reference
|
|
66
67
|
|
|
67
|
-
|
|
68
|
+
Full docs at [termuijs.dev/docs/core/overview](https://termuijs.dev/docs/core/overview).
|
|
68
69
|
|
|
69
70
|
## License
|
|
70
71
|
|