toolcraft 0.0.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.
- package/README.md +91 -0
- package/dist/cli.compile-check.d.ts +1 -0
- package/dist/cli.compile-check.js +26 -0
- package/dist/cli.d.ts +12 -0
- package/dist/cli.js +1312 -0
- package/dist/index.compile-check.d.ts +1 -0
- package/dist/index.compile-check.js +50 -0
- package/dist/index.d.ts +164 -0
- package/dist/index.js +366 -0
- package/dist/mcp.compile-check.d.ts +1 -0
- package/dist/mcp.compile-check.js +26 -0
- package/dist/mcp.d.ts +31 -0
- package/dist/mcp.js +354 -0
- package/dist/number-schema.d.ts +3 -0
- package/dist/number-schema.js +8 -0
- package/dist/renderer.d.ts +5 -0
- package/dist/renderer.js +148 -0
- package/dist/schema-scope.d.ts +4 -0
- package/dist/schema-scope.js +34 -0
- package/dist/sdk.compile-check.d.ts +1 -0
- package/dist/sdk.compile-check.js +79 -0
- package/dist/sdk.d.ts +63 -0
- package/dist/sdk.js +218 -0
- package/node_modules/@poe-code/design-system/dist/acp/components.d.ts +11 -0
- package/node_modules/@poe-code/design-system/dist/acp/components.js +121 -0
- package/node_modules/@poe-code/design-system/dist/acp/index.d.ts +3 -0
- package/node_modules/@poe-code/design-system/dist/acp/index.js +2 -0
- package/node_modules/@poe-code/design-system/dist/acp/writer.d.ts +13 -0
- package/node_modules/@poe-code/design-system/dist/acp/writer.js +21 -0
- package/node_modules/@poe-code/design-system/dist/components/command-errors.d.ts +16 -0
- package/node_modules/@poe-code/design-system/dist/components/command-errors.js +22 -0
- package/node_modules/@poe-code/design-system/dist/components/help-formatter.d.ts +20 -0
- package/node_modules/@poe-code/design-system/dist/components/help-formatter.js +27 -0
- package/node_modules/@poe-code/design-system/dist/components/index.d.ts +10 -0
- package/node_modules/@poe-code/design-system/dist/components/index.js +7 -0
- package/node_modules/@poe-code/design-system/dist/components/logger.d.ts +11 -0
- package/node_modules/@poe-code/design-system/dist/components/logger.js +60 -0
- package/node_modules/@poe-code/design-system/dist/components/symbols.d.ts +12 -0
- package/node_modules/@poe-code/design-system/dist/components/symbols.js +71 -0
- package/node_modules/@poe-code/design-system/dist/components/table.d.ts +13 -0
- package/node_modules/@poe-code/design-system/dist/components/table.js +74 -0
- package/node_modules/@poe-code/design-system/dist/components/text.d.ts +14 -0
- package/node_modules/@poe-code/design-system/dist/components/text.js +104 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/ansi.d.ts +18 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/ansi.js +298 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/buffer.d.ts +25 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/buffer.js +189 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/components/border.d.ts +9 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/components/border.js +123 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/components/footer.d.ts +8 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/components/footer.js +57 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/components/output-pane.d.ts +12 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/components/output-pane.js +254 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/components/stats-pane.d.ts +7 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/components/stats-pane.js +121 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/dashboard.d.ts +20 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/dashboard.js +167 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/demo.d.ts +13 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/demo.js +145 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/index.d.ts +8 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/index.js +4 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/keymap.d.ts +3 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/keymap.js +99 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/layout.d.ts +25 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/layout.js +79 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/should-use-dashboard.d.ts +10 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/should-use-dashboard.js +7 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/snapshot.d.ts +10 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/snapshot.js +68 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/store.d.ts +8 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/store.js +51 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/terminal.d.ts +37 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/terminal.js +233 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/types.d.ts +36 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/types.js +1 -0
- package/node_modules/@poe-code/design-system/dist/index.d.ts +33 -0
- package/node_modules/@poe-code/design-system/dist/index.js +31 -0
- package/node_modules/@poe-code/design-system/dist/internal/output-format.d.ts +6 -0
- package/node_modules/@poe-code/design-system/dist/internal/output-format.js +22 -0
- package/node_modules/@poe-code/design-system/dist/internal/strip-ansi.d.ts +1 -0
- package/node_modules/@poe-code/design-system/dist/internal/strip-ansi.js +3 -0
- package/node_modules/@poe-code/design-system/dist/internal/theme-detect.d.ts +11 -0
- package/node_modules/@poe-code/design-system/dist/internal/theme-detect.js +49 -0
- package/node_modules/@poe-code/design-system/dist/prompts/index.d.ts +66 -0
- package/node_modules/@poe-code/design-system/dist/prompts/index.js +132 -0
- package/node_modules/@poe-code/design-system/dist/prompts/primitives/cancel.d.ts +2 -0
- package/node_modules/@poe-code/design-system/dist/prompts/primitives/cancel.js +9 -0
- package/node_modules/@poe-code/design-system/dist/prompts/primitives/intro.d.ts +1 -0
- package/node_modules/@poe-code/design-system/dist/prompts/primitives/intro.js +15 -0
- package/node_modules/@poe-code/design-system/dist/prompts/primitives/log.d.ts +18 -0
- package/node_modules/@poe-code/design-system/dist/prompts/primitives/log.js +101 -0
- package/node_modules/@poe-code/design-system/dist/prompts/primitives/note.d.ts +1 -0
- package/node_modules/@poe-code/design-system/dist/prompts/primitives/note.js +39 -0
- package/node_modules/@poe-code/design-system/dist/prompts/primitives/outro.d.ts +1 -0
- package/node_modules/@poe-code/design-system/dist/prompts/primitives/outro.js +16 -0
- package/node_modules/@poe-code/design-system/dist/prompts/primitives/spinner.d.ts +6 -0
- package/node_modules/@poe-code/design-system/dist/prompts/primitives/spinner.js +74 -0
- package/node_modules/@poe-code/design-system/dist/prompts/theme.d.ts +11 -0
- package/node_modules/@poe-code/design-system/dist/prompts/theme.js +12 -0
- package/node_modules/@poe-code/design-system/dist/static/index.d.ts +4 -0
- package/node_modules/@poe-code/design-system/dist/static/index.js +2 -0
- package/node_modules/@poe-code/design-system/dist/static/menu.d.ts +11 -0
- package/node_modules/@poe-code/design-system/dist/static/menu.js +36 -0
- package/node_modules/@poe-code/design-system/dist/static/spinner.d.ts +14 -0
- package/node_modules/@poe-code/design-system/dist/static/spinner.js +46 -0
- package/node_modules/@poe-code/design-system/dist/terminal-markdown/ast.d.ts +92 -0
- package/node_modules/@poe-code/design-system/dist/terminal-markdown/ast.js +1 -0
- package/node_modules/@poe-code/design-system/dist/terminal-markdown/demo-content.d.ts +2 -0
- package/node_modules/@poe-code/design-system/dist/terminal-markdown/demo-content.js +139 -0
- package/node_modules/@poe-code/design-system/dist/terminal-markdown/index.d.ts +6 -0
- package/node_modules/@poe-code/design-system/dist/terminal-markdown/index.js +8 -0
- package/node_modules/@poe-code/design-system/dist/terminal-markdown/parser/block.d.ts +7 -0
- package/node_modules/@poe-code/design-system/dist/terminal-markdown/parser/block.js +1495 -0
- package/node_modules/@poe-code/design-system/dist/terminal-markdown/parser/frontmatter.d.ts +8 -0
- package/node_modules/@poe-code/design-system/dist/terminal-markdown/parser/frontmatter.js +412 -0
- package/node_modules/@poe-code/design-system/dist/terminal-markdown/parser/inline.d.ts +10 -0
- package/node_modules/@poe-code/design-system/dist/terminal-markdown/parser/inline.js +1166 -0
- package/node_modules/@poe-code/design-system/dist/terminal-markdown/parser.d.ts +5 -0
- package/node_modules/@poe-code/design-system/dist/terminal-markdown/parser.js +42 -0
- package/node_modules/@poe-code/design-system/dist/terminal-markdown/renderer.d.ts +6 -0
- package/node_modules/@poe-code/design-system/dist/terminal-markdown/renderer.js +572 -0
- package/node_modules/@poe-code/design-system/dist/terminal-markdown/testing/theme-render-fixture.d.ts +1 -0
- package/node_modules/@poe-code/design-system/dist/terminal-markdown/testing/theme-render-fixture.js +27 -0
- package/node_modules/@poe-code/design-system/dist/tokens/colors.d.ts +35 -0
- package/node_modules/@poe-code/design-system/dist/tokens/colors.js +34 -0
- package/node_modules/@poe-code/design-system/dist/tokens/index.d.ts +4 -0
- package/node_modules/@poe-code/design-system/dist/tokens/index.js +4 -0
- package/node_modules/@poe-code/design-system/dist/tokens/spacing.d.ts +6 -0
- package/node_modules/@poe-code/design-system/dist/tokens/spacing.js +6 -0
- package/node_modules/@poe-code/design-system/dist/tokens/typography.d.ts +7 -0
- package/node_modules/@poe-code/design-system/dist/tokens/typography.js +8 -0
- package/node_modules/@poe-code/design-system/dist/tokens/widths.d.ts +5 -0
- package/node_modules/@poe-code/design-system/dist/tokens/widths.js +5 -0
- package/node_modules/@poe-code/design-system/package.json +25 -0
- package/package.json +57 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import * as clack from "@clack/prompts";
|
|
2
|
+
import { cancel, isCancel } from "./primitives/cancel.js";
|
|
3
|
+
import { intro } from "./primitives/intro.js";
|
|
4
|
+
import { log } from "./primitives/log.js";
|
|
5
|
+
import { note } from "./primitives/note.js";
|
|
6
|
+
import { outro } from "./primitives/outro.js";
|
|
7
|
+
import { spinner } from "./primitives/spinner.js";
|
|
8
|
+
export { isCancel, cancel, log };
|
|
9
|
+
export { intro, outro, note, spinner };
|
|
10
|
+
export declare function introPlain(title: string): void;
|
|
11
|
+
export interface SelectOptions<Value> {
|
|
12
|
+
message: string;
|
|
13
|
+
options: Array<{
|
|
14
|
+
value: Value;
|
|
15
|
+
label: string;
|
|
16
|
+
hint?: string;
|
|
17
|
+
}>;
|
|
18
|
+
initialValue?: Value;
|
|
19
|
+
}
|
|
20
|
+
export declare function select<Value>(opts: SelectOptions<Value>): Promise<Value | symbol>;
|
|
21
|
+
export type MultiselectOptions<Value> = Parameters<typeof clack.multiselect<Value>>[0];
|
|
22
|
+
/**
|
|
23
|
+
* Prompts the user to select one or more values from a list.
|
|
24
|
+
*
|
|
25
|
+
* Returns the selected values as an array, or a cancellation symbol if the
|
|
26
|
+
* user cancels. Use `isCancel` to check for cancellation.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* const result = await multiselect({
|
|
30
|
+
* message: "Pick workflows to run",
|
|
31
|
+
* options: [{ label: "Fix Vulnerabilities", value: "fix-vulnerabilities" }],
|
|
32
|
+
* required: true
|
|
33
|
+
* });
|
|
34
|
+
* if (!isCancel(result)) {
|
|
35
|
+
* // result is Value[]
|
|
36
|
+
* }
|
|
37
|
+
*/
|
|
38
|
+
export declare function multiselect<Value>(opts: MultiselectOptions<Value>): Promise<Value[] | symbol>;
|
|
39
|
+
export type TextOptions = Parameters<typeof clack.text>[0];
|
|
40
|
+
export declare function text(opts: TextOptions): Promise<string | symbol>;
|
|
41
|
+
export interface ConfirmOptions {
|
|
42
|
+
message: string;
|
|
43
|
+
initialValue?: boolean;
|
|
44
|
+
}
|
|
45
|
+
export declare function confirm(opts: ConfirmOptions): Promise<boolean | symbol>;
|
|
46
|
+
export declare class PromptCancelledError extends Error {
|
|
47
|
+
constructor(message?: string);
|
|
48
|
+
}
|
|
49
|
+
export declare function confirmOrCancel(opts: ConfirmOptions): Promise<boolean>;
|
|
50
|
+
export interface PasswordOptions {
|
|
51
|
+
message: string;
|
|
52
|
+
validate?: (value: string) => string | undefined;
|
|
53
|
+
}
|
|
54
|
+
export declare function password(opts: PasswordOptions): Promise<string | symbol>;
|
|
55
|
+
export type SpinnerOptions = {
|
|
56
|
+
start: (message?: string) => void;
|
|
57
|
+
stop: (message?: string, code?: number) => void;
|
|
58
|
+
message: (message?: string) => void;
|
|
59
|
+
};
|
|
60
|
+
export interface WithSpinnerOptions<T> {
|
|
61
|
+
message: string;
|
|
62
|
+
fn: () => Promise<T>;
|
|
63
|
+
stopMessage?: (result: T) => string;
|
|
64
|
+
subtext?: (result: T) => string | undefined;
|
|
65
|
+
}
|
|
66
|
+
export declare function withSpinner<T>(options: WithSpinnerOptions<T>): Promise<T>;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import * as clack from "@clack/prompts";
|
|
3
|
+
import { resolveOutputFormat } from "../internal/output-format.js";
|
|
4
|
+
import { stripAnsi } from "../internal/strip-ansi.js";
|
|
5
|
+
import { cancel, isCancel } from "./primitives/cancel.js";
|
|
6
|
+
import { intro } from "./primitives/intro.js";
|
|
7
|
+
import { log } from "./primitives/log.js";
|
|
8
|
+
import { note } from "./primitives/note.js";
|
|
9
|
+
import { outro } from "./primitives/outro.js";
|
|
10
|
+
import { spinner } from "./primitives/spinner.js";
|
|
11
|
+
export { isCancel, cancel, log };
|
|
12
|
+
export { intro, outro, note, spinner };
|
|
13
|
+
export function introPlain(title) {
|
|
14
|
+
const format = resolveOutputFormat();
|
|
15
|
+
if (format === "markdown") {
|
|
16
|
+
process.stdout.write(`# ${stripAnsi(title)}\n\n`);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (format === "json") {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
process.stdout.write(`${chalk.gray("┌")} ${title}\n`);
|
|
23
|
+
}
|
|
24
|
+
export async function select(opts) {
|
|
25
|
+
return clack.select(opts);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Prompts the user to select one or more values from a list.
|
|
29
|
+
*
|
|
30
|
+
* Returns the selected values as an array, or a cancellation symbol if the
|
|
31
|
+
* user cancels. Use `isCancel` to check for cancellation.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* const result = await multiselect({
|
|
35
|
+
* message: "Pick workflows to run",
|
|
36
|
+
* options: [{ label: "Fix Vulnerabilities", value: "fix-vulnerabilities" }],
|
|
37
|
+
* required: true
|
|
38
|
+
* });
|
|
39
|
+
* if (!isCancel(result)) {
|
|
40
|
+
* // result is Value[]
|
|
41
|
+
* }
|
|
42
|
+
*/
|
|
43
|
+
export async function multiselect(opts) {
|
|
44
|
+
return clack.multiselect(opts);
|
|
45
|
+
}
|
|
46
|
+
export async function text(opts) {
|
|
47
|
+
return clack.text(opts);
|
|
48
|
+
}
|
|
49
|
+
export async function confirm(opts) {
|
|
50
|
+
return clack.confirm(opts);
|
|
51
|
+
}
|
|
52
|
+
export class PromptCancelledError extends Error {
|
|
53
|
+
constructor(message = "Operation cancelled.") {
|
|
54
|
+
super(message);
|
|
55
|
+
this.name = "PromptCancelledError";
|
|
56
|
+
if (Error.captureStackTrace) {
|
|
57
|
+
Error.captureStackTrace(this, this.constructor);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export async function confirmOrCancel(opts) {
|
|
62
|
+
const result = await confirm(opts);
|
|
63
|
+
if (isCancel(result)) {
|
|
64
|
+
cancel("Operation cancelled.");
|
|
65
|
+
throw new PromptCancelledError();
|
|
66
|
+
}
|
|
67
|
+
return result === true;
|
|
68
|
+
}
|
|
69
|
+
export async function password(opts) {
|
|
70
|
+
return clack.password(opts);
|
|
71
|
+
}
|
|
72
|
+
function formatElapsed(ms) {
|
|
73
|
+
const totalSeconds = Math.floor(ms / 1000);
|
|
74
|
+
if (totalSeconds < 60) {
|
|
75
|
+
return `${totalSeconds}s`;
|
|
76
|
+
}
|
|
77
|
+
const minutes = Math.floor(totalSeconds / 60);
|
|
78
|
+
const seconds = totalSeconds % 60;
|
|
79
|
+
return `${minutes}m ${seconds}s`;
|
|
80
|
+
}
|
|
81
|
+
export async function withSpinner(options) {
|
|
82
|
+
const { message, fn, stopMessage, subtext } = options;
|
|
83
|
+
if (resolveOutputFormat() === "json") {
|
|
84
|
+
const result = await fn();
|
|
85
|
+
const sub = subtext ? subtext(result) : undefined;
|
|
86
|
+
if (sub) {
|
|
87
|
+
process.stdout.write(sub + "\n");
|
|
88
|
+
}
|
|
89
|
+
return result;
|
|
90
|
+
}
|
|
91
|
+
const noSpinner = process.env.POE_NO_SPINNER === "1";
|
|
92
|
+
const isTTY = process.stdout.isTTY;
|
|
93
|
+
if (noSpinner || !isTTY) {
|
|
94
|
+
const result = await fn();
|
|
95
|
+
const msg = stopMessage ? stopMessage(result) : undefined;
|
|
96
|
+
if (msg) {
|
|
97
|
+
process.stdout.write(`\x1b[32m◆\x1b[0m ${msg}\n`);
|
|
98
|
+
}
|
|
99
|
+
const sub = subtext ? subtext(result) : undefined;
|
|
100
|
+
if (sub) {
|
|
101
|
+
for (const line of sub.split("\n")) {
|
|
102
|
+
process.stdout.write(`\x1b[90m│\x1b[0m ${line}\n`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return result;
|
|
106
|
+
}
|
|
107
|
+
const s = spinner();
|
|
108
|
+
const start = Date.now();
|
|
109
|
+
s.start(message);
|
|
110
|
+
const timer = setInterval(() => {
|
|
111
|
+
s.message(`${message} [${formatElapsed(Date.now() - start)}]`);
|
|
112
|
+
}, 1000);
|
|
113
|
+
try {
|
|
114
|
+
const result = await fn();
|
|
115
|
+
clearInterval(timer);
|
|
116
|
+
const elapsed = formatElapsed(Date.now() - start);
|
|
117
|
+
const msg = stopMessage ? stopMessage(result) : undefined;
|
|
118
|
+
s.stop(msg ? `${msg} [${elapsed}]` : `Done [${elapsed}]`);
|
|
119
|
+
const sub = subtext ? subtext(result) : undefined;
|
|
120
|
+
if (sub) {
|
|
121
|
+
for (const line of sub.split("\n")) {
|
|
122
|
+
process.stdout.write(`\x1b[90m│\x1b[0m ${line}\n`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return result;
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
clearInterval(timer);
|
|
129
|
+
s.stop("", 1);
|
|
130
|
+
throw error;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
export { isCancel } from "@clack/core";
|
|
3
|
+
import { resolveOutputFormat } from "../../internal/output-format.js";
|
|
4
|
+
export function cancel(msg = "") {
|
|
5
|
+
if (resolveOutputFormat() !== "terminal") {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
process.stdout.write(`${chalk.gray("└")} ${chalk.red(msg)}\n\n`);
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function intro(title: string): void;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import { text } from "../../components/text.js";
|
|
3
|
+
import { resolveOutputFormat } from "../../internal/output-format.js";
|
|
4
|
+
import { stripAnsi } from "../../internal/strip-ansi.js";
|
|
5
|
+
export function intro(title) {
|
|
6
|
+
const format = resolveOutputFormat();
|
|
7
|
+
if (format === "json") {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
if (format === "markdown") {
|
|
11
|
+
process.stdout.write(`# ${stripAnsi(title)}\n\n`);
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
process.stdout.write(`${chalk.gray("┌")} ${text.intro(title)}\n`);
|
|
15
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface LogMessageOptions {
|
|
2
|
+
symbol?: string;
|
|
3
|
+
secondarySymbol?: string;
|
|
4
|
+
spacing?: number;
|
|
5
|
+
withGuide?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare function message(msg: string, options?: LogMessageOptions): void;
|
|
8
|
+
export declare function info(msg: string): void;
|
|
9
|
+
export declare function success(msg: string): void;
|
|
10
|
+
export declare function warn(msg: string): void;
|
|
11
|
+
export declare function error(msg: string): void;
|
|
12
|
+
export declare const log: {
|
|
13
|
+
info: typeof info;
|
|
14
|
+
success: typeof success;
|
|
15
|
+
message: typeof message;
|
|
16
|
+
warn: typeof warn;
|
|
17
|
+
error: typeof error;
|
|
18
|
+
};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import { symbols } from "../../components/symbols.js";
|
|
3
|
+
import { resolveOutputFormat } from "../../internal/output-format.js";
|
|
4
|
+
import { stripAnsi } from "../../internal/strip-ansi.js";
|
|
5
|
+
function writeTerminalMessage(msg, { symbol = chalk.gray("│"), secondarySymbol = chalk.gray("│"), spacing = 1, withGuide = true } = {}) {
|
|
6
|
+
const lines = [];
|
|
7
|
+
const showGuide = withGuide !== false;
|
|
8
|
+
const contentLines = msg.split("\n");
|
|
9
|
+
const prefix = showGuide ? `${symbol} ` : "";
|
|
10
|
+
const continuationPrefix = showGuide ? `${secondarySymbol} ` : "";
|
|
11
|
+
const emptyGuide = showGuide ? secondarySymbol : "";
|
|
12
|
+
for (let index = 0; index < spacing; index += 1) {
|
|
13
|
+
lines.push(emptyGuide);
|
|
14
|
+
}
|
|
15
|
+
if (contentLines.length === 0) {
|
|
16
|
+
process.stdout.write("\n");
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const [firstLine = "", ...continuationLines] = contentLines;
|
|
20
|
+
if (firstLine.length > 0) {
|
|
21
|
+
lines.push(`${prefix}${firstLine}`);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
lines.push(showGuide ? symbol : "");
|
|
25
|
+
}
|
|
26
|
+
for (const line of continuationLines) {
|
|
27
|
+
if (line.length > 0) {
|
|
28
|
+
lines.push(`${continuationPrefix}${line}`);
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
lines.push(emptyGuide);
|
|
32
|
+
}
|
|
33
|
+
process.stdout.write(`${lines.join("\n")}\n`);
|
|
34
|
+
}
|
|
35
|
+
export function message(msg, options) {
|
|
36
|
+
const format = resolveOutputFormat();
|
|
37
|
+
if (format === "markdown") {
|
|
38
|
+
process.stdout.write(`- ${stripAnsi(msg)}\n`);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (format === "json") {
|
|
42
|
+
process.stdout.write(`${JSON.stringify({ level: "message", message: stripAnsi(msg) })}\n`);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
writeTerminalMessage(msg, options);
|
|
46
|
+
}
|
|
47
|
+
export function info(msg) {
|
|
48
|
+
const format = resolveOutputFormat();
|
|
49
|
+
if (format === "markdown") {
|
|
50
|
+
process.stdout.write(`- **info:** ${stripAnsi(msg)}\n`);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (format === "json") {
|
|
54
|
+
process.stdout.write(`${JSON.stringify({ level: "info", message: stripAnsi(msg) })}\n`);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
message(msg, { symbol: symbols.info });
|
|
58
|
+
}
|
|
59
|
+
export function success(msg) {
|
|
60
|
+
const format = resolveOutputFormat();
|
|
61
|
+
if (format === "markdown") {
|
|
62
|
+
process.stdout.write(`- **success:** ${stripAnsi(msg)}\n`);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (format === "json") {
|
|
66
|
+
process.stdout.write(`${JSON.stringify({ level: "success", message: stripAnsi(msg) })}\n`);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
message(msg, { symbol: symbols.success });
|
|
70
|
+
}
|
|
71
|
+
export function warn(msg) {
|
|
72
|
+
const format = resolveOutputFormat();
|
|
73
|
+
if (format === "markdown") {
|
|
74
|
+
process.stdout.write(`- **warning:** ${stripAnsi(msg)}\n`);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (format === "json") {
|
|
78
|
+
process.stdout.write(`${JSON.stringify({ level: "warn", message: stripAnsi(msg) })}\n`);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
message(msg, { symbol: chalk.yellow("▲") });
|
|
82
|
+
}
|
|
83
|
+
export function error(msg) {
|
|
84
|
+
const format = resolveOutputFormat();
|
|
85
|
+
if (format === "markdown") {
|
|
86
|
+
process.stdout.write(`- **error:** ${stripAnsi(msg)}\n`);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (format === "json") {
|
|
90
|
+
process.stdout.write(`${JSON.stringify({ level: "error", message: stripAnsi(msg) })}\n`);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
message(msg, { symbol: chalk.red("■") });
|
|
94
|
+
}
|
|
95
|
+
export const log = {
|
|
96
|
+
info,
|
|
97
|
+
success,
|
|
98
|
+
message,
|
|
99
|
+
warn,
|
|
100
|
+
error
|
|
101
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function note(message: string, title?: string): void;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import { resolveOutputFormat } from "../../internal/output-format.js";
|
|
3
|
+
import { stripAnsi } from "../../internal/strip-ansi.js";
|
|
4
|
+
function getVisibleWidth(value) {
|
|
5
|
+
return stripAnsi(value).length;
|
|
6
|
+
}
|
|
7
|
+
function renderTerminalNote(message, title) {
|
|
8
|
+
const contentLines = ["", ...message.split("\n"), ""];
|
|
9
|
+
const visibleTitle = stripAnsi(title ?? "");
|
|
10
|
+
const contentWidth = Math.max(visibleTitle.length, ...contentLines.map((line) => getVisibleWidth(line))) + 2;
|
|
11
|
+
const titleLine = `${chalk.green("◇")} ${chalk.reset(title ?? "")} ${chalk.gray(`${"─".repeat(Math.max(contentWidth - visibleTitle.length - 1, 1))}╮`)}`;
|
|
12
|
+
const content = contentLines.map((line) => {
|
|
13
|
+
const padding = " ".repeat(contentWidth - getVisibleWidth(line));
|
|
14
|
+
return `${chalk.gray("│")} ${line}${padding}${chalk.gray("│")}`;
|
|
15
|
+
});
|
|
16
|
+
const bottom = chalk.gray(`├${"─".repeat(contentWidth + 2)}╯`);
|
|
17
|
+
return [chalk.gray("│"), titleLine, ...content, bottom].join("\n");
|
|
18
|
+
}
|
|
19
|
+
export function note(message, title) {
|
|
20
|
+
const format = resolveOutputFormat();
|
|
21
|
+
const strippedMessage = stripAnsi(message);
|
|
22
|
+
const strippedTitle = stripAnsi(title ?? "");
|
|
23
|
+
if (format === "markdown") {
|
|
24
|
+
const lines = strippedMessage.split("\n");
|
|
25
|
+
const heading = strippedTitle ? `> **${strippedTitle}**\n` : "";
|
|
26
|
+
const body = lines.map((line) => `> ${line}`).join("\n");
|
|
27
|
+
process.stdout.write(`${heading}${body}\n`);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (format === "json") {
|
|
31
|
+
process.stdout.write(`${JSON.stringify({
|
|
32
|
+
type: "note",
|
|
33
|
+
title: strippedTitle,
|
|
34
|
+
message: strippedMessage
|
|
35
|
+
})}\n`);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
process.stdout.write(`${renderTerminalNote(message, title)}\n`);
|
|
39
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function outro(message: string): void;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import { resolveOutputFormat } from "../../internal/output-format.js";
|
|
3
|
+
import { stripAnsi } from "../../internal/strip-ansi.js";
|
|
4
|
+
export function outro(message) {
|
|
5
|
+
const format = resolveOutputFormat();
|
|
6
|
+
const stripped = stripAnsi(message);
|
|
7
|
+
if (format === "markdown") {
|
|
8
|
+
process.stdout.write(`---\n${stripped}\n`);
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
if (format === "json") {
|
|
12
|
+
process.stdout.write(`${JSON.stringify({ type: "outro", message: stripped })}\n`);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
process.stdout.write(`${chalk.gray("│")}\n${chalk.gray("└")} ${message}\n\n`);
|
|
16
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import { resolveOutputFormat } from "../../internal/output-format.js";
|
|
3
|
+
import { stripAnsi } from "../../internal/strip-ansi.js";
|
|
4
|
+
import { SPINNER_FRAMES } from "../../static/spinner.js";
|
|
5
|
+
function writeTerminalFrame(frame, message) {
|
|
6
|
+
process.stdout.write(`\r\x1b[K${frame} ${message}`);
|
|
7
|
+
}
|
|
8
|
+
export function spinner() {
|
|
9
|
+
let currentMessage = "";
|
|
10
|
+
let frameIndex = 0;
|
|
11
|
+
let timer;
|
|
12
|
+
let fallback = false;
|
|
13
|
+
const format = resolveOutputFormat();
|
|
14
|
+
const renderFrame = () => {
|
|
15
|
+
writeTerminalFrame(SPINNER_FRAMES[frameIndex % SPINNER_FRAMES.length], currentMessage);
|
|
16
|
+
};
|
|
17
|
+
const clearTimer = () => {
|
|
18
|
+
if (!timer) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
clearInterval(timer);
|
|
22
|
+
timer = undefined;
|
|
23
|
+
};
|
|
24
|
+
return {
|
|
25
|
+
start(message = "") {
|
|
26
|
+
currentMessage = stripAnsi(message);
|
|
27
|
+
if (format === "json") {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (format === "markdown") {
|
|
31
|
+
process.stdout.write(`- ${currentMessage}...\n`);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
fallback = process.env.POE_NO_SPINNER === "1" || !process.stdout.isTTY;
|
|
35
|
+
if (fallback) {
|
|
36
|
+
process.stdout.write(`${currentMessage}\n`);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
frameIndex = 0;
|
|
40
|
+
renderFrame();
|
|
41
|
+
timer = setInterval(() => {
|
|
42
|
+
frameIndex += 1;
|
|
43
|
+
renderFrame();
|
|
44
|
+
}, 16);
|
|
45
|
+
},
|
|
46
|
+
message(message = "") {
|
|
47
|
+
currentMessage = stripAnsi(message);
|
|
48
|
+
if (format !== "terminal" || fallback || !timer) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
renderFrame();
|
|
52
|
+
},
|
|
53
|
+
stop(message = currentMessage, code) {
|
|
54
|
+
currentMessage = stripAnsi(message);
|
|
55
|
+
if (format === "json") {
|
|
56
|
+
process.stdout.write(`${JSON.stringify({ type: "spinner", state: "stopped", message: currentMessage })}\n`);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (format === "markdown") {
|
|
60
|
+
process.stdout.write(`- ${currentMessage}\n`);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
clearTimer();
|
|
64
|
+
const symbol = code === undefined || code === 0
|
|
65
|
+
? chalk.green("◆")
|
|
66
|
+
: chalk.red("■");
|
|
67
|
+
if (fallback) {
|
|
68
|
+
process.stdout.write(`${symbol} ${currentMessage}\n`);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
process.stdout.write(`\r\x1b[K${symbol} ${currentMessage}\n`);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { SPINNER_FRAMES, renderSpinnerFrame, renderSpinnerStopped } from "./spinner.js";
|
|
2
|
+
export type { SpinnerFrameOptions, SpinnerStoppedOptions } from "./spinner.js";
|
|
3
|
+
export { renderMenu } from "./menu.js";
|
|
4
|
+
export type { MenuOption, RenderMenuOptions } from "./menu.js";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface MenuOption {
|
|
2
|
+
label: string;
|
|
3
|
+
value: string;
|
|
4
|
+
hint?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface RenderMenuOptions {
|
|
7
|
+
message: string;
|
|
8
|
+
options: MenuOption[];
|
|
9
|
+
selectedIndex?: number;
|
|
10
|
+
}
|
|
11
|
+
export declare function renderMenu(opts: RenderMenuOptions): string;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import { symbols } from "../components/symbols.js";
|
|
3
|
+
import { resolveOutputFormat } from "../internal/output-format.js";
|
|
4
|
+
import { getTheme } from "../internal/theme-detect.js";
|
|
5
|
+
export function renderMenu(opts) {
|
|
6
|
+
const format = resolveOutputFormat();
|
|
7
|
+
const selectedIndex = opts.selectedIndex ?? 0;
|
|
8
|
+
if (format === "markdown") {
|
|
9
|
+
return [
|
|
10
|
+
`**${opts.message}**`,
|
|
11
|
+
...opts.options.map((option, index) => `- [${index === selectedIndex ? "x" : " "}] ${option.label}`)
|
|
12
|
+
].join("\n");
|
|
13
|
+
}
|
|
14
|
+
if (format === "json") {
|
|
15
|
+
return JSON.stringify({
|
|
16
|
+
type: "menu",
|
|
17
|
+
message: opts.message,
|
|
18
|
+
options: opts.options,
|
|
19
|
+
selected: selectedIndex
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
const theme = getTheme();
|
|
23
|
+
const bar = chalk.gray(symbols.bar);
|
|
24
|
+
const lines = [];
|
|
25
|
+
lines.push(`${chalk.cyan(symbols.active)} ${opts.message}`);
|
|
26
|
+
lines.push(bar);
|
|
27
|
+
opts.options.forEach((option, index) => {
|
|
28
|
+
const isSelected = index === selectedIndex;
|
|
29
|
+
const prefix = isSelected ? chalk.cyan(symbols.active) : chalk.gray(symbols.inactive);
|
|
30
|
+
const label = isSelected ? theme.accent(option.label) : option.label;
|
|
31
|
+
const hint = option.hint ? chalk.dim(` (${option.hint})`) : "";
|
|
32
|
+
lines.push(`${bar} ${prefix} ${label}${hint}`);
|
|
33
|
+
});
|
|
34
|
+
lines.push(`${bar}`);
|
|
35
|
+
return lines.join("\n");
|
|
36
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const SPINNER_FRAMES: readonly ["◒", "◐", "◓", "◑"];
|
|
2
|
+
export interface SpinnerFrameOptions {
|
|
3
|
+
frame?: number;
|
|
4
|
+
message: string;
|
|
5
|
+
timer?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function renderSpinnerFrame(options: SpinnerFrameOptions): string;
|
|
8
|
+
export interface SpinnerStoppedOptions {
|
|
9
|
+
message: string;
|
|
10
|
+
code?: number;
|
|
11
|
+
timer?: string;
|
|
12
|
+
subtext?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function renderSpinnerStopped(options: SpinnerStoppedOptions): string;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import { symbols } from "../components/symbols.js";
|
|
3
|
+
import { resolveOutputFormat } from "../internal/output-format.js";
|
|
4
|
+
export const SPINNER_FRAMES = ["◒", "◐", "◓", "◑"];
|
|
5
|
+
export function renderSpinnerFrame(options) {
|
|
6
|
+
const format = resolveOutputFormat();
|
|
7
|
+
if (format === "markdown") {
|
|
8
|
+
return `- ${options.message}${options.timer ? ` [${options.timer}]` : ""}...\n`;
|
|
9
|
+
}
|
|
10
|
+
if (format === "json") {
|
|
11
|
+
return `${JSON.stringify({
|
|
12
|
+
type: "spinner",
|
|
13
|
+
state: "running",
|
|
14
|
+
message: options.message,
|
|
15
|
+
...(options.timer ? { timer: options.timer } : {})
|
|
16
|
+
})}\n`;
|
|
17
|
+
}
|
|
18
|
+
const frame = options.frame ?? 0;
|
|
19
|
+
const spinnerChar = chalk.magenta(SPINNER_FRAMES[frame % SPINNER_FRAMES.length]);
|
|
20
|
+
const timerSuffix = options.timer ? chalk.dim(` [${options.timer}]`) : "";
|
|
21
|
+
const bar = chalk.gray(symbols.bar);
|
|
22
|
+
return `${spinnerChar} ${options.message}${timerSuffix}\n${bar}`;
|
|
23
|
+
}
|
|
24
|
+
export function renderSpinnerStopped(options) {
|
|
25
|
+
const format = resolveOutputFormat();
|
|
26
|
+
if (format === "markdown") {
|
|
27
|
+
return `- ${options.message}${options.timer ? ` [${options.timer}]` : ""}\n`;
|
|
28
|
+
}
|
|
29
|
+
if (format === "json") {
|
|
30
|
+
return `${JSON.stringify({
|
|
31
|
+
type: "spinner",
|
|
32
|
+
state: "stopped",
|
|
33
|
+
message: options.message,
|
|
34
|
+
...(options.timer ? { timer: options.timer } : {})
|
|
35
|
+
})}\n`;
|
|
36
|
+
}
|
|
37
|
+
const code = options.code ?? 0;
|
|
38
|
+
const symbol = code === 0 ? chalk.green("◆") : chalk.red("■");
|
|
39
|
+
const timerSuffix = options.timer ? chalk.dim(` [${options.timer}]`) : "";
|
|
40
|
+
const bar = chalk.gray(symbols.bar);
|
|
41
|
+
let output = `${symbol} ${options.message}${timerSuffix}`;
|
|
42
|
+
if (options.subtext) {
|
|
43
|
+
output += `\n${bar} ${chalk.dim(options.subtext)}`;
|
|
44
|
+
}
|
|
45
|
+
return output;
|
|
46
|
+
}
|