Metadata-Version: 2.4
Name: xiepengcheng
Version: 0.4.0
Summary: A growing collection of tools: a Textual-based menu shell and an inline questionary-based network adapter picker.
Author-email: xiepengcheng <xiepengcheng2030@gmail.com>
License-Expression: MIT
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: textual>=0.55
Requires-Dist: questionary>=2.0
Dynamic: license-file

# xiepengcheng

Python 工具集合，目前包含：

- `MenuApp`：基于 [Textual](https://github.com/Textualize/textual) 的全屏终端菜单外壳，菜单项由外部传入
- `select_network_adapter`：基于 [questionary](https://github.com/tmbo/questionary) 的内联（非全屏）网络适配器选择器（仅支持 Windows）

```bash
pip install xiepengcheng
```

## 网络适配器选择

```python
import xiepengcheng

adapter = xiepengcheng.select_network_adapter()
if adapter:
    print(adapter.name, adapter.ip_addresses, adapter.mac_address, adapter.is_up)
```

也可以跳过交互，直接拿列表自己处理：

```python
from xiepengcheng import list_network_adapters

for a in list_network_adapters():
    print(a.name, a.description, a.mac_address, a.ip_addresses, a.status)
```

`NetworkAdapter` 字段：`id`（系统级标识符，程序里应该用它而不是 `name` 来指定网卡）、`name`、`description`、`mac_address`、`ip_addresses`、`status`、`speed`，以及派生属性 `is_up`。

## 全屏菜单（MenuApp）

菜单项可以是 `MenuItem` 对象，也可以是内置菜单的名称字符串（目前内置："网络适配器选择"）：

```python
import xiepengcheng

# 空菜单
xiepengcheng.MenuApp().run()

# 外部传入菜单项
items = [
    xiepengcheng.MenuItem(label="功能 A", description="这里是功能 A 的详情"),
    xiepengcheng.MenuItem(label="功能 B", action=lambda: print("执行功能 B")),
    "网络适配器选择",
]
result = xiepengcheng.MenuApp(items=items, title="我的工具").run()
```

交互方式：上下箭头选择，回车进入子菜单/详情/直接返回结果，Esc 或再次回车返回上一级，`q` 退出。
