@opentui/core 0.0.0-20250923-da12fb15 → 0.0.0-20250924-9d06e8e4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/3d.js +1 -1
- package/Renderable.d.ts +7 -7
- package/animation/Timeline.d.ts +2 -1
- package/{index-ce0mn4wa.js → index-bq6h36ne.js} +319 -34
- package/index-bq6h36ne.js.map +39 -0
- package/index.js +18 -2
- package/index.js.map +8 -8
- package/lib/KeyHandler.d.ts +51 -12
- package/lib/env.d.ts +41 -0
- package/lib/index.d.ts +1 -0
- package/lib/parse.keypress.d.ts +2 -2
- package/package.json +7 -7
- package/renderables/Input.d.ts +2 -2
- package/renderables/ScrollBar.d.ts +2 -2
- package/renderables/ScrollBox.d.ts +2 -2
- package/renderables/Select.d.ts +2 -2
- package/renderables/TabSelect.d.ts +2 -2
- package/renderer.d.ts +2 -1
- package/testing.js +1 -1
- package/types.d.ts +2 -1
- package/index-ce0mn4wa.js.map +0 -38
- /package/{singleton.d.ts → lib/singleton.d.ts} +0 -0
package/3d.js
CHANGED
package/Renderable.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EventEmitter } from "events";
|
|
2
2
|
import { type Node as YogaNode } from "yoga-layout";
|
|
3
3
|
import { OptimizedBuffer } from "./buffer";
|
|
4
|
-
import type {
|
|
4
|
+
import type { KeyEvent, PasteEvent } from "./lib/KeyHandler";
|
|
5
5
|
import type { Selection } from "./lib/selection";
|
|
6
6
|
import { type AlignString, type FlexDirectionString, type JustifyString, type OverflowString, type PositionTypeString, type WrapString } from "./lib/yoga.options";
|
|
7
7
|
import { type VNode } from "./renderables/composition/vnode";
|
|
@@ -78,7 +78,7 @@ export interface RenderableOptions<T extends BaseRenderable = BaseRenderable> ex
|
|
|
78
78
|
onMouseOut?: (this: T, event: MouseEvent) => void;
|
|
79
79
|
onMouseScroll?: (this: T, event: MouseEvent) => void;
|
|
80
80
|
onPaste?: (this: T, text: string) => void;
|
|
81
|
-
onKeyDown?: (key:
|
|
81
|
+
onKeyDown?: (key: KeyEvent) => void;
|
|
82
82
|
onSizeChange?: (this: T) => void;
|
|
83
83
|
}
|
|
84
84
|
export declare function isRenderable(obj: any): obj is Renderable;
|
|
@@ -126,8 +126,8 @@ export declare abstract class Renderable extends BaseRenderable {
|
|
|
126
126
|
protected frameBuffer: OptimizedBuffer | null;
|
|
127
127
|
protected _focusable: boolean;
|
|
128
128
|
protected _focused: boolean;
|
|
129
|
-
protected keypressHandler: ((key:
|
|
130
|
-
protected pasteHandler: ((
|
|
129
|
+
protected keypressHandler: ((key: KeyEvent) => void) | null;
|
|
130
|
+
protected pasteHandler: ((event: PasteEvent) => void) | null;
|
|
131
131
|
private _live;
|
|
132
132
|
protected _liveCount: number;
|
|
133
133
|
private _sizeChangeListener;
|
|
@@ -169,7 +169,7 @@ export declare abstract class Renderable extends BaseRenderable {
|
|
|
169
169
|
get liveCount(): number;
|
|
170
170
|
set live(value: boolean);
|
|
171
171
|
protected propagateLiveCount(delta: number): void;
|
|
172
|
-
handleKeyPress?(key:
|
|
172
|
+
handleKeyPress?(key: KeyEvent | string): boolean;
|
|
173
173
|
handlePaste?(text: string): void;
|
|
174
174
|
findDescendantById(id: string): Renderable | undefined;
|
|
175
175
|
requestRender(): void;
|
|
@@ -276,8 +276,8 @@ export declare abstract class Renderable extends BaseRenderable {
|
|
|
276
276
|
set onMouseScroll(handler: ((event: MouseEvent) => void) | undefined);
|
|
277
277
|
set onPaste(handler: ((text: string) => void) | undefined);
|
|
278
278
|
get onPaste(): ((text: string) => void) | undefined;
|
|
279
|
-
set onKeyDown(handler: ((key:
|
|
280
|
-
get onKeyDown(): ((key:
|
|
279
|
+
set onKeyDown(handler: ((key: KeyEvent) => void) | undefined);
|
|
280
|
+
get onKeyDown(): ((key: KeyEvent) => void) | undefined;
|
|
281
281
|
set onSizeChange(handler: (() => void) | undefined);
|
|
282
282
|
get onSizeChange(): (() => void) | undefined;
|
|
283
283
|
private applyEventOptions;
|
package/animation/Timeline.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { CliRenderer } from "../renderer";
|
|
1
2
|
export interface TimelineOptions {
|
|
2
3
|
duration?: number;
|
|
3
4
|
loop?: boolean;
|
|
@@ -111,7 +112,7 @@ declare class TimelineEngine {
|
|
|
111
112
|
defaults: {
|
|
112
113
|
frameRate: number;
|
|
113
114
|
};
|
|
114
|
-
attach(renderer:
|
|
115
|
+
attach(renderer: CliRenderer): void;
|
|
115
116
|
detach(): void;
|
|
116
117
|
private updateLiveState;
|
|
117
118
|
private onTimelineStateChange;
|
|
@@ -2191,6 +2191,62 @@ var ANSI = {
|
|
|
2191
2191
|
};
|
|
2192
2192
|
|
|
2193
2193
|
// src/lib/KeyHandler.ts
|
|
2194
|
+
class KeyEvent {
|
|
2195
|
+
name;
|
|
2196
|
+
ctrl;
|
|
2197
|
+
meta;
|
|
2198
|
+
shift;
|
|
2199
|
+
option;
|
|
2200
|
+
sequence;
|
|
2201
|
+
number;
|
|
2202
|
+
raw;
|
|
2203
|
+
eventType;
|
|
2204
|
+
code;
|
|
2205
|
+
super;
|
|
2206
|
+
hyper;
|
|
2207
|
+
capsLock;
|
|
2208
|
+
numLock;
|
|
2209
|
+
baseCode;
|
|
2210
|
+
_defaultPrevented = false;
|
|
2211
|
+
constructor(key) {
|
|
2212
|
+
this.name = key.name;
|
|
2213
|
+
this.ctrl = key.ctrl;
|
|
2214
|
+
this.meta = key.meta;
|
|
2215
|
+
this.shift = key.shift;
|
|
2216
|
+
this.option = key.option;
|
|
2217
|
+
this.sequence = key.sequence;
|
|
2218
|
+
this.number = key.number;
|
|
2219
|
+
this.raw = key.raw;
|
|
2220
|
+
this.eventType = key.eventType;
|
|
2221
|
+
this.code = key.code;
|
|
2222
|
+
this.super = key.super;
|
|
2223
|
+
this.hyper = key.hyper;
|
|
2224
|
+
this.capsLock = key.capsLock;
|
|
2225
|
+
this.numLock = key.numLock;
|
|
2226
|
+
this.baseCode = key.baseCode;
|
|
2227
|
+
}
|
|
2228
|
+
get defaultPrevented() {
|
|
2229
|
+
return this._defaultPrevented;
|
|
2230
|
+
}
|
|
2231
|
+
preventDefault() {
|
|
2232
|
+
this._defaultPrevented = true;
|
|
2233
|
+
}
|
|
2234
|
+
}
|
|
2235
|
+
|
|
2236
|
+
class PasteEvent {
|
|
2237
|
+
text;
|
|
2238
|
+
_defaultPrevented = false;
|
|
2239
|
+
constructor(text) {
|
|
2240
|
+
this.text = text;
|
|
2241
|
+
}
|
|
2242
|
+
get defaultPrevented() {
|
|
2243
|
+
return this._defaultPrevented;
|
|
2244
|
+
}
|
|
2245
|
+
preventDefault() {
|
|
2246
|
+
this._defaultPrevented = true;
|
|
2247
|
+
}
|
|
2248
|
+
}
|
|
2249
|
+
|
|
2194
2250
|
class KeyHandler extends EventEmitter {
|
|
2195
2251
|
stdin;
|
|
2196
2252
|
useKittyKeyboard;
|
|
@@ -2210,7 +2266,7 @@ class KeyHandler extends EventEmitter {
|
|
|
2210
2266
|
this.pasteBuffer.push(Bun.stripANSI(data));
|
|
2211
2267
|
if (data.endsWith(ANSI.bracketedPasteEnd)) {
|
|
2212
2268
|
this.pasteMode = false;
|
|
2213
|
-
this.emit("paste", this.pasteBuffer.join(""));
|
|
2269
|
+
this.emit("paste", new PasteEvent(this.pasteBuffer.join("")));
|
|
2214
2270
|
this.pasteBuffer = [];
|
|
2215
2271
|
}
|
|
2216
2272
|
return;
|
|
@@ -2218,16 +2274,16 @@ class KeyHandler extends EventEmitter {
|
|
|
2218
2274
|
const parsedKey = parseKeypress(key, { useKittyKeyboard: this.useKittyKeyboard });
|
|
2219
2275
|
switch (parsedKey.eventType) {
|
|
2220
2276
|
case "press":
|
|
2221
|
-
this.emit("keypress", parsedKey);
|
|
2277
|
+
this.emit("keypress", new KeyEvent(parsedKey));
|
|
2222
2278
|
break;
|
|
2223
2279
|
case "repeat":
|
|
2224
|
-
this.emit("keyrepeat", parsedKey);
|
|
2280
|
+
this.emit("keyrepeat", new KeyEvent(parsedKey));
|
|
2225
2281
|
break;
|
|
2226
2282
|
case "release":
|
|
2227
|
-
this.emit("keyrelease", parsedKey);
|
|
2283
|
+
this.emit("keyrelease", new KeyEvent(parsedKey));
|
|
2228
2284
|
break;
|
|
2229
2285
|
default:
|
|
2230
|
-
this.emit("keypress", parsedKey);
|
|
2286
|
+
this.emit("keypress", new KeyEvent(parsedKey));
|
|
2231
2287
|
break;
|
|
2232
2288
|
}
|
|
2233
2289
|
};
|
|
@@ -2238,6 +2294,45 @@ class KeyHandler extends EventEmitter {
|
|
|
2238
2294
|
}
|
|
2239
2295
|
}
|
|
2240
2296
|
|
|
2297
|
+
class InternalKeyHandler extends KeyHandler {
|
|
2298
|
+
renderableHandlers = new Map;
|
|
2299
|
+
constructor(stdin, useKittyKeyboard = false) {
|
|
2300
|
+
super(stdin, useKittyKeyboard);
|
|
2301
|
+
}
|
|
2302
|
+
emit(event, ...args) {
|
|
2303
|
+
return this.emitWithPriority(event, ...args);
|
|
2304
|
+
}
|
|
2305
|
+
emitWithPriority(event, ...args) {
|
|
2306
|
+
const hasGlobalListeners = super.emit(event, ...args);
|
|
2307
|
+
const renderableSet = this.renderableHandlers.get(event);
|
|
2308
|
+
let hasRenderableListeners = false;
|
|
2309
|
+
if (renderableSet && renderableSet.size > 0) {
|
|
2310
|
+
hasRenderableListeners = true;
|
|
2311
|
+
if (event === "keypress" || event === "keyrepeat" || event === "keyrelease" || event === "paste") {
|
|
2312
|
+
const keyEvent = args[0];
|
|
2313
|
+
if (keyEvent.defaultPrevented)
|
|
2314
|
+
return hasGlobalListeners || hasRenderableListeners;
|
|
2315
|
+
}
|
|
2316
|
+
for (const handler of renderableSet) {
|
|
2317
|
+
handler(...args);
|
|
2318
|
+
}
|
|
2319
|
+
}
|
|
2320
|
+
return hasGlobalListeners || hasRenderableListeners;
|
|
2321
|
+
}
|
|
2322
|
+
onInternal(event, handler) {
|
|
2323
|
+
if (!this.renderableHandlers.has(event)) {
|
|
2324
|
+
this.renderableHandlers.set(event, new Set);
|
|
2325
|
+
}
|
|
2326
|
+
this.renderableHandlers.get(event).add(handler);
|
|
2327
|
+
}
|
|
2328
|
+
offInternal(event, handler) {
|
|
2329
|
+
const handlers = this.renderableHandlers.get(event);
|
|
2330
|
+
if (handlers) {
|
|
2331
|
+
handlers.delete(handler);
|
|
2332
|
+
}
|
|
2333
|
+
}
|
|
2334
|
+
}
|
|
2335
|
+
|
|
2241
2336
|
// src/lib/RGBA.ts
|
|
2242
2337
|
class RGBA {
|
|
2243
2338
|
buffer;
|
|
@@ -4814,6 +4909,166 @@ class ASCIIFontSelectionHelper {
|
|
|
4814
4909
|
return previousSelection?.start !== this.localSelection?.start || previousSelection?.end !== this.localSelection?.end;
|
|
4815
4910
|
}
|
|
4816
4911
|
}
|
|
4912
|
+
|
|
4913
|
+
// src/lib/singleton.ts
|
|
4914
|
+
var singletonCacheSymbol = Symbol.for("@opentui/core/singleton");
|
|
4915
|
+
function singleton(key, factory) {
|
|
4916
|
+
const bag = globalThis[singletonCacheSymbol] ??= {};
|
|
4917
|
+
if (!(key in bag)) {
|
|
4918
|
+
bag[key] = factory();
|
|
4919
|
+
}
|
|
4920
|
+
return bag[key];
|
|
4921
|
+
}
|
|
4922
|
+
|
|
4923
|
+
// src/lib/env.ts
|
|
4924
|
+
var envRegistry = {};
|
|
4925
|
+
function registerEnvVar(config) {
|
|
4926
|
+
const existing = envRegistry[config.name];
|
|
4927
|
+
if (existing) {
|
|
4928
|
+
if (existing.description !== config.description || existing.type !== config.type || existing.default !== config.default) {
|
|
4929
|
+
throw new Error(`Environment variable "${config.name}" is already registered with different configuration. ` + `Existing: ${JSON.stringify(existing)}, New: ${JSON.stringify(config)}`);
|
|
4930
|
+
}
|
|
4931
|
+
return;
|
|
4932
|
+
}
|
|
4933
|
+
envRegistry[config.name] = config;
|
|
4934
|
+
}
|
|
4935
|
+
function normalizeBoolean(value) {
|
|
4936
|
+
const lowerValue = value.toLowerCase();
|
|
4937
|
+
return ["true", "1", "on", "yes"].includes(lowerValue);
|
|
4938
|
+
}
|
|
4939
|
+
function parseEnvValue(config) {
|
|
4940
|
+
const envValue = process.env[config.name];
|
|
4941
|
+
if (envValue === undefined && config.default !== undefined) {
|
|
4942
|
+
return config.default;
|
|
4943
|
+
}
|
|
4944
|
+
if (envValue === undefined) {
|
|
4945
|
+
throw new Error(`Required environment variable ${config.name} is not set. ${config.description}`);
|
|
4946
|
+
}
|
|
4947
|
+
switch (config.type) {
|
|
4948
|
+
case "boolean":
|
|
4949
|
+
return typeof envValue === "boolean" ? envValue : normalizeBoolean(envValue);
|
|
4950
|
+
case "number":
|
|
4951
|
+
const numValue = Number(envValue);
|
|
4952
|
+
if (isNaN(numValue)) {
|
|
4953
|
+
throw new Error(`Environment variable ${config.name} must be a valid number, got: ${envValue}`);
|
|
4954
|
+
}
|
|
4955
|
+
return numValue;
|
|
4956
|
+
case "string":
|
|
4957
|
+
default:
|
|
4958
|
+
return envValue;
|
|
4959
|
+
}
|
|
4960
|
+
}
|
|
4961
|
+
|
|
4962
|
+
class EnvStore {
|
|
4963
|
+
parsedValues = new Map;
|
|
4964
|
+
get(key) {
|
|
4965
|
+
if (this.parsedValues.has(key)) {
|
|
4966
|
+
return this.parsedValues.get(key);
|
|
4967
|
+
}
|
|
4968
|
+
if (!(key in envRegistry)) {
|
|
4969
|
+
throw new Error(`Environment variable ${key} is not registered.`);
|
|
4970
|
+
}
|
|
4971
|
+
try {
|
|
4972
|
+
const value = parseEnvValue(envRegistry[key]);
|
|
4973
|
+
this.parsedValues.set(key, value);
|
|
4974
|
+
return value;
|
|
4975
|
+
} catch (error) {
|
|
4976
|
+
throw new Error(`Failed to parse env var ${key}: ${error instanceof Error ? error.message : String(error)}`);
|
|
4977
|
+
}
|
|
4978
|
+
}
|
|
4979
|
+
has(key) {
|
|
4980
|
+
return key in envRegistry;
|
|
4981
|
+
}
|
|
4982
|
+
}
|
|
4983
|
+
var envStore = singleton("env-store", () => new EnvStore);
|
|
4984
|
+
function generateEnvMarkdown() {
|
|
4985
|
+
const configs = Object.values(envRegistry);
|
|
4986
|
+
if (configs.length === 0) {
|
|
4987
|
+
return `# Environment Variables
|
|
4988
|
+
|
|
4989
|
+
No environment variables registered.
|
|
4990
|
+
`;
|
|
4991
|
+
}
|
|
4992
|
+
let markdown = `# Environment Variables
|
|
4993
|
+
|
|
4994
|
+
`;
|
|
4995
|
+
for (const config of configs) {
|
|
4996
|
+
markdown += `## ${config.name}
|
|
4997
|
+
|
|
4998
|
+
`;
|
|
4999
|
+
markdown += `${config.description}
|
|
5000
|
+
|
|
5001
|
+
`;
|
|
5002
|
+
markdown += `**Type:** \`${config.type || "string"}\`
|
|
5003
|
+
`;
|
|
5004
|
+
if (config.default !== undefined) {
|
|
5005
|
+
const defaultValue = typeof config.default === "string" ? `"${config.default}"` : String(config.default);
|
|
5006
|
+
markdown += `**Default:** \`${defaultValue}\`
|
|
5007
|
+
`;
|
|
5008
|
+
} else {
|
|
5009
|
+
markdown += `**Default:** *Required*
|
|
5010
|
+
`;
|
|
5011
|
+
}
|
|
5012
|
+
markdown += `
|
|
5013
|
+
`;
|
|
5014
|
+
}
|
|
5015
|
+
return markdown;
|
|
5016
|
+
}
|
|
5017
|
+
function generateEnvColored() {
|
|
5018
|
+
const configs = Object.values(envRegistry);
|
|
5019
|
+
if (configs.length === 0) {
|
|
5020
|
+
return `\x1B[1;36mEnvironment Variables\x1B[0m
|
|
5021
|
+
|
|
5022
|
+
No environment variables registered.
|
|
5023
|
+
`;
|
|
5024
|
+
}
|
|
5025
|
+
let output = `\x1B[1;36mEnvironment Variables\x1B[0m
|
|
5026
|
+
|
|
5027
|
+
`;
|
|
5028
|
+
for (const config of configs) {
|
|
5029
|
+
output += `\x1B[1;33m${config.name}\x1B[0m
|
|
5030
|
+
`;
|
|
5031
|
+
output += `${config.description}
|
|
5032
|
+
`;
|
|
5033
|
+
output += `\x1B[32mType:\x1B[0m \x1B[36m${config.type || "string"}\x1B[0m
|
|
5034
|
+
`;
|
|
5035
|
+
if (config.default !== undefined) {
|
|
5036
|
+
const defaultValue = typeof config.default === "string" ? `"${config.default}"` : String(config.default);
|
|
5037
|
+
output += `\x1B[32mDefault:\x1B[0m \x1B[35m${defaultValue}\x1B[0m
|
|
5038
|
+
`;
|
|
5039
|
+
} else {
|
|
5040
|
+
output += `\x1B[32mDefault:\x1B[0m \x1B[31mRequired\x1B[0m
|
|
5041
|
+
`;
|
|
5042
|
+
}
|
|
5043
|
+
output += `
|
|
5044
|
+
`;
|
|
5045
|
+
}
|
|
5046
|
+
return output;
|
|
5047
|
+
}
|
|
5048
|
+
var env = new Proxy({}, {
|
|
5049
|
+
get(target, prop) {
|
|
5050
|
+
if (typeof prop !== "string") {
|
|
5051
|
+
return;
|
|
5052
|
+
}
|
|
5053
|
+
return envStore.get(prop);
|
|
5054
|
+
},
|
|
5055
|
+
has(target, prop) {
|
|
5056
|
+
return envStore.has(prop);
|
|
5057
|
+
},
|
|
5058
|
+
ownKeys() {
|
|
5059
|
+
return Object.keys(envRegistry);
|
|
5060
|
+
},
|
|
5061
|
+
getOwnPropertyDescriptor(target, prop) {
|
|
5062
|
+
if (envStore.has(prop)) {
|
|
5063
|
+
return {
|
|
5064
|
+
enumerable: true,
|
|
5065
|
+
configurable: true,
|
|
5066
|
+
get: () => envStore.get(prop)
|
|
5067
|
+
};
|
|
5068
|
+
}
|
|
5069
|
+
return;
|
|
5070
|
+
}
|
|
5071
|
+
});
|
|
4817
5072
|
// src/zig.ts
|
|
4818
5073
|
import { dlopen, toArrayBuffer as toArrayBuffer2, JSCallback, ptr } from "bun:ffi";
|
|
4819
5074
|
import { existsSync } from "fs";
|
|
@@ -5020,6 +5275,18 @@ var targetLibPath = module.default;
|
|
|
5020
5275
|
if (!existsSync(targetLibPath)) {
|
|
5021
5276
|
throw new Error(`opentui is not supported on the current platform: ${process.platform}-${process.arch}`);
|
|
5022
5277
|
}
|
|
5278
|
+
registerEnvVar({
|
|
5279
|
+
name: "OTUI_DEBUG_FFI",
|
|
5280
|
+
description: "Enable debug logging for the FFI bindings.",
|
|
5281
|
+
type: "boolean",
|
|
5282
|
+
default: false
|
|
5283
|
+
});
|
|
5284
|
+
registerEnvVar({
|
|
5285
|
+
name: "OTUI_TRACE_FFI",
|
|
5286
|
+
description: "Enable tracing for the FFI bindings.",
|
|
5287
|
+
type: "boolean",
|
|
5288
|
+
default: false
|
|
5289
|
+
});
|
|
5023
5290
|
function getOpenTUILib(libPath) {
|
|
5024
5291
|
const resolvedLibPath = libPath || targetLibPath;
|
|
5025
5292
|
const rawSymbols = dlopen(resolvedLibPath, {
|
|
@@ -5360,7 +5627,7 @@ function getOpenTUILib(libPath) {
|
|
|
5360
5627
|
returns: "void"
|
|
5361
5628
|
}
|
|
5362
5629
|
});
|
|
5363
|
-
if (
|
|
5630
|
+
if (env.OTUI_DEBUG_FFI || env.OTUI_TRACE_FFI) {
|
|
5364
5631
|
return {
|
|
5365
5632
|
symbols: convertToDebugSymbols(rawSymbols.symbols)
|
|
5366
5633
|
};
|
|
@@ -5374,7 +5641,7 @@ function convertToDebugSymbols(symbols) {
|
|
|
5374
5641
|
Object.entries(symbols).forEach(([key, value]) => {
|
|
5375
5642
|
debugSymbols[key] = value;
|
|
5376
5643
|
});
|
|
5377
|
-
if (
|
|
5644
|
+
if (env.OTUI_DEBUG_FFI) {
|
|
5378
5645
|
Object.entries(symbols).forEach(([key, value]) => {
|
|
5379
5646
|
if (typeof value === "function") {
|
|
5380
5647
|
debugSymbols[key] = (...args) => {
|
|
@@ -5386,7 +5653,7 @@ function convertToDebugSymbols(symbols) {
|
|
|
5386
5653
|
}
|
|
5387
5654
|
});
|
|
5388
5655
|
}
|
|
5389
|
-
if (
|
|
5656
|
+
if (env.OTUI_TRACE_FFI) {
|
|
5390
5657
|
hasTracing = true;
|
|
5391
5658
|
Object.entries(symbols).forEach(([key, value]) => {
|
|
5392
5659
|
if (typeof value === "function") {
|
|
@@ -6378,14 +6645,14 @@ class Renderable extends BaseRenderable {
|
|
|
6378
6645
|
this.handleKeyPress(key);
|
|
6379
6646
|
}
|
|
6380
6647
|
};
|
|
6381
|
-
this.pasteHandler = (
|
|
6382
|
-
this._pasteListener?.call(this, text);
|
|
6648
|
+
this.pasteHandler = (event) => {
|
|
6649
|
+
this._pasteListener?.call(this, event.text);
|
|
6383
6650
|
if (this.handlePaste) {
|
|
6384
|
-
this.handlePaste(text);
|
|
6651
|
+
this.handlePaste(event.text);
|
|
6385
6652
|
}
|
|
6386
6653
|
};
|
|
6387
|
-
this.ctx.
|
|
6388
|
-
this.ctx.
|
|
6654
|
+
this.ctx._internalKeyInput.onInternal("keypress", this.keypressHandler);
|
|
6655
|
+
this.ctx._internalKeyInput.onInternal("paste", this.pasteHandler);
|
|
6389
6656
|
this.emit("focused" /* FOCUSED */);
|
|
6390
6657
|
}
|
|
6391
6658
|
blur() {
|
|
@@ -6394,11 +6661,11 @@ class Renderable extends BaseRenderable {
|
|
|
6394
6661
|
this._focused = false;
|
|
6395
6662
|
this.requestRender();
|
|
6396
6663
|
if (this.keypressHandler) {
|
|
6397
|
-
this.ctx.
|
|
6664
|
+
this.ctx._internalKeyInput.offInternal("keypress", this.keypressHandler);
|
|
6398
6665
|
this.keypressHandler = null;
|
|
6399
6666
|
}
|
|
6400
6667
|
if (this.pasteHandler) {
|
|
6401
|
-
this.ctx.
|
|
6668
|
+
this.ctx._internalKeyInput.offInternal("paste", this.pasteHandler);
|
|
6402
6669
|
this.pasteHandler = null;
|
|
6403
6670
|
}
|
|
6404
6671
|
this.emit("blurred" /* BLURRED */);
|
|
@@ -7547,16 +7814,6 @@ class CapturedWritableStream extends Writable {
|
|
|
7547
7814
|
}
|
|
7548
7815
|
}
|
|
7549
7816
|
|
|
7550
|
-
// src/singleton.ts
|
|
7551
|
-
var singletonCacheSymbol = Symbol.for("@opentui/core/singleton");
|
|
7552
|
-
function singleton(key, factory) {
|
|
7553
|
-
const bag = globalThis[singletonCacheSymbol] ??= {};
|
|
7554
|
-
if (!(key in bag)) {
|
|
7555
|
-
bag[key] = factory();
|
|
7556
|
-
}
|
|
7557
|
-
return bag[key];
|
|
7558
|
-
}
|
|
7559
|
-
|
|
7560
7817
|
// src/console.ts
|
|
7561
7818
|
function getCallerInfo() {
|
|
7562
7819
|
const err = new Error;
|
|
@@ -7577,6 +7834,18 @@ function getCallerInfo() {
|
|
|
7577
7834
|
return { functionName, fullPath, fileName, lineNumber, columnNumber };
|
|
7578
7835
|
}
|
|
7579
7836
|
var capture = singleton("ConsoleCapture", () => new Capture);
|
|
7837
|
+
registerEnvVar({
|
|
7838
|
+
name: "OTUI_USE_CONSOLE",
|
|
7839
|
+
description: "Whether to use the console. Will not capture console output if set to false.",
|
|
7840
|
+
type: "boolean",
|
|
7841
|
+
default: true
|
|
7842
|
+
});
|
|
7843
|
+
registerEnvVar({
|
|
7844
|
+
name: "SHOW_CONSOLE",
|
|
7845
|
+
description: "Show the console at startup if set to true.",
|
|
7846
|
+
type: "boolean",
|
|
7847
|
+
default: false
|
|
7848
|
+
});
|
|
7580
7849
|
|
|
7581
7850
|
class TerminalConsoleCache extends EventEmitter4 {
|
|
7582
7851
|
_cachedLogs = [];
|
|
@@ -7594,7 +7863,7 @@ class TerminalConsoleCache extends EventEmitter4 {
|
|
|
7594
7863
|
this.overrideConsoleMethods();
|
|
7595
7864
|
}
|
|
7596
7865
|
setupConsoleCapture() {
|
|
7597
|
-
if (
|
|
7866
|
+
if (!env.OTUI_USE_CONSOLE)
|
|
7598
7867
|
return;
|
|
7599
7868
|
const mockStdout = new CapturedWritableStream("stdout", capture);
|
|
7600
7869
|
const mockStderr = new CapturedWritableStream("stderr", capture);
|
|
@@ -7759,7 +8028,7 @@ class TerminalConsole extends EventEmitter4 {
|
|
|
7759
8028
|
terminalConsoleCache.on("entry", (logEntry) => {
|
|
7760
8029
|
this._handleNewLog(logEntry);
|
|
7761
8030
|
});
|
|
7762
|
-
if (
|
|
8031
|
+
if (env.SHOW_CONSOLE) {
|
|
7763
8032
|
this.show();
|
|
7764
8033
|
}
|
|
7765
8034
|
}
|
|
@@ -8237,6 +8506,19 @@ function getObjectsInViewport(viewport, objects, direction = "column", padding =
|
|
|
8237
8506
|
}
|
|
8238
8507
|
|
|
8239
8508
|
// src/renderer.ts
|
|
8509
|
+
registerEnvVar({
|
|
8510
|
+
name: "OTUI_DUMP_CAPTURES",
|
|
8511
|
+
description: "Dump captured output when the renderer exits.",
|
|
8512
|
+
type: "boolean",
|
|
8513
|
+
default: false
|
|
8514
|
+
});
|
|
8515
|
+
registerEnvVar({
|
|
8516
|
+
name: "OTUI_NO_NATIVE_RENDER",
|
|
8517
|
+
description: "Disable native rendering. This will not actually output ansi and is useful for debugging.",
|
|
8518
|
+
type: "boolean",
|
|
8519
|
+
default: false
|
|
8520
|
+
});
|
|
8521
|
+
|
|
8240
8522
|
class MouseEvent {
|
|
8241
8523
|
type;
|
|
8242
8524
|
button;
|
|
@@ -8468,8 +8750,8 @@ Captured output:
|
|
|
8468
8750
|
}
|
|
8469
8751
|
exitHandler = (() => {
|
|
8470
8752
|
this.destroy();
|
|
8471
|
-
if (
|
|
8472
|
-
this.dumpOutputCache(`===
|
|
8753
|
+
if (env.OTUI_DUMP_CAPTURES) {
|
|
8754
|
+
this.dumpOutputCache(`=== CAPTURED OUTPUT ===
|
|
8473
8755
|
`);
|
|
8474
8756
|
}
|
|
8475
8757
|
}).bind(this);
|
|
@@ -8520,7 +8802,7 @@ Captured output:
|
|
|
8520
8802
|
process.on("exit", this.exitHandler);
|
|
8521
8803
|
this._console = new TerminalConsole(this, config.consoleOptions);
|
|
8522
8804
|
this.useConsole = config.useConsole ?? true;
|
|
8523
|
-
this._keyHandler = new
|
|
8805
|
+
this._keyHandler = new InternalKeyHandler(this.stdin, config.useKittyKeyboard ?? false);
|
|
8524
8806
|
global.requestAnimationFrame = (callback) => {
|
|
8525
8807
|
const id = CliRenderer.animationFrameId++;
|
|
8526
8808
|
this.animationRequest.set(id, callback);
|
|
@@ -8535,7 +8817,7 @@ Captured output:
|
|
|
8535
8817
|
global.window = {};
|
|
8536
8818
|
}
|
|
8537
8819
|
global.window.requestAnimationFrame = requestAnimationFrame;
|
|
8538
|
-
if (
|
|
8820
|
+
if (env.OTUI_NO_NATIVE_RENDER) {
|
|
8539
8821
|
this.renderNative = () => {
|
|
8540
8822
|
if (this._splitHeight > 0) {
|
|
8541
8823
|
this.flushStdoutCache(this._splitHeight);
|
|
@@ -8608,6 +8890,9 @@ Captured output:
|
|
|
8608
8890
|
get keyInput() {
|
|
8609
8891
|
return this._keyHandler;
|
|
8610
8892
|
}
|
|
8893
|
+
get _internalKeyInput() {
|
|
8894
|
+
return this._keyHandler;
|
|
8895
|
+
}
|
|
8611
8896
|
get terminalWidth() {
|
|
8612
8897
|
return this._terminalWidth;
|
|
8613
8898
|
}
|
|
@@ -9385,7 +9670,7 @@ Captured output:
|
|
|
9385
9670
|
}
|
|
9386
9671
|
}
|
|
9387
9672
|
|
|
9388
|
-
export { __toESM, __commonJS, __export, __require, Edge, Gutter, exports_src, BorderChars, getBorderFromSides, getBorderSides, borderCharsToArray, BorderCharArrays, nonAlphanumericKeys, parseKeypress, ANSI, KeyHandler, RGBA, hexToRgb, rgbToHex, hsvToRgb, parseColor, fonts, measureText, getCharacterPositions, coordinateToCharacterIndex, renderFontToFrameBuffer, TextAttributes, DebugOverlayCorner, createTextAttributes, 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, t, SyntaxStyle, hastToStyledText, parseAlign, parseBoxSizing, parseDimension, parseDirection, parseDisplay, parseEdge, parseFlexDirection, parseGutter, parseJustify, parseLogLevel, parseMeasureMode, parseOverflow, parsePositionType, parseUnit, parseWrap, MouseParser, Selection, convertGlobalToLocalSelection, ASCIIFontSelectionHelper, TextBuffer, LogLevel2 as LogLevel, setRenderLibPath, resolveRenderLib, OptimizedBuffer, h, isVNode, maybeMakeRenderable, wrapWithDelegates, instantiate, delegate, isValidPercentage, LayoutEvents, RenderableEvents, isRenderable, BaseRenderable, Renderable, RootRenderable, capture, ConsolePosition, TerminalConsole, getObjectsInViewport, MouseEvent, MouseButton, createCliRenderer, CliRenderEvents, CliRenderer };
|
|
9673
|
+
export { __toESM, __commonJS, __export, __require, Edge, Gutter, exports_src, BorderChars, getBorderFromSides, getBorderSides, borderCharsToArray, BorderCharArrays, nonAlphanumericKeys, parseKeypress, ANSI, KeyEvent, PasteEvent, KeyHandler, InternalKeyHandler, RGBA, hexToRgb, rgbToHex, hsvToRgb, parseColor, fonts, measureText, getCharacterPositions, coordinateToCharacterIndex, renderFontToFrameBuffer, TextAttributes, DebugOverlayCorner, createTextAttributes, 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, t, SyntaxStyle, hastToStyledText, parseAlign, parseBoxSizing, parseDimension, parseDirection, parseDisplay, parseEdge, parseFlexDirection, parseGutter, parseJustify, parseLogLevel, parseMeasureMode, parseOverflow, parsePositionType, parseUnit, parseWrap, MouseParser, Selection, convertGlobalToLocalSelection, ASCIIFontSelectionHelper, envRegistry, registerEnvVar, generateEnvMarkdown, generateEnvColored, env, TextBuffer, LogLevel2 as LogLevel, setRenderLibPath, resolveRenderLib, OptimizedBuffer, h, isVNode, maybeMakeRenderable, wrapWithDelegates, instantiate, delegate, isValidPercentage, LayoutEvents, RenderableEvents, isRenderable, BaseRenderable, Renderable, RootRenderable, capture, ConsolePosition, TerminalConsole, getObjectsInViewport, MouseEvent, MouseButton, createCliRenderer, CliRenderEvents, CliRenderer };
|
|
9389
9674
|
|
|
9390
|
-
//# debugId=
|
|
9391
|
-
//# sourceMappingURL=index-
|
|
9675
|
+
//# debugId=16DF4272CB23A07264756E2164756E21
|
|
9676
|
+
//# sourceMappingURL=index-bq6h36ne.js.map
|