@runtypelabs/ink-components 0.2.2 → 0.3.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/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { ComponentProps } from 'react';
2
+ import * as react from 'react';
3
+ import { ComponentProps, ReactNode } from 'react';
3
4
  import InkSpinner from 'ink-spinner';
4
5
 
5
6
  type InkSpinnerType = ComponentProps<typeof InkSpinner>['type'];
@@ -11,7 +12,7 @@ interface SpinnerProps {
11
12
  declare function Spinner({ label, color, type, }: SpinnerProps): react_jsx_runtime.JSX.Element;
12
13
 
13
14
  interface StatusBarProps {
14
- left?: string;
15
+ left?: ReactNode;
15
16
  center?: string;
16
17
  right?: string;
17
18
  }
@@ -25,7 +26,12 @@ interface StreamOutputProps {
25
26
  /** Lines to scroll up from the bottom (0 = follow latest) */
26
27
  scrollOffset?: number;
27
28
  }
28
- declare function StreamOutput({ content, isStreaming, enableMarkdown, maxVisibleLines, scrollOffset, }: StreamOutputProps): react_jsx_runtime.JSX.Element;
29
+ /**
30
+ * Render raw markdown content to terminal-styled text with ANSI color codes.
31
+ * Uses the module-level `marked` + `marked-terminal` configuration.
32
+ */
33
+ declare function renderMarkdownToTerminal(content: string): string;
34
+ declare const StreamOutput: react.NamedExoticComponent<StreamOutputProps>;
29
35
 
30
36
  interface ErrorDisplayProps {
31
37
  error: Error | string;
@@ -34,6 +40,7 @@ interface ErrorDisplayProps {
34
40
  declare function ErrorDisplay({ error, context }: ErrorDisplayProps): react_jsx_runtime.JSX.Element;
35
41
 
36
42
  declare const theme: {
43
+ readonly backgroundDeep: "#000000";
37
44
  readonly background: "#1b212b";
38
45
  readonly surface: "#202733";
39
46
  readonly surfaceMuted: "#1d2430";
@@ -72,4 +79,4 @@ interface ToolResult {
72
79
  duration?: number;
73
80
  }
74
81
 
75
- export { ErrorDisplay, type ErrorDisplayProps, Spinner, type SpinnerProps, StatusBar, type StatusBarProps, StreamOutput, type StreamOutputProps, type StreamPhase, type Theme, type ToolResult, theme };
82
+ export { ErrorDisplay, type ErrorDisplayProps, Spinner, type SpinnerProps, StatusBar, type StatusBarProps, StreamOutput, type StreamOutputProps, type StreamPhase, type Theme, type ToolResult, renderMarkdownToTerminal, theme };
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ import InkSpinner from "ink-spinner";
4
4
 
5
5
  // src/theme.ts
6
6
  var theme = {
7
+ backgroundDeep: "#000000",
7
8
  background: "#1b212b",
8
9
  surface: "#202733",
9
10
  surfaceMuted: "#1d2430",
@@ -63,7 +64,7 @@ function StatusBar({ left, center, right }) {
63
64
  paddingX: theme.panelPaddingX,
64
65
  paddingY: theme.panelPaddingY,
65
66
  children: [
66
- /* @__PURE__ */ jsx2(Box2, { flexGrow: 1, children: /* @__PURE__ */ jsx2(Text2, { color: theme.textMuted, children: left }) }),
67
+ /* @__PURE__ */ jsx2(Box2, { flexGrow: 1, children: typeof left === "string" ? /* @__PURE__ */ jsx2(Text2, { color: theme.textMuted, children: left }) : left }),
67
68
  center && /* @__PURE__ */ jsx2(Box2, { flexGrow: 1, justifyContent: "center", children: /* @__PURE__ */ jsx2(Text2, { color: theme.accent, children: center }) }),
68
69
  right && /* @__PURE__ */ jsx2(Box2, { children: /* @__PURE__ */ jsx2(Text2, { color: theme.textSubtle, children: right }) })
69
70
  ]
@@ -72,7 +73,7 @@ function StatusBar({ left, center, right }) {
72
73
  }
73
74
 
74
75
  // src/components/StreamOutput.tsx
75
- import { useMemo } from "react";
76
+ import { useMemo, memo } from "react";
76
77
  import { Box as Box3, Text as Text3 } from "ink";
77
78
  import chalk from "chalk";
78
79
  import InkSpinner2 from "ink-spinner";
@@ -154,7 +155,12 @@ marked.use(
154
155
  }
155
156
  )
156
157
  );
157
- function StreamOutput({
158
+ function renderMarkdownToTerminal(content) {
159
+ const stripped = stripAnsi(content);
160
+ if (!stripped) return "";
161
+ return marked.parse(stripped).trimEnd();
162
+ }
163
+ var StreamOutput = memo(function StreamOutput2({
158
164
  content,
159
165
  isStreaming,
160
166
  enableMarkdown = true,
@@ -169,20 +175,20 @@ function StreamOutput({
169
175
  }
170
176
  return stripped;
171
177
  }, [content, enableMarkdown]);
178
+ const lines = useMemo(() => rendered.split("\n"), [rendered]);
172
179
  const visible = useMemo(() => {
173
180
  if (!maxVisibleLines) return rendered;
174
- const lines = rendered.split("\n");
175
181
  const totalLines = lines.length;
176
182
  const clampedOffset = Math.min(scrollOffset, Math.max(0, totalLines - maxVisibleLines));
177
183
  const end = totalLines - clampedOffset;
178
184
  const start = Math.max(0, end - maxVisibleLines);
179
185
  return lines.slice(start, end).join("\n");
180
- }, [rendered, maxVisibleLines, scrollOffset]);
186
+ }, [rendered, lines, maxVisibleLines, scrollOffset]);
181
187
  return /* @__PURE__ */ jsxs3(Box3, { flexDirection: "column", children: [
182
188
  visible && /* @__PURE__ */ jsx3(Text3, { color: theme.text, children: visible }),
183
189
  isStreaming && /* @__PURE__ */ jsx3(Box3, { children: /* @__PURE__ */ jsx3(Text3, { color: theme.textMuted, children: /* @__PURE__ */ jsx3(InkSpinner2, { type: "dots" }) }) })
184
190
  ] });
185
- }
191
+ });
186
192
 
187
193
  // src/components/ErrorDisplay.tsx
188
194
  import { Box as Box4, Text as Text4 } from "ink";
@@ -208,6 +214,6 @@ export {
208
214
  Spinner,
209
215
  StatusBar,
210
216
  StreamOutput,
217
+ renderMarkdownToTerminal,
211
218
  theme
212
219
  };
213
- //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runtypelabs/ink-components",
3
- "version": "0.2.2",
3
+ "version": "0.3.1",
4
4
  "description": "Shared Ink (React for CLI) components for the Runtype CLI — spinners, status bars, streaming output, and error displays.",
5
5
  "license": "MIT",
6
6
  "author": "Runtype Labs",
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/components/Spinner.tsx","../src/theme.ts","../src/components/StatusBar.tsx","../src/components/StreamOutput.tsx","../src/components/ErrorDisplay.tsx"],"sourcesContent":["import type { ComponentProps } from 'react'\nimport { Box, Text } from 'ink'\nimport InkSpinner from 'ink-spinner'\nimport { theme } from '../theme.js'\n\ntype InkSpinnerType = ComponentProps<typeof InkSpinner>['type']\n\nexport interface SpinnerProps {\n label?: string\n color?: string\n type?: InkSpinnerType\n}\n\nexport function Spinner({\n label = 'Loading...',\n color = theme.spinner,\n type = 'dots',\n}: SpinnerProps) {\n return (\n <Box>\n <Text color={color}>\n <InkSpinner type={type} />\n </Text>\n <Text color={theme.textMuted}> {label}</Text>\n </Box>\n )\n}\n","export const theme = {\n background: '#1b212b',\n surface: '#202733',\n surfaceMuted: '#1d2430',\n surfaceElevated: '#252d3b',\n text: '#d8d3c9',\n textMuted: '#918b84',\n textSubtle: '#66625d',\n accent: '#8fc4bf',\n accentActive: '#a7d8d2',\n success: '#8ecb73',\n warning: '#d8ae63',\n danger: '#c97b73',\n border: '#394252',\n borderActive: '#546077',\n error: '#c97b73',\n info: '#8fc4bf',\n muted: '#918b84',\n primary: '#8fc4bf',\n secondary: '#a7d8d2',\n spinner: '#8fc4bf',\n progress: '#8fc4bf',\n label: '#d8d3c9',\n dimLabel: '#66625d',\n highlight: 'bold',\n separator: ' · ',\n sectionGap: 1,\n panelPaddingX: 1,\n panelPaddingY: 0,\n} as const\n\nexport type Theme = typeof theme\n","import { Box, Text } from 'ink'\nimport { theme } from '../theme.js'\n\nexport interface StatusBarProps {\n left?: string\n center?: string\n right?: string\n}\n\nexport function StatusBar({ left, center, right }: StatusBarProps) {\n return (\n <Box\n borderStyle=\"single\"\n borderColor={theme.border}\n backgroundColor={theme.background}\n paddingX={theme.panelPaddingX}\n paddingY={theme.panelPaddingY}\n >\n <Box flexGrow={1}>\n <Text color={theme.textMuted}>{left}</Text>\n </Box>\n {center && (\n <Box flexGrow={1} justifyContent=\"center\">\n <Text color={theme.accent}>{center}</Text>\n </Box>\n )}\n {right && (\n <Box>\n <Text color={theme.textSubtle}>{right}</Text>\n </Box>\n )}\n </Box>\n )\n}\n","import { useMemo } from 'react'\nimport { Box, Text } from 'ink'\nimport chalk from 'chalk'\nimport InkSpinner from 'ink-spinner'\nimport { type MarkedExtension, marked } from 'marked'\n// @ts-expect-error marked-terminal has no type declarations\nimport { markedTerminal } from 'marked-terminal'\nimport stripAnsi from 'strip-ansi'\nimport { theme } from '../theme.js'\n\nexport interface StreamOutputProps {\n content: string\n isStreaming: boolean\n enableMarkdown?: boolean\n maxVisibleLines?: number\n /** Lines to scroll up from the bottom (0 = follow latest) */\n scrollOffset?: number\n}\n\nconst bodyText = chalk.hex(theme.text)\nconst mutedText = chalk.hex(theme.textMuted)\nconst subtleText = chalk.hex(theme.textSubtle)\nconst accentText = chalk.hex(theme.accent)\nconst accentActiveText = chalk.hex(theme.accentActive)\nconst successText = chalk.hex(theme.success)\nconst warningText = chalk.hex(theme.warning)\nconst dangerText = chalk.hex(theme.danger)\n\nconst markdownHighlightTheme = {\n default: bodyText,\n keyword: accentText,\n built_in: accentActiveText,\n type: accentActiveText,\n literal: accentText,\n number: successText,\n regexp: warningText,\n string: bodyText,\n subst: accentText,\n symbol: bodyText,\n class: accentActiveText,\n function: accentActiveText,\n title: accentActiveText,\n params: mutedText,\n comment: subtleText,\n doctag: subtleText,\n meta: subtleText,\n 'meta-keyword': accentText,\n 'meta-string': mutedText,\n section: accentText,\n tag: accentText,\n name: accentActiveText,\n 'builtin-name': accentActiveText,\n attr: accentText,\n attribute: accentText,\n variable: accentActiveText,\n bullet: mutedText,\n code: successText,\n emphasis: accentText,\n strong: accentActiveText,\n formula: accentText,\n link: accentActiveText,\n quote: mutedText,\n addition: successText,\n deletion: dangerText,\n} as const\n\n// Configure marked with terminal renderer once at module level.\nmarked.use(\n markedTerminal(\n {\n code: successText,\n blockquote: mutedText,\n html: subtleText,\n heading: accentText,\n firstHeading: accentActiveText.bold,\n hr: subtleText,\n listitem: bodyText,\n list: (body: string) => bodyText(body),\n table: mutedText,\n paragraph: bodyText,\n strong: accentActiveText.bold,\n em: accentText.italic,\n codespan: successText,\n del: subtleText.strikethrough,\n link: accentActiveText,\n href: mutedText.underline,\n text: bodyText,\n showSectionPrefix: false,\n reflowText: false,\n },\n {\n ignoreIllegals: true,\n theme: markdownHighlightTheme,\n }\n ) as MarkedExtension\n)\n\nexport function StreamOutput({\n content,\n isStreaming,\n enableMarkdown = true,\n maxVisibleLines,\n scrollOffset = 0,\n}: StreamOutputProps) {\n const rendered = useMemo(() => {\n // Strip incoming ANSI codes, then re-render via marked-terminal if enabled\n const stripped = stripAnsi(content)\n if (!stripped) return ''\n if (enableMarkdown) {\n return (marked.parse(stripped) as string).trimEnd()\n }\n return stripped\n }, [content, enableMarkdown])\n\n // Window to N lines with optional scroll offset from bottom\n const visible = useMemo(() => {\n if (!maxVisibleLines) return rendered\n const lines = rendered.split('\\n')\n const totalLines = lines.length\n const clampedOffset = Math.min(scrollOffset, Math.max(0, totalLines - maxVisibleLines))\n const end = totalLines - clampedOffset\n const start = Math.max(0, end - maxVisibleLines)\n return lines.slice(start, end).join('\\n')\n }, [rendered, maxVisibleLines, scrollOffset])\n\n return (\n <Box flexDirection=\"column\">\n {visible && <Text color={theme.text}>{visible}</Text>}\n {isStreaming && (\n <Box>\n <Text color={theme.textMuted}>\n <InkSpinner type=\"dots\" />\n </Text>\n </Box>\n )}\n </Box>\n )\n}\n","import { Box, Text } from 'ink'\nimport { theme } from '../theme.js'\n\nexport interface ErrorDisplayProps {\n error: Error | string\n context?: string\n}\n\nexport function ErrorDisplay({ error, context }: ErrorDisplayProps) {\n const message = error instanceof Error ? error.message : error\n const cause =\n error instanceof Error && error.cause ? String(error.cause) : undefined\n\n return (\n <Box flexDirection=\"column\" marginTop={theme.sectionGap}>\n <Text color={theme.danger} bold>\n Error{context ? ` ${context}` : ''}: {message}\n </Text>\n {cause && <Text color={theme.textMuted}>Cause: {cause}</Text>}\n </Box>\n )\n}\n"],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