cx-wealthy 0.9.0__tar.gz

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.
@@ -0,0 +1,195 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+ /temp/
54
+
55
+ # Django stuff:
56
+ *.log
57
+ local_settings.py
58
+ db.sqlite3
59
+ db.sqlite3-journal
60
+
61
+ # Flask stuff:
62
+ instance/
63
+ .webassets-cache
64
+
65
+ # Scrapy stuff:
66
+ .scrapy
67
+
68
+ # Sphinx documentation
69
+ docs/_build/
70
+
71
+ # PyBuilder
72
+ .pybuilder/
73
+ target/
74
+
75
+ # Jupyter Notebook
76
+ .ipynb_checkpoints
77
+
78
+ # IPython
79
+ profile_default/
80
+ ipython_config.py
81
+
82
+ # pyenv
83
+ # For a library or package, you might want to ignore these files since the code is
84
+ # intended to run in multiple environments; otherwise, check them in:
85
+ .python-version
86
+
87
+ # pipenv
88
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
90
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
91
+ # install all needed dependencies.
92
+ Pipfile.lock
93
+
94
+ # UV
95
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
96
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
97
+ # commonly ignored for libraries.
98
+
99
+ # poetry
100
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
101
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
102
+ # commonly ignored for libraries.
103
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
104
+ poetry.lock
105
+
106
+ # pdm
107
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
108
+ #pdm.lock
109
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
110
+ # in version control.
111
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
112
+ .pdm.toml
113
+ .pdm-python
114
+ .pdm-build/
115
+
116
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
117
+ __pypackages__/
118
+
119
+ # Celery stuff
120
+ celerybeat-schedule
121
+ celerybeat.pid
122
+
123
+ # SageMath parsed files
124
+ *.sage.py
125
+
126
+ # Environments
127
+ .env
128
+ .venv
129
+ /.venv*/
130
+ env/
131
+ venv/
132
+ ENV/
133
+ env.bak/
134
+ venv.bak/
135
+
136
+ # Spyder project settings
137
+ .spyderproject
138
+ .spyproject
139
+
140
+ # Rope project settings
141
+ .ropeproject
142
+
143
+ # mkdocs documentation
144
+ /site
145
+
146
+ # mypy
147
+ .mypy_cache/
148
+ .dmypy.json
149
+ dmypy.json
150
+
151
+ # Pyre type checker
152
+ .pyre/
153
+
154
+ # pytype static type analyzer
155
+ .pytype/
156
+
157
+ # Cython debug symbols
158
+ cython_debug/
159
+
160
+ # PyCharm
161
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
162
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
163
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
164
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
165
+ #.idea/
166
+
167
+ # Ruff stuff:
168
+ .ruff_cache/
169
+
170
+ # PyPI configuration file
171
+ .pypirc
172
+
173
+
174
+ /temp/
175
+ py.typed
176
+ # Agent & IDE directories
177
+ .vscode/
178
+ .idea/
179
+ .vs/
180
+ .qoder/
181
+ .trae/
182
+ .claude/
183
+ .cursor/
184
+ .windsurf/
185
+ .cline/
186
+ .roo/
187
+ .aider/
188
+ .continue/
189
+ .codex/
190
+ .codegraph/
191
+
192
+
193
+ # Other files and directories
194
+ *.log
195
+ *.bak
@@ -0,0 +1,146 @@
1
+ # cx-wealthy 工作区指南
2
+
3
+ > 本文件是根目录 `AGENTS.md` 在 `cx-wealthy` 工作区的特化补充。全局约定(命名、类型标注、Git workflow、版本策略、i18n 政策等)见根文件,此处不重述。本文件仅记录本工作区独有的定位、设计原则、协议定义与代码风格偏离点。
4
+
5
+ ## 定位
6
+
7
+ `cx-wealthy` 是基于 [Rich](https://github.com/Textualize/rich) 的终端结构化文档与 UI 组件库,提供两大核心能力:
8
+
9
+ 1. **通用结构化文档系统**——基于复合树的声明式文档构建与主题化渲染。帮助系统只是其特化之一,任何"分组 + 条目 + 注释"的结构化输出都可使用。
10
+ 2. **双渲染协议**——`__rich_label__`(紧凑标签)+ `__rich_detail__`(键值面板),通过 mixin 让领域对象自身可被 `console.print()` 直接渲染。
11
+
12
+ **双重定位**:本包首先是 cx 系列自用的 Rich 扩展,同时作为独立库可供任何人使用。沿用 Rich 自身的 mixin 命名风格、提供 `rich_types` 便利出口等设计均在此定位下进行——对内服务于 cx 系列工具,对外不绑定 cx 系列的依赖与惯例。
13
+
14
+ **依赖**:仅 `rich>=14.0.0`。不依赖 `cx-studio`——UI 库应保持单一职责与最小依赖链。所需的基础工具函数(分隔符插入、locale 检测)逻辑很短,在包内内联实现,不为短函数引入整包依赖。
15
+
16
+ **依赖关系**:与 `cx-studio` 无依赖关系,两者在依赖层面平级;`cxalio-studio-tools` 同时依赖两者。`cx-wealthy` 仍是 cx- 系列的一员,提供 `cx.*` 命名空间的主题样式预设(纯数据导出,不引入依赖)。
17
+
18
+ ## 核心设计原则
19
+
20
+ ### 通用核心与特化分层
21
+
22
+ `document/` 是通用复合树核心(`Node`/`Group`/`Note`/`WealthyDocument`),`help/` 是帮助系统特化层(`Action`/`WealthyHelp` 继承 `WealthyDocument`)。通用核心不知道 flags/nargs/usage 为何物。
23
+
24
+ 合并两者会导致通用核心的稳定性被 help 的迭代绑架——help 一变通用核心就要跟着变。且通用复合树被封装在 help 内部时,使用方不会想到它还能渲染非帮助类的结构化文档,能力被埋没。
25
+
26
+ ### mixin + 包装器双轨
27
+
28
+ 渲染协议用 mixin 承载(非 Protocol):mixin 提供默认 `__rich__` 实现,使 `console.print(obj)` 直接输出正确渲染——"协议即渲染"。同时提供包装器(`RichLabel`/`WealthyDetailPanel`)给不愿或不能继承的使用方(第三方类型、frozen dataclass 继承位已满等)。两者共享底层渲染逻辑。
29
+
30
+ Protocol-only 不可取:Protocol 不允许带方法体,"协议即渲染"无法成立——所有使用方都必须显式 `console.print(RichLabel(obj))`,丢失直接打印的体验。mixin 只定义方法不定义字段,与 frozen dataclass 完全兼容,无实质冲突。
31
+
32
+ ### rich_types 仅作对外便利出口
33
+
34
+ `rich_types` 模块是给使用方的 `r` 别名出口(与项目 `r` 约定一致),收窄到高频类型。**库内部一律用真实 import 路径**(`from rich.table import Table`)。
35
+
36
+ 内部用别名会损失 IDE 跳转精度、类型推断绕一道、grep 无法区分真实类型与别名。新增 Rich 类型时内部直接 import 零成本,不需要同步注册到 rich_types。
37
+
38
+ ### 标准渲染范式
39
+
40
+ 所有 `__rich_console__` 实现**必须 yield 渲染对象**,禁止直接调用 `console.render()` 返回。直接返回会绕过 Rich 的渲染管线。
41
+
42
+ ### 诚实命名
43
+
44
+ 组件命名必须反映实际行为。例如列布局组件命名为 `MaxColumnsLayout`(固定最大列数 + 平均宽度),而非暗示动态测量的名字——除非真正实现了基于内容宽度的动态列数计算。名实不符会误导使用方对 API 契约的预期。
45
+
46
+ ### 不做 i18n
47
+
48
+ 本包不创建 `i18n/` 模块。作为 UI 组件库,其自身输出的文字(面板标题、占位符等)属于框架固定文本,由使用方控制而非库自行翻译。创建空壳 i18n 模块后,每次新增字符串都要思考"要不要包 `_()`",这个心智负担在零翻译需求下是纯成本。若未来确有需求,按项目既有 i18n 方案落地。
49
+
50
+ ### 不做 argparse 包装器
51
+
52
+ `WealthyHelp` 不提供 `from_argparse(parser)` 适配器。argparse 的扁平字段信息不足以驱动声明式排版,且生态中已有大量 argparse 美化器。本包的价值在于独立于任何解析器的声明式排版能力。
53
+
54
+ ## 渲染协议定义
55
+
56
+ 本包是 `__rich_label__` / `__rich_detail__` 双渲染协议的定义者。根 AGENTS 描述了协议的基本形态,此处补充定义性约定。
57
+
58
+ ### `__rich_label__`:紧凑标签
59
+
60
+ - yield 一组 Renderable 片段,用分隔符拼接为单行 `Text`
61
+ - 用于列表行标题、行内摘要等紧凑场景
62
+ - `RichLabelMixin` 提供默认 `__rich__`,`RichLabel` 是包装器,共享同一套渲染逻辑
63
+
64
+ ### `__rich_detail__`:键值面板
65
+
66
+ - yield `(key, value)` 或 `(key, value, default)` 三元组;三元组中 `value == default` 时该行不显示(去重)
67
+ - value 若实现同协议则自动嵌套渲染为 sub-panel;value 为列表自动渲染为 `IndexedListPanel`
68
+ - `RichDetailMixin` 提供默认 `__rich__`(包装为 `WealthyDetailPanel`),`WealthyDetailPanel`/`WealthyDetailTable` 是包装器
69
+
70
+ **key/value 的字符串语义**:
71
+
72
+ - `str` 类型的 key/value → 逐字显示,不解析 markup(数据安全)
73
+ - `Text` 类型的 key/value → 保留已有样式(用于需要 markup 的展示标签)
74
+ - 需要 markup 格式的 key/value,yield `Text.from_markup(...)` 而非裸字符串
75
+
76
+ 这与 `__rich_label__` 的默认行为不同——label 的片段是展示字符串(`_fragment_to_text` 默认解析 markup),detail 的 value 是领域数据(默认逐字显示)。
77
+
78
+ ### `__rich_detail__` ≠ `__rich_repr__`
79
+
80
+ 两者不互相替代,语义不同:
81
+
82
+ | 维度 | `__rich_repr__`(Rich 原生) | `__rich_detail__`(本包) |
83
+ |---|---|---|
84
+ | 语义 | debug repr——"对象长什么样" | 展示——"对象该展示哪些字段" |
85
+ | value 渲染 | `Pretty`(repr 风格,raw 值) | 递归 sub-panel / IndexedListPanel / RichLabel 协同 |
86
+ | 格式化 | raw 值交给 Pretty | 使用方可预格式化(如 `str(path)`) |
87
+
88
+ `__rich_detail__` 吸收了 `__rich_repr__` 的去重能力(三元组),但保留展示视角的渲染策略链。复用 `__rich_repr__` 替代 `__rich_detail__` 会丢失嵌套渲染、展示视角格式化、与 IndexedListPanel/RichLabel 的协同——这些是 detail 面板的核心价值。
89
+
90
+ ### 协议是可选的
91
+
92
+ `__rich_label__` 和 `__rich_detail__` 是并列的可选协议——使用方按展示场景二选一或都实现,不应为实现而写空的协议方法或抛 `NotImplementedError`。不是所有领域对象都适合键值面板展示。
93
+
94
+ ## 否决方案记录
95
+
96
+ 以下方案在本包设计中被提出并否决,记录理由以防重新提出。每条只记否决依据,不记方案细节。
97
+
98
+ 1. **复用 `__rich_repr__` 替代 `__rich_detail__`**——repr 的 value 由 `Pretty` 渲染(repr 风格),没有"value 若实现同协议则自动嵌套为 sub-panel"的约定,丢失嵌套展示能力。展示场景使用方需要预格式化(如 `str(path)` → 文件名而非 `PosixPath('/foo/bar')`),repr 期望 raw 值,复用会强制使用方在 yield 前自行包装,更繁琐。
99
+
100
+ 2. **Protocol-only(不提供 mixin 默认实现)**——"协议即渲染"无法成立,所有使用方都必须显式包装,与 Rich 自身"`__rich__` 即渲染"的约定背离。
101
+
102
+ 3. **Wrapper-only(不提供 mixin,只用包装器)**——detail 面板的 value 若是可展示对象,需要该对象**自身具备 `__rich__`** 才能自动以标签形态嵌套渲染。包装器 `RichLabel(obj)` 是外层包装,`obj` 自身没有 `__rich__`,在 detail 面板中作为 value 时不会被识别为可渲染对象。mixin 让对象自身具备 `__rich__`,是 detail 嵌套渲染的前置依赖。
103
+
104
+ 4. **不分层,全部塞在 help/ 里**——通用核心的稳定性被 help 的迭代绑架;通用复合树被封装在 help 内部时,使用方不会想到它还能渲染非帮助类结构化文档。
105
+
106
+ 5. **依赖 cx-studio**——本包对 cx-studio 的唯一潜在需求是短工具函数(分隔符插入约 10 行、locale 检测约 10 行),内联即可实现,为这些引入整包依赖不划算。
107
+
108
+ 6. **照搬项目 i18n 惯例创建 i18n 模块**——本包没有需要翻译的字符串,空壳 i18n 模块引入心智负担且违反项目硬约束(空翻译文件有覆盖 msgid 的风险)。
109
+
110
+ 7. **提供 `from_argparse(parser)` 适配器**——argparse 的扁平字段不足以驱动声明式排版,包装产出的排版无法达到独立构建的灵活度;生态有成熟 argparse 美化器,不应在此重复。
111
+
112
+ 8. **在初始版本直接做真正的动态列测量**——真正基于 `Measurement.get` 的动态测量复杂度被低估,且单点需求不足以验证必要性。诚实命名(`MaxColumnsLayout`)比名实不符更好。
113
+
114
+ ## 代码风格特化
115
+
116
+ 以下约定与根 AGENTS 的通用规则存在偏离或补充,仅适用于本工作区。
117
+
118
+ ### 导出:显式 `__all__`,不用 star-import
119
+
120
+ 根 AGENTS 规定"每个子包通过 `__init__.py` star-import 汇聚公开符号"。**本包偏离此规则**:每个模块定义 `__all__`,`__init__.py` 显式列出每个导出符号。目的:不泄漏 `typing`/`Literal` 等第三方符号,导出边界可控。
121
+
122
+ ### Rich 类型引用:内部真实路径
123
+
124
+ 根 AGENTS 规定"依赖 cx-wealth 的包必须通过 rich_types 引用 Rich 类型"。**本包特化此规则**:该约束针对使用方,不针对本包内部。库内部模块用 `from rich.table import Table` 真实路径,`rich_types` 仅作对外便利出口。
125
+
126
+ ### 私有命名:无双下划线
127
+
128
+ 内部辅助方法用单下划线前缀(如 `_render_label`、`_check_value`),不用双下划线。双下划线触发 name mangling,子类无法 override。
129
+
130
+ ### 主题透明性
131
+
132
+ 组件不持有主题——`WealthyDocument` / `WealthyHelp` 均无 `styles` / `theme` / `DEFAULT_STYLES` 属性,也不在渲染时导入或补全任何主题。组件内 `style="cx.*"` 等样式名是**约定**,由调用方通过 `Console(theme=...)` 决定样式值。
133
+
134
+ - **cxalio tools**:在 `IAppEnvironment` 中 `Console(theme=cx_default_theme)` 应用 cx 主题
135
+ - **第三方使用方**:不设主题时 `cx.*` 样式静默不生效(Rich 默认行为),内容仍完整可读;需样式时导入 `default_theme` 设为 Console 主题
136
+
137
+ `default_theme` 与 `BASE_STYLES` / `HELP_STYLES` / `DETAIL_STYLES` / `INDEXED_LIST_STYLES` 等常量在 `theme.py` 定义并对外导出,供调用方按需引用或覆盖。
138
+
139
+ 组件**不使用** Rich 私有 API(如 `console._theme_stack`)。曾考虑在 `__rich_console__` 中检测缺失样式并兜底补全,但因依赖私有 API 被否决——没有公开 API 能实现"选择性补全缺失样式但不覆盖用户定义",而无条件的 `console.use_theme(default_theme)` 会覆盖调用方自定义的 `cx.*` 样式,违反透明性。
140
+
141
+
142
+ ## 扩展判断原则
143
+
144
+ 本库作为 UI 组件库,天然面临"提前抽象"的诱惑——每个组件看起来都可复用,每个渲染分支看起来都可策略化,每个特化场景看起来都可泛化。
145
+
146
+ **扩展的触发条件是"第二个真实使用场景出现",不是"技术上能做到更灵活"。** 当某场景只有一个使用方时,让使用方用 Rich 原生 API 凑合,而非提取入库。需求不出现的点保持简单,这是正确状态,不是待办。
@@ -0,0 +1,109 @@
1
+ # Changelog
2
+
3
+ ## 0.9.0
4
+
5
+ ### 版本统一
6
+
7
+ - 本次与其余包同步发布,统一版本号为 0.9.0
8
+
9
+ ### 展示字段重命名与语义统一
10
+
11
+ - **`descriptor` → `detailer` 全量重命名**:统一「渲染器」命名(`titler` / `detailer` 对称),覆盖
12
+ `Node`、`Group`、`Action`、`HelpGroup` 四个类的属性名、方法名(`_default_descriptor` → `_default_detailer`)、
13
+ kwargs key(`"descriptor"` → `"detailer"`)及所有 docstring 引用。
14
+ - **公共 API 参数 `description=` → `detail=`**:`add_group` / `add_command` / `add_action` 的
15
+ 描述参数从 `description=` 统一改为 `detail=`,与 `Node.detail` 语义字段同名,消除「对外叫 description、
16
+ 内部叫 detail」的双轨命名。
17
+ - **`add_note` 透传支持**:`Group.add_note` / `WealthyDocument.add_note` 增加 `**kwargs`
18
+ 参数,支持透传 `titler` / `detailer`,与 `add_group` 等接口对齐。
19
+ - **Node 类 docstring 重写**:完整说明 `name`/`detail`(语义字段)、`titler`/`detailer`(渲染器)、
20
+ `title`/`description`(计算属性)六者关系,以及 `title`/`description` 的三条计算路径(显式 None / 非 callable 回退 /
21
+ callable 替代)。
22
+
23
+ ### 调用方迁移
24
+
25
+ - **hosts_keeper `app_help.py`**:16 处 `description=` → `detail=`
26
+ - **jpegger `simple_appcontext.py`**:13 处 `description=` → `detail=`(argparse 的 `description=`
27
+ 保留不变)
28
+
29
+ ### 禁止范围
30
+
31
+ - `media_killer`、`media_scout`、`ffpretty`、`cx_wealth`(旧包)均未触碰,仍使用旧版接口。
32
+
33
+ ## 0.3.0
34
+
35
+ ### 架构重构
36
+
37
+ - **HelpGroup 单类取代 ActionGroup + CommandGroup**:能力重复的两个类合并为单一 `HelpGroup(Group)`,通过 `commands` 字段区分参数分组语义(`commands=()`)与命令语义(`commands=("list",)`)。
38
+ - 删除 `ActionGroup` 与 `CommandGroup` 类、`command_group.py`、`action_group.py` 文件
39
+ - 删除 `add_command_group()` 方法(分组用 `add_group()`)
40
+ - 删除 `is_nested` 属性(死代码)
41
+ - 新增 `HelpGroup.iter_commands()` 递归遍历辅助方法
42
+ - 渲染层 `isinstance(x, CommandGroup)` → `isinstance(x, HelpGroup) and x.is_command`
43
+ - **所有现有 CLI 工具的 --help 输出字面不变**
44
+ - **导出更新**:`ActionGroup`、`CommandGroup` 从 `cx_wealthy` / `cx_wealthy.help` 导出中删除,新增 `HelpGroup`
45
+
46
+ ### 修复
47
+
48
+ - **恢复文档导入**:`cx_wealthy/__init__.py` 中补回误删的 `from .document import Group, Node, Note, WealthyDocument`——`__all__` 中仍列出这些符号但导入被意外移除。
49
+ - **恢复 epilog 样式**:`theme.py` 中补回误删的 `cx.help.epilog` 样式,epilog 文本不再回退到默认 Rich 样式。
50
+ - **usage 渲染修复**(三个渲染 bug):
51
+ - 修复子命令详版行与首行不对齐:将混合的 Table+Padding 结构统一为双列 Table,prog 末尾空格作列间分隔,所有行在同一右列中自然对齐。
52
+ - 修复 usage 与 description 左 padding 不一致:Table 统一加 `Padding(pad=(0,0,0,2))`。
53
+ - 修复子命令 pipe 排在参数后面:简版行拼接顺序从 `path → actions → sub_commands` 改为 `path → sub_commands → actions`,符合 CLI 惯例。
54
+ - **列间距职责上移**:前导空格从 `_render_node_usage` 的简版行内部提取到 Table 层(prog 末尾空格),不再由数据层隐含提供。
55
+
56
+ ## 0.2.0
57
+
58
+ ### 新特性
59
+
60
+ - **CommandGroup 机制**:`WealthyHelp` 新增 `CommandGroup` 类型,原生支持子命令结构(git/docker 风格 CLI)。
61
+ - `CommandGroup` 继承 `ActionGroup`,兼具命令本身与组织容器两种角色
62
+ - `add_command(*keywords, name=, description=)` / `add_command_group(name=, description=)` API
63
+ - 递归 usage 渲染:简版总览行 + 每个子命令详版行,支持嵌套
64
+ - details 渲染:CommandGroup 作为子命令区块,递归展开
65
+ - 无 CommandGroup 的工具(如 jpegger)行为完全不变
66
+ - **新增样式**:`cx.help.usage.command`(命令关键词样式)
67
+ - **新增导出**:`CommandGroup` 在 `cx_wealthy` 和 `cx_wealthy.help` 顶层导出
68
+
69
+ ### 文档
70
+
71
+ - 新增 `docs/wealthy-help-guide.md`:WealthyHelp 完整用法文档
72
+ - README 简要介绍补充 CommandGroup 示例
73
+
74
+ ## 0.1.2
75
+
76
+ 修正 0.1.1 引入的问题:
77
+
78
+ - **detail str 语义**:`_check_value` 和 `_make_table_from_rows` 不再用 `Text.from_markup` 解析 `str` 类型 key/value。`str` = 数据(逐字显示),`Text` = 富文本(保留样式)。避免用户数据中匹配 Rich 样式名的 `[...]` 被当作样式标签消费。
79
+ - **移除私有 API**:`WealthyDocument.__rich_console__` 不再访问 `console._theme_stack`(Rich 私有属性),不再做主题兜底补全。组件完全主题透明——调用方通过 `Console(theme=default_theme)` 提供样式。
80
+ - **BASE_STYLES 值恢复**:`cx.info`/`cx.success`/`cx.error`/`cx.warning`/`cx.number` 恢复为 0.1.0 的设计值(bold 变体、cyan 色调),不再从 iappenv 复制。
81
+
82
+ ## 0.1.1
83
+
84
+ 基于 jpegger 迁移审计反馈的修正:
85
+
86
+ ### 架构改进
87
+
88
+ - **主题透明机制**(N2):`WealthyDocument` / `WealthyHelp` 不再持有主题(移除 `theme` / `styles` / `DEFAULT_STYLES` 属性)。渲染时通过 `__rich_console__` **兜底补全**调用方未定义的 `cx.*` 样式——不覆盖调用方已有定义,仅在缺失时用 `default_theme` 填充。第三方不应用 `default_theme` 时组件仍可渲染(透明兼容)。
89
+ - **ActionGroup 特化**(B2):新增 `cx_wealthy.help.action_group.ActionGroup`,在 help 特化层继承 `Group` 提供 `add_action` 便利方法。`WealthyHelp.add_group` 覆盖父类方法返回 `ActionGroup`。`Group`(document 通用核心)保持语义纯净,不感知 `Action` / flags / nargs。
90
+ - **接口级样式统一**(B1):`cx_tools/app/iappenv.py` 的 11 个 `DEFAULT_STYLES` 迁移到 `cx_wealthy/theme.py` 的 `BASE_STYLES`。主题来源单一化,cx_wealthy 作为依赖统一提供所有 `cx.*` 样式。
91
+
92
+ ### Bug 修复
93
+
94
+ - **detail markup 解析**(N1):`WealthDetailTable` 的 KEY 和 VALUE 渲染均改用 `Text.from_markup(str(...))`,与 `console.print(str)` 默认解析 markup 的行为对齐。原 `Text(str(...))` 不解析 markup,导致 `[cyan]#0 AutoResize[/]` 等显示为字面量。
95
+ - **Action flag 校验**(B3):`_validate_flags` 分两类校验——选项(`^[prefix_chars]+\w[\w-]*$`)和位置参数名(`^\w[\w-]*$`),支持位置参数名和含连字符的 flag(如 `--force-overwrite`)。
96
+
97
+ ## 0.1.0
98
+
99
+ - 初始发布,建立 `cx-wealthy` 包骨架。
100
+ - 主要模块(按实现计划):
101
+ - `theme` — `cx.*` 命名空间主题预设(success / error / warning / info 等)。
102
+ - `rich_types` — 对外便利的 Rich 高频类型出口。
103
+ - `label` — 紧凑标签协议 `RichLabelMixin` 与 `RichLabel` 包装器。
104
+ - `detail` — 详情键值面板协议 `RichDetailMixin` 与 `WealthDetailPanel` / `WealthDetailTable`。
105
+ - `document` — 通用结构化文档核心:`Node` / `Group` / `Note` / `WealthyDocument`。
106
+ - `help` — 帮助系统特化层:`Action` / `WealthyHelp`。
107
+ - `indexed_list` — 带索引列表面板 `IndexedListPanel`。
108
+ - `columns` — 最大列数布局 `MaxColumnsLayout`。
109
+ - `tutorial` — 本地化教程渲染 `render_tutorial()`。
@@ -0,0 +1,178 @@
1
+ Metadata-Version: 2.4
2
+ Name: cx-wealthy
3
+ Version: 0.9.0
4
+ Summary: Cxalio Rich UI component library — declarative structured document rendering for terminal applications.
5
+ Author-email: xiii_1991 <xiii_1991@163.com>
6
+ Requires-Python: <3.15,>=3.12
7
+ Requires-Dist: rich>=14.0.0
8
+ Description-Content-Type: text/markdown
9
+
10
+ [English](README.en.md) | 简体中文
11
+
12
+ # cx-wealthy
13
+
14
+ 基于 [Rich](https://github.com/Textualize/rich) 的终端结构化文档与 UI 组件库。
15
+
16
+ 为领域对象提供标签与详情两种渲染模式,让结构化输出声明式构建——不手写 Table/Panel 拼装,不继承 Rich 内部协议。
17
+
18
+ ## 安装
19
+
20
+ ```bash
21
+ pip install cx-wealthy
22
+ ```
23
+
24
+ 在 uv 项目中引入:
25
+
26
+ ```bash
27
+ uv add cx-wealthy
28
+ ```
29
+
30
+ ## 核心概念
31
+
32
+ ### 标签与详情渲染协议
33
+
34
+ cx-wealthy 为 Rich 扩展了两种渲染模式:`__rich_label__`(紧凑标签,用于行内摘要)和 `__rich_detail__`(键值面板,用于结构化详情)。继承对应的 mixin 后,`console.print()` 自动以该模式渲染——无需在调用点手动包装。
35
+
36
+ ```python
37
+ from cx_wealthy import RichLabelMixin, RichDetailMixin, WealthyDetailPanel
38
+ from rich.console import Console
39
+
40
+ console = Console()
41
+
42
+ class Mission(RichLabelMixin, RichDetailMixin):
43
+ def __init__(self, name, source, overwrite=False):
44
+ self.name = name
45
+ self.source = source
46
+ self.overwrite = overwrite
47
+
48
+ def __rich_label__(self):
49
+ yield "[bold]M[/]"
50
+ yield self.name
51
+ yield f"→ {self.source}"
52
+
53
+ def __rich_detail__(self):
54
+ yield "名称", self.name
55
+ yield "源文件", str(self.source)
56
+ yield "覆盖", self.overwrite, False # 三元组:值等于默认时不显示
57
+
58
+ console.print(Mission("encode", "input.mp4"))
59
+ # 输出标签:M encode → input.mp4
60
+
61
+ console.print(WealthyDetailPanel(Mission("encode", "input.mp4")))
62
+ # 输出键值面板,"覆盖"行因 overwrite==False 被去重隐藏
63
+ ```
64
+
65
+ 不愿继承时,用包装器 `RichLabel(obj)` / `WealthyDetailPanel(obj)` 渲染任意实现了协议的对象。
66
+
67
+ **`__rich_detail__` yield 格式:**
68
+
69
+ | 元组形态 | 效果 |
70
+ |---|---|
71
+ | `(key, value)` | 显示 `key = value` |
72
+ | `(key, value, default)` | `value == default` 时该行不显示 |
73
+ | `(value,)` | 仅显示值,key 列为空 |
74
+ | `(key, *values)` | value 为列表 |
75
+
76
+ **字符串与 markup**:`str` 类型的 key/value 逐字显示(不解析 markup);需要 markup 格式时 yield `Text.from_markup(...)`。
77
+
78
+ `__rich_detail__` 与 Rich 原生 `__rich_repr__` 语义不同:后者是 debug repr(raw 值 + Pretty 渲染),前者是展示视角(value 可预格式化、支持递归嵌套 sub-panel、列表自动渲染为 `IndexedListPanel`)。
79
+
80
+ ### 声明式文档构建
81
+
82
+ 通过 `Node` → `Group` + `Note` 的复合树构建结构化文档,`WealthyDocument` 组织渲染。帮助系统是其中的特化层——`WealthyHelp` 继承 `WealthyDocument`,增加 `Action` 节点和 usage/details 渲染。
83
+
84
+ ```python
85
+ from cx_wealthy import WealthyHelp
86
+
87
+ help = WealthyHelp(prog="myapp", description="CLI 工具说明")
88
+ help.add_action("--input", metavar="FILE", description="输入文件路径")
89
+ help.add_action("--output", metavar="FILE", description="输出文件路径")
90
+ help.add_action("--verbose", description="详细输出")
91
+ help.add_note("使用 --help 查看完整用法。")
92
+ console.print(help)
93
+ ```
94
+
95
+ `WealthyHelp` 自动渲染 usage 行(选项按可选/位置分组)、参数详情表格、epilog 尾部。
96
+
97
+ `WealthyDocument` 不限于帮助系统——任何"分组 + 条目 + 注释"的结构化输出都可以用它构建。
98
+
99
+ ### 子命令结构
100
+
101
+ 对于有子命令的 CLI 工具(如 `git`/`docker` 风格),使用 `HelpGroup` 表达:
102
+
103
+ ```python
104
+ commands = help.add_group("子命令")
105
+ list_cmd = commands.add_command("list", description="列出所有项")
106
+ list_cmd.add_action("-s", "--search", metavar="PATTERN", description="搜索过滤")
107
+
108
+ update_cmd = commands.add_command("update", description="更新")
109
+ update_cmd.add_action("--force", description="强制更新")
110
+ ```
111
+
112
+ `WealthyHelp` 自动渲染多行 usage(简版总览 + 每个子命令详版)和按命令分组的参数详情。
113
+
114
+ ## 辅助组件
115
+
116
+ | 组件 | 用途 |
117
+ |---|---|
118
+ | `IndexedListPanel` | 带行号索引的列表面板,支持截断(`max_lines=None` 不限) |
119
+ | `MaxColumnsLayout` | 固定最大列数的多列布局 |
120
+ | `render_tutorial()` | 按 locale 加载 Markdown 教程文件并渲染为 Panel |
121
+
122
+ ```python
123
+ from cx_wealthy import IndexedListPanel, MaxColumnsLayout, render_tutorial
124
+
125
+ console.print(IndexedListPanel(["a", "b", "c"], title="文件列表"))
126
+ console.print(MaxColumnsLayout(["one", "two", "three", "four"], max_columns=3))
127
+ console.print(render_tutorial(__package__, "help.md", title="教程"))
128
+ ```
129
+
130
+ ## 主题预设
131
+
132
+ `cx.*` 命名空间的 Rich 主题样式。
133
+
134
+ ```python
135
+ from cx_wealthy.theme import default_theme
136
+ from rich.console import Console
137
+
138
+ console = Console(theme=default_theme)
139
+ console.print("[cx.success]操作成功[/]")
140
+ console.print("[cx.error]操作失败[/]")
141
+ ```
142
+
143
+ | 样式 | 效果 |
144
+ |---|---|
145
+ | `cx.success` | 粗体绿色 |
146
+ | `cx.error` | 粗体红色 |
147
+ | `cx.warning` | 粗体黄色 |
148
+ | `cx.info` | 青色 |
149
+ | `cx.whisper` | 暗色 |
150
+ | `cx.number` | 青色 |
151
+
152
+ ## Rich 类型便利出口
153
+
154
+ ```python
155
+ from cx_wealthy import rich_types as r
156
+
157
+ table = r.Table(show_header=True)
158
+ table.add_column(r.Column("名称"))
159
+ r.Console().print(table)
160
+ ```
161
+
162
+ ## 模块索引
163
+
164
+ | 模块 | 导出 |
165
+ |---|---|
166
+ | `label` | `RichLabelMixin` · `RichLabel` |
167
+ | `detail` | `RichDetailMixin` · `WealthyDetailTable` · `WealthyDetailPanel` |
168
+ | `document` | `Node` · `Group` · `Note` · `WealthyDocument` |
169
+ | `help` | `Action` · `HelpGroup` · `WealthyHelp` |
170
+ | `indexed_list` | `IndexedListPanel` |
171
+ | `columns` | `MaxColumnsLayout` |
172
+ | `tutorial` | `render_tutorial` |
173
+ | `theme` | `CX_STYLES` · `HELP_STYLES` · `default_theme` |
174
+ | `rich_types` | Rich 高频类型别名出口 |
175
+
176
+ ## 协议
177
+
178
+ MIT