@opentui/core 0.1.31 → 0.1.32

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/index.js CHANGED
@@ -30,6 +30,7 @@ import {
30
30
  RendererControlState,
31
31
  RootRenderable,
32
32
  Selection,
33
+ StdinBuffer,
33
34
  StyledText,
34
35
  TerminalConsole,
35
36
  TextAttributes,
@@ -133,7 +134,7 @@ import {
133
134
  white,
134
135
  wrapWithDelegates,
135
136
  yellow
136
- } from "./index-91qheh74.js";
137
+ } from "./index-3f9h747j.js";
137
138
  // src/text-buffer-view.ts
138
139
  class TextBufferView {
139
140
  lib;
@@ -222,6 +223,15 @@ class TextBufferView {
222
223
  return "";
223
224
  return this.lib.decoder.decode(plainBytes);
224
225
  }
226
+ setTabIndicator(indicator) {
227
+ this.guard();
228
+ const codePoint = typeof indicator === "string" ? indicator.codePointAt(0) ?? 0 : indicator;
229
+ this.lib.textBufferViewSetTabIndicator(this.viewPtr, codePoint);
230
+ }
231
+ setTabIndicatorColor(color) {
232
+ this.guard();
233
+ this.lib.textBufferViewSetTabIndicatorColor(this.viewPtr, color);
234
+ }
225
235
  destroy() {
226
236
  if (this._destroyed)
227
237
  return;
@@ -657,6 +667,15 @@ class EditorView {
657
667
  this.guard();
658
668
  this.lib.editorViewSetPlaceholderStyledText(this.viewPtr, chunks);
659
669
  }
670
+ setTabIndicator(indicator) {
671
+ this.guard();
672
+ const codePoint = typeof indicator === "string" ? indicator.codePointAt(0) ?? 0 : indicator;
673
+ this.lib.editorViewSetTabIndicator(this.viewPtr, codePoint);
674
+ }
675
+ setTabIndicatorColor(color) {
676
+ this.guard();
677
+ this.lib.editorViewSetTabIndicatorColor(this.viewPtr, color);
678
+ }
660
679
  destroy() {
661
680
  if (this._destroyed)
662
681
  return;
@@ -842,6 +861,14 @@ class SyntaxStyle {
842
861
  this.guard();
843
862
  return this.mergedCache.size;
844
863
  }
864
+ getAllStyles() {
865
+ this.guard();
866
+ return new Map(this.styleDefs);
867
+ }
868
+ getRegisteredNames() {
869
+ this.guard();
870
+ return Array.from(this.styleDefs.keys());
871
+ }
845
872
  destroy() {
846
873
  if (this._destroyed)
847
874
  return;
@@ -2176,6 +2203,13 @@ class BoxRenderable extends Renderable {
2176
2203
  this.applyYogaGap(options);
2177
2204
  }
2178
2205
  }
2206
+ initializeBorder() {
2207
+ if (this._border === false) {
2208
+ this._border = true;
2209
+ this.borderSides = getBorderSides(this._border);
2210
+ this.applyYogaBorders();
2211
+ }
2212
+ }
2179
2213
  get customBorderChars() {
2180
2214
  return this._customBorderCharsObj;
2181
2215
  }
@@ -2210,9 +2244,10 @@ class BoxRenderable extends Renderable {
2210
2244
  }
2211
2245
  set borderStyle(value) {
2212
2246
  let _value = value ?? this._defaultOptions.borderStyle;
2213
- if (this._borderStyle !== _value) {
2247
+ if (this._borderStyle !== _value || !this._border) {
2214
2248
  this._borderStyle = _value;
2215
2249
  this._customBorderChars = undefined;
2250
+ this.initializeBorder();
2216
2251
  this.requestRender();
2217
2252
  }
2218
2253
  }
@@ -2223,6 +2258,7 @@ class BoxRenderable extends Renderable {
2223
2258
  const newColor = parseColor(value ?? this._defaultOptions.borderColor);
2224
2259
  if (this._borderColor !== newColor) {
2225
2260
  this._borderColor = newColor;
2261
+ this.initializeBorder();
2226
2262
  this.requestRender();
2227
2263
  }
2228
2264
  }
@@ -2233,6 +2269,7 @@ class BoxRenderable extends Renderable {
2233
2269
  const newColor = parseColor(value ?? this._defaultOptions.focusedBorderColor);
2234
2270
  if (this._focusedBorderColor !== newColor) {
2235
2271
  this._focusedBorderColor = newColor;
2272
+ this.initializeBorder();
2236
2273
  if (this._focused) {
2237
2274
  this.requestRender();
2238
2275
  }
@@ -2338,6 +2375,8 @@ class TextBufferRenderable extends Renderable {
2338
2375
  _selectionFg;
2339
2376
  _wrapMode = "word";
2340
2377
  lastLocalSelection = null;
2378
+ _tabIndicator;
2379
+ _tabIndicatorColor;
2341
2380
  textBuffer;
2342
2381
  textBufferView;
2343
2382
  _lineInfo = { lineStarts: [], lineWidths: [], maxLineWidth: 0 };
@@ -2348,7 +2387,9 @@ class TextBufferRenderable extends Renderable {
2348
2387
  selectionFg: undefined,
2349
2388
  selectable: true,
2350
2389
  attributes: 0,
2351
- wrapMode: "word"
2390
+ wrapMode: "word",
2391
+ tabIndicator: undefined,
2392
+ tabIndicatorColor: undefined
2352
2393
  };
2353
2394
  constructor(ctx, options) {
2354
2395
  super(ctx, options);
@@ -2359,6 +2400,8 @@ class TextBufferRenderable extends Renderable {
2359
2400
  this._selectionFg = options.selectionFg ? parseColor(options.selectionFg) : this._defaultOptions.selectionFg;
2360
2401
  this.selectable = options.selectable ?? this._defaultOptions.selectable;
2361
2402
  this._wrapMode = options.wrapMode ?? this._defaultOptions.wrapMode;
2403
+ this._tabIndicator = options.tabIndicator ?? this._defaultOptions.tabIndicator;
2404
+ this._tabIndicatorColor = options.tabIndicatorColor ? parseColor(options.tabIndicatorColor) : this._defaultOptions.tabIndicatorColor;
2362
2405
  this.textBuffer = TextBuffer.create(this._ctx.widthMethod);
2363
2406
  this.textBufferView = TextBufferView.create(this.textBuffer);
2364
2407
  const style = SyntaxStyle.create();
@@ -2368,6 +2411,12 @@ class TextBufferRenderable extends Renderable {
2368
2411
  this.textBuffer.setDefaultFg(this._defaultFg);
2369
2412
  this.textBuffer.setDefaultBg(this._defaultBg);
2370
2413
  this.textBuffer.setDefaultAttributes(this._defaultAttributes);
2414
+ if (this._tabIndicator !== undefined) {
2415
+ this.textBufferView.setTabIndicator(this._tabIndicator);
2416
+ }
2417
+ if (this._tabIndicatorColor !== undefined) {
2418
+ this.textBufferView.setTabIndicatorColor(this._tabIndicatorColor);
2419
+ }
2371
2420
  if (this._wrapMode !== "none" && this.width > 0) {
2372
2421
  this.updateWrapWidth(this.width);
2373
2422
  }
@@ -2454,6 +2503,31 @@ class TextBufferRenderable extends Renderable {
2454
2503
  this.requestRender();
2455
2504
  }
2456
2505
  }
2506
+ get tabIndicator() {
2507
+ return this._tabIndicator;
2508
+ }
2509
+ set tabIndicator(value) {
2510
+ if (this._tabIndicator !== value) {
2511
+ this._tabIndicator = value;
2512
+ if (value !== undefined) {
2513
+ this.textBufferView.setTabIndicator(value);
2514
+ }
2515
+ this.requestRender();
2516
+ }
2517
+ }
2518
+ get tabIndicatorColor() {
2519
+ return this._tabIndicatorColor;
2520
+ }
2521
+ set tabIndicatorColor(value) {
2522
+ const newColor = value ? parseColor(value) : undefined;
2523
+ if (this._tabIndicatorColor !== newColor) {
2524
+ this._tabIndicatorColor = newColor;
2525
+ if (newColor !== undefined) {
2526
+ this.textBufferView.setTabIndicatorColor(newColor);
2527
+ }
2528
+ this.requestRender();
2529
+ }
2530
+ }
2457
2531
  onResize(width, height) {
2458
2532
  this.textBufferView.setViewportSize(width, height);
2459
2533
  if (this.lastLocalSelection) {
@@ -2568,8 +2642,14 @@ class CodeRenderable extends TextBufferRenderable {
2568
2642
  _isHighlighting = false;
2569
2643
  _treeSitterClient;
2570
2644
  _pendingRehighlight = false;
2645
+ _pendingUpdate = false;
2646
+ _currentHighlightId = 0;
2647
+ _conceal;
2648
+ _drawUnstyledText;
2571
2649
  _contentDefaultOptions = {
2572
- content: ""
2650
+ content: "",
2651
+ conceal: true,
2652
+ drawUnstyledText: true
2573
2653
  };
2574
2654
  constructor(ctx, options) {
2575
2655
  super(ctx, options);
@@ -2577,6 +2657,8 @@ class CodeRenderable extends TextBufferRenderable {
2577
2657
  this._filetype = options.filetype;
2578
2658
  this._syntaxStyle = options.syntaxStyle;
2579
2659
  this._treeSitterClient = options.treeSitterClient ?? getTreeSitterClient();
2660
+ this._conceal = options.conceal ?? this._contentDefaultOptions.conceal;
2661
+ this._drawUnstyledText = options.drawUnstyledText ?? this._contentDefaultOptions.drawUnstyledText;
2580
2662
  this.updateContent(this._content);
2581
2663
  }
2582
2664
  get content() {
@@ -2585,7 +2667,7 @@ class CodeRenderable extends TextBufferRenderable {
2585
2667
  set content(value) {
2586
2668
  if (this._content !== value) {
2587
2669
  this._content = value;
2588
- this.updateContent(value);
2670
+ this.scheduleUpdate();
2589
2671
  }
2590
2672
  }
2591
2673
  get filetype() {
@@ -2594,7 +2676,7 @@ class CodeRenderable extends TextBufferRenderable {
2594
2676
  set filetype(value) {
2595
2677
  if (this._filetype !== value) {
2596
2678
  this._filetype = value;
2597
- this.updateContent(this._content);
2679
+ this.scheduleUpdate();
2598
2680
  }
2599
2681
  }
2600
2682
  get syntaxStyle() {
@@ -2603,36 +2685,70 @@ class CodeRenderable extends TextBufferRenderable {
2603
2685
  set syntaxStyle(value) {
2604
2686
  if (this._syntaxStyle !== value) {
2605
2687
  this._syntaxStyle = value;
2606
- this.updateContent(this._content);
2688
+ this.scheduleUpdate();
2607
2689
  }
2608
2690
  }
2691
+ get conceal() {
2692
+ return this._conceal;
2693
+ }
2694
+ set conceal(value) {
2695
+ if (this._conceal !== value) {
2696
+ this._conceal = value;
2697
+ this.scheduleUpdate();
2698
+ }
2699
+ }
2700
+ get drawUnstyledText() {
2701
+ return this._drawUnstyledText;
2702
+ }
2703
+ set drawUnstyledText(value) {
2704
+ if (this._drawUnstyledText !== value) {
2705
+ this._drawUnstyledText = value;
2706
+ this.scheduleUpdate();
2707
+ }
2708
+ }
2709
+ scheduleUpdate() {
2710
+ if (this._pendingUpdate)
2711
+ return;
2712
+ this._pendingUpdate = true;
2713
+ queueMicrotask(() => {
2714
+ this._pendingUpdate = false;
2715
+ this.updateContent(this._content);
2716
+ });
2717
+ }
2609
2718
  async updateContent(content) {
2610
2719
  if (content.length === 0)
2611
2720
  return;
2612
- if (this._isHighlighting) {
2613
- this._pendingRehighlight = true;
2614
- return;
2615
- }
2616
2721
  if (!this._filetype) {
2617
2722
  this.fallback(content);
2618
2723
  return;
2619
2724
  }
2620
- this.fallback(content);
2725
+ this._currentHighlightId++;
2726
+ const highlightId = this._currentHighlightId;
2727
+ if (this._drawUnstyledText) {
2728
+ this.fallback(content);
2729
+ }
2621
2730
  this._isHighlighting = true;
2731
+ this._pendingRehighlight = false;
2622
2732
  try {
2623
- const styledText = await treeSitterToStyledText(content, this._filetype, this._syntaxStyle, this._treeSitterClient);
2733
+ const styledText = await treeSitterToStyledText(content, this._filetype, this._syntaxStyle, this._treeSitterClient, {
2734
+ conceal: { enabled: this._conceal }
2735
+ });
2736
+ if (highlightId !== this._currentHighlightId) {
2737
+ return;
2738
+ }
2624
2739
  if (this.isDestroyed)
2625
2740
  return;
2626
2741
  this.textBuffer.setStyledText(styledText);
2627
2742
  this.updateTextInfo();
2628
2743
  } catch (error) {
2744
+ if (highlightId !== this._currentHighlightId) {
2745
+ return;
2746
+ }
2629
2747
  console.warn("Code highlighting failed, falling back to plain text:", error);
2630
2748
  this.fallback(content);
2631
2749
  } finally {
2632
- this._isHighlighting = false;
2633
- if (this._pendingRehighlight) {
2634
- this._pendingRehighlight = false;
2635
- process.nextTick(() => this.updateContent(this._content));
2750
+ if (highlightId === this._currentHighlightId) {
2751
+ this._isHighlighting = false;
2636
2752
  }
2637
2753
  }
2638
2754
  }
@@ -2655,6 +2771,9 @@ class CodeRenderable extends TextBufferRenderable {
2655
2771
  ];
2656
2772
  return new StyledText(chunks);
2657
2773
  }
2774
+ getLineHighlights(lineIdx) {
2775
+ return this.textBuffer.getLineHighlights(lineIdx);
2776
+ }
2658
2777
  }
2659
2778
  // src/renderables/TextNode.ts
2660
2779
  var BrandedTextNodeRenderable = Symbol.for("@opentui/core/TextNodeRenderable");
@@ -3151,7 +3270,7 @@ class InputRenderable extends Renderable {
3151
3270
  this.deleteCharacter("forward");
3152
3271
  return true;
3153
3272
  case "return":
3154
- case "enter":
3273
+ case "linefeed":
3155
3274
  if (this._value !== this._lastCommittedValue) {
3156
3275
  this._lastCommittedValue = this._value;
3157
3276
  this.emit("change" /* CHANGE */, this._value);
@@ -4506,7 +4625,7 @@ class SelectRenderable extends Renderable {
4506
4625
  this.moveDown(isShift ? this._fastScrollStep : 1);
4507
4626
  return true;
4508
4627
  case "return":
4509
- case "enter":
4628
+ case "linefeed":
4510
4629
  this.selectCurrent();
4511
4630
  return true;
4512
4631
  }
@@ -4825,7 +4944,7 @@ class TabSelectRenderable extends Renderable {
4825
4944
  this.moveRight();
4826
4945
  return true;
4827
4946
  case "return":
4828
- case "enter":
4947
+ case "linefeed":
4829
4948
  this.selectCurrent();
4830
4949
  return true;
4831
4950
  }
@@ -5026,6 +5145,8 @@ class EditBufferRenderable extends Renderable {
5026
5145
  _showCursor = true;
5027
5146
  _cursorColor;
5028
5147
  lastLocalSelection = null;
5148
+ _tabIndicator;
5149
+ _tabIndicatorColor;
5029
5150
  _cursorChangeListener = undefined;
5030
5151
  _contentChangeListener = undefined;
5031
5152
  editBuffer;
@@ -5040,7 +5161,9 @@ class EditBufferRenderable extends Renderable {
5040
5161
  wrapMode: "word",
5041
5162
  scrollMargin: 0.2,
5042
5163
  showCursor: true,
5043
- cursorColor: RGBA.fromValues(1, 1, 1, 1)
5164
+ cursorColor: RGBA.fromValues(1, 1, 1, 1),
5165
+ tabIndicator: undefined,
5166
+ tabIndicatorColor: undefined
5044
5167
  };
5045
5168
  constructor(ctx, options) {
5046
5169
  super(ctx, options);
@@ -5054,6 +5177,8 @@ class EditBufferRenderable extends Renderable {
5054
5177
  this._scrollMargin = options.scrollMargin ?? this._defaultOptions.scrollMargin;
5055
5178
  this._showCursor = options.showCursor ?? this._defaultOptions.showCursor;
5056
5179
  this._cursorColor = parseColor(options.cursorColor ?? this._defaultOptions.cursorColor);
5180
+ this._tabIndicator = options.tabIndicator ?? this._defaultOptions.tabIndicator;
5181
+ this._tabIndicatorColor = options.tabIndicatorColor ? parseColor(options.tabIndicatorColor) : this._defaultOptions.tabIndicatorColor;
5057
5182
  this.editBuffer = EditBuffer.create(this._ctx.widthMethod);
5058
5183
  this.editorView = EditorView.create(this.editBuffer, this.width || 80, this.height || 24);
5059
5184
  this.editorView.setWrapMode(this._wrapMode);
@@ -5064,6 +5189,12 @@ class EditBufferRenderable extends Renderable {
5064
5189
  if (options.syntaxStyle) {
5065
5190
  this.editBuffer.setSyntaxStyle(options.syntaxStyle);
5066
5191
  }
5192
+ if (this._tabIndicator !== undefined) {
5193
+ this.editorView.setTabIndicator(this._tabIndicator);
5194
+ }
5195
+ if (this._tabIndicatorColor !== undefined) {
5196
+ this.editorView.setTabIndicatorColor(this._tabIndicatorColor);
5197
+ }
5067
5198
  this.setupMeasureFunc();
5068
5199
  this.setupEventListeners(options);
5069
5200
  }
@@ -5191,6 +5322,31 @@ class EditBufferRenderable extends Renderable {
5191
5322
  this.requestRender();
5192
5323
  }
5193
5324
  }
5325
+ get tabIndicator() {
5326
+ return this._tabIndicator;
5327
+ }
5328
+ set tabIndicator(value) {
5329
+ if (this._tabIndicator !== value) {
5330
+ this._tabIndicator = value;
5331
+ if (value !== undefined) {
5332
+ this.editorView.setTabIndicator(value);
5333
+ }
5334
+ this.requestRender();
5335
+ }
5336
+ }
5337
+ get tabIndicatorColor() {
5338
+ return this._tabIndicatorColor;
5339
+ }
5340
+ set tabIndicatorColor(value) {
5341
+ const newColor = value ? parseColor(value) : undefined;
5342
+ if (this._tabIndicatorColor !== newColor) {
5343
+ this._tabIndicatorColor = newColor;
5344
+ if (newColor !== undefined) {
5345
+ this.editorView.setTabIndicatorColor(newColor);
5346
+ }
5347
+ this.requestRender();
5348
+ }
5349
+ }
5194
5350
  onResize(width, height) {
5195
5351
  this.editorView.setViewportSize(width, height);
5196
5352
  if (this.lastLocalSelection) {
@@ -5415,9 +5571,8 @@ var defaultTextareaKeybindings = [
5415
5571
  { name: "backspace", action: "backspace" },
5416
5572
  { name: "delete", action: "delete" },
5417
5573
  { name: "return", action: "newline" },
5418
- { name: "enter", action: "newline" },
5574
+ { name: "linefeed", action: "newline" },
5419
5575
  { name: "return", meta: true, action: "submit" },
5420
- { name: "enter", meta: true, action: "submit" },
5421
5576
  { name: "z", ctrl: true, action: "undo" },
5422
5577
  { name: "Z", ctrl: true, shift: true, action: "redo" },
5423
5578
  { name: "y", ctrl: true, action: "redo" },
@@ -5968,6 +6123,7 @@ export {
5968
6123
  TabSelect,
5969
6124
  SyntaxStyle,
5970
6125
  StyledText,
6126
+ StdinBuffer,
5971
6127
  SliderRenderable,
5972
6128
  Selection,
5973
6129
  SelectRenderableEvents,
@@ -6023,5 +6179,5 @@ export {
6023
6179
  ASCIIFont
6024
6180
  };
6025
6181
 
6026
- //# debugId=F972C01B99F2CD0364756E2164756E21
6182
+ //# debugId=52657F382323749F64756E2164756E21
6027
6183
  //# sourceMappingURL=index.js.map