# promptt 架构图
> Interactive CLI prompts library for Rust (text, confirm, number, select, toggle, list, password, invisible)
## 1. 高层架构
```mermaid
flowchart TB
subgraph Entry["入口层"]
main["main.rs<br/>Demo Binary"]
lib["lib.rs<br/>Library Root"]
end
subgraph Core["核心层"]
prompts["prompts.rs<br/>Question → PromptValue<br/>run_prompt"]
end
subgraph Elements["元素层 (elements/)"]
confirm["confirm.rs"]
number["number.rs"]
text["text.rs"]
select["select.rs"]
toggle["toggle.rs"]
prompt_base["prompt.rs"]
end
subgraph Util["工具层 (util/)"]
action["action.rs"]
style["style.rs"]
clear["clear.rs"]
figures["figures.rs"]
lines["lines.rs"]
strip["strip.rs"]
end
main --> lib
lib --> prompts
lib --> Elements
lib --> Util
prompts --> Elements
prompts --> style
Elements --> style
Elements --> figures
Elements --> prompt_base
style --> figures
clear --> strip
lines --> strip
```
## 2. 模块依赖关系
```mermaid
flowchart LR
subgraph lib
prompt_fn["prompt()"]
end
subgraph prompts_rs
run_prompt["run_prompt()"]
Question["Question"]
PromptValue["PromptValue"]
end
subgraph elements
run_confirm["run_confirm"]
run_number["run_number"]
run_text["run_text"]
run_select["run_select"]
run_toggle["run_toggle"]
end
subgraph util
action["action"]
style["style"]
clear["clear"]
figures["figures"]
lines["lines"]
strip["strip"]
end
prompt_fn --> run_prompt
run_prompt --> run_confirm
run_prompt --> run_number
run_prompt --> run_text
run_prompt --> run_select
run_prompt --> run_toggle
run_prompt --> style
run_confirm --> style
run_number --> style
run_text --> style
run_select --> style
run_select --> figures
run_toggle --> style
style --> figures
clear --> strip
lines --> strip
```
## 3. 数据流
```mermaid
flowchart TD
A["Questions: Vec<Question>"] --> B["prompt()"]
B --> C{"for each Question"}
C --> D["run_prompt(q, stdin, stdout)"]
D --> E{"type_name"}
E -->|text/password/invisible| F["run_text"]
E -->|confirm| G["run_confirm"]
E -->|number| H["run_number"]
E -->|select| I["run_select"]
E -->|toggle| J["run_toggle"]
E -->|list| K["run_text (list)"]
F --> L["PromptValue"]
G --> L
H --> L
I --> L
J --> L
K --> L
L --> M["HashMap<String, PromptValue>"]
M --> N["answers"]
```
## 4. 支持的问题类型映射
| type_name | 元素 | 返回类型 |
| password | `run_text` (InputStyle::Password) | `PromptValue::String` |
| invisible | `run_text` (InputStyle::Invisible) | `PromptValue::String` |
| number | `run_number` | `PromptValue::Float` |
| confirm | `run_confirm` | `PromptValue::Bool` |
| toggle | `run_toggle` | `PromptValue::String` |
| select | `run_select` | `PromptValue::String` |
| list | `run_text` (split by separator) | `PromptValue::List` |
## 5. 文件结构
```
src/
├── lib.rs # 库入口,prompt() API,re-exports
├── main.rs # Demo 二进制
├── prompts.rs # Question, PromptValue, run_prompt 分发逻辑
├── elements/
│ ├── mod.rs
│ ├── prompt.rs # 基础 Prompt trait (bell)
│ ├── confirm.rs # Y/n 确认
│ ├── number.rs # 数字输入 (min/max, int/float)
│ ├── text.rs # 文本/密码/不可见/列表
│ ├── select.rs # 选择列表 (TTY 交互 / 非 TTY 行模式)
│ └── toggle.rs # 开关 (on/off)
└── util/
├── mod.rs
├── action.rs # Key → PromptAction 映射
├── figures.rs # Unicode 符号 (tick, cross, arrows)
├── style.rs # InputStyle, StyleTransform, 渲染样式
├── clear.rs # ANSI 清行
├── lines.rs # 换行计数
└── strip.rs # ANSI 转义移除 (regex)
```
## 6. 外部依赖
```
ansi-escapes → prompt (bell)
colour → 彩色输出
crossterm → select 交互 (raw mode)
regex → strip (ANSI 移除)
```