@gjermundgaraba/clankermux 0.0.0-stage → 0.1.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/dist/client/attachment.d.ts +71 -0
- package/dist/client/attachment.js +240 -0
- package/dist/client/connection.d.ts +51 -0
- package/dist/client/connection.js +171 -0
- package/dist/client/index.d.ts +9 -0
- package/dist/client/index.js +4 -0
- package/dist/client/keyboard.d.ts +24 -0
- package/dist/client/keyboard.js +32 -0
- package/dist/client/mount.d.ts +46 -0
- package/dist/client/mount.js +139 -0
- package/dist/client/osc52.d.ts +14 -0
- package/dist/client/osc52.js +88 -0
- package/dist/client/profile.d.ts +10 -0
- package/dist/client/profile.js +30 -0
- package/dist/client/worker.d.ts +59 -0
- package/dist/client/worker.js +449 -0
- package/dist/engine/decoder.d.ts +45 -0
- package/dist/engine/decoder.js +137 -0
- package/dist/engine/index.d.ts +110 -0
- package/dist/engine/index.js +372 -0
- package/dist/engine/keys.d.ts +39 -0
- package/dist/engine/keys.js +66 -0
- package/dist/engine/pin.d.ts +2 -0
- package/dist/engine/pin.js +3 -0
- package/dist/engine/render.d.ts +79 -0
- package/dist/engine/render.js +224 -0
- package/dist/proto/frame.d.ts +47 -0
- package/dist/proto/frame.js +78 -0
- package/dist/proto/index.d.ts +3 -0
- package/dist/proto/index.js +3 -0
- package/dist/proto/messages.d.ts +218 -0
- package/dist/proto/messages.js +1 -0
- package/dist/proto/stream.d.ts +11 -0
- package/dist/proto/stream.js +30 -0
- package/dist/renderer/index.d.ts +44 -0
- package/dist/renderer/index.js +138 -0
- package/ghostty-vt.wasm +0 -0
- package/package.json +48 -3
- package/README.md +0 -3
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { FLAG, NO_COLOR } from "../engine/index.js";
|
|
2
|
+
const hex = (color) => `#${color.toString(16).padStart(6, "0")}`;
|
|
3
|
+
/** A cell or cursor colour, or `fallback` when it has none. */
|
|
4
|
+
const css = (color, fallback) => (color === NO_COLOR ? fallback : hex(color));
|
|
5
|
+
/**
|
|
6
|
+
* Draws frames onto a 2D context: changed rows only, then the cursor.
|
|
7
|
+
* Rows are cached so the row the cursor leaves can be redrawn.
|
|
8
|
+
*/
|
|
9
|
+
export class CanvasRenderer {
|
|
10
|
+
ctx;
|
|
11
|
+
metrics;
|
|
12
|
+
palette;
|
|
13
|
+
rows = new Map();
|
|
14
|
+
cursorRow;
|
|
15
|
+
cols = 0;
|
|
16
|
+
background = "";
|
|
17
|
+
foreground = "";
|
|
18
|
+
constructor(ctx, metrics, palette) {
|
|
19
|
+
this.ctx = ctx;
|
|
20
|
+
this.metrics = metrics;
|
|
21
|
+
this.palette = palette;
|
|
22
|
+
}
|
|
23
|
+
draw(frame) {
|
|
24
|
+
// The frame always carries the default colours.
|
|
25
|
+
this.background = hex(frame.background);
|
|
26
|
+
this.foreground = hex(frame.foreground);
|
|
27
|
+
if (frame.full || frame.cols !== this.cols) {
|
|
28
|
+
this.cols = frame.cols;
|
|
29
|
+
this.rows.clear();
|
|
30
|
+
this.ctx.globalAlpha = 1;
|
|
31
|
+
this.ctx.fillStyle = this.background;
|
|
32
|
+
this.ctx.fillRect(0, 0, frame.cols * this.metrics.cellWidth, frame.rows * this.metrics.cellHeight);
|
|
33
|
+
}
|
|
34
|
+
const drawn = new Set();
|
|
35
|
+
for (const row of frame.lines) {
|
|
36
|
+
this.rows.set(row.y, row.cells);
|
|
37
|
+
this.drawRow(row);
|
|
38
|
+
drawn.add(row.y);
|
|
39
|
+
}
|
|
40
|
+
// The cursor's old row is redrawn from the cache when the cursor
|
|
41
|
+
// moved or went away; the engine marks no row dirty for either.
|
|
42
|
+
const cursor = frame.cursor?.visible ? frame.cursor : undefined;
|
|
43
|
+
if (this.cursorRow !== undefined && this.cursorRow !== cursor?.y && !drawn.has(this.cursorRow)) {
|
|
44
|
+
const cells = this.rows.get(this.cursorRow);
|
|
45
|
+
if (cells)
|
|
46
|
+
this.drawRow({ y: this.cursorRow, cells });
|
|
47
|
+
}
|
|
48
|
+
this.cursorRow = undefined;
|
|
49
|
+
if (!cursor)
|
|
50
|
+
return;
|
|
51
|
+
if (!drawn.has(cursor.y)) {
|
|
52
|
+
const cells = this.rows.get(cursor.y);
|
|
53
|
+
if (cells)
|
|
54
|
+
this.drawRow({ y: cursor.y, cells });
|
|
55
|
+
}
|
|
56
|
+
this.drawCursor(cursor);
|
|
57
|
+
this.cursorRow = cursor.y;
|
|
58
|
+
}
|
|
59
|
+
drawRow(row) {
|
|
60
|
+
const { cellWidth, cellHeight, baseline } = this.metrics;
|
|
61
|
+
const y = row.y * cellHeight;
|
|
62
|
+
this.ctx.globalAlpha = 1;
|
|
63
|
+
this.ctx.fillStyle = this.background;
|
|
64
|
+
this.ctx.fillRect(0, y, this.cols * cellWidth, cellHeight);
|
|
65
|
+
for (let x = 0; x < row.cells.length; x++) {
|
|
66
|
+
const cell = row.cells[x];
|
|
67
|
+
if (cell.flags & FLAG.SPACER)
|
|
68
|
+
continue;
|
|
69
|
+
const width = cell.flags & FLAG.WIDE ? 2 : 1;
|
|
70
|
+
let fg = css(cell.fg, this.foreground);
|
|
71
|
+
let bg = css(cell.bg, this.background);
|
|
72
|
+
if (cell.flags & FLAG.INVERSE)
|
|
73
|
+
[fg, bg] = [bg, fg];
|
|
74
|
+
if (bg !== this.background) {
|
|
75
|
+
this.ctx.fillStyle = bg;
|
|
76
|
+
this.ctx.fillRect(x * cellWidth, y, width * cellWidth, cellHeight);
|
|
77
|
+
}
|
|
78
|
+
if (cell.flags & FLAG.INVISIBLE)
|
|
79
|
+
continue;
|
|
80
|
+
this.ctx.globalAlpha = cell.flags & FLAG.FAINT ? 0.6 : 1;
|
|
81
|
+
this.ctx.fillStyle = fg;
|
|
82
|
+
if (cell.text !== "" && cell.text !== " ") {
|
|
83
|
+
this.ctx.font = this.font(cell.flags);
|
|
84
|
+
this.ctx.fillText(cell.text, x * cellWidth, y + baseline);
|
|
85
|
+
}
|
|
86
|
+
if (cell.underline !== 0) {
|
|
87
|
+
this.ctx.fillRect(x * cellWidth, y + cellHeight - 2, width * cellWidth, 1);
|
|
88
|
+
}
|
|
89
|
+
if (cell.flags & FLAG.STRIKETHROUGH) {
|
|
90
|
+
this.ctx.fillRect(x * cellWidth, y + Math.floor(cellHeight / 2), width * cellWidth, 1);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
this.ctx.globalAlpha = 1;
|
|
94
|
+
}
|
|
95
|
+
font(flags) {
|
|
96
|
+
const bold = (flags & FLAG.BOLD) !== 0;
|
|
97
|
+
const italic = (flags & FLAG.ITALIC) !== 0;
|
|
98
|
+
if (bold && italic)
|
|
99
|
+
return this.metrics.boldItalicFont;
|
|
100
|
+
if (bold)
|
|
101
|
+
return this.metrics.boldFont;
|
|
102
|
+
if (italic)
|
|
103
|
+
return this.metrics.italicFont;
|
|
104
|
+
return this.metrics.font;
|
|
105
|
+
}
|
|
106
|
+
drawCursor(cursor) {
|
|
107
|
+
const { cellWidth, cellHeight, baseline } = this.metrics;
|
|
108
|
+
const x = cursor.x * cellWidth;
|
|
109
|
+
const y = cursor.y * cellHeight;
|
|
110
|
+
const color = css(cursor.color, this.palette.cursor);
|
|
111
|
+
this.ctx.globalAlpha = 1;
|
|
112
|
+
this.ctx.fillStyle = color;
|
|
113
|
+
switch (cursor.style) {
|
|
114
|
+
case "bar":
|
|
115
|
+
this.ctx.fillRect(x, y, 2, cellHeight);
|
|
116
|
+
return;
|
|
117
|
+
case "underline":
|
|
118
|
+
this.ctx.fillRect(x, y + cellHeight - 2, cellWidth, 2);
|
|
119
|
+
return;
|
|
120
|
+
case "block_hollow":
|
|
121
|
+
this.ctx.fillRect(x, y, cellWidth, 1);
|
|
122
|
+
this.ctx.fillRect(x, y + cellHeight - 1, cellWidth, 1);
|
|
123
|
+
this.ctx.fillRect(x, y, 1, cellHeight);
|
|
124
|
+
this.ctx.fillRect(x + cellWidth - 1, y, 1, cellHeight);
|
|
125
|
+
return;
|
|
126
|
+
default: {
|
|
127
|
+
this.ctx.fillRect(x, y, cellWidth, cellHeight);
|
|
128
|
+
// The cell's text in the background colour, over the block.
|
|
129
|
+
const cell = this.rows.get(cursor.y)?.[cursor.x];
|
|
130
|
+
if (cell && cell.text !== "" && cell.text !== " ") {
|
|
131
|
+
this.ctx.fillStyle = this.background;
|
|
132
|
+
this.ctx.font = this.font(cell.flags);
|
|
133
|
+
this.ctx.fillText(cell.text, x, y + baseline);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
package/ghostty-vt.wasm
ADDED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,51 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjermundgaraba/clankermux",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/gjermundgaraba/clankermux.git",
|
|
8
|
+
"directory": "web/packages/clankermux"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"sideEffects": false,
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/client/index.d.ts",
|
|
15
|
+
"default": "./dist/client/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./worker": {
|
|
18
|
+
"types": "./dist/client/worker.d.ts",
|
|
19
|
+
"default": "./dist/client/worker.js"
|
|
20
|
+
},
|
|
21
|
+
"./proto": {
|
|
22
|
+
"types": "./dist/proto/index.d.ts",
|
|
23
|
+
"default": "./dist/proto/index.js"
|
|
24
|
+
},
|
|
25
|
+
"./engine": {
|
|
26
|
+
"types": "./dist/engine/index.d.ts",
|
|
27
|
+
"default": "./dist/engine/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./renderer": {
|
|
30
|
+
"types": "./dist/renderer/index.d.ts",
|
|
31
|
+
"default": "./dist/renderer/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./ghostty-vt.wasm": "./ghostty-vt.wasm"
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist",
|
|
37
|
+
"ghostty-vt.wasm"
|
|
38
|
+
],
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"ws": "^8.18.0",
|
|
44
|
+
"@types/ws": "^8.18.0"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"typecheck": "tsc -p tsconfig.json && tsc -p tsconfig.worker.json",
|
|
48
|
+
"test": "vitest run",
|
|
49
|
+
"build": "tsc -p tsconfig.build.json"
|
|
50
|
+
}
|
|
6
51
|
}
|
package/README.md
DELETED