@opentui/core 0.1.46 → 0.1.48

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 CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  __export,
6
6
  __require,
7
7
  __toESM
8
- } from "./index-31ycf9q5.js";
8
+ } from "./index-rkpj2eng.js";
9
9
 
10
10
  // ../../node_modules/omggif/omggif.js
11
11
  var require_omggif = __commonJS((exports) => {
package/buffer.d.ts CHANGED
@@ -12,6 +12,7 @@ export declare class OptimizedBuffer {
12
12
  private bufferPtr;
13
13
  private _width;
14
14
  private _height;
15
+ private _widthMethod;
15
16
  respectAlpha: boolean;
16
17
  private _rawBuffers;
17
18
  private _destroyed;
@@ -26,11 +27,13 @@ export declare class OptimizedBuffer {
26
27
  constructor(lib: RenderLib, ptr: Pointer, width: number, height: number, options: {
27
28
  respectAlpha?: boolean;
28
29
  id?: string;
30
+ widthMethod?: WidthMethod;
29
31
  });
30
32
  static create(width: number, height: number, widthMethod: WidthMethod, options?: {
31
33
  respectAlpha?: boolean;
32
34
  id?: string;
33
35
  }): OptimizedBuffer;
36
+ get widthMethod(): WidthMethod;
34
37
  get width(): number;
35
38
  get height(): number;
36
39
  setRespectAlpha(respectAlpha: boolean): void;
@@ -70,4 +73,19 @@ export declare class OptimizedBuffer {
70
73
  pushScissorRect(x: number, y: number, width: number, height: number): void;
71
74
  popScissorRect(): void;
72
75
  clearScissorRects(): void;
76
+ encodeUnicode(text: string): {
77
+ ptr: Pointer;
78
+ data: Array<{
79
+ width: number;
80
+ char: number;
81
+ }>;
82
+ } | null;
83
+ freeUnicode(encoded: {
84
+ ptr: Pointer;
85
+ data: Array<{
86
+ width: number;
87
+ char: number;
88
+ }>;
89
+ }): void;
90
+ drawChar(char: number, x: number, y: number, fg: RGBA, bg: RGBA, attributes?: number): void;
73
91
  }
@@ -2307,15 +2307,11 @@ class PasteEvent {
2307
2307
 
2308
2308
  class KeyHandler extends EventEmitter {
2309
2309
  useKittyKeyboard;
2310
- suspended = false;
2311
2310
  constructor(useKittyKeyboard = false) {
2312
2311
  super();
2313
2312
  this.useKittyKeyboard = useKittyKeyboard;
2314
2313
  }
2315
2314
  processInput(data) {
2316
- if (this.suspended) {
2317
- return false;
2318
- }
2319
2315
  const parsedKey = parseKeypress(data, { useKittyKeyboard: this.useKittyKeyboard });
2320
2316
  if (!parsedKey) {
2321
2317
  return false;
@@ -2337,18 +2333,9 @@ class KeyHandler extends EventEmitter {
2337
2333
  return true;
2338
2334
  }
2339
2335
  processPaste(data) {
2340
- if (this.suspended) {
2341
- return;
2342
- }
2343
2336
  const cleanedData = Bun.stripANSI(data);
2344
2337
  this.emit("paste", new PasteEvent(cleanedData));
2345
2338
  }
2346
- suspend() {
2347
- this.suspended = true;
2348
- }
2349
- resume() {
2350
- this.suspended = false;
2351
- }
2352
2339
  }
2353
2340
 
2354
2341
  class InternalKeyHandler extends KeyHandler {
@@ -6445,7 +6432,7 @@ class Selection {
6445
6432
  return aY - bY;
6446
6433
  }
6447
6434
  return a.x - b.x;
6448
- }).map((renderable) => renderable.getSelectedText()).filter((text) => text);
6435
+ }).filter((renderable) => !renderable.isDestroyed).map((renderable) => renderable.getSelectedText()).filter((text) => text);
6449
6436
  return selectedTexts.join(`
6450
6437
  `);
6451
6438
  }
@@ -6638,10 +6625,10 @@ No environment variables registered.
6638
6625
  `;
6639
6626
  if (config.default !== undefined) {
6640
6627
  const defaultValue = typeof config.default === "string" ? `"${config.default}"` : String(config.default);
6641
- markdown += `**Default:** \`${defaultValue}\`
6628
+ markdown += `**Default:** \`${defaultValue}\`
6642
6629
  `;
6643
6630
  } else {
6644
- markdown += `**Default:** *Required*
6631
+ markdown += `**Default:** *Required*
6645
6632
  `;
6646
6633
  }
6647
6634
  markdown += `
@@ -9084,6 +9071,7 @@ class OptimizedBuffer {
9084
9071
  bufferPtr;
9085
9072
  _width;
9086
9073
  _height;
9074
+ _widthMethod;
9087
9075
  respectAlpha = false;
9088
9076
  _rawBuffers = null;
9089
9077
  _destroyed = false;
@@ -9117,13 +9105,18 @@ class OptimizedBuffer {
9117
9105
  this.respectAlpha = options.respectAlpha || false;
9118
9106
  this._width = width;
9119
9107
  this._height = height;
9108
+ this._widthMethod = options.widthMethod || "unicode";
9120
9109
  this.bufferPtr = ptr;
9121
9110
  }
9122
9111
  static create(width, height, widthMethod, options = {}) {
9123
9112
  const lib = resolveRenderLib();
9124
9113
  const respectAlpha = options.respectAlpha || false;
9125
9114
  const id = options.id && options.id.trim() !== "" ? options.id : "unnamed buffer";
9126
- return lib.createOptimizedBuffer(width, height, widthMethod, respectAlpha, id);
9115
+ const buffer = lib.createOptimizedBuffer(width, height, widthMethod, respectAlpha, id);
9116
+ return buffer;
9117
+ }
9118
+ get widthMethod() {
9119
+ return this._widthMethod;
9127
9120
  }
9128
9121
  get width() {
9129
9122
  return this._width;
@@ -9246,6 +9239,18 @@ class OptimizedBuffer {
9246
9239
  this.guard();
9247
9240
  this.lib.bufferClearScissorRects(this.bufferPtr);
9248
9241
  }
9242
+ encodeUnicode(text) {
9243
+ this.guard();
9244
+ return this.lib.encodeUnicode(text, this._widthMethod);
9245
+ }
9246
+ freeUnicode(encoded) {
9247
+ this.guard();
9248
+ this.lib.freeUnicode(encoded);
9249
+ }
9250
+ drawChar(char, x, y, fg2, bg2, attributes = 0) {
9251
+ this.guard();
9252
+ this.lib.bufferDrawChar(this.bufferPtr, char, x, y, fg2, bg2, attributes);
9253
+ }
9249
9254
  }
9250
9255
 
9251
9256
  // ../../node_modules/bun-ffi-structs/index.js
@@ -9923,6 +9928,10 @@ var TerminalCapabilitiesStruct = defineStruct([
9923
9928
  ["term_version_len", "u64", { lengthOf: "term_version" }],
9924
9929
  ["term_from_xtversion", "bool_u8"]
9925
9930
  ]);
9931
+ var EncodedCharStruct = defineStruct([
9932
+ ["width", "u8"],
9933
+ ["char", "u32"]
9934
+ ]);
9926
9935
 
9927
9936
  // src/zig.ts
9928
9937
  var module = await import(`@opentui/core-${process.platform}-${process.arch}/index.ts`);
@@ -9945,6 +9954,18 @@ registerEnvVar({
9945
9954
  type: "boolean",
9946
9955
  default: false
9947
9956
  });
9957
+ registerEnvVar({
9958
+ name: "OPENTUI_FORCE_WCWIDTH",
9959
+ description: "Use wcwidth for character width calculations",
9960
+ type: "boolean",
9961
+ default: false
9962
+ });
9963
+ registerEnvVar({
9964
+ name: "OPENTUI_FORCE_UNICODE",
9965
+ description: "Force Mode 2026 Unicode support in terminal capabilities",
9966
+ type: "boolean",
9967
+ default: false
9968
+ });
9948
9969
  function getOpenTUILib(libPath) {
9949
9970
  const resolvedLibPath = libPath || targetLibPath;
9950
9971
  const rawSymbols = dlopen(resolvedLibPath, {
@@ -10180,6 +10201,14 @@ function getOpenTUILib(libPath) {
10180
10201
  args: ["ptr", "bool"],
10181
10202
  returns: "void"
10182
10203
  },
10204
+ suspendRenderer: {
10205
+ args: ["ptr"],
10206
+ returns: "void"
10207
+ },
10208
+ resumeRenderer: {
10209
+ args: ["ptr"],
10210
+ returns: "void"
10211
+ },
10183
10212
  createTextBuffer: {
10184
10213
  args: ["u8"],
10185
10214
  returns: "ptr"
@@ -10691,6 +10720,18 @@ function getOpenTUILib(libPath) {
10691
10720
  processCapabilityResponse: {
10692
10721
  args: ["ptr", "ptr", "usize"],
10693
10722
  returns: "void"
10723
+ },
10724
+ encodeUnicode: {
10725
+ args: ["ptr", "usize", "ptr", "ptr", "u8"],
10726
+ returns: "bool"
10727
+ },
10728
+ freeUnicode: {
10729
+ args: ["ptr", "usize"],
10730
+ returns: "void"
10731
+ },
10732
+ bufferDrawChar: {
10733
+ args: ["ptr", "u32", "u32", "u32", "ptr", "ptr", "u8"],
10734
+ returns: "void"
10694
10735
  }
10695
10736
  });
10696
10737
  if (env.OTUI_DEBUG_FFI || env.OTUI_TRACE_FFI) {
@@ -10958,7 +10999,7 @@ class FFIRenderLib {
10958
10999
  }
10959
11000
  const width = this.opentui.symbols.getBufferWidth(bufferPtr);
10960
11001
  const height = this.opentui.symbols.getBufferHeight(bufferPtr);
10961
- return new OptimizedBuffer(this, bufferPtr, width, height, { id: "next buffer" });
11002
+ return new OptimizedBuffer(this, bufferPtr, width, height, { id: "next buffer", widthMethod: "unicode" });
10962
11003
  }
10963
11004
  getCurrentBuffer(renderer) {
10964
11005
  const bufferPtr = this.opentui.symbols.getCurrentBuffer(renderer);
@@ -10967,7 +11008,7 @@ class FFIRenderLib {
10967
11008
  }
10968
11009
  const width = this.opentui.symbols.getBufferWidth(bufferPtr);
10969
11010
  const height = this.opentui.symbols.getBufferHeight(bufferPtr);
10970
- return new OptimizedBuffer(this, bufferPtr, width, height, { id: "current buffer" });
11011
+ return new OptimizedBuffer(this, bufferPtr, width, height, { id: "current buffer", widthMethod: "unicode" });
10971
11012
  }
10972
11013
  bufferGetCharPtr(buffer) {
10973
11014
  const ptr4 = this.opentui.symbols.bufferGetCharPtr(buffer);
@@ -11092,7 +11133,7 @@ class FFIRenderLib {
11092
11133
  if (!bufferPtr) {
11093
11134
  throw new Error(`Failed to create optimized buffer: ${width}x${height}`);
11094
11135
  }
11095
- return new OptimizedBuffer(this, bufferPtr, width, height, { respectAlpha, id });
11136
+ return new OptimizedBuffer(this, bufferPtr, width, height, { respectAlpha, id, widthMethod });
11096
11137
  }
11097
11138
  destroyOptimizedBuffer(bufferPtr) {
11098
11139
  this.opentui.symbols.destroyOptimizedBuffer(bufferPtr);
@@ -11152,6 +11193,12 @@ class FFIRenderLib {
11152
11193
  setupTerminal(renderer, useAlternateScreen) {
11153
11194
  this.opentui.symbols.setupTerminal(renderer, useAlternateScreen);
11154
11195
  }
11196
+ suspendRenderer(renderer) {
11197
+ this.opentui.symbols.suspendRenderer(renderer);
11198
+ }
11199
+ resumeRenderer(renderer) {
11200
+ this.opentui.symbols.resumeRenderer(renderer);
11201
+ }
11155
11202
  queryPixelResolution(renderer) {
11156
11203
  this.opentui.symbols.queryPixelResolution(renderer);
11157
11204
  }
@@ -11780,6 +11827,33 @@ class FFIRenderLib {
11780
11827
  const responseBytes = this.encoder.encode(response);
11781
11828
  this.opentui.symbols.processCapabilityResponse(renderer, responseBytes, responseBytes.length);
11782
11829
  }
11830
+ encodeUnicode(text, widthMethod) {
11831
+ const textBytes = this.encoder.encode(text);
11832
+ const widthMethodCode = widthMethod === "wcwidth" ? 0 : 1;
11833
+ const outPtrBuffer = new ArrayBuffer(8);
11834
+ const outLenBuffer = new ArrayBuffer(8);
11835
+ const success = this.opentui.symbols.encodeUnicode(textBytes, textBytes.length, ptr3(outPtrBuffer), ptr3(outLenBuffer), widthMethodCode);
11836
+ if (!success) {
11837
+ return null;
11838
+ }
11839
+ const outPtrView = new BigUint64Array(outPtrBuffer);
11840
+ const outLenView = new BigUint64Array(outLenBuffer);
11841
+ const resultPtr = Number(outPtrView[0]);
11842
+ const resultLen = Number(outLenView[0]);
11843
+ if (resultLen === 0) {
11844
+ return { ptr: resultPtr, data: [] };
11845
+ }
11846
+ const byteLen = resultLen * EncodedCharStruct.size;
11847
+ const raw = toArrayBuffer4(resultPtr, 0, byteLen);
11848
+ const data = EncodedCharStruct.unpackList(raw, resultLen);
11849
+ return { ptr: resultPtr, data };
11850
+ }
11851
+ freeUnicode(encoded) {
11852
+ this.opentui.symbols.freeUnicode(encoded.ptr, encoded.data.length);
11853
+ }
11854
+ bufferDrawChar(buffer, char, x, y, fg2, bg2, attributes = 0) {
11855
+ this.opentui.symbols.bufferDrawChar(buffer, char, x, y, fg2.buffer, bg2.buffer, attributes);
11856
+ }
11783
11857
  createSyntaxStyle() {
11784
11858
  const stylePtr = this.opentui.symbols.createSyntaxStyle();
11785
11859
  if (!stylePtr) {
@@ -15222,25 +15296,28 @@ Captured output:
15222
15296
  this.internalPause();
15223
15297
  this._suspendedMouseEnabled = this._useMouse;
15224
15298
  this.disableMouse();
15225
- this._keyHandler.suspend();
15226
15299
  this._stdinBuffer.clear();
15300
+ this.stdin.removeListener("data", this.stdinListener);
15301
+ this.lib.suspendRenderer(this.rendererPtr);
15227
15302
  if (this.stdin.setRawMode) {
15228
15303
  this.stdin.setRawMode(false);
15229
15304
  }
15230
- this.stdin.pause();
15231
15305
  }
15232
15306
  resume() {
15233
15307
  if (this.stdin.setRawMode) {
15234
15308
  this.stdin.setRawMode(true);
15235
15309
  }
15236
- this.stdin.resume();
15237
- this._keyHandler.resume();
15310
+ this.stdin.on("data", this.stdinListener);
15311
+ this.lib.resumeRenderer(this.rendererPtr);
15238
15312
  if (this._suspendedMouseEnabled) {
15239
15313
  this.enableMouse();
15240
15314
  }
15315
+ this.currentRenderBuffer.clear(this.backgroundColor);
15241
15316
  this._controlState = this._previousControlState;
15242
15317
  if (this._previousControlState === "auto_started" /* AUTO_STARTED */ || this._previousControlState === "explicit_started" /* EXPLICIT_STARTED */) {
15243
15318
  this.internalStart();
15319
+ } else {
15320
+ this.requestRender();
15244
15321
  }
15245
15322
  }
15246
15323
  internalPause() {
@@ -15515,7 +15592,7 @@ Captured output:
15515
15592
  if (this.currentSelection) {
15516
15593
  this.walkSelectableRenderables(currentContainer, this.currentSelection.bounds, selectedRenderables, touchedRenderables);
15517
15594
  for (const renderable of this.currentSelection.touchedRenderables) {
15518
- if (!touchedRenderables.includes(renderable)) {
15595
+ if (!touchedRenderables.includes(renderable) && !renderable.isDestroyed) {
15519
15596
  renderable.onSelectionChanged(null);
15520
15597
  }
15521
15598
  }
@@ -15576,5 +15653,5 @@ Captured output:
15576
15653
 
15577
15654
  export { __toESM, __commonJS, __export, __require, Edge, Gutter, exports_src, BorderChars, getBorderFromSides, getBorderSides, borderCharsToArray, BorderCharArrays, nonAlphanumericKeys, parseKeypress, 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, hastToStyledText, LinearScrollAccel, MacOSScrollAccel, StdinBuffer, 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, ExtmarksController, createExtmarksController, TerminalPalette, createTerminalPalette, TextBuffer, LogLevel2 as LogLevel, setRenderLibPath, resolveRenderLib, OptimizedBuffer, h, isVNode, maybeMakeRenderable, wrapWithDelegates, instantiate, delegate, isValidPercentage, LayoutEvents, RenderableEvents, isRenderable, BaseRenderable, Renderable, RootRenderable, ANSI, capture, ConsolePosition, TerminalConsole, getObjectsInViewport, MouseEvent, MouseButton, createCliRenderer, CliRenderEvents, RendererControlState, CliRenderer };
15578
15655
 
15579
- //# debugId=30281CA4D2B7A01164756E2164756E21
15580
- //# sourceMappingURL=index-31ycf9q5.js.map
15656
+ //# debugId=587CA1E559D65E6264756E2164756E21
15657
+ //# sourceMappingURL=index-rkpj2eng.js.map