@opentui/core 0.1.95 → 0.1.96

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