pdd-skills 3.0.0
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/README.md +1478 -0
- package/bin/pdd.js +354 -0
- package/config/bpmn-rules.yaml +166 -0
- package/config/checkstyle.xml +105 -0
- package/config/eslint.config.js +48 -0
- package/config/pmd.xml +91 -0
- package/config/prd-rules.yaml +113 -0
- package/config/ruff.toml +45 -0
- package/config/sqlfluff.cfg +82 -0
- package/hooks/hook-executor.js +332 -0
- package/index.js +43 -0
- package/lib/api-routes.js +750 -0
- package/lib/api-server.js +408 -0
- package/lib/cache/cache-config.js +209 -0
- package/lib/cache/system-cache.js +852 -0
- package/lib/config-manager.js +373 -0
- package/lib/generate.js +528 -0
- package/lib/grpc/grpc-routes.js +1134 -0
- package/lib/grpc/grpc-server.js +912 -0
- package/lib/grpc/proto-definitions.js +1033 -0
- package/lib/init.js +172 -0
- package/lib/iteration/auto-fixer.js +1025 -0
- package/lib/iteration/auto-reviewer.js +923 -0
- package/lib/iteration/controller.js +577 -0
- package/lib/list.js +130 -0
- package/lib/mcp-server.js +548 -0
- package/lib/openclaw/api-integration.js +535 -0
- package/lib/openclaw/cli-integration.js +567 -0
- package/lib/openclaw/data-sync.js +845 -0
- package/lib/openclaw/openclaw-adapter.js +783 -0
- package/lib/plugin/example-plugins/code-stats/index.js +332 -0
- package/lib/plugin/example-plugins/code-stats/plugin.json +1 -0
- package/lib/plugin/example-plugins/custom-linter/index.js +472 -0
- package/lib/plugin/example-plugins/custom-linter/plugin.json +1 -0
- package/lib/plugin/example-plugins/hello-world/index.js +86 -0
- package/lib/plugin/example-plugins/hello-world/plugin.json +1 -0
- package/lib/plugin/plugin-manager.js +655 -0
- package/lib/plugin/plugin-sdk.js +565 -0
- package/lib/plugin/sandbox.js +627 -0
- package/lib/quality/rules/maintainability.js +418 -0
- package/lib/quality/rules/performance.js +498 -0
- package/lib/quality/rules/readability.js +441 -0
- package/lib/quality/rules/robustness.js +504 -0
- package/lib/quality/rules/security.js +444 -0
- package/lib/quality/scorer.js +576 -0
- package/lib/report.js +669 -0
- package/lib/sdk-base.js +301 -0
- package/lib/sdk-js.js +446 -0
- package/lib/sdk-python/README.md +546 -0
- package/lib/sdk-python/examples/basic_usage.py +450 -0
- package/lib/sdk-python/pdd_sdk/__init__.py +180 -0
- package/lib/sdk-python/pdd_sdk/client.py +1170 -0
- package/lib/sdk-python/pdd_sdk/events.py +423 -0
- package/lib/sdk-python/pdd_sdk/exceptions.py +158 -0
- package/lib/sdk-python/pdd_sdk/models.py +518 -0
- package/lib/sdk-python/pdd_sdk/utils.py +759 -0
- package/lib/token/budget-alert.js +367 -0
- package/lib/token/budget-manager.js +485 -0
- package/lib/update.js +54 -0
- package/lib/utils/logger.js +88 -0
- package/lib/verify.js +741 -0
- package/lib/version.js +52 -0
- package/lib/vm/README.md +102 -0
- package/lib/vm/dashboard/api-routes.js +669 -0
- package/lib/vm/dashboard/server.js +391 -0
- package/lib/vm/dashboard/sse.js +358 -0
- package/lib/vm/dashboard/static/css/dashboard.css +1378 -0
- package/lib/vm/dashboard/static/index.html +118 -0
- package/lib/vm/dashboard/static/js/app.js +949 -0
- package/lib/vm/dashboard/static/js/charts.js +913 -0
- package/lib/vm/dashboard/static/js/kanban-view.js +1053 -0
- package/lib/vm/dashboard/static/js/pipeline-view.js +463 -0
- package/lib/vm/dashboard/static/js/quality-view.js +598 -0
- package/lib/vm/dashboard/static/js/system-view.js +1021 -0
- package/lib/vm/data-provider.js +1191 -0
- package/lib/vm/event-bus.js +402 -0
- package/lib/vm/hooks/extract-hook.js +307 -0
- package/lib/vm/hooks/generate-hook.js +374 -0
- package/lib/vm/hooks/hook-interface.js +458 -0
- package/lib/vm/hooks/report-hook.js +331 -0
- package/lib/vm/hooks/verify-hook.js +454 -0
- package/lib/vm/models.js +1003 -0
- package/lib/vm/reconciler.js +855 -0
- package/lib/vm/scanner.js +988 -0
- package/lib/vm/state-schema.js +955 -0
- package/lib/vm/state-store.js +733 -0
- package/lib/vm/tui/components/card.js +339 -0
- package/lib/vm/tui/components/progress-bar.js +368 -0
- package/lib/vm/tui/components/sparkline.js +327 -0
- package/lib/vm/tui/components/status-light.js +294 -0
- package/lib/vm/tui/components/table.js +370 -0
- package/lib/vm/tui/input.js +335 -0
- package/lib/vm/tui/renderer.js +548 -0
- package/lib/vm/tui/screens/kanban-screen.js +397 -0
- package/lib/vm/tui/screens/overview-screen.js +357 -0
- package/lib/vm/tui/screens/quality-screen.js +336 -0
- package/lib/vm/tui/screens/system-screen.js +379 -0
- package/lib/vm/tui/tui.js +805 -0
- package/package.json +1 -0
- package/scripts/cso-analyzer.js +198 -0
- package/scripts/eval-runner.js +359 -0
- package/scripts/i18n-checker.js +109 -0
- package/scripts/linter/activiti-linter.js +272 -0
- package/scripts/linter/prd-linter.js +162 -0
- package/scripts/linter/report-generator.js +207 -0
- package/scripts/linter/run-linters.js +285 -0
- package/scripts/linter/sql-linter.js +166 -0
- package/scripts/token-analyzer.js +162 -0
- package/scripts/vm-test.js +180 -0
- package/skills/core/official-doc-writer/LICENSE +21 -0
- package/skills/core/official-doc-writer/README.md +232 -0
- package/skills/core/official-doc-writer/SKILL.md +475 -0
- package/skills/core/official-doc-writer/_meta.json +1 -0
- package/skills/core/official-doc-writer/document_generator.py +580 -0
- package/skills/core/official-doc-writer/evals/default-evals.json +1 -0
- package/skills/core/official-doc-writer/examples.md +150 -0
- package/skills/core/official-doc-writer/fonts/FONTS_LIST.md +45 -0
- package/skills/core/official-doc-writer/fonts/README.md +141 -0
- package/skills/core/official-doc-writer/fonts/SIMFANG.TTF +0 -0
- package/skills/core/official-doc-writer/fonts/SIMHEI.TTF +0 -0
- package/skills/core/official-doc-writer/fonts/SIMKAI.TTF +0 -0
- package/skills/core/official-doc-writer/fonts/SIMSUN.TTC +0 -0
- package/skills/core/official-doc-writer/fonts//346/226/271/346/255/243/345/260/217/346/240/207/345/256/213GBK.TTF +0 -0
- package/skills/core/official-doc-writer/references/GBT_9704-2012_/345/205/232/346/224/277/346/234/272/345/205/263/345/205/254/346/226/207/346/240/274/345/274/217.md +422 -0
- package/skills/core/official-doc-writer/scripts/__pycache__/generate_official_doc.cpython-313.pyc +0 -0
- package/skills/core/official-doc-writer/scripts/dialog_manager.py +564 -0
- package/skills/core/official-doc-writer/scripts/generate_official_doc.py +252 -0
- package/skills/core/official-doc-writer/scripts/install_fonts.py +390 -0
- package/skills/core/official-doc-writer/scripts/smart_prompts.py +363 -0
- package/skills/core/pdd-ba/SKILL.md +305 -0
- package/skills/core/pdd-ba/_meta.json +1 -0
- package/skills/core/pdd-ba/evals/default-evals.json +1 -0
- package/skills/core/pdd-code-reviewer/SKILL.md +378 -0
- package/skills/core/pdd-code-reviewer/_meta.json +1 -0
- package/skills/core/pdd-code-reviewer/evals/default-evals.json +1 -0
- package/skills/core/pdd-doc-change/SKILL.md +350 -0
- package/skills/core/pdd-doc-change/_meta.json +1 -0
- package/skills/core/pdd-doc-change/evals/default-evals.json +1 -0
- package/skills/core/pdd-doc-gardener/SKILL.md +248 -0
- package/skills/core/pdd-doc-gardener/_meta.json +1 -0
- package/skills/core/pdd-doc-gardener/evals/default-evals.json +1 -0
- package/skills/core/pdd-entropy-reduction/SKILL.md +360 -0
- package/skills/core/pdd-entropy-reduction/_meta.json +1 -0
- package/skills/core/pdd-entropy-reduction/evals/default-evals.json +1 -0
- package/skills/core/pdd-entropy-reduction/references/entropy-report-template.md +287 -0
- package/skills/core/pdd-entropy-reduction/references/golden-principles.md +573 -0
- package/skills/core/pdd-entropy-reduction/scripts/entropy_scan.py +712 -0
- package/skills/core/pdd-extract-features/SKILL.md +320 -0
- package/skills/core/pdd-extract-features/_meta.json +1 -0
- package/skills/core/pdd-extract-features/evals/default-evals.json +1 -0
- package/skills/core/pdd-generate-spec/SKILL.md +418 -0
- package/skills/core/pdd-generate-spec/_meta.json +1 -0
- package/skills/core/pdd-generate-spec/evals/default-evals.json +1 -0
- package/skills/core/pdd-implement-feature/SKILL.md +332 -0
- package/skills/core/pdd-implement-feature/_meta.json +1 -0
- package/skills/core/pdd-implement-feature/evals/default-evals.json +1 -0
- package/skills/core/pdd-main/SKILL.md +540 -0
- package/skills/core/pdd-main/_meta.json +1 -0
- package/skills/core/pdd-main/evals/default-evals.json +1 -0
- package/skills/core/pdd-main/evals/evals.json +215 -0
- package/skills/core/pdd-verify-feature/SKILL.md +474 -0
- package/skills/core/pdd-verify-feature/_meta.json +1 -0
- package/skills/core/pdd-verify-feature/evals/default-evals.json +1 -0
- package/skills/core/pdd-vm/evals/default-evals.json +1 -0
- package/skills/core/traffic-accident-assessor/LICENSE +29 -0
- package/skills/core/traffic-accident-assessor/SKILL.md +439 -0
- package/skills/core/traffic-accident-assessor/evals/evals.json +1 -0
- package/skills/core/traffic-accident-assessor/references/accident-types.md +369 -0
- package/skills/core/traffic-accident-assessor/references/liability-rules.md +287 -0
- package/skills/core/traffic-accident-assessor/references/traffic-laws.md +226 -0
- package/skills/core/traffic-accident-assessor/references//351/253/230/345/260/224/345/244/253/350/257/264/346/230/216/344/271/246.pdf +32576 -106
- package/skills/core/traffic-accident-assessor/scripts/generate_official_statement.py +588 -0
- package/skills/core/traffic-accident-assessor/scripts/generate_report.py +495 -0
- package/skills/core/traffic-accident-assessor/scripts/generate_statement.py +528 -0
- package/skills/core/traffic-accident-assessor.zip +0 -0
- package/skills/entropy/expert-arch-enforcer/SKILL.md +292 -0
- package/skills/entropy/expert-arch-enforcer/_meta.json +1 -0
- package/skills/entropy/expert-arch-enforcer/evals/default-evals.json +1 -0
- package/skills/entropy/expert-auto-refactor/SKILL.md +327 -0
- package/skills/entropy/expert-auto-refactor/_meta.json +1 -0
- package/skills/entropy/expert-auto-refactor/evals/default-evals.json +1 -0
- package/skills/entropy/expert-code-quality/SKILL.md +468 -0
- package/skills/entropy/expert-code-quality/_meta.json +1 -0
- package/skills/entropy/expert-code-quality/evals/default-evals.json +1 -0
- package/skills/entropy/expert-code-quality/evals/evals.json +109 -0
- package/skills/entropy/expert-code-quality/references/code-smells.md +605 -0
- package/skills/entropy/expert-code-quality/references/design-patterns.md +1111 -0
- package/skills/entropy/expert-code-quality/references/refactoring-catalog.md +1281 -0
- package/skills/entropy/expert-code-quality/references/solid-principles.md +524 -0
- package/skills/entropy/expert-entropy-auditor/SKILL.md +276 -0
- package/skills/entropy/expert-entropy-auditor/_meta.json +1 -0
- package/skills/entropy/expert-entropy-auditor/evals/default-evals.json +1 -0
- package/skills/expert/expert-activiti/SKILL.md +497 -0
- package/skills/expert/expert-activiti/_meta.json +1 -0
- package/skills/expert/expert-mysql/SKILL.md +832 -0
- package/skills/expert/expert-mysql/_meta.json +1 -0
- package/skills/expert/expert-performance/SKILL.md +379 -0
- package/skills/expert/expert-performance/_meta.json +1 -0
- package/skills/expert/expert-performance/evals/default-evals.json +1 -0
- package/skills/expert/expert-ruoyi/SKILL.md +472 -0
- package/skills/expert/expert-ruoyi/_meta.json +1 -0
- package/skills/expert/expert-security/SKILL.md +1341 -0
- package/skills/expert/expert-security/_meta.json +1 -0
- package/skills/expert/expert-security/evals/default-evals.json +1 -0
- package/skills/expert/software-architect/SKILL.md +350 -0
- package/skills/expert/software-architect/_meta.json +1 -0
- package/skills/expert/software-engineer/SKILL.md +437 -0
- package/skills/expert/software-engineer/_meta.json +1 -0
- package/skills/expert/software-engineer/architecture.md +130 -0
- package/skills/expert/software-engineer/patterns.md +151 -0
- package/skills/expert/software-engineer/testing.md +135 -0
- package/skills/expert/system-architect/SKILL.md +628 -0
- package/skills/expert/system-architect/_meta.json +1 -0
- package/skills/expert/system-architect/assets/templates/ARCHITECTURE.md +25 -0
- package/skills/expert/system-architect/assets/templates/README.md +44 -0
- package/skills/expert/system-architect/references/js-ts-standards.md +18 -0
- package/skills/expert/system-architect/references/python-standards.md +19 -0
- package/skills/expert/system-architect/references/scaffolding.md +61 -0
- package/skills/expert/system-architect/references/security-checklist.md +21 -0
- package/skills/openspec/openspec-apply-change/SKILL.md +156 -0
- package/skills/openspec/openspec-apply-change/_meta.json +1 -0
- package/skills/openspec/openspec-archive-change/SKILL.md +114 -0
- package/skills/openspec/openspec-archive-change/_meta.json +1 -0
- package/skills/openspec/openspec-bulk-archive-change/SKILL.md +246 -0
- package/skills/openspec/openspec-bulk-archive-change/_meta.json +1 -0
- package/skills/openspec/openspec-continue-change/SKILL.md +118 -0
- package/skills/openspec/openspec-continue-change/_meta.json +1 -0
- package/skills/openspec/openspec-explore/SKILL.md +288 -0
- package/skills/openspec/openspec-explore/_meta.json +1 -0
- package/skills/openspec/openspec-ff-change/SKILL.md +101 -0
- package/skills/openspec/openspec-ff-change/_meta.json +1 -0
- package/skills/openspec/openspec-new-change/SKILL.md +74 -0
- package/skills/openspec/openspec-new-change/_meta.json +1 -0
- package/skills/openspec/openspec-onboard/SKILL.md +554 -0
- package/skills/openspec/openspec-onboard/_meta.json +1 -0
- package/skills/openspec/openspec-sync-specs/SKILL.md +138 -0
- package/skills/openspec/openspec-sync-specs/_meta.json +1 -0
- package/skills/openspec/openspec-verify-change/SKILL.md +168 -0
- package/skills/openspec/openspec-verify-change/_meta.json +1 -0
- package/skills/pr/pdd-multi-review/SKILL.md +534 -0
- package/skills/pr/pdd-multi-review/_meta.json +1 -0
- package/skills/pr/pdd-pr-batch/SKILL.md +303 -0
- package/skills/pr/pdd-pr-batch/_meta.json +1 -0
- package/skills/pr/pdd-pr-create/SKILL.md +344 -0
- package/skills/pr/pdd-pr-create/_meta.json +1 -0
- package/skills/pr/pdd-pr-merge/SKILL.md +286 -0
- package/skills/pr/pdd-pr-merge/_meta.json +1 -0
- package/skills/pr/pdd-pr-review/SKILL.md +217 -0
- package/skills/pr/pdd-pr-review/_meta.json +1 -0
- package/skills/pr/pdd-task-manager/SKILL.md +636 -0
- package/skills/pr/pdd-task-manager/_meta.json +1 -0
- package/skills/pr/pdd-template-engine/SKILL.md +306 -0
- package/skills/pr/pdd-template-engine/_meta.json +1 -0
- package/templates/behavior-shaping/iron-law-template.md +87 -0
- package/templates/behavior-shaping/rationalization-template.md +62 -0
- package/templates/behavior-shaping/red-flags-template.md +70 -0
- package/templates/bilingual-template.md +139 -0
- package/templates/config/default.yaml +47 -0
- package/templates/project/default/README.md +31 -0
- package/templates/project/frontend/README.md +46 -0
- package/templates/project/java/README.md +48 -0
|
@@ -0,0 +1,548 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PDD Visual Manager - ANSI 渲染引擎 (VM-C002)
|
|
3
|
+
*
|
|
4
|
+
* 提供终端 UI 的底层渲染能力:
|
|
5
|
+
* - ANSI 转义码常量定义
|
|
6
|
+
* - 彩色文字输出
|
|
7
|
+
* - 边框盒子绘制
|
|
8
|
+
* - 进度条渲染
|
|
9
|
+
* - 表格格式化
|
|
10
|
+
* - 文本填充/截断(支持中文等宽)
|
|
11
|
+
* - 终端尺寸自适应
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
// ============================================================
|
|
15
|
+
// ANSI 转义码常量
|
|
16
|
+
// ============================================================
|
|
17
|
+
export const ANSI = Object.freeze({
|
|
18
|
+
// 屏幕控制
|
|
19
|
+
CLEAR: '\x1b[2J',
|
|
20
|
+
HOME: '\x1b[H',
|
|
21
|
+
SHOW_CURSOR: '\x1b[?25h',
|
|
22
|
+
HIDE_CURSOR: '\x1b[?25l',
|
|
23
|
+
ALT_BUFFER: '\x1b[?1049h',
|
|
24
|
+
MAIN_BUFFER: '\x1b[?1049l',
|
|
25
|
+
SAVE_POS: '\x1b[s',
|
|
26
|
+
RESTORE_POS: '\x1b[u',
|
|
27
|
+
|
|
28
|
+
// 前景色 (标准)
|
|
29
|
+
BLACK: '\x1b[30m',
|
|
30
|
+
RED: '\x1b[31m',
|
|
31
|
+
GREEN: '\x1b[32m',
|
|
32
|
+
YELLOW: '\x1b[33m',
|
|
33
|
+
BLUE: '\x1b[34m',
|
|
34
|
+
MAGENTA: '\x1b[35m',
|
|
35
|
+
CYAN: '\x1b[36m',
|
|
36
|
+
WHITE: '\x1b[37m',
|
|
37
|
+
|
|
38
|
+
// 前景色 (亮色)
|
|
39
|
+
BRIGHT_RED: '\x1b[91m',
|
|
40
|
+
BRIGHT_GREEN: '\x1b[92m',
|
|
41
|
+
BRIGHT_YELLOW: '\x1b[93m',
|
|
42
|
+
BRIGHT_BLUE: '\x1b[94m',
|
|
43
|
+
BRIGHT_MAGENTA: '\x1b[95m',
|
|
44
|
+
BRIGHT_CYAN: '\x1b[96m',
|
|
45
|
+
BRIGHT_WHITE: '\x1b[97m',
|
|
46
|
+
|
|
47
|
+
// 背景色
|
|
48
|
+
BG_BLACK: '\x1b[40m',
|
|
49
|
+
BG_RED: '\x1b[41m',
|
|
50
|
+
BG_GREEN: '\x1b[42m',
|
|
51
|
+
BG_YELLOW: '\x1b[43m',
|
|
52
|
+
BG_BLUE: '\x1b[44m',
|
|
53
|
+
BG_MAGENTA: '\x1b[45m',
|
|
54
|
+
BG_CYAN: '\x1b[46m',
|
|
55
|
+
BG_WHITE: '\x1b[47m',
|
|
56
|
+
|
|
57
|
+
// 重置与样式
|
|
58
|
+
RESET: '\x1b[0m',
|
|
59
|
+
BOLD: '\x1b[1m',
|
|
60
|
+
DIM: '\x1b[2m',
|
|
61
|
+
ITALIC: '\x1b[3m',
|
|
62
|
+
UNDERLINE: '\x1b[4m',
|
|
63
|
+
REVERSE: '\x1b[7m',
|
|
64
|
+
STRIKETHROUGH: '\x1b[9m',
|
|
65
|
+
|
|
66
|
+
// 光标移动
|
|
67
|
+
POS(row, col) {
|
|
68
|
+
return `\x1b[${row};${col}H`;
|
|
69
|
+
},
|
|
70
|
+
UP(n = 1) {
|
|
71
|
+
return `\x1b[${n}A`;
|
|
72
|
+
},
|
|
73
|
+
DOWN(n = 1) {
|
|
74
|
+
return `\x1b[${n}B`;
|
|
75
|
+
},
|
|
76
|
+
LEFT(n = 1) {
|
|
77
|
+
return `\x1b[${n}D`;
|
|
78
|
+
},
|
|
79
|
+
RIGHT(n = 1) {
|
|
80
|
+
return `\x1b[${n}C`;
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
// 清除操作
|
|
84
|
+
CLEAR_LINE: '\x1b[K',
|
|
85
|
+
CLEAR_TO_START: '\x1b[1K',
|
|
86
|
+
CLEAR_TO_END: '\x1b[0J',
|
|
87
|
+
CLEAR_SCREEN_BELOW: '\x1b[0J',
|
|
88
|
+
CLEAR_SCREEN_ABOVE: '\x1b[1J'
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* 边框字符集
|
|
93
|
+
*/
|
|
94
|
+
const BORDER_CHARS = {
|
|
95
|
+
single: {
|
|
96
|
+
tl: '┌', tr: '┐', bl: '└', br: '┘',
|
|
97
|
+
h: '─', v: '│',
|
|
98
|
+
lt: '├', rt: '┤', bt: '┬', bb: '┴', cross: '┼'
|
|
99
|
+
},
|
|
100
|
+
double: {
|
|
101
|
+
tl: '╔', tr: '╗', bl: '╚', br: '╝',
|
|
102
|
+
h: '═', v: '║',
|
|
103
|
+
lt: '╠', rt: '╣', bt: '╦', bb: '╩', cross: '╬'
|
|
104
|
+
},
|
|
105
|
+
rounded: {
|
|
106
|
+
tl: '╭', tr: '╮', bl: '╰', br: '╯',
|
|
107
|
+
h: '─', v: '│',
|
|
108
|
+
lt: '├', rt: '┤', bt: '┬', bb: '┴', cross: '┼'
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Renderer - ANSI 渲染引擎
|
|
114
|
+
*
|
|
115
|
+
* 封装所有终端输出操作,提供高层绘图 API。
|
|
116
|
+
* 支持终端尺寸自适应、Unicode 字符宽度计算等。
|
|
117
|
+
*/
|
|
118
|
+
class Renderer {
|
|
119
|
+
constructor() {
|
|
120
|
+
this._updateSize();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* 更新终端尺寸信息
|
|
125
|
+
*/
|
|
126
|
+
_updateSize() {
|
|
127
|
+
this.width = process.stdout.columns || 80;
|
|
128
|
+
this.height = process.stdout.rows || 24;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* 获取当前终端尺寸
|
|
133
|
+
*/
|
|
134
|
+
get size() {
|
|
135
|
+
this._updateSize();
|
|
136
|
+
return { width: this.width, height: this.height };
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// ============================================================
|
|
140
|
+
// 屏幕控制
|
|
141
|
+
// ============================================================
|
|
142
|
+
|
|
143
|
+
/** 清屏并将光标移到左上角 */
|
|
144
|
+
clear() {
|
|
145
|
+
process.stdout.write(ANSI.CLEAR + ANSI.HOME);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** 隐藏光标并归位 */
|
|
149
|
+
home() {
|
|
150
|
+
process.stdout.write(ANSI.HIDE_CURSOR + ANSI.HOME);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** 恢复光标显示,切回主屏幕缓冲区 */
|
|
154
|
+
restore() {
|
|
155
|
+
process.stdout.write(ANSI.SHOW_CURSOR + ANSI.MAIN_BUFFER + ANSI.CLEAR);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** 进入备用屏幕缓冲区并隐藏光标 */
|
|
159
|
+
enterAltBuffer() {
|
|
160
|
+
process.stdout.write(ANSI.ALT_BUFFER + ANSI.HIDE_CURSOR);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// ============================================================
|
|
164
|
+
// 基础输出
|
|
165
|
+
// ============================================================
|
|
166
|
+
|
|
167
|
+
/** 写入文本 */
|
|
168
|
+
write(text) {
|
|
169
|
+
if (text) process.stdout.write(text);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** 写入一行 */
|
|
173
|
+
writeln(text = '') {
|
|
174
|
+
process.stdout.write(text + '\n');
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** 移动光标到指定位置 */
|
|
178
|
+
moveTo(row, col) {
|
|
179
|
+
process.stdout.write(ANSI.POS(row, col));
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// ============================================================
|
|
183
|
+
// 彩色文字
|
|
184
|
+
// ============================================================
|
|
185
|
+
|
|
186
|
+
/** 包裹颜色代码 */
|
|
187
|
+
colored(text, color) {
|
|
188
|
+
return `${color}${text}${ANSI.RESET}`;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
red(t) { return this.colored(t, ANSI.RED); }
|
|
192
|
+
green(t) { return this.colored(t, ANSI.GREEN); }
|
|
193
|
+
yellow(t) { return this.colored(t, ANSI.YELLOW); }
|
|
194
|
+
blue(t) { return this.colored(t, ANSI.BLUE); }
|
|
195
|
+
magenta(t) { return this.colored(t, ANSI.MAGENTA); }
|
|
196
|
+
cyan(t) { return this.colored(t, ANSI.CYAN); }
|
|
197
|
+
brightRed(t) { return this.colored(t, ANSI.BRIGHT_RED); }
|
|
198
|
+
brightGreen(t) { return this.colored(t, ANSI.BRIGHT_GREEN); }
|
|
199
|
+
brightYellow(t) { return this.colored(t, ANSI.BRIGHT_YELLOW); }
|
|
200
|
+
brightBlue(t) { return this.colored(t, ANSI.BRIGHT_BLUE); }
|
|
201
|
+
brightCyan(t) { return this.colored(t, ANSI.BRIGHT_CYAN); }
|
|
202
|
+
brightWhite(t) { return this.colored(t, ANSI.BRIGHT_WHITE); }
|
|
203
|
+
|
|
204
|
+
bold(t) { return `${ANSI.BOLD}${t}${ANSI.RESET}`; }
|
|
205
|
+
dim(t) { return `${ANSI.DIM}${t}${ANSI.RESET}`; }
|
|
206
|
+
italic(t) { return `${ANSI.ITALIC}${t}${ANSI.RESET}`; }
|
|
207
|
+
underline(t) { return `${ANSI.UNDERLINE}${t}${ANSI.RESET}`; }
|
|
208
|
+
reverse(t) { return `${ANSI.REVERSE}${t}${ANSI.RESET}`; }
|
|
209
|
+
|
|
210
|
+
// ============================================================
|
|
211
|
+
// 进度条
|
|
212
|
+
// ============================================================
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* 渲染进度条
|
|
216
|
+
* @param {number} current - 当前值
|
|
217
|
+
* @param {number} total - 总量
|
|
218
|
+
* @param {number} width - 进度条字符宽度
|
|
219
|
+
* @param {Object} opts - 选项
|
|
220
|
+
* @returns {string} 格式化的进度条字符串
|
|
221
|
+
*/
|
|
222
|
+
progressBar(current, total, width = 20, opts = {}) {
|
|
223
|
+
const {
|
|
224
|
+
filledChar = '█',
|
|
225
|
+
emptyChar = '░',
|
|
226
|
+
showPercent = true,
|
|
227
|
+
color = null
|
|
228
|
+
} = opts;
|
|
229
|
+
|
|
230
|
+
const pct = total > 0 ? Math.round((current / total) * 100) : 0;
|
|
231
|
+
const clampedPct = Math.max(0, Math.min(100, pct));
|
|
232
|
+
const filled = Math.round(width * clampedPct / 100);
|
|
233
|
+
|
|
234
|
+
let bar = filledChar.repeat(filled) + emptyChar.repeat(width - filled);
|
|
235
|
+
|
|
236
|
+
if (color) {
|
|
237
|
+
bar = this.colored(bar, color);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return showPercent !== false ? `${bar} ${clampedPct}%` : bar;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* 渲染带颜色的进度条(根据百分比自动变色)
|
|
245
|
+
* @param {number} current - 当前值
|
|
246
|
+
* @param {number} total - 总量
|
|
247
|
+
* @param {number} width - 宽度
|
|
248
|
+
* @param {Object} opts - 选项
|
|
249
|
+
* @returns {string}
|
|
250
|
+
*/
|
|
251
|
+
coloredProgressBar(current, total, width = 20, opts = {}) {
|
|
252
|
+
const pct = total > 0 ? (current / total) * 100 : 0;
|
|
253
|
+
let color;
|
|
254
|
+
if (pct >= 90) color = ANSI.GREEN;
|
|
255
|
+
else if (pct >= 60) color = ANSI.BRIGHT_GREEN;
|
|
256
|
+
else if (pct >= 30) color = ANSI.YELLOW;
|
|
257
|
+
else color = ANSI.RED;
|
|
258
|
+
|
|
259
|
+
return this.progressBar(current, total, width, { ...opts, color });
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// ============================================================
|
|
263
|
+
// 边框盒子
|
|
264
|
+
// ============================================================
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* 绘制边框盒子
|
|
268
|
+
* @param {number} x - 左上角列(从1开始)
|
|
269
|
+
* @param {number} y - 左上角行(从1开始)
|
|
270
|
+
* @param {number} w - 宽度(字符数)
|
|
271
|
+
* @param {number} h - 高度(行数)
|
|
272
|
+
* @param {string} title - 标题(可选,居中显示在顶部边框)
|
|
273
|
+
* @param {string} style - 边框风格 ('single'|'double'|'rounded')
|
|
274
|
+
* @returns {string[]} 行数组
|
|
275
|
+
*/
|
|
276
|
+
box(x, y, w, h, title = '', style = 'single') {
|
|
277
|
+
const c = BORDER_CHARS[style] || BORDER_CHARS.single;
|
|
278
|
+
const lines = [];
|
|
279
|
+
|
|
280
|
+
// 顶行(可能包含标题)
|
|
281
|
+
let topLine = c.tl + c.h.repeat(w - 2) + c.tr;
|
|
282
|
+
if (title) {
|
|
283
|
+
const titleStr = ` ${title} `;
|
|
284
|
+
const titleStart = Math.floor((w - this.strWidth(titleStr)) / 2);
|
|
285
|
+
if (titleStart > 0 && titleStart + this.strWidth(titleStr) < w - 1) {
|
|
286
|
+
const before = c.h.repeat(titleStart);
|
|
287
|
+
const after = c.h.repeat(w - 2 - titleStart - this.strWidth(titleStr));
|
|
288
|
+
topLine = c.tl + before + titleStr + after + c.tr;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
lines.push(topLine);
|
|
292
|
+
|
|
293
|
+
// 中间行
|
|
294
|
+
for (let i = 1; i < h - 1; i++) {
|
|
295
|
+
lines.push(c.v + ' '.repeat(w - 2) + c.v);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// 底行(如果高度>=2)
|
|
299
|
+
if (h >= 2) {
|
|
300
|
+
lines.push(c.bl + c.h.repeat(w - 2) + c.br);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
return lines;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* 将内容放入盒子中
|
|
308
|
+
* @param {string[]} contentLines - 内容行数组
|
|
309
|
+
* @param {number} width - 盒子内部宽度
|
|
310
|
+
* @param {string} title - 标题
|
|
311
|
+
* @param {string} style - 边框风格
|
|
312
|
+
* @returns {string[]} 完整的盒子行数组
|
|
313
|
+
*/
|
|
314
|
+
boxWithContent(contentLines, width, title = '', style = 'single') {
|
|
315
|
+
const innerWidth = width - 2; // 减去两边边框
|
|
316
|
+
const paddedLines = contentLines.map(line => {
|
|
317
|
+
const displayWidth = this.strWidth(line);
|
|
318
|
+
if (displayWidth > innerWidth) {
|
|
319
|
+
return this.truncate(line, innerWidth);
|
|
320
|
+
}
|
|
321
|
+
return line + ' '.repeat(innerWidth - displayWidth);
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
const height = paddedLines.length + 2; // 内容行 + 顶底边框
|
|
325
|
+
const boxLines = this.box(1, 1, width, height, title, style);
|
|
326
|
+
|
|
327
|
+
// 将内容填入盒子中间行
|
|
328
|
+
for (let i = 0; i < paddedLines.length; i++) {
|
|
329
|
+
const borderChar = (BORDER_CHARS[style] || BORDER_CHARS.single).v;
|
|
330
|
+
boxLines[i + 1] = borderChar + paddedLines[i] + borderChar;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
return boxLines;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// ============================================================
|
|
337
|
+
// 表格
|
|
338
|
+
// ============================================================
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* 渲染表格
|
|
342
|
+
* @param {string[]} headers - 表头数组
|
|
343
|
+
* @param {string[][]} rows - 数据行二维数组
|
|
344
|
+
* @param {Object} opts - 选项
|
|
345
|
+
* @returns {string} 格式化的表格字符串
|
|
346
|
+
*/
|
|
347
|
+
table(headers, rows, opts = {}) {
|
|
348
|
+
const {
|
|
349
|
+
columnWidths = null,
|
|
350
|
+
aligns = [],
|
|
351
|
+
highlightRow = -1,
|
|
352
|
+
padStr = ' ',
|
|
353
|
+
borderStyle = 'single'
|
|
354
|
+
} = opts;
|
|
355
|
+
|
|
356
|
+
const c = BORDER_CHARS[borderStyle] || BORDER_CHARS.single;
|
|
357
|
+
const allRows = [headers, ...rows];
|
|
358
|
+
|
|
359
|
+
// 计算列宽
|
|
360
|
+
let widths = columnWidths;
|
|
361
|
+
if (!widths) {
|
|
362
|
+
widths = headers.map(() => 0);
|
|
363
|
+
for (const row of allRows) {
|
|
364
|
+
for (let i = 0; i < row.length; i++) {
|
|
365
|
+
const w = this.strWidth(String(row[i] || ''));
|
|
366
|
+
if (w > widths[i]) widths[i] = w;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
// 最小宽度3
|
|
370
|
+
widths = widths.map(w => Math.max(w, 3));
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
const totalWidth = widths.reduce((sum, w) => sum + w + 1, 0) + 1; // | between + edges
|
|
374
|
+
const lines = [];
|
|
375
|
+
|
|
376
|
+
// 分隔线生成器
|
|
377
|
+
const sep = (left, mid, right) => {
|
|
378
|
+
return left + widths.map(w => c.h.repeat(w)).join(mid) + right;
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
// 顶部分隔线
|
|
382
|
+
lines.push(sep(c.tl, c.bt, c.tr));
|
|
383
|
+
|
|
384
|
+
// 表头
|
|
385
|
+
const headerCells = headers.map((h, i) => {
|
|
386
|
+
const align = aligns[i] || 'left';
|
|
387
|
+
return this.pad(String(h || ''), widths[i], align, padStr);
|
|
388
|
+
});
|
|
389
|
+
lines.push(c.v + ' ' + headerCells.join(' ' + c.v + ' ') + ' ' + c.v);
|
|
390
|
+
|
|
391
|
+
// 表头下分隔线
|
|
392
|
+
lines.push(sep(c.lt, c.cross, c.rt));
|
|
393
|
+
|
|
394
|
+
// 数据行
|
|
395
|
+
for (let r = 0; r < rows.length; r++) {
|
|
396
|
+
const cells = rows[r].map((cell, i) => {
|
|
397
|
+
const align = aligns[i] || 'left';
|
|
398
|
+
return this.pad(String(cell || ''), widths[i], align, padStr);
|
|
399
|
+
});
|
|
400
|
+
let line = c.v + ' ' + cells.join(' ' + c.v + ' ') + ' ' + c.v;
|
|
401
|
+
|
|
402
|
+
if (r === highlightRow) {
|
|
403
|
+
line = ANSI.REVERSE + line + ANSI.RESET;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
lines.push(line);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// 底部分隔线
|
|
410
|
+
lines.push(sep(c.bl, c.bb, c.br));
|
|
411
|
+
|
|
412
|
+
return lines.join('\n');
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// ============================================================
|
|
416
|
+
// 文本工具
|
|
417
|
+
// ============================================================
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* 计算字符串显示宽度(中文=2单位)
|
|
421
|
+
* @param {string} text - 输入字符串
|
|
422
|
+
* @returns {number} 显示宽度
|
|
423
|
+
*/
|
|
424
|
+
strWidth(text) {
|
|
425
|
+
let w = 0;
|
|
426
|
+
for (const ch of String(text)) {
|
|
427
|
+
const code = ch.charCodeAt(0);
|
|
428
|
+
// CJK范围或其他全宽字符
|
|
429
|
+
if (code > 0xff ||
|
|
430
|
+
(code >= 0x3000 && code <= 0x303f) || // CJK符号和标点
|
|
431
|
+
(code >= 0x3400 && code <= 0x4dbf) || // CJK扩展A
|
|
432
|
+
(code >= 0x4e00 && code <= 0x9fff) || // CJK统一表意文字
|
|
433
|
+
(code >= 0xf900 && code <= 0xfaff) || // CJK兼容表意文字
|
|
434
|
+
(code >= 0xfe30 && code <= 0xfe4f)) { // CJK兼容形式
|
|
435
|
+
w += 2;
|
|
436
|
+
} else {
|
|
437
|
+
w += 1;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
return w;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* 文本填充到指定宽度
|
|
445
|
+
* @param {string} text - 输入文本
|
|
446
|
+
* @param {number} width - 目标宽度
|
|
447
|
+
* @param {string} align - 对齐方式 ('left'|'right'|'center')
|
|
448
|
+
* @param {string} fillChar - 填充字符
|
|
449
|
+
* @returns {string}
|
|
450
|
+
*/
|
|
451
|
+
pad(text, width, align = 'left', fillChar = ' ') {
|
|
452
|
+
const len = this.strWidth(String(text));
|
|
453
|
+
if (len >= width) return this.truncate(text, width);
|
|
454
|
+
const pad = width - len;
|
|
455
|
+
switch (align) {
|
|
456
|
+
case 'right':
|
|
457
|
+
return fillChar.repeat(pad) + text;
|
|
458
|
+
case 'center':
|
|
459
|
+
return fillChar.repeat(Math.floor(pad / 2)) + text + fillChar.repeat(Math.ceil(pad / 2));
|
|
460
|
+
default:
|
|
461
|
+
return text + fillChar.repeat(pad);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* 截断文本到指定显示宽度
|
|
467
|
+
* @param {string} text - 输入文本
|
|
468
|
+
* @param {number} maxLen - 最大显示宽度
|
|
469
|
+
* @param {string} suffix - 截断后缀(默认省略号)
|
|
470
|
+
* @returns {string}
|
|
471
|
+
*/
|
|
472
|
+
truncate(text, maxLen, suffix = '') {
|
|
473
|
+
const str = String(text);
|
|
474
|
+
if (this.strWidth(str) <= maxLen) return str;
|
|
475
|
+
|
|
476
|
+
let result = '';
|
|
477
|
+
let currentWidth = 0;
|
|
478
|
+
const targetWidth = maxLen - this.strWidth(suffix);
|
|
479
|
+
|
|
480
|
+
for (const ch of str) {
|
|
481
|
+
const chWidth = this.strWidth(ch);
|
|
482
|
+
if (currentWidth + chWidth > targetWidth) break;
|
|
483
|
+
result += ch;
|
|
484
|
+
currentWidth += chWidth;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
return result + suffix;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* 生成分割线
|
|
492
|
+
* @param {string} char - 分割字符
|
|
493
|
+
* @param {number} width - 宽度(默认终端宽度)
|
|
494
|
+
* @returns {string}
|
|
495
|
+
*/
|
|
496
|
+
separator(char = '─', width = null) {
|
|
497
|
+
const w = width || this.width;
|
|
498
|
+
return (char || '─').repeat(Math.max(1, w));
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
// ============================================================
|
|
502
|
+
// 高级布局辅助
|
|
503
|
+
// ============================================================
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* 创建多列布局
|
|
507
|
+
* @param {string[]} columns - 每列的内容字符串
|
|
508
|
+
* @param {number[]} colWidths - 每列宽度
|
|
509
|
+
* @param {number} spacing - 列间距
|
|
510
|
+
* @returns {string[]}
|
|
511
|
+
*/
|
|
512
|
+
layoutColumns(columns, colWidths, spacing = 2) {
|
|
513
|
+
const result = [];
|
|
514
|
+
const colLines = columns.map(col => col.split('\n'));
|
|
515
|
+
const maxLines = Math.max(...colLines.map(lines => lines.length), 1);
|
|
516
|
+
|
|
517
|
+
for (let i = 0; i < maxLines; i++) {
|
|
518
|
+
let line = '';
|
|
519
|
+
for (let c = 0; c < columns.length; c++) {
|
|
520
|
+
const cellLine = colLines[c][i] || '';
|
|
521
|
+
line += this.pad(cellLine, colWidths[c]);
|
|
522
|
+
if (c < columns.length - 1) {
|
|
523
|
+
line += ' '.repeat(spacing);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
result.push(line);
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
return result;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* 在指定区域居中文本
|
|
534
|
+
* @param {string} text - 文本
|
|
535
|
+
* @param {number} width - 区域宽度
|
|
536
|
+
* @returns {string}
|
|
537
|
+
*/
|
|
538
|
+
center(text, width = null) {
|
|
539
|
+
const w = width || this.width;
|
|
540
|
+
return this.pad(text, w, 'center');
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
/** 全局单例实例 */
|
|
545
|
+
const rendererInstance = new Renderer();
|
|
546
|
+
|
|
547
|
+
export default Renderer;
|
|
548
|
+
export { rendererInstance, BORDER_CHARS };
|