@code-yeongyu/senpi-tui 2026.9.12-3 → 2026.9.12

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.
Files changed (94) hide show
  1. package/README.md +4 -53
  2. package/dist/alt-screen-search.d.ts +1 -21
  3. package/dist/alt-screen-search.d.ts.map +1 -1
  4. package/dist/alt-screen-search.js +42 -199
  5. package/dist/alt-screen-search.js.map +1 -1
  6. package/dist/components/box.d.ts +1 -3
  7. package/dist/components/box.d.ts.map +1 -1
  8. package/dist/components/box.js +0 -28
  9. package/dist/components/box.js.map +1 -1
  10. package/dist/components/editor.d.ts +1 -6
  11. package/dist/components/editor.d.ts.map +1 -1
  12. package/dist/components/editor.js +18 -98
  13. package/dist/components/editor.js.map +1 -1
  14. package/dist/components/input.d.ts +1 -12
  15. package/dist/components/input.d.ts.map +1 -1
  16. package/dist/components/input.js +6 -40
  17. package/dist/components/input.js.map +1 -1
  18. package/dist/components/latex.d.ts.map +1 -1
  19. package/dist/components/latex.js +0 -7
  20. package/dist/components/latex.js.map +1 -1
  21. package/dist/components/loader.d.ts +0 -3
  22. package/dist/components/loader.d.ts.map +1 -1
  23. package/dist/components/loader.js +8 -20
  24. package/dist/components/loader.js.map +1 -1
  25. package/dist/components/scroll-view.d.ts +3 -6
  26. package/dist/components/scroll-view.d.ts.map +1 -1
  27. package/dist/components/scroll-view.js +1 -6
  28. package/dist/components/scroll-view.js.map +1 -1
  29. package/dist/components/select-list.d.ts +1 -4
  30. package/dist/components/select-list.d.ts.map +1 -1
  31. package/dist/components/select-list.js +2 -48
  32. package/dist/components/select-list.js.map +1 -1
  33. package/dist/components/settings-list.d.ts +1 -5
  34. package/dist/components/settings-list.d.ts.map +1 -1
  35. package/dist/components/settings-list.js +5 -54
  36. package/dist/components/settings-list.js.map +1 -1
  37. package/dist/index.d.ts +1 -3
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +0 -3
  40. package/dist/index.js.map +1 -1
  41. package/dist/layout.d.ts +1 -3
  42. package/dist/layout.d.ts.map +1 -1
  43. package/dist/layout.js +9 -32
  44. package/dist/layout.js.map +1 -1
  45. package/dist/native-modifiers.d.ts +1 -2
  46. package/dist/native-modifiers.d.ts.map +1 -1
  47. package/dist/native-modifiers.js +44 -3
  48. package/dist/native-modifiers.js.map +1 -1
  49. package/dist/terminal.d.ts.map +1 -1
  50. package/dist/terminal.js +20 -2
  51. package/dist/terminal.js.map +1 -1
  52. package/dist/tui-alt-screen.d.ts +1 -31
  53. package/dist/tui-alt-screen.d.ts.map +1 -1
  54. package/dist/tui-alt-screen.js +41 -335
  55. package/dist/tui-alt-screen.js.map +1 -1
  56. package/dist/tui.d.ts +5 -83
  57. package/dist/tui.d.ts.map +1 -1
  58. package/dist/tui.js +4 -118
  59. package/dist/tui.js.map +1 -1
  60. package/dist/utils.d.ts +0 -2
  61. package/dist/utils.d.ts.map +1 -1
  62. package/dist/utils.js +0 -9
  63. package/dist/utils.js.map +1 -1
  64. package/native/darwin/README.md +6 -8
  65. package/native/darwin/build.sh +5 -12
  66. package/native/darwin/prebuilds/darwin-arm64/{darwin-platform.node → darwin-modifiers.node} +0 -0
  67. package/native/darwin/prebuilds/darwin-x64/{darwin-platform.node → darwin-modifiers.node} +0 -0
  68. package/native/darwin/src/darwin-modifiers.c +70 -0
  69. package/native/win32/README.md +7 -18
  70. package/native/win32/build.mjs +4 -7
  71. package/native/win32/prebuilds/win32-arm64/win32-console-mode.node +0 -0
  72. package/native/win32/prebuilds/win32-x64/win32-console-mode.node +0 -0
  73. package/native/win32/src/win32-console-mode.c +119 -0
  74. package/package.json +3 -10
  75. package/dist/components/mouse-region.d.ts +0 -12
  76. package/dist/components/mouse-region.d.ts.map +0 -1
  77. package/dist/components/mouse-region.js +0 -19
  78. package/dist/components/mouse-region.js.map +0 -1
  79. package/dist/native-platform.d.ts +0 -18
  80. package/dist/native-platform.d.ts.map +0 -1
  81. package/dist/native-platform.js +0 -42
  82. package/dist/native-platform.js.map +0 -1
  83. package/native/clipboard.h +0 -170
  84. package/native/darwin/src/darwin-platform.m +0 -93
  85. package/native/linux/README.md +0 -23
  86. package/native/linux/build.sh +0 -65
  87. package/native/linux/prebuilds/linux-arm64/linux-platform-x11.node +0 -0
  88. package/native/linux/prebuilds/linux-x64/linux-platform-x11.node +0 -0
  89. package/native/linux/src/clipboard-worker.h +0 -70
  90. package/native/linux/src/linux-platform-x11.c +0 -274
  91. package/native/napi.h +0 -89
  92. package/native/win32/prebuilds/win32-arm64/win32-platform.node +0 -0
  93. package/native/win32/prebuilds/win32-x64/win32-platform.node +0 -0
  94. package/native/win32/src/win32-platform.c +0 -241
