Files
Rtty/desktop/README.md

64 lines
2.2 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 Desktop (桌面端)
Rtty 的 Flutter Windows 桌面终端客户端。连接 `rtty-server`Rust 后端),通过
**`flutter_alacritty`**Alacritty Rust 引擎的 Flutter 绑定)做 **100% 工业级
ANSI 渲染**,完美支持 vim / neovim / htop / tmux 等全屏 TUI 应用。
## 架构
```
rtty-server (Rust, alacritty_terminal 真相源)
│ WebSocket (ws://host:8080/ws?client=desktop)
│ • JSON 控制帧 (ready / error / session_closed)
│ • 二进制帧 = 原始 ANSI 字节流
rtty-desktop (Flutter / Windows)
• RttyPtyBackend —— 实现 flutter_alacritty 的 PtyBackend 接口,桥接 WebSocket
• TerminalEngine —— Alacritty Rust 引擎(解析 ANSI / 维护网格 / GPU 渲染)
• TerminalView —— 终端渲染 + 输入/剪贴板/滚动
• ConnectionBar —— 顶部连接控制条
```
关键点:`PtyBackend` 抽象正是 `flutter_alacritty` 为远程WebSocket/SSH数据源
预留的扩展点。本地版用 `FlutterPtyBackend`(自带 PTY本项目用自定义
`RttyPtyBackend` 把 WebSocket 原始 ANSI 流接入引擎,实现"远程 PTY + 本地
alacritty 渲染",服务端与 PC 端共享同一 Alacritty 引擎。
## 运行
```bash
# 1. 先启动 Rust 服务端(仓库根目录)
cd .. && cargo run
# 2. 启动桌面端
cd desktop
flutter run -d windows
```
## 构建
```bash
# release 会连同 Alacritty Rust 引擎一起编译(首次较慢)
flutter build windows --release
# 产物build/windows/x64/runner/Release/rtty_desktop.exe
```
## 测试
```bash
# Widget 测试(无需服务端)
flutter test test/widget_test.dart
# 端到端集成测试(需先启动 Rust 服务端;离线时自动跳过)
flutter test test/e2e_ws_test.dart
flutter test test/regression_ws_test.dart
```
## 协议要点
- 连接 `ws://host:port/ws?client=desktop``client` 声明端类型,实现多端解耦)。
- 服务端 `ready` 帧携带会话 ID 与初始尺寸,驱动引擎网格。
- PTY 输出以二进制帧下发,经 `RttyPtyBackend.output` 喂给引擎渲染。
- 键盘输入由引擎产生,经 `RttyPtyBackend.write` 发回服务端写入远端 PTY。
- 窗口尺寸变化经 `TerminalView.onPtyResize``RttyPtyBackend.resize` 同步。