convoker 0.4.0 → 0.4.1

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.
Files changed (40) hide show
  1. package/dist/color/index.d.mts +2 -2
  2. package/dist/color/index.mjs +2 -2
  3. package/dist/{color-DiZvJ0Fc.mjs → color-s-N9yh90.mjs} +2 -65
  4. package/dist/color-s-N9yh90.mjs.map +1 -0
  5. package/dist/command/index.d.mts +4 -4
  6. package/dist/command/index.mjs +7 -6
  7. package/dist/{command-8P8qXJ2o.mjs → command-C9QIG--8.mjs} +145 -9
  8. package/dist/command-C9QIG--8.mjs.map +1 -0
  9. package/dist/{index-BYLskLxk.d.mts → index-C0cH9MIP.d.mts} +4 -4
  10. package/dist/{index-ClhbwSD8.d.mts → index-C6iJZTo3.d.mts} +2 -2
  11. package/dist/index-CCQ6jz54.d.mts +58 -0
  12. package/dist/{index-Cnx4H4D-.d.mts → index-OUlP1L9o.d.mts} +3 -3
  13. package/dist/index.d.mts +62 -7
  14. package/dist/index.mjs +8 -91
  15. package/dist/input/index.d.mts +2 -2
  16. package/dist/input/index.mjs +2 -2
  17. package/dist/{input-XUsy1LCQ.mjs → input-li13L1uf.mjs} +2 -2
  18. package/dist/{input-XUsy1LCQ.mjs.map → input-li13L1uf.mjs.map} +1 -1
  19. package/dist/prompt/index.d.mts +4 -4
  20. package/dist/prompt/index.mjs +5 -4
  21. package/dist/prompt/raw.d.mts +1 -1
  22. package/dist/prompt/raw.mjs +1 -1
  23. package/dist/{prompt-a5Ix_Hyc.mjs → prompt-OXGrAkDf.mjs} +4 -4
  24. package/dist/{prompt-a5Ix_Hyc.mjs.map → prompt-OXGrAkDf.mjs.map} +1 -1
  25. package/dist/{raw-cqTp2vds.d.mts → raw-BqvlveTU.d.mts} +1 -1
  26. package/dist/{raw-DEtZFeMv.mjs → raw-DVT5lw11.mjs} +1 -1
  27. package/dist/{raw-DEtZFeMv.mjs.map → raw-DVT5lw11.mjs.map} +1 -1
  28. package/dist/{standard-schema-DXS-QnwX.d.mts → standard-schema-D1sStgzy.d.mts} +1 -1
  29. package/dist/{standard-schema-DTuaYJjO.mjs → standard-schema-WhGEzW0C.mjs} +1 -1
  30. package/dist/{standard-schema-DTuaYJjO.mjs.map → standard-schema-WhGEzW0C.mjs.map} +1 -1
  31. package/dist/theme-Chg3mOhZ.mjs +68 -0
  32. package/dist/theme-Chg3mOhZ.mjs.map +1 -0
  33. package/dist/theme-EERPMtQU.d.mts +115 -0
  34. package/dist/theme.d.mts +2 -0
  35. package/dist/theme.mjs +4 -0
  36. package/package.json +5 -1
  37. package/dist/color-DiZvJ0Fc.mjs.map +0 -1
  38. package/dist/command-8P8qXJ2o.mjs.map +0 -1
  39. package/dist/index-BtbthYjp.d.mts +0 -168
  40. package/dist/index.mjs.map +0 -1
package/dist/index.mjs CHANGED
@@ -1,92 +1,9 @@
1
- import { t as __export } from "./chunk-z5eko27R.mjs";
2
- import { S as color_exports, q as merge, t as DEFAULT_THEME } from "./color-DiZvJ0Fc.mjs";
3
- import "./standard-schema-DTuaYJjO.mjs";
4
- import "./raw-DEtZFeMv.mjs";
5
- import { a as prompt_exports } from "./prompt-a5Ix_Hyc.mjs";
6
- import { a as MissingRequiredOptionError, i as MissingRequiredArgumentError, n as ConvokerError, o as TooManyArgumentsError, r as HelpAskedError, s as UnknownOptionError, t as Command } from "./command-8P8qXJ2o.mjs";
7
- import { a as input_exports } from "./input-XUsy1LCQ.mjs";
8
- import process from "node:process";
1
+ import { x as color_exports } from "./color-s-N9yh90.mjs";
2
+ import { n as defineTheme, t as DEFAULT_THEME } from "./theme-Chg3mOhZ.mjs";
3
+ import "./standard-schema-WhGEzW0C.mjs";
4
+ import "./raw-DVT5lw11.mjs";
5
+ import { a as prompt_exports } from "./prompt-OXGrAkDf.mjs";
6
+ import { a as MissingRequiredOptionError, c as log_exports, i as MissingRequiredArgumentError, n as ConvokerError, o as TooManyArgumentsError, r as HelpAskedError, s as UnknownOptionError, t as Command } from "./command-C9QIG--8.mjs";
7
+ import { a as input_exports } from "./input-li13L1uf.mjs";
9
8
 
10
- //#region src/log/error.ts
11
- var WriteError = class extends Error {
12
- constructor(streamName) {
13
- super(`Could not write to \`${streamName}\`.`);
14
- }
15
- };
16
-
17
- //#endregion
18
- //#region src/log/index.ts
19
- var log_exports = /* @__PURE__ */ __export({
20
- DEFAULT_CONFIG: () => DEFAULT_CONFIG,
21
- WriteError: () => WriteError,
22
- error: () => error,
23
- fatal: () => fatal,
24
- info: () => info,
25
- setConfig: () => setConfig,
26
- setTheme: () => setTheme,
27
- trace: () => trace,
28
- warn: () => warn
29
- });
30
- let th = DEFAULT_THEME;
31
- function setTheme(theme) {
32
- th = theme;
33
- }
34
- const DEFAULT_CONFIG = {
35
- format: "text",
36
- stderr: process.stderr,
37
- stdout: process.stdout,
38
- jsonSpace: 2
39
- };
40
- let config = DEFAULT_CONFIG;
41
- function setConfig({ theme,...cfg }) {
42
- config = merge(DEFAULT_CONFIG, cfg);
43
- th = theme ?? th;
44
- }
45
- function trace(...msgs) {
46
- const str = format(msgs, "TRACE");
47
- if (!config.stdout.write(str)) throw new WriteError("stdout");
48
- }
49
- function info(...msgs) {
50
- const str = format(msgs, "INFO");
51
- if (!config.stdout.write(str)) throw new WriteError("stdout");
52
- }
53
- function warn(...msgs) {
54
- const str = format(msgs, "WARN");
55
- if (!config.stderr.write(th.warning(str))) throw new WriteError("stderr");
56
- }
57
- function error(...msgs) {
58
- const str = format(msgs, "ERROR");
59
- if (!config.stderr.write(str)) throw new WriteError("stderr");
60
- }
61
- function fatal(...msgs) {
62
- const str = format(msgs, "FATAL");
63
- if (!config.stderr.write(str)) throw new WriteError("stderr");
64
- process.exit(-1);
65
- }
66
- function format(msgs, level) {
67
- const timestamp = (/* @__PURE__ */ new Date()).toISOString();
68
- const msg = msgs.map((m) => typeof m === "string" ? m : JSON.stringify(m, null, config.jsonSpace)).join(" ");
69
- switch (config.format) {
70
- case "json": return colorize(JSON.stringify({
71
- timestamp,
72
- level,
73
- message: msg
74
- }) + "\n", level);
75
- case "text":
76
- default: return colorize(`[${timestamp}] [${th.symbols[level] ?? level}] ${msg}\n`, level);
77
- }
78
- }
79
- function colorize(str, level) {
80
- switch (level) {
81
- case "TRACE": return th.secondary(str);
82
- case "WARN": return th.warning(str);
83
- case "ERROR": return th.error(str);
84
- case "FATAL": return th.styles?.bold ? th.styles.bold(th.error(str)) : th.error(str);
85
- case "INFO":
86
- default: return th.info?.(str) ?? str;
87
- }
88
- }
89
-
90
- //#endregion
91
- export { Command, ConvokerError, HelpAskedError, MissingRequiredArgumentError, MissingRequiredOptionError, TooManyArgumentsError, UnknownOptionError, color_exports as color, input_exports as i, log_exports as log, prompt_exports as prompt };
92
- //# sourceMappingURL=index.mjs.map
9
+ export { Command, ConvokerError, DEFAULT_THEME, HelpAskedError, MissingRequiredArgumentError, MissingRequiredOptionError, TooManyArgumentsError, UnknownOptionError, color_exports as color, defineTheme, input_exports as i, log_exports as log, prompt_exports as prompt };
@@ -1,3 +1,3 @@
1
- import "../standard-schema-DXS-QnwX.mjs";
2
- import { a as Kind, c as TypeOf, f as option, i as Input, l as argument, m as InputValidationError, n as InferEntry, o as Option, p as positional, r as InferInput, s as Positional, t as BasicKind, u as convert } from "../index-ClhbwSD8.mjs";
1
+ import "../standard-schema-D1sStgzy.mjs";
2
+ import { a as Kind, c as TypeOf, f as option, i as Input, l as argument, m as InputValidationError, n as InferEntry, o as Option, p as positional, r as InferInput, s as Positional, t as BasicKind, u as convert } from "../index-C6iJZTo3.mjs";
3
3
  export { BasicKind, InferEntry, InferInput, Input, InputValidationError, Kind, Option, Positional, TypeOf, argument, convert, option, positional };
@@ -1,4 +1,4 @@
1
- import { n as InputValidationError } from "../standard-schema-DTuaYJjO.mjs";
2
- import { i as convert, n as Positional, o as option, r as argument, s as positional, t as Option } from "../input-XUsy1LCQ.mjs";
1
+ import { n as InputValidationError } from "../standard-schema-WhGEzW0C.mjs";
2
+ import { i as convert, n as Positional, o as option, r as argument, s as positional, t as Option } from "../input-li13L1uf.mjs";
3
3
 
4
4
  export { InputValidationError, Option, Positional, argument, convert, option, positional };
@@ -1,5 +1,5 @@
1
1
  import { t as __export } from "./chunk-z5eko27R.mjs";
2
- import { n as InputValidationError, t as validate } from "./standard-schema-DTuaYJjO.mjs";
2
+ import { n as InputValidationError, t as validate } from "./standard-schema-WhGEzW0C.mjs";
3
3
 
4
4
  //#region src/input/index.ts
