@code-yeongyu/senpi-tui 2026.9.12 → 2026.9.13
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 +53 -4
- package/dist/alt-screen-search.d.ts +21 -1
- package/dist/alt-screen-search.d.ts.map +1 -1
- package/dist/alt-screen-search.js +199 -42
- package/dist/alt-screen-search.js.map +1 -1
- package/dist/components/box.d.ts +3 -1
- package/dist/components/box.d.ts.map +1 -1
- package/dist/components/box.js +28 -0
- package/dist/components/box.js.map +1 -1
- package/dist/components/editor.d.ts +6 -1
- package/dist/components/editor.d.ts.map +1 -1
- package/dist/components/editor.js +98 -18
- package/dist/components/editor.js.map +1 -1
- package/dist/components/input.d.ts +12 -1
- package/dist/components/input.d.ts.map +1 -1
- package/dist/components/input.js +40 -6
- package/dist/components/input.js.map +1 -1
- package/dist/components/latex.d.ts.map +1 -1
- package/dist/components/latex.js +7 -0
- package/dist/components/latex.js.map +1 -1
- package/dist/components/loader.d.ts +3 -0
- package/dist/components/loader.d.ts.map +1 -1
- package/dist/components/loader.js +20 -8
- package/dist/components/loader.js.map +1 -1
- package/dist/components/mouse-region.d.ts +12 -0
- package/dist/components/mouse-region.d.ts.map +1 -0
- package/dist/components/mouse-region.js +19 -0
- package/dist/components/mouse-region.js.map +1 -0
- package/dist/components/scroll-view.d.ts +6 -3
- package/dist/components/scroll-view.d.ts.map +1 -1
- package/dist/components/scroll-view.js +6 -1
- package/dist/components/scroll-view.js.map +1 -1
- package/dist/components/select-list.d.ts +4 -1
- package/dist/components/select-list.d.ts.map +1 -1
- package/dist/components/select-list.js +48 -2
- package/dist/components/select-list.js.map +1 -1
- package/dist/components/settings-list.d.ts +5 -1
- package/dist/components/settings-list.d.ts.map +1 -1
- package/dist/components/settings-list.js +54 -5
- package/dist/components/settings-list.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/layout.d.ts +3 -1
- package/dist/layout.d.ts.map +1 -1
- package/dist/layout.js +32 -9
- package/dist/layout.js.map +1 -1
- package/dist/native-modifiers.d.ts +2 -1
- package/dist/native-modifiers.d.ts.map +1 -1
- package/dist/native-modifiers.js +3 -44
- package/dist/native-modifiers.js.map +1 -1
- package/dist/native-platform.d.ts +18 -0
- package/dist/native-platform.d.ts.map +1 -0
- package/dist/native-platform.js +42 -0
- package/dist/native-platform.js.map +1 -0
- package/dist/terminal.d.ts.map +1 -1
- package/dist/terminal.js +2 -20
- package/dist/terminal.js.map +1 -1
- package/dist/tui-alt-screen.d.ts +31 -1
- package/dist/tui-alt-screen.d.ts.map +1 -1
- package/dist/tui-alt-screen.js +335 -41
- package/dist/tui-alt-screen.js.map +1 -1
- package/dist/tui.d.ts +83 -5
- package/dist/tui.d.ts.map +1 -1
- package/dist/tui.js +118 -4
- package/dist/tui.js.map +1 -1
- package/dist/utils.d.ts +2 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +9 -0
- package/dist/utils.js.map +1 -1
- package/native/clipboard.h +170 -0
- package/native/darwin/README.md +8 -6
- package/native/darwin/build.sh +12 -5
- package/native/darwin/prebuilds/darwin-arm64/{darwin-modifiers.node → darwin-platform.node} +0 -0
- package/native/darwin/prebuilds/darwin-x64/{darwin-modifiers.node → darwin-platform.node} +0 -0
- package/native/darwin/src/darwin-platform.m +93 -0
- package/native/linux/README.md +23 -0
- package/native/linux/build.sh +65 -0
- package/native/linux/prebuilds/linux-arm64/linux-platform-x11.node +0 -0
- package/native/linux/prebuilds/linux-x64/linux-platform-x11.node +0 -0
- package/native/linux/src/clipboard-worker.h +70 -0
- package/native/linux/src/linux-platform-x11.c +274 -0
- package/native/napi.h +89 -0
- package/native/win32/README.md +18 -7
- package/native/win32/build.mjs +7 -4
- package/native/win32/prebuilds/win32-arm64/win32-platform.node +0 -0
- package/native/win32/prebuilds/win32-x64/win32-platform.node +0 -0
- package/native/win32/src/win32-platform.c +241 -0
- package/package.json +10 -3
- package/native/darwin/src/darwin-modifiers.c +0 -70
- package/native/win32/prebuilds/win32-arm64/win32-console-mode.node +0 -0
- package/native/win32/prebuilds/win32-x64/win32-console-mode.node +0 -0
- package/native/win32/src/win32-console-mode.c +0 -119
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
#include <xcb/xcb.h>
|
|
2
|
+
#include <string.h>
|
|
3
|
+
#include <xcb/xcbext.h>
|
|
4
|
+
#include <errno.h>
|
|
5
|
+
#include <poll.h>
|
|
6
|
+
#include <time.h>
|
|
7
|
+
#include "clipboard-worker.h"
|
|
8
|
+
|
|
9
|
+
#define MAX_CLIPBOARD_BYTES (50u * 1024u * 1024u)
|
|
10
|
+
#define CLIPBOARD_TIMEOUT_MS 2000
|
|
11
|
+
|
|
12
|
+
static const char* const text_types[] = {
|
|
13
|
+
"text/plain;charset=utf-8", "text/plain;charset=UTF-8", "UTF8_STRING", "text/plain", "STRING",
|
|
14
|
+
};
|
|
15
|
+
static const char* const image_types[] = {
|
|
16
|
+
"image/png", "image/jpeg", "image/webp", "image/gif", "image/bmp", "image/tiff",
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
static int64_t monotonic_ms(void) {
|
|
20
|
+
struct timespec now;
|
|
21
|
+
clock_gettime(CLOCK_MONOTONIC, &now);
|
|
22
|
+
return (int64_t)now.tv_sec * 1000 + now.tv_nsec / 1000000;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
typedef struct {
|
|
26
|
+
unsigned char* data;
|
|
27
|
+
size_t length;
|
|
28
|
+
uint32_t items;
|
|
29
|
+
uint8_t format;
|
|
30
|
+
xcb_atom_t type;
|
|
31
|
+
} property_data;
|
|
32
|
+
|
|
33
|
+
typedef struct {
|
|
34
|
+
xcb_connection_t* connection;
|
|
35
|
+
xcb_window_t window;
|
|
36
|
+
xcb_atom_t clipboard;
|
|
37
|
+
xcb_atom_t property;
|
|
38
|
+
xcb_atom_t targets;
|
|
39
|
+
xcb_atom_t incr;
|
|
40
|
+
int64_t deadline;
|
|
41
|
+
} x11_clipboard;
|
|
42
|
+
|
|
43
|
+
static bool append_bytes(property_data* result, const unsigned char* bytes, size_t length) {
|
|
44
|
+
if (length > MAX_CLIPBOARD_BYTES - result->length) return false;
|
|
45
|
+
unsigned char* data = realloc(result->data, result->length + length + 1);
|
|
46
|
+
if (!data) return false;
|
|
47
|
+
memcpy(data + result->length, bytes, length);
|
|
48
|
+
result->length += length;
|
|
49
|
+
data[result->length] = 0;
|
|
50
|
+
result->data = data;
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Share one deadline across discovery, replies, and incremental chunks.
|
|
55
|
+
// Connection setup and flushing are libxcb calls on the private thread.
|
|
56
|
+
static bool wait_for_input(x11_clipboard* clipboard) {
|
|
57
|
+
for (;;) {
|
|
58
|
+
int64_t remaining = clipboard->deadline - monotonic_ms();
|
|
59
|
+
if (remaining <= 0 || xcb_connection_has_error(clipboard->connection)) return false;
|
|
60
|
+
struct pollfd descriptor = {xcb_get_file_descriptor(clipboard->connection), POLLIN, 0};
|
|
61
|
+
int ready = poll(&descriptor, 1, (int)remaining);
|
|
62
|
+
if (ready >= 0) return ready && (descriptor.revents & POLLIN);
|
|
63
|
+
if (errno != EINTR) return false;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
static void* wait_for_reply(x11_clipboard* clipboard, unsigned sequence) {
|
|
68
|
+
if (xcb_flush(clipboard->connection) <= 0) return 0;
|
|
69
|
+
while (monotonic_ms() < clipboard->deadline) {
|
|
70
|
+
void* reply = 0;
|
|
71
|
+
xcb_generic_error_t* error = 0;
|
|
72
|
+
if (xcb_poll_for_reply(clipboard->connection, sequence, &reply, &error)) {
|
|
73
|
+
free(error);
|
|
74
|
+
return reply;
|
|
75
|
+
}
|
|
76
|
+
if (!wait_for_input(clipboard)) break;
|
|
77
|
+
}
|
|
78
|
+
xcb_discard_reply(clipboard->connection, sequence);
|
|
79
|
+
return 0;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
static xcb_generic_event_t* wait_for_event(x11_clipboard* clipboard, uint8_t type) {
|
|
83
|
+
if (xcb_flush(clipboard->connection) <= 0) return 0;
|
|
84
|
+
while (monotonic_ms() < clipboard->deadline) {
|
|
85
|
+
xcb_generic_event_t* event = xcb_poll_for_event(clipboard->connection);
|
|
86
|
+
if (event) {
|
|
87
|
+
if ((event->response_type & 0x7f) == type) return event;
|
|
88
|
+
free(event);
|
|
89
|
+
} else if (!wait_for_input(clipboard)) {
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return 0;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
static bool read_property(x11_clipboard* clipboard, bool remove, property_data* result) {
|
|
97
|
+
xcb_get_property_cookie_t cookie = xcb_get_property(
|
|
98
|
+
clipboard->connection, remove, clipboard->window, clipboard->property,
|
|
99
|
+
XCB_GET_PROPERTY_TYPE_ANY, 0, MAX_CLIPBOARD_BYTES / 4
|
|
100
|
+
);
|
|
101
|
+
xcb_get_property_reply_t* reply = wait_for_reply(clipboard, cookie.sequence);
|
|
102
|
+
if (!reply) return false;
|
|
103
|
+
bool copied = false;
|
|
104
|
+
bool valid_format = reply->format == 8 || reply->format == 16 || reply->format == 32;
|
|
105
|
+
uint64_t length = (uint64_t)reply->value_len * (reply->format / 8);
|
|
106
|
+
if (reply->bytes_after == 0 && reply->type != XCB_NONE && valid_format &&
|
|
107
|
+
length <= MAX_CLIPBOARD_BYTES && length <= (uint64_t)reply->length * 4) {
|
|
108
|
+
result->type = reply->type;
|
|
109
|
+
result->format = reply->format;
|
|
110
|
+
result->items = reply->value_len;
|
|
111
|
+
copied = append_bytes(result, xcb_get_property_value(reply), (size_t)length);
|
|
112
|
+
}
|
|
113
|
+
free(reply);
|
|
114
|
+
return copied;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
static bool append_property(property_data* result, const property_data* chunk) {
|
|
118
|
+
if ((chunk->format != 8 && chunk->format != 16 && chunk->format != 32) ||
|
|
119
|
+
chunk->type == XCB_NONE ||
|
|
120
|
+
(uint64_t)chunk->items * (chunk->format / 8) != chunk->length ||
|
|
121
|
+
(result->type != XCB_NONE && (result->type != chunk->type || result->format != chunk->format)) ||
|
|
122
|
+
chunk->items > UINT32_MAX - result->items) return false;
|
|
123
|
+
if (!append_bytes(result, chunk->data, chunk->length)) return false;
|
|
124
|
+
result->type = chunk->type;
|
|
125
|
+
result->format = chunk->format;
|
|
126
|
+
result->items += chunk->items;
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
static bool request_selection(x11_clipboard* clipboard, xcb_atom_t target, property_data* result) {
|
|
131
|
+
memset(result, 0, sizeof(*result));
|
|
132
|
+
xcb_delete_property(clipboard->connection, clipboard->window, clipboard->property);
|
|
133
|
+
xcb_convert_selection(
|
|
134
|
+
clipboard->connection, clipboard->window, clipboard->clipboard,
|
|
135
|
+
target, clipboard->property, XCB_CURRENT_TIME
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
while (true) {
|
|
139
|
+
xcb_selection_notify_event_t* event = (xcb_selection_notify_event_t*)wait_for_event(clipboard, XCB_SELECTION_NOTIFY);
|
|
140
|
+
if (!event) return false;
|
|
141
|
+
bool matches = event->selection == clipboard->clipboard && event->target == target;
|
|
142
|
+
bool received = event->property != XCB_NONE;
|
|
143
|
+
free(event);
|
|
144
|
+
if (!matches) continue;
|
|
145
|
+
if (!received) return true; // No owner, or the owner does not offer this target.
|
|
146
|
+
if (!read_property(clipboard, false, result)) return false;
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
if (result->type != clipboard->incr) return true;
|
|
150
|
+
|
|
151
|
+
free(result->data);
|
|
152
|
+
memset(result, 0, sizeof(*result));
|
|
153
|
+
xcb_delete_property(clipboard->connection, clipboard->window, clipboard->property);
|
|
154
|
+
|
|
155
|
+
while (true) {
|
|
156
|
+
xcb_property_notify_event_t* event = (xcb_property_notify_event_t*)wait_for_event(clipboard, XCB_PROPERTY_NOTIFY);
|
|
157
|
+
if (!event) return false;
|
|
158
|
+
bool matches = event->atom == clipboard->property && event->state == XCB_PROPERTY_NEW_VALUE;
|
|
159
|
+
free(event);
|
|
160
|
+
if (!matches) continue;
|
|
161
|
+
|
|
162
|
+
property_data chunk = {0};
|
|
163
|
+
if (!read_property(clipboard, true, &chunk)) return false;
|
|
164
|
+
bool appended = append_property(result, &chunk);
|
|
165
|
+
bool finished = chunk.items == 0;
|
|
166
|
+
free(chunk.data);
|
|
167
|
+
if (!appended) return false;
|
|
168
|
+
if (finished) return true;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
static xcb_atom_t intern_atom(x11_clipboard* clipboard, const char* name) {
|
|
173
|
+
xcb_intern_atom_cookie_t cookie = xcb_intern_atom(clipboard->connection, false, strlen(name), name);
|
|
174
|
+
xcb_intern_atom_reply_t* reply = wait_for_reply(clipboard, cookie.sequence);
|
|
175
|
+
if (!reply) return XCB_NONE;
|
|
176
|
+
xcb_atom_t atom = reply->atom;
|
|
177
|
+
free(reply);
|
|
178
|
+
return atom;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
static bool open_clipboard(x11_clipboard* clipboard) {
|
|
182
|
+
memset(clipboard, 0, sizeof(*clipboard));
|
|
183
|
+
clipboard->deadline = monotonic_ms() + CLIPBOARD_TIMEOUT_MS;
|
|
184
|
+
int screen_number = 0;
|
|
185
|
+
clipboard->connection = xcb_connect(0, &screen_number);
|
|
186
|
+
if (xcb_connection_has_error(clipboard->connection)) return false;
|
|
187
|
+
xcb_screen_iterator_t screens = xcb_setup_roots_iterator(xcb_get_setup(clipboard->connection));
|
|
188
|
+
while (screen_number-- > 0 && screens.rem) xcb_screen_next(&screens);
|
|
189
|
+
if (!screens.rem) return false;
|
|
190
|
+
|
|
191
|
+
clipboard->window = xcb_generate_id(clipboard->connection);
|
|
192
|
+
uint32_t mask = XCB_EVENT_MASK_PROPERTY_CHANGE;
|
|
193
|
+
xcb_create_window(
|
|
194
|
+
clipboard->connection, XCB_COPY_FROM_PARENT, clipboard->window,
|
|
195
|
+
screens.data->root, 0, 0, 1, 1, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT,
|
|
196
|
+
XCB_COPY_FROM_PARENT, XCB_CW_EVENT_MASK, &mask
|
|
197
|
+
);
|
|
198
|
+
clipboard->clipboard = intern_atom(clipboard, "CLIPBOARD");
|
|
199
|
+
clipboard->property = intern_atom(clipboard, "PI_CLIPBOARD");
|
|
200
|
+
clipboard->targets = intern_atom(clipboard, "TARGETS");
|
|
201
|
+
clipboard->incr = intern_atom(clipboard, "INCR");
|
|
202
|
+
return clipboard->clipboard && clipboard->property && clipboard->targets && clipboard->incr;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
static void close_clipboard(x11_clipboard* clipboard) {
|
|
206
|
+
if (clipboard->connection) xcb_disconnect(clipboard->connection);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
static bool preferred_target(x11_clipboard* clipboard, bool image, xcb_atom_t* target) {
|
|
210
|
+
const char* const* types = image ? image_types : text_types;
|
|
211
|
+
size_t type_count = image ? 6 : 5;
|
|
212
|
+
xcb_atom_t wanted[6];
|
|
213
|
+
for (size_t index = 0; index < type_count; index++) {
|
|
214
|
+
wanted[index] = intern_atom(clipboard, types[index]);
|
|
215
|
+
if (wanted[index] == XCB_NONE) return false;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
property_data targets = {0};
|
|
219
|
+
bool received = request_selection(clipboard, clipboard->targets, &targets);
|
|
220
|
+
bool valid = targets.type == XCB_ATOM_ATOM && targets.format == 32 &&
|
|
221
|
+
targets.items == targets.length / sizeof(xcb_atom_t) && targets.length % sizeof(xcb_atom_t) == 0;
|
|
222
|
+
if (received && valid) {
|
|
223
|
+
xcb_atom_t* offered = (xcb_atom_t*)targets.data;
|
|
224
|
+
for (size_t wanted_index = 0; wanted_index < type_count; wanted_index++) {
|
|
225
|
+
for (uint32_t offered_index = 0; offered_index < targets.items; offered_index++) {
|
|
226
|
+
if (offered[offered_index] == wanted[wanted_index]) {
|
|
227
|
+
free(targets.data);
|
|
228
|
+
*target = wanted[wanted_index];
|
|
229
|
+
return true;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
free(targets.data);
|
|
235
|
+
// Some owners refuse TARGETS but still serve text directly.
|
|
236
|
+
if (received && !image && targets.type == XCB_NONE) {
|
|
237
|
+
*target = intern_atom(clipboard, "UTF8_STRING");
|
|
238
|
+
return *target != XCB_NONE;
|
|
239
|
+
}
|
|
240
|
+
return received && (valid || targets.type == XCB_NONE);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
static bool read_selection(x11_clipboard* clipboard, bool image, property_data* result) {
|
|
244
|
+
xcb_atom_t target = XCB_NONE;
|
|
245
|
+
bool received = preferred_target(clipboard, image, &target) &&
|
|
246
|
+
(target == XCB_NONE || request_selection(clipboard, target, result));
|
|
247
|
+
if (!received) {
|
|
248
|
+
free(result->data);
|
|
249
|
+
memset(result, 0, sizeof(*result));
|
|
250
|
+
}
|
|
251
|
+
return received;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
static void read_clipboard(clipboard_job* job) {
|
|
255
|
+
x11_clipboard clipboard;
|
|
256
|
+
if (open_clipboard(&clipboard)) {
|
|
257
|
+
property_data contents = {0};
|
|
258
|
+
if (!read_selection(&clipboard, job->operation == CLIPBOARD_IMAGE, &contents)) {
|
|
259
|
+
job->error = "Could not read X11 clipboard";
|
|
260
|
+
} else {
|
|
261
|
+
job->data = contents.data;
|
|
262
|
+
job->length = contents.length;
|
|
263
|
+
job->format = !contents.data ? CLIPBOARD_EMPTY : job->operation == CLIPBOARD_IMAGE
|
|
264
|
+
? CLIPBOARD_BUFFER : contents.type == XCB_ATOM_STRING ? CLIPBOARD_LATIN1 : CLIPBOARD_UTF8;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
close_clipboard(&clipboard);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
PI_NAPI_EXPORT napi_value napi_register_module_v1(napi_env env, napi_value exports) {
|
|
271
|
+
set_function_export(env, exports, "getText", get_clipboard_text);
|
|
272
|
+
set_function_export(env, exports, "getImage", get_clipboard_image);
|
|
273
|
+
return exports;
|
|
274
|
+
}
|
package/native/napi.h
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
#ifndef PI_NAPI_H
|
|
2
|
+
#define PI_NAPI_H
|
|
3
|
+
|
|
4
|
+
// Resolve the small N-API surface we use from Node or Bun, without Node headers
|
|
5
|
+
// or a link-time dependency on a particular runtime.
|
|
6
|
+
#include <stdbool.h>
|
|
7
|
+
#include <stddef.h>
|
|
8
|
+
#include <stdint.h>
|
|
9
|
+
#ifdef _WIN32
|
|
10
|
+
#include <windows.h>
|
|
11
|
+
#define PI_NAPI_CALL __cdecl
|
|
12
|
+
#define PI_NAPI_EXPORT __declspec(dllexport)
|
|
13
|
+
#else
|
|
14
|
+
#include <dlfcn.h>
|
|
15
|
+
#define PI_NAPI_CALL
|
|
16
|
+
#define PI_NAPI_EXPORT __attribute__((visibility("default")))
|
|
17
|
+
#endif
|
|
18
|
+
|
|
19
|
+
#define NAPI_AUTO_LENGTH ((size_t)-1)
|
|
20
|
+
|
|
21
|
+
typedef void* napi_env;
|
|
22
|
+
typedef void* napi_value;
|
|
23
|
+
typedef void* napi_callback_info;
|
|
24
|
+
typedef void* napi_async_work;
|
|
25
|
+
typedef void* napi_deferred;
|
|
26
|
+
typedef void (PI_NAPI_CALL *napi_async_execute_callback)(napi_env, void*);
|
|
27
|
+
typedef void (PI_NAPI_CALL *napi_async_complete_callback)(napi_env, int, void*);
|
|
28
|
+
typedef int (PI_NAPI_CALL *napi_create_async_work_fn)(napi_env, napi_value, napi_value, napi_async_execute_callback, napi_async_complete_callback, void*, napi_async_work*);
|
|
29
|
+
typedef int (PI_NAPI_CALL *napi_async_work_fn)(napi_env, napi_async_work);
|
|
30
|
+
typedef int (PI_NAPI_CALL *napi_create_promise_fn)(napi_env, napi_deferred*, napi_value*);
|
|
31
|
+
typedef int (PI_NAPI_CALL *napi_settle_deferred_fn)(napi_env, napi_deferred, napi_value);
|
|
32
|
+
typedef int (PI_NAPI_CALL *napi_create_error_fn)(napi_env, napi_value, napi_value, napi_value*);
|
|
33
|
+
typedef napi_value (PI_NAPI_CALL *napi_callback)(napi_env, napi_callback_info);
|
|
34
|
+
typedef int (PI_NAPI_CALL *napi_create_buffer_copy_fn)(napi_env, size_t, const void*, void**, napi_value*);
|
|
35
|
+
typedef int (PI_NAPI_CALL *napi_create_function_fn)(napi_env, const char*, size_t, napi_callback, void*, napi_value*);
|
|
36
|
+
typedef int (PI_NAPI_CALL *napi_create_string_utf8_fn)(napi_env, const char*, size_t, napi_value*);
|
|
37
|
+
typedef int (PI_NAPI_CALL *napi_create_string_utf16_fn)(napi_env, const uint16_t*, size_t, napi_value*);
|
|
38
|
+
typedef int (PI_NAPI_CALL *napi_get_boolean_fn)(napi_env, bool, napi_value*);
|
|
39
|
+
typedef int (PI_NAPI_CALL *napi_get_cb_info_fn)(napi_env, napi_callback_info, size_t*, napi_value*, napi_value*, void**);
|
|
40
|
+
typedef int (PI_NAPI_CALL *napi_get_value_fn)(napi_env, napi_value*);
|
|
41
|
+
typedef int (PI_NAPI_CALL *napi_get_value_string_utf8_fn)(napi_env, napi_value, char*, size_t, size_t*);
|
|
42
|
+
typedef int (PI_NAPI_CALL *napi_get_value_string_utf16_fn)(napi_env, napi_value, uint16_t*, size_t, size_t*);
|
|
43
|
+
typedef int (PI_NAPI_CALL *napi_set_named_property_fn)(napi_env, napi_value, const char*, napi_value);
|
|
44
|
+
typedef int (PI_NAPI_CALL *napi_throw_error_fn)(napi_env, const char*, const char*);
|
|
45
|
+
|
|
46
|
+
static void* node_symbol(const char* name) {
|
|
47
|
+
#ifdef _WIN32
|
|
48
|
+
HMODULE module = GetModuleHandleA(0);
|
|
49
|
+
void* proc = module ? (void*)GetProcAddress(module, name) : 0;
|
|
50
|
+
if (proc) return proc;
|
|
51
|
+
module = GetModuleHandleA("node.dll");
|
|
52
|
+
return module ? (void*)GetProcAddress(module, name) : 0;
|
|
53
|
+
#else
|
|
54
|
+
return dlsym(RTLD_DEFAULT, name);
|
|
55
|
+
#endif
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
static napi_value undefined_value(napi_env env) {
|
|
59
|
+
napi_get_value_fn get_value = (napi_get_value_fn)node_symbol("napi_get_undefined");
|
|
60
|
+
napi_value result = 0;
|
|
61
|
+
if (get_value) get_value(env, &result);
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
static napi_value null_value(napi_env env) {
|
|
66
|
+
napi_get_value_fn get_value = (napi_get_value_fn)node_symbol("napi_get_null");
|
|
67
|
+
napi_value result = 0;
|
|
68
|
+
if (get_value) get_value(env, &result);
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
static napi_value fail(napi_env env, const char* message) {
|
|
73
|
+
napi_throw_error_fn napi_throw_error = (napi_throw_error_fn)node_symbol("napi_throw_error");
|
|
74
|
+
if (napi_throw_error) napi_throw_error(env, 0, message);
|
|
75
|
+
return undefined_value(env);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
static void set_function_export(napi_env env, napi_value exports, const char* name, napi_callback callback) {
|
|
79
|
+
napi_create_function_fn napi_create_function = (napi_create_function_fn)node_symbol("napi_create_function");
|
|
80
|
+
napi_set_named_property_fn napi_set_named_property =
|
|
81
|
+
(napi_set_named_property_fn)node_symbol("napi_set_named_property");
|
|
82
|
+
napi_value fn = 0;
|
|
83
|
+
if (napi_create_function && napi_set_named_property &&
|
|
84
|
+
napi_create_function(env, name, NAPI_AUTO_LENGTH, callback, 0, &fn) == 0) {
|
|
85
|
+
napi_set_named_property(env, exports, name, fn);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
#endif
|
package/native/win32/README.md
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
# Windows native prebuilds
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Provides console input setup, modifier-key state, and asynchronous text/image clipboard access. Links to `kernel32` and `user32`; no Node headers are required.
|
|
4
|
+
|
|
5
|
+
## Building
|
|
6
|
+
|
|
7
|
+
On Windows, install Visual Studio's "Desktop development with C++" workload, then run from the repository root to build x64 and arm64:
|
|
4
8
|
|
|
5
9
|
```sh
|
|
6
10
|
bun run --cwd packages/tui build:native:win32
|
|
7
11
|
```
|
|
8
12
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
Install the "Desktop development with C++" workload, or at minimum the MSVC toolset and Windows SDK components. No Node headers are required; the addon resolves N-API symbols from the host process.
|
|
12
|
-
|
|
13
|
-
For non-Windows cross-builds, or for custom Windows toolchains, set `PI_TUI_WIN32_TOOLCHAIN=mingw` and provide MinGW-compatible compilers:
|
|
13
|
+
For cross-builds or custom toolchains, provide MinGW-compatible compilers:
|
|
14
14
|
|
|
15
15
|
```sh
|
|
16
16
|
PI_TUI_WIN32_TOOLCHAIN=mingw \
|
|
@@ -19,4 +19,15 @@ CC_ARM64=/path/to/aarch64-w64-mingw32-gcc \
|
|
|
19
19
|
bun run --cwd packages/tui build:native:win32
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
## Testing clipboard writes
|
|
23
|
+
|
|
24
|
+
On a Windows test desktop, run from `packages/tui` in PowerShell:
|
|
25
|
+
|
|
26
|
+
```powershell
|
|
27
|
+
$env:PI_TEST_NATIVE_CLIPBOARD = "1"
|
|
28
|
+
node --test test/native-platform.test.ts
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
This opt-in test checks native text writes and reads. **It replaces the system clipboard contents.**
|
|
32
|
+
|
|
33
|
+
The opt-in clipboard test only runs on a real Windows desktop session. Cross-builds from macOS or Linux hosts produce the addon but cannot exercise it, and the `windows-latest` runners in `.github/workflows/native-prebuilds.yml` build the prebuilds without running this clipboard test. Treat Windows clipboard behavior as verified only when someone has run the test above on Windows.
|
package/native/win32/build.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import * as path from "node:path";
|
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
6
|
|
|
7
7
|
const scriptDir = path.dirname(fileURLToPath(import.meta.url));
|
|
8
|
-
const sourceFile = path.join(scriptDir, "src", "win32-
|
|
8
|
+
const sourceFile = path.join(scriptDir, "src", "win32-platform.c");
|
|
9
9
|
const temporaryDir = mkdtempSync(path.join(tmpdir(), "pi-tui-win32-"));
|
|
10
10
|
|
|
11
11
|
const targets = [
|
|
@@ -121,7 +121,7 @@ function resolveMingwCompiler(target) {
|
|
|
121
121
|
function installOutput(temporaryOutput, target) {
|
|
122
122
|
const outputDir = path.join(scriptDir, "prebuilds", `win32-${target.arch}`);
|
|
123
123
|
mkdirSync(outputDir, { recursive: true });
|
|
124
|
-
const output = path.join(outputDir, "win32-
|
|
124
|
+
const output = path.join(outputDir, "win32-platform.node");
|
|
125
125
|
copyFileSync(temporaryOutput, output);
|
|
126
126
|
chmodSync(output, 0o755);
|
|
127
127
|
console.log(`Built ${path.relative(process.cwd(), output)}`);
|
|
@@ -129,7 +129,7 @@ function installOutput(temporaryOutput, target) {
|
|
|
129
129
|
|
|
130
130
|
function buildWithMsvc(target, vsDevCmd) {
|
|
131
131
|
const buildDir = path.join(temporaryDir, `msvc-${target.arch}`);
|
|
132
|
-
const temporaryOutput = path.join(buildDir, "win32-
|
|
132
|
+
const temporaryOutput = path.join(buildDir, "win32-platform.node");
|
|
133
133
|
mkdirSync(buildDir, { recursive: true });
|
|
134
134
|
|
|
135
135
|
const batchFile = path.join(buildDir, "build.cmd");
|
|
@@ -154,6 +154,7 @@ function buildWithMsvc(target, vsDevCmd) {
|
|
|
154
154
|
"/NOENTRY",
|
|
155
155
|
"/NODEFAULTLIB",
|
|
156
156
|
"kernel32.lib",
|
|
157
|
+
"user32.lib",
|
|
157
158
|
"/OPT:REF",
|
|
158
159
|
"/OPT:ICF",
|
|
159
160
|
].join(" "),
|
|
@@ -174,7 +175,7 @@ function buildWithMingw(target) {
|
|
|
174
175
|
}
|
|
175
176
|
|
|
176
177
|
const buildDir = path.join(temporaryDir, `mingw-${target.arch}`);
|
|
177
|
-
const temporaryOutput = path.join(buildDir, "win32-
|
|
178
|
+
const temporaryOutput = path.join(buildDir, "win32-platform.node");
|
|
178
179
|
mkdirSync(buildDir, { recursive: true });
|
|
179
180
|
|
|
180
181
|
const args = [
|
|
@@ -183,12 +184,14 @@ function buildWithMingw(target) {
|
|
|
183
184
|
"-Wall",
|
|
184
185
|
"-Wextra",
|
|
185
186
|
"-Oz",
|
|
187
|
+
"-fno-builtin",
|
|
186
188
|
"-shared",
|
|
187
189
|
"-nostdlib",
|
|
188
190
|
"-Wl,--no-entry",
|
|
189
191
|
"-Wl,--strip-all",
|
|
190
192
|
sourceFile,
|
|
191
193
|
"-lkernel32",
|
|
194
|
+
"-luser32",
|
|
192
195
|
"-o",
|
|
193
196
|
temporaryOutput,
|
|
194
197
|
];
|
|
Binary file
|
|
Binary file
|