@gjermundgaraba/clankermux 0.1.1 → 0.2.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 +64 -0
- package/dist/client/keyboard.d.ts +41 -0
- package/dist/client/keyboard.js +60 -0
- package/dist/client/mount.d.ts +18 -6
- package/dist/client/mount.js +287 -15
- package/dist/client/profile.d.ts +4 -0
- package/dist/client/profile.js +11 -0
- package/dist/client/worker.d.ts +36 -3
- package/dist/client/worker.js +163 -6
- package/dist/engine/index.d.ts +34 -0
- package/dist/engine/index.js +102 -0
- package/dist/engine/render.d.ts +8 -1
- package/dist/engine/render.js +24 -3
- package/dist/engine/selection.d.ts +39 -0
- package/dist/engine/selection.js +114 -0
- package/dist/renderer/index.d.ts +8 -2
- package/dist/renderer/index.js +57 -16
- package/package.json +1 -1
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/** Pixels per cell in the gesture's geometry: positions are in cells,
|
|
2
|
+
* scaled to whole numbers. */
|
|
3
|
+
const SCALE = 1000;
|
|
4
|
+
/** Clicks closer together than this, and within a cell of each other,
|
|
5
|
+
* count up to a word (two) and a line (three). */
|
|
6
|
+
const REPEAT_MS = 500;
|
|
7
|
+
/**
|
|
8
|
+
* Mouse selection through the engine's gesture: a press, then drags, then
|
|
9
|
+
* a release. A single press selects nothing; a drag selects from it by
|
|
10
|
+
* cells, a double press a word and a triple press a line, dragging by
|
|
11
|
+
* words or lines. The gesture tracks its anchor in the terminal, so
|
|
12
|
+
* output between press and drag does not move it.
|
|
13
|
+
*/
|
|
14
|
+
export class SelectionGesture {
|
|
15
|
+
engine;
|
|
16
|
+
gesture;
|
|
17
|
+
events;
|
|
18
|
+
/** The terminal the gesture tracks its anchor in. */
|
|
19
|
+
term;
|
|
20
|
+
constructor(engine) {
|
|
21
|
+
this.engine = engine;
|
|
22
|
+
this.gesture = engine.construct("ghostty_selection_gesture_new");
|
|
23
|
+
const event = (type) => engine.construct("ghostty_selection_gesture_event_new", engine.enumValue("GhosttySelectionGestureEventType", type));
|
|
24
|
+
this.events = { press: event("PRESS"), drag: event("DRAG"), release: event("RELEASE") };
|
|
25
|
+
const f64 = new Uint8Array(8);
|
|
26
|
+
new DataView(f64.buffer).setFloat64(0, SCALE, true);
|
|
27
|
+
this.set(this.events.press, "REPEAT_DISTANCE", f64);
|
|
28
|
+
this.set(this.events.press, "REPEAT_INTERVAL_NS", u64(REPEAT_MS * 1e6));
|
|
29
|
+
}
|
|
30
|
+
/** Presses at `at` (`time` in ms); the selection to install, or
|
|
31
|
+
* undefined for none (a single press). */
|
|
32
|
+
press(term, at, time) {
|
|
33
|
+
this.follow(term);
|
|
34
|
+
this.set(this.events.press, "REF", term.gridRef(at));
|
|
35
|
+
this.set(this.events.press, "POSITION", position(at));
|
|
36
|
+
this.set(this.events.press, "TIME_NS", u64(time * 1e6));
|
|
37
|
+
return this.apply(term, this.events.press);
|
|
38
|
+
}
|
|
39
|
+
/** Drags to `at`; the selection from the press, or undefined when the
|
|
40
|
+
* pointer has not left the pressed cell. */
|
|
41
|
+
drag(term, at) {
|
|
42
|
+
if (this.term !== term.handle)
|
|
43
|
+
return undefined;
|
|
44
|
+
const geometry = new Uint8Array(16);
|
|
45
|
+
const view = new DataView(geometry.buffer);
|
|
46
|
+
view.setUint32(0, term.cols, true);
|
|
47
|
+
view.setUint32(4, SCALE, true);
|
|
48
|
+
view.setUint32(8, 0, true);
|
|
49
|
+
view.setUint32(12, term.rows * SCALE, true);
|
|
50
|
+
this.set(this.events.drag, "REF", term.gridRef(at));
|
|
51
|
+
this.set(this.events.drag, "POSITION", position(at));
|
|
52
|
+
this.set(this.events.drag, "GEOMETRY", geometry);
|
|
53
|
+
return this.apply(term, this.events.drag);
|
|
54
|
+
}
|
|
55
|
+
release(term, at) {
|
|
56
|
+
if (this.term !== term.handle)
|
|
57
|
+
return;
|
|
58
|
+
this.set(this.events.release, "REF", term.gridRef(at));
|
|
59
|
+
this.apply(term, this.events.release);
|
|
60
|
+
}
|
|
61
|
+
/** Starts afresh, for a terminal freed or about to be: `term` when it
|
|
62
|
+
* is still alive, to release the tracked anchor in it, else none. The
|
|
63
|
+
* caller says so, since a new terminal may have the handle of a freed
|
|
64
|
+
* one. */
|
|
65
|
+
forget(term) {
|
|
66
|
+
if (this.term === undefined)
|
|
67
|
+
return;
|
|
68
|
+
this.engine.call("ghostty_selection_gesture_free", this.gesture, term?.handle ?? 0);
|
|
69
|
+
this.gesture = this.engine.construct("ghostty_selection_gesture_new");
|
|
70
|
+
this.term = undefined;
|
|
71
|
+
}
|
|
72
|
+
/** A gesture is in one terminal. */
|
|
73
|
+
follow(term) {
|
|
74
|
+
if (this.term !== term.handle)
|
|
75
|
+
this.forget();
|
|
76
|
+
this.term = term.handle;
|
|
77
|
+
}
|
|
78
|
+
set(event, option, value) {
|
|
79
|
+
const e = this.engine;
|
|
80
|
+
e.withBytes(value, (ptr) => e.check("ghostty_selection_gesture_event_set", event, e.enumValue("GhosttySelectionGestureEventOption", option), ptr));
|
|
81
|
+
}
|
|
82
|
+
apply(term, event) {
|
|
83
|
+
const e = this.engine;
|
|
84
|
+
const size = e.sizeOf("GhosttySelection");
|
|
85
|
+
return e.scratch(size, (out) => {
|
|
86
|
+
e.memory.fill(0, out, out + size);
|
|
87
|
+
e.view.setUint32(out, size, true);
|
|
88
|
+
const code = e.call("ghostty_selection_gesture_event", this.gesture, term.handle, event, out);
|
|
89
|
+
if (code === e.result.NO_VALUE)
|
|
90
|
+
return undefined;
|
|
91
|
+
if (code !== e.result.SUCCESS)
|
|
92
|
+
throw new Error(`selection gesture: ${code}`);
|
|
93
|
+
return e.memory.slice(out, out + size);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
free() {
|
|
97
|
+
for (const event of Object.values(this.events))
|
|
98
|
+
this.engine.call("ghostty_selection_gesture_event_free", event);
|
|
99
|
+
this.engine.call("ghostty_selection_gesture_free", this.gesture, 0);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
function u64(value) {
|
|
103
|
+
const bytes = new Uint8Array(8);
|
|
104
|
+
new DataView(bytes.buffer).setBigUint64(0, BigInt(Math.round(value)), true);
|
|
105
|
+
return bytes;
|
|
106
|
+
}
|
|
107
|
+
/** A `GhosttySurfacePosition` for `at`, in the gesture's scaled pixels. */
|
|
108
|
+
function position(at) {
|
|
109
|
+
const bytes = new Uint8Array(16);
|
|
110
|
+
const view = new DataView(bytes.buffer);
|
|
111
|
+
view.setFloat64(0, at.x * SCALE, true);
|
|
112
|
+
view.setFloat64(8, at.y * SCALE, true);
|
|
113
|
+
return bytes;
|
|
114
|
+
}
|
package/dist/renderer/index.d.ts
CHANGED
|
@@ -24,8 +24,9 @@ export interface Context2D {
|
|
|
24
24
|
fillText(text: string, x: number, y: number): void;
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
|
-
* Draws frames onto a 2D context: changed rows only, then the cursor
|
|
28
|
-
* Rows are cached so the
|
|
27
|
+
* Draws frames onto a 2D context: changed rows only, then the cursor, then
|
|
28
|
+
* the scrollback mark. Rows are cached so the rows the cursor or the mark
|
|
29
|
+
* leaves can be redrawn.
|
|
29
30
|
*/
|
|
30
31
|
export declare class CanvasRenderer {
|
|
31
32
|
private readonly ctx;
|
|
@@ -33,11 +34,16 @@ export declare class CanvasRenderer {
|
|
|
33
34
|
private readonly palette;
|
|
34
35
|
private rows;
|
|
35
36
|
private cursorRow;
|
|
37
|
+
/** The scrollback mark drawn last, in pixels from the top. */
|
|
38
|
+
private mark;
|
|
36
39
|
private cols;
|
|
37
40
|
private background;
|
|
38
41
|
private foreground;
|
|
39
42
|
constructor(ctx: Context2D, metrics: Metrics, palette: Palette);
|
|
40
43
|
draw(frame: Frame): void;
|
|
44
|
+
/** The scrollback mark for `frame`: the viewport's share of the history
|
|
45
|
+
* at the right edge, while the view is scrolled back. */
|
|
46
|
+
private markOf;
|
|
41
47
|
private drawRow;
|
|
42
48
|
private font;
|
|
43
49
|
private drawCursor;
|
package/dist/renderer/index.js
CHANGED
|
@@ -2,9 +2,13 @@ import { FLAG, NO_COLOR } from "../engine/index.js";
|
|
|
2
2
|
const hex = (color) => `#${color.toString(16).padStart(6, "0")}`;
|
|
3
3
|
/** A cell or cursor colour, or `fallback` when it has none. */
|
|
4
4
|
const css = (color, fallback) => (color === NO_COLOR ? fallback : hex(color));
|
|
5
|
+
/** Width in CSS pixels of the mark at the right edge that shows the view
|
|
6
|
+
* scrolled back, and where it is in the history. */
|
|
7
|
+
const MARK_WIDTH = 3;
|
|
5
8
|
/**
|
|
6
|
-
* Draws frames onto a 2D context: changed rows only, then the cursor
|
|
7
|
-
* Rows are cached so the
|
|
9
|
+
* Draws frames onto a 2D context: changed rows only, then the cursor, then
|
|
10
|
+
* the scrollback mark. Rows are cached so the rows the cursor or the mark
|
|
11
|
+
* leaves can be redrawn.
|
|
8
12
|
*/
|
|
9
13
|
export class CanvasRenderer {
|
|
10
14
|
ctx;
|
|
@@ -12,6 +16,8 @@ export class CanvasRenderer {
|
|
|
12
16
|
palette;
|
|
13
17
|
rows = new Map();
|
|
14
18
|
cursorRow;
|
|
19
|
+
/** The scrollback mark drawn last, in pixels from the top. */
|
|
20
|
+
mark;
|
|
15
21
|
cols = 0;
|
|
16
22
|
background = "";
|
|
17
23
|
foreground = "";
|
|
@@ -27,34 +33,67 @@ export class CanvasRenderer {
|
|
|
27
33
|
if (frame.full || frame.cols !== this.cols) {
|
|
28
34
|
this.cols = frame.cols;
|
|
29
35
|
this.rows.clear();
|
|
36
|
+
this.mark = undefined;
|
|
30
37
|
this.ctx.globalAlpha = 1;
|
|
31
38
|
this.ctx.fillStyle = this.background;
|
|
32
39
|
this.ctx.fillRect(0, 0, frame.cols * this.metrics.cellWidth, frame.rows * this.metrics.cellHeight);
|
|
33
40
|
}
|
|
34
41
|
const drawn = new Set();
|
|
35
42
|
for (const row of frame.lines) {
|
|
36
|
-
this.rows.set(row.y, row
|
|
43
|
+
this.rows.set(row.y, row);
|
|
37
44
|
this.drawRow(row);
|
|
38
45
|
drawn.add(row.y);
|
|
39
46
|
}
|
|
47
|
+
// The last mark is erased with the rows under it, every frame: it is
|
|
48
|
+
// translucent, so one drawn over itself would darken.
|
|
49
|
+
const mark = this.markOf(frame);
|
|
50
|
+
if (this.mark) {
|
|
51
|
+
const { cellHeight } = this.metrics;
|
|
52
|
+
const last = Math.ceil((this.mark.top + this.mark.height) / cellHeight);
|
|
53
|
+
for (let y = Math.floor(this.mark.top / cellHeight); y < last; y++) {
|
|
54
|
+
const row = this.rows.get(y);
|
|
55
|
+
if (row && !drawn.has(y)) {
|
|
56
|
+
this.drawRow(row);
|
|
57
|
+
drawn.add(y);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
40
61
|
// The cursor's old row is redrawn from the cache when the cursor
|
|
41
62
|
// moved or went away; the engine marks no row dirty for either.
|
|
42
63
|
const cursor = frame.cursor?.visible ? frame.cursor : undefined;
|
|
43
64
|
if (this.cursorRow !== undefined && this.cursorRow !== cursor?.y && !drawn.has(this.cursorRow)) {
|
|
44
|
-
const
|
|
45
|
-
if (
|
|
46
|
-
this.drawRow(
|
|
65
|
+
const row = this.rows.get(this.cursorRow);
|
|
66
|
+
if (row)
|
|
67
|
+
this.drawRow(row);
|
|
47
68
|
}
|
|
48
69
|
this.cursorRow = undefined;
|
|
49
|
-
if (
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
70
|
+
if (cursor) {
|
|
71
|
+
if (!drawn.has(cursor.y)) {
|
|
72
|
+
const row = this.rows.get(cursor.y);
|
|
73
|
+
if (row)
|
|
74
|
+
this.drawRow(row);
|
|
75
|
+
}
|
|
76
|
+
this.drawCursor(cursor);
|
|
77
|
+
this.cursorRow = cursor.y;
|
|
55
78
|
}
|
|
56
|
-
|
|
57
|
-
this.
|
|
79
|
+
// Over everything, on rows just drawn.
|
|
80
|
+
this.mark = mark;
|
|
81
|
+
if (mark) {
|
|
82
|
+
this.ctx.globalAlpha = 0.5;
|
|
83
|
+
this.ctx.fillStyle = this.foreground;
|
|
84
|
+
this.ctx.fillRect(this.cols * this.metrics.cellWidth - MARK_WIDTH, mark.top, MARK_WIDTH, mark.height);
|
|
85
|
+
this.ctx.globalAlpha = 1;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/** The scrollback mark for `frame`: the viewport's share of the history
|
|
89
|
+
* at the right edge, while the view is scrolled back. */
|
|
90
|
+
markOf(frame) {
|
|
91
|
+
const { total, offset, len } = frame.scrollbar;
|
|
92
|
+
if (offset + len >= total)
|
|
93
|
+
return undefined;
|
|
94
|
+
const height = frame.rows * this.metrics.cellHeight;
|
|
95
|
+
const size = Math.max(Math.round((height * len) / total), Math.min(height, this.metrics.cellHeight));
|
|
96
|
+
return { top: Math.min(Math.round((height * offset) / total), height - size), height: size };
|
|
58
97
|
}
|
|
59
98
|
drawRow(row) {
|
|
60
99
|
const { cellWidth, cellHeight, baseline } = this.metrics;
|
|
@@ -69,7 +108,9 @@ export class CanvasRenderer {
|
|
|
69
108
|
const width = cell.flags & FLAG.WIDE ? 2 : 1;
|
|
70
109
|
let fg = css(cell.fg, this.foreground);
|
|
71
110
|
let bg = css(cell.bg, this.background);
|
|
72
|
-
|
|
111
|
+
// A selected cell is drawn inverted, an inverse one the other way.
|
|
112
|
+
const selected = row.selection !== undefined && x >= row.selection[0] && x <= row.selection[1];
|
|
113
|
+
if (((cell.flags & FLAG.INVERSE) !== 0) !== selected)
|
|
73
114
|
[fg, bg] = [bg, fg];
|
|
74
115
|
if (bg !== this.background) {
|
|
75
116
|
this.ctx.fillStyle = bg;
|
|
@@ -126,7 +167,7 @@ export class CanvasRenderer {
|
|
|
126
167
|
default: {
|
|
127
168
|
this.ctx.fillRect(x, y, cellWidth, cellHeight);
|
|
128
169
|
// The cell's text in the background colour, over the block.
|
|
129
|
-
const cell = this.rows.get(cursor.y)?.[cursor.x];
|
|
170
|
+
const cell = this.rows.get(cursor.y)?.cells[cursor.x];
|
|
130
171
|
if (cell && cell.text !== "" && cell.text !== " ") {
|
|
131
172
|
this.ctx.fillStyle = this.background;
|
|
132
173
|
this.ctx.font = this.font(cell.flags);
|