5
5
  var input_exports = /* @__PURE__ */ __export({
@@ -173,4 +173,4 @@ function argument(kind) {
173
173
 
174
174
  //#endregion
175
175
  export { input_exports as a, convert as i, Positional as n, option as o, argument as r, positional as s, Option as t };
176
- //# sourceMappingURL=input-XUsy1LCQ.mjs.map
176
+ //# sourceMappingURL=input-li13L1uf.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"input-XUsy1LCQ.mjs","names":[],"sources":["../src/input/index.ts"],"sourcesContent":["import { validate, type StandardSchemaV1 } from \"./standard-schema\";\n\n/**\n * An input object.\n */\nexport interface Input {\n [x: string]: Option<any, any, any> | Positional<any, any, any>;\n}\n\n/**\n * A basic input type.\n */\nexport type BasicKind = \"boolean\" | \"string\" | \"number\" | \"bigint\";\n/**\n * An input type.\n */\nexport type Kind = BasicKind | StandardSchemaV1<any, any>;\n\n/**\n * Converts a Kind to a TypeScript type.\n */\nexport type TypeOf<T extends Kind> =\n T extends StandardSchemaV1<any, infer Out>\n ? Out\n : T extends \"boolean\"\n ? boolean\n : T extends \"string\"\n ? string\n : T extends \"number\"\n ? number\n : T extends \"bigint\"\n ? bigint\n : never;\n\n/**\n * Infers TypeScript types from an input object.\n */\nexport type InferInput<T extends Input> = {\n [K in keyof T]: InferEntry<T[K]>;\n};\n\n/**\n * Infers a TypeScript type from an option or positional.\n */\nexport type InferEntry<T> = T extends {\n $kind: infer TKind extends Kind;\n $required: infer Required;\n $list: infer List;\n}\n ? List extends true\n ? Required extends true\n ? TypeOf<TKind>[]\n : TypeOf<TKind>[] | undefined\n : Required extends true\n ? TypeOf<TKind>\n : TypeOf<TKind> | undefined\n : never;\n\n/**\n * Converts a value from a Kind to a TypeScript type.\n * @param kind The kind to convert to.\n * @param value The value to convert.\n * @returns The converted value.\n */\nexport async function convert<TKind extends Kind>(\n kind: TKind,\n value: string | string[],\n): Promise<TypeOf<TKind> | TypeOf<TKind>[]> {\n // Helper for single value conversion\n async function convertOne(val: string): Promise<TypeOf<TKind>> {\n if (typeof kind === \"string\") {\n switch (kind) {\n case \"boolean\":\n return (val === \"true\") as any;\n case \"bigint\":\n return BigInt(val) as any;\n case \"number\":\n return parseFloat(val) as any;\n case \"string\":\n return val as any;\n }\n }\n // Otherwise, Standard Schema\n return validate(kind, val);\n }\n\n // If list → map each item\n if (Array.isArray(value)) {\n const results = await Promise.all(value.map((v) => convertOne(v)));\n return results as any;\n }\n\n // Single value case\n return convertOne(value);\n}\n\n/**\n * An option.\n */\nexport class Option<\n TKind extends Kind,\n TRequired extends boolean = true,\n TList extends boolean = false,\n> {\n /**\n * The kind of this option.\n */\n $kind: TKind;\n /**\n * The aliases of this option.\n */\n $names: string[];\n /**\n * The description of this option.\n */\n $description: string | undefined;\n /**\n * The default value of this option.\n */\n $default: TypeOf<TKind> | undefined;\n /**\n * If this option is required.\n */\n $required: TRequired = true as TRequired;\n /**\n * If this option is a list.\n */\n $list: TList = false as TList;\n /**\n * A separator if this option is a list.\n */\n $separator: string | undefined;\n\n /**\n * Creates a new option.\n * @param kind The type of this option.\n * @param names The names of this option.\n */\n constructor(kind: TKind, names: string[]) {\n this.$kind = kind;\n this.$names = names.map((name) => name.replace(/^-+/, \"\"));\n }\n\n /**\n * Makes this option a list.\n * @returns this\n */\n list(separator?: string): Option<TKind, TRequired, true> {\n this.$list = true as TList;\n this.$separator = separator ?? this.$separator;\n return this as any;\n }\n\n /**\n * Makes this option required.\n * @returns this\n */\n required(): Option<TKind, true, TList> {\n this.$required = true as TRequired;\n return this as any;\n }\n\n /**\n * Makes this option optional.\n * @returns this\n */\n optional(): Option<TKind, false, TList> {\n this.$required = false as TRequired;\n return this as any;\n }\n\n /**\n * Sets a default value.\n * @param value The default value.\n * @returns this\n */\n default(value: TypeOf<TKind>): this {\n this.$default = value;\n return this;\n }\n\n /**\n * Sets a description.\n * @param desc The description.\n * @returns this\n */\n description(desc: string): this {\n this.$description = desc;\n return this;\n }\n}\n\n/**\n * A positional argument.\n */\nexport class Positional<\n TKind extends Kind,\n TRequired extends boolean = true,\n TList extends boolean = false,\n> {\n /**\n * The type of this argument.\n */\n $kind: TKind;\n /**\n * The default value of this argument.\n */\n $default: TypeOf<TKind> | undefined;\n /**\n * The description of this argument.\n */\n $description: string | undefined;\n /**\n * If this argument is required.\n */\n $required: TRequired = true as TRequired;\n /**\n * If this argument is a list.\n */\n $list: TList = false as TList;\n\n /**\n * Creates a new positional argument.\n * @param kind The positional argument.\n */\n constructor(kind: TKind) {\n this.$kind = kind;\n }\n\n /**\n * Makes this argument a list.\n * @returns this\n */\n list(): Positional<TKind, TRequired, true> {\n this.$list = true as TList;\n return this as any;\n }\n\n /**\n * Makes this argument required.\n * @returns this\n */\n required(): Positional<TKind, true, TList> {\n this.$required = true as TRequired;\n return this as any;\n }\n\n /**\n * Makes this argument optional.\n * @returns this\n */\n optional(): Positional<TKind, false, TList> {\n this.$required = false as TRequired;\n return this as any;\n }\n\n /**\n * Sets a default value.\n * @param value The default value.\n * @returns this\n */\n default(value: TypeOf<TKind>): this {\n this.$default = value;\n return this;\n }\n\n /**\n * Sets a description.\n * @param desc The description.\n * @returns this\n */\n description(desc: string): this {\n this.$description = desc;\n return this;\n }\n}\n\n/**\n * Creates a new option.\n * @param kind The kind of option.\n * @param names The names of the option.\n * @returns A new option.\n */\nexport function option<T extends Kind>(kind: T, ...names: string[]): Option<T> {\n return new Option(kind, names);\n}\n\n/**\n * Creates a new positional argument.\n * @param kind The kind of positional argument.\n * @returns A new positional argument.\n */\nexport function positional<T extends Kind>(kind: T): Positional<T> {\n return new Positional(kind);\n}\n\n/**\n * Creates a new positional argument.\n * @param kind The kind of positional argument.\n * @returns A new positional argument.\n */\nexport function argument<T extends Kind>(kind: T): Positional<T> {\n return new Positional(kind);\n}\n\nexport * from \"./error\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAgEA,eAAsB,QACpB,MACA,OAC0C;CAE1C,eAAe,WAAW,KAAqC;AAC7D,MAAI,OAAO,SAAS,SAClB,SAAQ,MAAR;GACE,KAAK,UACH,QAAQ,QAAQ;GAClB,KAAK,SACH,QAAO,OAAO,IAAI;GACpB,KAAK,SACH,QAAO,WAAW,IAAI;GACxB,KAAK,SACH,QAAO;;AAIb,SAAO,SAAS,MAAM,IAAI;;AAI5B,KAAI,MAAM,QAAQ,MAAM,CAEtB,QADgB,MAAM,QAAQ,IAAI,MAAM,KAAK,MAAM,WAAW,EAAE,CAAC,CAAC;AAKpE,QAAO,WAAW,MAAM;;;;;AAM1B,IAAa,SAAb,MAIE;;;;;;CAmCA,YAAY,MAAa,OAAiB;mBAfnB;eAIR;AAYb,OAAK,QAAQ;AACb,OAAK,SAAS,MAAM,KAAK,SAAS,KAAK,QAAQ,OAAO,GAAG,CAAC;;;;;;CAO5D,KAAK,WAAoD;AACvD,OAAK,QAAQ;AACb,OAAK,aAAa,aAAa,KAAK;AACpC,SAAO;;;;;;CAOT,WAAuC;AACrC,OAAK,YAAY;AACjB,SAAO;;;;;;CAOT,WAAwC;AACtC,OAAK,YAAY;AACjB,SAAO;;;;;;;CAQT,QAAQ,OAA4B;AAClC,OAAK,WAAW;AAChB,SAAO;;;;;;;CAQT,YAAY,MAAoB;AAC9B,OAAK,eAAe;AACpB,SAAO;;;;;;AAOX,IAAa,aAAb,MAIE;;;;;CA0BA,YAAY,MAAa;mBAVF;eAIR;AAOb,OAAK,QAAQ;;;;;;CAOf,OAA2C;AACzC,OAAK,QAAQ;AACb,SAAO;;;;;;CAOT,WAA2C;AACzC,OAAK,YAAY;AACjB,SAAO;;;;;;CAOT,WAA4C;AAC1C,OAAK,YAAY;AACjB,SAAO;;;;;;;CAQT,QAAQ,OAA4B;AAClC,OAAK,WAAW;AAChB,SAAO;;;;;;;CAQT,YAAY,MAAoB;AAC9B,OAAK,eAAe;AACpB,SAAO;;;;;;;;;AAUX,SAAgB,OAAuB,MAAS,GAAG,OAA4B;AAC7E,QAAO,IAAI,OAAO,MAAM,MAAM;;;;;;;AAQhC,SAAgB,WAA2B,MAAwB;AACjE,QAAO,IAAI,WAAW,KAAK;;;;;;;AAQ7B,SAAgB,SAAyB,MAAwB;AAC/D,QAAO,IAAI,WAAW,KAAK"}
1
+ {"version":3,"file":"input-li13L1uf.mjs","names":[],"sources":["../src/input/index.ts"],"sourcesContent":["import { validate, type StandardSchemaV1 } from \"./standard-schema\";\n\n/**\n * An input object.\n */\nexport interface Input {\n [x: string]: Option<any, any, any> | Positional<any, any, any>;\n}\n\n/**\n * A basic input type.\n */\nexport type BasicKind = \"boolean\" | \"string\" | \"number\" | \"bigint\";\n/**\n * An input type.\n */\nexport type Kind = BasicKind | StandardSchemaV1<any, any>;\n\n/**\n * Converts a Kind to a TypeScript type.\n */\nexport type TypeOf<T extends Kind> =\n T extends StandardSchemaV1<any, infer Out>\n ? Out\n : T extends \"boolean\"\n ? boolean\n : T extends \"string\"\n ? string\n : T extends \"number\"\n ? number\n : T extends \"bigint\"\n ? bigint\n : never;\n\n/**\n * Infers TypeScript types from an input object.\n */\nexport type InferInput<T extends Input> = {\n [K in keyof T]: InferEntry<T[K]>;\n};\n\n/**\n * Infers a TypeScript type from an option or positional.\n */\nexport type InferEntry<T> = T extends {\n $kind: infer TKind extends Kind;\n $required: infer Required;\n $list: infer List;\n}\n ? List extends true\n ? Required extends true\n ? TypeOf<TKind>[]\n : TypeOf<TKind>[] | undefined\n : Required extends true\n ? TypeOf<TKind>\n : TypeOf<TKind> | undefined\n : never;\n\n/**\n * Converts a value from a Kind to a TypeScript type.\n * @param kind The kind to convert to.\n * @param value The value to convert.\n * @returns The converted value.\n */\nexport async function convert<TKind extends Kind>(\n kind: TKind,\n value: string | string[],\n): Promise<TypeOf<TKind> | TypeOf<TKind>[]> {\n // Helper for single value conversion\n async function convertOne(val: string): Promise<TypeOf<TKind>> {\n if (typeof kind === \"string\") {\n switch (kind) {\n case \"boolean\":\n return (val === \"true\") as any;\n case \"bigint\":\n return BigInt(val) as any;\n case \"number\":\n return parseFloat(val) as any;\n case \"string\":\n return val as any;\n }\n }\n // Otherwise, Standard Schema\n return validate(kind, val);\n }\n\n // If list → map each item\n if (Array.isArray(value)) {\n const results = await Promise.all(value.map((v) => convertOne(v)));\n return results as any;\n }\n\n // Single value case\n return convertOne(value);\n}\n\n/**\n * An option.\n */\nexport class Option<\n TKind extends Kind,\n TRequired extends boolean = true,\n TList extends boolean = false,\n> {\n /**\n * The kind of this option.\n */\n $kind: TKind;\n /**\n * The aliases of this option.\n */\n $names: string[];\n /**\n * The description of this option.\n */\n $description: string | undefined;\n /**\n * The default value of this option.\n */\n $default: TypeOf<TKind> | undefined;\n /**\n * If this option is required.\n */\n $required: TRequired = true as TRequired;\n /**\n * If this option is a list.\n */\n $list: TList = false as TList;\n /**\n * A separator if this option is a list.\n */\n $separator: string | undefined;\n\n /**\n * Creates a new option.\n * @param kind The type of this option.\n * @param names The names of this option.\n */\n constructor(kind: TKind, names: string[]) {\n this.$kind = kind;\n this.$names = names.map((name) => name.replace(/^-+/, \"\"));\n }\n\n /**\n * Makes this option a list.\n * @returns this\n */\n list(separator?: string): Option<TKind, TRequired, true> {\n this.$list = true as TList;\n this.$separator = separator ?? this.$separator;\n return this as any;\n }\n\n /**\n * Makes this option required.\n * @returns this\n */\n required(): Option<TKind, true, TList> {\n this.$required = true as TRequired;\n return this as any;\n }\n\n /**\n * Makes this option optional.\n * @returns this\n */\n optional(): Option<TKind, false, TList> {\n this.$required = false as TRequired;\n return this as any;\n }\n\n /**\n * Sets a default value.\n * @param value The default value.\n * @returns this\n */\n default(value: TypeOf<TKind>): this {\n this.$default = value;\n return this;\n }\n\n /**\n * Sets a description.\n * @param desc The description.\n * @returns this\n */\n description(desc: string): this {\n this.$description = desc;\n return this;\n }\n}\n\n/**\n * A positional argument.\n */\nexport class Positional<\n TKind extends Kind,\n TRequired extends boolean = true,\n TList extends boolean = false,\n> {\n /**\n * The type of this argument.\n */\n $kind: TKind;\n /**\n * The default value of this argument.\n */\n $default: TypeOf<TKind> | undefined;\n /**\n * The description of this argument.\n */\n $description: string | undefined;\n /**\n * If this argument is required.\n */\n $required: TRequired = true as TRequired;\n /**\n * If this argument is a list.\n */\n $list: TList = false as TList;\n\n /**\n * Creates a new positional argument.\n * @param kind The positional argument.\n */\n constructor(kind: TKind) {\n this.$kind = kind;\n }\n\n /**\n * Makes this argument a list.\n * @returns this\n */\n list(): Positional<TKind, TRequired, true> {\n this.$list = true as TList;\n return this as any;\n }\n\n /**\n * Makes this argument required.\n * @returns this\n */\n required(): Positional<TKind, true, TList> {\n this.$required = true as TRequired;\n return this as any;\n }\n\n /**\n * Makes this argument optional.\n * @returns this\n */\n optional(): Positional<TKind, false, TList> {\n this.$required = false as TRequired;\n return this as any;\n }\n\n /**\n * Sets a default value.\n * @param value The default value.\n * @returns this\n */\n default(value: TypeOf<TKind>): this {\n this.$default = value;\n return this;\n }\n\n /**\n * Sets a description.\n * @param desc The description.\n * @returns this\n */\n description(desc: string): this {\n this.$description = desc;\n return this;\n }\n}\n\n/**\n * Creates a new option.\n * @param kind The kind of option.\n * @param names The names of the option.\n * @returns A new option.\n */\nexport function option<T extends Kind>(kind: T, ...names: string[]): Option<T> {\n return new Option(kind, names);\n}\n\n/**\n * Creates a new positional argument.\n * @param kind The kind of positional argument.\n * @returns A new positional argument.\n */\nexport function positional<T extends Kind>(kind: T): Positional<T> {\n return new Positional(kind);\n}\n\n/**\n * Creates a new positional argument.\n * @param kind The kind of positional argument.\n * @returns A new positional argument.\n */\nexport function argument<T extends Kind>(kind: T): Positional<T> {\n return new Positional(kind);\n}\n\nexport * from \"./error\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAgEA,eAAsB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G,OAA4B;AAC7E,QAAO,IAAI,OAAO,MAAM,MAAM;;;;;;;AAQhC,SAAgB,WAA2B,MAAwB;AACjE,QAAO,IAAI,WAAW,KAAK;;;;;;;AAQ7B,SAAgB,SAAyB,MAAwB;AAC/D,QAAO,IAAI,WAAW,KAAK"}
@@ -1,5 +1,5 @@
1
- import "../index-BtbthYjp.mjs";
2
- import "../standard-schema-DXS-QnwX.mjs";
3
- import { i as raw_d_exports } from "../raw-cqTp2vds.mjs";
4
- import { _ as text, a as SearchOpts, c as TextOpts, f as multiselect, g as setTheme, h as select, i as PasswordOpts, l as confirm, m as search, n as ConfirmOpts, o as SelectOption, p as password, r as EditorOpts, s as SelectOpts, t as BaseOpts, u as editor } from "../index-BYLskLxk.mjs";
1
+ import "../theme-EERPMtQU.mjs";
2
+ import "../standard-schema-D1sStgzy.mjs";
3
+ import { i as raw_d_exports } from "../raw-BqvlveTU.mjs";
4
+ import { _ as text, a as SearchOpts, c as TextOpts, f as multiselect, g as setTheme, h as select, i as PasswordOpts, l as confirm, m as search, n as ConfirmOpts, o as SelectOption, p as password, r as EditorOpts, s as SelectOpts, t as BaseOpts, u as editor } from "../index-C0cH9MIP.mjs";
5
5
  export { BaseOpts, ConfirmOpts, EditorOpts, PasswordOpts, SearchOpts, SelectOption, SelectOpts, TextOpts, confirm, editor, multiselect, password, raw_d_exports as raw, search, select, setTheme, text };
@@ -1,6 +1,7 @@
1
- import "../color-DiZvJ0Fc.mjs";
2
- import "../standard-schema-DTuaYJjO.mjs";
3
- import { i as raw_exports } from "../raw-DEtZFeMv.mjs";
4
- import { c as setTheme, i as password, l as text, n as editor, o as search, r as multiselect, s as select, t as confirm } from "../prompt-a5Ix_Hyc.mjs";
1
+ import "../color-s-N9yh90.mjs";
2
+ import "../theme-Chg3mOhZ.mjs";
3
+ import "../standard-schema-WhGEzW0C.mjs";
4
+ import { i as raw_exports } from "../raw-DVT5lw11.mjs";
5
+ import { c as setTheme, i as password, l as text, n as editor, o as search, r as multiselect, s as select, t as confirm } from "../prompt-OXGrAkDf.mjs";
5
6
 
6
7
  export { confirm, editor, multiselect, password, raw_exports as raw, search, select, setTheme, text };
@@ -1,2 +1,2 @@
1
- import { a as readKey, n as cursorDown, o as readLine, r as cursorUp, t as clearLines } from "../raw-cqTp2vds.mjs";
1
+ import { a as readKey, n as cursorDown, o as readLine, r as cursorUp, t as clearLines } from "../raw-BqvlveTU.mjs";
2
2
  export { clearLines, cursorDown, cursorUp, readKey, readLine };
@@ -1,3 +1,3 @@
1
- import { a as readKey, n as cursorDown, o as readLine, r as cursorUp, t as clearLines } from "../raw-DEtZFeMv.mjs";
1
+ import { a as readKey, n as cursorDown, o as readLine, r as cursorUp, t as clearLines } from "../raw-DVT5lw11.mjs";
2
2
 
3
3
  export { clearLines, cursorDown, cursorUp, readKey, readLine };
@@ -1,7 +1,7 @@
1
1
  import { t as __export } from "./chunk-z5eko27R.mjs";
2
- import { t as DEFAULT_THEME } from "./color-DiZvJ0Fc.mjs";
3
- import { n as InputValidationError, t as validate } from "./standard-schema-DTuaYJjO.mjs";
4
- import { a as readKey, i as raw_exports, o as readLine, r as cursorUp, t as clearLines } from "./raw-DEtZFeMv.mjs";
2
+ import { t as DEFAULT_THEME } from "./theme-Chg3mOhZ.mjs";
3
+ import { n as InputValidationError, t as validate } from "./standard-schema-WhGEzW0C.mjs";
4
+ import { a as readKey, i as raw_exports, o as readLine, r as cursorUp, t as clearLines } from "./raw-DVT5lw11.mjs";
5
5
  import childProcess from "node:child_process";
6
6
  import fs from "node:fs/promises";
7
7
  import path from "node:path";
@@ -217,4 +217,4 @@ async function openSystemEditor(initial) {
217
217
 
218
218
  //#endregion
219
219
  export { prompt_exports as a, setTheme as c, password as i, text as l, editor as n, search as o, multiselect as r, select as s, confirm as t };
220
- //# sourceMappingURL=prompt-a5Ix_Hyc.mjs.map
220
+ //# sourceMappingURL=prompt-OXGrAkDf.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"prompt-a5Ix_Hyc.mjs","names":["theme: Theme","raw.readLine","raw.readKey","editor"],"sources":["../src/prompt/index.ts"],"sourcesContent":["import childProcess from \"node:child_process\";\nimport fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport os from \"node:os\";\n\nimport { DEFAULT_THEME, type Theme } from \"@/color\";\nimport { validate, type StandardSchemaV1 } from \"@/input/standard-schema\";\nimport { InputValidationError } from \"@/input/error\";\nimport * as raw from \"./raw\";\n\nlet theme: Theme = DEFAULT_THEME;\n\n/**\n * Sets the theme of the prompts.\n * @param t The new theme.\n */\nexport function setTheme(t: Theme) {\n theme = t;\n}\n\n/**\n * Base options for prompts.\n */\nexport interface BaseOpts<T> {\n /**\n * The message of the prompt.\n */\n message: string;\n /**\n * An `AbortSignal` to cancel the prompt.\n */\n signal?: AbortSignal;\n /**\n * The default value.\n */\n default?: T;\n /**\n * The theme of the prompt.\n */\n theme?: Theme;\n /**\n * A validator function, or a Standard Schema validator.\n */\n validate?: StandardSchemaV1<any, T> | ((value: T) => boolean | T);\n}\n\n// -- text -- //\n\n/**\n * Options for text input.\n */\nexport interface TextOpts extends BaseOpts<string> {\n /**\n * A placeholder, displayed when the user hasn't typed anything yet.\n */\n placeholder?: string;\n /**\n * Minimum length of the input.\n */\n minLength?: number;\n /**\n * Maximum length of the input.\n */\n maxLength?: number;\n}\n\n/**\n * Prompts the user for text input.\n * @param opts Options for text input.\n * @returns The text the user typed in, or the default.\n */\nexport async function text(opts: TextOpts): Promise<string> {\n const th = opts.theme ?? theme;\n const message = th.primary(opts.message) + \" \";\n const answer = await raw.readLine(message, opts.default);\n\n if (opts.minLength && answer.length < opts.minLength)\n throw new InputValidationError([\n `Must be at least ${opts.minLength} characters`,\n ]);\n if (opts.maxLength && answer.length > opts.maxLength)\n throw new InputValidationError([\n `Must be at most ${opts.maxLength} characters`,\n ]);\n\n if (typeof opts.validate === \"function\") {\n if (!opts.validate(answer))\n throw new InputValidationError([\n \"Validation function returned a falsy value\",\n ]);\n } else if (opts.validate) {\n await validate(opts.validate, answer);\n }\n return answer;\n}\n\n// -- password -- //\n\n/**\n * Options for password input.\n */\nexport interface PasswordOpts extends TextOpts {\n /**\n * The mask for the password input.\n */\n mask?: string;\n /**\n * If the user should be asked to confirm the password, by typing it again.\n */\n confirm?: boolean;\n}\n\n/**\n * Prompts the user for a password.\n * @param opts Options for password input.\n * @returns The password.\n */\nexport async function password(opts: PasswordOpts): Promise<string> {\n const th = opts.theme ?? theme;\n const first = await raw.readLine(th.primary(opts.message) + \" \", undefined, {\n masked: true,\n maskChar: opts.mask ?? \"*\",\n });\n if (opts.confirm) {\n const second = await raw.readLine(\n th.secondary(\"Confirm password: \"),\n undefined,\n {\n masked: true,\n maskChar: opts.mask ?? \"*\",\n },\n );\n if (first !== second) throw new Error(th.error(\"Passwords do not match\"));\n }\n return first;\n}\n\n// -- select -- //\n\n/**\n * An option for select input.\n */\nexport interface SelectOption<T> {\n /**\n * The label (what gets displayed) of the select option.\n */\n label: string;\n /**\n * The value (what gets returned) of the select option.\n */\n value: T;\n /**\n * A description of the option.\n */\n hint?: string;\n /**\n * If this option is disabled.\n */\n disabled?: boolean;\n}\n\n/**\n * Options for select input.\n */\nexport interface SelectOpts<T> extends BaseOpts<T> {\n /**\n * Every option the user can pick from.\n */\n options: SelectOption<T>[];\n /**\n * The initial option selected.\n */\n initialIndex?: number;\n}\n\n/**\n * Prompts the user to select a single option.\n * @param opts Options for select input.\n * @returns The selected option's value.\n */\nexport async function select<T>(opts: SelectOpts<T>): Promise<T> {\n const th = opts.theme ?? theme;\n const options = opts.options;\n let index = opts.initialIndex ?? 0;\n\n const render = () => {\n raw.clearLines(options.length + 1);\n console.log(th.primary(opts.message));\n for (let i = 0; i < options.length; i++) {\n const o = options[i];\n const prefix = i === index ? (th.accent?.(\"> \") ?? \"> \") : \" \";\n const label = o.disabled\n ? th.secondary(o.label)\n : (th.foreground?.(o.label) ?? o.label);\n console.log(prefix + label);\n }\n };\n\n console.log(th.primary(opts.message));\n options.forEach((o, i) =>\n console.log(`${i === index ? \"> \" : \" \"}${o.label}`),\n );\n\n while (true) {\n const key = await raw.readKey();\n if (key === \"up\" && index > 0) index--;\n else if (key === \"down\" && index < options.length - 1) index++;\n else if (key === \"enter\") {\n const choice = options[index];\n if (choice.disabled) continue;\n raw.clearLines(options.length + 1);\n console.log(th.success(`${th.symbols?.success ?? \"✔\"} ${choice.label}`));\n return choice.value;\n }\n render();\n }\n}\n\n/**\n * Prompts the user to select multiple options.\n * @param opts Options for select input.\n * @returns The selected options.\n */\nexport async function multiselect<T>(opts: SelectOpts<T>): Promise<T[]> {\n const th = opts.theme ?? theme;\n const options = opts.options;\n let index = opts.initialIndex ?? 0;\n const selected = new Set<number>();\n\n const render = () => {\n raw.clearLines();\n console.log(th.primary(opts.message));\n options.forEach((opt, i) => {\n const prefix = i === index ? (th.accent?.(\"> \") ?? \"> \") : \" \";\n const mark = selected.has(i) ? th.success(\"[x]\") : \"[ ]\";\n console.log(prefix + mark + \" \" + opt.label);\n });\n };\n\n render();\n while (true) {\n const key = await raw.readKey();\n if (key === \"up\" && index > 0) index--;\n else if (key === \"down\" && index < options.length - 1) index++;\n else if (key === \"space\") {\n if (selected.has(index)) selected.delete(index);\n else selected.add(index);\n } else if (key === \"enter\") {\n const chosen = Array.from(selected).map((i) => options[i].value);\n raw.clearLines(options.length + 1);\n console.log(th.success(`${opts.message} ${chosen.length} selected`));\n return chosen;\n }\n raw.cursorUp(options.length);\n render();\n }\n}\n\n// -- search -- //\n\n/**\n * Options for search input.\n */\nexport interface SearchOpts<T> extends BaseOpts<T> {\n /**\n * Every option the user can search through.\n */\n options: SelectOption<T>[];\n /**\n * Placeholder for the search input.\n */\n placeholder?: string;\n /**\n * Minimum length for a query string.\n */\n minQueryLength?: number;\n /**\n * Filters a single option.\n * @param query The search query.\n * @param option The option to filter.\n */\n filter?(query: string, option: SelectOption<T>): boolean;\n}\n\n/**\n * Prompts the user to search through a list of options.\n * @param opts Options for search input.\n * @returns The selected option.\n */\nexport async function search<T>(opts: SearchOpts<T>): Promise<T> {\n const th = opts.theme ?? theme;\n let query = \"\";\n const filter =\n opts.filter ?? ((q, o) => o.label.toLowerCase().includes(q.toLowerCase()));\n while (true) {\n raw.clearLines();\n console.log(th.primary(opts.message));\n\n const matches = opts.options.filter((o) => filter(query, o));\n matches.forEach((o) =>\n console.log(\" \" + (th.foreground?.(o.label) ?? o.label)),\n );\n\n if (matches.length === 1) {\n return matches[0].value;\n }\n\n const input = await raw.readLine(th.secondary(`Search: ${query}`));\n if (!input) continue;\n\n query = input;\n }\n}\n\n// -- confirm -- //\n\n/**\n * Options for confirm input.\n */\nexport interface ConfirmOpts extends BaseOpts<boolean> {\n /**\n * What gets displayed for the Yes option.\n */\n yesLabel?: string;\n /**\n * What gets displayed for the No option.\n */\n noLabel?: string;\n}\n\n/**\n * Prompts the user to confirm an action.\n * @param opts Options for confirm input.\n * @returns If the user picked Yes.\n */\nexport async function confirm(opts: ConfirmOpts): Promise<boolean> {\n const th = opts.theme ?? theme;\n const yes = opts.yesLabel ?? \"y\";\n const no = opts.noLabel ?? \"n\";\n const def = opts.default ? yes : no;\n const res = await raw.readLine(\n `${th.primary(opts.message)} ${th.secondary(`[${yes}/${no}] (default: ${def})`)} `,\n );\n if (!res) return !!opts.default;\n return /^y/i.test(res.trim());\n}\n\n// -- editor -- //\n\n/**\n * Options for opening the system editor.\n */\nexport interface EditorOpts extends BaseOpts<string> {\n /**\n * The initial value.\n */\n initial?: string;\n /**\n * The language of the value.\n */\n language?: string;\n /**\n * If the input is required for continuing or not.\n */\n required?: boolean;\n}\n\n/**\n * Opens the system editor, or asks for input in the terminal as fallback.\n * @param opts Options for opening the system editor.\n * @returns The result of the system editor.\n */\nexport async function editor(opts: EditorOpts): Promise<string> {\n const th = opts.theme ?? {\n primary: (s: string) => s,\n secondary: (s: string) => s,\n };\n\n console.log(th.primary(opts.message ?? \"Please enter text:\"));\n console.log(th.secondary(\"Press Ctrl+D (or save & close editor) when done.\"));\n\n try {\n const result = await openSystemEditor(opts.initial ?? \"\");\n if (opts.required && !result.trim()) throw new Error(\"Input required.\");\n return result;\n } catch {\n // fallback: cross-runtime multiline input\n const value = await raw.readLine(\"\", opts.initial, { multiline: true });\n if (opts.required && !value.trim()) throw new Error(\"Input required.\");\n return value;\n }\n}\n\n/**\n * Opens the system editor on a temporary file.\n * @param initial Initial contents of the file.\n * @returns The contents of the file after saving.\n */\nasync function openSystemEditor(initial: string): Promise<string> {\n const tmpFile = `edit-${Date.now()}.txt`;\n const filePath = path.join(os.tmpdir(), tmpFile);\n await fs.writeFile(filePath, initial ?? \"\", \"utf8\");\n\n const editor =\n process.env.EDITOR ||\n process.env.VISUAL ||\n (process.platform === \"win32\" ? \"notepad\" : \"vi\");\n\n return new Promise((resolve, reject) => {\n const child = childProcess.spawn(editor, [filePath], { stdio: \"inherit\" });\n child.on(\"exit\", async (code: number) => {\n if (code !== 0) {\n reject(new Error(`${editor} exited with code ${code}`));\n return;\n }\n try {\n const data = await fs.readFile(filePath, \"utf8\");\n await fs.unlink(filePath).catch(() => {});\n resolve(data);\n } catch (err) {\n reject(err);\n }\n });\n });\n}\n\nexport { raw };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAUA,IAAIA,QAAe;;;;;AAMnB,SAAgB,SAAS,GAAU;AACjC,SAAQ;;;;;;;AAsDV,eAAsB,KAAK,MAAiC;CAE1D,MAAM,WADK,KAAK,SAAS,OACN,QAAQ,KAAK,QAAQ,GAAG;CAC3C,MAAM,SAAS,MAAMC,SAAa,SAAS,KAAK,QAAQ;AAExD,KAAI,KAAK,aAAa,OAAO,SAAS,KAAK,UACzC,OAAM,IAAI,qBAAqB,CAC7B,oBAAoB,KAAK,UAAU,aACpC,CAAC;AACJ,KAAI,KAAK,aAAa,OAAO,SAAS,KAAK,UACzC,OAAM,IAAI,qBAAqB,CAC7B,mBAAmB,KAAK,UAAU,aACnC,CAAC;AAEJ,KAAI,OAAO,KAAK,aAAa,YAC3B;MAAI,CAAC,KAAK,SAAS,O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AW,GAAG;AACzD,MAAI,KAAK,YAAY,CAAC,OAAO,MAAM,CAAE,OAAM,IAAI,MAAM,kBAAkB;AACvE,SAAO;SACD;EAEN,MAAM,QAAQ,MAAMA,SAAa,IAAI,KAAK,SAAS,EAAE,WAAW,MAAM,CAAC;AACvE,MAAI,KAAK,YAAY,CAAC,MAAM,MAAM,CAAE,OAAM,IAAI,MAAM,kBAAkB;AACtE,SAAO;;;;;;;;AASX,eAAe,iBAAiB,SAAkC;CAChE,MAAM,UAAU,QAAQ,KAAK,KAAK,CAAC;CACnC,MAAM,WAAW,KAAK,KAAK,GAAG,QAAQ,EAAE,QAAQ;AAChD,OAAM,GAAG,UAAU,UAAU,WAAW,IAAI,OAAO;CAEnD,MAAME,WACJ,QAAQ,IAAI,UACZ,QAAQ,IAAI,WACX,QAAQ,aAAa,UAAU,YAAY;AAE9C,QAAO,IAAI,SAAS,SAAS,WAAW;AAEtC,EADc,aAAa,MAAMA,UAAQ,CAAC,SAAS,EAAE,EAAE,OAAO,WAAW,CAAC,CACpE,GAAG,QAAQ,OAAO,SAAiB;AACvC,OAAI,SAAS,GAAG;AACd,2BAAO,IAAI,MAAM,GAAGA,SAAO,oBAAoB,OAAO,CAAC;AACvD;;AAEF,OAAI;IACF,MAAM,OAAO,MAAM,GAAG,SAAS,UAAU,OAAO;AAChD,UAAM,GAAG,OAAO,SAAS,CAAC,YAAY,GAAG;AACzC,YAAQ,KAAK;YACN,KAAK;AACZ,WAAO,IAAI;;IAEb;GACF"}
1
+ {"version":3,"file":"prompt-OXGrAkDf.mjs","names":["theme: Theme","raw.readLine","raw.readKey","editor"],"sources":["../src/prompt/index.ts"],"sourcesContent":["import childProcess from \"node:child_process\";\nimport fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport os from \"node:os\";\n\nimport { DEFAULT_THEME, type Theme } from \"@/theme\";\nimport { validate, type StandardSchemaV1 } from \"@/input/standard-schema\";\nimport { InputValidationError } from \"@/input/error\";\nimport * as raw from \"./raw\";\n\nlet theme: Theme = DEFAULT_THEME;\n\n/**\n * Sets the theme of the prompts.\n * @param t The new theme.\n */\nexport function setTheme(t: Theme) {\n theme = t;\n}\n\n/**\n * Base options for prompts.\n */\nexport interface BaseOpts<T> {\n /**\n * The message of the prompt.\n */\n message: string;\n /**\n * An `AbortSignal` to cancel the prompt.\n */\n signal?: AbortSignal;\n /**\n * The default value.\n */\n default?: T;\n /**\n * The theme of the prompt.\n */\n theme?: Theme;\n /**\n * A validator function, or a Standard Schema validator.\n */\n validate?: StandardSchemaV1<any, T> | ((value: T) => boolean | T);\n}\n\n// -- text -- //\n\n/**\n * Options for text input.\n */\nexport interface TextOpts extends BaseOpts<string> {\n /**\n * A placeholder, displayed when the user hasn't typed anything yet.\n */\n placeholder?: string;\n /**\n * Minimum length of the input.\n */\n minLength?: number;\n /**\n * Maximum length of the input.\n */\n maxLength?: number;\n}\n\n/**\n * Prompts the user for text input.\n * @param opts Options for text input.\n * @returns The text the user typed in, or the default.\n */\nexport async function text(opts: TextOpts): Promise<string> {\n const th = opts.theme ?? theme;\n const message = th.primary(opts.message) + \" \";\n const answer = await raw.readLine(message, opts.default);\n\n if (opts.minLength && answer.length < opts.minLength)\n throw new InputValidationError([\n `Must be at least ${opts.minLength} characters`,\n ]);\n if (opts.maxLength && answer.length > opts.maxLength)\n throw new InputValidationError([\n `Must be at most ${opts.maxLength} characters`,\n ]);\n\n if (typeof opts.validate === \"function\") {\n if (!opts.validate(answer))\n throw new InputValidationError([\n \"Validation function returned a falsy value\",\n ]);\n } else if (opts.validate) {\n await validate(opts.validate, answer);\n }\n return answer;\n}\n\n// -- password -- //\n\n/**\n * Options for password input.\n */\nexport interface PasswordOpts extends TextOpts {\n /**\n * The mask for the password input.\n */\n mask?: string;\n /**\n * If the user should be asked to confirm the password, by typing it again.\n */\n confirm?: boolean;\n}\n\n/**\n * Prompts the user for a password.\n * @param opts Options for password input.\n * @returns The password.\n */\nexport async function password(opts: PasswordOpts): Promise<string> {\n const th = opts.theme ?? theme;\n const first = await raw.readLine(th.primary(opts.message) + \" \", undefined, {\n masked: true,\n maskChar: opts.mask ?? \"*\",\n });\n if (opts.confirm) {\n const second = await raw.readLine(\n th.secondary(\"Confirm password: \"),\n undefined,\n {\n masked: true,\n maskChar: opts.mask ?? \"*\",\n },\n );\n if (first !== second) throw new Error(th.error(\"Passwords do not match\"));\n }\n return first;\n}\n\n// -- select -- //\n\n/**\n * An option for select input.\n */\nexport interface SelectOption<T> {\n /**\n * The label (what gets displayed) of the select option.\n */\n label: string;\n /**\n * The value (what gets returned) of the select option.\n */\n value: T;\n /**\n * A description of the option.\n */\n hint?: string;\n /**\n * If this option is disabled.\n */\n disabled?: boolean;\n}\n\n/**\n * Options for select input.\n */\nexport interface SelectOpts<T> extends BaseOpts<T> {\n /**\n * Every option the user can pick from.\n */\n options: SelectOption<T>[];\n /**\n * The initial option selected.\n */\n initialIndex?: number;\n}\n\n/**\n * Prompts the user to select a single option.\n * @param opts Options for select input.\n * @returns The selected option's value.\n */\nexport async function select<T>(opts: SelectOpts<T>): Promise<T> {\n const th = opts.theme ?? theme;\n const options = opts.options;\n let index = opts.initialIndex ?? 0;\n\n const render = () => {\n raw.clearLines(options.length + 1);\n console.log(th.primary(opts.message));\n for (let i = 0; i < options.length; i++) {\n const o = options[i];\n const prefix = i === index ? (th.accent?.(\"> \") ?? \"> \") : \" \";\n const label = o.disabled\n ? th.secondary(o.label)\n : (th.foreground?.(o.label) ?? o.label);\n console.log(prefix + label);\n }\n };\n\n console.log(th.primary(opts.message));\n options.forEach((o, i) =>\n console.log(`${i === index ? \"> \" : \" \"}${o.label}`),\n );\n\n while (true) {\n const key = await raw.readKey();\n if (key === \"up\" && index > 0) index--;\n else if (key === \"down\" && index < options.length - 1) index++;\n else if (key === \"enter\") {\n const choice = options[index];\n if (choice.disabled) continue;\n raw.clearLines(options.length + 1);\n console.log(th.success(`${th.symbols?.success ?? \"✔\"} ${choice.label}`));\n return choice.value;\n }\n render();\n }\n}\n\n/**\n * Prompts the user to select multiple options.\n * @param opts Options for select input.\n * @returns The selected options.\n */\nexport async function multiselect<T>(opts: SelectOpts<T>): Promise<T[]> {\n const th = opts.theme ?? theme;\n const options = opts.options;\n let index = opts.initialIndex ?? 0;\n const selected = new Set<number>();\n\n const render = () => {\n raw.clearLines();\n console.log(th.primary(opts.message));\n options.forEach((opt, i) => {\n const prefix = i === index ? (th.accent?.(\"> \") ?? \"> \") : \" \";\n const mark = selected.has(i) ? th.success(\"[x]\") : \"[ ]\";\n console.log(prefix + mark + \" \" + opt.label);\n });\n };\n\n render();\n while (true) {\n const key = await raw.readKey();\n if (key === \"up\" && index > 0) index--;\n else if (key === \"down\" && index < options.length - 1) index++;\n else if (key === \"space\") {\n if (selected.has(index)) selected.delete(index);\n else selected.add(index);\n } else if (key === \"enter\") {\n const chosen = Array.from(selected).map((i) => options[i].value);\n raw.clearLines(options.length + 1);\n console.log(th.success(`${opts.message} ${chosen.length} selected`));\n return chosen;\n }\n raw.cursorUp(options.length);\n render();\n }\n}\n\n// -- search -- //\n\n/**\n * Options for search input.\n */\nexport interface SearchOpts<T> extends BaseOpts<T> {\n /**\n * Every option the user can search through.\n */\n options: SelectOption<T>[];\n /**\n * Placeholder for the search input.\n */\n placeholder?: string;\n /**\n * Minimum length for a query string.\n */\n minQueryLength?: number;\n /**\n * Filters a single option.\n * @param query The search query.\n * @param option The option to filter.\n */\n filter?(query: string, option: SelectOption<T>): boolean;\n}\n\n/**\n * Prompts the user to search through a list of options.\n * @param opts Options for search input.\n * @returns The selected option.\n */\nexport async function search<T>(opts: SearchOpts<T>): Promise<T> {\n const th = opts.theme ?? theme;\n let query = \"\";\n const filter =\n opts.filter ?? ((q, o) => o.label.toLowerCase().includes(q.toLowerCase()));\n while (true) {\n raw.clearLines();\n console.log(th.primary(opts.message));\n\n const matches = opts.options.filter((o) => filter(query, o));\n matches.forEach((o) =>\n console.log(\" \" + (th.foreground?.(o.label) ?? o.label)),\n );\n\n if (matches.length === 1) {\n return matches[0].value;\n }\n\n const input = await raw.readLine(th.secondary(`Search: ${query}`));\n if (!input) continue;\n\n query = input;\n }\n}\n\n// -- confirm -- //\n\n/**\n * Options for confirm input.\n */\nexport interface ConfirmOpts extends BaseOpts<boolean> {\n /**\n * What gets displayed for the Yes option.\n */\n yesLabel?: string;\n /**\n * What gets displayed for the No option.\n */\n noLabel?: string;\n}\n\n/**\n * Prompts the user to confirm an action.\n * @param opts Options for confirm input.\n * @returns If the user picked Yes.\n */\nexport async function confirm(opts: ConfirmOpts): Promise<boolean> {\n const th = opts.theme ?? theme;\n const yes = opts.yesLabel ?? \"y\";\n const no = opts.noLabel ?? \"n\";\n const def = opts.default ? yes : no;\n const res = await raw.readLine(\n `${th.primary(opts.message)} ${th.secondary(`[${yes}/${no}] (default: ${def})`)} `,\n );\n if (!res) return !!opts.default;\n return /^y/i.test(res.trim());\n}\n\n// -- editor -- //\n\n/**\n * Options for opening the system editor.\n */\nexport interface EditorOpts extends BaseOpts<string> {\n /**\n * The initial value.\n */\n initial?: string;\n /**\n * The language of the value.\n */\n language?: string;\n /**\n * If the input is required for continuing or not.\n */\n required?: boolean;\n}\n\n/**\n * Opens the system editor, or asks for input in the terminal as fallback.\n * @param opts Options for opening the system editor.\n * @returns The result of the system editor.\n */\nexport async function editor(opts: EditorOpts): Promise<string> {\n const th = opts.theme ?? {\n primary: (s: string) => s,\n secondary: (s: string) => s,\n };\n\n console.log(th.primary(opts.message ?? \"Please enter text:\"));\n console.log(th.secondary(\"Press Ctrl+D (or save & close editor) when done.\"));\n\n try {\n const result = await openSystemEditor(opts.initial ?? \"\");\n if (opts.required && !result.trim()) throw new Error(\"Input required.\");\n return result;\n } catch {\n // fallback: cross-runtime multiline input\n const value = await raw.readLine(\"\", opts.initial, { multiline: true });\n if (opts.required && !value.trim()) throw new Error(\"Input required.\");\n return value;\n }\n}\n\n/**\n * Opens the system editor on a temporary file.\n * @param initial Initial contents of the file.\n * @returns The contents of the file after saving.\n */\nasync function openSystemEditor(initial: string): Promise<string> {\n const tmpFile = `edit-${Date.now()}.txt`;\n const filePath = path.join(os.tmpdir(), tmpFile);\n await fs.writeFile(filePath, initial ?? \"\", \"utf8\");\n\n const editor =\n process.env.EDITOR ||\n process.env.VISUAL ||\n (process.platform === \"win32\" ? \"notepad\" : \"vi\");\n\n return new Promise((resolve, reject) => {\n const child = childProcess.spawn(editor, [filePath], { stdio: \"inherit\" });\n child.on(\"exit\", async (code: number) => {\n if (code !== 0) {\n reject(new Error(`${editor} exited with code ${code}`));\n return;\n }\n try {\n const data = await fs.readFile(filePath, \"utf8\");\n await fs.unlink(filePath).catch(() => {});\n resolve(data);\n } catch (err) {\n reject(err);\n }\n });\n });\n}\n\nexport { raw };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAUA,IAAIA,QAAe;;;;;AAMnB,SAAgB,SAAS,GAAU;AACjC,SAAQ;;;;;;;AAsDV,eAAsB,KAAK,MAAiC;CAE1D,MAAM,WADK,KAAK,SAAS,OACN,QAAQ,KAAK,QAAQ,GAAG;CAC3C,MAAM,SAAS,MAAMC,SAAa,SAAS,KAAK,QAAQ;AAExD,KAAI,KAAK,aAAa,OAAO,SAAS,KAAK,UACzC,OAAM,IAAI,qBAAqB,CAC7B,oBAAoB,KAAK,UAAU,aACpC,CAAC;AACJ,KAAI,KAAK,aAAa,OAAO,SAAS,KAAK,UACzC,OAAM,IAAI,qBAAqB,CAC7B,mBAAmB,KAAK,UAAU,aACnC,CAAC;AAEJ,KAAI,OAAO,KAAK,aAAa,YAC3B;MAAI,CAAC,KAAK,SAAS,OAAO,CACxB,OAAM,IAAI,qBAAqB,CAC7B,6CACD,CAAC;YACK,KAAK,SACd,OAAM,SAAS,KAAK,UAAU,OAAO;AAEvC,QAAO;;;;;;;AAwBT,eAAsB,SAAS,MAAqC;CAClE,MAAM,KAAK,KAAK,SAAS;CACzB,MAAM,QAAQ,MAAMA,SAAa,GAAG,QAAQ,KAAK,QAAQ,GAAG,KAAK,QAAW;EAC1E,QAAQ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;;;;;AASX,eAAe,iBAAiB,SAAkC;CAChE,MAAM,UAAU,QAAQ,KAAK,KAAK,CAAC;CACnC,MAAM,WAAW,KAAK,KAAK,GAAG,QAAQ,EAAE,QAAQ;AAChD,OAAM,GAAG,UAAU,UAAU,WAAW,IAAI,OAAO;CAEnD,MAAME,WACJ,QAAQ,IAAI,UACZ,QAAQ,IAAI,WACX,QAAQ,aAAa,UAAU,YAAY;AAE9C,QAAO,IAAI,SAAS,SAAS,WAAW;AAEtC,EADc,aAAa,MAAMA,UAAQ,CAAC,SAAS,EAAE,EAAE,OAAO,WAAW,CAAC,CACpE,GAAG,QAAQ,OAAO,SAAiB;AACvC,OAAI,SAAS,GAAG;AACd,2BAAO,IAAI,MAAM,GAAGA,SAAO,oBAAoB,OAAO,CAAC;AACvD;;AAEF,OAAI;IACF,MAAM,OAAO,MAAM,GAAG,SAAS,UAAU,OAAO;AAChD,UAAM,GAAG,OAAO,SAAS,CAAC,YAAY,GAAG;AACzC,YAAQ,KAAK;YACN,KAAK;AACZ,WAAO,IAAI;;IAEb;GACF"}
@@ -35,4 +35,4 @@ declare function cursorUp(n?: number): void;
35
35
  declare function cursorDown(n?: number): void;
36
36
  //#endregion
37
37
  export { readKey as a, raw_d_exports as i, cursorDown as n, readLine as o, cursorUp as r, clearLines as t };
38
- //# sourceMappingURL=raw-cqTp2vds.d.mts.map
38
+ //# sourceMappingURL=raw-BqvlveTU.d.mts.map
@@ -85,4 +85,4 @@ function cursorDown(n = 1) {
85
85
 
86
86
  //#endregion
87
87
  export { readKey as a, raw_exports as i, cursorDown as n, readLine as o, cursorUp as r, clearLines as t };
88
- //# sourceMappingURL=raw-DEtZFeMv.mjs.map
88
+ //# sourceMappingURL=raw-DVT5lw11.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"raw-DEtZFeMv.mjs","names":[],"sources":["../src/prompt/raw.ts"],"sourcesContent":["import readline from \"node:readline\";\n\n/**\n * Reads a line from standard input.\n * @param message The message.\n * @param def Default value.\n * @param opts Options for reading a line.\n * @returns The line that was read.\n */\nexport function readLine(\n message = \"\",\n def?: string,\n opts?: { masked?: boolean; maskChar?: string; multiline?: boolean },\n): Promise<string> {\n return new Promise((resolve) => {\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: true,\n });\n\n if (opts?.masked) {\n const write = (rl as any)._writeToOutput.bind(rl);\n (rl as any)._writeToOutput = (str: string) => {\n if (str.match(/^\\x1b/)) return write(str);\n if (str.endsWith(\"\\n\") || str.endsWith(\"\\r\")) return write(str);\n const mask = opts.maskChar ?? \"*\";\n write(mask.repeat(str.length));\n };\n }\n\n rl.question(message, (answer: string) => {\n rl.close();\n resolve(answer || def || \"\");\n });\n });\n}\n\n/**\n * Reads a single key from stdin.\n * @returns The key that was read.\n */\nexport async function readKey(): Promise<string> {\n return new Promise((resolve) => {\n const stdin = process.stdin;\n stdin.setRawMode(true);\n stdin.resume();\n stdin.once(\"data\", (data: Buffer) => {\n const s = data.toString();\n stdin.setRawMode(false);\n stdin.pause();\n if (s === \"\\r\" || s === \"\\n\") return resolve(\"enter\");\n if (s === \" \") return resolve(\"space\");\n if (s === \"\\u001b[A\") return resolve(\"up\");\n if (s === \"\\u001b[B\") return resolve(\"down\");\n if (s === \"\\u001b[C\") return resolve(\"right\");\n if (s === \"\\u001b[D\") return resolve(\"left\");\n return resolve(s);\n });\n });\n}\n\n/**\n * Clears `lines` amount of lines.\n * @param lines Amount of lines to clear.\n */\nexport function clearLines(lines = 1) {\n for (let i = 0; i < lines; i++) process.stdout.write(\"\\x1b[2K\\x1b[1A\");\n process.stdout.write(\"\\x1b[2K\\r\");\n}\n\n/**\n * Moves the cursor up `n` times.\n * @param n The amount of steps to move.\n */\nexport function cursorUp(n = 1) {\n process.stdout.write(`\\x1b[${n}A`);\n}\n\n/**\n * Moves the cursor down `n` times.\n * @param n The amount of steps to move.\n */\nexport function cursorDown(n = 1) {\n process.stdout.write(`\\x1b[${n}B`);\n}\n"],"mappings":";;;;;;;;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AAQ,OAAO,MAAM,YAAY;;;;;;AAOnC,SAAgB,SAAS,IAAI,GAAG;AAC9B,SAAQ,OAAO,MAAM,QAAQ,EAAE,GAAG;;;;;;AAOpC,SAAgB,WAAW,IAAI,GAAG;AAChC,SAAQ,OAAO,MAAM,QAAQ,EAAE,GAAG"}
1
+ {"version":3,"file":"raw-DVT5lw11.mjs","names":[],"sources":["../src/prompt/raw.ts"],"sourcesContent":["import readline from \"node:readline\";\n\n/**\n * Reads a line from standard input.\n * @param message The message.\n * @param def Default value.\n * @param opts Options for reading a line.\n * @returns The line that was read.\n */\nexport function readLine(\n message = \"\",\n def?: string,\n opts?: { masked?: boolean; maskChar?: string; multiline?: boolean },\n): Promise<string> {\n return new Promise((resolve) => {\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: true,\n });\n\n if (opts?.masked) {\n const write = (rl as any)._writeToOutput.bind(rl);\n (rl as any)._writeToOutput = (str: string) => {\n if (str.match(/^\\x1b/)) return write(str);\n if (str.endsWith(\"\\n\") || str.endsWith(\"\\r\")) return write(str);\n const mask = opts.maskChar ?? \"*\";\n write(mask.repeat(str.length));\n };\n }\n\n rl.question(message, (answer: string) => {\n rl.close();\n resolve(answer || def || \"\");\n });\n });\n}\n\n/**\n * Reads a single key from stdin.\n * @returns The key that was read.\n */\nexport async function readKey(): Promise<string> {\n return new Promise((resolve) => {\n const stdin = process.stdin;\n stdin.setRawMode(true);\n stdin.resume();\n stdin.once(\"data\", (data: Buffer) => {\n const s = data.toString();\n stdin.setRawMode(false);\n stdin.pause();\n if (s === \"\\r\" || s === \"\\n\") return resolve(\"enter\");\n if (s === \" \") return resolve(\"space\");\n if (s === \"\\u001b[A\") return resolve(\"up\");\n if (s === \"\\u001b[B\") return resolve(\"down\");\n if (s === \"\\u001b[C\") return resolve(\"right\");\n if (s === \"\\u001b[D\") return resolve(\"left\");\n return resolve(s);\n });\n });\n}\n\n/**\n * Clears `lines` amount of lines.\n * @param lines Amount of lines to clear.\n */\nexport function clearLines(lines = 1) {\n for (let i = 0; i < lines; i++) process.stdout.write(\"\\x1b[2K\\x1b[1A\");\n process.stdout.write(\"\\x1b[2K\\r\");\n}\n\n/**\n * Moves the cursor up `n` times.\n * @param n The amount of steps to move.\n */\nexport function cursorUp(n = 1) {\n process.stdout.write(`\\x1b[${n}A`);\n}\n\n/**\n * Moves the cursor down `n` times.\n * @param n The amount of steps to move.\n */\nexport function cursorDown(n = 1) {\n process.stdout.write(`\\x1b[${n}B`);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AASA,SAAgB,SACd,UAAU,IACV,KACA,MACiB;AACjB,QAAO,IAAI,SAAS,YAAY;EAC9B,MAAM,KAAK,SAAS,gBAAgB;GAClC,OAAO,QAAQ;GACf,QAAQ,QAAQ;GAChB,UAAU;GACX,CAAC;AAEF,MAAI,MAAM,QAAQ;GAChB,MAAM,QAAS,GAAW,eAAe,KAAK,GAAG;AACjD,GAAC,GAAW,kBAAkB,QAAgB;AAC5C,QAAI,IAAI,MAAM,QAAQ,CAAE,QAAO,MAAM,IAAI;AACzC,QAAI,IAAI,SAAS,KAAK,IAAI,IAAI,SAAS,KAAK,CAAE,QAAO,MAAM,IAAI;AAE/D,WADa,KAAK,YAAY,KACnB,OAAO,IAAI,OAAO,CAAC;;;AAIlC,KAAG,SAAS,UAAU,WAAmB;AACvC,MAAG,OAAO;AACV,WAAQ,UAAU,OAAO,GAAG;IAC5B;GACF;;;;;;AAOJ,eAAsB,UAA2B;AAC/C,QAAO,IAAI,SAAS,YAAY;EAC9B,MAAM,QAAQ,QAAQ;AACtB,QAAM,WAAW,KAAK;AACtB,QAAM,QAAQ;AACd,QAAM,KAAK,SAAS,SAAiB;GACnC,MAAM,IAAI,KAAK,UAAU;AACzB,SAAM,WAAW,MAAM;AACvB,SAAM,OAAO;AACb,OAAI,MAAM,QAAQ,MAAM,KAAM,QAAO,QAAQ,QAAQ;AACrD,OAAI,MAAM,IAAK,QAAO,QAAQ,QAAQ;AACtC,OAAI,MAAM,SAAY,QAAO,QAAQ,KAAK;AAC1C,OAAI,MAAM,SAAY,QAAO,QAAQ,OAAO;AAC5C,OAAI,MAAM,SAAY,QAAO,QAAQ,QAAQ;AAC7C,OAAI,MAAM,SAAY,QAAO,QAAQ,OAAO;AAC5C,UAAO,QAAQ,EAAE;IACjB;GACF;;;;;;AAOJ,SAAgB,WAAW,QAAQ,GAAG;AACpC,MAAK,IAAI,IAAI,GAAG,IAAI,OAAO,IAAK,SAAQ,OAAO,MAAM,iBAAiB;AACtE,SAAQ,OAAO,MAAM,YAAY;;;;;;AAOnC,SAAgB,SAAS,IAAI,GAAG;AAC9B,SAAQ,OAAO,MAAM,QAAQ,EAAE,GAAG;;;;;;AAOpC,SAAgB,WAAW,IAAI,GAAG;AAChC,SAAQ,OAAO,MAAM,QAAQ,EAAE,GAAG"}
@@ -56,4 +56,4 @@ declare namespace StandardSchemaV1 {
56
56
  }
57
57
  //#endregion
58
58
  export { StandardSchemaV1 as t };
59
- //# sourceMappingURL=standard-schema-DXS-QnwX.d.mts.map
59
+ //# sourceMappingURL=standard-schema-D1sStgzy.d.mts.map
@@ -29,4 +29,4 @@ async function validate(entry, value) {
29
29
 
30
30
  //#endregion
31
31
  export { InputValidationError as n, validate as t };
32
- //# sourceMappingURL=standard-schema-DTuaYJjO.mjs.map
32
+ //# sourceMappingURL=standard-schema-WhGEzW0C.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"standard-schema-DTuaYJjO.mjs","names":[],"sources":["../src/input/error.ts","../src/input/standard-schema.ts"],"sourcesContent":["/**\n * Thrown when the command fails to validate an input.\n */\nexport class InputValidationError extends Error {\n /**\n * A list of messages.\n */\n messages: string[];\n\n /**\n * Creates a new input validation error.\n * @param messages The messages.\n */\n constructor(messages: string[]) {\n super(`Validation failed: ${messages.join(\", \")}`);\n this.messages = messages;\n }\n}\n","// * https://standardschema.dev * //\n\nimport { InputValidationError } from \"./error\";\n\n/** The Standard Schema interface. */\nexport interface StandardSchemaV1<Input = unknown, Output = Input> {\n /** The Standard Schema properties. */\n readonly \"~standard\": StandardSchemaV1.Props<Input, Output>;\n}\n\n// eslint-disable-next-line -- this is Standard Schema\nexport declare namespace StandardSchemaV1 {\n /** The Standard Schema properties interface. */\n export interface Props<Input = unknown, Output = Input> {\n /** The version number of the standard. */\n readonly version: 1;\n /** The vendor name of the schema library. */\n readonly vendor: string;\n /** Validates unknown input values. */\n readonly validate: (\n value: unknown,\n ) => Result<Output> | Promise<Result<Output>>;\n /** Inferred types associated with the schema. */\n readonly types?: Types<Input, Output> | undefined;\n }\n\n /** The result interface of the validate function. */\n export type Result<Output> = SuccessResult<Output> | FailureResult;\n\n /** The result interface if validation succeeds. */\n export interface SuccessResult<Output> {\n /** The typed output value. */\n readonly value: Output;\n /** The non-existent issues. */\n readonly issues?: undefined;\n }\n\n /** The result interface if validation fails. */\n export interface FailureResult {\n /** The issues of failed validation. */\n readonly issues: ReadonlyArray<Issue>;\n }\n\n /** The issue interface of the failure output. */\n export interface Issue {\n /** The error message of the issue. */\n readonly message: string;\n /** The path of the issue, if any. */\n readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;\n }\n\n /** The path segment interface of the issue. */\n export interface PathSegment {\n /** The key representing a path segment. */\n readonly key: PropertyKey;\n }\n\n /** The Standard Schema types interface. */\n export interface Types<Input = unknown, Output = Input> {\n /** The input type of the schema. */\n readonly input: Input;\n /** The output type of the schema. */\n readonly output: Output;\n }\n\n /** Infers the input type of a Standard Schema. */\n export type InferInput<Schema extends StandardSchemaV1> = NonNullable<\n Schema[\"~standard\"][\"types\"]\n >[\"input\"];\n\n /** Infers the output type of a Standard Schema. */\n export type InferOutput<Schema extends StandardSchemaV1> = NonNullable<\n Schema[\"~standard\"][\"types\"]\n >[\"output\"];\n}\n\n/**\n * Validates a value.\n * @param entry The Standard Schema validator.\n * @param value The value to validate.\n * @returns The validated value.\n */\nexport async function validate<T extends StandardSchemaV1<any, any>>(\n entry: T,\n value: any,\n): Promise<T extends StandardSchemaV1<any, infer Out> ? Out : never> {\n const result = await entry[\"~standard\"].validate(value);\n if (result.issues) {\n const msgs = result.issues.map((i) => i.message);\n throw new InputValidationError(msgs);\n }\n\n return result.value;\n}\n"],"mappings":";;;;AAGA,IAAa,uBAAb,cAA0C,MAAM;;;;;CAU9C,YAAY,UAAoB;AAC9B,QAAM,sBAAsB,SAAS,KAAK,KAAK,GAAG;AAClD,OAAK,WAAW;;;;;;;;;;;;ACmEpB,eAAsB,SACpB,OACA,OACmE;CACnE,MAAM,SAAS,MAAM,MAAM,aAAa,SAAS,MAAM;AACvD,KAAI,OAAO,OAET,OAAM,IAAI,qBADG,OAAO,OAAO,KAAK,MAAM,EAAE,QAAQ,CACZ;AAGtC,QAAO,OAAO"}
1
+ {"version":3,"file":"standard-schema-WhGEzW0C.mjs","names":[],"sources":["../src/input/error.ts","../src/input/standard-schema.ts"],"sourcesContent":["/**\n * Thrown when the command fails to validate an input.\n */\nexport class InputValidationError extends Error {\n /**\n * A list of messages.\n */\n messages: string[];\n\n /**\n * Creates a new input validation error.\n * @param messages The messages.\n */\n constructor(messages: string[]) {\n super(`Validation failed: ${messages.join(\", \")}`);\n this.messages = messages;\n }\n}\n","// * https://standardschema.dev * //\n\nimport { InputValidationError } from \"./error\";\n\n/** The Standard Schema interface. */\nexport interface StandardSchemaV1<Input = unknown, Output = Input> {\n /** The Standard Schema properties. */\n readonly \"~standard\": StandardSchemaV1.Props<Input, Output>;\n}\n\n// eslint-disable-next-line -- this is Standard Schema\nexport declare namespace StandardSchemaV1 {\n /** The Standard Schema properties interface. */\n export interface Props<Input = unknown, Output = Input> {\n /** The version number of the standard. */\n readonly version: 1;\n /** The vendor name of the schema library. */\n readonly vendor: string;\n /** Validates unknown input values. */\n readonly validate: (\n value: unknown,\n ) => Result<Output> | Promise<Result<Output>>;\n /** Inferred types associated with the schema. */\n readonly types?: Types<Input, Output> | undefined;\n }\n\n /** The result interface of the validate function. */\n export type Result<Output> = SuccessResult<Output> | FailureResult;\n\n /** The result interface if validation succeeds. */\n export interface SuccessResult<Output> {\n /** The typed output value. */\n readonly value: Output;\n /** The non-existent issues. */\n readonly issues?: undefined;\n }\n\n /** The result interface if validation fails. */\n export interface FailureResult {\n /** The issues of failed validation. */\n readonly issues: ReadonlyArray<Issue>;\n }\n\n /** The issue interface of the failure output. */\n export interface Issue {\n /** The error message of the issue. */\n readonly message: string;\n /** The path of the issue, if any. */\n readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;\n }\n\n /** The path segment interface of the issue. */\n export interface PathSegment {\n /** The key representing a path segment. */\n readonly key: PropertyKey;\n }\n\n /** The Standard Schema types interface. */\n export interface Types<Input = unknown, Output = Input> {\n /** The input type of the schema. */\n readonly input: Input;\n /** The output type of the schema. */\n readonly output: Output;\n }\n\n /** Infers the input type of a Standard Schema. */\n export type InferInput<Schema extends StandardSchemaV1> = NonNullable<\n Schema[\"~standard\"][\"types\"]\n >[\"input\"];\n\n /** Infers the output type of a Standard Schema. */\n export type InferOutput<Schema extends StandardSchemaV1> = NonNullable<\n Schema[\"~standard\"][\"types\"]\n >[\"output\"];\n}\n\n/**\n * Validates a value.\n * @param entry The Standard Schema validator.\n * @param value The value to validate.\n * @returns The validated value.\n */\nexport async function validate<T extends StandardSchemaV1<any, any>>(\n entry: T,\n value: any,\n): Promise<T extends StandardSchemaV1<any, infer Out> ? Out : never> {\n const result = await entry[\"~standard\"].validate(value);\n if (result.issues) {\n const msgs = result.issues.map((i) => i.message);\n throw new InputValidationError(msgs);\n }\n\n return result.value;\n}\n"],"mappings":";;;;AAGA,IAAa,uBAAb,cAA0C,MAAM;;;;;CAU9C,YAAY,UAAoB;AAC9B,QAAM,sBAAsB,SAAS,KAAK,KAAK,GAAG;AAClD,OAAK,WAAW;;;;;;;;;;;;ACmEpB,eAAsB,SACpB,OACA,OACmE;CACnE,MAAM,SAAS,MAAM,MAAM,aAAa,SAAS,MAAM;AACvD,KAAI,OAAO,OAET,OAAM,IAAI,qBADG,OAAO,OAAO,KAAK,MAAM,EAAE,QAAQ,CACZ;AAGtC,QAAO,OAAO"}
@@ -0,0 +1,68 @@
1
+ import { B as underline, C as cyan, D as green, E as gray, F as red, U as yellow, b as bold, j as italic } from "./color-s-N9yh90.mjs";
2
+
3
+ //#region src/utils.ts
4
+ /**
5
+ * Checks if a value is a plain object.
6
+ * @param value The value to check.
7
+ * @returns If the value is a plain object.
8
+ */
9
+ function isPlainObject(value) {
10
+ return value !== null && typeof value === "object" && Object.getPrototypeOf(value) === Object.prototype;
11
+ }
12
+ /**
13
+ * Merges two objects deeply.
14
+ * @param source The source object.
15
+ * @param target The target object.
16
+ * @returns The merged objects.
17
+ */
18
+ function merge(source, target) {
19
+ if (Array.isArray(source) && Array.isArray(target)) return target;
20
+ if (isPlainObject(source) && isPlainObject(target)) {
21
+ const result = {};
22
+ new Set([...Object.keys(source), ...Object.keys(target)]).forEach((key) => {
23
+ const sourceVal = source[key];
24
+ const targetVal = target[key];
25
+ if (sourceVal !== void 0 && targetVal !== void 0) result[key] = merge(sourceVal, targetVal);
26
+ else if (targetVal !== void 0) result[key] = targetVal;
27
+ else result[key] = sourceVal;
28
+ });
29
+ return result;
30
+ }
31
+ return target;
32
+ }
33
+
34
+ //#endregion
35
+ //#region src/theme.ts
36
+ /**
37
+ * The default theme.
38
+ */
39
+ const DEFAULT_THEME = {
40
+ primary: cyan,
41
+ secondary: gray,
42
+ success: green,
43
+ warning: yellow,
44
+ error: red,
45
+ symbols: {
46
+ success: "✔",
47
+ error: "✖",
48
+ fatal: "✖",
49
+ warning: "⚠"
50
+ },
51
+ styles: {
52
+ bold,
53
+ italic,
54
+ underline
55
+ }
56
+ };
57
+ /**
58
+ * Defines a theme.
59
+ * @param theme The (partial) theme.
60
+ * @returns The theme, merged with the default theme.
61
+ */
62
+ function defineTheme(theme) {
63
+ return merge(DEFAULT_THEME, theme);
64
+ }
65
+
66
+ //#endregion
67
+ export { defineTheme as n, merge as r, DEFAULT_THEME as t };
68
+ //# sourceMappingURL=theme-Chg3mOhZ.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme-Chg3mOhZ.mjs","names":["result: any","DEFAULT_THEME: Theme","color.cyan","color.gray","color.green","color.yellow","color.red","color.bold","color.italic","color.underline"],"sources":["../src/utils.ts","../src/theme.ts"],"sourcesContent":["/**\n * Deep `Partial<T>`.\n */\nexport type DeepPartial<T> = {\n [P in keyof T]?: DeepPartial<T[P]>;\n};\n\n/**\n * All TypeScript primitive types.\n */\ntype Primitive = string | number | boolean | symbol | null | undefined | bigint;\n\n/**\n * A plain TypeScript object.\n */\ntype PlainObject = Record<string | number | symbol, unknown>;\n\n/**\n * Merges two objects deeply.\n */\nexport type DeepMerge<T, U> = U extends Primitive\n ? T\n : T extends Primitive\n ? T\n : U extends readonly (infer TItem)[]\n ? T extends readonly (infer UItem)[]\n ? Array<DeepMerge<TItem, UItem>>\n : T\n : U extends PlainObject\n ? T extends PlainObject\n ? {\n [K in keyof U | keyof T]: K extends keyof T\n ? K extends keyof U\n ? DeepMerge<U[K], T[K]>\n : T[K]\n : K extends keyof U\n ? U[K]\n : never;\n }\n : T\n : T;\n\n/**\n * Checks if a value is a plain object.\n * @param value The value to check.\n * @returns If the value is a plain object.\n */\nfunction isPlainObject(value: any): value is Record<string, any> {\n return (\n value !== null &&\n typeof value === \"object\" &&\n Object.getPrototypeOf(value) === Object.prototype\n );\n}\n\n/**\n * Merges two objects deeply.\n * @param source The source object.\n * @param target The target object.\n * @returns The merged objects.\n */\nexport function merge<T, U>(source: T, target: U): DeepMerge<T, U> {\n if (Array.isArray(source) && Array.isArray(target)) {\n // Replace arrays\n return target as any;\n }\n\n if (isPlainObject(source) && isPlainObject(target)) {\n const result: any = {};\n const keys = new Set([...Object.keys(source), ...Object.keys(target)]);\n keys.forEach((key) => {\n const sourceVal = (source as any)[key];\n const targetVal = (target as any)[key];\n\n if (sourceVal !== undefined && targetVal !== undefined) {\n result[key] = merge(sourceVal, targetVal);\n } else if (targetVal !== undefined) {\n result[key] = targetVal;\n } else {\n result[key] = sourceVal;\n }\n });\n return result;\n }\n\n // For class instances or primitives, always use target\n return target as any;\n}\n","import { merge, type DeepPartial } from \"@/utils\";\nimport * as color from \"@/color\";\n\n/**\n * A theme.\n */\nexport interface Theme {\n /**\n * Wraps a string in a background ANSI code.\n * @param a The string to wrap.\n */\n background?(a: string): string;\n /**\n * Wraps a string in a foreground ANSI code.\n * @param a The string to wrap.\n */\n foreground?(a: string): string;\n /**\n * Wraps a string in a primary ANSI code.\n * @param a The string to wrap.\n */\n primary(a: string): string;\n /**\n * Wraps a string in a secondary ANSI code.\n * @param a The string to wrap.\n */\n secondary(a: string): string;\n /**\n * Wraps a string in a accent ANSI code.\n * @param a The string to wrap.\n */\n accent?(a: string): string;\n\n /**\n * Wraps a string in a success ANSI code.\n * @param a The string to wrap.\n */\n success(a: string): string;\n /**\n * Wraps a string in a warning ANSI code.\n * @param a The string to wrap.\n */\n warning(a: string): string;\n /**\n * Wraps a string in a error ANSI code.\n * @param a The string to wrap.\n */\n error(a: string): string;\n /**\n * Wraps a string in a info ANSI code.\n * @param a The string to wrap.\n */\n info?(a: string): string;\n\n /**\n * Set of symbols for logging.\n */\n symbols?: {\n /**\n * Success message symbol.\n */\n success: string;\n /**\n * Error message symbol.\n */\n error: string;\n /**\n * Fatal error message symbol.\n */\n fatal: string;\n /**\n * Warning message symbol.\n */\n warning: string;\n /**\n * Information message symbol.\n */\n info?: string;\n };\n\n /**\n * Optional styles.\n */\n styles?: {\n /**\n * Wraps a string in a bold ANSI code.\n * @param a The string to wrap.\n */\n bold?(a: string): string;\n /**\n * Wraps a string in an italic ANSI code.\n * @param a The string to wrap.\n */\n italic?(a: string): string;\n /**\n * Wraps a string in an underline ANSI code.\n * @param a The string to wrap.\n */\n underline?(a: string): string;\n };\n}\n\n/**\n * The default theme.\n */\nexport const DEFAULT_THEME: Theme = {\n primary: color.cyan,\n secondary: color.gray,\n\n success: color.green,\n warning: color.yellow,\n error: color.red,\n\n symbols: {\n success: \"✔\",\n error: \"✖\",\n fatal: \"✖\",\n warning: \"⚠\",\n },\n\n styles: {\n bold: color.bold,\n italic: color.italic,\n underline: color.underline,\n },\n};\n\n/**\n * Defines a theme.\n * @param theme The (partial) theme.\n * @returns The theme, merged with the default theme.\n */\nexport function defineTheme(theme: DeepPartial<Theme>): Theme {\n return merge(DEFAULT_THEME, theme);\n}\n"],"mappings":";;;;;;;;AA+CA,SAAS,cAAc,OAA0C;AAC/D,QACE,UAAU,QACV,OAAO,UAAU,YACjB,OAAO,eAAe,MAAM,KAAK,OAAO;;;;;;;;AAU5C,SAAgB,MAAY,QAAW,QAA4B;AACjE,KAAI,MAAM,QAAQ,OAAO,IAAI,MAAM,QAAQ,OAAO,CAEhD,QAAO;AAGT,KAAI,cAAc,OAAO,IAAI,cAAc,OAAO,EAAE;EAClD,MAAMA,SAAc,EAAE;AAEtB,EADa,IAAI,IAAI,CAAC,GAAG,OAAO,KAAK,OAAO,EAAE,GAAG,OAAO,KAAK,OAAO,CAAC,CAAC,CACjE,SAAS,QAAQ;GACpB,MAAM,YAAa,OAAe;GAClC,MAAM,YAAa,OAAe;AAElC,OAAI,cAAc,UAAa,cAAc,OAC3C,QAAO,OAAO,MAAM,WAAW,UAAU;YAChC,cAAc,OACvB,QAAO,OAAO;OAEd,QAAO,OAAO;IAEhB;AACF,SAAO;;AAIT,QAAO;;;;;;;;ACmBT,MAAaC,gBAAuB;CAClC,SAASC;CACT,WAAWC;CAEX,SAASC;CACT,SAASC;CACT,OAAOC;CAEP,SAAS;EACP,SAAS;EACT,OAAO;EACP,OAAO;EACP,SAAS;EACV;CAED,QAAQ;EACAC;EACEC;EACGC;EACZ;CACF;;;;;;AAOD,SAAgB,YAAY,OAAkC;AAC5D,QAAO,MAAM,eAAe,MAAM"}
@@ -0,0 +1,115 @@
1
+ //#region src/utils.d.ts
2
+ /**
3
+ * Deep `Partial<T>`.
4
+ */
5
+ type DeepPartial<T> = { [P in keyof T]?: DeepPartial<T[P]> };
6
+ //#endregion
7
+ //#region src/theme.d.ts
8
+ /**
9
+ * A theme.
10
+ */
11
+ interface Theme {
12
+ /**
13
+ * Wraps a string in a background ANSI code.
14
+ * @param a The string to wrap.
15
+ */
16
+ background?(a: string): string;
17
+ /**
18
+ * Wraps a string in a foreground ANSI code.
19
+ * @param a The string to wrap.
20
+ */
21
+ foreground?(a: string): string;
22
+ /**
23
+ * Wraps a string in a primary ANSI code.
24
+ * @param a The string to wrap.
25
+ */
26
+ primary(a: string): string;
27
+ /**
28
+ * Wraps a string in a secondary ANSI code.
29
+ * @param a The string to wrap.
30
+ */
31
+ secondary(a: string): string;
32
+ /**
33
+ * Wraps a string in a accent ANSI code.
34
+ * @param a The string to wrap.
35
+ */
36
+ accent?(a: string): string;
37
+ /**
38
+ * Wraps a string in a success ANSI code.
39
+ * @param a The string to wrap.
40
+ */
41
+ success(a: string): string;
42
+ /**
43
+ * Wraps a string in a warning ANSI code.
44
+ * @param a The string to wrap.
45
+ */
46
+ warning(a: string): string;
47
+ /**
48
+ * Wraps a string in a error ANSI code.
49
+ * @param a The string to wrap.
50
+ */
51
+ error(a: string): string;
52
+ /**
53
+ * Wraps a string in a info ANSI code.
54
+ * @param a The string to wrap.
55
+ */
56
+ info?(a: string): string;
57
+ /**
58
+ * Set of symbols for logging.
59
+ */
60
+ symbols?: {
61
+ /**
62
+ * Success message symbol.
63
+ */
64
+ success: string;
65
+ /**
66
+ * Error message symbol.
67
+ */
68
+ error: string;
69
+ /**
70
+ * Fatal error message symbol.
71
+ */
72
+ fatal: string;
73
+ /**
74
+ * Warning message symbol.
75
+ */
76
+ warning: string;
77
+ /**
78
+ * Information message symbol.
79
+ */
80
+ info?: string;
81
+ };
82
+ /**
83
+ * Optional styles.
84
+ */
85
+ styles?: {
86
+ /**
87
+ * Wraps a string in a bold ANSI code.
88
+ * @param a The string to wrap.
89
+ */
90
+ bold?(a: string): string;
91
+ /**
92
+ * Wraps a string in an italic ANSI code.
93
+ * @param a The string to wrap.
94
+ */
95
+ italic?(a: string): string;
96
+ /**
97
+ * Wraps a string in an underline ANSI code.
98
+ * @param a The string to wrap.
99
+ */
100
+ underline?(a: string): string;
101
+ };
102
+ }
103
+ /**
104
+ * The default theme.
105
+ */
106
+ declare const DEFAULT_THEME: Theme;
107
+ /**
108
+ * Defines a theme.
109
+ * @param theme The (partial) theme.
110
+ * @returns The theme, merged with the default theme.
111
+ */
112
+ declare function defineTheme(theme: DeepPartial<Theme>): Theme;
113
+ //#endregion
114
+ export { DeepPartial as i, Theme as n, defineTheme as r, DEFAULT_THEME as t };
115
+ //# sourceMappingURL=theme-EERPMtQU.d.mts.map
@@ -0,0 +1,2 @@
1
+ import { n as Theme, r as defineTheme, t as DEFAULT_THEME } from "./theme-EERPMtQU.mjs";
2
+ export { DEFAULT_THEME, Theme, defineTheme };
package/dist/theme.mjs ADDED
@@ -0,0 +1,4 @@
1
+ import "./color-s-N9yh90.mjs";
2
+ import { n as defineTheme, t as DEFAULT_THEME } from "./theme-Chg3mOhZ.mjs";
3
+
4
+ export { DEFAULT_THEME, defineTheme };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "convoker",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "A simple, type safe CLI framework for TypeScript.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -17,6 +17,10 @@
17
17
  "types": "./dist/command/index.d.mts",
18
18
  "import": "./dist/command/index.mjs"
19
19
  },
20
+ "./theme": {
21
+ "types": "./dist/theme.d.mts",
22
+ "import": "./dist/theme.mjs"
23
+ },
20
24
  "./input": {
21
25
  "types": "./dist/input/index.d.mts",
22
26
  "import": "./dist/input/index.mjs"