toolcraft-openapi 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 +64 -0
- package/dist/api-command.d.ts +7 -0
- package/dist/api-command.js +4 -0
- package/dist/auth/bearer-token-auth.d.ts +8 -0
- package/dist/auth/bearer-token-auth.js +216 -0
- package/dist/auth/types.d.ts +9 -0
- package/dist/auth/types.js +1 -0
- package/dist/bin/generate.d.ts +40 -0
- package/dist/bin/generate.js +248 -0
- package/dist/define-client.d.ts +20 -0
- package/dist/define-client.js +148 -0
- package/dist/generate.d.ts +210 -0
- package/dist/generate.js +1131 -0
- package/dist/group-by-noun.d.ts +6 -0
- package/dist/group-by-noun.js +17 -0
- package/dist/http.d.ts +26 -0
- package/dist/http.js +123 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +6 -0
- package/dist/interpreter.d.ts +6 -0
- package/dist/interpreter.js +289 -0
- package/dist/lock.d.ts +14 -0
- package/dist/lock.js +48 -0
- package/dist/naming.d.ts +24 -0
- package/dist/naming.js +218 -0
- package/dist/request-shape.d.ts +15 -0
- package/dist/request-shape.js +5 -0
- package/dist/runtime.d.ts +13 -0
- package/dist/runtime.js +94 -0
- package/dist/spec-source.d.ts +11 -0
- package/dist/spec-source.js +63 -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/node_modules/auth-store/README.md +47 -0
- package/node_modules/auth-store/dist/create-secret-store.d.ts +2 -0
- package/node_modules/auth-store/dist/create-secret-store.js +35 -0
- package/node_modules/auth-store/dist/encrypted-file-store.d.ts +39 -0
- package/node_modules/auth-store/dist/encrypted-file-store.js +156 -0
- package/node_modules/auth-store/dist/index.d.ts +7 -0
- package/node_modules/auth-store/dist/index.js +4 -0
- package/node_modules/auth-store/dist/keychain-store.d.ts +22 -0
- package/node_modules/auth-store/dist/keychain-store.js +111 -0
- package/node_modules/auth-store/dist/provider-store.d.ts +10 -0
- package/node_modules/auth-store/dist/provider-store.js +28 -0
- package/node_modules/auth-store/dist/types.d.ts +20 -0
- package/node_modules/auth-store/dist/types.js +1 -0
- package/node_modules/auth-store/package.json +25 -0
- package/package.json +48 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { text } from "./text.js";
|
|
2
|
+
import { widths } from "../tokens/widths.js";
|
|
3
|
+
export function formatCommand(name, description) {
|
|
4
|
+
const paddedName = name.padEnd(widths.helpColumn);
|
|
5
|
+
return ` ${text.command(paddedName)} ${description}`;
|
|
6
|
+
}
|
|
7
|
+
export function formatUsage(command, args) {
|
|
8
|
+
const argsStr = args ? ` ${text.argument(args)}` : "";
|
|
9
|
+
return `${text.usageCommand(command)}${argsStr}`;
|
|
10
|
+
}
|
|
11
|
+
export function formatOption(flags, description) {
|
|
12
|
+
const paddedFlags = flags.padEnd(widths.helpColumn);
|
|
13
|
+
return ` ${text.option(paddedFlags)} ${description}`;
|
|
14
|
+
}
|
|
15
|
+
export function formatCommandList(commands) {
|
|
16
|
+
return commands.map((cmd) => formatCommand(cmd.name, cmd.description)).join("\n");
|
|
17
|
+
}
|
|
18
|
+
export function formatOptionList(options) {
|
|
19
|
+
return options.map((opt) => formatOption(opt.flags, opt.description)).join("\n");
|
|
20
|
+
}
|
|
21
|
+
export const helpFormatter = {
|
|
22
|
+
formatCommand,
|
|
23
|
+
formatUsage,
|
|
24
|
+
formatOption,
|
|
25
|
+
formatCommandList,
|
|
26
|
+
formatOptionList
|
|
27
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { text } from "./text.js";
|
|
2
|
+
export { symbols } from "./symbols.js";
|
|
3
|
+
export { createLogger, logger } from "./logger.js";
|
|
4
|
+
export type { LoggerOutput } from "./logger.js";
|
|
5
|
+
export { helpFormatter, formatCommand, formatUsage, formatOption, formatCommandList, formatOptionList } from "./help-formatter.js";
|
|
6
|
+
export type { CommandInfo, OptionInfo } from "./help-formatter.js";
|
|
7
|
+
export { formatCommandNotFound } from "./command-errors.js";
|
|
8
|
+
export { formatCommandNotFoundPanel } from "./command-errors.js";
|
|
9
|
+
export { renderTable } from "./table.js";
|
|
10
|
+
export type { TableColumn, RenderTableOptions } from "./table.js";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { text } from "./text.js";
|
|
2
|
+
export { symbols } from "./symbols.js";
|
|
3
|
+
export { createLogger, logger } from "./logger.js";
|
|
4
|
+
export { helpFormatter, formatCommand, formatUsage, formatOption, formatCommandList, formatOptionList } from "./help-formatter.js";
|
|
5
|
+
export { formatCommandNotFound } from "./command-errors.js";
|
|
6
|
+
export { formatCommandNotFoundPanel } from "./command-errors.js";
|
|
7
|
+
export { renderTable } from "./table.js";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface LoggerOutput {
|
|
2
|
+
info(message: string): void;
|
|
3
|
+
success(message: string): void;
|
|
4
|
+
warn(message: string): void;
|
|
5
|
+
error(message: string): void;
|
|
6
|
+
resolved(label: string, value: string): void;
|
|
7
|
+
errorResolved(label: string, value: string): void;
|
|
8
|
+
message(message: string, symbol?: string): void;
|
|
9
|
+
}
|
|
10
|
+
export declare function createLogger(emitter?: (message: string) => void): LoggerOutput;
|
|
11
|
+
export declare const logger: LoggerOutput;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import { log } from "../prompts/primitives/log.js";
|
|
3
|
+
import { symbols } from "./symbols.js";
|
|
4
|
+
export function createLogger(emitter) {
|
|
5
|
+
const emit = (level, message) => {
|
|
6
|
+
if (emitter) {
|
|
7
|
+
emitter(message);
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
if (level === "success") {
|
|
11
|
+
log.success(message);
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
if (level === "warn") {
|
|
15
|
+
log.warn(message);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (level === "error") {
|
|
19
|
+
log.error(message);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
log.info(message);
|
|
23
|
+
};
|
|
24
|
+
return {
|
|
25
|
+
info(message) {
|
|
26
|
+
emit("info", message);
|
|
27
|
+
},
|
|
28
|
+
success(message) {
|
|
29
|
+
emit("success", message);
|
|
30
|
+
},
|
|
31
|
+
warn(message) {
|
|
32
|
+
emit("warn", message);
|
|
33
|
+
},
|
|
34
|
+
error(message) {
|
|
35
|
+
emit("error", message);
|
|
36
|
+
},
|
|
37
|
+
resolved(label, value) {
|
|
38
|
+
if (emitter) {
|
|
39
|
+
emitter(`${label}: ${value}`);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
log.message(`${label}\n ${value}`, { symbol: symbols.resolved });
|
|
43
|
+
},
|
|
44
|
+
errorResolved(label, value) {
|
|
45
|
+
if (emitter) {
|
|
46
|
+
emitter(`${label}: ${value}`);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
log.message(`${label}\n ${value}`, { symbol: symbols.errorResolved });
|
|
50
|
+
},
|
|
51
|
+
message(message, symbol) {
|
|
52
|
+
if (emitter) {
|
|
53
|
+
emitter(message);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
log.message(message, { symbol: symbol ?? chalk.gray("│") });
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export const logger = createLogger();
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const symbols: {
|
|
2
|
+
readonly info: string;
|
|
3
|
+
readonly success: string;
|
|
4
|
+
readonly resolved: string;
|
|
5
|
+
readonly errorResolved: string;
|
|
6
|
+
readonly bar: string;
|
|
7
|
+
readonly cornerTopRight: "╮";
|
|
8
|
+
readonly cornerBottomRight: "╯";
|
|
9
|
+
readonly warning: string;
|
|
10
|
+
readonly active: string;
|
|
11
|
+
readonly inactive: string;
|
|
12
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import { resolveOutputFormat } from "../internal/output-format.js";
|
|
3
|
+
import { getTheme } from "../internal/theme-detect.js";
|
|
4
|
+
export const symbols = {
|
|
5
|
+
get info() {
|
|
6
|
+
const format = resolveOutputFormat();
|
|
7
|
+
if (format === "json")
|
|
8
|
+
return "info";
|
|
9
|
+
if (format === "markdown")
|
|
10
|
+
return "(i)";
|
|
11
|
+
return chalk.magenta("●");
|
|
12
|
+
},
|
|
13
|
+
get success() {
|
|
14
|
+
const format = resolveOutputFormat();
|
|
15
|
+
if (format === "json")
|
|
16
|
+
return "success";
|
|
17
|
+
if (format === "markdown")
|
|
18
|
+
return "[ok]";
|
|
19
|
+
return chalk.magenta("◆");
|
|
20
|
+
},
|
|
21
|
+
get resolved() {
|
|
22
|
+
const format = resolveOutputFormat();
|
|
23
|
+
if (format === "json")
|
|
24
|
+
return "resolved";
|
|
25
|
+
if (format === "markdown")
|
|
26
|
+
return ">";
|
|
27
|
+
return getTheme().resolvedSymbol;
|
|
28
|
+
},
|
|
29
|
+
get errorResolved() {
|
|
30
|
+
const format = resolveOutputFormat();
|
|
31
|
+
if (format === "json")
|
|
32
|
+
return "error";
|
|
33
|
+
if (format === "markdown")
|
|
34
|
+
return "[!]";
|
|
35
|
+
return getTheme().errorSymbol;
|
|
36
|
+
},
|
|
37
|
+
get bar() {
|
|
38
|
+
const format = resolveOutputFormat();
|
|
39
|
+
if (format === "json")
|
|
40
|
+
return "";
|
|
41
|
+
if (format === "markdown")
|
|
42
|
+
return "|";
|
|
43
|
+
return "│";
|
|
44
|
+
},
|
|
45
|
+
cornerTopRight: "╮",
|
|
46
|
+
cornerBottomRight: "╯",
|
|
47
|
+
get warning() {
|
|
48
|
+
const format = resolveOutputFormat();
|
|
49
|
+
if (format === "json")
|
|
50
|
+
return "warning";
|
|
51
|
+
if (format === "markdown")
|
|
52
|
+
return "[!]";
|
|
53
|
+
return "▲";
|
|
54
|
+
},
|
|
55
|
+
get active() {
|
|
56
|
+
const format = resolveOutputFormat();
|
|
57
|
+
if (format === "json")
|
|
58
|
+
return "active";
|
|
59
|
+
if (format === "markdown")
|
|
60
|
+
return "[x]";
|
|
61
|
+
return "◆";
|
|
62
|
+
},
|
|
63
|
+
get inactive() {
|
|
64
|
+
const format = resolveOutputFormat();
|
|
65
|
+
if (format === "json")
|
|
66
|
+
return "inactive";
|
|
67
|
+
if (format === "markdown")
|
|
68
|
+
return "[ ]";
|
|
69
|
+
return "○";
|
|
70
|
+
}
|
|
71
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ThemePalette } from "../tokens/colors.js";
|
|
2
|
+
export interface TableColumn {
|
|
3
|
+
name: string;
|
|
4
|
+
title: string;
|
|
5
|
+
alignment: "left" | "right";
|
|
6
|
+
maxLen: number;
|
|
7
|
+
}
|
|
8
|
+
export interface RenderTableOptions {
|
|
9
|
+
theme: ThemePalette;
|
|
10
|
+
columns: TableColumn[];
|
|
11
|
+
rows: Record<string, string>[];
|
|
12
|
+
}
|
|
13
|
+
export declare function renderTable(options: RenderTableOptions): string;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Table } from "console-table-printer";
|
|
2
|
+
import { resolveOutputFormat } from "../internal/output-format.js";
|
|
3
|
+
import { stripAnsi } from "../internal/strip-ansi.js";
|
|
4
|
+
function renderTableTerminal(options) {
|
|
5
|
+
const { theme, columns, rows } = options;
|
|
6
|
+
const table = new Table({
|
|
7
|
+
style: {
|
|
8
|
+
headerTop: {
|
|
9
|
+
left: theme.muted("┌"),
|
|
10
|
+
mid: theme.muted("┬"),
|
|
11
|
+
right: theme.muted("┐"),
|
|
12
|
+
other: theme.muted("─")
|
|
13
|
+
},
|
|
14
|
+
headerBottom: {
|
|
15
|
+
left: theme.muted("├"),
|
|
16
|
+
mid: theme.muted("┼"),
|
|
17
|
+
right: theme.muted("┤"),
|
|
18
|
+
other: theme.muted("─")
|
|
19
|
+
},
|
|
20
|
+
tableBottom: {
|
|
21
|
+
left: theme.muted("└"),
|
|
22
|
+
mid: theme.muted("┴"),
|
|
23
|
+
right: theme.muted("┘"),
|
|
24
|
+
other: theme.muted("─")
|
|
25
|
+
},
|
|
26
|
+
vertical: theme.muted("│"),
|
|
27
|
+
rowSeparator: {
|
|
28
|
+
left: theme.muted("├"),
|
|
29
|
+
mid: theme.muted("┼"),
|
|
30
|
+
right: theme.muted("┤"),
|
|
31
|
+
other: theme.muted("─")
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
columns: columns.map((col) => ({
|
|
35
|
+
name: col.name,
|
|
36
|
+
title: theme.header(col.title),
|
|
37
|
+
alignment: col.alignment,
|
|
38
|
+
maxLen: col.maxLen
|
|
39
|
+
}))
|
|
40
|
+
});
|
|
41
|
+
for (const row of rows) {
|
|
42
|
+
table.addRow(row);
|
|
43
|
+
}
|
|
44
|
+
return table.render();
|
|
45
|
+
}
|
|
46
|
+
function renderTableMarkdown(options) {
|
|
47
|
+
const { columns, rows } = options;
|
|
48
|
+
const header = `| ${columns.map((c) => c.title).join(" | ")} |`;
|
|
49
|
+
const separator = `| ${columns.map((c) => (c.alignment === "right" ? "---:" : ":---")).join(" | ")} |`;
|
|
50
|
+
const dataRows = rows.map((row) => `| ${columns.map((c) => stripAnsi(row[c.name] ?? "").replace(/\|/g, "\\|")).join(" | ")} |`);
|
|
51
|
+
return [header, separator, ...dataRows].join("\n");
|
|
52
|
+
}
|
|
53
|
+
function renderTableJson(options) {
|
|
54
|
+
const { columns, rows } = options;
|
|
55
|
+
const cleaned = rows.map((row) => {
|
|
56
|
+
const obj = {};
|
|
57
|
+
for (const col of columns) {
|
|
58
|
+
obj[col.name] = stripAnsi(row[col.name] ?? "");
|
|
59
|
+
}
|
|
60
|
+
return obj;
|
|
61
|
+
});
|
|
62
|
+
return JSON.stringify(cleaned, null, 2);
|
|
63
|
+
}
|
|
64
|
+
export function renderTable(options) {
|
|
65
|
+
const format = resolveOutputFormat();
|
|
66
|
+
switch (format) {
|
|
67
|
+
case "markdown":
|
|
68
|
+
return renderTableMarkdown(options);
|
|
69
|
+
case "json":
|
|
70
|
+
return renderTableJson(options);
|
|
71
|
+
default:
|
|
72
|
+
return renderTableTerminal(options);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const text: {
|
|
2
|
+
readonly intro: (content: string) => string;
|
|
3
|
+
readonly heading: (content: string) => string;
|
|
4
|
+
readonly section: (content: string) => string;
|
|
5
|
+
readonly command: (content: string) => string;
|
|
6
|
+
readonly argument: (content: string) => string;
|
|
7
|
+
readonly option: (content: string) => string;
|
|
8
|
+
readonly example: (content: string) => string;
|
|
9
|
+
readonly usageCommand: (content: string) => string;
|
|
10
|
+
readonly link: (content: string) => string;
|
|
11
|
+
readonly muted: (content: string) => string;
|
|
12
|
+
readonly badge: (content: string) => string;
|
|
13
|
+
readonly selectLabel: (label: string, detail?: string) => string;
|
|
14
|
+
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import { resolveOutputFormat } from "../internal/output-format.js";
|
|
3
|
+
import { getTheme } from "../internal/theme-detect.js";
|
|
4
|
+
import { typography } from "../tokens/typography.js";
|
|
5
|
+
export const text = {
|
|
6
|
+
intro(content) {
|
|
7
|
+
const format = resolveOutputFormat();
|
|
8
|
+
if (format === "json")
|
|
9
|
+
return content;
|
|
10
|
+
if (format === "markdown")
|
|
11
|
+
return `**${content}**`;
|
|
12
|
+
return getTheme().intro(content);
|
|
13
|
+
},
|
|
14
|
+
heading(content) {
|
|
15
|
+
const format = resolveOutputFormat();
|
|
16
|
+
if (format === "json")
|
|
17
|
+
return content;
|
|
18
|
+
if (format === "markdown")
|
|
19
|
+
return `## ${content}`;
|
|
20
|
+
return getTheme().header(content);
|
|
21
|
+
},
|
|
22
|
+
section(content) {
|
|
23
|
+
const format = resolveOutputFormat();
|
|
24
|
+
if (format === "json")
|
|
25
|
+
return content;
|
|
26
|
+
if (format === "markdown")
|
|
27
|
+
return `**${content}**`;
|
|
28
|
+
return typography.bold(content);
|
|
29
|
+
},
|
|
30
|
+
command(content) {
|
|
31
|
+
const format = resolveOutputFormat();
|
|
32
|
+
if (format === "json")
|
|
33
|
+
return content;
|
|
34
|
+
if (format === "markdown")
|
|
35
|
+
return `\`${content}\``;
|
|
36
|
+
return getTheme().accent(content);
|
|
37
|
+
},
|
|
38
|
+
argument(content) {
|
|
39
|
+
const format = resolveOutputFormat();
|
|
40
|
+
if (format === "json")
|
|
41
|
+
return content;
|
|
42
|
+
if (format === "markdown")
|
|
43
|
+
return `<${content}>`;
|
|
44
|
+
return getTheme().muted(content);
|
|
45
|
+
},
|
|
46
|
+
option(content) {
|
|
47
|
+
const format = resolveOutputFormat();
|
|
48
|
+
if (format === "json")
|
|
49
|
+
return content;
|
|
50
|
+
if (format === "markdown")
|
|
51
|
+
return `\`${content}\``;
|
|
52
|
+
return chalk.yellow(content);
|
|
53
|
+
},
|
|
54
|
+
example(content) {
|
|
55
|
+
const format = resolveOutputFormat();
|
|
56
|
+
if (format === "json")
|
|
57
|
+
return content;
|
|
58
|
+
if (format === "markdown")
|
|
59
|
+
return `\`${content}\``;
|
|
60
|
+
return getTheme().muted(content);
|
|
61
|
+
},
|
|
62
|
+
usageCommand(content) {
|
|
63
|
+
const format = resolveOutputFormat();
|
|
64
|
+
if (format === "json")
|
|
65
|
+
return content;
|
|
66
|
+
if (format === "markdown")
|
|
67
|
+
return `\`${content}\``;
|
|
68
|
+
return chalk.green(content);
|
|
69
|
+
},
|
|
70
|
+
link(content) {
|
|
71
|
+
const format = resolveOutputFormat();
|
|
72
|
+
if (format === "json")
|
|
73
|
+
return content;
|
|
74
|
+
if (format === "markdown")
|
|
75
|
+
return `[${content}](${content})`;
|
|
76
|
+
return getTheme().accent(content);
|
|
77
|
+
},
|
|
78
|
+
muted(content) {
|
|
79
|
+
const format = resolveOutputFormat();
|
|
80
|
+
if (format === "json")
|
|
81
|
+
return content;
|
|
82
|
+
if (format === "markdown")
|
|
83
|
+
return `*${content}*`;
|
|
84
|
+
return getTheme().muted(content);
|
|
85
|
+
},
|
|
86
|
+
badge(content) {
|
|
87
|
+
const format = resolveOutputFormat();
|
|
88
|
+
if (format === "json")
|
|
89
|
+
return content;
|
|
90
|
+
if (format === "markdown")
|
|
91
|
+
return `[${content}]`;
|
|
92
|
+
return getTheme().badge(content);
|
|
93
|
+
},
|
|
94
|
+
selectLabel(label, detail) {
|
|
95
|
+
if (!detail) {
|
|
96
|
+
return label;
|
|
97
|
+
}
|
|
98
|
+
const format = resolveOutputFormat();
|
|
99
|
+
if (format !== "terminal") {
|
|
100
|
+
return `${label} — ${detail}`;
|
|
101
|
+
}
|
|
102
|
+
return `${label} ${typography.dim("—")} ${typography.dim(detail)}`;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { CellStyle } from "./types.js";
|
|
2
|
+
export interface StyledSegment {
|
|
3
|
+
text: string;
|
|
4
|
+
style: CellStyle;
|
|
5
|
+
}
|
|
6
|
+
export interface StyledLine {
|
|
7
|
+
segments: StyledSegment[];
|
|
8
|
+
}
|
|
9
|
+
export declare function hasAnsi(text: string): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Parse a block of text that may contain ANSI SGR escape codes into a sequence of
|
|
12
|
+
* logical lines split on "\n". Each line is a list of styled segments: contiguous
|
|
13
|
+
* printable runs of characters sharing the same style.
|
|
14
|
+
*
|
|
15
|
+
* Non-SGR CSI sequences and other control characters are discarded. `baseStyle` is
|
|
16
|
+
* used as the initial style and as the restore target for SGR reset / default color.
|
|
17
|
+
*/
|
|
18
|
+
export declare function parseAnsi(text: string, baseStyle?: CellStyle): StyledLine[];
|