UNPKG

askeroo

Version:

A modern CLI prompt library with flow control, history navigation, and conditional prompts

55 lines 2.28 kB
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime"; import { useEffect } from "react"; import { createPrompt } from "../../core/registry.js"; import { parseMarkdown, isMarkdownString, } from "../../utils/markdown.js"; import { Box, Text } from "ink"; /** * Log symbol and color mapping */ const LOG_CONFIG = { info: { symbol: "●", color: "blue" }, warn: { symbol: "▲", color: "yellow" }, error: { symbol: "■", color: "red" }, success: { symbol: "■", color: "green" }, }; // Internal plugin implementation const logInternal = createPrompt({ type: "log", component: ({ node, options, events }) => { const msg = options.message; const level = (options.level || "info"); const isMarkdown = isMarkdownString(msg); const config = LOG_CONFIG[level]; // Auto-submit when component becomes active useEffect(() => { if (node.state === "active" && events.onSubmit) { // setTimeout is now baked into onSubmit for auto submissions events.onSubmit({ type: "auto" }); } }, [node.state, events.onSubmit]); return (_jsx(Box, { flexDirection: "column", children: _jsxs(Box, { flexDirection: "row", alignItems: "flex-start", children: [_jsxs(Text, { color: config.color, children: [config.symbol, " "] }), _jsx(Box, { flexDirection: "column", children: parseMarkdown(isMarkdown ? msg.content : msg || "", isMarkdown ? { ...msg.theme, text: config.color } : { text: config.color }) })] }) })); }, }); // Public API functions for each log level export function logInfo(message, options) { return logInternal({ message, level: "info", ...options }); } export function logWarn(message, options) { return logInternal({ message, level: "warn", ...options }); } export function logError(message, options) { return logInternal({ message, level: "error", ...options }); } export function logSuccess(message, options) { return logInternal({ message, level: "success", ...options }); } // Create the main log object with methods export const log = { info: logInfo, warn: logWarn, error: logError, success: logSuccess, }; //# sourceMappingURL=index.js.map