Files
Rtty/README.md

61 lines
3.7 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 🚀 Rtty 项目设计总结与架构指南
## 📝 一句话描述
> **Rtty 是一款基于 Rust 与 Flutter 构建的高性能、跨平台虚拟终端系统,通过服务端状态保持与多端解耦渲染,实现 PC 端工业级 ANSI 兼容与移动端原生语义化重排。**
---
## 🏗️ 系统整体架构图
```
┌───────────────────────────────┐
│ Rtty Server (Rust 后端) │
│ • portable-pty (进程/Shell) │
│ • alacritty_terminal (真相源)│
└───────────────┬───────────────┘
WebSocket (JSON / ANSI 字节流)
┌─────────────────────────┴─────────────────────────┐
▼ ▼
┌───────────────────────────────┐ ┌───────────────────────────────┐
│ Rtty Desktop (PC 客户端) │ │ Rtty Mobile (移动客户端) │
│ • flutter_alacritty (FFI) │ │ • Flutter Native Controls │
│ • Canvas 经典 ANSI 网格 │ │ • ListView + RichText 重排 │
│ • 100% 工业级 ANSI 兼容 │ │ • 自适应换行 / 卡片化 UI │
└───────────────────────────────┘ └───────────────────────────────┘
```
---
## 🛠️ 核心组件与职责划分
### 1. **服务端内核 (`rtty-server`)**
* **`portable-pty`**:负责底层的 POSIX/Windows 伪终端创建、子进程Shell/Bash/Zsh拉起与文件描述符读写。
* **`alacritty_terminal`**:作为整个系统的“真相源 (Source of Truth)”,在内存中实时解析 ANSI 序列,维护 2D 屏幕网格Grid、光标位置及历史回滚缓冲区同时提供断线重连时的快照恢复Dump Screen Snapshot
* **`WebSocket (Axum/Tokio)`**:负责与各终端建立双向实时通信,分发事件流与控制信号。
### 2. **桌面端渲染管线 (`rtty-desktop`)**
* **`flutter_alacritty` (Rust FFI 绑定)**PC 端放弃纯 Dart 的轻量级解析,直接调用本地 C-Bindings 共享 `alacritty_terminal` 的 Rust 渲染引擎。
* **渲染特性**Canvas 纯网格高效绘制,保持对 `vim``htop``tmux` 等全屏 ANSI 软件的 100% 工业级兼容与真彩显示。
### 3. **移动端渲染管线 (`rtty-mobile`)**
* **Flutter Native 组件重排**:移动端抛弃传统 2D 字符网格,采用语义化数据拆解。
* **渲染特性**
* **命令与输出**:封装为 `ListView` 卡片支持文本按词软换行Word Wrap彻底消除横向滚动条与小字号看不清的痛点。
* **键盘与交互**:吸底 Command Input 配合移动端专属快捷键工具栏Keybar
---
## 💡 Rtty 的三大核心设计优势
1. **状态与渲染解耦**:服务端 Rust 负责维持单一终端状态,客户端按平台特性自由渲染。
2. **前后端内核统一**:后端与 PC 端共享 `alacritty_terminal` 引擎,解析行为 100% 绝对一致。
3. **移动端体验革新**:告别画面缩放与 TUI 错乱,用 Native UI 呈现命令行数据。