hacksh 0.18.0 → 0.19.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 +32 -1
- package/dist/{command-Czf4qXhe.d.ts → command-D12G9f2b.d.ts} +13 -4
- package/dist/index.d.ts +2 -2
- package/dist/index.js +73 -1
- package/dist/index.js.map +1 -1
- package/dist/{pretty-BjzGnVLM.js → pretty-BykhfUqM.js} +37 -6
- package/dist/pretty-BykhfUqM.js.map +1 -0
- package/dist/printer-api.d.ts +2 -2
- package/dist/printer-api.js +1 -1
- package/package.json +1 -1
- package/dist/pretty-BjzGnVLM.js.map +0 -1
package/README.md
CHANGED
|
@@ -606,7 +606,7 @@ produces `input-error` with the original error as `cause`.
|
|
|
606
606
|
Explicit option types take the whole item type, for example
|
|
607
607
|
`SelectOptions<{ value: "staging" | "production"; priority: number }>`.
|
|
608
608
|
|
|
609
|
-
|
|
609
|
+
Input prompts are allowed only when the resolved mode is interactive: pretty output outside CI with TTY
|
|
610
610
|
stdin and stdout. JSON, CI, and non-TTY invocations throw `HackshPromptError` immediately even if a
|
|
611
611
|
default is available. Its `reason` and `prompt` fields identify why input failed and the prompt's
|
|
612
612
|
`kind`, `message`, and select/autocomplete `choices`. Reasons distinguish `non-interactive`, `cancelled`,
|
|
@@ -626,6 +626,37 @@ Physical rows are calculated from explicit newlines, ANSI-free Unicode display w
|
|
|
626
626
|
`stdout.columns`, including terminal wrapping. When a custom output writer does not expose a
|
|
627
627
|
positive `columns` value, the renderer conservatively counts explicit lines only.
|
|
628
628
|
|
|
629
|
+
### Waiting for work
|
|
630
|
+
|
|
631
|
+
Use `prompt.wait` to display a spinner in the left rail while a callback runs:
|
|
632
|
+
|
|
633
|
+
```ts
|
|
634
|
+
const data = await prompt.wait(() => fetchData(), { message: "Fetching data" });
|
|
635
|
+
```
|
|
636
|
+
|
|
637
|
+
The message is optional and defaults to `待機中`. The callback may return a value or a
|
|
638
|
+
promise; `wait` infers and returns its result, and propagates its thrown error unchanged.
|
|
639
|
+
The spinner animates only in interactive pretty mode. Non-TTY and CI invocations still
|
|
640
|
+
run the callback: pretty output prints a static message, while JSON emits `active` and
|
|
641
|
+
`closed` prompt events with `kind: "wait"`, without animation frames.
|
|
642
|
+
|
|
643
|
+
Logger and output events remain visible during the wait. On success or failure, the
|
|
644
|
+
animated row is replaced by the plain rail; `wait` does not print a success message.
|
|
645
|
+
With `unicode: false`, the spinner and rail use ASCII. Only one prompt or wait may be
|
|
646
|
+
active per invocation. Nested waits, input prompts, and terminal-owning external
|
|
647
|
+
commands are rejected with `overlapping`; captured `exec` calls remain available.
|
|
648
|
+
|
|
649
|
+
Wait does not read stdin or enable raw mode. An invocation abort stops the animation
|
|
650
|
+
and closes the display, but still awaits the callback and retains the terminal lock
|
|
651
|
+
until it settles. Pass the command context's `signal` to cancellable work. If the
|
|
652
|
+
callback rejects, its error takes precedence; otherwise an aborted wait rejects with
|
|
653
|
+
`HackshPromptError` (`aborted`). Printer failures similarly close the display and
|
|
654
|
+
reject with `printer-error` once the callback settles.
|
|
655
|
+
|
|
656
|
+
Custom printers receive `WaitPromptState` through ordinary prompt events. `frame` is
|
|
657
|
+
present for animated waits (including their closing event), and absent for static
|
|
658
|
+
waits.
|
|
659
|
+
|
|
629
660
|
### Cancellation and exit status
|
|
630
661
|
|
|
631
662
|
Every `run` context has a `signal`, an `AbortSignal` for that invocation. `exec` calls and prompts
|
|
@@ -91,7 +91,7 @@ declare class HackshValidationError extends HackshUsageError {
|
|
|
91
91
|
readonly issues: ReadonlyArray<HackshIssue>;
|
|
92
92
|
constructor(command: AnyCommandDef, issues: ReadonlyArray<HackshIssue>);
|
|
93
93
|
}
|
|
94
|
-
type PromptKind = "select" | "autocomplete" | "confirm" | "text";
|
|
94
|
+
type PromptKind = "select" | "autocomplete" | "confirm" | "text" | "wait";
|
|
95
95
|
type HackshPromptErrorReason = "non-interactive" | "cancelled" | "aborted" | "eof" | "overlapping" | "invalid-options" | "input-error" | "printer-error";
|
|
96
96
|
interface PromptErrorDetails {
|
|
97
97
|
kind: PromptKind;
|
|
@@ -285,7 +285,12 @@ interface AutocompletePromptState extends PromptStateBase {
|
|
|
285
285
|
choices: readonly PromptChoiceState[];
|
|
286
286
|
value?: string;
|
|
287
287
|
}
|
|
288
|
-
|
|
288
|
+
/** Waiting for callback completion; frame is present only for animated output. */
|
|
289
|
+
interface WaitPromptState extends PromptStateBase {
|
|
290
|
+
kind: "wait";
|
|
291
|
+
frame?: number;
|
|
292
|
+
}
|
|
293
|
+
type PromptState = SelectPromptState | ConfirmPromptState | TextPromptState | AutocompletePromptState | WaitPromptState;
|
|
289
294
|
interface PromptPrintEvent {
|
|
290
295
|
type: "prompt";
|
|
291
296
|
prompt: PromptState;
|
|
@@ -380,11 +385,15 @@ interface TextOptions {
|
|
|
380
385
|
placeholder?: string;
|
|
381
386
|
validate?(value: string): string | undefined;
|
|
382
387
|
}
|
|
388
|
+
interface WaitOptions {
|
|
389
|
+
message?: string;
|
|
390
|
+
}
|
|
383
391
|
interface Prompter {
|
|
384
392
|
select<const TItem extends SelectOption<string>>(options: SelectOptions<TItem>): Promise<TItem["value"]>;
|
|
385
393
|
autocomplete<const TItem extends SelectOption<string>>(options: AutocompleteOptions<TItem>): Promise<TItem["value"]>;
|
|
386
394
|
confirm(options: ConfirmOptions): Promise<boolean>;
|
|
387
395
|
text(options: TextOptions): Promise<string>;
|
|
396
|
+
wait<T>(work: () => T | Promise<T>, options?: WaitOptions): Promise<T>;
|
|
388
397
|
}
|
|
389
398
|
//#endregion
|
|
390
399
|
//#region src/schema.d.ts
|
|
@@ -431,5 +440,5 @@ interface CommandDef<S extends ArgsSchema = EmptyArgs, R = unknown, Children ext
|
|
|
431
440
|
type AnyCommandDef = CommandDef<ArgsSchema>;
|
|
432
441
|
declare function defineCommand<S extends ArgsSchema = EmptyArgs, R = never, Children extends Record<string, AnyCommandDef> = {}>(def: CommandDef<S, R, Children>): NoInfer<CommandDef<S, R, Children>>;
|
|
433
442
|
//#endregion
|
|
434
|
-
export {
|
|
435
|
-
//# sourceMappingURL=command-
|
|
443
|
+
export { LogProperties as $, PromptState as A, WaitPromptState as B, OutputPrintEvent as C, ExecSuccess as Ct, Printer as D, PrintStream as E, TerminalInput as F, UsageCommandSummary as G, resolveOutputMode as H, TerminalOutput as I, renderUsage as J, UsageOptionSummary as K, TextPromptState as L, ResolveOutputModeOptions as M, SelectPromptState as N, PromptChoiceState as O, StreamColors as P, LogLevel as Q, UsagePrintEvent as R, OutputPreference as S, ExecSkipped as St, PrintEvent as T, ShowUsageOptions as U, createJsonPrinter as V, UsageArgumentSummary as W, summarizeUsage as X, showUsage as Y, LogKind as Z, ExecPrintEvent as _, ExecFailure as _t, ArgsSchema as a, HackshExecError as at, OutputFormat as b, ExecResult as bt, Prompter as c, HackshPromptError as ct, TextOptions as d, HackshValidationError as dt, LogRecord as et, WaitOptions as f, PromptErrorDetails as ft, ErrorPrintEvent as g, ExecCommand as gt, ConfirmPromptState as h, Exec as ht, defineCommand as i, HackshErrorSummary as it, PromptStatus as j, PromptPrintEvent as k, SelectOption as l, HackshPromptErrorReason as lt, AutocompletePromptState as m, ValidationIssueSummary as mt, CommandContext as n, HackshError as nt, AutocompleteOptions as o, HackshExitError as ot, Output as p, PromptKind as pt, UsageSummary as q, CommandDef as r, HackshErrorKind as rt, ConfirmOptions as s, HackshIssue as st, AnyCommandDef as t, Logger as tt, SelectOptions as u, HackshUsageError as ut, JsonPrinterOptions as v, ExecFailureReason as vt, OutputWriter as w, OutputMode as x, ExecReturn as xt, LogPrintEvent as y, ExecOptions as yt, VersionPrintEvent as z };
|
|
444
|
+
//# sourceMappingURL=command-D12G9f2b.d.ts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Ct as ExecSuccess, D as Printer, F as TerminalInput, I as TerminalOutput, J as renderUsage, S as OutputPreference, St as ExecSkipped, U as ShowUsageOptions, X as summarizeUsage, Y as showUsage, _t as ExecFailure, a as ArgsSchema, at as HackshExecError, bt as ExecResult, c as Prompter, ct as HackshPromptError, d as TextOptions, dt as HackshValidationError, f as WaitOptions, ft as PromptErrorDetails, gt as ExecCommand, ht as Exec, i as defineCommand, l as SelectOption, lt as HackshPromptErrorReason, n as CommandContext, nt as HackshError, o as AutocompleteOptions, ot as HackshExitError, p as Output, pt as PromptKind, r as CommandDef, s as ConfirmOptions, st as HackshIssue, t as AnyCommandDef, tt as Logger, u as SelectOptions, ut as HackshUsageError, vt as ExecFailureReason, xt as ExecReturn, yt as ExecOptions } from "./command-D12G9f2b.js";
|
|
2
2
|
import { output } from "zod/v4/core";
|
|
3
3
|
//#region src/parser.d.ts
|
|
4
4
|
/**
|
|
@@ -39,5 +39,5 @@ interface RunMainOptions extends OutputOptions {
|
|
|
39
39
|
}
|
|
40
40
|
declare function runMain<S extends ArgsSchema>(command: CommandDef<S>, options?: RunMainOptions): Promise<void>;
|
|
41
41
|
//#endregion
|
|
42
|
-
export { type AutocompleteOptions, type CommandContext, type CommandDef, type ConfirmOptions, type Exec, type ExecCommand, type ExecFailure, type ExecFailureReason, type ExecOptions, type ExecResult, type ExecReturn, type ExecSkipped, type ExecSuccess, HackshError, HackshExecError, HackshExitError, type HackshIssue, HackshPromptError, type HackshPromptErrorReason, HackshUsageError, HackshValidationError, type Logger, type Output, type OutputOptions, type PromptErrorDetails, type PromptKind, type Prompter, type RunCommandOptions, type RunMainOptions, type SelectOption, type SelectOptions, type ShowUsageOptions, type TextOptions, defineCommand, parseArgs, renderUsage, runCommand, runMain, showUsage, summarizeUsage };
|
|
42
|
+
export { type AutocompleteOptions, type CommandContext, type CommandDef, type ConfirmOptions, type Exec, type ExecCommand, type ExecFailure, type ExecFailureReason, type ExecOptions, type ExecResult, type ExecReturn, type ExecSkipped, type ExecSuccess, HackshError, HackshExecError, HackshExitError, type HackshIssue, HackshPromptError, type HackshPromptErrorReason, HackshUsageError, HackshValidationError, type Logger, type Output, type OutputOptions, type PromptErrorDetails, type PromptKind, type Prompter, type RunCommandOptions, type RunMainOptions, type SelectOption, type SelectOptions, type ShowUsageOptions, type TextOptions, type WaitOptions, defineCommand, parseArgs, renderUsage, runCommand, runMain, showUsage, summarizeUsage };
|
|
43
43
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as createExec, c as HackshExitError, d as HackshValidationError, f as summarizeError, i as resolveOutputMode, l as HackshPromptError, n as createJsonPrinter, o as HackshError, p as summarizeErrors, r as createPrintQueue, s as HackshExecError, t as createPrettyPrinter, u as HackshUsageError } from "./pretty-
|
|
1
|
+
import { a as createExec, c as HackshExitError, d as HackshValidationError, f as summarizeError, i as resolveOutputMode, l as HackshPromptError, n as createJsonPrinter, o as HackshError, p as summarizeErrors, r as createPrintQueue, s as HackshExecError, t as createPrettyPrinter, u as HackshUsageError } from "./pretty-BykhfUqM.js";
|
|
2
2
|
import { globalRegistry, safeParseAsync } from "zod/v4/core";
|
|
3
3
|
import { parseArgs as parseArgs$1 } from "node:util";
|
|
4
4
|
import { readFile, realpath } from "node:fs/promises";
|
|
@@ -834,6 +834,78 @@ var PromptController = class {
|
|
|
834
834
|
this.#terminal.release();
|
|
835
835
|
}
|
|
836
836
|
}
|
|
837
|
+
async wait(work, options) {
|
|
838
|
+
const message = options?.message === void 0 ? "待機中" : options.message;
|
|
839
|
+
const prompt = details$1("wait", message);
|
|
840
|
+
validateMessage("wait", message);
|
|
841
|
+
if (typeof work !== "function") throw promptError("invalid-options", prompt, "Wait work must be a function");
|
|
842
|
+
if (this.#signal.aborted) throw promptError("aborted", prompt, "Prompt aborted", this.#signal.reason);
|
|
843
|
+
if (!this.#terminal.acquire("prompt")) throw promptError("overlapping", prompt, this.#terminal.owner === "exec" ? "A command is using the terminal" : "Another prompt is already active");
|
|
844
|
+
let frame = 0;
|
|
845
|
+
let stopped = false;
|
|
846
|
+
let timer;
|
|
847
|
+
let rendering = Promise.resolve();
|
|
848
|
+
let closing;
|
|
849
|
+
let failure;
|
|
850
|
+
const state = (status) => ({
|
|
851
|
+
kind: "wait",
|
|
852
|
+
message,
|
|
853
|
+
status,
|
|
854
|
+
...this.#interactive ? { frame } : {}
|
|
855
|
+
});
|
|
856
|
+
const recordFailure = (error) => {
|
|
857
|
+
failure ??= error;
|
|
858
|
+
};
|
|
859
|
+
const close = () => {
|
|
860
|
+
stopped = true;
|
|
861
|
+
clearTimeout(timer);
|
|
862
|
+
timer = void 0;
|
|
863
|
+
closing ??= rendering.then(() => this.#print(state("closed"), prompt)).catch(recordFailure);
|
|
864
|
+
return closing;
|
|
865
|
+
};
|
|
866
|
+
const tick = () => {
|
|
867
|
+
timer = void 0;
|
|
868
|
+
frame += 1;
|
|
869
|
+
rendering = rendering.then(() => this.#print(state("active"), prompt)).then(() => {
|
|
870
|
+
if (!stopped) timer = setTimeout(tick, 80);
|
|
871
|
+
}, (error) => {
|
|
872
|
+
recordFailure(error);
|
|
873
|
+
close();
|
|
874
|
+
});
|
|
875
|
+
};
|
|
876
|
+
const onAbort = () => {
|
|
877
|
+
recordFailure(promptError("aborted", prompt, "Prompt aborted", this.#signal.reason));
|
|
878
|
+
close();
|
|
879
|
+
};
|
|
880
|
+
let outcome;
|
|
881
|
+
try {
|
|
882
|
+
rendering = rendering.then(() => this.#print(state("active"), prompt)).catch(recordFailure);
|
|
883
|
+
this.#signal.addEventListener("abort", onAbort, { once: true });
|
|
884
|
+
if (this.#signal.aborted) onAbort();
|
|
885
|
+
await rendering;
|
|
886
|
+
if (failure !== void 0) throw failure;
|
|
887
|
+
if (this.#interactive) timer = setTimeout(tick, 80);
|
|
888
|
+
outcome = {
|
|
889
|
+
ok: true,
|
|
890
|
+
value: await work()
|
|
891
|
+
};
|
|
892
|
+
} catch (error) {
|
|
893
|
+
outcome = {
|
|
894
|
+
ok: false,
|
|
895
|
+
error
|
|
896
|
+
};
|
|
897
|
+
} finally {
|
|
898
|
+
try {
|
|
899
|
+
await close();
|
|
900
|
+
} finally {
|
|
901
|
+
this.#signal.removeEventListener("abort", onAbort);
|
|
902
|
+
this.#terminal.release();
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
if (!outcome.ok) throw outcome.error;
|
|
906
|
+
if (failure !== void 0) throw failure;
|
|
907
|
+
return outcome.value;
|
|
908
|
+
}
|
|
837
909
|
async select(options) {
|
|
838
910
|
const prompt = validateChoices("select", options);
|
|
839
911
|
const choices = sortedChoices(options, prompt);
|