@opentuah/core 0.1.80 → 0.1.84

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
@@ -37,6 +37,7 @@ import {
37
37
  TextAttributes,
38
38
  TextBuffer,
39
39
  TreeSitterClient,
40
+ VTermStyleFlags,
40
41
  addDefaultParsers,
41
42
  attributesWithLink,
42
43
  bg,
@@ -145,10 +146,11 @@ import {
145
146
  treeSitterToTextChunks,
146
147
  underline,
147
148
  visualizeRenderableTree,
149
+ vtermDataToStyledText,
148
150
  white,
149
151
  wrapWithDelegates,
150
152
  yellow
151
- } from "./index-0envey0s.js";
153
+ } from "./index-0t4rap2j.js";
152
154
  // src/text-buffer-view.ts
153
155
  class TextBufferView {
154
156
  lib;
@@ -3893,21 +3895,10 @@ class LineNumberRenderable extends Renderable {
3893
3895
  this._inlineHighlights = inlineHighlights;
3894
3896
  this.requestRender();
3895
3897
  }
3896
- getInlineHighlights() {
3897
- return this._inlineHighlights;
3898
- }
3899
3898
  clearInlineHighlights() {
3900
3899
  this._inlineHighlights.clear();
3901
3900
  this.requestRender();
3902
3901
  }
3903
- setLineInlineHighlights(line, highlights) {
3904
- this._inlineHighlights.set(line, highlights);
3905
- this.requestRender();
3906
- }
3907
- clearLineInlineHighlights(line) {
3908
- this._inlineHighlights.delete(line);
3909
- this.requestRender();
3910
- }
3911
3902
  }
3912
3903
 
3913
3904
  // src/renderables/Diff.ts
@@ -4045,8 +4036,8 @@ function computeInlineHighlights(oldContent, newContent) {
4045
4036
  return { oldHighlight: null, newHighlight: null };
4046
4037
  }
4047
4038
  const { stringARange, stringBRange } = relativeChanges(oldContent, newContent);
4048
- const oldHighlight = stringARange.length > 0 ? { ...toDisplayColumns(oldContent, stringARange.location, stringARange.length), type: "removed-word" } : null;
4049
- const newHighlight = stringBRange.length > 0 ? { ...toDisplayColumns(newContent, stringBRange.location, stringBRange.length), type: "added-word" } : null;
4039
+ const oldHighlight = stringARange.length > 0 ? toDisplayColumns(oldContent, stringARange.location, stringARange.length) : null;
4040
+ const newHighlight = stringBRange.length > 0 ? toDisplayColumns(newContent, stringBRange.location, stringBRange.length) : null;
4050
4041
  return { oldHighlight, newHighlight };
4051
4042
  }
4052
4043
 
