CommandCodeAI / CommandCodeAI/command-code

ModApi: UI Layout & Display primitives

未关闭
#633 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
没有语言数据
星标
4k
派生
350
PR 合并指标
30 天内没有已合并 PR

描述

Feature Description

Disclaimer: This message was synthesized by an AI from a long, unstructured Markdown file of notes accumulated while building real mods. Use cases have been kept intentionally simple and generic. If anything seems off or incoherent, feel free to ask for clarification.

1. cmd.ui.panel() / cmd.ui.divider() — native layout helpers

Problem: Every mod that wants to display a panel or separator has to rewrite the same ~50 lines of utilities (terminal width handling, ANSI, padding). There's no visual consistency across community mods.

Use case: Any mod that displays structured output in the feed currently duplicates the same layout boilerplate. A shared cmd.ui.panel(['line 1'], { title: 'my-mod' }) and cmd.ui.divider() would give all mods a consistent look for free.


2. cmd.ui.table() — structured data display

Problem: Displaying a formatted table requires manual .padEnd() per column, which breaks as soon as data changes or the terminal is too narrow.

Use case: Any mod that shows structured data with multiple columns (name, value, status, etc.) would benefit from a standard table primitive rather than fragile manual padding.

cmd.ui.table({
  headers: ['Name', 'Value', 'Status'],
  rows: [['item-1', '42', 'ok']],
  align: ['left', 'right', 'left'],
});

3. cmd.ui.spacing() — explicit spacing

Problem: Adding blank lines between display blocks currently requires console.log(""). This is non-standard and bypasses the API.

Use case: Any mod that displays multiple panels or sections needs a clean, idiomatic way to add vertical spacing.

cmd.ui.spacing(2); // 2 blank lines

4. cmd.ui.clearFeed() — clear the feed

Problem: There's no way to clear old messages from the feed. A mod that displays updates periodically accumulates lines that stay forever.

Use case: A mod that shows a regularly updated report should be able to clear its previous output and redisplay cleanly, rather than appending duplicate blocks on every update.

cmd.ui.clearFeed({ keepLast: 5 });

PART2

1. cmd.ui.layout() — Native layout system (flexbox/grid)

Problem: There is no way to position elements relative to each other. Every mod stacks panel() on top of panel() and manually handles padding and width. When the terminal is too narrow, everything breaks. There is no visual consistency across community mods because each one reinvents its own layout boilerplate.

Use case: A mod that displays a dashboard with stats on top and a chart below must manually calculate widths, handle line wrapping, and adapt to terminal size. A native layout system would solve this in one call.

cmd.ui.layout({
  direction: 'column',
  children: [
    cmd.ui.box({ flex: 1, children: [statsPanel] }),
    cmd.ui.box({ flex: 2, children: [chartPanel] }),
  ],
});

References: OpenTUI (native Flexbox with Box and Text components — used in production by OpenCode), Ink (React Flexbox for terminals — used by Claude Code, Amp, Gemini CLI), Ratatui (constraints system with min/max widths — used by Netflix, AWS, OpenAI), terminui (layout engine with JSX — 10+ widgets). The TUI Renaissance article (2026) notes: "Every modern TUI has a layout system — it's the foundation."


2. Responsive layout — Terminal resize handling

Problem: When the user resizes the terminal window, mod outputs break — panels overflow, text gets cut off, alignment is lost. There is no way for a mod to react to resize events or define minimum sizes.

Use case: A mod that displays a table with 5 columns should collapse to 3 columns when the terminal is narrow, or switch to a compact view. Currently it just wraps ugly and becomes unreadable.

cmd.ui.onResize(({ width, height }) => {
  if (width < 80) setCompactMode(true);
});

References: OpenTUI (terminal-aware rendering with layout constraints), Ink (automatic resize handling via React reconciler), Ratatui (layout constraints with min/max widths — flexgrow/flexshrink), Bubble Tea (WindowMsg for resize events). Every modern TUI handles this gracefully.


3. Native Code / Markdown / Diff components

Problem: Displaying code blocks, markdown, or diffs requires manual ANSI formatting. There is no syntax highlighting, no markdown rendering, no word-level diff — just raw text with bold/italic. Mods that show code reviews or file changes produce unreadable output.

Use case: A mod that shows a code review or file diff should display syntax-highlighted code with proper indentation, not plain text with manual color codes. A mod that displays documentation should render markdown headings, lists, and code blocks correctly.

cmd.ui.code({ language: 'typescript', content: codeString });
cmd.ui.markdown({ content: readmeContent });
cmd.ui.diff({ old: original, new: modified });

References: OpenTUI (Code, Markdown, Diff, Tree-sitter components — native syntax highlighting for any language), bat (syntax highlighting for 200+ languages — 63K GitHub stars), delta (word-level diff with syntax highlighting — used by Claude Code), Tree-sitter (incremental parsing — used by Neovim, Zed). These are solved problems in the TUI ecosystem.

7. cmd.ui.image() — Native image rendering with thumbnail/expand

Problem: There is no way to display images inline in the terminal feed. Mods that want to show visual content must use a text placeholder like [#1image] or skip them entirely.

Use case: A mod that generates reports, previews, or visual summaries should display a small thumbnail image in the feed. When the user selects it, the image expands to full size. On terminals that support image protocols (Kitty, Sixel, iTerm2), thumbnails render as actual images. On unsupported terminals, a styled placeholder is shown.

cmd.ui.image({
  path: '/path/to/chart.png',
  width: 20,  // thumbnail width in columns
  expandable: true,  // click to view full size
});

References: OpenTUI (native Image component), Ratatui (ratatui-image — Kitty/Sixel/iTerm2), Textual (textual-image), Ink (ink-image), chafa (auto-detects protocol — 4.9K stars), timg (image + video viewer — 2.7K stars). Three protocols exist today: Kitty graphics (best quality), Sixel (broadest compat), iTerm2 inline (macOS). WezTerm supports all three. Fallback on unsupported terminals shows a styled placeholder.

No response

Additional Context

No response

How important is this to you?

None

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

未指定任何文件、测试或入口点。首先定位现有的 cmd.ui API 和 feed 渲染实现,然后确定所提议的布局、调整大小、富内容和图像 primitive 中哪些属于范围。只有在确定了一个达成共识且可测试的范围以及相应的 API 行为(包括终端大小和不受支持终端的处理)后,才能视为完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
typescript
领域
cli
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
活跃
描述清晰度
需要澄清
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。