@opentui/core 0.3.0 → 0.3.2

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/ansi.d.ts CHANGED
@@ -2,6 +2,10 @@ export declare const ANSI: {
2
2
  switchToAlternateScreen: string;
3
3
  switchToMainScreen: string;
4
4
  reset: string;
5
+ resetScrollRegion: string;
6
+ home: string;
7
+ clearScreen: string;
8
+ clearSavedLines: string;
5
9
  scrollDown: (lines: number) => string;
6
10
  scrollUp: (lines: number) => string;
7
11
  moveCursor: (row: number, col: number) => string;
@@ -12525,7 +12525,51 @@ var AudioStatsStruct = defineStruct([
12525
12525
  ]);
12526
12526
 
12527
12527
  // src/zig.ts
12528
- var nativePackage = await import(`@opentui/core-${process.platform}-${process.arch}`);
12528
+ registerEnvVar({
12529
+ name: "OPENTUI_LIBC",
12530
+ description: "Select Linux native libc package. Supported values: glibc, musl.",
12531
+ type: "string",
12532
+ default: ""
12533
+ });
12534
+ function validateLinuxLibcOverride() {
12535
+ const libc = process.env.OPENTUI_LIBC;
12536
+ if (libc === undefined || libc === "" || libc === "glibc" || libc === "musl")
12537
+ return;
12538
+ throw new Error(`OPENTUI_LIBC must be "glibc" or "musl", got "${libc}"`);
12539
+ }
12540
+ async function resolveNativePackage() {
12541
+ if (process.platform === "darwin") {
12542
+ if (process.arch === "x64")
12543
+ return await import("@opentui/core-darwin-x64");
12544
+ if (process.arch === "arm64")
12545
+ return await import("@opentui/core-darwin-arm64");
12546
+ }
12547
+ if (process.platform === "linux") {
12548
+ validateLinuxLibcOverride();
12549
+ if (process.arch === "x64") {
12550
+ if (process.env.OPENTUI_LIBC === "musl") {
12551
+ return await import("@opentui/core-linux-x64-musl");
12552
+ } else {
12553
+ return await import("@opentui/core-linux-x64");
12554
+ }
12555
+ }
12556
+ if (process.arch === "arm64") {
12557
+ if (process.env.OPENTUI_LIBC === "musl") {
12558
+ return await import("@opentui/core-linux-arm64-musl");
12559
+ } else {
12560
+ return await import("@opentui/core-linux-arm64");
12561
+ }
12562
+ }
12563
+ }
12564
+ if (process.platform === "win32") {
12565
+ if (process.arch === "x64")
12566
+ return await import("@opentui/core-win32-x64");
12567
+ if (process.arch === "arm64")
12568
+ return await import("@opentui/core-win32-arm64");
12569
+ }
12570
+ throw new Error(`opentui is not supported on the current platform: ${process.platform}-${process.arch}`);
12571
+ }
12572
+ var nativePackage = await resolveNativePackage();
12529
12573
  var targetLibPath = nativePackage.default;
12530
12574
  if (isBunfsPath(targetLibPath)) {
12531
12575
  targetLibPath = targetLibPath.replace("../", "");
@@ -18583,6 +18627,8 @@ class CodeRenderable extends TextBufferRenderable {
18583
18627
  _onHighlight;
18584
18628
  _onChunks;
18585
18629
  _highlightingPromise = Promise.resolve();
18630
+ _renderedLineSources;
18631
+ _mappedLineInfo;
18586
18632
  _contentDefaultOptions = {
18587
18633
  content: "",
18588
18634
  conceal: true,
@@ -18621,9 +18667,40 @@ class CodeRenderable extends TextBufferRenderable {
18621
18667
  return;
18622
18668
  }
18623
18669
  this.textBuffer.setText(value);
18670
+ this.setRenderedLineSources(undefined);
18624
18671
  this.updateTextInfo();
18625
18672
  }
18626
18673
  }
18674
+ get lineInfo() {
18675
+ if (!this._renderedLineSources)
18676
+ return super.lineInfo;
18677
+ if (this._mappedLineInfo)
18678
+ return this._mappedLineInfo;
18679
+ const lineInfo = super.lineInfo;
18680
+ const renderedLineSources = this._renderedLineSources;
18681
+ this._mappedLineInfo = {
18682
+ ...lineInfo,
18683
+ lineSources: lineInfo.lineSources.map((line) => renderedLineSources[line] ?? line)
18684
+ };
18685
+ return this._mappedLineInfo;
18686
+ }
18687
+ get wrapMode() {
18688
+ return super.wrapMode;
18689
+ }
18690
+ set wrapMode(value) {
18691
+ if (super.wrapMode !== value) {
18692
+ this._mappedLineInfo = undefined;
18693
+ super.wrapMode = value;
18694
+ }
18695
+ }
18696
+ onResize(width, height) {
18697
+ this._mappedLineInfo = undefined;
18698
+ super.onResize(width, height);
18699
+ }
18700
+ updateTextInfo() {
18701
+ this._mappedLineInfo = undefined;
18702
+ super.updateTextInfo();
18703
+ }
18627
18704
  get filetype() {
18628
18705
  return this._filetype;
18629
18706
  }
@@ -18733,6 +18810,7 @@ class CodeRenderable extends TextBufferRenderable {
18733
18810
  this._shouldRenderTextBuffer = true;
18734
18811
  } else if (shouldDrawUnstyledNow) {
18735
18812
  this.textBuffer.setText(content);
18813
+ this.setRenderedLineSources(undefined);
18736
18814
  this._shouldRenderTextBuffer = true;
18737
18815
  } else {
18738
18816
  this._shouldRenderTextBuffer = false;
@@ -18791,6 +18869,7 @@ class CodeRenderable extends TextBufferRenderable {
18791
18869
  enabled: this._conceal,
18792
18870
  baseHighlight: this._baseHighlight
18793
18871
  });
18872
+ const renderedLineSources = this._onChunks ? undefined : this.getConcealLinesSourceMap(content, highlights);
18794
18873
  chunks = await this.transformChunks(chunks, context);
18795
18874
  if (snapshotId !== this._highlightSnapshotId) {
18796
18875
  this.requestRender();
@@ -18800,8 +18879,10 @@ class CodeRenderable extends TextBufferRenderable {
18800
18879
  return;
18801
18880
  const styledText = new StyledText(chunks);
18802
18881
  this.textBuffer.setStyledText(styledText);
18882
+ this.setRenderedLineSources(renderedLineSources);
18803
18883
  } else {
18804
18884
  this.textBuffer.setText(content);
18885
+ this.setRenderedLineSources(undefined);
18805
18886
  }
18806
18887
  this._shouldRenderTextBuffer = true;
18807
18888
  this._isHighlighting = false;
@@ -18817,6 +18898,7 @@ class CodeRenderable extends TextBufferRenderable {
18817
18898
  if (this.isDestroyed)
18818
18899
  return;
18819
18900
  this.textBuffer.setText(content);
18901
+ this.setRenderedLineSources(undefined);
18820
18902
  this._shouldRenderTextBuffer = true;
18821
18903
  this._isHighlighting = false;
18822
18904
  this._highlightsDirty = false;
@@ -18824,6 +18906,95 @@ class CodeRenderable extends TextBufferRenderable {
18824
18906
  this.requestRender();
18825
18907
  }
18826
18908
  }
18909
+ setRenderedLineSources(lineSources) {
18910
+ this._renderedLineSources = lineSources;
18911
+ this._mappedLineInfo = undefined;
18912
+ }
18913
+ static isIdentityLineSources(lineSources) {
18914
+ for (let i = 0;i < lineSources.length; i++) {
18915
+ if (lineSources[i] !== i)
18916
+ return false;
18917
+ }
18918
+ return true;
18919
+ }
18920
+ static getMergedConcealLineRanges(highlights) {
18921
+ const ranges = [];
18922
+ for (const highlight of highlights) {
18923
+ const meta = highlight[3];
18924
+ if (meta?.concealLines === undefined)
18925
+ continue;
18926
+ const group = highlight[2];
18927
+ const isEmptyConceal = meta.conceal === "" || meta.conceal === undefined && (group === "conceal" || group.startsWith("conceal."));
18928
+ if (isEmptyConceal) {
18929
+ ranges.push([highlight[0], highlight[1]]);
18930
+ }
18931
+ }
18932
+ if (ranges.length <= 1)
18933
+ return ranges;
18934
+ ranges.sort((a, b) => a[0] - b[0]);
18935
+ let writeIndex = 0;
18936
+ for (let i = 1;i < ranges.length; i++) {
18937
+ const current = ranges[writeIndex];
18938
+ const next = ranges[i];
18939
+ if (next[0] <= current[1]) {
18940
+ current[1] = Math.max(current[1], next[1]);
18941
+ } else {
18942
+ writeIndex++;
18943
+ ranges[writeIndex] = next;
18944
+ }
18945
+ }
18946
+ ranges.length = writeIndex + 1;
18947
+ return ranges;
18948
+ }
18949
+ getConcealLinesSourceMap(content, highlights) {
18950
+ if (!this._conceal || content.length === 0)
18951
+ return;
18952
+ const concealLineRanges = CodeRenderable.getMergedConcealLineRanges(highlights);
18953
+ if (concealLineRanges.length === 0)
18954
+ return;
18955
+ const lineSources = [];
18956
+ let sourceLine = 0;
18957
+ let lineStart = 0;
18958
+ let rangeIndex = 0;
18959
+ let currentRenderedLineHasText = false;
18960
+ const setCurrentRenderedLineSource = (line, hasText) => {
18961
+ if (lineSources.length === 0) {
18962
+ lineSources.push(line);
18963
+ } else if (!currentRenderedLineHasText) {
18964
+ lineSources[lineSources.length - 1] = line;
18965
+ }
18966
+ if (hasText)
18967
+ currentRenderedLineHasText = true;
18968
+ };
18969
+ while (lineStart <= content.length) {
18970
+ const newlineOffset = content.indexOf(`
18971
+ `, lineStart);
18972
+ const lineEnd = newlineOffset === -1 ? content.length : newlineOffset;
18973
+ while (rangeIndex < concealLineRanges.length && concealLineRanges[rangeIndex][1] <= lineStart) {
18974
+ rangeIndex++;
18975
+ }
18976
+ const range = concealLineRanges[rangeIndex];
18977
+ const fullyConcealed = !!range && lineEnd > lineStart && range[0] <= lineStart && range[1] >= lineEnd;
18978
+ const lineBreakConcealed = newlineOffset !== -1 && !!range && range[0] <= newlineOffset && range[1] >= newlineOffset;
18979
+ if (!fullyConcealed || !lineBreakConcealed) {
18980
+ const hasText = lineEnd > lineStart && !fullyConcealed;
18981
+ if (hasText || newlineOffset !== -1 || !fullyConcealed) {
18982
+ setCurrentRenderedLineSource(sourceLine, hasText);
18983
+ }
18984
+ if (newlineOffset !== -1 && !lineBreakConcealed) {
18985
+ lineSources.push(sourceLine + 1);
18986
+ currentRenderedLineHasText = false;
18987
+ }
18988
+ }
18989
+ sourceLine++;
18990
+ if (newlineOffset === -1)
18991
+ break;
18992
+ lineStart = newlineOffset + 1;
18993
+ }
18994
+ if (lineSources.length === 0 || CodeRenderable.isIdentityLineSources(lineSources))
18995
+ return;
18996
+ return lineSources;
18997
+ }
18827
18998
  getLineHighlights(lineIdx) {
18828
18999
  return this.textBuffer.getLineHighlights(lineIdx);
18829
19000
  }
@@ -21523,6 +21694,10 @@ var ANSI = {
21523
21694
  switchToAlternateScreen: "\x1B[?1049h",
21524
21695
  switchToMainScreen: "\x1B[?1049l",
21525
21696
  reset: "\x1B[0m",
21697
+ resetScrollRegion: "\x1B[r",
21698
+ home: "\x1B[H",
21699
+ clearScreen: "\x1B[2J",
21700
+ clearSavedLines: "\x1B[3J",
21526
21701
  scrollDown: (lines) => `\x1B[${lines}T`,
21527
21702
  scrollUp: (lines) => `\x1B[${lines}S`,
21528
21703
  moveCursor: (row, col) => `\x1B[${row};${col}H`,
@@ -23339,6 +23514,26 @@ Captured external output:
23339
23514
  }
23340
23515
  }
23341
23516
  }
23517
+ resetSplitFooterForReplay(options = {}) {
23518
+ if (this._isDestroyed)
23519
+ return;
23520
+ if (this._screenMode !== "split-footer" || this._externalOutputMode !== "capture-stdout") {
23521
+ throw new Error('resetSplitFooterForReplay requires screenMode "split-footer" and externalOutputMode "capture-stdout"');
23522
+ }
23523
+ if (!this._terminalIsSetup || this._controlState === "explicit_suspended" /* EXPLICIT_SUSPENDED */) {
23524
+ throw new Error("resetSplitFooterForReplay requires an active terminal");
23525
+ }
23526
+ this.flushPendingSplitOutputBeforeTransition(true);
23527
+ this.externalOutputQueue.clear();
23528
+ this.abortSplitStartupCursorSeed();
23529
+ this.clearPendingSplitFooterTransition();
23530
+ this.resetSplitScrollback();
23531
+ this.currentRenderBuffer.clear(this.backgroundColor);
23532
+ this.nextRenderBuffer.clear(this.backgroundColor);
23533
+ this.forceFullRepaintRequested = true;
23534
+ this.writeOut(ANSI.resetScrollRegion + ANSI.reset + ANSI.home + ANSI.clearScreen + (options.clearSavedLines ? ANSI.clearSavedLines : "") + ANSI.home);
23535
+ this.requestRender();
23536
+ }
23342
23537
  getSnapshotWidth(value, fallback) {
23343
23538
  const rawValue = value ?? fallback;
23344
23539
  if (!Number.isFinite(rawValue)) {
@@ -25231,5 +25426,5 @@ Captured external output:
25231
25426
 
25232
25427
  export { __export, __require, MeasureMode, exports_src, isValidBorderStyle, parseBorderStyle, BorderChars, getBorderFromSides, getBorderSides, borderCharsToArray, BorderCharArrays, KeyEvent, PasteEvent, KeyHandler, InternalKeyHandler, DEFAULT_FOREGROUND_RGB, DEFAULT_BACKGROUND_RGB, normalizeIndexedColorIndex, ansi256IndexToRgb, RGBA, normalizeColorValue, hexToRgb, rgbToHex, hsvToRgb, parseColor, fonts, measureText, getCharacterPositions, coordinateToCharacterIndex, renderFontToFrameBuffer, TextAttributes, ATTRIBUTE_BASE_BITS, ATTRIBUTE_BASE_MASK, getBaseAttributes, DebugOverlayCorner, TargetChannel, createTextAttributes, attributesWithLink, getLinkId, 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, link, t, hastToStyledText, SystemClock, nonAlphanumericKeys, terminalNamedSingleStrokeKeys, parseKeypress, LinearScrollAccel, MacOSScrollAccel, parseAlign, parseAlignItems, parseBoxSizing, parseDimension, parseDirection, parseDisplay, parseEdge, parseFlexDirection, parseGutter, parseJustify, parseLogLevel, parseMeasureMode, parseOverflow, parsePositionType, parseUnit, parseWrap, MouseParser, Selection, convertGlobalToLocalSelection, ASCIIFontSelectionHelper, envRegistry, registerEnvVar, clearEnvCache, generateEnvMarkdown, generateEnvColored, env, StdinParser, treeSitterToTextChunks, treeSitterToStyledText, stringWidth2 as stringWidth, addDefaultParsers, TreeSitterClient, DataPathsManager, getDataPaths, extensionToFiletype, basenameToFiletype, extToFiletype, pathToFiletype, infoStringToFiletype, getTreeSitterClient, ExtmarksController, createExtmarksController, TerminalPalette, createTerminalPalette, normalizeTerminalPalette, buildTerminalPaletteSignature, decodePasteBytes, stripAnsiSequences, detectLinks, TextBuffer, LogLevel2 as LogLevel, setRenderLibPath, resolveRenderLib, OptimizedBuffer, h, isVNode, maybeMakeRenderable, wrapWithDelegates, instantiate, delegate, LayoutEvents, RenderableEvents, isRenderable, BaseRenderable, Renderable, RootRenderable, TextBufferView, EditBuffer, EditorView, convertThemeToStyles, SyntaxStyle, ANSI, BoxRenderable, TextBufferRenderable, CodeRenderable, isTextNodeRenderable, TextNodeRenderable, RootTextNodeRenderable, TextRenderable, NativeSpanFeed, defaultKeyAliases, mergeKeyAliases, mergeKeyBindings, getKeyBindingAction, buildKeyBindingsMap, capture, ConsolePosition, TerminalConsole, getObjectsInViewport, EditBufferRenderableEvents, isEditBufferRenderable, EditBufferRenderable, buildKittyKeyboardFlags, MouseEvent, MouseButton, createCliRenderer, CliRenderEvents, RendererControlState, CliRenderer };
25233
25428
 
25234
- //# debugId=F97AFCBE61BE955464756E2164756E21
25235
- //# sourceMappingURL=index-081xws23.js.map
25429
+ //# debugId=E9E2E0C5F621879764756E2164756E21
25430
+ //# sourceMappingURL=index-218h9p3f.js.map