@opentui/core 0.0.0-20250930-a8fe63ce → 0.0.0-20250930-d50102aa
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/3d.js +5 -3
- package/3d.js.map +2 -2
- package/{index-h87jjatk.js → index-0p8687g8.js} +167 -224
- package/{index-h87jjatk.js.map → index-0p8687g8.js.map} +7 -8
- package/index-cc14z67g.js +3846 -0
- package/index-cc14z67g.js.map +12 -0
- package/index.js +3 -2
- package/index.js.map +2 -2
- package/lib/tree-sitter/client.d.ts +2 -0
- package/lib/tree-sitter/default-parsers.d.ts +1 -1
- package/lib/tree-sitter/parser.worker.d.ts +1 -55
- package/package.json +12 -7
- package/parser.worker.d.ts +1 -0
- package/parser.worker.js +5 -0
- package/parser.worker.js.map +9 -0
- package/testing.js +3 -2
- package/testing.js.map +2 -2
|
@@ -1,31 +1,10 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
9
|
-
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
10
|
-
for (let key of __getOwnPropNames(mod))
|
|
11
|
-
if (!__hasOwnProp.call(to, key))
|
|
12
|
-
__defProp(to, key, {
|
|
13
|
-
get: () => mod[key],
|
|
14
|
-
enumerable: true
|
|
15
|
-
});
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
19
|
-
var __export = (target, all) => {
|
|
20
|
-
for (var name in all)
|
|
21
|
-
__defProp(target, name, {
|
|
22
|
-
get: all[name],
|
|
23
|
-
enumerable: true,
|
|
24
|
-
configurable: true,
|
|
25
|
-
set: (newValue) => all[name] = () => newValue
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
|
-
var __require = import.meta.require;
|
|
2
|
+
import {
|
|
3
|
+
DownloadUtils,
|
|
4
|
+
__export,
|
|
5
|
+
__require,
|
|
6
|
+
parser_worker_default
|
|
7
|
+
} from "./index-cc14z67g.js";
|
|
29
8
|
|
|
30
9
|
// ../../node_modules/yoga-layout/dist/src/index.js
|
|
31
10
|
var exports_src = {};
|
|
@@ -1763,7 +1742,7 @@ var BorderCharArrays = {
|
|
|
1763
1742
|
};
|
|
1764
1743
|
|
|
1765
1744
|
// src/lib/parse.keypress.ts
|
|
1766
|
-
import { Buffer
|
|
1745
|
+
import { Buffer } from "buffer";
|
|
1767
1746
|
|
|
1768
1747
|
// src/lib/parse.keypress-kitty.ts
|
|
1769
1748
|
var kittyKeyMap = {
|
|
@@ -2080,7 +2059,7 @@ var isCtrlKey = (code) => {
|
|
|
2080
2059
|
};
|
|
2081
2060
|
var parseKeypress = (s = "", options = {}) => {
|
|
2082
2061
|
let parts;
|
|
2083
|
-
if (
|
|
2062
|
+
if (Buffer.isBuffer(s)) {
|
|
2084
2063
|
if (s[0] > 127 && s[1] === undefined) {
|
|
2085
2064
|
s[0] -= 128;
|
|
2086
2065
|
s = "\x1B" + String(s);
|
|
@@ -5282,6 +5261,10 @@ class ProcessQueue {
|
|
|
5282
5261
|
}
|
|
5283
5262
|
}
|
|
5284
5263
|
|
|
5264
|
+
// src/lib/tree-sitter/default-parsers.ts
|
|
5265
|
+
import { resolve, dirname } from "path";
|
|
5266
|
+
import { fileURLToPath } from "url";
|
|
5267
|
+
|
|
5285
5268
|
// src/lib/tree-sitter/assets/javascript/highlights.scm
|
|
5286
5269
|
var highlights_default = "./highlights-ghv9g403.scm";
|
|
5287
5270
|
|
|
@@ -5295,32 +5278,39 @@ var highlights_default2 = "./highlights-eq9cgrbb.scm";
|
|
|
5295
5278
|
var tree_sitter_typescript_default = "./tree-sitter-typescript-zxjzwt75.wasm";
|
|
5296
5279
|
|
|
5297
5280
|
// src/lib/tree-sitter/default-parsers.ts
|
|
5298
|
-
var
|
|
5299
|
-
|
|
5300
|
-
|
|
5301
|
-
|
|
5302
|
-
|
|
5303
|
-
|
|
5304
|
-
|
|
5305
|
-
|
|
5306
|
-
|
|
5307
|
-
|
|
5308
|
-
|
|
5309
|
-
|
|
5310
|
-
|
|
5311
|
-
|
|
5281
|
+
var _cachedParsers;
|
|
5282
|
+
function getParsers() {
|
|
5283
|
+
if (!_cachedParsers) {
|
|
5284
|
+
_cachedParsers = [
|
|
5285
|
+
{
|
|
5286
|
+
filetype: "javascript",
|
|
5287
|
+
queries: {
|
|
5288
|
+
highlights: [resolve(dirname(fileURLToPath(import.meta.url)), highlights_default)]
|
|
5289
|
+
},
|
|
5290
|
+
wasm: resolve(dirname(fileURLToPath(import.meta.url)), tree_sitter_javascript_default)
|
|
5291
|
+
},
|
|
5292
|
+
{
|
|
5293
|
+
filetype: "typescript",
|
|
5294
|
+
queries: {
|
|
5295
|
+
highlights: [resolve(dirname(fileURLToPath(import.meta.url)), highlights_default2)]
|
|
5296
|
+
},
|
|
5297
|
+
wasm: resolve(dirname(fileURLToPath(import.meta.url)), tree_sitter_typescript_default)
|
|
5298
|
+
}
|
|
5299
|
+
];
|
|
5312
5300
|
}
|
|
5313
|
-
|
|
5301
|
+
return _cachedParsers;
|
|
5302
|
+
}
|
|
5314
5303
|
|
|
5315
5304
|
// src/lib/tree-sitter/client.ts
|
|
5316
|
-
|
|
5305
|
+
import { resolve as resolve2, isAbsolute } from "path";
|
|
5306
|
+
var DEFAULT_PARSERS = getParsers();
|
|
5317
5307
|
function addDefaultParsers(parsers) {
|
|
5318
5308
|
for (const parser of parsers) {
|
|
5319
|
-
const existingIndex =
|
|
5309
|
+
const existingIndex = DEFAULT_PARSERS.findIndex((p) => p.filetype === parser.filetype);
|
|
5320
5310
|
if (existingIndex >= 0) {
|
|
5321
|
-
|
|
5311
|
+
DEFAULT_PARSERS[existingIndex] = parser;
|
|
5322
5312
|
} else {
|
|
5323
|
-
|
|
5313
|
+
DEFAULT_PARSERS.push(parser);
|
|
5324
5314
|
}
|
|
5325
5315
|
}
|
|
5326
5316
|
}
|
|
@@ -5342,13 +5332,32 @@ class TreeSitterClient extends EventEmitter2 {
|
|
|
5342
5332
|
this.debouncer = createDebounce("tree-sitter-client");
|
|
5343
5333
|
this.startWorker();
|
|
5344
5334
|
}
|
|
5335
|
+
emitError(error, bufferId) {
|
|
5336
|
+
if (this.listenerCount("error") > 0) {
|
|
5337
|
+
this.emit("error", error, bufferId);
|
|
5338
|
+
}
|
|
5339
|
+
}
|
|
5340
|
+
emitWarning(warning, bufferId) {
|
|
5341
|
+
if (this.listenerCount("warning") > 0) {
|
|
5342
|
+
this.emit("warning", warning, bufferId);
|
|
5343
|
+
}
|
|
5344
|
+
}
|
|
5345
5345
|
startWorker() {
|
|
5346
5346
|
if (this.worker) {
|
|
5347
5347
|
return;
|
|
5348
5348
|
}
|
|
5349
|
-
const workerPath = this.options.workerPath ||
|
|
5349
|
+
const workerPath = this.options.workerPath || parser_worker_default;
|
|
5350
5350
|
this.worker = new Worker(workerPath);
|
|
5351
5351
|
this.worker.onmessage = this.handleWorkerMessage.bind(this);
|
|
5352
|
+
this.worker.onerror = (error) => {
|
|
5353
|
+
console.error("TreeSitter worker error:", error.message);
|
|
5354
|
+
if (this.initializeResolvers) {
|
|
5355
|
+
clearTimeout(this.initializeResolvers.timeoutId);
|
|
5356
|
+
this.initializeResolvers.reject(new Error(`Worker error: ${error.message}`));
|
|
5357
|
+
this.initializeResolvers = undefined;
|
|
5358
|
+
}
|
|
5359
|
+
this.emitError(`Worker error: ${error.message}`);
|
|
5360
|
+
};
|
|
5352
5361
|
}
|
|
5353
5362
|
stopWorker() {
|
|
5354
5363
|
if (!this.worker) {
|
|
@@ -5369,13 +5378,15 @@ class TreeSitterClient extends EventEmitter2 {
|
|
|
5369
5378
|
if (this.initializePromise) {
|
|
5370
5379
|
return this.initializePromise;
|
|
5371
5380
|
}
|
|
5372
|
-
this.initializePromise = new Promise((
|
|
5381
|
+
this.initializePromise = new Promise((resolve3, reject) => {
|
|
5373
5382
|
const timeoutMs = this.options.initTimeout ?? 1e4;
|
|
5374
5383
|
const timeoutId = setTimeout(() => {
|
|
5384
|
+
const error = new Error("Worker initialization timed out");
|
|
5385
|
+
console.error("TreeSitter client:", error.message);
|
|
5375
5386
|
this.initializeResolvers = undefined;
|
|
5376
|
-
reject(
|
|
5387
|
+
reject(error);
|
|
5377
5388
|
}, timeoutMs);
|
|
5378
|
-
this.initializeResolvers = { resolve, reject, timeoutId };
|
|
5389
|
+
this.initializeResolvers = { resolve: resolve3, reject, timeoutId };
|
|
5379
5390
|
this.worker?.postMessage({
|
|
5380
5391
|
type: "INIT",
|
|
5381
5392
|
dataPath: this.options.dataPath
|
|
@@ -5386,17 +5397,25 @@ class TreeSitterClient extends EventEmitter2 {
|
|
|
5386
5397
|
return this.initializePromise;
|
|
5387
5398
|
}
|
|
5388
5399
|
async registerDefaultParsers() {
|
|
5389
|
-
for (const parser of
|
|
5400
|
+
for (const parser of DEFAULT_PARSERS) {
|
|
5390
5401
|
this.addFiletypeParser(parser);
|
|
5391
5402
|
}
|
|
5392
5403
|
}
|
|
5393
5404
|
addFiletypeParser(filetypeParser) {
|
|
5394
|
-
|
|
5405
|
+
const isUrl = (path) => path.startsWith("http://") || path.startsWith("https://");
|
|
5406
|
+
const resolvedParser = {
|
|
5407
|
+
...filetypeParser,
|
|
5408
|
+
wasm: isUrl(filetypeParser.wasm) || isAbsolute(filetypeParser.wasm) ? filetypeParser.wasm : resolve2(filetypeParser.wasm),
|
|
5409
|
+
queries: {
|
|
5410
|
+
highlights: filetypeParser.queries.highlights.map((path) => isUrl(path) || isAbsolute(path) ? path : resolve2(path))
|
|
5411
|
+
}
|
|
5412
|
+
};
|
|
5413
|
+
this.worker?.postMessage({ type: "ADD_FILETYPE_PARSER", filetypeParser: resolvedParser });
|
|
5395
5414
|
}
|
|
5396
5415
|
async getPerformance() {
|
|
5397
5416
|
const messageId = `performance_${this.messageIdCounter++}`;
|
|
5398
|
-
return new Promise((
|
|
5399
|
-
this.messageCallbacks.set(messageId,
|
|
5417
|
+
return new Promise((resolve3) => {
|
|
5418
|
+
this.messageCallbacks.set(messageId, resolve3);
|
|
5400
5419
|
this.worker?.postMessage({ type: "GET_PERFORMANCE", messageId });
|
|
5401
5420
|
});
|
|
5402
5421
|
}
|
|
@@ -5409,8 +5428,8 @@ class TreeSitterClient extends EventEmitter2 {
|
|
|
5409
5428
|
}
|
|
5410
5429
|
}
|
|
5411
5430
|
const messageId = `oneshot_${this.messageIdCounter++}`;
|
|
5412
|
-
return new Promise((
|
|
5413
|
-
this.messageCallbacks.set(messageId,
|
|
5431
|
+
return new Promise((resolve3) => {
|
|
5432
|
+
this.messageCallbacks.set(messageId, resolve3);
|
|
5414
5433
|
this.worker?.postMessage({
|
|
5415
5434
|
type: "ONESHOT_HIGHLIGHT",
|
|
5416
5435
|
content,
|
|
@@ -5435,6 +5454,7 @@ class TreeSitterClient extends EventEmitter2 {
|
|
|
5435
5454
|
if (this.initializeResolvers) {
|
|
5436
5455
|
clearTimeout(this.initializeResolvers.timeoutId);
|
|
5437
5456
|
if (error) {
|
|
5457
|
+
console.error("TreeSitter client initialization failed:", error);
|
|
5438
5458
|
this.initializeResolvers.reject(new Error(error));
|
|
5439
5459
|
} else {
|
|
5440
5460
|
this.initialized = true;
|
|
@@ -5494,11 +5514,11 @@ class TreeSitterClient extends EventEmitter2 {
|
|
|
5494
5514
|
return;
|
|
5495
5515
|
}
|
|
5496
5516
|
if (warning) {
|
|
5497
|
-
this.
|
|
5517
|
+
this.emitWarning(warning, bufferId);
|
|
5498
5518
|
return;
|
|
5499
5519
|
}
|
|
5500
5520
|
if (error) {
|
|
5501
|
-
this.
|
|
5521
|
+
this.emitError(error, bufferId);
|
|
5502
5522
|
return;
|
|
5503
5523
|
}
|
|
5504
5524
|
if (type === "WORKER_LOG") {
|
|
@@ -5515,8 +5535,8 @@ class TreeSitterClient extends EventEmitter2 {
|
|
|
5515
5535
|
}
|
|
5516
5536
|
async preloadParser(filetype) {
|
|
5517
5537
|
const messageId = `has_parser_${this.messageIdCounter++}`;
|
|
5518
|
-
const response = await new Promise((
|
|
5519
|
-
this.messageCallbacks.set(messageId,
|
|
5538
|
+
const response = await new Promise((resolve3) => {
|
|
5539
|
+
this.messageCallbacks.set(messageId, resolve3);
|
|
5520
5540
|
this.worker?.postMessage({
|
|
5521
5541
|
type: "PRELOAD_PARSER",
|
|
5522
5542
|
filetype,
|
|
@@ -5528,13 +5548,13 @@ class TreeSitterClient extends EventEmitter2 {
|
|
|
5528
5548
|
async createBuffer(id, content, filetype, version = 1, autoInitialize = true) {
|
|
5529
5549
|
if (!this.initialized) {
|
|
5530
5550
|
if (!autoInitialize) {
|
|
5531
|
-
this.
|
|
5551
|
+
this.emitError("Could not create buffer because client is not initialized");
|
|
5532
5552
|
return false;
|
|
5533
5553
|
}
|
|
5534
5554
|
try {
|
|
5535
5555
|
await this.initialize();
|
|
5536
5556
|
} catch (error) {
|
|
5537
|
-
this.
|
|
5557
|
+
this.emitError("Could not create buffer because of initialization error");
|
|
5538
5558
|
return false;
|
|
5539
5559
|
}
|
|
5540
5560
|
}
|
|
@@ -5543,8 +5563,8 @@ class TreeSitterClient extends EventEmitter2 {
|
|
|
5543
5563
|
}
|
|
5544
5564
|
this.buffers.set(id, { id, content, filetype, version, hasParser: false });
|
|
5545
5565
|
const messageId = `init_${this.messageIdCounter++}`;
|
|
5546
|
-
const response = await new Promise((
|
|
5547
|
-
this.messageCallbacks.set(messageId,
|
|
5566
|
+
const response = await new Promise((resolve3) => {
|
|
5567
|
+
this.messageCallbacks.set(messageId, resolve3);
|
|
5548
5568
|
this.worker?.postMessage({
|
|
5549
5569
|
type: "INITIALIZE_PARSER",
|
|
5550
5570
|
bufferId: id,
|
|
@@ -5557,7 +5577,7 @@ class TreeSitterClient extends EventEmitter2 {
|
|
|
5557
5577
|
if (!response.hasParser) {
|
|
5558
5578
|
this.emit("buffer:initialized", id, false);
|
|
5559
5579
|
if (filetype !== "plaintext") {
|
|
5560
|
-
this.
|
|
5580
|
+
this.emitWarning(response.warning || response.error || "Buffer has no parser", id);
|
|
5561
5581
|
}
|
|
5562
5582
|
return false;
|
|
5563
5583
|
}
|
|
@@ -5600,9 +5620,9 @@ class TreeSitterClient extends EventEmitter2 {
|
|
|
5600
5620
|
this.editQueues.delete(bufferId);
|
|
5601
5621
|
}
|
|
5602
5622
|
if (this.worker) {
|
|
5603
|
-
await new Promise((
|
|
5623
|
+
await new Promise((resolve3) => {
|
|
5604
5624
|
const messageId = `dispose_${bufferId}`;
|
|
5605
|
-
this.messageCallbacks.set(messageId,
|
|
5625
|
+
this.messageCallbacks.set(messageId, resolve3);
|
|
5606
5626
|
try {
|
|
5607
5627
|
this.worker.postMessage({
|
|
5608
5628
|
type: "DISPOSE_BUFFER",
|
|
@@ -5610,13 +5630,13 @@ class TreeSitterClient extends EventEmitter2 {
|
|
|
5610
5630
|
});
|
|
5611
5631
|
} catch (error) {
|
|
5612
5632
|
console.error("Error disposing buffer", error);
|
|
5613
|
-
|
|
5633
|
+
resolve3(false);
|
|
5614
5634
|
}
|
|
5615
5635
|
setTimeout(() => {
|
|
5616
5636
|
if (this.messageCallbacks.has(messageId)) {
|
|
5617
5637
|
this.messageCallbacks.delete(messageId);
|
|
5618
5638
|
console.warn({ bufferId }, "Timed out waiting for buffer to be disposed");
|
|
5619
|
-
|
|
5639
|
+
resolve3(false);
|
|
5620
5640
|
}
|
|
5621
5641
|
}, 3000);
|
|
5622
5642
|
});
|
|
@@ -5628,10 +5648,19 @@ class TreeSitterClient extends EventEmitter2 {
|
|
|
5628
5648
|
clearTimeout(this.initializeResolvers.timeoutId);
|
|
5629
5649
|
this.initializeResolvers = undefined;
|
|
5630
5650
|
}
|
|
5651
|
+
for (const [messageId, callback] of this.messageCallbacks.entries()) {
|
|
5652
|
+
if (typeof callback === "function") {
|
|
5653
|
+
try {
|
|
5654
|
+
callback({ error: "Client destroyed" });
|
|
5655
|
+
} catch (e) {}
|
|
5656
|
+
}
|
|
5657
|
+
}
|
|
5658
|
+
this.messageCallbacks.clear();
|
|
5631
5659
|
clearDebounceScope("tree-sitter-client");
|
|
5632
|
-
this.
|
|
5633
|
-
this.buffers.clear();
|
|
5660
|
+
this.debouncer.clear();
|
|
5634
5661
|
this.editQueues.clear();
|
|
5662
|
+
this.buffers.clear();
|
|
5663
|
+
this.stopWorker();
|
|
5635
5664
|
this.initialized = false;
|
|
5636
5665
|
this.initializePromise = undefined;
|
|
5637
5666
|
}
|
|
@@ -5641,7 +5670,7 @@ class TreeSitterClient extends EventEmitter2 {
|
|
|
5641
5670
|
}
|
|
5642
5671
|
const buffer = this.buffers.get(bufferId);
|
|
5643
5672
|
if (!buffer || !buffer.hasParser) {
|
|
5644
|
-
this.
|
|
5673
|
+
this.emitError("Cannot reset buffer with no parser", bufferId);
|
|
5645
5674
|
return;
|
|
5646
5675
|
}
|
|
5647
5676
|
this.buffers.set(bufferId, { ...buffer, content, version });
|
|
@@ -5663,12 +5692,12 @@ class TreeSitterClient extends EventEmitter2 {
|
|
|
5663
5692
|
this.options.dataPath = dataPath;
|
|
5664
5693
|
if (this.initialized && this.worker) {
|
|
5665
5694
|
const messageId = `update_datapath_${this.messageIdCounter++}`;
|
|
5666
|
-
return new Promise((
|
|
5695
|
+
return new Promise((resolve3, reject) => {
|
|
5667
5696
|
this.messageCallbacks.set(messageId, (response) => {
|
|
5668
5697
|
if (response.error) {
|
|
5669
5698
|
reject(new Error(response.error));
|
|
5670
5699
|
} else {
|
|
5671
|
-
|
|
5700
|
+
resolve3();
|
|
5672
5701
|
}
|
|
5673
5702
|
});
|
|
5674
5703
|
this.worker.postMessage({
|
|
@@ -5862,124 +5891,14 @@ function pathToFiletype(path2) {
|
|
|
5862
5891
|
}
|
|
5863
5892
|
|
|
5864
5893
|
// src/lib/tree-sitter/assets/update.ts
|
|
5865
|
-
import { readFile, writeFile
|
|
5866
|
-
import * as path3 from "path";
|
|
5867
|
-
|
|
5868
|
-
// src/lib/tree-sitter/download-utils.ts
|
|
5869
|
-
import { mkdir, writeFile } from "fs/promises";
|
|
5894
|
+
import { readFile, writeFile, mkdir } from "fs/promises";
|
|
5870
5895
|
import * as path2 from "path";
|
|
5871
|
-
|
|
5872
|
-
class DownloadUtils {
|
|
5873
|
-
static hashUrl(url) {
|
|
5874
|
-
let hash = 0;
|
|
5875
|
-
for (let i = 0;i < url.length; i++) {
|
|
5876
|
-
const char = url.charCodeAt(i);
|
|
5877
|
-
hash = (hash << 5) - hash + char;
|
|
5878
|
-
hash = hash & hash;
|
|
5879
|
-
}
|
|
5880
|
-
return Math.abs(hash).toString(16);
|
|
5881
|
-
}
|
|
5882
|
-
static async downloadOrLoad(source, cacheDir, cacheSubdir, fileExtension, useHashForCache = true, filetype) {
|
|
5883
|
-
const isUrl = source.startsWith("http://") || source.startsWith("https://");
|
|
5884
|
-
if (isUrl) {
|
|
5885
|
-
let cacheFileName;
|
|
5886
|
-
if (useHashForCache) {
|
|
5887
|
-
const hash = this.hashUrl(source);
|
|
5888
|
-
cacheFileName = filetype ? `${filetype}-${hash}${fileExtension}` : `${hash}${fileExtension}`;
|
|
5889
|
-
} else {
|
|
5890
|
-
cacheFileName = path2.basename(source);
|
|
5891
|
-
}
|
|
5892
|
-
const cacheFile = path2.join(cacheDir, cacheSubdir, cacheFileName);
|
|
5893
|
-
await mkdir(path2.dirname(cacheFile), { recursive: true });
|
|
5894
|
-
try {
|
|
5895
|
-
const cachedContent = await Bun.file(cacheFile).arrayBuffer();
|
|
5896
|
-
if (cachedContent.byteLength > 0) {
|
|
5897
|
-
console.log(`Loaded from cache: ${cacheFile} (${source})`);
|
|
5898
|
-
return { content: cachedContent, filePath: cacheFile };
|
|
5899
|
-
}
|
|
5900
|
-
} catch (error) {}
|
|
5901
|
-
try {
|
|
5902
|
-
console.log(`Downloading from URL: ${source}`);
|
|
5903
|
-
const response = await fetch(source);
|
|
5904
|
-
if (!response.ok) {
|
|
5905
|
-
return { error: `Failed to fetch from ${source}: ${response.statusText}` };
|
|
5906
|
-
}
|
|
5907
|
-
const content = await response.arrayBuffer();
|
|
5908
|
-
try {
|
|
5909
|
-
await writeFile(cacheFile, Buffer.from(content));
|
|
5910
|
-
console.log(`Cached: ${source}`);
|
|
5911
|
-
} catch (cacheError) {
|
|
5912
|
-
console.warn(`Failed to cache: ${cacheError}`);
|
|
5913
|
-
}
|
|
5914
|
-
return { content, filePath: cacheFile };
|
|
5915
|
-
} catch (error) {
|
|
5916
|
-
return { error: `Error downloading from ${source}: ${error}` };
|
|
5917
|
-
}
|
|
5918
|
-
} else {
|
|
5919
|
-
try {
|
|
5920
|
-
console.log(`Loading from local path: ${source}`);
|
|
5921
|
-
const content = await Bun.file(source).arrayBuffer();
|
|
5922
|
-
return { content, filePath: source };
|
|
5923
|
-
} catch (error) {
|
|
5924
|
-
return { error: `Error loading from local path ${source}: ${error}` };
|
|
5925
|
-
}
|
|
5926
|
-
}
|
|
5927
|
-
}
|
|
5928
|
-
static async downloadToPath(source, targetPath) {
|
|
5929
|
-
const isUrl = source.startsWith("http://") || source.startsWith("https://");
|
|
5930
|
-
await mkdir(path2.dirname(targetPath), { recursive: true });
|
|
5931
|
-
if (isUrl) {
|
|
5932
|
-
try {
|
|
5933
|
-
console.log(`Downloading from URL: ${source}`);
|
|
5934
|
-
const response = await fetch(source);
|
|
5935
|
-
if (!response.ok) {
|
|
5936
|
-
return { error: `Failed to fetch from ${source}: ${response.statusText}` };
|
|
5937
|
-
}
|
|
5938
|
-
const content = await response.arrayBuffer();
|
|
5939
|
-
await writeFile(targetPath, Buffer.from(content));
|
|
5940
|
-
console.log(`Downloaded: ${source} -> ${targetPath}`);
|
|
5941
|
-
return { content, filePath: targetPath };
|
|
5942
|
-
} catch (error) {
|
|
5943
|
-
return { error: `Error downloading from ${source}: ${error}` };
|
|
5944
|
-
}
|
|
5945
|
-
} else {
|
|
5946
|
-
try {
|
|
5947
|
-
console.log(`Copying from local path: ${source}`);
|
|
5948
|
-
const content = await Bun.file(source).arrayBuffer();
|
|
5949
|
-
await writeFile(targetPath, Buffer.from(content));
|
|
5950
|
-
return { content, filePath: targetPath };
|
|
5951
|
-
} catch (error) {
|
|
5952
|
-
return { error: `Error copying from local path ${source}: ${error}` };
|
|
5953
|
-
}
|
|
5954
|
-
}
|
|
5955
|
-
}
|
|
5956
|
-
static async fetchHighlightQueries(sources, cacheDir, filetype) {
|
|
5957
|
-
const queryPromises = sources.map((source) => this.fetchHighlightQuery(source, cacheDir, filetype));
|
|
5958
|
-
const queryResults = await Promise.all(queryPromises);
|
|
5959
|
-
const validQueries = queryResults.filter((query) => query.trim().length > 0);
|
|
5960
|
-
return validQueries.join(`
|
|
5961
|
-
`);
|
|
5962
|
-
}
|
|
5963
|
-
static async fetchHighlightQuery(source, cacheDir, filetype) {
|
|
5964
|
-
const result = await this.downloadOrLoad(source, cacheDir, "queries", ".scm", true, filetype);
|
|
5965
|
-
if (result.error) {
|
|
5966
|
-
console.error(`Error fetching highlight query from ${source}:`, result.error);
|
|
5967
|
-
return "";
|
|
5968
|
-
}
|
|
5969
|
-
if (result.content) {
|
|
5970
|
-
return new TextDecoder().decode(result.content);
|
|
5971
|
-
}
|
|
5972
|
-
return "";
|
|
5973
|
-
}
|
|
5974
|
-
}
|
|
5975
|
-
|
|
5976
|
-
// src/lib/tree-sitter/assets/update.ts
|
|
5977
5896
|
var __dirname = "/Users/runner/work/opentui/opentui/packages/core/src/lib/tree-sitter/assets";
|
|
5978
5897
|
function getDefaultOptions() {
|
|
5979
5898
|
return {
|
|
5980
|
-
configPath:
|
|
5981
|
-
assetsDir:
|
|
5982
|
-
outputPath:
|
|
5899
|
+
configPath: path2.resolve(__dirname, "../parsers-config.json"),
|
|
5900
|
+
assetsDir: path2.resolve(__dirname),
|
|
5901
|
+
outputPath: path2.resolve(__dirname, "../default-parsers.ts")
|
|
5983
5902
|
};
|
|
5984
5903
|
}
|
|
5985
5904
|
async function loadConfig(configPath) {
|
|
@@ -5987,18 +5906,18 @@ async function loadConfig(configPath) {
|
|
|
5987
5906
|
return JSON.parse(configContent);
|
|
5988
5907
|
}
|
|
5989
5908
|
async function downloadLanguage(filetype, languageUrl, assetsDir, outputPath) {
|
|
5990
|
-
const languageDir =
|
|
5991
|
-
const languageFilename =
|
|
5992
|
-
const languagePath =
|
|
5909
|
+
const languageDir = path2.join(assetsDir, filetype);
|
|
5910
|
+
const languageFilename = path2.basename(languageUrl);
|
|
5911
|
+
const languagePath = path2.join(languageDir, languageFilename);
|
|
5993
5912
|
const result = await DownloadUtils.downloadToPath(languageUrl, languagePath);
|
|
5994
5913
|
if (result.error) {
|
|
5995
5914
|
throw new Error(`Failed to download language for ${filetype}: ${result.error}`);
|
|
5996
5915
|
}
|
|
5997
|
-
return "./" +
|
|
5916
|
+
return "./" + path2.relative(path2.dirname(outputPath), languagePath);
|
|
5998
5917
|
}
|
|
5999
5918
|
async function downloadAndCombineQueries(filetype, queryUrls, assetsDir, outputPath) {
|
|
6000
|
-
const queriesDir =
|
|
6001
|
-
const highlightsPath =
|
|
5919
|
+
const queriesDir = path2.join(assetsDir, filetype);
|
|
5920
|
+
const highlightsPath = path2.join(queriesDir, "highlights.scm");
|
|
6002
5921
|
const queryContents = [];
|
|
6003
5922
|
for (let i = 0;i < queryUrls.length; i++) {
|
|
6004
5923
|
const queryUrl = queryUrls[i];
|
|
@@ -6024,9 +5943,9 @@ ${content}`);
|
|
|
6024
5943
|
const combinedContent = queryContents.join(`
|
|
6025
5944
|
|
|
6026
5945
|
`);
|
|
6027
|
-
await
|
|
5946
|
+
await writeFile(highlightsPath, combinedContent, "utf-8");
|
|
6028
5947
|
console.log(` Combined ${queryContents.length} queries into ${highlightsPath}`);
|
|
6029
|
-
return "./" +
|
|
5948
|
+
return "./" + path2.relative(path2.dirname(outputPath), highlightsPath);
|
|
6030
5949
|
}
|
|
6031
5950
|
async function generateDefaultParsersFile(parsers, outputPath) {
|
|
6032
5951
|
const imports = parsers.map((parser) => {
|
|
@@ -6037,13 +5956,13 @@ import ${safeFiletype}_language from "${parser.languagePath}" with { type: "file
|
|
|
6037
5956
|
`);
|
|
6038
5957
|
const parserDefinitions = parsers.map((parser) => {
|
|
6039
5958
|
const safeFiletype = parser.filetype.replace(/[^a-zA-Z0-9]/g, "_");
|
|
6040
|
-
return `
|
|
6041
|
-
|
|
6042
|
-
|
|
6043
|
-
|
|
6044
|
-
|
|
6045
|
-
|
|
6046
|
-
|
|
5959
|
+
return ` {
|
|
5960
|
+
filetype: "${parser.filetype}",
|
|
5961
|
+
queries: {
|
|
5962
|
+
highlights: [resolve(dirname(fileURLToPath(import.meta.url)), ${safeFiletype}_highlights)],
|
|
5963
|
+
},
|
|
5964
|
+
wasm: resolve(dirname(fileURLToPath(import.meta.url)), ${safeFiletype}_language),
|
|
5965
|
+
}`;
|
|
6047
5966
|
}).join(`,
|
|
6048
5967
|
`);
|
|
6049
5968
|
const fileContent = `// This file is generated by assets/update.ts - DO NOT EDIT MANUALLY
|
|
@@ -6051,16 +5970,26 @@ import ${safeFiletype}_language from "${parser.languagePath}" with { type: "file
|
|
|
6051
5970
|
// Last generated: ${new Date().toISOString()}
|
|
6052
5971
|
|
|
6053
5972
|
import type { FiletypeParserOptions } from "./types"
|
|
5973
|
+
import { resolve, dirname } from "path"
|
|
5974
|
+
import { fileURLToPath } from "url"
|
|
6054
5975
|
|
|
6055
5976
|
${imports}
|
|
6056
5977
|
|
|
6057
|
-
|
|
5978
|
+
// Cached parsers to avoid re-resolving paths on every call
|
|
5979
|
+
let _cachedParsers: FiletypeParserOptions[] | undefined
|
|
5980
|
+
|
|
5981
|
+
export function getParsers(): FiletypeParserOptions[] {
|
|
5982
|
+
if (!_cachedParsers) {
|
|
5983
|
+
_cachedParsers = [
|
|
6058
5984
|
${parserDefinitions},
|
|
6059
|
-
]
|
|
5985
|
+
]
|
|
5986
|
+
}
|
|
5987
|
+
return _cachedParsers
|
|
5988
|
+
}
|
|
6060
5989
|
`;
|
|
6061
|
-
await
|
|
6062
|
-
await
|
|
6063
|
-
console.log(`Generated ${
|
|
5990
|
+
await mkdir(path2.dirname(outputPath), { recursive: true });
|
|
5991
|
+
await writeFile(outputPath, fileContent, "utf-8");
|
|
5992
|
+
console.log(`Generated ${path2.basename(outputPath)} with ${parsers.length} parsers`);
|
|
6064
5993
|
}
|
|
6065
5994
|
async function main(options) {
|
|
6066
5995
|
const opts = { ...getDefaultOptions(), ...options };
|
|
@@ -8815,7 +8744,7 @@ function delegate(mapping, vnode) {
|
|
|
8815
8744
|
import { EventEmitter as EventEmitter6 } from "events";
|
|
8816
8745
|
import { Console } from "console";
|
|
8817
8746
|
import fs from "fs";
|
|
8818
|
-
import
|
|
8747
|
+
import path3 from "path";
|
|
8819
8748
|
import util2 from "util";
|
|
8820
8749
|
|
|
8821
8750
|
// src/lib/output.capture.ts
|
|
@@ -9458,7 +9387,7 @@ class TerminalConsole extends EventEmitter6 {
|
|
|
9458
9387
|
try {
|
|
9459
9388
|
const timestamp = Date.now();
|
|
9460
9389
|
const filename = `_console_${timestamp}.log`;
|
|
9461
|
-
const filepath =
|
|
9390
|
+
const filepath = path3.join(process.cwd(), filename);
|
|
9462
9391
|
const allLogEntries = [...this._allLogEntries, ...terminalConsoleCache.cachedLogs];
|
|
9463
9392
|
const logLines = [];
|
|
9464
9393
|
for (const [date, level, args, callerInfo] of allLogEntries) {
|
|
@@ -9569,6 +9498,18 @@ registerEnvVar({
|
|
|
9569
9498
|
type: "boolean",
|
|
9570
9499
|
default: false
|
|
9571
9500
|
});
|
|
9501
|
+
registerEnvVar({
|
|
9502
|
+
name: "OTUI_USE_ALTERNATE_SCREEN",
|
|
9503
|
+
description: "Whether to use the console. Will not capture console output if set to false.",
|
|
9504
|
+
type: "boolean",
|
|
9505
|
+
default: true
|
|
9506
|
+
});
|
|
9507
|
+
registerEnvVar({
|
|
9508
|
+
name: "OTUI_OVERRIDE_STDOUT",
|
|
9509
|
+
description: "Override the stdout stream. This is useful for debugging.",
|
|
9510
|
+
type: "boolean",
|
|
9511
|
+
default: true
|
|
9512
|
+
});
|
|
9572
9513
|
|
|
9573
9514
|
class MouseEvent {
|
|
9574
9515
|
type;
|
|
@@ -9641,7 +9582,7 @@ var rendererTracker = singleton("RendererTracker", () => {
|
|
|
9641
9582
|
});
|
|
9642
9583
|
async function createCliRenderer(config = {}) {
|
|
9643
9584
|
if (process.argv.includes("--delay-start")) {
|
|
9644
|
-
await new Promise((
|
|
9585
|
+
await new Promise((resolve4) => setTimeout(resolve4, 5000));
|
|
9645
9586
|
}
|
|
9646
9587
|
const stdin = config.stdin || process.stdin;
|
|
9647
9588
|
const stdout = config.stdout || process.stdout;
|
|
@@ -9729,7 +9670,7 @@ class CliRenderer extends EventEmitter7 {
|
|
|
9729
9670
|
resizeDebounceDelay = 100;
|
|
9730
9671
|
enableMouseMovement = false;
|
|
9731
9672
|
_useMouse = true;
|
|
9732
|
-
_useAlternateScreen =
|
|
9673
|
+
_useAlternateScreen = env.OTUI_USE_ALTERNATE_SCREEN;
|
|
9733
9674
|
capturedRenderable;
|
|
9734
9675
|
lastOverRenderableNum = 0;
|
|
9735
9676
|
lastOverRenderable;
|
|
@@ -9760,9 +9701,9 @@ class CliRenderer extends EventEmitter7 {
|
|
|
9760
9701
|
handleError = ((error) => {
|
|
9761
9702
|
this.stop();
|
|
9762
9703
|
this.destroy();
|
|
9763
|
-
new Promise((
|
|
9704
|
+
new Promise((resolve4) => {
|
|
9764
9705
|
setTimeout(() => {
|
|
9765
|
-
|
|
9706
|
+
resolve4(true);
|
|
9766
9707
|
}, 100);
|
|
9767
9708
|
}).then(() => {
|
|
9768
9709
|
this.realStdoutWrite.call(this.stdout, `
|
|
@@ -9841,7 +9782,7 @@ Captured output:
|
|
|
9841
9782
|
this.maxStatSamples = config.maxStatSamples || 300;
|
|
9842
9783
|
this.enableMouseMovement = config.enableMouseMovement || true;
|
|
9843
9784
|
this._useMouse = config.useMouse ?? true;
|
|
9844
|
-
this._useAlternateScreen = config.useAlternateScreen ??
|
|
9785
|
+
this._useAlternateScreen = config.useAlternateScreen ?? env.OTUI_USE_ALTERNATE_SCREEN;
|
|
9845
9786
|
this.nextRenderBuffer = this.lib.getNextBuffer(this.rendererPtr);
|
|
9846
9787
|
this.currentRenderBuffer = this.lib.getCurrentBuffer(this.rendererPtr);
|
|
9847
9788
|
this.postProcessFns = config.postProcessFns || [];
|
|
@@ -9849,7 +9790,9 @@ Captured output:
|
|
|
9849
9790
|
if (this.memorySnapshotInterval > 0) {
|
|
9850
9791
|
this.startMemorySnapshotTimer();
|
|
9851
9792
|
}
|
|
9852
|
-
|
|
9793
|
+
if (env.OTUI_OVERRIDE_STDOUT) {
|
|
9794
|
+
this.stdout.write = this.interceptStdoutWrite.bind(this);
|
|
9795
|
+
}
|
|
9853
9796
|
process.on("SIGWINCH", this.sigwinchHandler);
|
|
9854
9797
|
process.on("warning", this.warningHandler);
|
|
9855
9798
|
process.on("uncaughtException", this.handleError);
|
|
@@ -10081,16 +10024,16 @@ Captured output:
|
|
|
10081
10024
|
if (this._terminalIsSetup)
|
|
10082
10025
|
return;
|
|
10083
10026
|
this._terminalIsSetup = true;
|
|
10084
|
-
await new Promise((
|
|
10027
|
+
await new Promise((resolve4) => {
|
|
10085
10028
|
const timeout = setTimeout(() => {
|
|
10086
10029
|
this.stdin.off("data", capListener);
|
|
10087
|
-
|
|
10030
|
+
resolve4(true);
|
|
10088
10031
|
}, 100);
|
|
10089
10032
|
const capListener = (str) => {
|
|
10090
10033
|
clearTimeout(timeout);
|
|
10091
10034
|
this.lib.processCapabilityResponse(this.rendererPtr, str);
|
|
10092
10035
|
this.stdin.off("data", capListener);
|
|
10093
|
-
|
|
10036
|
+
resolve4(true);
|
|
10094
10037
|
};
|
|
10095
10038
|
this.stdin.on("data", capListener);
|
|
10096
10039
|
this.lib.setupTerminal(this.rendererPtr, this._useAlternateScreen);
|
|
@@ -10732,7 +10675,7 @@ Captured output:
|
|
|
10732
10675
|
}
|
|
10733
10676
|
}
|
|
10734
10677
|
|
|
10735
|
-
export {
|
|
10678
|
+
export { Edge, Gutter, exports_src, BorderChars, getBorderFromSides, getBorderSides, borderCharsToArray, BorderCharArrays, nonAlphanumericKeys, parseKeypress, ANSI, KeyEvent, PasteEvent, KeyHandler, InternalKeyHandler, RGBA, hexToRgb, rgbToHex, hsvToRgb, parseColor, fonts, measureText, getCharacterPositions, coordinateToCharacterIndex, renderFontToFrameBuffer, TextAttributes, DebugOverlayCorner, createTextAttributes, visualizeRenderableTree, isStyledText, StyledText, stringToStyledText, black, red, green, yellow, blue, magenta, cyan, white, brightBlack, brightRed, brightGreen, brightYellow, brightBlue, brightMagenta, brightCyan, brightWhite, bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite, bold, italic, underline, strikethrough, dim, reverse, blink, fg, bg, t, convertThemeToStyles, SyntaxStyle, hastToStyledText, parseAlign, parseBoxSizing, parseDimension, parseDirection, parseDisplay, parseEdge, parseFlexDirection, parseGutter, parseJustify, parseLogLevel, parseMeasureMode, parseOverflow, parsePositionType, parseUnit, parseWrap, MouseParser, Selection, convertGlobalToLocalSelection, ASCIIFontSelectionHelper, envRegistry, registerEnvVar, clearEnvCache, generateEnvMarkdown, generateEnvColored, env, treeSitterToTextChunks, treeSitterToStyledText, addDefaultParsers, TreeSitterClient, DataPathsManager, getDataPaths, extToFiletype, pathToFiletype, main, getTreeSitterClient, TextBuffer, LogLevel2 as LogLevel, setRenderLibPath, resolveRenderLib, OptimizedBuffer, h, isVNode, maybeMakeRenderable, wrapWithDelegates, instantiate, delegate, isValidPercentage, LayoutEvents, RenderableEvents, isRenderable, BaseRenderable, Renderable, RootRenderable, capture, ConsolePosition, TerminalConsole, getObjectsInViewport, MouseEvent, MouseButton, createCliRenderer, CliRenderEvents, CliRenderer };
|
|
10736
10679
|
|
|
10737
|
-
//# debugId=
|
|
10738
|
-
//# sourceMappingURL=index-
|
|
10680
|
+
//# debugId=68D4874E884EA10964756E2164756E21
|
|
10681
|
+
//# sourceMappingURL=index-0p8687g8.js.map
|