You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+97-18Lines changed: 97 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,48 @@
1
1
# clayterm
2
2
3
-
A terminal rendering backend for [Clay](https://github.com/nicbarker/clay), and
4
-
a terminal input event parser compiled to WebAssembly.
3
+
A low-level, platform-independent terminal renderer and event parser for JavaScript. You can use clayterm directly, or as the foundation for your own framework.
4
+
5
+
## Features
6
+
7
+
**Declarative terminal UI** — Build terminal interfaces the same way you'd
8
+
build a web page. Clayterm uses [Clay](https://github.com/nicbarker/clay) under
9
+
the hood, giving you flexbox-like layout, pointer detection, and scroll
10
+
containers — all rendered to the terminal as box-drawing characters and ANSI
11
+
escape sequences.
12
+
13
+
**Zero I/O** — Clayterm never reads stdin or writes stdout. You feed it bytes
14
+
and get bytes back. This makes it trivially embeddable in any framework, any
15
+
runtime, any event loop. There are no opinions about how you do I/O, just pure
16
+
computation.
17
+
18
+
**Runs everywhere** — The entire engine is compiled to WebAssembly, so
19
+
clayterm will run anywhere JavaScript runs with no native
20
+
dependencies, and no build step for consumers.
21
+
22
+
### Demo
23
+
24
+
The application in this demo uses Clayterm for all layout and input parsing
25
+
26
+
#### Keyboard Events
27
+
28
+
The input parser decodes raw terminal bytes into structured events.
29
+
Here you can see each key event as the string "hello world" is typed.
Clayterm does not do any I/O itself. On the ouput side, it converts UI elements into a raw sequence of bytes and pointer events, and on the input side, it converts a stream of raw bytes into structured events.
45
+
8
46
### Output
9
47
10
48
With every frame, the entire UI tree is packed into a flat byte array and sent
@@ -54,36 +92,41 @@ multi-byte sequences time to arrive.
54
92
| |
55
93
+---------------+ | |
56
94
| | events[] | |
57
-
| CharEvent | <============= | |
58
-
| KeyEvent | | |
59
-
| MouseEvent | +---------------------------+
60
-
| DragEvent |
95
+
| KeyEvent | <============= | |
96
+
| MouseDownEvent| | |
97
+
| MouseUpEvent | +---------------------------+
98
+
| MouseMoveEvent|
61
99
| WheelEvent |
62
100
| ResizeEvent |
63
101
+---------------+
64
102
```
65
103
66
104
## Usage
67
105
68
-
### Output
106
+
### Rendering
107
+
108
+
To render this:
109
+
110
+
```
111
+
╭───────────────╮
112
+
│ Hello, World! │
113
+
╰───────────────╯
114
+
```
69
115
70
116
```typescript
71
117
import { close, createTerm, grow, open, rgba, text } from"clayterm";
72
118
73
-
const term =awaitcreateTerm({ width: 80, height: 24 });
119
+
let term =awaitcreateTerm({ width: 80, height: 24 });
0 commit comments