ModApi: Widget system & Footer

未關閉
#635 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
5/5
預估耗時
一週以上
新手友好度
30/100
Issue 類型
功能
描述清晰度
基本清楚
活躍度
活躍
技術堆疊
typescript
領域
cli

研究方向

先定位 cmd.ui.widget()、w.update() 和 cmd.ui.setStatus() 這些 entry point,以及它們所提供資料的 TUI renderer。在進行任何變更之前,先定義 widget rendering、status badges、shared theming 和 double-buffering 的範圍;當要求的行為能夠無閃爍地運作,並且 mods 可以使用時,即表示完成。

由索引模型根據 Issue 內容生成。

描述

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.widget() — actually wired in the TUI

Problem: cmd.ui.widget() exists in the API and is used in community mods (e.g. David Thyresson's weather mod), but it's currently a no-op — the widget renders nowhere. The docs explicitly say: "Widgets are not wired into the TUI yet."

Use case: Any mod that wants to show persistent information above the editor (status, live counter, etc.) is currently blocked. The code exists; it just needs to be wired up.


2. w.update() — update a widget without recreating it

Problem: To update a widget's content, you have to .dispose() it and create a new one. This causes flickering and unnecessary boilerplate.

Use case: Any widget displaying live or periodically refreshed data needs to update its content without destroying and recreating the whole component.

const w = cmd.ui.widget({ render: () => ['loading...'] });
// later:
w.update(() => [`${count} items`]);

3. Structured cmd.ui.setStatus() with colored badges

Problem: setStatus() only supports plain text in the footer. No color, no icon, no badge styling.

Use case: A mod that tracks some state would benefit from a colored, iconified badge in the footer rather than unformatted text.

cmd.ui.setStatus([
  { text: 'active', color: 'green', icon: '●' },
  { text: '14 items', color: 'yellow', icon: '📦' },
]);

4. Theming / shared color palette across mods

Problem: Every mod hardcodes its own colors. There's no way to share a theme across multiple mods, or let the user customize the visual style.

Use case: An author publishing a set of related mods would want them to share a consistent visual identity without duplicating ANSI constants across every file. Users would benefit from being able to adjust colors to match their terminal theme.

#PART 2

4. Double-buffering — Flicker-free rendering

Problem: When a mod updates its display (widget refresh, status change, progress bar), the entire screen redraws character by character, causing visible flicker. This is the TUI equivalent of a 1995 web page. The user sees the screen flash on every update, which makes live data displays unusable.

Use case: A mod that updates a live counter or progress bar every second produces visible flickering that makes the interface feel broken. Double-buffering renders to an off-screen buffer first, then swaps atomically — zero flicker, smooth updates.

// Implicit — the TUI renderer handles it
// But needs to be enabled/wired at the framework level
cmd.ui.enableDoubleBuffer();

References: terminui (double-buffered by default — "renders to an off-screen buffer, then flushes to the terminal in one write"), Ratatui (full double-buffer with implicit flush — the standard for Rust TUIs), Ink (React reconciliation = implicit double-buffer via virtual DOM diffing). No modern TUI renders directly to stdout anymore. The old approach causes flicker because each character write triggers a terminal repaint.

Use Case

No response

Additional Context

No response

How important is this to you?

None

主要語言
沒有語言資料
星號
4k
分支
350
PR 合併指標
30 天內沒有已合併 PR

貢獻指南

這個儲存庫沒有索引到貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

CommandCodeAI/command-code 的其他 Issue

查看 CommandCodeAI/command-code 的全部 Issue

相似的 Issue

更多 CLI Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。