@opentui/core 0.1.95 → 0.1.97

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.
@@ -8812,13 +8812,6 @@ class TreeSitterClient extends EventEmitter2 {
8812
8812
  const { logType, data } = event.data;
8813
8813
  const message = data.join(" ");
8814
8814
  this.emit("worker:log", logType, message);
8815
- if (logType === "log") {
8816
- console.log("TSWorker:", ...data);
8817
- } else if (logType === "error") {
8818
- console.error("TSWorker:", ...data);
8819
- } else if (logType === "warn") {
8820
- console.warn("TSWorker:", ...data);
8821
- }
8822
8815
  return;
8823
8816
  }
8824
8817
  }
@@ -10700,7 +10693,7 @@ import { EventEmitter as EventEmitter4 } from "events";
10700
10693
 
10701
10694
  // src/buffer.ts
10702
10695
  import { toArrayBuffer, ptr } from "bun:ffi";
10703
- function packDrawOptions(border2, shouldFill, titleAlignment) {
10696
+ function packDrawOptions(border2, shouldFill, titleAlignment, bottomTitleAlignment) {
10704
10697
  let packed = 0;
10705
10698
  if (border2 === true) {
10706
10699
  packed |= 15;
@@ -10723,7 +10716,9 @@ function packDrawOptions(border2, shouldFill, titleAlignment) {
10723
10716
  right: 2
10724
10717
  };
10725
10718
  const alignment = alignmentMap[titleAlignment];
10719
+ const bottomAlignment = alignmentMap[bottomTitleAlignment];
10726
10720
  packed |= alignment << 5;
10721
+ packed |= bottomAlignment << 7;
10727
10722
  return packed;
10728
10723
  }
10729
10724
 
@@ -10955,8 +10950,8 @@ class OptimizedBuffer {
10955
10950
  this.guard();
10956
10951
  const style = parseBorderStyle(options.borderStyle, "single");
10957
10952
  const borderChars = options.customBorderChars ?? BorderCharArrays[style];
10958
- const packedOptions = packDrawOptions(options.border, options.shouldFill ?? false, options.titleAlignment || "left");
10959
- this.lib.bufferDrawBox(this.bufferPtr, options.x, options.y, options.width, options.height, borderChars, packedOptions, options.borderColor, options.backgroundColor, options.title ?? null);
10953
+ const packedOptions = packDrawOptions(options.border, options.shouldFill ?? false, options.titleAlignment || "left", options.bottomTitleAlignment || "left");
10954
+ this.lib.bufferDrawBox(this.bufferPtr, options.x, options.y, options.width, options.height, borderChars, packedOptions, options.borderColor, options.backgroundColor, options.title ?? null, options.bottomTitle ?? null);
10960
10955
  }
10961
10956
  pushScissorRect(x, y, width, height) {
10962
10957
  this.guard();
@@ -12084,7 +12079,7 @@ function getOpenTUILib(libPath) {
12084
12079
  returns: "void"
12085
12080
  },
12086
12081
  bufferDrawBox: {
12087
- args: ["ptr", "i32", "i32", "u32", "u32", "ptr", "u32", "ptr", "ptr", "ptr", "u32"],
12082
+ args: ["ptr", "i32", "i32", "u32", "u32", "ptr", "u32", "ptr", "ptr", "ptr", "u32", "ptr", "u32"],
12088
12083
  returns: "void"
12089
12084
  },
12090
12085
  bufferPushScissorRect: {
@@ -13252,11 +13247,14 @@ class FFIRenderLib {
13252
13247
  });
13253
13248
  this.opentui.symbols.bufferDrawGrid(buffer, borderChars, borderFg.buffer, borderBg.buffer, columnOffsets, columnCount, rowOffsets, rowCount, ptr4(optionsBuffer));
13254
13249
  }
13255
- bufferDrawBox(buffer, x, y, width, height, borderChars, packedOptions, borderColor, backgroundColor, title) {
13250
+ bufferDrawBox(buffer, x, y, width, height, borderChars, packedOptions, borderColor, backgroundColor, title, bottomTitle) {
13256
13251
  const titleBytes = title ? this.encoder.encode(title) : null;
13257
13252
  const titleLen = title ? titleBytes.length : 0;
13258
13253
  const titlePtr = title ? titleBytes : null;
13259
- this.opentui.symbols.bufferDrawBox(buffer, x, y, width, height, borderChars, packedOptions, borderColor.buffer, backgroundColor.buffer, titlePtr, titleLen);
13254
+ const bottomTitleBytes = bottomTitle ? this.encoder.encode(bottomTitle) : null;
13255
+ const bottomTitleLen = bottomTitle ? bottomTitleBytes.length : 0;
13256
+ const bottomTitlePtr = bottomTitle ? bottomTitleBytes : null;
13257
+ this.opentui.symbols.bufferDrawBox(buffer, x, y, width, height, borderChars, packedOptions, borderColor.buffer, backgroundColor.buffer, titlePtr, titleLen, bottomTitlePtr, bottomTitleLen);
13260
13258
  }
13261
13259
  bufferResize(buffer, width, height) {
13262
13260
  this.opentui.symbols.bufferResize(buffer, width, height);
@@ -15974,244 +15972,776 @@ function delegate(mapping, vnode) {
15974
15972
  return vnode;
15975
15973
  }
15976
15974
 
15977
- // src/console.ts
15978
- import { EventEmitter as EventEmitter7 } from "events";
15979
- import { Console } from "console";
15980
- import fs from "fs";
15981
- import path5 from "path";
15982
- import util2 from "util";
15983
-
15984
- // src/lib/output.capture.ts
15985
- import { Writable } from "stream";
15975
+ // src/edit-buffer.ts
15986
15976
  import { EventEmitter as EventEmitter6 } from "events";
15987
15977
 
15988
- class Capture extends EventEmitter6 {
15989
- output = [];
15990
- constructor() {
15978
+ class EditBuffer extends EventEmitter6 {
15979
+ static registry = new Map;
15980
+ static nativeEventsSubscribed = false;
15981
+ lib;
15982
+ bufferPtr;
15983
+ textBufferPtr;
15984
+ id;
15985
+ _destroyed = false;
15986
+ _textBytes = [];
15987
+ _singleTextBytes = null;
15988
+ _singleTextMemId = null;
15989
+ _syntaxStyle;
15990
+ constructor(lib, ptr5) {
15991
15991
  super();
15992
+ this.lib = lib;
15993
+ this.bufferPtr = ptr5;
15994
+ this.textBufferPtr = lib.editBufferGetTextBuffer(ptr5);
15995
+ this.id = lib.editBufferGetId(ptr5);
15996
+ EditBuffer.registry.set(this.id, this);
15997
+ EditBuffer.subscribeToNativeEvents(lib);
15992
15998
  }
15993
- get size() {
15994
- return this.output.length;
15999
+ static create(widthMethod) {
16000
+ const lib = resolveRenderLib();
16001
+ const ptr5 = lib.createEditBuffer(widthMethod);
16002
+ return new EditBuffer(lib, ptr5);
15995
16003
  }
15996
- write(stream, data) {
15997
- this.output.push({ stream, output: data });
15998
- this.emit("write", stream, data);
16004
+ static subscribeToNativeEvents(lib) {
16005
+ if (EditBuffer.nativeEventsSubscribed)
16006
+ return;
16007
+ EditBuffer.nativeEventsSubscribed = true;
16008
+ lib.onAnyNativeEvent((name, data) => {
16009
+ const buffer = new Uint16Array(data);
16010
+ if (name.startsWith("eb_") && buffer.length >= 1) {
16011
+ const id = buffer[0];
16012
+ const instance = EditBuffer.registry.get(id);
16013
+ if (instance) {
16014
+ const eventName = name.slice(3);
16015
+ const eventData = data.slice(2);
16016
+ instance.emit(eventName, eventData);
16017
+ }
16018
+ }
16019
+ });
15999
16020
  }
16000
- claimOutput() {
16001
- const output = this.output.map((o) => o.output).join("");
16002
- this.clear();
16003
- return output;
16021
+ guard() {
16022
+ if (this._destroyed)
16023
+ throw new Error("EditBuffer is destroyed");
16004
16024
  }
16005
- clear() {
16006
- this.output = [];
16025
+ get ptr() {
16026
+ this.guard();
16027
+ return this.bufferPtr;
16007
16028
  }
16008
- }
16009
-
16010
- class CapturedWritableStream extends Writable {
16011
- stream;
16012
- capture;
16013
- isTTY = true;
16014
- columns = process.stdout.columns || 80;
16015
- rows = process.stdout.rows || 24;
16016
- constructor(stream, capture) {
16017
- super();
16018
- this.stream = stream;
16019
- this.capture = capture;
16029
+ setText(text) {
16030
+ this.guard();
16031
+ const textBytes = this.lib.encoder.encode(text);
16032
+ if (this._singleTextMemId !== null) {
16033
+ this.lib.textBufferReplaceMemBuffer(this.textBufferPtr, this._singleTextMemId, textBytes, false);
16034
+ } else {
16035
+ this._singleTextMemId = this.lib.textBufferRegisterMemBuffer(this.textBufferPtr, textBytes, false);
16036
+ }
16037
+ this._singleTextBytes = textBytes;
16038
+ this.lib.editBufferSetTextFromMem(this.bufferPtr, this._singleTextMemId);
16020
16039
  }
16021
- _write(chunk, encoding, callback) {
16022
- const data = chunk.toString();
16023
- this.capture.write(this.stream, data);
16024
- callback();
16040
+ setTextOwned(text) {
16041
+ this.guard();
16042
+ const textBytes = this.lib.encoder.encode(text);
16043
+ this.lib.editBufferSetText(this.bufferPtr, textBytes);
16025
16044
  }
16026
- getColorDepth() {
16027
- return process.stdout.getColorDepth?.() || 8;
16045
+ replaceText(text) {
16046
+ this.guard();
16047
+ const textBytes = this.lib.encoder.encode(text);
16048
+ this._textBytes.push(textBytes);
16049
+ const memId = this.lib.textBufferRegisterMemBuffer(this.textBufferPtr, textBytes, false);
16050
+ this.lib.editBufferReplaceTextFromMem(this.bufferPtr, memId);
16028
16051
  }
16029
- }
16030
-
16031
- // src/lib/keymapping.ts
16032
- var defaultKeyAliases = {
16033
- enter: "return",
16034
- esc: "escape"
16035
- };
16036
- function mergeKeyAliases(defaults, custom) {
16037
- return { ...defaults, ...custom };
16038
- }
16039
- function mergeKeyBindings(defaults, custom) {
16040
- const map = new Map;
16041
- for (const binding of defaults) {
16042
- const key = getKeyBindingKey(binding);
16043
- map.set(key, binding);
16052
+ replaceTextOwned(text) {
16053
+ this.guard();
16054
+ const textBytes = this.lib.encoder.encode(text);
16055
+ this.lib.editBufferReplaceText(this.bufferPtr, textBytes);
16044
16056
  }
16045
- for (const binding of custom) {
16046
- const key = getKeyBindingKey(binding);
16047
- map.set(key, binding);
16057
+ getLineCount() {
16058
+ this.guard();
16059
+ return this.lib.textBufferGetLineCount(this.textBufferPtr);
16048
16060
  }
16049
- return Array.from(map.values());
16050
- }
16051
- function getKeyBindingKey(binding) {
16052
- return `${binding.name}:${binding.ctrl ? 1 : 0}:${binding.shift ? 1 : 0}:${binding.meta ? 1 : 0}:${binding.super ? 1 : 0}`;
16053
- }
16054
- function buildKeyBindingsMap(bindings, aliasMap) {
16055
- const map = new Map;
16056
- const aliases = aliasMap || {};
16057
- for (const binding of bindings) {
16058
- const key = getKeyBindingKey(binding);
16059
- map.set(key, binding.action);
16061
+ getText() {
16062
+ this.guard();
16063
+ const maxSize = 1024 * 1024;
16064
+ const textBytes = this.lib.editBufferGetText(this.bufferPtr, maxSize);
16065
+ if (!textBytes)
16066
+ return "";
16067
+ return this.lib.decoder.decode(textBytes);
16060
16068
  }
16061
- for (const binding of bindings) {
16062
- const normalizedName = aliases[binding.name] || binding.name;
16063
- if (normalizedName !== binding.name) {
16064
- const aliasedKey = getKeyBindingKey({ ...binding, name: normalizedName });
16065
- map.set(aliasedKey, binding.action);
16066
- }
16069
+ insertChar(char) {
16070
+ this.guard();
16071
+ this.lib.editBufferInsertChar(this.bufferPtr, char);
16067
16072
  }
16068
- return map;
16069
- }
16070
- function keyBindingToString(binding) {
16071
- const parts = [];
16072
- if (binding.ctrl)
16073
- parts.push("ctrl");
16074
- if (binding.shift)
16075
- parts.push("shift");
16076
- if (binding.meta)
16077
- parts.push("meta");
16078
- if (binding.super)
16079
- parts.push("super");
16080
- parts.push(binding.name);
16081
- return parts.join("+");
16082
- }
16083
-
16084
- // src/console.ts
16085
- function getCallerInfo() {
16086
- const err = new Error;
16087
- const stackLines = err.stack?.split(`
16088
- `).slice(5) || [];
16089
- if (!stackLines.length)
16090
- return null;
16091
- const callerLine = stackLines[0].trim();
16092
- const regex = /at\s+(?:([\w$.<>]+)\s+\()?((?:\/|[A-Za-z]:\\)[^:]+):(\d+):(\d+)\)?/;
16093
- const match = callerLine.match(regex);
16094
- if (!match)
16095
- return null;
16096
- const functionName = match[1] || "<anonymous>";
16097
- const fullPath = match[2];
16098
- const fileName = fullPath.split(/[\\/]/).pop() || "<unknown>";
16099
- const lineNumber = parseInt(match[3], 10) || 0;
16100
- const columnNumber = parseInt(match[4], 10) || 0;
16101
- return { functionName, fullPath, fileName, lineNumber, columnNumber };
16102
- }
16103
- var capture = singleton("ConsoleCapture", () => new Capture);
16104
- registerEnvVar({
16105
- name: "OTUI_USE_CONSOLE",
16106
- description: "Whether to use the console. Will not capture console output if set to false.",
16107
- type: "boolean",
16108
- default: true
16109
- });
16110
- registerEnvVar({
16111
- name: "SHOW_CONSOLE",
16112
- description: "Show the console at startup if set to true.",
16113
- type: "boolean",
16114
- default: false
16115
- });
16116
-
16117
- class TerminalConsoleCache extends EventEmitter7 {
16118
- _cachedLogs = [];
16119
- MAX_CACHE_SIZE = 1000;
16120
- _collectCallerInfo = false;
16121
- _cachingEnabled = true;
16122
- _originalConsole = null;
16123
- get cachedLogs() {
16124
- return this._cachedLogs;
16073
+ insertText(text) {
16074
+ this.guard();
16075
+ this.lib.editBufferInsertText(this.bufferPtr, text);
16125
16076
  }
16126
- constructor() {
16127
- super();
16077
+ deleteChar() {
16078
+ this.guard();
16079
+ this.lib.editBufferDeleteChar(this.bufferPtr);
16128
16080
  }
16129
- activate() {
16130
- if (!this._originalConsole) {
16131
- this._originalConsole = global.console;
16132
- }
16133
- this.setupConsoleCapture();
16134
- this.overrideConsoleMethods();
16081
+ deleteCharBackward() {
16082
+ this.guard();
16083
+ this.lib.editBufferDeleteCharBackward(this.bufferPtr);
16135
16084
  }
16136
- setupConsoleCapture() {
16137
- if (!env.OTUI_USE_CONSOLE)
16138
- return;
16139
- const mockStdout = new CapturedWritableStream("stdout", capture);
16140
- const mockStderr = new CapturedWritableStream("stderr", capture);
16141
- global.console = new Console({
16142
- stdout: mockStdout,
16143
- stderr: mockStderr,
16144
- colorMode: true,
16145
- inspectOptions: {
16146
- compact: false,
16147
- breakLength: 80,
16148
- depth: 2
16149
- }
16150
- });
16085
+ deleteRange(startLine, startCol, endLine, endCol) {
16086
+ this.guard();
16087
+ this.lib.editBufferDeleteRange(this.bufferPtr, startLine, startCol, endLine, endCol);
16151
16088
  }
16152
- overrideConsoleMethods() {
16153
- console.log = (...args) => {
16154
- this.appendToConsole("LOG" /* LOG */, ...args);
16155
- };
16156
- console.info = (...args) => {
16157
- this.appendToConsole("INFO" /* INFO */, ...args);
16158
- };
16159
- console.warn = (...args) => {
16160
- this.appendToConsole("WARN" /* WARN */, ...args);
16161
- };
16162
- console.error = (...args) => {
16163
- this.appendToConsole("ERROR" /* ERROR */, ...args);
16164
- };
16165
- console.debug = (...args) => {
16166
- this.appendToConsole("DEBUG" /* DEBUG */, ...args);
16167
- };
16089
+ newLine() {
16090
+ this.guard();
16091
+ this.lib.editBufferNewLine(this.bufferPtr);
16168
16092
  }
16169
- setCollectCallerInfo(enabled) {
16170
- this._collectCallerInfo = enabled;
16093
+ deleteLine() {
16094
+ this.guard();
16095
+ this.lib.editBufferDeleteLine(this.bufferPtr);
16171
16096
  }
16172
- clearConsole() {
16173
- this._cachedLogs = [];
16097
+ moveCursorLeft() {
16098
+ this.guard();
16099
+ this.lib.editBufferMoveCursorLeft(this.bufferPtr);
16174
16100
  }
16175
- setCachingEnabled(enabled) {
16176
- this._cachingEnabled = enabled;
16101
+ moveCursorRight() {
16102
+ this.guard();
16103
+ this.lib.editBufferMoveCursorRight(this.bufferPtr);
16177
16104
  }
16178
- deactivate() {
16179
- this.restoreOriginalConsole();
16105
+ moveCursorUp() {
16106
+ this.guard();
16107
+ this.lib.editBufferMoveCursorUp(this.bufferPtr);
16180
16108
  }
16181
- restoreOriginalConsole() {
16182
- if (this._originalConsole) {
16183
- global.console = this._originalConsole;
16184
- }
16109
+ moveCursorDown() {
16110
+ this.guard();
16111
+ this.lib.editBufferMoveCursorDown(this.bufferPtr);
16185
16112
  }
16186
- addLogEntry(level, ...args) {
16187
- const callerInfo = this._collectCallerInfo ? getCallerInfo() : null;
16188
- const logEntry = [new Date, level, args, callerInfo];
16189
- if (this._cachingEnabled) {
16190
- if (this._cachedLogs.length >= this.MAX_CACHE_SIZE) {
16191
- this._cachedLogs.shift();
16192
- }
16193
- this._cachedLogs.push(logEntry);
16194
- }
16195
- return logEntry;
16113
+ gotoLine(line) {
16114
+ this.guard();
16115
+ this.lib.editBufferGotoLine(this.bufferPtr, line);
16196
16116
  }
16197
- appendToConsole(level, ...args) {
16198
- if (this._cachedLogs.length >= this.MAX_CACHE_SIZE) {
16199
- this._cachedLogs.shift();
16200
- }
16201
- const entry = this.addLogEntry(level, ...args);
16202
- this.emit("entry", entry);
16117
+ setCursor(line, col) {
16118
+ this.guard();
16119
+ this.lib.editBufferSetCursor(this.bufferPtr, line, col);
16203
16120
  }
16204
- destroy() {
16205
- this.deactivate();
16121
+ setCursorToLineCol(line, col) {
16122
+ this.guard();
16123
+ this.lib.editBufferSetCursorToLineCol(this.bufferPtr, line, col);
16206
16124
  }
16207
- }
16208
- var terminalConsoleCache = singleton("TerminalConsoleCache", () => {
16209
- const terminalConsoleCache2 = new TerminalConsoleCache;
16210
- process.on("exit", () => {
16211
- terminalConsoleCache2.destroy();
16212
- });
16213
- return terminalConsoleCache2;
16214
- });
16125
+ setCursorByOffset(offset) {
16126
+ this.guard();
16127
+ this.lib.editBufferSetCursorByOffset(this.bufferPtr, offset);
16128
+ }
16129
+ getCursorPosition() {
16130
+ this.guard();
16131
+ return this.lib.editBufferGetCursorPosition(this.bufferPtr);
16132
+ }
16133
+ getNextWordBoundary() {
16134
+ this.guard();
16135
+ const boundary = this.lib.editBufferGetNextWordBoundary(this.bufferPtr);
16136
+ return {
16137
+ row: boundary.row,
16138
+ col: boundary.col,
16139
+ offset: boundary.offset
16140
+ };
16141
+ }
16142
+ getPrevWordBoundary() {
16143
+ this.guard();
16144
+ const boundary = this.lib.editBufferGetPrevWordBoundary(this.bufferPtr);
16145
+ return {
16146
+ row: boundary.row,
16147
+ col: boundary.col,
16148
+ offset: boundary.offset
16149
+ };
16150
+ }
16151
+ getEOL() {
16152
+ this.guard();
16153
+ const boundary = this.lib.editBufferGetEOL(this.bufferPtr);
16154
+ return {
16155
+ row: boundary.row,
16156
+ col: boundary.col,
16157
+ offset: boundary.offset
16158
+ };
16159
+ }
16160
+ offsetToPosition(offset) {
16161
+ this.guard();
16162
+ const result = this.lib.editBufferOffsetToPosition(this.bufferPtr, offset);
16163
+ if (!result)
16164
+ return null;
16165
+ return { row: result.row, col: result.col };
16166
+ }
16167
+ positionToOffset(row, col) {
16168
+ this.guard();
16169
+ return this.lib.editBufferPositionToOffset(this.bufferPtr, row, col);
16170
+ }
16171
+ getLineStartOffset(row) {
16172
+ this.guard();
16173
+ return this.lib.editBufferGetLineStartOffset(this.bufferPtr, row);
16174
+ }
16175
+ getTextRange(startOffset, endOffset) {
16176
+ this.guard();
16177
+ if (startOffset >= endOffset)
16178
+ return "";
16179
+ const maxSize = 1024 * 1024;
16180
+ const textBytes = this.lib.editBufferGetTextRange(this.bufferPtr, startOffset, endOffset, maxSize);
16181
+ if (!textBytes)
16182
+ return "";
16183
+ return this.lib.decoder.decode(textBytes);
16184
+ }
16185
+ getTextRangeByCoords(startRow, startCol, endRow, endCol) {
16186
+ this.guard();
16187
+ const maxSize = 1024 * 1024;
16188
+ const textBytes = this.lib.editBufferGetTextRangeByCoords(this.bufferPtr, startRow, startCol, endRow, endCol, maxSize);
16189
+ if (!textBytes)
16190
+ return "";
16191
+ return this.lib.decoder.decode(textBytes);
16192
+ }
16193
+ debugLogRope() {
16194
+ this.guard();
16195
+ this.lib.editBufferDebugLogRope(this.bufferPtr);
16196
+ }
16197
+ undo() {
16198
+ this.guard();
16199
+ const maxSize = 256;
16200
+ const metaBytes = this.lib.editBufferUndo(this.bufferPtr, maxSize);
16201
+ if (!metaBytes)
16202
+ return null;
16203
+ return this.lib.decoder.decode(metaBytes);
16204
+ }
16205
+ redo() {
16206
+ this.guard();
16207
+ const maxSize = 256;
16208
+ const metaBytes = this.lib.editBufferRedo(this.bufferPtr, maxSize);
16209
+ if (!metaBytes)
16210
+ return null;
16211
+ return this.lib.decoder.decode(metaBytes);
16212
+ }
16213
+ canUndo() {
16214
+ this.guard();
16215
+ return this.lib.editBufferCanUndo(this.bufferPtr);
16216
+ }
16217
+ canRedo() {
16218
+ this.guard();
16219
+ return this.lib.editBufferCanRedo(this.bufferPtr);
16220
+ }
16221
+ clearHistory() {
16222
+ this.guard();
16223
+ this.lib.editBufferClearHistory(this.bufferPtr);
16224
+ }
16225
+ setDefaultFg(fg2) {
16226
+ this.guard();
16227
+ this.lib.textBufferSetDefaultFg(this.textBufferPtr, fg2);
16228
+ }
16229
+ setDefaultBg(bg2) {
16230
+ this.guard();
16231
+ this.lib.textBufferSetDefaultBg(this.textBufferPtr, bg2);
16232
+ }
16233
+ setDefaultAttributes(attributes) {
16234
+ this.guard();
16235
+ this.lib.textBufferSetDefaultAttributes(this.textBufferPtr, attributes);
16236
+ }
16237
+ resetDefaults() {
16238
+ this.guard();
16239
+ this.lib.textBufferResetDefaults(this.textBufferPtr);
16240
+ }
16241
+ setSyntaxStyle(style) {
16242
+ this.guard();
16243
+ this._syntaxStyle = style ?? undefined;
16244
+ this.lib.textBufferSetSyntaxStyle(this.textBufferPtr, style?.ptr ?? null);
16245
+ }
16246
+ getSyntaxStyle() {
16247
+ this.guard();
16248
+ return this._syntaxStyle ?? null;
16249
+ }
16250
+ addHighlight(lineIdx, highlight) {
16251
+ this.guard();
16252
+ this.lib.textBufferAddHighlight(this.textBufferPtr, lineIdx, highlight);
16253
+ }
16254
+ addHighlightByCharRange(highlight) {
16255
+ this.guard();
16256
+ this.lib.textBufferAddHighlightByCharRange(this.textBufferPtr, highlight);
16257
+ }
16258
+ removeHighlightsByRef(hlRef) {
16259
+ this.guard();
16260
+ this.lib.textBufferRemoveHighlightsByRef(this.textBufferPtr, hlRef);
16261
+ }
16262
+ clearLineHighlights(lineIdx) {
16263
+ this.guard();
16264
+ this.lib.textBufferClearLineHighlights(this.textBufferPtr, lineIdx);
16265
+ }
16266
+ clearAllHighlights() {
16267
+ this.guard();
16268
+ this.lib.textBufferClearAllHighlights(this.textBufferPtr);
16269
+ }
16270
+ getLineHighlights(lineIdx) {
16271
+ this.guard();
16272
+ return this.lib.textBufferGetLineHighlights(this.textBufferPtr, lineIdx);
16273
+ }
16274
+ clear() {
16275
+ this.guard();
16276
+ this.lib.editBufferClear(this.bufferPtr);
16277
+ }
16278
+ destroy() {
16279
+ if (this._destroyed)
16280
+ return;
16281
+ this._destroyed = true;
16282
+ EditBuffer.registry.delete(this.id);
16283
+ this.lib.destroyEditBuffer(this.bufferPtr);
16284
+ }
16285
+ }
16286
+
16287
+ // src/editor-view.ts
16288
+ class EditorView {
16289
+ lib;
16290
+ viewPtr;
16291
+ editBuffer;
16292
+ _destroyed = false;
16293
+ _extmarksController;
16294
+ _textBufferViewPtr;
16295
+ constructor(lib, ptr5, editBuffer) {
16296
+ this.lib = lib;
16297
+ this.viewPtr = ptr5;
16298
+ this.editBuffer = editBuffer;
16299
+ }
16300
+ static create(editBuffer, viewportWidth, viewportHeight) {
16301
+ const lib = resolveRenderLib();
16302
+ const viewPtr = lib.createEditorView(editBuffer.ptr, viewportWidth, viewportHeight);
16303
+ return new EditorView(lib, viewPtr, editBuffer);
16304
+ }
16305
+ guard() {
16306
+ if (this._destroyed)
16307
+ throw new Error("EditorView is destroyed");
16308
+ }
16309
+ get ptr() {
16310
+ this.guard();
16311
+ return this.viewPtr;
16312
+ }
16313
+ setViewportSize(width, height) {
16314
+ this.guard();
16315
+ this.lib.editorViewSetViewportSize(this.viewPtr, width, height);
16316
+ }
16317
+ setViewport(x, y, width, height, moveCursor = true) {
16318
+ this.guard();
16319
+ this.lib.editorViewSetViewport(this.viewPtr, x, y, width, height, moveCursor);
16320
+ }
16321
+ getViewport() {
16322
+ this.guard();
16323
+ return this.lib.editorViewGetViewport(this.viewPtr);
16324
+ }
16325
+ setScrollMargin(margin) {
16326
+ this.guard();
16327
+ this.lib.editorViewSetScrollMargin(this.viewPtr, margin);
16328
+ }
16329
+ setWrapMode(mode) {
16330
+ this.guard();
16331
+ this.lib.editorViewSetWrapMode(this.viewPtr, mode);
16332
+ }
16333
+ getVirtualLineCount() {
16334
+ this.guard();
16335
+ return this.lib.editorViewGetVirtualLineCount(this.viewPtr);
16336
+ }
16337
+ getTotalVirtualLineCount() {
16338
+ this.guard();
16339
+ return this.lib.editorViewGetTotalVirtualLineCount(this.viewPtr);
16340
+ }
16341
+ setSelection(start, end, bgColor, fgColor) {
16342
+ this.guard();
16343
+ this.lib.editorViewSetSelection(this.viewPtr, start, end, bgColor || null, fgColor || null);
16344
+ }
16345
+ updateSelection(end, bgColor, fgColor) {
16346
+ this.guard();
16347
+ this.lib.editorViewUpdateSelection(this.viewPtr, end, bgColor || null, fgColor || null);
16348
+ }
16349
+ resetSelection() {
16350
+ this.guard();
16351
+ this.lib.editorViewResetSelection(this.viewPtr);
16352
+ }
16353
+ getSelection() {
16354
+ this.guard();
16355
+ return this.lib.editorViewGetSelection(this.viewPtr);
16356
+ }
16357
+ hasSelection() {
16358
+ this.guard();
16359
+ return this.getSelection() !== null;
16360
+ }
16361
+ setLocalSelection(anchorX, anchorY, focusX, focusY, bgColor, fgColor, updateCursor, followCursor) {
16362
+ this.guard();
16363
+ return this.lib.editorViewSetLocalSelection(this.viewPtr, anchorX, anchorY, focusX, focusY, bgColor || null, fgColor || null, updateCursor ?? false, followCursor ?? false);
16364
+ }
16365
+ updateLocalSelection(anchorX, anchorY, focusX, focusY, bgColor, fgColor, updateCursor, followCursor) {
16366
+ this.guard();
16367
+ return this.lib.editorViewUpdateLocalSelection(this.viewPtr, anchorX, anchorY, focusX, focusY, bgColor || null, fgColor || null, updateCursor ?? false, followCursor ?? false);
16368
+ }
16369
+ resetLocalSelection() {
16370
+ this.guard();
16371
+ this.lib.editorViewResetLocalSelection(this.viewPtr);
16372
+ }
16373
+ getSelectedText() {
16374
+ this.guard();
16375
+ const maxLength = 1024 * 1024;
16376
+ const selectedBytes = this.lib.editorViewGetSelectedTextBytes(this.viewPtr, maxLength);
16377
+ if (!selectedBytes)
16378
+ return "";
16379
+ return this.lib.decoder.decode(selectedBytes);
16380
+ }
16381
+ getCursor() {
16382
+ this.guard();
16383
+ return this.lib.editorViewGetCursor(this.viewPtr);
16384
+ }
16385
+ getText() {
16386
+ this.guard();
16387
+ const maxLength = 1024 * 1024;
16388
+ const textBytes = this.lib.editorViewGetText(this.viewPtr, maxLength);
16389
+ if (!textBytes)
16390
+ return "";
16391
+ return this.lib.decoder.decode(textBytes);
16392
+ }
16393
+ getVisualCursor() {
16394
+ this.guard();
16395
+ return this.lib.editorViewGetVisualCursor(this.viewPtr);
16396
+ }
16397
+ moveUpVisual() {
16398
+ this.guard();
16399
+ this.lib.editorViewMoveUpVisual(this.viewPtr);
16400
+ }
16401
+ moveDownVisual() {
16402
+ this.guard();
16403
+ this.lib.editorViewMoveDownVisual(this.viewPtr);
16404
+ }
16405
+ deleteSelectedText() {
16406
+ this.guard();
16407
+ this.lib.editorViewDeleteSelectedText(this.viewPtr);
16408
+ }
16409
+ setCursorByOffset(offset) {
16410
+ this.guard();
16411
+ this.lib.editorViewSetCursorByOffset(this.viewPtr, offset);
16412
+ }
16413
+ getNextWordBoundary() {
16414
+ this.guard();
16415
+ return this.lib.editorViewGetNextWordBoundary(this.viewPtr);
16416
+ }
16417
+ getPrevWordBoundary() {
16418
+ this.guard();
16419
+ return this.lib.editorViewGetPrevWordBoundary(this.viewPtr);
16420
+ }
16421
+ getEOL() {
16422
+ this.guard();
16423
+ return this.lib.editorViewGetEOL(this.viewPtr);
16424
+ }
16425
+ getVisualSOL() {
16426
+ this.guard();
16427
+ return this.lib.editorViewGetVisualSOL(this.viewPtr);
16428
+ }
16429
+ getVisualEOL() {
16430
+ this.guard();
16431
+ return this.lib.editorViewGetVisualEOL(this.viewPtr);
16432
+ }
16433
+ getLineInfo() {
16434
+ this.guard();
16435
+ return this.lib.editorViewGetLineInfo(this.viewPtr);
16436
+ }
16437
+ getLogicalLineInfo() {
16438
+ this.guard();
16439
+ return this.lib.editorViewGetLogicalLineInfo(this.viewPtr);
16440
+ }
16441
+ get extmarks() {
16442
+ if (!this._extmarksController) {
16443
+ this._extmarksController = createExtmarksController(this.editBuffer, this);
16444
+ }
16445
+ return this._extmarksController;
16446
+ }
16447
+ setPlaceholderStyledText(chunks) {
16448
+ this.guard();
16449
+ this.lib.editorViewSetPlaceholderStyledText(this.viewPtr, chunks);
16450
+ }
16451
+ setTabIndicator(indicator) {
16452
+ this.guard();
16453
+ const codePoint = typeof indicator === "string" ? indicator.codePointAt(0) ?? 0 : indicator;
16454
+ this.lib.editorViewSetTabIndicator(this.viewPtr, codePoint);
16455
+ }
16456
+ setTabIndicatorColor(color) {
16457
+ this.guard();
16458
+ this.lib.editorViewSetTabIndicatorColor(this.viewPtr, color);
16459
+ }
16460
+ measureForDimensions(width, height) {
16461
+ this.guard();
16462
+ if (!this._textBufferViewPtr) {
16463
+ this._textBufferViewPtr = this.lib.editorViewGetTextBufferView(this.viewPtr);
16464
+ }
16465
+ return this.lib.textBufferViewMeasureForDimensions(this._textBufferViewPtr, width, height);
16466
+ }
16467
+ destroy() {
16468
+ if (this._destroyed)
16469
+ return;
16470
+ if (this._extmarksController) {
16471
+ this._extmarksController.destroy();
16472
+ this._extmarksController = undefined;
16473
+ }
16474
+ this._destroyed = true;
16475
+ this.lib.destroyEditorView(this.viewPtr);
16476
+ }
16477
+ }
16478
+
16479
+ // src/console.ts
16480
+ import { EventEmitter as EventEmitter8 } from "events";
16481
+ import { Console } from "console";
16482
+ import fs from "fs";
16483
+ import path5 from "path";
16484
+ import util2 from "util";
16485
+
16486
+ // src/lib/output.capture.ts
16487
+ import { Writable } from "stream";
16488
+ import { EventEmitter as EventEmitter7 } from "events";
16489
+
16490
+ class Capture extends EventEmitter7 {
16491
+ output = [];
16492
+ constructor() {
16493
+ super();
16494
+ }
16495
+ get size() {
16496
+ return this.output.length;
16497
+ }
16498
+ write(stream, data) {
16499
+ this.output.push({ stream, output: data });
16500
+ this.emit("write", stream, data);
16501
+ }
16502
+ claimOutput() {
16503
+ const output = this.output.map((o) => o.output).join("");
16504
+ this.clear();
16505
+ return output;
16506
+ }
16507
+ clear() {
16508
+ this.output = [];
16509
+ }
16510
+ }
16511
+
16512
+ class CapturedWritableStream extends Writable {
16513
+ stream;
16514
+ capture;
16515
+ isTTY = true;
16516
+ columns = process.stdout.columns || 80;
16517
+ rows = process.stdout.rows || 24;
16518
+ constructor(stream, capture) {
16519
+ super();
16520
+ this.stream = stream;
16521
+ this.capture = capture;
16522
+ }
16523
+ _write(chunk, encoding, callback) {
16524
+ const data = chunk.toString();
16525
+ this.capture.write(this.stream, data);
16526
+ callback();
16527
+ }
16528
+ getColorDepth() {
16529
+ return process.stdout.getColorDepth?.() || 8;
16530
+ }
16531
+ }
16532
+
16533
+ // src/lib/keymapping.ts
16534
+ var defaultKeyAliases = {
16535
+ enter: "return",
16536
+ esc: "escape",
16537
+ kp0: "0",
16538
+ kp1: "1",
16539
+ kp2: "2",
16540
+ kp3: "3",
16541
+ kp4: "4",
16542
+ kp5: "5",
16543
+ kp6: "6",
16544
+ kp7: "7",
16545
+ kp8: "8",
16546
+ kp9: "9",
16547
+ kpdecimal: ".",
16548
+ kpdivide: "/",
16549
+ kpmultiply: "*",
16550
+ kpminus: "-",
16551
+ kpplus: "+",
16552
+ kpenter: "enter",
16553
+ kpequal: "=",
16554
+ kpseparator: ",",
16555
+ kpleft: "left",
16556
+ kpright: "right",
16557
+ kpup: "up",
16558
+ kpdown: "down",
16559
+ kppageup: "pageup",
16560
+ kppagedown: "pagedown",
16561
+ kphome: "home",
16562
+ kpend: "end",
16563
+ kpinsert: "insert",
16564
+ kpdelete: "delete"
16565
+ };
16566
+ function mergeKeyAliases(defaults, custom) {
16567
+ return { ...defaults, ...custom };
16568
+ }
16569
+ function mergeKeyBindings(defaults, custom) {
16570
+ const map = new Map;
16571
+ for (const binding of defaults) {
16572
+ const key = getKeyBindingKey(binding);
16573
+ map.set(key, binding);
16574
+ }
16575
+ for (const binding of custom) {
16576
+ const key = getKeyBindingKey(binding);
16577
+ map.set(key, binding);
16578
+ }
16579
+ return Array.from(map.values());
16580
+ }
16581
+ function getKeyBindingKey(binding) {
16582
+ return `${binding.name}:${binding.ctrl ? 1 : 0}:${binding.shift ? 1 : 0}:${binding.meta ? 1 : 0}:${binding.super ? 1 : 0}`;
16583
+ }
16584
+ function buildKeyBindingsMap(bindings, aliasMap) {
16585
+ const map = new Map;
16586
+ const aliases = aliasMap || {};
16587
+ for (const binding of bindings) {
16588
+ const key = getKeyBindingKey(binding);
16589
+ map.set(key, binding.action);
16590
+ }
16591
+ for (const binding of bindings) {
16592
+ const normalizedName = aliases[binding.name] || binding.name;
16593
+ if (normalizedName !== binding.name) {
16594
+ const aliasedKey = getKeyBindingKey({ ...binding, name: normalizedName });
16595
+ map.set(aliasedKey, binding.action);
16596
+ }
16597
+ }
16598
+ return map;
16599
+ }
16600
+ function keyBindingToString(binding) {
16601
+ const parts = [];
16602
+ if (binding.ctrl)
16603
+ parts.push("ctrl");
16604
+ if (binding.shift)
16605
+ parts.push("shift");
16606
+ if (binding.meta)
16607
+ parts.push("meta");
16608
+ if (binding.super)
16609
+ parts.push("super");
16610
+ parts.push(binding.name);
16611
+ return parts.join("+");
16612
+ }
16613
+
16614
+ // src/console.ts
16615
+ function getCallerInfo() {
16616
+ const err = new Error;
16617
+ const stackLines = err.stack?.split(`
16618
+ `).slice(5) || [];
16619
+ if (!stackLines.length)
16620
+ return null;
16621
+ const callerLine = stackLines[0].trim();
16622
+ const regex = /at\s+(?:([\w$.<>]+)\s+\()?((?:\/|[A-Za-z]:\\)[^:]+):(\d+):(\d+)\)?/;
16623
+ const match = callerLine.match(regex);
16624
+ if (!match)
16625
+ return null;
16626
+ const functionName = match[1] || "<anonymous>";
16627
+ const fullPath = match[2];
16628
+ const fileName = fullPath.split(/[\\/]/).pop() || "<unknown>";
16629
+ const lineNumber = parseInt(match[3], 10) || 0;
16630
+ const columnNumber = parseInt(match[4], 10) || 0;
16631
+ return { functionName, fullPath, fileName, lineNumber, columnNumber };
16632
+ }
16633
+ var capture = singleton("ConsoleCapture", () => new Capture);
16634
+ registerEnvVar({
16635
+ name: "OTUI_USE_CONSOLE",
16636
+ description: "Whether to use the console. Will not capture console output if set to false.",
16637
+ type: "boolean",
16638
+ default: true
16639
+ });
16640
+ registerEnvVar({
16641
+ name: "SHOW_CONSOLE",
16642
+ description: "Show the console at startup if set to true.",
16643
+ type: "boolean",
16644
+ default: false
16645
+ });
16646
+
16647
+ class TerminalConsoleCache extends EventEmitter8 {
16648
+ _cachedLogs = [];
16649
+ MAX_CACHE_SIZE = 1000;
16650
+ _collectCallerInfo = false;
16651
+ _cachingEnabled = true;
16652
+ _originalConsole = null;
16653
+ get cachedLogs() {
16654
+ return this._cachedLogs;
16655
+ }
16656
+ constructor() {
16657
+ super();
16658
+ }
16659
+ activate() {
16660
+ if (!this._originalConsole) {
16661
+ this._originalConsole = global.console;
16662
+ }
16663
+ this.setupConsoleCapture();
16664
+ this.overrideConsoleMethods();
16665
+ }
16666
+ setupConsoleCapture() {
16667
+ if (!env.OTUI_USE_CONSOLE)
16668
+ return;
16669
+ const mockStdout = new CapturedWritableStream("stdout", capture);
16670
+ const mockStderr = new CapturedWritableStream("stderr", capture);
16671
+ global.console = new Console({
16672
+ stdout: mockStdout,
16673
+ stderr: mockStderr,
16674
+ colorMode: true,
16675
+ inspectOptions: {
16676
+ compact: false,
16677
+ breakLength: 80,
16678
+ depth: 2
16679
+ }
16680
+ });
16681
+ }
16682
+ overrideConsoleMethods() {
16683
+ console.log = (...args) => {
16684
+ this.appendToConsole("LOG" /* LOG */, ...args);
16685
+ };
16686
+ console.info = (...args) => {
16687
+ this.appendToConsole("INFO" /* INFO */, ...args);
16688
+ };
16689
+ console.warn = (...args) => {
16690
+ this.appendToConsole("WARN" /* WARN */, ...args);
16691
+ };
16692
+ console.error = (...args) => {
16693
+ this.appendToConsole("ERROR" /* ERROR */, ...args);
16694
+ };
16695
+ console.debug = (...args) => {
16696
+ this.appendToConsole("DEBUG" /* DEBUG */, ...args);
16697
+ };
16698
+ }
16699
+ setCollectCallerInfo(enabled) {
16700
+ this._collectCallerInfo = enabled;
16701
+ }
16702
+ clearConsole() {
16703
+ this._cachedLogs = [];
16704
+ }
16705
+ setCachingEnabled(enabled) {
16706
+ this._cachingEnabled = enabled;
16707
+ }
16708
+ deactivate() {
16709
+ this.restoreOriginalConsole();
16710
+ }
16711
+ restoreOriginalConsole() {
16712
+ if (this._originalConsole) {
16713
+ global.console = this._originalConsole;
16714
+ }
16715
+ }
16716
+ addLogEntry(level, ...args) {
16717
+ const callerInfo = this._collectCallerInfo ? getCallerInfo() : null;
16718
+ const logEntry = [new Date, level, args, callerInfo];
16719
+ if (this._cachingEnabled) {
16720
+ if (this._cachedLogs.length >= this.MAX_CACHE_SIZE) {
16721
+ this._cachedLogs.shift();
16722
+ }
16723
+ this._cachedLogs.push(logEntry);
16724
+ }
16725
+ return logEntry;
16726
+ }
16727
+ appendToConsole(level, ...args) {
16728
+ if (this._cachedLogs.length >= this.MAX_CACHE_SIZE) {
16729
+ this._cachedLogs.shift();
16730
+ }
16731
+ const entry = this.addLogEntry(level, ...args);
16732
+ this.emit("entry", entry);
16733
+ }
16734
+ destroy() {
16735
+ this.deactivate();
16736
+ }
16737
+ }
16738
+ var terminalConsoleCache = singleton("TerminalConsoleCache", () => {
16739
+ const terminalConsoleCache2 = new TerminalConsoleCache;
16740
+ process.on("exit", () => {
16741
+ terminalConsoleCache2.destroy();
16742
+ });
16743
+ return terminalConsoleCache2;
16744
+ });
16215
16745
  var ConsolePosition;
16216
16746
  ((ConsolePosition2) => {
16217
16747
  ConsolePosition2["TOP"] = "top";
@@ -16257,7 +16787,7 @@ var DEFAULT_CONSOLE_OPTIONS = {
16257
16787
  };
16258
16788
  var INDENT_WIDTH = 2;
16259
16789
 
16260
- class TerminalConsole extends EventEmitter7 {
16790
+ class TerminalConsole extends EventEmitter8 {
16261
16791
  isVisible = false;
16262
16792
  isFocused = false;
16263
16793
  renderer;
@@ -16358,699 +16888,1590 @@ class TerminalConsole extends EventEmitter7 {
16358
16888
  this.show();
16359
16889
  }
16360
16890
  }
16361
- buildActionHandlers() {
16362
- return new Map([
16363
- ["scroll-up", () => this.scrollUp()],
16364
- ["scroll-down", () => this.scrollDown()],
16365
- ["scroll-to-top", () => this.scrollToTop()],
16366
- ["scroll-to-bottom", () => this.scrollToBottomAction()],
16367
- ["position-previous", () => this.positionPrevious()],
16368
- ["position-next", () => this.positionNext()],
16369
- ["size-increase", () => this.sizeIncrease()],
16370
- ["size-decrease", () => this.sizeDecrease()],
16371
- ["save-logs", () => this.saveLogsAction()],
16372
- ["copy-selection", () => this.triggerCopyAction()]
16373
- ]);
16891
+ buildActionHandlers() {
16892
+ return new Map([
16893
+ ["scroll-up", () => this.scrollUp()],
16894
+ ["scroll-down", () => this.scrollDown()],
16895
+ ["scroll-to-top", () => this.scrollToTop()],
16896
+ ["scroll-to-bottom", () => this.scrollToBottomAction()],
16897
+ ["position-previous", () => this.positionPrevious()],
16898
+ ["position-next", () => this.positionNext()],
16899
+ ["size-increase", () => this.sizeIncrease()],
16900
+ ["size-decrease", () => this.sizeDecrease()],
16901
+ ["save-logs", () => this.saveLogsAction()],
16902
+ ["copy-selection", () => this.triggerCopyAction()]
16903
+ ]);
16904
+ }
16905
+ activate() {
16906
+ terminalConsoleCache.activate();
16907
+ }
16908
+ deactivate() {
16909
+ terminalConsoleCache.deactivate();
16910
+ }
16911
+ _handleNewLog(logEntry) {
16912
+ if (!this.isVisible)
16913
+ return;
16914
+ this._allLogEntries.push(logEntry);
16915
+ if (this._allLogEntries.length > this.options.maxStoredLogs) {
16916
+ this._allLogEntries.splice(0, this._allLogEntries.length - this.options.maxStoredLogs);
16917
+ }
16918
+ const newDisplayLines = this._processLogEntry(logEntry);
16919
+ this._displayLines.push(...newDisplayLines);
16920
+ if (this._displayLines.length > this.options.maxDisplayLines) {
16921
+ this._displayLines.splice(0, this._displayLines.length - this.options.maxDisplayLines);
16922
+ const linesRemoved = this._displayLines.length - this.options.maxDisplayLines;
16923
+ this.scrollTopIndex = Math.max(0, this.scrollTopIndex - linesRemoved);
16924
+ }
16925
+ if (this.isScrolledToBottom) {
16926
+ this._scrollToBottom();
16927
+ }
16928
+ this.markNeedsRerender();
16929
+ }
16930
+ _updateConsoleDimensions(termWidth, termHeight) {
16931
+ const width = termWidth ?? this.renderer.width;
16932
+ const height = termHeight ?? this.renderer.height;
16933
+ const sizePercent = this.options.sizePercent / 100;
16934
+ switch (this.options.position) {
16935
+ case "top" /* TOP */:
16936
+ this.consoleX = 0;
16937
+ this.consoleY = 0;
16938
+ this.consoleWidth = width;
16939
+ this.consoleHeight = Math.max(1, Math.floor(height * sizePercent));
16940
+ break;
16941
+ case "bottom" /* BOTTOM */:
16942
+ this.consoleHeight = Math.max(1, Math.floor(height * sizePercent));
16943
+ this.consoleWidth = width;
16944
+ this.consoleX = 0;
16945
+ this.consoleY = height - this.consoleHeight;
16946
+ break;
16947
+ case "left" /* LEFT */:
16948
+ this.consoleWidth = Math.max(1, Math.floor(width * sizePercent));
16949
+ this.consoleHeight = height;
16950
+ this.consoleX = 0;
16951
+ this.consoleY = 0;
16952
+ break;
16953
+ case "right" /* RIGHT */:
16954
+ this.consoleWidth = Math.max(1, Math.floor(width * sizePercent));
16955
+ this.consoleHeight = height;
16956
+ this.consoleY = 0;
16957
+ this.consoleX = width - this.consoleWidth;
16958
+ break;
16959
+ }
16960
+ this.currentLineIndex = Math.max(0, Math.min(this.currentLineIndex, this.consoleHeight - 1));
16961
+ }
16962
+ handleKeyPress(event) {
16963
+ if (event.name === "escape") {
16964
+ this.blur();
16965
+ return;
16966
+ }
16967
+ const bindingKey = getKeyBindingKey({
16968
+ name: event.name,
16969
+ ctrl: event.ctrl,
16970
+ shift: event.shift,
16971
+ meta: event.meta,
16972
+ super: event.super,
16973
+ action: "scroll-up"
16974
+ });
16975
+ const action = this._keyBindingsMap.get(bindingKey);
16976
+ if (action) {
16977
+ const handler = this._actionHandlers.get(action);
16978
+ if (handler) {
16979
+ handler();
16980
+ return;
16981
+ }
16982
+ }
16983
+ }
16984
+ scrollUp() {
16985
+ const logAreaHeight = Math.max(1, this.consoleHeight - 1);
16986
+ if (this.currentLineIndex > 0) {
16987
+ this.currentLineIndex--;
16988
+ this.markNeedsRerender();
16989
+ } else if (this.scrollTopIndex > 0) {
16990
+ this.scrollTopIndex--;
16991
+ this.isScrolledToBottom = false;
16992
+ this.markNeedsRerender();
16993
+ }
16994
+ return true;
16995
+ }
16996
+ scrollDown() {
16997
+ const displayLineCount = this._displayLines.length;
16998
+ const logAreaHeight = Math.max(1, this.consoleHeight - 1);
16999
+ const maxScrollTop = Math.max(0, displayLineCount - logAreaHeight);
17000
+ const canCursorMoveDown = this.currentLineIndex < logAreaHeight - 1 && this.scrollTopIndex + this.currentLineIndex < displayLineCount - 1;
17001
+ if (canCursorMoveDown) {
17002
+ this.currentLineIndex++;
17003
+ this.markNeedsRerender();
17004
+ } else if (this.scrollTopIndex < maxScrollTop) {
17005
+ this.scrollTopIndex++;
17006
+ this.isScrolledToBottom = this.scrollTopIndex === maxScrollTop;
17007
+ this.markNeedsRerender();
17008
+ }
17009
+ return true;
17010
+ }
17011
+ scrollToTop() {
17012
+ if (this.scrollTopIndex > 0 || this.currentLineIndex > 0) {
17013
+ this.scrollTopIndex = 0;
17014
+ this.currentLineIndex = 0;
17015
+ this.isScrolledToBottom = this._displayLines.length <= Math.max(1, this.consoleHeight - 1);
17016
+ this.markNeedsRerender();
17017
+ }
17018
+ return true;
17019
+ }
17020
+ scrollToBottomAction() {
17021
+ const logAreaHeightForScroll = Math.max(1, this.consoleHeight - 1);
17022
+ const maxScrollPossible = Math.max(0, this._displayLines.length - logAreaHeightForScroll);
17023
+ if (this.scrollTopIndex < maxScrollPossible || !this.isScrolledToBottom) {
17024
+ this._scrollToBottom(true);
17025
+ this.markNeedsRerender();
17026
+ }
17027
+ return true;
17028
+ }
17029
+ positionPrevious() {
17030
+ const currentPositionIndex = this._positions.indexOf(this.options.position);
17031
+ const prevIndex = (currentPositionIndex - 1 + this._positions.length) % this._positions.length;
17032
+ this.options.position = this._positions[prevIndex];
17033
+ this.resize(this.renderer.width, this.renderer.height);
17034
+ return true;
17035
+ }
17036
+ positionNext() {
17037
+ const currentPositionIndex = this._positions.indexOf(this.options.position);
17038
+ const nextIndex = (currentPositionIndex + 1) % this._positions.length;
17039
+ this.options.position = this._positions[nextIndex];
17040
+ this.resize(this.renderer.width, this.renderer.height);
17041
+ return true;
17042
+ }
17043
+ sizeIncrease() {
17044
+ this.options.sizePercent = Math.min(100, this.options.sizePercent + 5);
17045
+ this.resize(this.renderer.width, this.renderer.height);
17046
+ return true;
17047
+ }
17048
+ sizeDecrease() {
17049
+ this.options.sizePercent = Math.max(10, this.options.sizePercent - 5);
17050
+ this.resize(this.renderer.width, this.renderer.height);
17051
+ return true;
17052
+ }
17053
+ saveLogsAction() {
17054
+ this.saveLogsToFile();
17055
+ return true;
17056
+ }
17057
+ triggerCopyAction() {
17058
+ this.triggerCopy();
17059
+ return true;
17060
+ }
17061
+ attachStdin() {
17062
+ if (this.isFocused)
17063
+ return;
17064
+ this.renderer.keyInput.on("keypress", this.keyHandler);
17065
+ this.isFocused = true;
17066
+ }
17067
+ detachStdin() {
17068
+ if (!this.isFocused)
17069
+ return;
17070
+ this.renderer.keyInput.off("keypress", this.keyHandler);
17071
+ this.isFocused = false;
17072
+ }
17073
+ formatTimestamp(date) {
17074
+ return new Intl.DateTimeFormat("en-US", {
17075
+ hour: "2-digit",
17076
+ minute: "2-digit",
17077
+ second: "2-digit",
17078
+ hour12: false
17079
+ }).format(date);
17080
+ }
17081
+ formatArguments(args) {
17082
+ return args.map((arg) => {
17083
+ if (arg instanceof Error) {
17084
+ const errorProps = arg;
17085
+ return `Error: ${errorProps.message}
17086
+ ` + (errorProps.stack ? `${errorProps.stack}
17087
+ ` : "");
17088
+ }
17089
+ if (typeof arg === "object" && arg !== null) {
17090
+ try {
17091
+ return util2.inspect(arg, { depth: 2 });
17092
+ } catch (e) {
17093
+ return String(arg);
17094
+ }
17095
+ }
17096
+ try {
17097
+ return util2.inspect(arg, { depth: 2 });
17098
+ } catch (e) {
17099
+ return String(arg);
17100
+ }
17101
+ }).join(" ");
17102
+ }
17103
+ resize(width, height) {
17104
+ this._updateConsoleDimensions(width, height);
17105
+ if (this.frameBuffer) {
17106
+ this.frameBuffer.resize(this.consoleWidth, this.consoleHeight);
17107
+ const displayLineCount = this._displayLines.length;
17108
+ const logAreaHeight = Math.max(1, this.consoleHeight - 1);
17109
+ const maxScrollTop = Math.max(0, displayLineCount - logAreaHeight);
17110
+ this.scrollTopIndex = Math.min(this.scrollTopIndex, maxScrollTop);
17111
+ this.isScrolledToBottom = this.scrollTopIndex === maxScrollTop;
17112
+ const visibleLineCount = Math.min(logAreaHeight, displayLineCount - this.scrollTopIndex);
17113
+ this.currentLineIndex = Math.max(0, Math.min(this.currentLineIndex, visibleLineCount - 1));
17114
+ if (this.isVisible) {
17115
+ this.markNeedsRerender();
17116
+ }
17117
+ }
17118
+ }
17119
+ clear() {
17120
+ terminalConsoleCache.clearConsole();
17121
+ this._allLogEntries = [];
17122
+ this._displayLines = [];
17123
+ this.markNeedsRerender();
17124
+ }
17125
+ toggle() {
17126
+ if (this.isVisible) {
17127
+ if (this.isFocused) {
17128
+ this.hide();
17129
+ } else {
17130
+ this.focus();
17131
+ }
17132
+ } else {
17133
+ this.show();
17134
+ }
17135
+ if (!this.renderer.isRunning) {
17136
+ this.renderer.requestRender();
17137
+ }
17138
+ }
17139
+ focus() {
17140
+ this.attachStdin();
17141
+ this._scrollToBottom(true);
17142
+ this.markNeedsRerender();
16374
17143
  }
16375
- activate() {
16376
- terminalConsoleCache.activate();
17144
+ blur() {
17145
+ this.detachStdin();
17146
+ this.markNeedsRerender();
16377
17147
  }
16378
- deactivate() {
16379
- terminalConsoleCache.deactivate();
17148
+ show() {
17149
+ if (!this.isVisible) {
17150
+ this.isVisible = true;
17151
+ this._processCachedLogs();
17152
+ terminalConsoleCache.setCachingEnabled(false);
17153
+ if (!this.frameBuffer) {
17154
+ this.frameBuffer = OptimizedBuffer.create(this.consoleWidth, this.consoleHeight, this.renderer.widthMethod, {
17155
+ respectAlpha: this.backgroundColor.a < 1,
17156
+ id: "console framebuffer"
17157
+ });
17158
+ }
17159
+ const logCount = terminalConsoleCache.cachedLogs.length;
17160
+ const visibleLogLines = Math.min(this.consoleHeight, logCount);
17161
+ this.currentLineIndex = Math.max(0, visibleLogLines - 1);
17162
+ this.scrollTopIndex = 0;
17163
+ this._scrollToBottom(true);
17164
+ this.focus();
17165
+ this.markNeedsRerender();
17166
+ }
16380
17167
  }
16381
- _handleNewLog(logEntry) {
16382
- if (!this.isVisible)
17168
+ hide() {
17169
+ if (this.isVisible) {
17170
+ this.isVisible = false;
17171
+ this.blur();
17172
+ terminalConsoleCache.setCachingEnabled(true);
17173
+ }
17174
+ }
17175
+ destroy() {
17176
+ this.stopAutoScroll();
17177
+ this.hide();
17178
+ this.deactivate();
17179
+ terminalConsoleCache.off("entry", this._entryListener);
17180
+ }
17181
+ getCachedLogs() {
17182
+ return terminalConsoleCache.cachedLogs.map((logEntry) => logEntry[0].toISOString() + " " + logEntry.slice(1).join(" ")).join(`
17183
+ `);
17184
+ }
17185
+ updateFrameBuffer() {
17186
+ if (!this.frameBuffer)
16383
17187
  return;
16384
- this._allLogEntries.push(logEntry);
16385
- if (this._allLogEntries.length > this.options.maxStoredLogs) {
16386
- this._allLogEntries.splice(0, this._allLogEntries.length - this.options.maxStoredLogs);
17188
+ this.frameBuffer.clear(this.backgroundColor);
17189
+ const displayLines = this._displayLines;
17190
+ const displayLineCount = displayLines.length;
17191
+ const logAreaHeight = Math.max(1, this.consoleHeight - 1);
17192
+ this.frameBuffer.fillRect(0, 0, this.consoleWidth, 1, this._rgbaTitleBar);
17193
+ const dynamicTitle = `${this._title}${this.isFocused ? " (Focused)" : ""}`;
17194
+ const titleX = Math.max(0, Math.floor((this.consoleWidth - dynamicTitle.length) / 2));
17195
+ this.frameBuffer.drawText(dynamicTitle, titleX, 0, this._rgbaTitleBarText, this._rgbaTitleBar);
17196
+ const copyLabel = this.getCopyButtonLabel();
17197
+ const copyButtonX = this.consoleWidth - copyLabel.length - 1;
17198
+ if (copyButtonX >= 0) {
17199
+ const copyButtonEnabled = this.hasSelection();
17200
+ const disabledColor = RGBA.fromInts(100, 100, 100, 255);
17201
+ const copyColor = copyButtonEnabled ? this._rgbaCopyButton : disabledColor;
17202
+ this.frameBuffer.drawText(copyLabel, copyButtonX, 0, copyColor, this._rgbaTitleBar);
17203
+ this._copyButtonBounds = { x: copyButtonX, y: 0, width: copyLabel.length, height: 1 };
17204
+ } else {
17205
+ this._copyButtonBounds = { x: -1, y: -1, width: 0, height: 0 };
16387
17206
  }
16388
- const newDisplayLines = this._processLogEntry(logEntry);
16389
- this._displayLines.push(...newDisplayLines);
16390
- if (this._displayLines.length > this.options.maxDisplayLines) {
16391
- this._displayLines.splice(0, this._displayLines.length - this.options.maxDisplayLines);
16392
- const linesRemoved = this._displayLines.length - this.options.maxDisplayLines;
16393
- this.scrollTopIndex = Math.max(0, this.scrollTopIndex - linesRemoved);
17207
+ const startIndex = this.scrollTopIndex;
17208
+ const endIndex = Math.min(startIndex + logAreaHeight, displayLineCount);
17209
+ const visibleDisplayLines = displayLines.slice(startIndex, endIndex);
17210
+ let lineY = 1;
17211
+ for (let i = 0;i < visibleDisplayLines.length; i++) {
17212
+ if (lineY >= this.consoleHeight)
17213
+ break;
17214
+ const displayLine = visibleDisplayLines[i];
17215
+ const absoluteLineIndex = startIndex + i;
17216
+ let levelColor = this._rgbaDefault;
17217
+ switch (displayLine.level) {
17218
+ case "INFO" /* INFO */:
17219
+ levelColor = this._rgbaInfo;
17220
+ break;
17221
+ case "WARN" /* WARN */:
17222
+ levelColor = this._rgbaWarn;
17223
+ break;
17224
+ case "ERROR" /* ERROR */:
17225
+ levelColor = this._rgbaError;
17226
+ break;
17227
+ case "DEBUG" /* DEBUG */:
17228
+ levelColor = this._rgbaDebug;
17229
+ break;
17230
+ }
17231
+ const linePrefix = displayLine.indent ? " ".repeat(INDENT_WIDTH) : "";
17232
+ const textToDraw = displayLine.text;
17233
+ const textAvailableWidth = this.consoleWidth - 1 - (displayLine.indent ? INDENT_WIDTH : 0);
17234
+ const showCursor = this.isFocused && lineY - 1 === this.currentLineIndex;
17235
+ if (showCursor) {
17236
+ this.frameBuffer.drawText(">", 0, lineY, this._rgbaCursor, this.backgroundColor);
17237
+ } else {
17238
+ this.frameBuffer.drawText(" ", 0, lineY, this._rgbaDefault, this.backgroundColor);
17239
+ }
17240
+ const fullText = `${linePrefix}${textToDraw.substring(0, textAvailableWidth)}`;
17241
+ const selectionRange = this.getLineSelectionRange(absoluteLineIndex);
17242
+ if (selectionRange) {
17243
+ const adjustedStart = Math.max(0, selectionRange.start);
17244
+ const adjustedEnd = Math.min(fullText.length, selectionRange.end);
17245
+ if (adjustedStart > 0) {
17246
+ this.frameBuffer.drawText(fullText.substring(0, adjustedStart), 1, lineY, levelColor);
17247
+ }
17248
+ if (adjustedStart < adjustedEnd) {
17249
+ this.frameBuffer.fillRect(1 + adjustedStart, lineY, adjustedEnd - adjustedStart, 1, this._rgbaSelection);
17250
+ this.frameBuffer.drawText(fullText.substring(adjustedStart, adjustedEnd), 1 + adjustedStart, lineY, levelColor, this._rgbaSelection);
17251
+ }
17252
+ if (adjustedEnd < fullText.length) {
17253
+ this.frameBuffer.drawText(fullText.substring(adjustedEnd), 1 + adjustedEnd, lineY, levelColor);
17254
+ }
17255
+ } else {
17256
+ this.frameBuffer.drawText(fullText, 1, lineY, levelColor);
17257
+ }
17258
+ lineY++;
16394
17259
  }
16395
- if (this.isScrolledToBottom) {
16396
- this._scrollToBottom();
17260
+ }
17261
+ renderToBuffer(buffer) {
17262
+ if (!this.isVisible || !this.frameBuffer)
17263
+ return;
17264
+ if (this._needsFrameBufferUpdate) {
17265
+ this.updateFrameBuffer();
17266
+ this._needsFrameBufferUpdate = false;
16397
17267
  }
16398
- this.markNeedsRerender();
17268
+ buffer.drawFrameBuffer(this.consoleX, this.consoleY, this.frameBuffer);
16399
17269
  }
16400
- _updateConsoleDimensions(termWidth, termHeight) {
16401
- const width = termWidth ?? this.renderer.width;
16402
- const height = termHeight ?? this.renderer.height;
16403
- const sizePercent = this.options.sizePercent / 100;
16404
- switch (this.options.position) {
16405
- case "top" /* TOP */:
16406
- this.consoleX = 0;
16407
- this.consoleY = 0;
16408
- this.consoleWidth = width;
16409
- this.consoleHeight = Math.max(1, Math.floor(height * sizePercent));
16410
- break;
16411
- case "bottom" /* BOTTOM */:
16412
- this.consoleHeight = Math.max(1, Math.floor(height * sizePercent));
16413
- this.consoleWidth = width;
16414
- this.consoleX = 0;
16415
- this.consoleY = height - this.consoleHeight;
16416
- break;
16417
- case "left" /* LEFT */:
16418
- this.consoleWidth = Math.max(1, Math.floor(width * sizePercent));
16419
- this.consoleHeight = height;
16420
- this.consoleX = 0;
16421
- this.consoleY = 0;
16422
- break;
16423
- case "right" /* RIGHT */:
16424
- this.consoleWidth = Math.max(1, Math.floor(width * sizePercent));
16425
- this.consoleHeight = height;
16426
- this.consoleY = 0;
16427
- this.consoleX = width - this.consoleWidth;
16428
- break;
17270
+ setDebugMode(enabled) {
17271
+ this._debugModeEnabled = enabled;
17272
+ terminalConsoleCache.setCollectCallerInfo(enabled);
17273
+ if (this.isVisible) {
17274
+ this.markNeedsRerender();
16429
17275
  }
16430
- this.currentLineIndex = Math.max(0, Math.min(this.currentLineIndex, this.consoleHeight - 1));
16431
17276
  }
16432
- handleKeyPress(event) {
16433
- if (event.name === "escape") {
16434
- this.blur();
16435
- return;
17277
+ toggleDebugMode() {
17278
+ this.setDebugMode(!this._debugModeEnabled);
17279
+ }
17280
+ set keyBindings(bindings) {
17281
+ this._keyBindings = bindings;
17282
+ this._mergedKeyBindings = mergeKeyBindings(defaultConsoleKeybindings, bindings);
17283
+ this._keyBindingsMap = buildKeyBindingsMap(this._mergedKeyBindings, this._keyAliasMap);
17284
+ this.markNeedsRerender();
17285
+ }
17286
+ set keyAliasMap(aliases) {
17287
+ this._keyAliasMap = mergeKeyAliases(defaultKeyAliases, aliases);
17288
+ this._mergedKeyBindings = mergeKeyBindings(defaultConsoleKeybindings, this._keyBindings);
17289
+ this._keyBindingsMap = buildKeyBindingsMap(this._mergedKeyBindings, this._keyAliasMap);
17290
+ this.markNeedsRerender();
17291
+ }
17292
+ set onCopySelection(callback) {
17293
+ this.options.onCopySelection = callback;
17294
+ }
17295
+ get onCopySelection() {
17296
+ return this.options.onCopySelection;
17297
+ }
17298
+ _scrollToBottom(forceCursorToLastLine = false) {
17299
+ const displayLineCount = this._displayLines.length;
17300
+ const logAreaHeight = Math.max(1, this.consoleHeight - 1);
17301
+ const maxScrollTop = Math.max(0, displayLineCount - logAreaHeight);
17302
+ this.scrollTopIndex = maxScrollTop;
17303
+ this.isScrolledToBottom = true;
17304
+ const visibleLineCount = Math.min(logAreaHeight, displayLineCount - this.scrollTopIndex);
17305
+ if (forceCursorToLastLine || this.currentLineIndex >= visibleLineCount) {
17306
+ this.currentLineIndex = Math.max(0, visibleLineCount - 1);
16436
17307
  }
16437
- const bindingKey = getKeyBindingKey({
16438
- name: event.name,
16439
- ctrl: event.ctrl,
16440
- shift: event.shift,
16441
- meta: event.meta,
16442
- super: event.super,
16443
- action: "scroll-up"
16444
- });
16445
- const action = this._keyBindingsMap.get(bindingKey);
16446
- if (action) {
16447
- const handler = this._actionHandlers.get(action);
16448
- if (handler) {
16449
- handler();
16450
- return;
17308
+ }
17309
+ _processLogEntry(logEntry) {
17310
+ const [date, level, args, callerInfo] = logEntry;
17311
+ const displayLines = [];
17312
+ const timestamp = this.formatTimestamp(date);
17313
+ const callerSource = callerInfo ? `${callerInfo.fileName}:${callerInfo.lineNumber}` : "unknown";
17314
+ const prefix = `[${timestamp}] [${level}]` + (this._debugModeEnabled ? ` [${callerSource}]` : "") + " ";
17315
+ const formattedArgs = this.formatArguments(args);
17316
+ const initialLines = formattedArgs.split(`
17317
+ `);
17318
+ for (let i = 0;i < initialLines.length; i++) {
17319
+ const lineText = initialLines[i];
17320
+ const isFirstLineOfEntry = i === 0;
17321
+ const availableWidth = this.consoleWidth - 1 - (isFirstLineOfEntry ? 0 : INDENT_WIDTH);
17322
+ const linePrefix = isFirstLineOfEntry ? prefix : " ".repeat(INDENT_WIDTH);
17323
+ const textToWrap = isFirstLineOfEntry ? linePrefix + lineText : lineText;
17324
+ let currentPos = 0;
17325
+ while (currentPos < textToWrap.length || isFirstLineOfEntry && currentPos === 0 && textToWrap.length === 0) {
17326
+ const segment = textToWrap.substring(currentPos, currentPos + availableWidth);
17327
+ const isFirstSegmentOfLine = currentPos === 0;
17328
+ displayLines.push({
17329
+ text: isFirstSegmentOfLine && !isFirstLineOfEntry ? linePrefix + segment : segment,
17330
+ level,
17331
+ indent: !isFirstLineOfEntry || !isFirstSegmentOfLine
17332
+ });
17333
+ currentPos += availableWidth;
17334
+ if (isFirstLineOfEntry && currentPos === 0 && textToWrap.length === 0)
17335
+ break;
16451
17336
  }
16452
17337
  }
17338
+ return displayLines;
16453
17339
  }
16454
- scrollUp() {
16455
- const logAreaHeight = Math.max(1, this.consoleHeight - 1);
16456
- if (this.currentLineIndex > 0) {
16457
- this.currentLineIndex--;
16458
- this.markNeedsRerender();
16459
- } else if (this.scrollTopIndex > 0) {
16460
- this.scrollTopIndex--;
16461
- this.isScrolledToBottom = false;
16462
- this.markNeedsRerender();
16463
- }
16464
- return true;
16465
- }
16466
- scrollDown() {
16467
- const displayLineCount = this._displayLines.length;
16468
- const logAreaHeight = Math.max(1, this.consoleHeight - 1);
16469
- const maxScrollTop = Math.max(0, displayLineCount - logAreaHeight);
16470
- const canCursorMoveDown = this.currentLineIndex < logAreaHeight - 1 && this.scrollTopIndex + this.currentLineIndex < displayLineCount - 1;
16471
- if (canCursorMoveDown) {
16472
- this.currentLineIndex++;
16473
- this.markNeedsRerender();
16474
- } else if (this.scrollTopIndex < maxScrollTop) {
16475
- this.scrollTopIndex++;
16476
- this.isScrolledToBottom = this.scrollTopIndex === maxScrollTop;
16477
- this.markNeedsRerender();
17340
+ _processCachedLogs() {
17341
+ const logsToProcess = [...terminalConsoleCache.cachedLogs];
17342
+ terminalConsoleCache.clearConsole();
17343
+ this._allLogEntries.push(...logsToProcess);
17344
+ if (this._allLogEntries.length > this.options.maxStoredLogs) {
17345
+ this._allLogEntries.splice(0, this._allLogEntries.length - this.options.maxStoredLogs);
16478
17346
  }
16479
- return true;
16480
- }
16481
- scrollToTop() {
16482
- if (this.scrollTopIndex > 0 || this.currentLineIndex > 0) {
16483
- this.scrollTopIndex = 0;
16484
- this.currentLineIndex = 0;
16485
- this.isScrolledToBottom = this._displayLines.length <= Math.max(1, this.consoleHeight - 1);
16486
- this.markNeedsRerender();
17347
+ for (const logEntry of logsToProcess) {
17348
+ const processed = this._processLogEntry(logEntry);
17349
+ this._displayLines.push(...processed);
16487
17350
  }
16488
- return true;
16489
- }
16490
- scrollToBottomAction() {
16491
- const logAreaHeightForScroll = Math.max(1, this.consoleHeight - 1);
16492
- const maxScrollPossible = Math.max(0, this._displayLines.length - logAreaHeightForScroll);
16493
- if (this.scrollTopIndex < maxScrollPossible || !this.isScrolledToBottom) {
16494
- this._scrollToBottom(true);
16495
- this.markNeedsRerender();
17351
+ if (this._displayLines.length > this.options.maxDisplayLines) {
17352
+ this._displayLines.splice(0, this._displayLines.length - this.options.maxDisplayLines);
16496
17353
  }
16497
- return true;
16498
- }
16499
- positionPrevious() {
16500
- const currentPositionIndex = this._positions.indexOf(this.options.position);
16501
- const prevIndex = (currentPositionIndex - 1 + this._positions.length) % this._positions.length;
16502
- this.options.position = this._positions[prevIndex];
16503
- this.resize(this.renderer.width, this.renderer.height);
16504
- return true;
16505
17354
  }
16506
- positionNext() {
16507
- const currentPositionIndex = this._positions.indexOf(this.options.position);
16508
- const nextIndex = (currentPositionIndex + 1) % this._positions.length;
16509
- this.options.position = this._positions[nextIndex];
16510
- this.resize(this.renderer.width, this.renderer.height);
16511
- return true;
17355
+ hasSelection() {
17356
+ if (this._selectionStart === null || this._selectionEnd === null)
17357
+ return false;
17358
+ return this._selectionStart.line !== this._selectionEnd.line || this._selectionStart.col !== this._selectionEnd.col;
16512
17359
  }
16513
- sizeIncrease() {
16514
- this.options.sizePercent = Math.min(100, this.options.sizePercent + 5);
16515
- this.resize(this.renderer.width, this.renderer.height);
16516
- return true;
17360
+ normalizeSelection() {
17361
+ if (!this._selectionStart || !this._selectionEnd)
17362
+ return null;
17363
+ const start = this._selectionStart;
17364
+ const end = this._selectionEnd;
17365
+ const startBeforeEnd = start.line < end.line || start.line === end.line && start.col <= end.col;
17366
+ if (startBeforeEnd) {
17367
+ return {
17368
+ startLine: start.line,
17369
+ startCol: start.col,
17370
+ endLine: end.line,
17371
+ endCol: end.col
17372
+ };
17373
+ } else {
17374
+ return {
17375
+ startLine: end.line,
17376
+ startCol: end.col,
17377
+ endLine: start.line,
17378
+ endCol: start.col
17379
+ };
17380
+ }
16517
17381
  }
16518
- sizeDecrease() {
16519
- this.options.sizePercent = Math.max(10, this.options.sizePercent - 5);
16520
- this.resize(this.renderer.width, this.renderer.height);
16521
- return true;
17382
+ getSelectedText() {
17383
+ const selection2 = this.normalizeSelection();
17384
+ if (!selection2)
17385
+ return "";
17386
+ const lines = [];
17387
+ for (let i = selection2.startLine;i <= selection2.endLine; i++) {
17388
+ if (i < 0 || i >= this._displayLines.length)
17389
+ continue;
17390
+ const line = this._displayLines[i];
17391
+ const linePrefix = line.indent ? " ".repeat(INDENT_WIDTH) : "";
17392
+ const textAvailableWidth = this.consoleWidth - 1 - (line.indent ? INDENT_WIDTH : 0);
17393
+ const fullText = linePrefix + line.text.substring(0, textAvailableWidth);
17394
+ let text = fullText;
17395
+ if (i === selection2.startLine && i === selection2.endLine) {
17396
+ text = fullText.substring(selection2.startCol, selection2.endCol);
17397
+ } else if (i === selection2.startLine) {
17398
+ text = fullText.substring(selection2.startCol);
17399
+ } else if (i === selection2.endLine) {
17400
+ text = fullText.substring(0, selection2.endCol);
17401
+ }
17402
+ lines.push(text);
17403
+ }
17404
+ return lines.join(`
17405
+ `);
16522
17406
  }
16523
- saveLogsAction() {
16524
- this.saveLogsToFile();
16525
- return true;
17407
+ clearSelection() {
17408
+ this._selectionStart = null;
17409
+ this._selectionEnd = null;
17410
+ this._isDragging = false;
17411
+ this.stopAutoScroll();
16526
17412
  }
16527
- triggerCopyAction() {
16528
- this.triggerCopy();
16529
- return true;
17413
+ stopAutoScroll() {
17414
+ if (this._autoScrollInterval !== null) {
17415
+ this.clock.clearInterval(this._autoScrollInterval);
17416
+ this._autoScrollInterval = null;
17417
+ }
16530
17418
  }
16531
- attachStdin() {
16532
- if (this.isFocused)
16533
- return;
16534
- this.renderer.keyInput.on("keypress", this.keyHandler);
16535
- this.isFocused = true;
17419
+ startAutoScroll(direction) {
17420
+ this.stopAutoScroll();
17421
+ this._autoScrollInterval = this.clock.setInterval(() => {
17422
+ if (direction === "up") {
17423
+ if (this.scrollTopIndex > 0) {
17424
+ this.scrollTopIndex--;
17425
+ this.isScrolledToBottom = false;
17426
+ if (this._selectionEnd) {
17427
+ this._selectionEnd = {
17428
+ line: this.scrollTopIndex,
17429
+ col: this._selectionEnd.col
17430
+ };
17431
+ }
17432
+ this.markNeedsRerender();
17433
+ } else {
17434
+ this.stopAutoScroll();
17435
+ }
17436
+ } else {
17437
+ const displayLineCount = this._displayLines.length;
17438
+ const logAreaHeight = Math.max(1, this.consoleHeight - 1);
17439
+ const maxScrollTop = Math.max(0, displayLineCount - logAreaHeight);
17440
+ if (this.scrollTopIndex < maxScrollTop) {
17441
+ this.scrollTopIndex++;
17442
+ this.isScrolledToBottom = this.scrollTopIndex === maxScrollTop;
17443
+ if (this._selectionEnd) {
17444
+ const maxLine = this.scrollTopIndex + logAreaHeight - 1;
17445
+ this._selectionEnd = {
17446
+ line: Math.min(maxLine, displayLineCount - 1),
17447
+ col: this._selectionEnd.col
17448
+ };
17449
+ }
17450
+ this.markNeedsRerender();
17451
+ } else {
17452
+ this.stopAutoScroll();
17453
+ }
17454
+ }
17455
+ }, 50);
16536
17456
  }
16537
- detachStdin() {
16538
- if (!this.isFocused)
17457
+ triggerCopy() {
17458
+ if (!this.hasSelection())
16539
17459
  return;
16540
- this.renderer.keyInput.off("keypress", this.keyHandler);
16541
- this.isFocused = false;
16542
- }
16543
- formatTimestamp(date) {
16544
- return new Intl.DateTimeFormat("en-US", {
16545
- hour: "2-digit",
16546
- minute: "2-digit",
16547
- second: "2-digit",
16548
- hour12: false
16549
- }).format(date);
17460
+ const text = this.getSelectedText();
17461
+ if (text && this.options.onCopySelection) {
17462
+ try {
17463
+ this.options.onCopySelection(text);
17464
+ } catch {}
17465
+ this.clearSelection();
17466
+ this.markNeedsRerender();
17467
+ }
16550
17468
  }
16551
- formatArguments(args) {
16552
- return args.map((arg) => {
16553
- if (arg instanceof Error) {
16554
- const errorProps = arg;
16555
- return `Error: ${errorProps.message}
16556
- ` + (errorProps.stack ? `${errorProps.stack}
16557
- ` : "");
16558
- }
16559
- if (typeof arg === "object" && arg !== null) {
16560
- try {
16561
- return util2.inspect(arg, { depth: 2 });
16562
- } catch (e) {
16563
- return String(arg);
16564
- }
17469
+ getLineSelectionRange(lineIndex) {
17470
+ const selection2 = this.normalizeSelection();
17471
+ if (!selection2)
17472
+ return null;
17473
+ if (lineIndex < selection2.startLine || lineIndex > selection2.endLine) {
17474
+ return null;
17475
+ }
17476
+ const line = this._displayLines[lineIndex];
17477
+ if (!line)
17478
+ return null;
17479
+ const linePrefix = line.indent ? " ".repeat(INDENT_WIDTH) : "";
17480
+ const textAvailableWidth = this.consoleWidth - 1 - (line.indent ? INDENT_WIDTH : 0);
17481
+ const fullTextLength = linePrefix.length + Math.min(line.text.length, textAvailableWidth);
17482
+ let start = 0;
17483
+ let end = fullTextLength;
17484
+ if (lineIndex === selection2.startLine) {
17485
+ start = Math.max(0, selection2.startCol);
17486
+ }
17487
+ if (lineIndex === selection2.endLine) {
17488
+ end = Math.min(fullTextLength, selection2.endCol);
17489
+ }
17490
+ if (start >= end)
17491
+ return null;
17492
+ return { start, end };
17493
+ }
17494
+ handleMouse(event) {
17495
+ if (!this.isVisible)
17496
+ return false;
17497
+ const localX = event.x - this.consoleX;
17498
+ const localY = event.y - this.consoleY;
17499
+ if (localX < 0 || localX >= this.consoleWidth || localY < 0 || localY >= this.consoleHeight) {
17500
+ return false;
17501
+ }
17502
+ if (event.type === "scroll" && event.scroll) {
17503
+ if (event.scroll.direction === "up") {
17504
+ this.scrollUp();
17505
+ } else if (event.scroll.direction === "down") {
17506
+ this.scrollDown();
16565
17507
  }
16566
- try {
16567
- return util2.inspect(arg, { depth: 2 });
16568
- } catch (e) {
16569
- return String(arg);
17508
+ return true;
17509
+ }
17510
+ if (localY === 0) {
17511
+ if (event.type === "down" && event.button === 0 && localX >= this._copyButtonBounds.x && localX < this._copyButtonBounds.x + this._copyButtonBounds.width) {
17512
+ this.triggerCopy();
17513
+ return true;
16570
17514
  }
16571
- }).join(" ");
16572
- }
16573
- resize(width, height) {
16574
- this._updateConsoleDimensions(width, height);
16575
- if (this.frameBuffer) {
16576
- this.frameBuffer.resize(this.consoleWidth, this.consoleHeight);
16577
- const displayLineCount = this._displayLines.length;
17515
+ return true;
17516
+ }
17517
+ const lineIndex = this.scrollTopIndex + (localY - 1);
17518
+ const colIndex = Math.max(0, localX - 1);
17519
+ if (event.type === "down" && event.button === 0) {
17520
+ this.clearSelection();
17521
+ this._selectionStart = { line: lineIndex, col: colIndex };
17522
+ this._selectionEnd = { line: lineIndex, col: colIndex };
17523
+ this._isDragging = true;
17524
+ this.markNeedsRerender();
17525
+ return true;
17526
+ }
17527
+ if (event.type === "drag" && this._isDragging) {
17528
+ this._selectionEnd = { line: lineIndex, col: colIndex };
16578
17529
  const logAreaHeight = Math.max(1, this.consoleHeight - 1);
16579
- const maxScrollTop = Math.max(0, displayLineCount - logAreaHeight);
16580
- this.scrollTopIndex = Math.min(this.scrollTopIndex, maxScrollTop);
16581
- this.isScrolledToBottom = this.scrollTopIndex === maxScrollTop;
16582
- const visibleLineCount = Math.min(logAreaHeight, displayLineCount - this.scrollTopIndex);
16583
- this.currentLineIndex = Math.max(0, Math.min(this.currentLineIndex, visibleLineCount - 1));
16584
- if (this.isVisible) {
17530
+ const relativeY = localY - 1;
17531
+ if (relativeY <= 0) {
17532
+ this.startAutoScroll("up");
17533
+ } else if (relativeY >= logAreaHeight - 1) {
17534
+ this.startAutoScroll("down");
17535
+ } else {
17536
+ this.stopAutoScroll();
17537
+ }
17538
+ this.markNeedsRerender();
17539
+ return true;
17540
+ }
17541
+ if (event.type === "up") {
17542
+ if (this._isDragging) {
17543
+ this._selectionEnd = { line: lineIndex, col: colIndex };
17544
+ this._isDragging = false;
17545
+ this.stopAutoScroll();
16585
17546
  this.markNeedsRerender();
16586
17547
  }
17548
+ return true;
16587
17549
  }
17550
+ return true;
16588
17551
  }
16589
- clear() {
16590
- terminalConsoleCache.clearConsole();
16591
- this._allLogEntries = [];
16592
- this._displayLines = [];
16593
- this.markNeedsRerender();
17552
+ get visible() {
17553
+ return this.isVisible;
16594
17554
  }
16595
- toggle() {
16596
- if (this.isVisible) {
16597
- if (this.isFocused) {
16598
- this.hide();
16599
- } else {
16600
- this.focus();
17555
+ get bounds() {
17556
+ return {
17557
+ x: this.consoleX,
17558
+ y: this.consoleY,
17559
+ width: this.consoleWidth,
17560
+ height: this.consoleHeight
17561
+ };
17562
+ }
17563
+ saveLogsToFile() {
17564
+ try {
17565
+ const timestamp = Date.now();
17566
+ const filename = `_console_${timestamp}.log`;
17567
+ const filepath = path5.join(process.cwd(), filename);
17568
+ const allLogEntries = [...this._allLogEntries, ...terminalConsoleCache.cachedLogs];
17569
+ const logLines = [];
17570
+ for (const [date, level, args, callerInfo] of allLogEntries) {
17571
+ const timestampStr = this.formatTimestamp(date);
17572
+ const callerSource = callerInfo ? `${callerInfo.fileName}:${callerInfo.lineNumber}` : "unknown";
17573
+ const prefix = `[${timestampStr}] [${level}]` + (this._debugModeEnabled ? ` [${callerSource}]` : "") + " ";
17574
+ const formattedArgs = this.formatArguments(args);
17575
+ logLines.push(prefix + formattedArgs);
16601
17576
  }
16602
- } else {
16603
- this.show();
16604
- }
16605
- if (!this.renderer.isRunning) {
16606
- this.renderer.requestRender();
17577
+ const content = logLines.join(`
17578
+ `);
17579
+ fs.writeFileSync(filepath, content, "utf8");
17580
+ console.info(`Console logs saved to: ${filename}`);
17581
+ } catch (error) {
17582
+ console.error(`Failed to save console logs:`, error);
16607
17583
  }
16608
17584
  }
16609
- focus() {
16610
- this.attachStdin();
16611
- this._scrollToBottom(true);
16612
- this.markNeedsRerender();
16613
- }
16614
- blur() {
16615
- this.detachStdin();
16616
- this.markNeedsRerender();
16617
- }
16618
- show() {
16619
- if (!this.isVisible) {
16620
- this.isVisible = true;
16621
- this._processCachedLogs();
16622
- terminalConsoleCache.setCachingEnabled(false);
16623
- if (!this.frameBuffer) {
16624
- this.frameBuffer = OptimizedBuffer.create(this.consoleWidth, this.consoleHeight, this.renderer.widthMethod, {
16625
- respectAlpha: this.backgroundColor.a < 1,
16626
- id: "console framebuffer"
17585
+ }
17586
+
17587
+ // src/renderables/EditBufferRenderable.ts
17588
+ var BrandedEditBufferRenderable = Symbol.for("@opentui/core/EditBufferRenderable");
17589
+ var EditBufferRenderableEvents;
17590
+ ((EditBufferRenderableEvents2) => {
17591
+ EditBufferRenderableEvents2["TRAITS_CHANGED"] = "traits-changed";
17592
+ })(EditBufferRenderableEvents ||= {});
17593
+ function sameCapture(a, b) {
17594
+ if (a === b)
17595
+ return true;
17596
+ if (!a || !b)
17597
+ return !a && !b;
17598
+ if (a.length !== b.length)
17599
+ return false;
17600
+ return a.every((item, i) => item === b[i]);
17601
+ }
17602
+ function sameTraits(a, b) {
17603
+ return a.suspend === b.suspend && a.status === b.status && sameCapture(a.capture, b.capture);
17604
+ }
17605
+ function isEditBufferRenderable(obj) {
17606
+ return !!(obj && typeof obj === "object" && (BrandedEditBufferRenderable in obj));
17607
+ }
17608
+
17609
+ class EditBufferRenderable extends Renderable {
17610
+ [BrandedEditBufferRenderable] = true;
17611
+ _focusable = true;
17612
+ selectable = true;
17613
+ _traits = {};
17614
+ _textColor;
17615
+ _backgroundColor;
17616
+ _defaultAttributes;
17617
+ _selectionBg;
17618
+ _selectionFg;
17619
+ _wrapMode = "word";
17620
+ _scrollMargin = 0.2;
17621
+ _showCursor = true;
17622
+ _cursorColor;
17623
+ _cursorStyle;
17624
+ lastLocalSelection = null;
17625
+ _tabIndicator;
17626
+ _tabIndicatorColor;
17627
+ _cursorChangeListener = undefined;
17628
+ _contentChangeListener = undefined;
17629
+ _autoScrollVelocity = 0;
17630
+ _autoScrollAccumulator = 0;
17631
+ _scrollSpeed = 16;
17632
+ _keyboardSelectionActive = false;
17633
+ editBuffer;
17634
+ editorView;
17635
+ _defaultOptions = {
17636
+ textColor: RGBA.fromValues(1, 1, 1, 1),
17637
+ backgroundColor: "transparent",
17638
+ selectionBg: undefined,
17639
+ selectionFg: undefined,
17640
+ selectable: true,
17641
+ attributes: 0,
17642
+ wrapMode: "word",
17643
+ scrollMargin: 0.2,
17644
+ scrollSpeed: 16,
17645
+ showCursor: true,
17646
+ cursorColor: RGBA.fromValues(1, 1, 1, 1),
17647
+ cursorStyle: {
17648
+ style: "block",
17649
+ blinking: true
17650
+ },
17651
+ tabIndicator: undefined,
17652
+ tabIndicatorColor: undefined
17653
+ };
17654
+ constructor(ctx, options) {
17655
+ super(ctx, options);
17656
+ this._textColor = parseColor(options.textColor ?? this._defaultOptions.textColor);
17657
+ this._backgroundColor = parseColor(options.backgroundColor ?? this._defaultOptions.backgroundColor);
17658
+ this._defaultAttributes = options.attributes ?? this._defaultOptions.attributes;
17659
+ this._selectionBg = options.selectionBg ? parseColor(options.selectionBg) : this._defaultOptions.selectionBg;
17660
+ this._selectionFg = options.selectionFg ? parseColor(options.selectionFg) : this._defaultOptions.selectionFg;
17661
+ this.selectable = options.selectable ?? this._defaultOptions.selectable;
17662
+ this._wrapMode = options.wrapMode ?? this._defaultOptions.wrapMode;
17663
+ this._scrollMargin = options.scrollMargin ?? this._defaultOptions.scrollMargin;
17664
+ this._scrollSpeed = options.scrollSpeed ?? this._defaultOptions.scrollSpeed;
17665
+ this._showCursor = options.showCursor ?? this._defaultOptions.showCursor;
17666
+ this._cursorColor = parseColor(options.cursorColor ?? this._defaultOptions.cursorColor);
17667
+ this._cursorStyle = options.cursorStyle ?? this._defaultOptions.cursorStyle;
17668
+ this._tabIndicator = options.tabIndicator ?? this._defaultOptions.tabIndicator;
17669
+ this._tabIndicatorColor = options.tabIndicatorColor ? parseColor(options.tabIndicatorColor) : this._defaultOptions.tabIndicatorColor;
17670
+ this.editBuffer = EditBuffer.create(this._ctx.widthMethod);
17671
+ this.editorView = EditorView.create(this.editBuffer, this.width || 80, this.height || 24);
17672
+ this.editorView.setWrapMode(this._wrapMode);
17673
+ this.editorView.setScrollMargin(this._scrollMargin);
17674
+ this.editBuffer.setDefaultFg(this._textColor);
17675
+ this.editBuffer.setDefaultBg(this._backgroundColor);
17676
+ this.editBuffer.setDefaultAttributes(this._defaultAttributes);
17677
+ if (options.syntaxStyle) {
17678
+ this.editBuffer.setSyntaxStyle(options.syntaxStyle);
17679
+ }
17680
+ if (this._tabIndicator !== undefined) {
17681
+ this.editorView.setTabIndicator(this._tabIndicator);
17682
+ }
17683
+ if (this._tabIndicatorColor !== undefined) {
17684
+ this.editorView.setTabIndicatorColor(this._tabIndicatorColor);
17685
+ }
17686
+ this.setupMeasureFunc();
17687
+ this.setupEventListeners(options);
17688
+ }
17689
+ get lineInfo() {
17690
+ return this.editorView.getLogicalLineInfo();
17691
+ }
17692
+ setupEventListeners(options) {
17693
+ this._cursorChangeListener = options.onCursorChange;
17694
+ this._contentChangeListener = options.onContentChange;
17695
+ this.editBuffer.on("cursor-changed", () => {
17696
+ if (this._cursorChangeListener) {
17697
+ const cursor = this.editBuffer.getCursorPosition();
17698
+ this._cursorChangeListener({
17699
+ line: cursor.row,
17700
+ visualColumn: cursor.col
16627
17701
  });
16628
17702
  }
16629
- const logCount = terminalConsoleCache.cachedLogs.length;
16630
- const visibleLogLines = Math.min(this.consoleHeight, logCount);
16631
- this.currentLineIndex = Math.max(0, visibleLogLines - 1);
16632
- this.scrollTopIndex = 0;
16633
- this._scrollToBottom(true);
16634
- this.focus();
16635
- this.markNeedsRerender();
16636
- }
17703
+ });
17704
+ this.editBuffer.on("content-changed", () => {
17705
+ this.yogaNode.markDirty();
17706
+ this.requestRender();
17707
+ this.emit("line-info-change");
17708
+ if (this._contentChangeListener) {
17709
+ this._contentChangeListener({});
17710
+ }
17711
+ });
16637
17712
  }
16638
- hide() {
16639
- if (this.isVisible) {
16640
- this.isVisible = false;
16641
- this.blur();
16642
- terminalConsoleCache.setCachingEnabled(true);
16643
- }
17713
+ get lineCount() {
17714
+ return this.editBuffer.getLineCount();
16644
17715
  }
16645
- destroy() {
16646
- this.stopAutoScroll();
16647
- this.hide();
16648
- this.deactivate();
16649
- terminalConsoleCache.off("entry", this._entryListener);
17716
+ get virtualLineCount() {
17717
+ return this.editorView.getVirtualLineCount();
16650
17718
  }
16651
- getCachedLogs() {
16652
- return terminalConsoleCache.cachedLogs.map((logEntry) => logEntry[0].toISOString() + " " + logEntry.slice(1).join(" ")).join(`
16653
- `);
17719
+ get scrollY() {
17720
+ return this.editorView.getViewport().offsetY;
16654
17721
  }
16655
- updateFrameBuffer() {
16656
- if (!this.frameBuffer)
17722
+ get plainText() {
17723
+ return this.editBuffer.getText();
17724
+ }
17725
+ get logicalCursor() {
17726
+ return this.editBuffer.getCursorPosition();
17727
+ }
17728
+ get visualCursor() {
17729
+ return this.editorView.getVisualCursor();
17730
+ }
17731
+ get cursorOffset() {
17732
+ return this.editorView.getVisualCursor().offset;
17733
+ }
17734
+ set cursorOffset(offset) {
17735
+ this.editorView.setCursorByOffset(offset);
17736
+ this.requestRender();
17737
+ }
17738
+ get cursorCharacterOffset() {
17739
+ const len = this.plainText.length;
17740
+ if (len <= 0)
16657
17741
  return;
16658
- this.frameBuffer.clear(this.backgroundColor);
16659
- const displayLines = this._displayLines;
16660
- const displayLineCount = displayLines.length;
16661
- const logAreaHeight = Math.max(1, this.consoleHeight - 1);
16662
- this.frameBuffer.fillRect(0, 0, this.consoleWidth, 1, this._rgbaTitleBar);
16663
- const dynamicTitle = `${this._title}${this.isFocused ? " (Focused)" : ""}`;
16664
- const titleX = Math.max(0, Math.floor((this.consoleWidth - dynamicTitle.length) / 2));
16665
- this.frameBuffer.drawText(dynamicTitle, titleX, 0, this._rgbaTitleBarText, this._rgbaTitleBar);
16666
- const copyLabel = this.getCopyButtonLabel();
16667
- const copyButtonX = this.consoleWidth - copyLabel.length - 1;
16668
- if (copyButtonX >= 0) {
16669
- const copyButtonEnabled = this.hasSelection();
16670
- const disabledColor = RGBA.fromInts(100, 100, 100, 255);
16671
- const copyColor = copyButtonEnabled ? this._rgbaCopyButton : disabledColor;
16672
- this.frameBuffer.drawText(copyLabel, copyButtonX, 0, copyColor, this._rgbaTitleBar);
16673
- this._copyButtonBounds = { x: copyButtonX, y: 0, width: copyLabel.length, height: 1 };
16674
- } else {
16675
- this._copyButtonBounds = { x: -1, y: -1, width: 0, height: 0 };
17742
+ const cursor = this.logicalCursor;
17743
+ const offset = this.cursorOffset;
17744
+ if (offset >= len) {
17745
+ if (cursor.col > 0)
17746
+ return len - 1;
17747
+ return 0;
16676
17748
  }
16677
- const startIndex = this.scrollTopIndex;
16678
- const endIndex = Math.min(startIndex + logAreaHeight, displayLineCount);
16679
- const visibleDisplayLines = displayLines.slice(startIndex, endIndex);
16680
- let lineY = 1;
16681
- for (let i = 0;i < visibleDisplayLines.length; i++) {
16682
- if (lineY >= this.consoleHeight)
16683
- break;
16684
- const displayLine = visibleDisplayLines[i];
16685
- const absoluteLineIndex = startIndex + i;
16686
- let levelColor = this._rgbaDefault;
16687
- switch (displayLine.level) {
16688
- case "INFO" /* INFO */:
16689
- levelColor = this._rgbaInfo;
16690
- break;
16691
- case "WARN" /* WARN */:
16692
- levelColor = this._rgbaWarn;
16693
- break;
16694
- case "ERROR" /* ERROR */:
16695
- levelColor = this._rgbaError;
16696
- break;
16697
- case "DEBUG" /* DEBUG */:
16698
- levelColor = this._rgbaDebug;
16699
- break;
16700
- }
16701
- const linePrefix = displayLine.indent ? " ".repeat(INDENT_WIDTH) : "";
16702
- const textToDraw = displayLine.text;
16703
- const textAvailableWidth = this.consoleWidth - 1 - (displayLine.indent ? INDENT_WIDTH : 0);
16704
- const showCursor = this.isFocused && lineY - 1 === this.currentLineIndex;
16705
- if (showCursor) {
16706
- this.frameBuffer.drawText(">", 0, lineY, this._rgbaCursor, this.backgroundColor);
16707
- } else {
16708
- this.frameBuffer.drawText(" ", 0, lineY, this._rgbaDefault, this.backgroundColor);
16709
- }
16710
- const fullText = `${linePrefix}${textToDraw.substring(0, textAvailableWidth)}`;
16711
- const selectionRange = this.getLineSelectionRange(absoluteLineIndex);
16712
- if (selectionRange) {
16713
- const adjustedStart = Math.max(0, selectionRange.start);
16714
- const adjustedEnd = Math.min(fullText.length, selectionRange.end);
16715
- if (adjustedStart > 0) {
16716
- this.frameBuffer.drawText(fullText.substring(0, adjustedStart), 1, lineY, levelColor);
16717
- }
16718
- if (adjustedStart < adjustedEnd) {
16719
- this.frameBuffer.fillRect(1 + adjustedStart, lineY, adjustedEnd - adjustedStart, 1, this._rgbaSelection);
16720
- this.frameBuffer.drawText(fullText.substring(adjustedStart, adjustedEnd), 1 + adjustedStart, lineY, levelColor, this._rgbaSelection);
16721
- }
16722
- if (adjustedEnd < fullText.length) {
16723
- this.frameBuffer.drawText(fullText.substring(adjustedEnd), 1 + adjustedEnd, lineY, levelColor);
16724
- }
16725
- } else {
16726
- this.frameBuffer.drawText(fullText, 1, lineY, levelColor);
16727
- }
16728
- lineY++;
17749
+ if (this.plainText[offset] === `
17750
+ ` && cursor.col > 0) {
17751
+ return offset - 1;
17752
+ }
17753
+ return offset;
17754
+ }
17755
+ get textColor() {
17756
+ return this._textColor;
17757
+ }
17758
+ set textColor(value) {
17759
+ const newColor = parseColor(value ?? this._defaultOptions.textColor);
17760
+ if (this._textColor !== newColor) {
17761
+ this._textColor = newColor;
17762
+ this.editBuffer.setDefaultFg(newColor);
17763
+ this.requestRender();
16729
17764
  }
16730
17765
  }
16731
- renderToBuffer(buffer) {
16732
- if (!this.isVisible || !this.frameBuffer)
17766
+ get selectionBg() {
17767
+ return this._selectionBg;
17768
+ }
17769
+ get traits() {
17770
+ return this._traits;
17771
+ }
17772
+ set traits(value) {
17773
+ if (sameTraits(this._traits, value))
16733
17774
  return;
16734
- if (this._needsFrameBufferUpdate) {
16735
- this.updateFrameBuffer();
16736
- this._needsFrameBufferUpdate = false;
17775
+ const prev = this._traits;
17776
+ this._traits = value;
17777
+ this.emit("traits-changed" /* TRAITS_CHANGED */, value, prev);
17778
+ }
17779
+ set selectionBg(value) {
17780
+ const newColor = value ? parseColor(value) : this._defaultOptions.selectionBg;
17781
+ if (this._selectionBg !== newColor) {
17782
+ this._selectionBg = newColor;
17783
+ this.refreshSelectionStyle();
17784
+ this.requestRender();
16737
17785
  }
16738
- buffer.drawFrameBuffer(this.consoleX, this.consoleY, this.frameBuffer);
16739
17786
  }
16740
- setDebugMode(enabled) {
16741
- this._debugModeEnabled = enabled;
16742
- terminalConsoleCache.setCollectCallerInfo(enabled);
16743
- if (this.isVisible) {
16744
- this.markNeedsRerender();
17787
+ get selectionFg() {
17788
+ return this._selectionFg;
17789
+ }
17790
+ set selectionFg(value) {
17791
+ const newColor = value ? parseColor(value) : this._defaultOptions.selectionFg;
17792
+ if (this._selectionFg !== newColor) {
17793
+ this._selectionFg = newColor;
17794
+ this.refreshSelectionStyle();
17795
+ this.requestRender();
16745
17796
  }
16746
17797
  }
16747
- toggleDebugMode() {
16748
- this.setDebugMode(!this._debugModeEnabled);
17798
+ get backgroundColor() {
17799
+ return this._backgroundColor;
16749
17800
  }
16750
- set keyBindings(bindings) {
16751
- this._keyBindings = bindings;
16752
- this._mergedKeyBindings = mergeKeyBindings(defaultConsoleKeybindings, bindings);
16753
- this._keyBindingsMap = buildKeyBindingsMap(this._mergedKeyBindings, this._keyAliasMap);
16754
- this.markNeedsRerender();
17801
+ set backgroundColor(value) {
17802
+ const newColor = parseColor(value ?? this._defaultOptions.backgroundColor);
17803
+ if (this._backgroundColor !== newColor) {
17804
+ this._backgroundColor = newColor;
17805
+ this.editBuffer.setDefaultBg(newColor);
17806
+ this.requestRender();
17807
+ }
16755
17808
  }
16756
- set keyAliasMap(aliases) {
16757
- this._keyAliasMap = mergeKeyAliases(defaultKeyAliases, aliases);
16758
- this._mergedKeyBindings = mergeKeyBindings(defaultConsoleKeybindings, this._keyBindings);
16759
- this._keyBindingsMap = buildKeyBindingsMap(this._mergedKeyBindings, this._keyAliasMap);
16760
- this.markNeedsRerender();
17809
+ get attributes() {
17810
+ return this._defaultAttributes;
16761
17811
  }
16762
- set onCopySelection(callback) {
16763
- this.options.onCopySelection = callback;
17812
+ set attributes(value) {
17813
+ if (this._defaultAttributes !== value) {
17814
+ this._defaultAttributes = value;
17815
+ this.editBuffer.setDefaultAttributes(value);
17816
+ this.requestRender();
17817
+ }
16764
17818
  }
16765
- get onCopySelection() {
16766
- return this.options.onCopySelection;
17819
+ get wrapMode() {
17820
+ return this._wrapMode;
16767
17821
  }
16768
- _scrollToBottom(forceCursorToLastLine = false) {
16769
- const displayLineCount = this._displayLines.length;
16770
- const logAreaHeight = Math.max(1, this.consoleHeight - 1);
16771
- const maxScrollTop = Math.max(0, displayLineCount - logAreaHeight);
16772
- this.scrollTopIndex = maxScrollTop;
16773
- this.isScrolledToBottom = true;
16774
- const visibleLineCount = Math.min(logAreaHeight, displayLineCount - this.scrollTopIndex);
16775
- if (forceCursorToLastLine || this.currentLineIndex >= visibleLineCount) {
16776
- this.currentLineIndex = Math.max(0, visibleLineCount - 1);
17822
+ set wrapMode(value) {
17823
+ if (this._wrapMode !== value) {
17824
+ this._wrapMode = value;
17825
+ this.editorView.setWrapMode(value);
17826
+ this.yogaNode.markDirty();
17827
+ this.requestRender();
16777
17828
  }
16778
17829
  }
16779
- _processLogEntry(logEntry) {
16780
- const [date, level, args, callerInfo] = logEntry;
16781
- const displayLines = [];
16782
- const timestamp = this.formatTimestamp(date);
16783
- const callerSource = callerInfo ? `${callerInfo.fileName}:${callerInfo.lineNumber}` : "unknown";
16784
- const prefix = `[${timestamp}] [${level}]` + (this._debugModeEnabled ? ` [${callerSource}]` : "") + " ";
16785
- const formattedArgs = this.formatArguments(args);
16786
- const initialLines = formattedArgs.split(`
16787
- `);
16788
- for (let i = 0;i < initialLines.length; i++) {
16789
- const lineText = initialLines[i];
16790
- const isFirstLineOfEntry = i === 0;
16791
- const availableWidth = this.consoleWidth - 1 - (isFirstLineOfEntry ? 0 : INDENT_WIDTH);
16792
- const linePrefix = isFirstLineOfEntry ? prefix : " ".repeat(INDENT_WIDTH);
16793
- const textToWrap = isFirstLineOfEntry ? linePrefix + lineText : lineText;
16794
- let currentPos = 0;
16795
- while (currentPos < textToWrap.length || isFirstLineOfEntry && currentPos === 0 && textToWrap.length === 0) {
16796
- const segment = textToWrap.substring(currentPos, currentPos + availableWidth);
16797
- const isFirstSegmentOfLine = currentPos === 0;
16798
- displayLines.push({
16799
- text: isFirstSegmentOfLine && !isFirstLineOfEntry ? linePrefix + segment : segment,
16800
- level,
16801
- indent: !isFirstLineOfEntry || !isFirstSegmentOfLine
16802
- });
16803
- currentPos += availableWidth;
16804
- if (isFirstLineOfEntry && currentPos === 0 && textToWrap.length === 0)
16805
- break;
17830
+ get showCursor() {
17831
+ return this._showCursor;
17832
+ }
17833
+ set showCursor(value) {
17834
+ if (this._showCursor !== value) {
17835
+ this._showCursor = value;
17836
+ if (!value && this._focused) {
17837
+ this._ctx.setCursorPosition(0, 0, false);
16806
17838
  }
17839
+ this.requestRender();
16807
17840
  }
16808
- return displayLines;
16809
17841
  }
16810
- _processCachedLogs() {
16811
- const logsToProcess = [...terminalConsoleCache.cachedLogs];
16812
- terminalConsoleCache.clearConsole();
16813
- this._allLogEntries.push(...logsToProcess);
16814
- if (this._allLogEntries.length > this.options.maxStoredLogs) {
16815
- this._allLogEntries.splice(0, this._allLogEntries.length - this.options.maxStoredLogs);
17842
+ get cursorColor() {
17843
+ return this._cursorColor;
17844
+ }
17845
+ set cursorColor(value) {
17846
+ const newColor = parseColor(value);
17847
+ if (this._cursorColor !== newColor) {
17848
+ this._cursorColor = newColor;
17849
+ if (this._focused) {
17850
+ this.requestRender();
17851
+ }
16816
17852
  }
16817
- for (const logEntry of logsToProcess) {
16818
- const processed = this._processLogEntry(logEntry);
16819
- this._displayLines.push(...processed);
17853
+ }
17854
+ get cursorStyle() {
17855
+ return this._cursorStyle;
17856
+ }
17857
+ set cursorStyle(style) {
17858
+ const newStyle = style;
17859
+ if (this.cursorStyle.style !== newStyle.style || this.cursorStyle.blinking !== newStyle.blinking) {
17860
+ this._cursorStyle = newStyle;
17861
+ if (this._focused) {
17862
+ this.requestRender();
17863
+ }
16820
17864
  }
16821
- if (this._displayLines.length > this.options.maxDisplayLines) {
16822
- this._displayLines.splice(0, this._displayLines.length - this.options.maxDisplayLines);
17865
+ }
17866
+ get tabIndicator() {
17867
+ return this._tabIndicator;
17868
+ }
17869
+ set tabIndicator(value) {
17870
+ if (this._tabIndicator !== value) {
17871
+ this._tabIndicator = value;
17872
+ if (value !== undefined) {
17873
+ this.editorView.setTabIndicator(value);
17874
+ }
17875
+ this.requestRender();
16823
17876
  }
16824
17877
  }
16825
- hasSelection() {
16826
- if (this._selectionStart === null || this._selectionEnd === null)
16827
- return false;
16828
- return this._selectionStart.line !== this._selectionEnd.line || this._selectionStart.col !== this._selectionEnd.col;
17878
+ get tabIndicatorColor() {
17879
+ return this._tabIndicatorColor;
16829
17880
  }
16830
- normalizeSelection() {
16831
- if (!this._selectionStart || !this._selectionEnd)
16832
- return null;
16833
- const start = this._selectionStart;
16834
- const end = this._selectionEnd;
16835
- const startBeforeEnd = start.line < end.line || start.line === end.line && start.col <= end.col;
16836
- if (startBeforeEnd) {
16837
- return {
16838
- startLine: start.line,
16839
- startCol: start.col,
16840
- endLine: end.line,
16841
- endCol: end.col
16842
- };
16843
- } else {
16844
- return {
16845
- startLine: end.line,
16846
- startCol: end.col,
16847
- endLine: start.line,
16848
- endCol: start.col
16849
- };
17881
+ set tabIndicatorColor(value) {
17882
+ const newColor = value ? parseColor(value) : undefined;
17883
+ if (this._tabIndicatorColor !== newColor) {
17884
+ this._tabIndicatorColor = newColor;
17885
+ if (newColor !== undefined) {
17886
+ this.editorView.setTabIndicatorColor(newColor);
17887
+ }
17888
+ this.requestRender();
16850
17889
  }
16851
17890
  }
16852
- getSelectedText() {
16853
- const selection2 = this.normalizeSelection();
16854
- if (!selection2)
16855
- return "";
16856
- const lines = [];
16857
- for (let i = selection2.startLine;i <= selection2.endLine; i++) {
16858
- if (i < 0 || i >= this._displayLines.length)
16859
- continue;
16860
- const line = this._displayLines[i];
16861
- const linePrefix = line.indent ? " ".repeat(INDENT_WIDTH) : "";
16862
- const textAvailableWidth = this.consoleWidth - 1 - (line.indent ? INDENT_WIDTH : 0);
16863
- const fullText = linePrefix + line.text.substring(0, textAvailableWidth);
16864
- let text = fullText;
16865
- if (i === selection2.startLine && i === selection2.endLine) {
16866
- text = fullText.substring(selection2.startCol, selection2.endCol);
16867
- } else if (i === selection2.startLine) {
16868
- text = fullText.substring(selection2.startCol);
16869
- } else if (i === selection2.endLine) {
16870
- text = fullText.substring(0, selection2.endCol);
17891
+ get scrollSpeed() {
17892
+ return this._scrollSpeed;
17893
+ }
17894
+ set scrollSpeed(value) {
17895
+ this._scrollSpeed = Math.max(0, value);
17896
+ }
17897
+ onMouseEvent(event) {
17898
+ if (event.type === "scroll") {
17899
+ this.handleScroll(event);
17900
+ }
17901
+ }
17902
+ handleScroll(event) {
17903
+ if (!event.scroll)
17904
+ return;
17905
+ const { direction, delta } = event.scroll;
17906
+ const viewport = this.editorView.getViewport();
17907
+ if (direction === "up") {
17908
+ const newOffsetY = Math.max(0, viewport.offsetY - delta);
17909
+ this.editorView.setViewport(viewport.offsetX, newOffsetY, viewport.width, viewport.height, true);
17910
+ this.requestRender();
17911
+ } else if (direction === "down") {
17912
+ const totalVirtualLines = this.editorView.getTotalVirtualLineCount();
17913
+ const maxOffsetY = Math.max(0, totalVirtualLines - viewport.height);
17914
+ const newOffsetY = Math.min(viewport.offsetY + delta, maxOffsetY);
17915
+ this.editorView.setViewport(viewport.offsetX, newOffsetY, viewport.width, viewport.height, true);
17916
+ this.requestRender();
17917
+ }
17918
+ if (this._wrapMode === "none") {
17919
+ if (direction === "left") {
17920
+ const newOffsetX = Math.max(0, viewport.offsetX - delta);
17921
+ this.editorView.setViewport(newOffsetX, viewport.offsetY, viewport.width, viewport.height, true);
17922
+ this.requestRender();
17923
+ } else if (direction === "right") {
17924
+ const newOffsetX = viewport.offsetX + delta;
17925
+ this.editorView.setViewport(newOffsetX, viewport.offsetY, viewport.width, viewport.height, true);
17926
+ this.requestRender();
16871
17927
  }
16872
- lines.push(text);
16873
17928
  }
16874
- return lines.join(`
16875
- `);
16876
17929
  }
16877
- clearSelection() {
16878
- this._selectionStart = null;
16879
- this._selectionEnd = null;
16880
- this._isDragging = false;
16881
- this.stopAutoScroll();
17930
+ onResize(width, height) {
17931
+ this.editorView.setViewportSize(width, height);
16882
17932
  }
16883
- stopAutoScroll() {
16884
- if (this._autoScrollInterval !== null) {
16885
- this.clock.clearInterval(this._autoScrollInterval);
16886
- this._autoScrollInterval = null;
17933
+ refreshLocalSelection() {
17934
+ if (this.lastLocalSelection) {
17935
+ return this.updateLocalSelection(this.lastLocalSelection);
16887
17936
  }
17937
+ return false;
16888
17938
  }
16889
- startAutoScroll(direction) {
16890
- this.stopAutoScroll();
16891
- this._autoScrollInterval = this.clock.setInterval(() => {
16892
- if (direction === "up") {
16893
- if (this.scrollTopIndex > 0) {
16894
- this.scrollTopIndex--;
16895
- this.isScrolledToBottom = false;
16896
- if (this._selectionEnd) {
16897
- this._selectionEnd = {
16898
- line: this.scrollTopIndex,
16899
- col: this._selectionEnd.col
16900
- };
16901
- }
16902
- this.markNeedsRerender();
16903
- } else {
16904
- this.stopAutoScroll();
16905
- }
17939
+ updateLocalSelection(localSelection) {
17940
+ if (!localSelection?.isActive) {
17941
+ this.editorView.resetLocalSelection();
17942
+ return true;
17943
+ }
17944
+ return this.editorView.setLocalSelection(localSelection.anchorX, localSelection.anchorY, localSelection.focusX, localSelection.focusY, this._selectionBg, this._selectionFg, false);
17945
+ }
17946
+ shouldStartSelection(x, y) {
17947
+ if (!this.selectable)
17948
+ return false;
17949
+ const localX = x - this.x;
17950
+ const localY = y - this.y;
17951
+ return localX >= 0 && localX < this.width && localY >= 0 && localY < this.height;
17952
+ }
17953
+ onSelectionChanged(selection2) {
17954
+ const localSelection = convertGlobalToLocalSelection(selection2, this.x, this.y);
17955
+ this.lastLocalSelection = localSelection;
17956
+ const updateCursor = true;
17957
+ const followCursor = this._keyboardSelectionActive;
17958
+ let changed;
17959
+ if (!localSelection?.isActive) {
17960
+ this._keyboardSelectionActive = false;
17961
+ this.editorView.resetLocalSelection();
17962
+ changed = true;
17963
+ } else if (selection2?.isStart) {
17964
+ changed = this.editorView.setLocalSelection(localSelection.anchorX, localSelection.anchorY, localSelection.focusX, localSelection.focusY, this._selectionBg, this._selectionFg, updateCursor, followCursor);
17965
+ } else {
17966
+ changed = this.editorView.updateLocalSelection(localSelection.anchorX, localSelection.anchorY, localSelection.focusX, localSelection.focusY, this._selectionBg, this._selectionFg, updateCursor, followCursor);
17967
+ }
17968
+ if (changed && localSelection?.isActive && selection2?.isDragging) {
17969
+ const viewport = this.editorView.getViewport();
17970
+ const focusY = localSelection.focusY;
17971
+ const scrollMargin = Math.max(1, Math.floor(viewport.height * this._scrollMargin));
17972
+ if (focusY < scrollMargin) {
17973
+ this._autoScrollVelocity = -this._scrollSpeed;
17974
+ } else if (focusY >= viewport.height - scrollMargin) {
17975
+ this._autoScrollVelocity = this._scrollSpeed;
16906
17976
  } else {
16907
- const displayLineCount = this._displayLines.length;
16908
- const logAreaHeight = Math.max(1, this.consoleHeight - 1);
16909
- const maxScrollTop = Math.max(0, displayLineCount - logAreaHeight);
16910
- if (this.scrollTopIndex < maxScrollTop) {
16911
- this.scrollTopIndex++;
16912
- this.isScrolledToBottom = this.scrollTopIndex === maxScrollTop;
16913
- if (this._selectionEnd) {
16914
- const maxLine = this.scrollTopIndex + logAreaHeight - 1;
16915
- this._selectionEnd = {
16916
- line: Math.min(maxLine, displayLineCount - 1),
16917
- col: this._selectionEnd.col
16918
- };
16919
- }
16920
- this.markNeedsRerender();
16921
- } else {
16922
- this.stopAutoScroll();
17977
+ this._autoScrollVelocity = 0;
17978
+ }
17979
+ } else {
17980
+ this._keyboardSelectionActive = false;
17981
+ this._autoScrollVelocity = 0;
17982
+ this._autoScrollAccumulator = 0;
17983
+ }
17984
+ if (changed) {
17985
+ this.requestRender();
17986
+ }
17987
+ return this.hasSelection();
17988
+ }
17989
+ onUpdate(deltaTime) {
17990
+ super.onUpdate(deltaTime);
17991
+ if (this._autoScrollVelocity !== 0 && this.hasSelection()) {
17992
+ const deltaSeconds = deltaTime / 1000;
17993
+ this._autoScrollAccumulator += this._autoScrollVelocity * deltaSeconds;
17994
+ const linesToScroll = Math.floor(Math.abs(this._autoScrollAccumulator));
17995
+ if (linesToScroll > 0) {
17996
+ const direction = this._autoScrollVelocity > 0 ? 1 : -1;
17997
+ const viewport = this.editorView.getViewport();
17998
+ const totalVirtualLines = this.editorView.getTotalVirtualLineCount();
17999
+ const maxOffsetY = Math.max(0, totalVirtualLines - viewport.height);
18000
+ const newOffsetY = Math.max(0, Math.min(viewport.offsetY + direction * linesToScroll, maxOffsetY));
18001
+ if (newOffsetY !== viewport.offsetY) {
18002
+ this.editorView.setViewport(viewport.offsetX, newOffsetY, viewport.width, viewport.height, false);
18003
+ this._ctx.requestSelectionUpdate();
16923
18004
  }
18005
+ this._autoScrollAccumulator -= direction * linesToScroll;
16924
18006
  }
16925
- }, 50);
18007
+ }
18008
+ }
18009
+ getSelectedText() {
18010
+ return this.editorView.getSelectedText();
18011
+ }
18012
+ hasSelection() {
18013
+ return this.editorView.hasSelection();
18014
+ }
18015
+ getSelection() {
18016
+ return this.editorView.getSelection();
18017
+ }
18018
+ refreshSelectionStyle() {
18019
+ if (this.lastLocalSelection) {
18020
+ this.updateLocalSelection(this.lastLocalSelection);
18021
+ return;
18022
+ }
18023
+ const selection2 = this.getSelection();
18024
+ if (!selection2)
18025
+ return;
18026
+ this.editorView.setSelection(selection2.start, selection2.end, this._selectionBg, this._selectionFg);
18027
+ }
18028
+ deleteSelectedText() {
18029
+ this.editorView.deleteSelectedText();
18030
+ this._ctx.clearSelection();
18031
+ this.requestRender();
18032
+ }
18033
+ setSelection(start, end) {
18034
+ this.lastLocalSelection = null;
18035
+ this.editorView.resetLocalSelection();
18036
+ this._ctx.clearSelection();
18037
+ this.editorView.setSelection(start, end, this._selectionBg, this._selectionFg);
18038
+ this.requestRender();
18039
+ }
18040
+ setSelectionInclusive(start, end) {
18041
+ this.setSelection(Math.min(start, end), Math.max(start, end) + 1);
18042
+ }
18043
+ clearSelection() {
18044
+ const had = this.hasSelection();
18045
+ this.lastLocalSelection = null;
18046
+ this.editorView.resetSelection();
18047
+ this.editorView.resetLocalSelection();
18048
+ this._ctx.clearSelection();
18049
+ if (had) {
18050
+ this.requestRender();
18051
+ }
18052
+ return had;
18053
+ }
18054
+ deleteSelection() {
18055
+ if (!this.hasSelection())
18056
+ return false;
18057
+ this.lastLocalSelection = null;
18058
+ this.deleteSelectedText();
18059
+ return true;
18060
+ }
18061
+ setCursor(row, col) {
18062
+ this.editBuffer.setCursor(row, col);
18063
+ this.requestRender();
18064
+ }
18065
+ insertChar(char) {
18066
+ if (this.hasSelection()) {
18067
+ this.deleteSelectedText();
18068
+ }
18069
+ this.editBuffer.insertChar(char);
18070
+ this.requestRender();
18071
+ }
18072
+ insertText(text) {
18073
+ if (this.hasSelection()) {
18074
+ this.deleteSelectedText();
18075
+ }
18076
+ this.editBuffer.insertText(text);
18077
+ this.requestRender();
18078
+ }
18079
+ deleteChar() {
18080
+ if (this.hasSelection()) {
18081
+ this.deleteSelectedText();
18082
+ return true;
18083
+ }
18084
+ this._ctx.clearSelection();
18085
+ this.editBuffer.deleteChar();
18086
+ this.requestRender();
18087
+ return true;
18088
+ }
18089
+ deleteCharBackward() {
18090
+ if (this.hasSelection()) {
18091
+ this.deleteSelectedText();
18092
+ return true;
18093
+ }
18094
+ this._ctx.clearSelection();
18095
+ this.editBuffer.deleteCharBackward();
18096
+ this.requestRender();
18097
+ return true;
16926
18098
  }
16927
- triggerCopy() {
16928
- if (!this.hasSelection())
16929
- return;
16930
- const text = this.getSelectedText();
16931
- if (text && this.options.onCopySelection) {
16932
- try {
16933
- this.options.onCopySelection(text);
16934
- } catch {}
16935
- this.clearSelection();
16936
- this.markNeedsRerender();
18099
+ newLine() {
18100
+ this._ctx.clearSelection();
18101
+ this.editBuffer.newLine();
18102
+ this.requestRender();
18103
+ return true;
18104
+ }
18105
+ deleteLine() {
18106
+ this._ctx.clearSelection();
18107
+ this.editBuffer.deleteLine();
18108
+ this.requestRender();
18109
+ return true;
18110
+ }
18111
+ moveCursorLeft(options) {
18112
+ const select = options?.select ?? false;
18113
+ if (!select && this.hasSelection()) {
18114
+ const selection2 = this.getSelection();
18115
+ this.editBuffer.setCursorByOffset(selection2.start);
18116
+ this._ctx.clearSelection();
18117
+ this.requestRender();
18118
+ return true;
16937
18119
  }
18120
+ this.updateSelectionForMovement(select, true);
18121
+ this.editBuffer.moveCursorLeft();
18122
+ this.updateSelectionForMovement(select, false);
18123
+ this.requestRender();
18124
+ return true;
16938
18125
  }
16939
- getLineSelectionRange(lineIndex) {
16940
- const selection2 = this.normalizeSelection();
16941
- if (!selection2)
16942
- return null;
16943
- if (lineIndex < selection2.startLine || lineIndex > selection2.endLine) {
16944
- return null;
18126
+ moveCursorRight(options) {
18127
+ const select = options?.select ?? false;
18128
+ if (!select && this.hasSelection()) {
18129
+ const selection2 = this.getSelection();
18130
+ const targetOffset = this.cursorOffset === selection2.start ? selection2.end - 1 : selection2.end;
18131
+ this.editBuffer.setCursorByOffset(targetOffset);
18132
+ this._ctx.clearSelection();
18133
+ this.requestRender();
18134
+ return true;
16945
18135
  }
16946
- const line = this._displayLines[lineIndex];
16947
- if (!line)
16948
- return null;
16949
- const linePrefix = line.indent ? " ".repeat(INDENT_WIDTH) : "";
16950
- const textAvailableWidth = this.consoleWidth - 1 - (line.indent ? INDENT_WIDTH : 0);
16951
- const fullTextLength = linePrefix.length + Math.min(line.text.length, textAvailableWidth);
16952
- let start = 0;
16953
- let end = fullTextLength;
16954
- if (lineIndex === selection2.startLine) {
16955
- start = Math.max(0, selection2.startCol);
18136
+ this.updateSelectionForMovement(select, true);
18137
+ this.editBuffer.moveCursorRight();
18138
+ this.updateSelectionForMovement(select, false);
18139
+ this.requestRender();
18140
+ return true;
18141
+ }
18142
+ moveCursorUp(options) {
18143
+ const select = options?.select ?? false;
18144
+ this.updateSelectionForMovement(select, true);
18145
+ this.editorView.moveUpVisual();
18146
+ this.updateSelectionForMovement(select, false);
18147
+ this.requestRender();
18148
+ return true;
18149
+ }
18150
+ moveCursorDown(options) {
18151
+ const select = options?.select ?? false;
18152
+ this.updateSelectionForMovement(select, true);
18153
+ this.editorView.moveDownVisual();
18154
+ this.updateSelectionForMovement(select, false);
18155
+ this.requestRender();
18156
+ return true;
18157
+ }
18158
+ gotoLine(line) {
18159
+ this.editBuffer.gotoLine(line);
18160
+ this.requestRender();
18161
+ }
18162
+ gotoLineStart() {
18163
+ this.setCursor(this.logicalCursor.row, 0);
18164
+ }
18165
+ gotoLineTextEnd() {
18166
+ const eol = this.editBuffer.getEOL();
18167
+ this.setCursor(eol.row, eol.col);
18168
+ }
18169
+ gotoLineHome(options) {
18170
+ const select = options?.select ?? false;
18171
+ this.updateSelectionForMovement(select, true);
18172
+ const cursor = this.editorView.getCursor();
18173
+ if (cursor.col === 0 && cursor.row > 0) {
18174
+ this.editBuffer.setCursor(cursor.row - 1, 0);
18175
+ const prevLineEol = this.editBuffer.getEOL();
18176
+ this.editBuffer.setCursor(prevLineEol.row, prevLineEol.col);
18177
+ } else {
18178
+ this.editBuffer.setCursor(cursor.row, 0);
16956
18179
  }
16957
- if (lineIndex === selection2.endLine) {
16958
- end = Math.min(fullTextLength, selection2.endCol);
18180
+ this.updateSelectionForMovement(select, false);
18181
+ this.requestRender();
18182
+ return true;
18183
+ }
18184
+ gotoLineEnd(options) {
18185
+ const select = options?.select ?? false;
18186
+ this.updateSelectionForMovement(select, true);
18187
+ const cursor = this.editorView.getCursor();
18188
+ const eol = this.editBuffer.getEOL();
18189
+ const lineCount = this.editBuffer.getLineCount();
18190
+ if (cursor.col === eol.col && cursor.row < lineCount - 1) {
18191
+ this.editBuffer.setCursor(cursor.row + 1, 0);
18192
+ } else {
18193
+ this.editBuffer.setCursor(eol.row, eol.col);
16959
18194
  }
16960
- if (start >= end)
16961
- return null;
16962
- return { start, end };
18195
+ this.updateSelectionForMovement(select, false);
18196
+ this.requestRender();
18197
+ return true;
16963
18198
  }
16964
- handleMouse(event) {
16965
- if (!this.isVisible)
16966
- return false;
16967
- const localX = event.x - this.consoleX;
16968
- const localY = event.y - this.consoleY;
16969
- if (localX < 0 || localX >= this.consoleWidth || localY < 0 || localY >= this.consoleHeight) {
16970
- return false;
18199
+ gotoVisualLineHome(options) {
18200
+ const select = options?.select ?? false;
18201
+ this.updateSelectionForMovement(select, true);
18202
+ const sol = this.editorView.getVisualSOL();
18203
+ this.editBuffer.setCursor(sol.logicalRow, sol.logicalCol);
18204
+ this.updateSelectionForMovement(select, false);
18205
+ this.requestRender();
18206
+ return true;
18207
+ }
18208
+ gotoVisualLineEnd(options) {
18209
+ const select = options?.select ?? false;
18210
+ this.updateSelectionForMovement(select, true);
18211
+ const eol = this.editorView.getVisualEOL();
18212
+ this.editBuffer.setCursor(eol.logicalRow, eol.logicalCol);
18213
+ this.updateSelectionForMovement(select, false);
18214
+ this.requestRender();
18215
+ return true;
18216
+ }
18217
+ gotoBufferHome(options) {
18218
+ const select = options?.select ?? false;
18219
+ this.updateSelectionForMovement(select, true);
18220
+ this.editBuffer.setCursor(0, 0);
18221
+ this.updateSelectionForMovement(select, false);
18222
+ this.requestRender();
18223
+ return true;
18224
+ }
18225
+ gotoBufferEnd(options) {
18226
+ const select = options?.select ?? false;
18227
+ this.updateSelectionForMovement(select, true);
18228
+ this.editBuffer.gotoLine(999999);
18229
+ this.updateSelectionForMovement(select, false);
18230
+ this.requestRender();
18231
+ return true;
18232
+ }
18233
+ selectAll() {
18234
+ this.updateSelectionForMovement(false, true);
18235
+ this.editBuffer.setCursor(0, 0);
18236
+ return this.gotoBufferEnd({ select: true });
18237
+ }
18238
+ deleteToLineEnd() {
18239
+ const cursor = this.editorView.getCursor();
18240
+ const eol = this.editBuffer.getEOL();
18241
+ if (eol.col > cursor.col) {
18242
+ this.editBuffer.deleteRange(cursor.row, cursor.col, eol.row, eol.col);
16971
18243
  }
16972
- if (event.type === "scroll" && event.scroll) {
16973
- if (event.scroll.direction === "up") {
16974
- this.scrollUp();
16975
- } else if (event.scroll.direction === "down") {
16976
- this.scrollDown();
16977
- }
16978
- return true;
18244
+ this.requestRender();
18245
+ return true;
18246
+ }
18247
+ deleteToLineStart() {
18248
+ const cursor = this.editorView.getCursor();
18249
+ if (cursor.col > 0) {
18250
+ this.editBuffer.deleteRange(cursor.row, 0, cursor.row, cursor.col);
16979
18251
  }
16980
- if (localY === 0) {
16981
- if (event.type === "down" && event.button === 0 && localX >= this._copyButtonBounds.x && localX < this._copyButtonBounds.x + this._copyButtonBounds.width) {
16982
- this.triggerCopy();
16983
- return true;
16984
- }
18252
+ this.requestRender();
18253
+ return true;
18254
+ }
18255
+ undo() {
18256
+ this._ctx.clearSelection();
18257
+ this.editBuffer.undo();
18258
+ this.requestRender();
18259
+ return true;
18260
+ }
18261
+ redo() {
18262
+ this._ctx.clearSelection();
18263
+ this.editBuffer.redo();
18264
+ this.requestRender();
18265
+ return true;
18266
+ }
18267
+ moveWordForward(options) {
18268
+ const select = options?.select ?? false;
18269
+ this.updateSelectionForMovement(select, true);
18270
+ const nextWord = this.editBuffer.getNextWordBoundary();
18271
+ this.editBuffer.setCursorByOffset(nextWord.offset);
18272
+ this.updateSelectionForMovement(select, false);
18273
+ this.requestRender();
18274
+ return true;
18275
+ }
18276
+ moveWordBackward(options) {
18277
+ const select = options?.select ?? false;
18278
+ this.updateSelectionForMovement(select, true);
18279
+ const prevWord = this.editBuffer.getPrevWordBoundary();
18280
+ this.editBuffer.setCursorByOffset(prevWord.offset);
18281
+ this.updateSelectionForMovement(select, false);
18282
+ this.requestRender();
18283
+ return true;
18284
+ }
18285
+ deleteWordForward() {
18286
+ if (this.hasSelection()) {
18287
+ this.deleteSelectedText();
16985
18288
  return true;
16986
18289
  }
16987
- const lineIndex = this.scrollTopIndex + (localY - 1);
16988
- const colIndex = Math.max(0, localX - 1);
16989
- if (event.type === "down" && event.button === 0) {
16990
- this.clearSelection();
16991
- this._selectionStart = { line: lineIndex, col: colIndex };
16992
- this._selectionEnd = { line: lineIndex, col: colIndex };
16993
- this._isDragging = true;
16994
- this.markNeedsRerender();
18290
+ const currentCursor = this.editBuffer.getCursorPosition();
18291
+ const nextWord = this.editBuffer.getNextWordBoundary();
18292
+ if (nextWord.offset > currentCursor.offset) {
18293
+ this.editBuffer.deleteRange(currentCursor.row, currentCursor.col, nextWord.row, nextWord.col);
18294
+ }
18295
+ this._ctx.clearSelection();
18296
+ this.requestRender();
18297
+ return true;
18298
+ }
18299
+ deleteWordBackward() {
18300
+ if (this.hasSelection()) {
18301
+ this.deleteSelectedText();
16995
18302
  return true;
16996
18303
  }
16997
- if (event.type === "drag" && this._isDragging) {
16998
- this._selectionEnd = { line: lineIndex, col: colIndex };
16999
- const logAreaHeight = Math.max(1, this.consoleHeight - 1);
17000
- const relativeY = localY - 1;
17001
- if (relativeY <= 0) {
17002
- this.startAutoScroll("up");
17003
- } else if (relativeY >= logAreaHeight - 1) {
17004
- this.startAutoScroll("down");
18304
+ const currentCursor = this.editBuffer.getCursorPosition();
18305
+ const prevWord = this.editBuffer.getPrevWordBoundary();
18306
+ if (prevWord.offset < currentCursor.offset) {
18307
+ this.editBuffer.deleteRange(prevWord.row, prevWord.col, currentCursor.row, currentCursor.col);
18308
+ }
18309
+ this._ctx.clearSelection();
18310
+ this.requestRender();
18311
+ return true;
18312
+ }
18313
+ setupMeasureFunc() {
18314
+ const measureFunc = (width, widthMode, height, heightMode) => {
18315
+ let effectiveWidth;
18316
+ if (widthMode === MeasureMode.Undefined || isNaN(width)) {
18317
+ effectiveWidth = 0;
17005
18318
  } else {
17006
- this.stopAutoScroll();
18319
+ effectiveWidth = width;
17007
18320
  }
17008
- this.markNeedsRerender();
17009
- return true;
17010
- }
17011
- if (event.type === "up") {
17012
- if (this._isDragging) {
17013
- this._selectionEnd = { line: lineIndex, col: colIndex };
17014
- this._isDragging = false;
17015
- this.stopAutoScroll();
17016
- this.markNeedsRerender();
18321
+ const effectiveHeight = isNaN(height) ? 1 : height;
18322
+ const measureResult = this.editorView.measureForDimensions(Math.floor(effectiveWidth), Math.floor(effectiveHeight));
18323
+ const measuredWidth = measureResult ? Math.max(1, measureResult.widthColsMax) : 1;
18324
+ const measuredHeight = measureResult ? Math.max(1, measureResult.lineCount) : 1;
18325
+ if (widthMode === MeasureMode.AtMost && this._positionType !== "absolute") {
18326
+ return {
18327
+ width: Math.min(effectiveWidth, measuredWidth),
18328
+ height: Math.min(effectiveHeight, measuredHeight)
18329
+ };
17017
18330
  }
17018
- return true;
18331
+ return {
18332
+ width: measuredWidth,
18333
+ height: measuredHeight
18334
+ };
18335
+ };
18336
+ this.yogaNode.setMeasureFunc(measureFunc);
18337
+ }
18338
+ render(buffer, deltaTime) {
18339
+ if (!this.visible)
18340
+ return;
18341
+ if (this.isDestroyed)
18342
+ return;
18343
+ this.markClean();
18344
+ this._ctx.addToHitGrid(this.x, this.y, this.width, this.height, this.num);
18345
+ this.renderSelf(buffer);
18346
+ this.renderCursor(buffer);
18347
+ }
18348
+ renderSelf(buffer) {
18349
+ buffer.drawEditorView(this.editorView, this.x, this.y);
18350
+ }
18351
+ renderCursor(buffer) {
18352
+ if (!this._showCursor || !this._focused)
18353
+ return;
18354
+ const visualCursor = this.editorView.getVisualCursor();
18355
+ const cursorX = this.x + visualCursor.visualCol + 1;
18356
+ const cursorY = this.y + visualCursor.visualRow + 1;
18357
+ this._ctx.setCursorPosition(cursorX, cursorY, true);
18358
+ this._ctx.setCursorStyle({ ...this._cursorStyle, color: this._cursorColor });
18359
+ }
18360
+ focus() {
18361
+ super.focus();
18362
+ this._ctx.setCursorStyle({ ...this._cursorStyle, color: this._cursorColor });
18363
+ this.requestRender();
18364
+ }
18365
+ blur() {
18366
+ super.blur();
18367
+ this._ctx.setCursorPosition(0, 0, false);
18368
+ this.requestRender();
18369
+ }
18370
+ onRemove() {
18371
+ if (this._focused) {
18372
+ this._ctx.setCursorPosition(0, 0, false);
17019
18373
  }
17020
- return true;
17021
18374
  }
17022
- get visible() {
17023
- return this.isVisible;
18375
+ destroy() {
18376
+ if (this.isDestroyed)
18377
+ return;
18378
+ this.traits = {};
18379
+ if (this._focused) {
18380
+ this._ctx.setCursorPosition(0, 0, false);
18381
+ this.blur();
18382
+ }
18383
+ this.editorView.destroy();
18384
+ this.editBuffer.destroy();
18385
+ super.destroy();
17024
18386
  }
17025
- get bounds() {
17026
- return {
17027
- x: this.consoleX,
17028
- y: this.consoleY,
17029
- width: this.consoleWidth,
17030
- height: this.consoleHeight
17031
- };
18387
+ set onCursorChange(handler) {
18388
+ this._cursorChangeListener = handler;
17032
18389
  }
17033
- saveLogsToFile() {
17034
- try {
17035
- const timestamp = Date.now();
17036
- const filename = `_console_${timestamp}.log`;
17037
- const filepath = path5.join(process.cwd(), filename);
17038
- const allLogEntries = [...this._allLogEntries, ...terminalConsoleCache.cachedLogs];
17039
- const logLines = [];
17040
- for (const [date, level, args, callerInfo] of allLogEntries) {
17041
- const timestampStr = this.formatTimestamp(date);
17042
- const callerSource = callerInfo ? `${callerInfo.fileName}:${callerInfo.lineNumber}` : "unknown";
17043
- const prefix = `[${timestampStr}] [${level}]` + (this._debugModeEnabled ? ` [${callerSource}]` : "") + " ";
17044
- const formattedArgs = this.formatArguments(args);
17045
- logLines.push(prefix + formattedArgs);
18390
+ get onCursorChange() {
18391
+ return this._cursorChangeListener;
18392
+ }
18393
+ set onContentChange(handler) {
18394
+ this._contentChangeListener = handler;
18395
+ }
18396
+ get onContentChange() {
18397
+ return this._contentChangeListener;
18398
+ }
18399
+ get syntaxStyle() {
18400
+ return this.editBuffer.getSyntaxStyle();
18401
+ }
18402
+ set syntaxStyle(style) {
18403
+ this.editBuffer.setSyntaxStyle(style);
18404
+ this.requestRender();
18405
+ }
18406
+ addHighlight(lineIdx, highlight) {
18407
+ this.editBuffer.addHighlight(lineIdx, highlight);
18408
+ this.requestRender();
18409
+ }
18410
+ addHighlightByCharRange(highlight) {
18411
+ this.editBuffer.addHighlightByCharRange(highlight);
18412
+ this.requestRender();
18413
+ }
18414
+ removeHighlightsByRef(hlRef) {
18415
+ this.editBuffer.removeHighlightsByRef(hlRef);
18416
+ this.requestRender();
18417
+ }
18418
+ clearLineHighlights(lineIdx) {
18419
+ this.editBuffer.clearLineHighlights(lineIdx);
18420
+ this.requestRender();
18421
+ }
18422
+ clearAllHighlights() {
18423
+ this.editBuffer.clearAllHighlights();
18424
+ this.requestRender();
18425
+ }
18426
+ getLineHighlights(lineIdx) {
18427
+ return this.editBuffer.getLineHighlights(lineIdx);
18428
+ }
18429
+ setText(text) {
18430
+ this.editBuffer.setText(text);
18431
+ this.yogaNode.markDirty();
18432
+ this.requestRender();
18433
+ }
18434
+ replaceText(text) {
18435
+ this.editBuffer.replaceText(text);
18436
+ this.yogaNode.markDirty();
18437
+ this.requestRender();
18438
+ }
18439
+ clear() {
18440
+ this.editBuffer.clear();
18441
+ this.editBuffer.clearAllHighlights();
18442
+ this.yogaNode.markDirty();
18443
+ this.requestRender();
18444
+ }
18445
+ deleteRange(startLine, startCol, endLine, endCol) {
18446
+ this.editBuffer.deleteRange(startLine, startCol, endLine, endCol);
18447
+ this.yogaNode.markDirty();
18448
+ this.requestRender();
18449
+ }
18450
+ getTextRange(startOffset, endOffset) {
18451
+ return this.editBuffer.getTextRange(startOffset, endOffset);
18452
+ }
18453
+ getTextRangeByCoords(startRow, startCol, endRow, endCol) {
18454
+ return this.editBuffer.getTextRangeByCoords(startRow, startCol, endRow, endCol);
18455
+ }
18456
+ updateSelectionForMovement(shiftPressed, isBeforeMovement) {
18457
+ if (!this.selectable)
18458
+ return;
18459
+ if (!shiftPressed) {
18460
+ this._keyboardSelectionActive = false;
18461
+ this._ctx.clearSelection();
18462
+ return;
18463
+ }
18464
+ this._keyboardSelectionActive = true;
18465
+ const visualCursor = this.editorView.getVisualCursor();
18466
+ const cursorX = this.x + visualCursor.visualCol;
18467
+ const cursorY = this.y + visualCursor.visualRow;
18468
+ if (isBeforeMovement) {
18469
+ if (!this._ctx.hasSelection) {
18470
+ this._ctx.startSelection(this, cursorX, cursorY);
17046
18471
  }
17047
- const content = logLines.join(`
17048
- `);
17049
- fs.writeFileSync(filepath, content, "utf8");
17050
- console.info(`Console logs saved to: ${filename}`);
17051
- } catch (error) {
17052
- console.error(`Failed to save console logs:`, error);
18472
+ return;
17053
18473
  }
18474
+ this._ctx.updateSelection(this, cursorX, cursorY, { finishDragging: true });
17054
18475
  }
17055
18476
  }
17056
18477
 
@@ -17102,7 +18523,7 @@ class Clipboard {
17102
18523
  }
17103
18524
 
17104
18525
  // src/renderer.ts
17105
- import { EventEmitter as EventEmitter8 } from "events";
18526
+ import { EventEmitter as EventEmitter9 } from "events";
17106
18527
 
17107
18528
  // src/lib/objects-in-viewport.ts
17108
18529
  function getObjectsInViewport(viewport, objects, direction = "column", padding = 10, minTriggerSize = 16) {
@@ -17457,6 +18878,7 @@ var CliRenderEvents;
17457
18878
  CliRenderEvents2["RESIZE"] = "resize";
17458
18879
  CliRenderEvents2["FOCUS"] = "focus";
17459
18880
  CliRenderEvents2["BLUR"] = "blur";
18881
+ CliRenderEvents2["FOCUSED_EDITOR"] = "focused_editor";
17460
18882
  CliRenderEvents2["THEME_MODE"] = "theme_mode";
17461
18883
  CliRenderEvents2["CAPABILITIES"] = "capabilities";
17462
18884
  CliRenderEvents2["SELECTION"] = "selection";
@@ -17474,7 +18896,7 @@ var RendererControlState;
17474
18896
  RendererControlState2["EXPLICIT_STOPPED"] = "explicit_stopped";
17475
18897
  })(RendererControlState ||= {});
17476
18898
 
17477
- class CliRenderer extends EventEmitter8 {
18899
+ class CliRenderer extends EventEmitter9 {
17478
18900
  static animationFrameId = 0;
17479
18901
  lib;
17480
18902
  rendererPtr;
@@ -17669,8 +19091,7 @@ Captured output:
17669
19091
  "SIGHUP",
17670
19092
  "SIGBREAK",
17671
19093
  "SIGPIPE",
17672
- "SIGBUS",
17673
- "SIGFPE"
19094
+ "SIGBUS"
17674
19095
  ];
17675
19096
  this.clipboard = new Clipboard(this.lib, this.rendererPtr);
17676
19097
  this.resizeDebounceDelay = config.debounceDelay || 100;
@@ -17788,6 +19209,13 @@ Captured output:
17788
19209
  get currentFocusedRenderable() {
17789
19210
  return this._currentFocusedRenderable;
17790
19211
  }
19212
+ get currentFocusedEditor() {
19213
+ if (!this._currentFocusedRenderable)
19214
+ return null;
19215
+ if (!isEditBufferRenderable(this._currentFocusedRenderable))
19216
+ return null;
19217
+ return this._currentFocusedRenderable;
19218
+ }
17791
19219
  normalizeClockTime(now, fallback) {
17792
19220
  if (Number.isFinite(now)) {
17793
19221
  return now;
@@ -17803,10 +19231,15 @@ Captured output:
17803
19231
  focusRenderable(renderable) {
17804
19232
  if (this._currentFocusedRenderable === renderable)
17805
19233
  return;
19234
+ const prev = this.currentFocusedEditor;
17806
19235
  if (this._currentFocusedRenderable) {
17807
19236
  this._currentFocusedRenderable.blur();
17808
19237
  }
17809
19238
  this._currentFocusedRenderable = renderable;
19239
+ const next = this.currentFocusedEditor;
19240
+ if (prev !== next) {
19241
+ this.emit("focused_editor" /* FOCUSED_EDITOR */, next, prev);
19242
+ }
17810
19243
  }
17811
19244
  setCapturedRenderable(renderable) {
17812
19245
  if (this.capturedRenderable === renderable) {
@@ -19166,7 +20599,7 @@ Captured output:
19166
20599
  }
19167
20600
  }
19168
20601
 
19169
- export { __toESM, __commonJS, __export, __require, Edge, Gutter, MeasureMode, exports_src, isValidBorderStyle, parseBorderStyle, BorderChars, getBorderFromSides, getBorderSides, borderCharsToArray, BorderCharArrays, KeyEvent, PasteEvent, KeyHandler, InternalKeyHandler, RGBA, 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, 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, addDefaultParsers, TreeSitterClient, DataPathsManager, getDataPaths, extensionToFiletype, basenameToFiletype, extToFiletype, pathToFiletype, infoStringToFiletype, main, getTreeSitterClient, ExtmarksController, createExtmarksController, TerminalPalette, createTerminalPalette, decodePasteBytes, stripAnsiSequences, detectLinks, TextBuffer, SpanInfoStruct, LogLevel2 as LogLevel, setRenderLibPath, resolveRenderLib, OptimizedBuffer, h, isVNode, maybeMakeRenderable, wrapWithDelegates, instantiate, delegate, isValidPercentage, LayoutEvents, RenderableEvents, isRenderable, BaseRenderable, Renderable, RootRenderable, ANSI, defaultKeyAliases, mergeKeyAliases, mergeKeyBindings, getKeyBindingKey, buildKeyBindingsMap, capture, ConsolePosition, TerminalConsole, getObjectsInViewport, buildKittyKeyboardFlags, MouseEvent, MouseButton, createCliRenderer, CliRenderEvents, RendererControlState, CliRenderer };
20602
+ export { __toESM, __commonJS, __export, __require, Edge, Gutter, MeasureMode, exports_src, isValidBorderStyle, parseBorderStyle, BorderChars, getBorderFromSides, getBorderSides, borderCharsToArray, BorderCharArrays, KeyEvent, PasteEvent, KeyHandler, InternalKeyHandler, RGBA, 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, 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, addDefaultParsers, TreeSitterClient, DataPathsManager, getDataPaths, extensionToFiletype, basenameToFiletype, extToFiletype, pathToFiletype, infoStringToFiletype, main, getTreeSitterClient, ExtmarksController, createExtmarksController, TerminalPalette, createTerminalPalette, decodePasteBytes, stripAnsiSequences, detectLinks, TextBuffer, SpanInfoStruct, LogLevel2 as LogLevel, setRenderLibPath, resolveRenderLib, OptimizedBuffer, h, isVNode, maybeMakeRenderable, wrapWithDelegates, instantiate, delegate, isValidPercentage, LayoutEvents, RenderableEvents, isRenderable, BaseRenderable, Renderable, RootRenderable, EditBuffer, EditorView, ANSI, defaultKeyAliases, mergeKeyAliases, mergeKeyBindings, getKeyBindingKey, buildKeyBindingsMap, capture, ConsolePosition, TerminalConsole, getObjectsInViewport, EditBufferRenderableEvents, isEditBufferRenderable, EditBufferRenderable, buildKittyKeyboardFlags, MouseEvent, MouseButton, createCliRenderer, CliRenderEvents, RendererControlState, CliRenderer };
19170
20603
 
19171
- //# debugId=AAC1AF32CFE7F73F64756E2164756E21
19172
- //# sourceMappingURL=index-wv534m5j.js.map
20604
+ //# debugId=7AE492200477211D64756E2164756E21
20605
+ //# sourceMappingURL=index-kgg0v67t.js.map