@opentui/core 0.6.1 → 0.6.3

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.
@@ -1,6 +1,7 @@
1
1
  import { Writable } from "node:stream";
2
2
  import { ResourceContext } from "./buffer.js";
3
3
  import { NativeSessionRenderStatus, type NativeContextHandle, type NativeContextOptions, type NativeSceneFrameRequest, type NativeSessionCapabilities, type NativeSessionControl, type NativeSessionKittyImageTransportStatus, type NativeSessionOptions, type NativeSessionRendererOptions, type NativeSessionTerminalOptions, type RenderLib, type SessionHandle, type NativeSplitSnapshot } from "./zig.js";
4
+ import type { ProgramStatus } from "./types.js";
4
5
  export interface NativeSessionScheduler {
5
6
  /** Monotonic nanoseconds. */
6
7
  now(): bigint;
@@ -89,6 +90,8 @@ export declare class NativeSession {
89
90
  control(command: NativeSessionControl): void;
90
91
  writeClipboard(target: number, bytes: Uint8Array): boolean;
91
92
  triggerNotification(message: string, title?: string): boolean;
93
+ /** Returns false while the terminal is inactive or output is full. Invalid reports throw. */
94
+ setProgramStatus(status: ProgramStatus): boolean;
92
95
  setKittyImageTransport(mode: number): void;
93
96
  getKittyImageTransport(): NativeSessionKittyImageTransportStatus;
94
97
  pollKittyImageTransport(): boolean;
@@ -206,6 +206,7 @@ var nativeSymbols = {
206
206
  returns: "i32"
207
207
  },
208
208
  ot_edit_buffer_measure_text: { args: ["ptr", "buffer", "ptr", "u32", "buffer"], returns: "i32" },
209
+ ot_edit_measure_text: { args: ["ptr", "ptr", "u32", "u32", "u32", "buffer"], returns: "i32" },
209
210
  ot_edit_buffer_set_defaults: { args: ["ptr", "buffer", "u32", "buffer"], returns: "i32" },
210
211
  ot_syntax_style_register: { args: ["ptr", "buffer", "ptr", "u32", "buffer", "buffer"], returns: "i32" },
211
212
  ot_syntax_style_resolve: { args: ["ptr", "buffer", "ptr", "u32", "buffer"], returns: "i32" },
@@ -1273,6 +1274,20 @@ var nativeLayouts = {
1273
1274
  color: { offset: 16, size: 8, alignment: 2, type: "[4]u16" }
1274
1275
  }
1275
1276
  },
1277
+ ot_session_program_status: {
1278
+ size: 32,
1279
+ alignment: 4,
1280
+ fields: {
1281
+ state: { offset: 0, size: 4, alignment: 4, type: "u32" },
1282
+ kind: { offset: 4, size: 4, alignment: 4, type: "u32" },
1283
+ fields: { offset: 8, size: 4, alignment: 4, type: "u32" },
1284
+ progress: { offset: 12, size: 4, alignment: 4, type: "u32" },
1285
+ id_len: { offset: 16, size: 4, alignment: 4, type: "u32" },
1286
+ app_len: { offset: 20, size: 4, alignment: 4, type: "u32" },
1287
+ title_len: { offset: 24, size: 4, alignment: 4, type: "u32" },
1288
+ message_len: { offset: 28, size: 4, alignment: 4, type: "u32" }
1289
+ }
1290
+ },
1276
1291
  ot_session_capabilities: {
1277
1292
  size: 144,
1278
1293
  alignment: 4,
@@ -1913,11 +1928,22 @@ var nativeConstants = {
1913
1928
  OT_CONTROL_CURSOR: 8,
1914
1929
  OT_CONTROL_RESET_BACKGROUND: 9,
1915
1930
  OT_CONTROL_PALETTE_QUERY: 10,
1931
+ OT_CONTROL_PROGRAM_STATUS: 11,
1916
1932
  OT_CURSOR_POSITION: 1,
1917
1933
  OT_CURSOR_STYLE: 2,
1918
1934
  OT_CURSOR_BLINKING: 4,
1919
1935
  OT_CURSOR_COLOR: 8,
1920
1936
  OT_CURSOR_MOUSE_POINTER: 16,
1937
+ OT_PROGRAM_STATE_IDLE: 1,
1938
+ OT_PROGRAM_STATE_WORKING: 2,
1939
+ OT_PROGRAM_STATE_DONE: 3,
1940
+ OT_PROGRAM_STATE_BLOCKED: 4,
1941
+ OT_PROGRAM_STATE_ERROR: 5,
1942
+ OT_PROGRAM_STATE_CLEAR: 6,
1943
+ OT_PROGRAM_KIND_PERMISSION: 1,
1944
+ OT_PROGRAM_KIND_QUESTION: 2,
1945
+ OT_PROGRAM_KIND_AUTH: 3,
1946
+ OT_PROGRAM_STATUS_PROGRESS: 1,
1921
1947
  OT_CAP_KITTY_KEYBOARD: 1,
1922
1948
  OT_CAP_KITTY_GRAPHICS: 2,
1923
1949
  OT_CAP_RGB: 4,
@@ -1935,6 +1961,7 @@ var nativeConstants = {
1935
1961
  OT_CAP_NOTIFICATIONS: 16384,
1936
1962
  OT_CAP_EXPLICIT_CURSOR_POSITIONING: 32768,
1937
1963
  OT_CAP_REMOTE: 65536,
1964
+ OT_CAP_PROGRAM_STATUS: 131072,
1938
1965
  OT_TERMINAL_UNINITIALIZED: 0,
1939
1966
  OT_TERMINAL_SETTING_UP: 1,
1940
1967
  OT_TERMINAL_ACTIVE: 2,
@@ -5761,6 +5788,19 @@ registerEnvVar2({
5761
5788
  });
5762
5789
  var CURSOR_STYLE_TO_ID = { block: 0, line: 1, underline: 2, default: 3 };
5763
5790
  var CURSOR_ID_TO_STYLE = ["block", "line", "underline", "default"];
5791
+ var PROGRAM_STATE_TO_ID = {
5792
+ idle: nativeConstants.OT_PROGRAM_STATE_IDLE,
5793
+ working: nativeConstants.OT_PROGRAM_STATE_WORKING,
5794
+ done: nativeConstants.OT_PROGRAM_STATE_DONE,
5795
+ blocked: nativeConstants.OT_PROGRAM_STATE_BLOCKED,
5796
+ error: nativeConstants.OT_PROGRAM_STATE_ERROR,
5797
+ clear: nativeConstants.OT_PROGRAM_STATE_CLEAR
5798
+ };
5799
+ var PROGRAM_KIND_TO_ID = {
5800
+ permission: nativeConstants.OT_PROGRAM_KIND_PERMISSION,
5801
+ question: nativeConstants.OT_PROGRAM_KIND_QUESTION,
5802
+ auth: nativeConstants.OT_PROGRAM_KIND_AUTH
5803
+ };
5764
5804
  var MOUSE_STYLE_TO_ID = {
5765
5805
  auto: nativeConstants.OT_MOUSE_POINTER_AUTO,
5766
5806
  default: nativeConstants.OT_MOUSE_POINTER_DEFAULT,
@@ -5895,6 +5935,50 @@ function sessionBytes(bytes, label) {
5895
5935
  }
5896
5936
  return new Uint8Array(typedArrayAccessors.buffer.get.call(bytes), typedArrayAccessors.byteOffset.get.call(bytes), length);
5897
5937
  }
5938
+ function programStatusPayload(status, encoder) {
5939
+ const layout = nativeLayouts.ot_session_program_status;
5940
+ const { state, kind, progress, id, app, title, message } = status;
5941
+ const stateId = typeof state === "string" ? PROGRAM_STATE_TO_ID[state] : undefined;
5942
+ if (typeof stateId !== "number")
5943
+ throw new TypeError("Unknown program status state");
5944
+ const header = new Uint32Array(layout.size / 4);
5945
+ header[layout.fields.state.offset / 4] = stateId;
5946
+ if (kind != null) {
5947
+ const kindId = typeof kind === "string" ? PROGRAM_KIND_TO_ID[kind] : undefined;
5948
+ if (typeof kindId !== "number")
5949
+ throw new TypeError("Unknown program status kind");
5950
+ header[layout.fields.kind.offset / 4] = kindId;
5951
+ }
5952
+ if (progress != null) {
5953
+ if (typeof progress !== "number")
5954
+ throw new TypeError("Program status progress must be a number");
5955
+ if (!isFFIU32(progress))
5956
+ throw new RangeError("Program status progress must be an integer percentage");
5957
+ header[layout.fields.fields.offset / 4] = nativeConstants.OT_PROGRAM_STATUS_PROGRESS;
5958
+ header[layout.fields.progress.offset / 4] = progress;
5959
+ }
5960
+ if (id === "")
5961
+ throw new RangeError("Program status id must not be empty; omit it for the root record");
5962
+ const text = { id, app, title, message };
5963
+ const parts = ["id", "app", "title", "message"].map((name) => {
5964
+ const value = text[name];
5965
+ if (value == null)
5966
+ return new Uint8Array(0);
5967
+ if (typeof value !== "string")
5968
+ throw new TypeError(`Program status ${name} must be a string`);
5969
+ const bytes = encoder.encode(value.slice(0, NATIVE_SESSION_CONTROL_PACKET_BYTES2 + 1));
5970
+ header[layout.fields[`${name}_len`].offset / 4] = bytes.byteLength;
5971
+ return bytes;
5972
+ });
5973
+ const payload = new Uint8Array(layout.size + parts.reduce((total, part) => total + part.byteLength, 0));
5974
+ payload.set(new Uint8Array(header.buffer));
5975
+ let offset = layout.size;
5976
+ for (const part of parts) {
5977
+ payload.set(part, offset);
5978
+ offset += part.byteLength;
5979
+ }
5980
+ return payload;
5981
+ }
5898
5982
  function pixelInput(data, length) {
5899
5983
  if (typeof data === "number" || typeof data === "bigint")
5900
5984
  return toPointer(data);
@@ -7735,6 +7819,7 @@ class FFIRenderLib2 {
7735
7819
  clipboardServices = new Map;
7736
7820
  clipboardOperations = new Map;
7737
7821
  audioEngines = new Map;
7822
+ editMeasureContext;
7738
7823
  invalidStandaloneHandle = new BigUint64Array(nativeLayouts.ot_handle.size / 8);
7739
7824
  encoder = new TextEncoder;
7740
7825
  emptyBytes = new Uint8Array(0);
@@ -8692,6 +8777,16 @@ class FFIRenderLib2 {
8692
8777
  nativeResult("ot_edit_buffer_measure_text", this.opentui.symbols.ot_edit_buffer_measure_text(pointer, handle, viewOrNull(input), input.length, output));
8693
8778
  return output[0];
8694
8779
  }
8780
+ editMeasureText(bytes, widthMethod, tabWidth) {
8781
+ const method = widthMethodId(widthMethod, "editor");
8782
+ const width = toSafeFFIU32Length(tabWidth, "Edit buffer tab width");
8783
+ const input = sessionBytes(bytes, "Edit buffer measure length");
8784
+ const output = new Uint32Array(1);
8785
+ this.editMeasureContext ??= this.createContext({ objectCapacity: 1, renderCellsMax: 1 });
8786
+ const pointer = this.nativeContextPointer(this.editMeasureContext, "ot_edit_measure_text");
8787
+ nativeResult("ot_edit_measure_text", this.opentui.symbols.ot_edit_measure_text(pointer, viewOrNull(input), input.length, method, width, output));
8788
+ return output[0];
8789
+ }
8695
8790
  contextEditBufferSetDefaults(context, editBuffer, mask, style) {
8696
8791
  const handle = encodeContextHandle(context, editBuffer);
8697
8792
  const fields = toSafeFFIU32Length(mask, "Editor default style mask");
@@ -9547,6 +9642,10 @@ class FFIRenderLib2 {
9547
9642
  record[kind] = nativeConstants.OT_CONTROL_KITTY_KEYBOARD_FLAGS;
9548
9643
  record[layout.fields.argument.offset / 4] = toSafeFFIU32Length(command.flags, "Session Kitty keyboard flags");
9549
9644
  break;
9645
+ case "program-status":
9646
+ record[kind] = nativeConstants.OT_CONTROL_PROGRAM_STATUS;
9647
+ bytes = programStatusPayload(command.status, this.encoder);
9648
+ break;
9550
9649
  case "restore-modes":
9551
9650
  record[kind] = nativeConstants.OT_CONTROL_RESTORE_MODES;
9552
9651
  break;
@@ -9680,6 +9779,7 @@ class FFIRenderLib2 {
9680
9779
  notifications: flag(nativeConstants.OT_CAP_NOTIFICATIONS),
9681
9780
  explicit_cursor_positioning: flag(nativeConstants.OT_CAP_EXPLICIT_CURSOR_POSITIONING),
9682
9781
  remote: flag(nativeConstants.OT_CAP_REMOTE),
9782
+ program_status: flag(nativeConstants.OT_CAP_PROGRAM_STATUS),
9683
9783
  unicode: widthMethodFromCode(output[layout.fields.width_method.offset / 4]),
9684
9784
  multiplexer: ["none", "tmux", "zellij", "screen", "unknown"][output[layout.fields.multiplexer.offset / 4]],
9685
9785
  image_protocol: ["auto", "kitty", "sixel", "blocks"][output[layout.fields.image_protocol.offset / 4]],
@@ -10554,10 +10654,13 @@ class FFIRenderLib2 {
10554
10654
  if (this.clipboardServices.size > 0) {
10555
10655
  throw new Error("Cannot dispose OpenTUI native library while clipboard services are active");
10556
10656
  }
10557
- if (this.nativeContexts.size !== this.audioEngines.size) {
10657
+ if (this.nativeContexts.size !== this.audioEngines.size + Number(this.editMeasureContext !== undefined)) {
10558
10658
  throw new NativeError2("dispose", -6 /* ContextBusy */);
10559
10659
  }
10560
10660
  this.yogaHost?.dispose();
10661
+ if (this.editMeasureContext)
10662
+ this.releaseContext(this.editMeasureContext);
10663
+ this.editMeasureContext = undefined;
10561
10664
  for (const [engine, context] of this.audioEngines) {
10562
10665
  this.releaseContext(context);
10563
10666
  this.audioEngines.delete(engine);
@@ -12519,5 +12622,5 @@ var yoga_default = Yoga;
12519
12622
 
12520
12623
  export { nativeConstants, toArrayBuffer, singleton, getSingleton, destroySingleton, envRegistry2, registerEnvVar2, clearEnvCache2, generateEnvMarkdown2, generateEnvColored2, env2, stringWidth, resolveBundledFilePath2, Worker, TextAttributes2, ATTRIBUTE_BASE_BITS2, ATTRIBUTE_BASE_MASK2, getBaseAttributes2, DebugOverlayCorner2, TargetChannel2, DEFAULT_FOREGROUND_RGB2, DEFAULT_BACKGROUND_RGB2, normalizeIndexedColorIndex2, ansi256IndexToRgb2, RGBA2, normalizeColorValue2, hexToRgb2, rgbToHex2, hsvToRgb2, parseColor2, createTextAttributes2, attributesWithLink2, getLinkId2, visualizeRenderableTree2, isStyledText2, StyledText2, stringToStyledText2, black2, red2, green2, yellow2, blue2, magenta2, cyan2, white2, brightBlack2, brightRed2, brightGreen2, brightYellow2, brightBlue2, brightMagenta2, brightCyan2, brightWhite2, bgBlack2, bgRed2, bgGreen2, bgYellow2, bgBlue2, bgMagenta2, bgCyan2, bgWhite2, bold2, italic2, underline2, strikethrough2, dim2, reverse2, blink2, fg2, bg2, link2, t2, YogaEnumKind, YogaFloatKind, YogaValueKind, sceneSetEnum, sceneGetEnum, sceneSetFloat, sceneSetValue, sceneGetValue, sceneSetDimension, UNDEFINED_VALUE, parseYogaValue, SpanInfoStruct, NativeAudioStreamFormat2, NativeAudioStreamState2, NativeAudioStreamStateNames, NativeAudioStreamCloseReason2, isBunfsPath, normalizeBunfsPath, resolveDefaultParserAsset, resolveDefaultTreeSitterWorkerPath, resolveTreeSitterWasm, NativeAudioStreamState3, NativeAudioStreamCloseReason3, NativeAudioStreamFormat3, MAX_LINK_URL_BYTES2, NativeTextViewCommand2, NativeEditCommand2, NativeEditPositionQuery2, NativeEditorStyleMask2, NativeEditHighlightOperation2, NativeEditorCommand2, NativeEditorSelectionOperation2, NativeEditorPositionQuery2, NativeEditEvent2, NativeStyleGroup, NativeStyleFlags, NATIVE_EDGE_NONE2, NativeBorder2, NativeSceneHook2, NativeSceneFrame2, NativeScenePaintPhase2, NATIVE_BUFFER_TEXT_BYTES_MAX2, NativeSessionState2, NativeSessionRenderStatus2, NATIVE_SESSION_CONTROL_PACKET_BYTES2, NativeSessionTerminalPhase2, NativeSessionPumpStatus2, NativeStatus2, NativeError2, NativeClipboardOperationStatus2, NativeClipboardStartStatus2, NativeClipboardCancelStatus2, NativeClipboardCopyStatus2, NativeClipboardDestroyStatus2, NativeClipboardShutdownStatus2, SceneStaging, NativePaintRecorder, LogLevel2, FFIRenderLib2, setRenderLibPath2, resolveRenderLib2, Align2, BoxSizing2, Dimension2, Direction2, Display2, Edge2, Errata2, ExperimentalFeature2, FlexDirection2, Gutter2, Justify2, LogLevel3, MeasureMode2, NodeType2, Overflow2, PositionType2, Unit2, Wrap2, ALIGN_AUTO2, ALIGN_FLEX_START2, ALIGN_CENTER2, ALIGN_FLEX_END2, ALIGN_STRETCH2, ALIGN_BASELINE2, ALIGN_SPACE_BETWEEN2, ALIGN_SPACE_AROUND2, ALIGN_SPACE_EVENLY2, BOX_SIZING_BORDER_BOX2, BOX_SIZING_CONTENT_BOX2, DIMENSION_WIDTH2, DIMENSION_HEIGHT2, DIRECTION_INHERIT2, DIRECTION_LTR2, DIRECTION_RTL2, DISPLAY_FLEX2, DISPLAY_NONE2, DISPLAY_CONTENTS2, EDGE_LEFT2, EDGE_TOP2, EDGE_RIGHT2, EDGE_BOTTOM2, EDGE_START2, EDGE_END2, EDGE_HORIZONTAL2, EDGE_VERTICAL2, EDGE_ALL2, ERRATA_NONE2, ERRATA_STRETCH_FLEX_BASIS2, ERRATA_ABSOLUTE_POSITION_WITHOUT_INSETS_EXCLUDES_PADDING2, ERRATA_ABSOLUTE_PERCENT_AGAINST_INNER_SIZE2, ERRATA_ALL2, ERRATA_CLASSIC2, EXPERIMENTAL_FEATURE_WEB_FLEX_BASIS2, FLEX_DIRECTION_COLUMN2, FLEX_DIRECTION_COLUMN_REVERSE2, FLEX_DIRECTION_ROW2, FLEX_DIRECTION_ROW_REVERSE2, GUTTER_COLUMN2, GUTTER_ROW2, GUTTER_ALL2, JUSTIFY_FLEX_START2, JUSTIFY_CENTER2, JUSTIFY_FLEX_END2, JUSTIFY_SPACE_BETWEEN2, JUSTIFY_SPACE_AROUND2, JUSTIFY_SPACE_EVENLY2, LOG_LEVEL_ERROR2, LOG_LEVEL_WARN2, LOG_LEVEL_INFO2, LOG_LEVEL_DEBUG2, LOG_LEVEL_VERBOSE2, LOG_LEVEL_FATAL2, MEASURE_MODE_UNDEFINED2, MEASURE_MODE_EXACTLY2, MEASURE_MODE_AT_MOST2, NODE_TYPE_DEFAULT2, NODE_TYPE_TEXT2, OVERFLOW_VISIBLE2, OVERFLOW_HIDDEN2, OVERFLOW_SCROLL2, POSITION_TYPE_STATIC2, POSITION_TYPE_RELATIVE2, POSITION_TYPE_ABSOLUTE2, UNIT_UNDEFINED2, UNIT_POINT2, UNIT_PERCENT2, UNIT_AUTO2, WRAP_NO_WRAP2, WRAP_WRAP2, WRAP_WRAP_REVERSE2, YogaStatus2, YogaError2, Config2, Node2, exports_yoga, yoga_default };
12521
12624
 
12522
- //# debugId=8BF9D27184F628AC64756E2164756E21
12523
- //# sourceMappingURL=chunk-bun-wsqkxxm5.js.map
12625
+ //# debugId=F20A9528ED9106B664756E2164756E21
12626
+ //# sourceMappingURL=chunk-bun-e2gttx65.js.map