@alcyone-labs/arg-parser 2.9.0 → 2.10.0
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/README.md +94 -6
- package/dist/core/ArgParserBase.d.ts.map +1 -1
- package/dist/index.cjs +574 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.min.mjs +3830 -3442
- package/dist/index.min.mjs.map +1 -1
- package/dist/index.mjs +574 -2
- package/dist/index.mjs.map +1 -1
- package/dist/ui/App.d.ts +18 -0
- package/dist/ui/App.d.ts.map +1 -0
- package/dist/ui/Component.d.ts +21 -0
- package/dist/ui/Component.d.ts.map +1 -0
- package/dist/ui/Layout.d.ts +19 -0
- package/dist/ui/Layout.d.ts.map +1 -0
- package/dist/ui/Terminal.d.ts +19 -0
- package/dist/ui/Terminal.d.ts.map +1 -0
- package/dist/ui/Theme.d.ts +20 -0
- package/dist/ui/Theme.d.ts.map +1 -0
- package/dist/ui/components/Input.d.ts +21 -0
- package/dist/ui/components/Input.d.ts.map +1 -0
- package/dist/ui/components/List.d.ts +23 -0
- package/dist/ui/components/List.d.ts.map +1 -0
- package/dist/ui/components/ScrollArea.d.ts +16 -0
- package/dist/ui/components/ScrollArea.d.ts.map +1 -0
- package/dist/ui/components/StackNavigator.d.ts +16 -0
- package/dist/ui/components/StackNavigator.d.ts.map +1 -0
- package/dist/ui/index.d.ts +10 -0
- package/dist/ui/index.d.ts.map +1 -0
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1468,7 +1468,7 @@ const zodFlagSchema = z.object({
|
|
|
1468
1468
|
),
|
|
1469
1469
|
enum: z.array(z.any()).optional().describe("Array of allowed values for the flag."),
|
|
1470
1470
|
env: z.union([z.string(), z.array(z.string())]).optional().describe(
|
|
1471
|
-
"Environment
|
|
1471
|
+
"Environment variable(s) to map to this flag. Logic: Fallback (Env -> Flag) and Sync (Flag -> Env). Precedence: Flag > Env > Default."
|
|
1472
1472
|
),
|
|
1473
1473
|
dxtOptions: zodDxtOptionsSchema.optional().describe(
|
|
1474
1474
|
"DXT-specific configuration options for enhanced DXT manifest generation"
|
|
@@ -4013,7 +4013,7 @@ class ArgParserBase {
|
|
|
4013
4013
|
}
|
|
4014
4014
|
async #_handleGlobalChecks(processArgs, options) {
|
|
4015
4015
|
const isRootCliParser = !this.#parentParser && !!this.#appCommandName;
|
|
4016
|
-
if (processArgs.length === 0 && isRootCliParser && !this.#handler) {
|
|
4016
|
+
if (processArgs.length === 0 && isRootCliParser && !this.#handler && !options?.skipHelpHandling) {
|
|
4017
4017
|
console.log(this.helpText());
|
|
4018
4018
|
return this._handleExit(0, "Help displayed", "help");
|
|
4019
4019
|
}
|
|
@@ -4313,6 +4313,54 @@ class ArgParserBase {
|
|
|
4313
4313
|
}
|
|
4314
4314
|
}
|
|
4315
4315
|
}
|
|
4316
|
+
#_applyEnvFallback(finalArgs, finalParser) {
|
|
4317
|
+
for (const flag of finalParser.#flagManager.flags) {
|
|
4318
|
+
const flagName = flag["name"];
|
|
4319
|
+
if (!flag["env"]) continue;
|
|
4320
|
+
if (finalArgs[flagName] !== void 0) {
|
|
4321
|
+
continue;
|
|
4322
|
+
}
|
|
4323
|
+
const envVars = Array.isArray(flag["env"]) ? flag["env"] : [flag["env"]];
|
|
4324
|
+
let foundVal;
|
|
4325
|
+
for (const envKey of envVars) {
|
|
4326
|
+
if (process.env[envKey] !== void 0) {
|
|
4327
|
+
foundVal = process.env[envKey];
|
|
4328
|
+
break;
|
|
4329
|
+
}
|
|
4330
|
+
}
|
|
4331
|
+
if (foundVal !== void 0) {
|
|
4332
|
+
try {
|
|
4333
|
+
const typedVal = this.#configurationManager.convertValueToFlagType(foundVal, flag);
|
|
4334
|
+
if (flag["allowMultiple"]) {
|
|
4335
|
+
finalArgs[flagName] = Array.isArray(typedVal) ? typedVal : [typedVal];
|
|
4336
|
+
} else {
|
|
4337
|
+
finalArgs[flagName] = typedVal;
|
|
4338
|
+
}
|
|
4339
|
+
} catch (e) {
|
|
4340
|
+
console.warn(simpleChalk.yellow(`Warning: Failed to parse env var for flag '${flagName}': ${e}`));
|
|
4341
|
+
}
|
|
4342
|
+
}
|
|
4343
|
+
}
|
|
4344
|
+
}
|
|
4345
|
+
#_syncToEnv(finalArgs, finalParser) {
|
|
4346
|
+
for (const flag of finalParser.#flagManager.flags) {
|
|
4347
|
+
if (!flag["env"]) continue;
|
|
4348
|
+
const flagName = flag["name"];
|
|
4349
|
+
const value = finalArgs[flagName];
|
|
4350
|
+
if (value !== void 0) {
|
|
4351
|
+
const envVars = Array.isArray(flag["env"]) ? flag["env"] : [flag["env"]];
|
|
4352
|
+
let strVal = "";
|
|
4353
|
+
if (typeof value === "object") {
|
|
4354
|
+
strVal = JSON.stringify(value);
|
|
4355
|
+
} else {
|
|
4356
|
+
strVal = String(value);
|
|
4357
|
+
}
|
|
4358
|
+
for (const envKey of envVars) {
|
|
4359
|
+
process.env[envKey] = strVal;
|
|
4360
|
+
}
|
|
4361
|
+
}
|
|
4362
|
+
}
|
|
4363
|
+
}
|
|
4316
4364
|
#_prepareAndExecuteHandler(handlerToExecute, finalArgs, skipHandlers) {
|
|
4317
4365
|
if (skipHandlers || !handlerToExecute) {
|
|
4318
4366
|
return;
|
|
@@ -4524,7 +4572,9 @@ class ArgParserBase {
|
|
|
4524
4572
|
}
|
|
4525
4573
|
const argsForCurrentLevel = subCommandIndex === -1 ? argsToParse : argsToParse.slice(0, subCommandIndex);
|
|
4526
4574
|
const { parsedArgs: currentLevelArgs, firstUnconsumedIndex } = await currentParser.#parseFlags(argsForCurrentLevel, options);
|
|
4575
|
+
this.#_applyEnvFallback(currentLevelArgs, currentParser);
|
|
4527
4576
|
currentParser.#_applyDefaultValues(currentLevelArgs, currentParser);
|
|
4577
|
+
this.#_syncToEnv(currentLevelArgs, currentParser);
|
|
4528
4578
|
const combinedArgsFromThisAndParents = {
|
|
4529
4579
|
...accumulatedParentArgs,
|
|
4530
4580
|
...currentLevelArgs
|
|
@@ -8898,6 +8948,527 @@ class ArgParserFuzzyTester {
|
|
|
8898
8948
|
};
|
|
8899
8949
|
}
|
|
8900
8950
|
}
|
|
8951
|
+
class Terminal {
|
|
8952
|
+
constructor() {
|
|
8953
|
+
}
|
|
8954
|
+
static getInstance() {
|
|
8955
|
+
if (!Terminal.instance) {
|
|
8956
|
+
Terminal.instance = new Terminal();
|
|
8957
|
+
}
|
|
8958
|
+
return Terminal.instance;
|
|
8959
|
+
}
|
|
8960
|
+
get width() {
|
|
8961
|
+
return process.stdout.columns || 80;
|
|
8962
|
+
}
|
|
8963
|
+
get height() {
|
|
8964
|
+
return process.stdout.rows || 24;
|
|
8965
|
+
}
|
|
8966
|
+
write(text) {
|
|
8967
|
+
process.stdout.write(text);
|
|
8968
|
+
}
|
|
8969
|
+
clear() {
|
|
8970
|
+
process.stdout.write("\x1B[2J\x1B[3J\x1B[H");
|
|
8971
|
+
}
|
|
8972
|
+
hideCursor() {
|
|
8973
|
+
process.stdout.write("\x1B[?25l");
|
|
8974
|
+
}
|
|
8975
|
+
showCursor() {
|
|
8976
|
+
process.stdout.write("\x1B[?25h");
|
|
8977
|
+
}
|
|
8978
|
+
moveCursor(x, y) {
|
|
8979
|
+
(void 0)(process.stdout, x, y);
|
|
8980
|
+
}
|
|
8981
|
+
enableRawMode() {
|
|
8982
|
+
if (process.stdin.isTTY) {
|
|
8983
|
+
process.stdin.setRawMode(true);
|
|
8984
|
+
process.stdin.resume();
|
|
8985
|
+
process.stdin.setEncoding("utf8");
|
|
8986
|
+
}
|
|
8987
|
+
}
|
|
8988
|
+
enableMouse() {
|
|
8989
|
+
process.stdout.write("\x1B[?1000h\x1B[?1002h\x1B[?1006h");
|
|
8990
|
+
}
|
|
8991
|
+
disableMouse() {
|
|
8992
|
+
process.stdout.write("\x1B[?1000l\x1B[?1002l\x1B[?1006l");
|
|
8993
|
+
}
|
|
8994
|
+
disableRawMode() {
|
|
8995
|
+
if (process.stdin.isTTY) {
|
|
8996
|
+
process.stdin.setRawMode(false);
|
|
8997
|
+
process.stdin.pause();
|
|
8998
|
+
}
|
|
8999
|
+
}
|
|
9000
|
+
onKey(callback) {
|
|
9001
|
+
process.stdin.on("data", (data2) => {
|
|
9002
|
+
const char2 = data2.toString();
|
|
9003
|
+
if (char2 === "") {
|
|
9004
|
+
this.cleanup();
|
|
9005
|
+
process.exit(0);
|
|
9006
|
+
}
|
|
9007
|
+
callback(char2, false);
|
|
9008
|
+
});
|
|
9009
|
+
}
|
|
9010
|
+
cleanup() {
|
|
9011
|
+
this.showCursor();
|
|
9012
|
+
this.disableMouse();
|
|
9013
|
+
this.disableRawMode();
|
|
9014
|
+
}
|
|
9015
|
+
}
|
|
9016
|
+
class Component {
|
|
9017
|
+
constructor(config = {}) {
|
|
9018
|
+
this.x = 0;
|
|
9019
|
+
this.y = 0;
|
|
9020
|
+
this.width = 0;
|
|
9021
|
+
this.height = 0;
|
|
9022
|
+
this.config = config;
|
|
9023
|
+
this.id = config.id || `component_${Math.random().toString(36).substr(2, 9)}`;
|
|
9024
|
+
}
|
|
9025
|
+
resize(x, y, width, height) {
|
|
9026
|
+
this.x = x;
|
|
9027
|
+
this.y = y;
|
|
9028
|
+
this.width = width;
|
|
9029
|
+
this.height = height;
|
|
9030
|
+
}
|
|
9031
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
9032
|
+
handleInput(_key) {
|
|
9033
|
+
}
|
|
9034
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
9035
|
+
handleMouse(_event) {
|
|
9036
|
+
}
|
|
9037
|
+
}
|
|
9038
|
+
class SplitLayout extends Component {
|
|
9039
|
+
constructor(config) {
|
|
9040
|
+
super(config);
|
|
9041
|
+
this.direction = config.direction;
|
|
9042
|
+
this.first = config.first;
|
|
9043
|
+
this.second = config.second;
|
|
9044
|
+
this.splitRatio = config.splitRatio ?? 0.5;
|
|
9045
|
+
}
|
|
9046
|
+
resize(x, y, width, height) {
|
|
9047
|
+
super.resize(x, y, width, height);
|
|
9048
|
+
if (this.direction === "horizontal") {
|
|
9049
|
+
const splitX = Math.floor(width * this.splitRatio);
|
|
9050
|
+
this.first.resize(x, y, splitX, height);
|
|
9051
|
+
this.second.resize(x + splitX, y, width - splitX, height);
|
|
9052
|
+
} else {
|
|
9053
|
+
const splitY = Math.floor(height * this.splitRatio);
|
|
9054
|
+
this.first.resize(x, y, width, splitY);
|
|
9055
|
+
this.second.resize(x, y + splitY, width, height - splitY);
|
|
9056
|
+
}
|
|
9057
|
+
}
|
|
9058
|
+
render() {
|
|
9059
|
+
const lines = [];
|
|
9060
|
+
const firstLines = this.first.render();
|
|
9061
|
+
const secondLines = this.second.render();
|
|
9062
|
+
if (this.direction === "horizontal") {
|
|
9063
|
+
const maxHeight = Math.max(firstLines.length, secondLines.length);
|
|
9064
|
+
for (let i = 0; i < maxHeight; i++) {
|
|
9065
|
+
const line1 = firstLines[i] || " ".repeat(this.first["width"]);
|
|
9066
|
+
const line2 = secondLines[i] || " ".repeat(this.second["width"]);
|
|
9067
|
+
lines.push(line1 + line2);
|
|
9068
|
+
}
|
|
9069
|
+
} else {
|
|
9070
|
+
lines.push(...firstLines);
|
|
9071
|
+
lines.push(...secondLines);
|
|
9072
|
+
}
|
|
9073
|
+
return lines;
|
|
9074
|
+
}
|
|
9075
|
+
handleInput(key) {
|
|
9076
|
+
this.first.handleInput(key);
|
|
9077
|
+
this.second.handleInput(key);
|
|
9078
|
+
}
|
|
9079
|
+
handleMouse(event) {
|
|
9080
|
+
this.first.handleMouse(event);
|
|
9081
|
+
this.second.handleMouse(event);
|
|
9082
|
+
}
|
|
9083
|
+
}
|
|
9084
|
+
class App {
|
|
9085
|
+
constructor() {
|
|
9086
|
+
this.isRunning = false;
|
|
9087
|
+
this.lastRenderedLines = [];
|
|
9088
|
+
this.terminal = Terminal.getInstance();
|
|
9089
|
+
}
|
|
9090
|
+
run(root) {
|
|
9091
|
+
this.root = root;
|
|
9092
|
+
this.isRunning = true;
|
|
9093
|
+
this.terminal.enableRawMode();
|
|
9094
|
+
this.terminal.enableMouse();
|
|
9095
|
+
this.terminal.hideCursor();
|
|
9096
|
+
this.terminal.clear();
|
|
9097
|
+
this.render();
|
|
9098
|
+
const cleanup = () => this.terminal.cleanup();
|
|
9099
|
+
process.on("exit", cleanup);
|
|
9100
|
+
process.on("SIGINT", () => {
|
|
9101
|
+
cleanup();
|
|
9102
|
+
process.exit(0);
|
|
9103
|
+
});
|
|
9104
|
+
process.on("uncaughtException", (err) => {
|
|
9105
|
+
cleanup();
|
|
9106
|
+
console.error(err);
|
|
9107
|
+
process.exit(1);
|
|
9108
|
+
});
|
|
9109
|
+
this.terminal.onKey((key) => {
|
|
9110
|
+
if (key.startsWith("\x1B[<")) {
|
|
9111
|
+
const parts = key.substring(3).split(";");
|
|
9112
|
+
if (parts.length === 3) {
|
|
9113
|
+
let buttonCode = parseInt(parts[0]);
|
|
9114
|
+
const x = parseInt(parts[1]) - 1;
|
|
9115
|
+
const lastPart = parts[2];
|
|
9116
|
+
const y = parseInt(lastPart.substring(0, lastPart.length - 1)) - 1;
|
|
9117
|
+
const type2 = lastPart.charAt(lastPart.length - 1);
|
|
9118
|
+
let action = "press";
|
|
9119
|
+
let button = 0;
|
|
9120
|
+
if (type2 === "m") {
|
|
9121
|
+
action = "release";
|
|
9122
|
+
} else {
|
|
9123
|
+
if (buttonCode >= 64) {
|
|
9124
|
+
action = buttonCode === 64 ? "scroll_up" : "scroll_down";
|
|
9125
|
+
buttonCode -= 64;
|
|
9126
|
+
} else {
|
|
9127
|
+
if (buttonCode === 0) button = 0;
|
|
9128
|
+
else if (buttonCode === 1) button = 1;
|
|
9129
|
+
else if (buttonCode === 2) button = 2;
|
|
9130
|
+
if ((buttonCode & 32) === 32) {
|
|
9131
|
+
action = "drag";
|
|
9132
|
+
buttonCode -= 32;
|
|
9133
|
+
if (buttonCode === 0) button = 0;
|
|
9134
|
+
}
|
|
9135
|
+
}
|
|
9136
|
+
}
|
|
9137
|
+
const event = { x, y, button, action };
|
|
9138
|
+
if (this.root) {
|
|
9139
|
+
this.root.handleMouse(event);
|
|
9140
|
+
this.render();
|
|
9141
|
+
}
|
|
9142
|
+
return;
|
|
9143
|
+
}
|
|
9144
|
+
}
|
|
9145
|
+
if (key === "\x1B" || key === "") {
|
|
9146
|
+
this.stop();
|
|
9147
|
+
return;
|
|
9148
|
+
}
|
|
9149
|
+
if (this.root) {
|
|
9150
|
+
this.root.handleInput(key);
|
|
9151
|
+
this.render();
|
|
9152
|
+
}
|
|
9153
|
+
});
|
|
9154
|
+
process.stdout.on("resize", () => {
|
|
9155
|
+
this.render();
|
|
9156
|
+
});
|
|
9157
|
+
}
|
|
9158
|
+
stop() {
|
|
9159
|
+
this.isRunning = false;
|
|
9160
|
+
this.terminal.cleanup();
|
|
9161
|
+
process.exit(0);
|
|
9162
|
+
}
|
|
9163
|
+
render() {
|
|
9164
|
+
if (!this.root || !this.isRunning) return;
|
|
9165
|
+
const width = this.terminal.width;
|
|
9166
|
+
const height = this.terminal.height;
|
|
9167
|
+
this.root.resize(0, 0, width, height);
|
|
9168
|
+
const lines = this.root.render();
|
|
9169
|
+
const maxLines = Math.min(lines.length, height - 1);
|
|
9170
|
+
this.terminal.write("\x1B[H");
|
|
9171
|
+
for (let i = 0; i < maxLines; i++) {
|
|
9172
|
+
const line = lines[i];
|
|
9173
|
+
const lastLine = this.lastRenderedLines[i];
|
|
9174
|
+
if (line !== lastLine) {
|
|
9175
|
+
this.terminal.moveCursor(0, i);
|
|
9176
|
+
this.terminal.write(line);
|
|
9177
|
+
this.terminal.write("\x1B[K");
|
|
9178
|
+
}
|
|
9179
|
+
}
|
|
9180
|
+
this.lastRenderedLines = [...lines];
|
|
9181
|
+
}
|
|
9182
|
+
}
|
|
9183
|
+
const Themes = {
|
|
9184
|
+
Default: {
|
|
9185
|
+
// Dark Mode
|
|
9186
|
+
base: simpleChalk.white,
|
|
9187
|
+
muted: simpleChalk.gray,
|
|
9188
|
+
accent: simpleChalk.cyan,
|
|
9189
|
+
highlight: simpleChalk.cyan,
|
|
9190
|
+
// Was bgBlue.white
|
|
9191
|
+
success: simpleChalk.green,
|
|
9192
|
+
warning: simpleChalk.yellow,
|
|
9193
|
+
error: simpleChalk.red,
|
|
9194
|
+
border: simpleChalk.gray,
|
|
9195
|
+
scrollbarThumb: simpleChalk.white,
|
|
9196
|
+
scrollbarTrack: simpleChalk.gray
|
|
9197
|
+
},
|
|
9198
|
+
Light: {
|
|
9199
|
+
// "Ocean" theme (High contrast on dark)
|
|
9200
|
+
base: simpleChalk.white,
|
|
9201
|
+
muted: simpleChalk.gray,
|
|
9202
|
+
accent: simpleChalk.cyan,
|
|
9203
|
+
highlight: simpleChalk.cyan,
|
|
9204
|
+
// Fallback since bgCyan not supported
|
|
9205
|
+
success: simpleChalk.green,
|
|
9206
|
+
warning: simpleChalk.yellow,
|
|
9207
|
+
error: simpleChalk.red,
|
|
9208
|
+
border: simpleChalk.cyan,
|
|
9209
|
+
scrollbarThumb: simpleChalk.cyan,
|
|
9210
|
+
scrollbarTrack: simpleChalk.gray
|
|
9211
|
+
},
|
|
9212
|
+
Monokai: {
|
|
9213
|
+
base: simpleChalk.white,
|
|
9214
|
+
muted: simpleChalk.gray,
|
|
9215
|
+
accent: simpleChalk.magenta,
|
|
9216
|
+
highlight: simpleChalk.magenta,
|
|
9217
|
+
// Was bgMagenta.white
|
|
9218
|
+
success: simpleChalk.green,
|
|
9219
|
+
warning: simpleChalk.yellow,
|
|
9220
|
+
error: simpleChalk.red,
|
|
9221
|
+
border: simpleChalk.gray,
|
|
9222
|
+
scrollbarThumb: simpleChalk.magenta,
|
|
9223
|
+
scrollbarTrack: simpleChalk.gray
|
|
9224
|
+
}
|
|
9225
|
+
};
|
|
9226
|
+
const _ThemeManager = class _ThemeManager {
|
|
9227
|
+
static get current() {
|
|
9228
|
+
return this._current;
|
|
9229
|
+
}
|
|
9230
|
+
static setTheme(name) {
|
|
9231
|
+
if (Themes[name]) {
|
|
9232
|
+
this._current = Themes[name];
|
|
9233
|
+
}
|
|
9234
|
+
}
|
|
9235
|
+
static setCustomTheme(theme) {
|
|
9236
|
+
this._current = theme;
|
|
9237
|
+
}
|
|
9238
|
+
};
|
|
9239
|
+
_ThemeManager._current = Themes["Default"];
|
|
9240
|
+
let ThemeManager = _ThemeManager;
|
|
9241
|
+
class List extends Component {
|
|
9242
|
+
constructor(config) {
|
|
9243
|
+
super(config);
|
|
9244
|
+
this.selectedIndex = 0;
|
|
9245
|
+
this.scrollOffset = 0;
|
|
9246
|
+
this.items = config.items;
|
|
9247
|
+
this.onSelect = config.onSelect;
|
|
9248
|
+
this.onSubmit = config.onSubmit;
|
|
9249
|
+
}
|
|
9250
|
+
setItems(items2) {
|
|
9251
|
+
this.items = items2;
|
|
9252
|
+
if (this.selectedIndex >= this.items.length) {
|
|
9253
|
+
this.selectedIndex = Math.max(0, this.items.length - 1);
|
|
9254
|
+
}
|
|
9255
|
+
}
|
|
9256
|
+
render() {
|
|
9257
|
+
const lines = [];
|
|
9258
|
+
const visibleCount = this.height;
|
|
9259
|
+
if (this.selectedIndex < this.scrollOffset) {
|
|
9260
|
+
this.scrollOffset = this.selectedIndex;
|
|
9261
|
+
} else if (this.selectedIndex >= this.scrollOffset + visibleCount) {
|
|
9262
|
+
this.scrollOffset = this.selectedIndex - visibleCount + 1;
|
|
9263
|
+
}
|
|
9264
|
+
const visibleItems = this.items.slice(this.scrollOffset, this.scrollOffset + visibleCount);
|
|
9265
|
+
for (let i = 0; i < this.height; i++) {
|
|
9266
|
+
const itemIndex = this.scrollOffset + i;
|
|
9267
|
+
const item = visibleItems[i];
|
|
9268
|
+
if (!item) {
|
|
9269
|
+
lines.push(" ".repeat(this.width));
|
|
9270
|
+
continue;
|
|
9271
|
+
}
|
|
9272
|
+
const isSelected = itemIndex === this.selectedIndex;
|
|
9273
|
+
const theme = ThemeManager.current;
|
|
9274
|
+
let line = "";
|
|
9275
|
+
if (isSelected) {
|
|
9276
|
+
line = theme.highlight("> " + item.label);
|
|
9277
|
+
} else {
|
|
9278
|
+
line = theme.base(" " + item.label);
|
|
9279
|
+
}
|
|
9280
|
+
const rawLabelLength = item.label.length + 2;
|
|
9281
|
+
const padding = Math.max(0, this.width - rawLabelLength);
|
|
9282
|
+
if (isSelected) {
|
|
9283
|
+
line = theme.highlight("> " + item.label + " ".repeat(padding));
|
|
9284
|
+
} else {
|
|
9285
|
+
line = theme.base(" " + item.label + " ".repeat(padding));
|
|
9286
|
+
}
|
|
9287
|
+
lines.push(line);
|
|
9288
|
+
}
|
|
9289
|
+
return lines;
|
|
9290
|
+
}
|
|
9291
|
+
handleInput(key) {
|
|
9292
|
+
if (this.items.length === 0) return;
|
|
9293
|
+
if (key === "\x1B[A") {
|
|
9294
|
+
this.selectedIndex = Math.max(0, this.selectedIndex - 1);
|
|
9295
|
+
if (this.onSelect) this.onSelect(this.items[this.selectedIndex]);
|
|
9296
|
+
} else if (key === "\x1B[B") {
|
|
9297
|
+
this.selectedIndex = Math.min(this.items.length - 1, this.selectedIndex + 1);
|
|
9298
|
+
if (this.onSelect) this.onSelect(this.items[this.selectedIndex]);
|
|
9299
|
+
} else if (key === "\r" || key === "\x1B[C") {
|
|
9300
|
+
if (this.onSubmit) this.onSubmit(this.items[this.selectedIndex]);
|
|
9301
|
+
}
|
|
9302
|
+
}
|
|
9303
|
+
}
|
|
9304
|
+
class ScrollArea extends Component {
|
|
9305
|
+
constructor(config) {
|
|
9306
|
+
super(config);
|
|
9307
|
+
this.contentLines = [];
|
|
9308
|
+
this.scrollOffset = 0;
|
|
9309
|
+
this.content = config.content;
|
|
9310
|
+
this.updateContentLines();
|
|
9311
|
+
}
|
|
9312
|
+
setContent(content) {
|
|
9313
|
+
this.content = typeof content === "string" ? content : String(content || "");
|
|
9314
|
+
this.scrollOffset = 0;
|
|
9315
|
+
this.updateContentLines();
|
|
9316
|
+
}
|
|
9317
|
+
updateContentLines() {
|
|
9318
|
+
this.contentLines = this.content.split("\n");
|
|
9319
|
+
}
|
|
9320
|
+
render() {
|
|
9321
|
+
const lines = [];
|
|
9322
|
+
const visibleLines = this.contentLines.slice(this.scrollOffset, this.scrollOffset + this.height);
|
|
9323
|
+
const showScrollbar = this.contentLines.length > this.height;
|
|
9324
|
+
let scrollbarHeight = 0;
|
|
9325
|
+
let scrollbarTop = 0;
|
|
9326
|
+
if (showScrollbar) {
|
|
9327
|
+
const ratio = this.height / this.contentLines.length;
|
|
9328
|
+
scrollbarHeight = Math.max(1, Math.floor(this.height * ratio));
|
|
9329
|
+
const scrollPercent = this.scrollOffset / (this.contentLines.length - this.height);
|
|
9330
|
+
const maxTop = this.height - scrollbarHeight;
|
|
9331
|
+
scrollbarTop = Math.floor(scrollPercent * maxTop);
|
|
9332
|
+
}
|
|
9333
|
+
const stripAnsi = (str) => str.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, "");
|
|
9334
|
+
for (let i = 0; i < this.height; i++) {
|
|
9335
|
+
const lineContent = visibleLines[i] || "";
|
|
9336
|
+
let prefix = "";
|
|
9337
|
+
if (showScrollbar) {
|
|
9338
|
+
const isThumb = i >= scrollbarTop && i < scrollbarTop + scrollbarHeight;
|
|
9339
|
+
const theme = ThemeManager.current;
|
|
9340
|
+
prefix = isThumb ? theme.scrollbarThumb("█") : theme.scrollbarTrack("│");
|
|
9341
|
+
prefix += " ";
|
|
9342
|
+
}
|
|
9343
|
+
const visibleWidth = showScrollbar ? this.width - 2 : this.width;
|
|
9344
|
+
const visibleLength = stripAnsi(lineContent).length;
|
|
9345
|
+
const rawLength = lineContent.length;
|
|
9346
|
+
const invisibleLength = rawLength - visibleLength;
|
|
9347
|
+
let renderedContent = "";
|
|
9348
|
+
if (visibleLength > visibleWidth) {
|
|
9349
|
+
renderedContent = lineContent.substring(0, visibleWidth + invisibleLength);
|
|
9350
|
+
} else {
|
|
9351
|
+
const padding = Math.max(0, visibleWidth - visibleLength);
|
|
9352
|
+
renderedContent = lineContent + " ".repeat(padding);
|
|
9353
|
+
}
|
|
9354
|
+
lines.push(prefix + renderedContent);
|
|
9355
|
+
}
|
|
9356
|
+
return lines;
|
|
9357
|
+
}
|
|
9358
|
+
handleMouse(event) {
|
|
9359
|
+
if (event.x >= this.x && event.x < this.x + this.width && event.y >= this.y && event.y < this.y + this.height) {
|
|
9360
|
+
if (event.action === "scroll_up") {
|
|
9361
|
+
this.scrollOffset = Math.max(0, this.scrollOffset - 3);
|
|
9362
|
+
} else if (event.action === "scroll_down") {
|
|
9363
|
+
const maxScroll = Math.max(0, this.contentLines.length - this.height);
|
|
9364
|
+
this.scrollOffset = Math.min(maxScroll, this.scrollOffset + 3);
|
|
9365
|
+
}
|
|
9366
|
+
}
|
|
9367
|
+
}
|
|
9368
|
+
handleInput(key) {
|
|
9369
|
+
if (key === "\x1B[A") {
|
|
9370
|
+
this.scrollOffset = Math.max(0, this.scrollOffset - 1);
|
|
9371
|
+
} else if (key === "\x1B[B") {
|
|
9372
|
+
const maxScroll = Math.max(0, this.contentLines.length - this.height);
|
|
9373
|
+
this.scrollOffset = Math.min(maxScroll, this.scrollOffset + 1);
|
|
9374
|
+
} else if (key === "\x1B[5~") {
|
|
9375
|
+
this.scrollOffset = Math.max(0, this.scrollOffset - this.height);
|
|
9376
|
+
} else if (key === "\x1B[6~") {
|
|
9377
|
+
const maxScroll = Math.max(0, this.contentLines.length - this.height);
|
|
9378
|
+
this.scrollOffset = Math.min(maxScroll, this.scrollOffset + this.height);
|
|
9379
|
+
}
|
|
9380
|
+
}
|
|
9381
|
+
}
|
|
9382
|
+
class Input extends Component {
|
|
9383
|
+
constructor(config) {
|
|
9384
|
+
super(config);
|
|
9385
|
+
this.prefix = config.prefix || "";
|
|
9386
|
+
this.placeholder = config.placeholder || "";
|
|
9387
|
+
this.value = config.value || "";
|
|
9388
|
+
this.onChange = config.onChange;
|
|
9389
|
+
this.onSubmit = config.onSubmit;
|
|
9390
|
+
}
|
|
9391
|
+
setValue(value) {
|
|
9392
|
+
this.value = value;
|
|
9393
|
+
if (this.onChange) this.onChange(this.value);
|
|
9394
|
+
}
|
|
9395
|
+
getValue() {
|
|
9396
|
+
return this.value;
|
|
9397
|
+
}
|
|
9398
|
+
render() {
|
|
9399
|
+
const lines = [];
|
|
9400
|
+
const theme = ThemeManager.current;
|
|
9401
|
+
let text = this.prefix + (this.value || theme.muted(this.placeholder));
|
|
9402
|
+
if (text.length > this.width) {
|
|
9403
|
+
text = text.substring(0, this.width - 1) + "…";
|
|
9404
|
+
}
|
|
9405
|
+
lines.push((text + " ".repeat(Math.max(0, this.width - text.length))).substring(0, this.width));
|
|
9406
|
+
return lines;
|
|
9407
|
+
}
|
|
9408
|
+
handleInput(key) {
|
|
9409
|
+
if (key === "\r") {
|
|
9410
|
+
if (this.onSubmit) this.onSubmit(this.value);
|
|
9411
|
+
} else if (key === "" || key === "\b") {
|
|
9412
|
+
if (this.value.length > 0) {
|
|
9413
|
+
this.value = this.value.substring(0, this.value.length - 1);
|
|
9414
|
+
if (this.onChange) this.onChange(this.value);
|
|
9415
|
+
}
|
|
9416
|
+
} else if (key.length === 1 && key >= " " && key <= "~") {
|
|
9417
|
+
this.value += key;
|
|
9418
|
+
if (this.onChange) this.onChange(this.value);
|
|
9419
|
+
}
|
|
9420
|
+
}
|
|
9421
|
+
}
|
|
9422
|
+
class StackNavigator extends Component {
|
|
9423
|
+
constructor(config) {
|
|
9424
|
+
super(config);
|
|
9425
|
+
this.stack = [];
|
|
9426
|
+
this.stack.push(config.initialComponent);
|
|
9427
|
+
}
|
|
9428
|
+
push(component) {
|
|
9429
|
+
this.stack.push(component);
|
|
9430
|
+
component.resize(this.x, this.y, this.width, this.height);
|
|
9431
|
+
}
|
|
9432
|
+
pop() {
|
|
9433
|
+
if (this.stack.length > 1) {
|
|
9434
|
+
this.stack.pop();
|
|
9435
|
+
}
|
|
9436
|
+
}
|
|
9437
|
+
get currentComponent() {
|
|
9438
|
+
return this.stack[this.stack.length - 1];
|
|
9439
|
+
}
|
|
9440
|
+
resize(x, y, width, height) {
|
|
9441
|
+
super.resize(x, y, width, height);
|
|
9442
|
+
this.currentComponent.resize(x, y, width, height);
|
|
9443
|
+
}
|
|
9444
|
+
render() {
|
|
9445
|
+
return this.currentComponent.render();
|
|
9446
|
+
}
|
|
9447
|
+
handleInput(key) {
|
|
9448
|
+
if ((key === "\x1B" || key === "\x1B[D") && this.stack.length > 1) {
|
|
9449
|
+
this.pop();
|
|
9450
|
+
this.currentComponent.resize(this.x, this.y, this.width, this.height);
|
|
9451
|
+
return;
|
|
9452
|
+
}
|
|
9453
|
+
this.currentComponent.handleInput(key);
|
|
9454
|
+
}
|
|
9455
|
+
handleMouse(event) {
|
|
9456
|
+
this.currentComponent.handleMouse(event);
|
|
9457
|
+
}
|
|
9458
|
+
}
|
|
9459
|
+
const index$2 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
9460
|
+
__proto__: null,
|
|
9461
|
+
App,
|
|
9462
|
+
Component,
|
|
9463
|
+
Input,
|
|
9464
|
+
List,
|
|
9465
|
+
ScrollArea,
|
|
9466
|
+
SplitLayout,
|
|
9467
|
+
StackNavigator,
|
|
9468
|
+
Terminal,
|
|
9469
|
+
ThemeManager,
|
|
9470
|
+
Themes
|
|
9471
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
8901
9472
|
const LATEST_PROTOCOL_VERSION = "2025-06-18";
|
|
8902
9473
|
const DEFAULT_NEGOTIATED_PROTOCOL_VERSION = "2025-03-26";
|
|
8903
9474
|
const SUPPORTED_PROTOCOL_VERSIONS = [
|
|
@@ -25593,6 +26164,7 @@ export {
|
|
|
25593
26164
|
OutputSchemaPatterns,
|
|
25594
26165
|
simpleChalk as SimpleChalk,
|
|
25595
26166
|
TomlConfigPlugin,
|
|
26167
|
+
index$2 as UI,
|
|
25596
26168
|
YamlConfigPlugin,
|
|
25597
26169
|
absolutePath,
|
|
25598
26170
|
convertFlagToJsonSchemaProperty,
|