@@ -1,23 +0,0 @@
1
- # Linux clipboard helper
2
-
3
- Provides asynchronous X11 text and image reads using `libxcb.so.1`. Prebuilds support x64 and arm64 on glibc and musl. Reads have bounded waits; if a native operation stalls, the helper remains unavailable until it finishes.
4
-
5
- Coding-agent falls back to command-line tools when native reads are unavailable. Wayland reads use `wl-paste`; all Linux writes use the existing command-line or terminal clipboard paths.
6
-
7
- ## Building
8
-
9
- Install a C compiler and XCB development headers, then run from the repository root on each supported Linux architecture:
10
-
11
- ```sh
12
- bun run --cwd packages/tui build:native:linux
13
- ```
14
-
15
- ## Testing
16
-
17
- Install the build dependencies plus `pkg-config`, `Xvfb`, and `xclip`, then run from `packages/tui`:
18
-
19
- ```sh
20
- node --test test/native-clipboard-linux.test.ts
21
- ```
22
-
23
- Tests use isolated X11 servers, not the desktop clipboard. They skip when dependencies are missing.
@@ -1,65 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- set -euo pipefail
4
-
5
- script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6
- compiler="${CC:-cc}"
7
-
8
- if [[ "$(uname -s)" != "Linux" ]]; then
9
- echo "Linux native helpers must be built on Linux" >&2
10
- exit 1
11
- fi
12
-
13
- case "$(uname -m)" in
14
- x86_64)
15
- arch="x64"
16
- ;;
17
- aarch64|arm64)
18
- arch="arm64"
19
- ;;
20
- *)
21
- echo "Unsupported Linux architecture: $(uname -m)" >&2
22
- exit 1
23
- ;;
24
- esac
25
-
26
- if ! command -v "$compiler" >/dev/null 2>&1; then
27
- echo "Linux C compiler not found: $compiler" >&2
28
- exit 1
29
- fi
30
- build_dir="$(mktemp -d "${TMPDIR:-/tmp}/pi-tui-linux.XXXXXX")"
31
- trap 'rm -rf "$build_dir"' EXIT
32
-
33
- common_flags=(
34
- -std=c11
35
- -D_POSIX_C_SOURCE=200809L
36
- -Wall
37
- -Wextra
38
- -Werror
39
- -Os
40
- -flto
41
- -fPIC
42
- -pthread
43
- -fvisibility=hidden
44
- -fno-stack-protector
45
- -shared
46
- -nostdlib
47
- -Wl,--unresolved-symbols=ignore-all
48
- -Wl,--no-as-needed
49
- -Wl,-O2
50
- -Wl,--gc-sections
51
- # A timed-out private thread may outlive the Node environment that loaded us.
52
- -Wl,-z,nodelete
53
- -Wl,-s
54
- )
55
-
56
- x11_output="$build_dir/linux-platform-x11.node"
57
- "$compiler" "${common_flags[@]}" \
58
- "$script_dir/src/linux-platform-x11.c" \
59
- -lxcb \
60
- -o "$x11_output"
61
-
62
- output_dir="$script_dir/prebuilds/linux-$arch"
63
- mkdir -p "$output_dir"
64
- install -m 755 "$x11_output" "$output_dir/linux-platform-x11.node"
65
- printf 'Built %s\n' "$output_dir/linux-platform-x11.node"
@@ -1,70 +0,0 @@
1
- #include <pthread.h>
2
- #include <time.h>
3
- #include "../../clipboard.h"
4
-
5
- static void read_clipboard(clipboard_job* job);
6
- static pthread_mutex_t worker_mutex = PTHREAD_MUTEX_INITIALIZER;
7
- static pthread_once_t worker_once = PTHREAD_ONCE_INIT;
8
- static pthread_cond_t worker_changed;
9
- static bool worker_ready, worker_busy, worker_waiting, worker_finished;
10
- static clipboard_job worker_result;
11
- static int (*signal_worker)(pthread_cond_t*);
12
- static int (*wait_for_worker)(pthread_cond_t*, pthread_mutex_t*, const struct timespec*);
13
-
14
- static void initialize_worker_condition(void) {
15
- // Unversioned ELF imports otherwise bind obsolete condition variables on glibc x64.
16
- int (*initialize)(pthread_cond_t*, const pthread_condattr_t*) = node_symbol("pthread_cond_init");
17
- signal_worker = node_symbol("pthread_cond_signal");
18
- wait_for_worker = node_symbol("pthread_cond_timedwait");
19
- if (!initialize || !signal_worker || !wait_for_worker) return;
20
- pthread_condattr_t attributes;
21
- if (pthread_condattr_init(&attributes) != 0) return;
22
- worker_ready = pthread_condattr_setclock(&attributes, CLOCK_MONOTONIC) == 0 &&
23
- initialize(&worker_changed, &attributes) == 0;
24
- pthread_condattr_destroy(&attributes);
25
- }
26
-
27
- static void* read_on_private_thread(void* unused) {
28
- (void)unused;
29
- read_clipboard(&worker_result);
30
- pthread_mutex_lock(&worker_mutex);
31
- worker_finished = true;
32
- if (!worker_waiting) {
33
- free(worker_result.data); // The caller timed out; discard the late result.
34
- worker_busy = false;
35
- }
36
- signal_worker(&worker_changed);
37
- pthread_mutex_unlock(&worker_mutex);
38
- return 0;
39
- }
40
-
41
- static void clipboard_execute(clipboard_job* job) {
42
- pthread_once(&worker_once, initialize_worker_condition);
43
- if (!worker_ready) return;
44
- pthread_mutex_lock(&worker_mutex);
45
- if (!worker_busy) {
46
- worker_busy = worker_waiting = true;
47
- worker_finished = false;
48
- worker_result = (clipboard_job){.operation = job->operation};
49
- struct timespec deadline;
50
- clock_gettime(CLOCK_MONOTONIC, &deadline);
51
- deadline.tv_sec += 3; // Allow the two-second transfer deadline to report its own error first.
52
- pthread_t thread;
53
- if (pthread_create(&thread, 0, read_on_private_thread, 0) == 0) {
54
- pthread_detach(thread);
55
- // Only this bounded wait occupies libuv. Other callers return unavailable.
56
- while (!worker_finished && wait_for_worker(&worker_changed, &worker_mutex, &deadline) == 0) {}
57
- if (worker_finished) {
58
- job->data = worker_result.data;
59
- job->length = worker_result.length;
60
- job->format = worker_result.format;
61
- job->error = worker_result.error;
62
- worker_busy = false;
63
- }
64
- } else {
65
- worker_busy = false;
66
- }
67
- worker_waiting = false;
68
- }
69
- pthread_mutex_unlock(&worker_mutex);
70
- }
@@ -1,274 +0,0 @@
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 DELETED
@@ -1,89 +0,0 @@
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