@@ -4122,8 +4113,8 @@ class DiffRenderable extends Renderable {
4122
4113
  this._addedLineNumberBg = parseColor(options.addedLineNumberBg ?? "transparent");
4123
4114
  this._removedLineNumberBg = parseColor(options.removedLineNumberBg ?? "transparent");
4124
4115
  this._disableWordHighlights = options.disableWordHighlights ?? false;
4125
- this._addedWordBg = options.addedWordBg ? parseColor(options.addedWordBg) : this._addedBg.brighten(1.15);
4126
- this._removedWordBg = options.removedWordBg ? parseColor(options.removedWordBg) : this._removedBg.brighten(1.15);
4116
+ this._addedWordBg = options.addedWordBg ? parseColor(options.addedWordBg) : this._addedBg.brighten(1.1);
4117
+ this._removedWordBg = options.removedWordBg ? parseColor(options.removedWordBg) : this._removedBg.brighten(1.1);
4127
4118
  this._hunkHeaderBg = parseColor(options.hunkHeaderBg ?? "#1a1a2e");
4128
4119
  this._hunkHeaderFg = parseColor(options.hunkHeaderFg ?? "#6688aa");
4129
4120
  if (this._diff) {
@@ -4131,35 +4122,32 @@ class DiffRenderable extends Renderable {
4131
4122
  this.buildView();
4132
4123
  }
4133
4124
  }
4134
- toLineHighlights(highlights, bg2) {
4135
- return highlights.map((h2) => ({ startCol: h2.startCol, endCol: h2.endCol, bg: bg2 }));
4136
- }
4137
4125
  processChangeBlockWithHighlights(removes, adds) {
4138
4126
  const leftLines = [];
4139
4127
  const rightLines = [];
4140
4128
  const maxLength = Math.max(removes.length, adds.length);
4141
4129
  const shouldDisplayDiffInChunk = !this._disableWordHighlights && adds.length === removes.length;
4142
- const diffTokensBefore = [];
4143
- const diffTokensAfter = [];
4130
+ const removedHighlights = [];
4131
+ const addedHighlights = [];
4144
4132
  if (shouldDisplayDiffInChunk) {
4145
4133
  for (let i = 0;i < removes.length; i++) {
4146
4134
  const remove = removes[i];
4147
4135
  const add = adds[i];
4148
4136
  if (remove.content.length < MaxIntraLineDiffStringLength && add.content.length < MaxIntraLineDiffStringLength) {
4149
4137
  const { oldHighlight, newHighlight } = computeInlineHighlights(remove.content, add.content);
4150
- diffTokensBefore[i] = oldHighlight;
4151
- diffTokensAfter[i] = newHighlight;
4138
+ removedHighlights[i] = oldHighlight;
4139
+ addedHighlights[i] = newHighlight;
4152
4140
  } else {
4153
- diffTokensBefore[i] = null;
4154
- diffTokensAfter[i] = null;
4141
+ removedHighlights[i] = null;
4142
+ addedHighlights[i] = null;
4155
4143
  }
4156
4144
  }
4157
4145
  }
4158
4146
  for (let j = 0;j < maxLength; j++) {
4159
4147
  const remove = j < removes.length ? removes[j] : null;
4160
4148
  const add = j < adds.length ? adds[j] : null;
4161
- const leftHighlight = shouldDisplayDiffInChunk && j < diffTokensBefore.length ? diffTokensBefore[j] : null;
4162
- const rightHighlight = shouldDisplayDiffInChunk && j < diffTokensAfter.length ? diffTokensAfter[j] : null;
4149
+ const leftRange = shouldDisplayDiffInChunk && j < removedHighlights.length ? removedHighlights[j] : null;
4150
+ const rightRange = shouldDisplayDiffInChunk && j < addedHighlights.length ? addedHighlights[j] : null;
4163
4151
  if (remove) {
4164
4152
  leftLines.push({
4165
4153
  content: remove.content,
@@ -4170,7 +4158,7 @@ class DiffRenderable extends Renderable {
4170
4158
  afterColor: this._removedSignColor
4171
4159
  },
4172
4160
  type: "remove",
4173
- inlineHighlights: leftHighlight ? [leftHighlight] : []
4161
+ inlineHighlights: leftRange ? [{ ...leftRange, bg: this._removedWordBg }] : []
4174
4162
  });
4175
4163
  } else {
4176
4164
  leftLines.push({
@@ -4189,7 +4177,7 @@ class DiffRenderable extends Renderable {
4189
4177
  afterColor: this._addedSignColor
4190
4178
  },
4191
4179
  type: "add",
4192
- inlineHighlights: rightHighlight ? [rightHighlight] : []
4180
+ inlineHighlights: rightRange ? [{ ...rightRange, bg: this._addedWordBg }] : []
4193
4181
  });
4194
4182
  } else {
4195
4183
  rightLines.push({
@@ -4565,7 +4553,7 @@ class DiffRenderable extends Renderable {
4565
4553
  if (line2.lineNum !== undefined)
4566
4554
  lineNumbers.set(lineIndex, line2.lineNum);
4567
4555
  if (line2.inlineHighlights?.length) {
4568
- inlineHighlights.set(lineIndex, this.toLineHighlights(line2.inlineHighlights, this._removedWordBg));
4556
+ inlineHighlights.set(lineIndex, line2.inlineHighlights);
4569
4557
  }
4570
4558
  lineIndex++;
4571
4559
  }
@@ -4581,7 +4569,7 @@ class DiffRenderable extends Renderable {
4581
4569
  if (line2.lineNum !== undefined)
4582
4570
  lineNumbers.set(lineIndex, line2.lineNum);
4583
4571
  if (line2.inlineHighlights?.length) {
4584
- inlineHighlights.set(lineIndex, this.toLineHighlights(line2.inlineHighlights, this._addedWordBg));
4572
+ inlineHighlights.set(lineIndex, line2.inlineHighlights);
4585
4573
  }
4586
4574
  lineIndex++;
4587
4575
  }
@@ -4810,7 +4798,7 @@ class DiffRenderable extends Renderable {
4810
4798
  leftLineSigns.set(index, line.sign);
4811
4799
  }
4812
4800
  if (line.inlineHighlights?.length) {
4813
- leftInlineHighlights.set(index, this.toLineHighlights(line.inlineHighlights, this._removedWordBg));
4801
+ leftInlineHighlights.set(index, line.inlineHighlights);
4814
4802
  }
4815
4803
  });
4816
4804
  finalRightLines.forEach((line, index) => {
@@ -4855,7 +4843,7 @@ class DiffRenderable extends Renderable {
4855
4843
  rightLineSigns.set(index, line.sign);
4856
4844
  }
4857
4845
  if (line.inlineHighlights?.length) {
4858
- rightInlineHighlights.set(index, this.toLineHighlights(line.inlineHighlights, this._addedWordBg));
4846
+ rightInlineHighlights.set(index, line.inlineHighlights);
4859
4847
  }
4860
4848
  });
4861
4849
  const leftContentFinal = finalLeftLines.map((l) => l.content).join(`
@@ -9122,12 +9110,119 @@ class TabSelectRenderable extends Renderable {
9122
9110
  this._keyBindingsMap = buildKeyBindingsMap(mergedBindings, this._keyAliasMap);
9123
9111
  }
9124
9112
  }
9113
+ // src/renderables/Terminal.ts
9114
+ var DEFAULT_FG = RGBA.fromHex("#d4d4d4");
9115
+ function trimEmptyLines(data) {
9116
+ while (data.lines.length > 0) {
9117
+ const lastLine = data.lines[data.lines.length - 1];
9118
+ const hasText = lastLine.spans.some((span) => span.text.trim().length > 0);
9119
+ if (hasText)
9120
+ break;
9121
+ data.lines.pop();
9122
+ }
9123
+ }
9124
+
9125
+ class StatelessTerminalRenderable extends TextBufferRenderable {
9126
+ _ansi;
9127
+ _cols;
9128
+ _rows;
9129
+ _limit;
9130
+ _trimEnd;
9131
+ _needsUpdate = true;
9132
+ _lineCount = 0;
9133
+ _lib;
9134
+ constructor(ctx, options) {
9135
+ super(ctx, { ...options, fg: DEFAULT_FG, wrapMode: "none" });
9136
+ this._ansi = options.ansi ?? "";
9137
+ this._cols = options.cols ?? 120;
9138
+ this._rows = options.rows ?? 40;
9139
+ this._limit = options.limit;
9140
+ this._trimEnd = options.trimEnd;
9141
+ this._lib = resolveRenderLib();
9142
+ }
9143
+ get lineCount() {
9144
+ return this._lineCount;
9145
+ }
9146
+ get ansi() {
9147
+ return this._ansi;
9148
+ }
9149
+ set ansi(value) {
9150
+ if (this._ansi !== value) {
9151
+ this._ansi = value;
9152
+ this._needsUpdate = true;
9153
+ this.requestRender();
9154
+ }
9155
+ }
9156
+ get cols() {
9157
+ return this._cols;
9158
+ }
9159
+ set cols(value) {
9160
+ if (this._cols !== value) {
9161
+ this._cols = value;
9162
+ this._needsUpdate = true;
9163
+ this.requestRender();
9164
+ }
9165
+ }
9166
+ get rows() {
9167
+ return this._rows;
9168
+ }
9169
+ set rows(value) {
9170
+ if (this._rows !== value) {
9171
+ this._rows = value;
9172
+ this._needsUpdate = true;
9173
+ this.requestRender();
9174
+ }
9175
+ }
9176
+ get limit() {
9177
+ return this._limit;
9178
+ }
9179
+ set limit(value) {
9180
+ if (this._limit !== value) {
9181
+ this._limit = value;
9182
+ this._needsUpdate = true;
9183
+ this.requestRender();
9184
+ }
9185
+ }
9186
+ get trimEnd() {
9187
+ return this._trimEnd;
9188
+ }
9189
+ set trimEnd(value) {
9190
+ if (this._trimEnd !== value) {
9191
+ this._trimEnd = value;
9192
+ this._needsUpdate = true;
9193
+ this.requestRender();
9194
+ }
9195
+ }
9196
+ renderSelf(buffer) {
9197
+ if (this._needsUpdate) {
9198
+ const data = this._lib.vtermPtyToJson(this._ansi, {
9199
+ cols: this._cols,
9200
+ rows: this._rows,
9201
+ limit: this._limit
9202
+ });
9203
+ if (this._trimEnd)
9204
+ trimEmptyLines(data);
9205
+ this.textBuffer.setStyledText(vtermDataToStyledText(data));
9206
+ this.updateTextInfo();
9207
+ this._lineCount = this.textBufferView.logicalLineInfo.lineStarts.length;
9208
+ this._needsUpdate = false;
9209
+ }
9210
+ super.renderSelf(buffer);
9211
+ }
9212
+ getScrollPositionForLine(lineNumber) {
9213
+ const clampedLine = Math.max(0, Math.min(lineNumber, this._lineCount - 1));
9214
+ const lineStarts = this.textBufferView.logicalLineInfo.lineStarts;
9215
+ const lineYOffset = lineStarts?.[clampedLine] ?? clampedLine;
9216
+ return this.y + lineYOffset;
9217
+ }
9218
+ }
9125
9219
  // src/index.ts
9126
9220
  import * as Yoga from "yoga-layout";
9127
9221
  export {
9128
9222
  yellow,
9129
9223
  wrapWithDelegates,
9130
9224
  white,
9225
+ vtermDataToStyledText,
9131
9226
  vstyles,
9132
9227
  visualizeRenderableTree,
9133
9228
  main as updateAssets,
@@ -9245,6 +9340,7 @@ export {
9245
9340
  addDefaultParsers,
9246
9341
  Yoga,
9247
9342
  VignetteEffect,
9343
+ VTermStyleFlags,
9248
9344
  VRenderable,
9249
9345
  TreeSitterClient,
9250
9346
  Timeline,
@@ -9264,6 +9360,7 @@ export {
9264
9360
  SyntaxStyle,
9265
9361
  StyledText,
9266
9362
  StdinBuffer,
9363
+ StatelessTerminalRenderable,
9267
9364
  SliderRenderable,
9268
9365
  Selection,
9269
9366
  SelectRenderableEvents,
@@ -9327,5 +9424,5 @@ export {
9327
9424
  ASCIIFont
9328
9425
  };
9329
9426
 
9330
- //# debugId=920E724ED4DA89FA64756E2164756E21
9427
+ //# debugId=F3E0750B0CE8050E64756E2164756E21
9331
9428
  //# sourceMappingURL=index.js.map