TUT/NEXT_STEPS.md
m1ngsama 8d56a7b67b feat: Add persistent browsing history
- Implement HistoryManager for JSON persistence (~/.config/tut/history.json)
- Auto-record page visits with URL, title, and timestamp
- Update visit time when revisiting URLs (move to front)
- Limit to 1000 entries maximum
- Add :history command to view browsing history
- History entries are clickable links
- Add test_history test suite
2025-12-27 18:13:40 +08:00

5.4 KiB

TUT 2.0 - 下次继续从这里开始

当前位置

  • 阶段: Phase 7 - 历史记录持久化 (已完成!)
  • 进度: 历史记录自动保存,支持 :history 命令查看
  • 最后提交: feat: Add persistent browsing history

立即可做的事

1. 使用书签功能

  • B - 添加当前页面到书签
  • D - 从书签中移除当前页面
  • :bookmarks:bm - 查看书签列表

书签存储在 ~/.config/tut/bookmarks.json

2. 查看历史记录

  • :history:hist - 查看浏览历史

历史记录存储在 ~/.config/tut/history.json

已完成的功能清单

Phase 7 - 历史记录持久化

  • HistoryEntry 数据结构 (URL, 标题, 访问时间)
  • JSON 持久化存储 (~/.config/tut/history.json)
  • 自动记录访问历史
  • 重复访问更新时间
  • 最大 1000 条记录限制
  • :history 命令查看历史页面
  • 历史链接可点击跳转

Phase 6 - 异步HTTP

  • libcurl multi接口实现非阻塞请求
  • AsyncState状态管理 (IDLE/LOADING/COMPLETE/FAILED/CANCELLED)
  • start_async_fetch() 启动异步请求
  • poll_async() 非阻塞轮询
  • cancel_async() 取消请求
  • 加载动画 (旋转spinner: ⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏)
  • Esc键取消加载
  • 主循环50ms轮询集成

Phase 5 - 书签管理

  • 书签数据结构 (URL, 标题, 添加时间)
  • JSON 持久化存储 (~/.config/tut/bookmarks.json)
  • 添加书签 (B 键)
  • 删除书签 (D 键)
  • 书签列表页面 (:bookmarks 命令)
  • 书签链接可点击跳转

Phase 4 - 图片支持

  • <img> 标签解析 (src, alt, width, height)
  • 图片占位符显示 [alt text][Image: filename]
  • BinaryResponse 结构体
  • HttpClient::fetch_binary() 方法
  • ImageRenderer 类框架
  • PPM 格式内置解码
  • stb_image.h 集成 (PNG/JPEG/GIF/BMP 支持)
  • 浏览器中的图片下载和渲染
  • ASCII Art 彩色渲染 (True Color)

Phase 3 - 性能优化

  • LRU 页面缓存 (20页, 5分钟过期)
  • 差分渲染 (只更新变化的单元格)
  • 批量输出优化
  • 加载状态指示

Phase 2 - 交互增强

  • 搜索功能 (/, n/N)
  • 搜索高亮
  • Tab 切换链接时自动滚动
  • 窗口大小动态调整
  • 表单渲染 (input, button, checkbox, radio, select)
  • POST 表单提交

Phase 1 - 核心架构

  • Terminal 抽象层 (raw mode, True Color)
  • FrameBuffer 双缓冲
  • Renderer 差分渲染
  • LayoutEngine 布局引擎
  • DocumentRenderer 文档渲染
  • Unicode 宽度计算 (CJK 支持)
  • 温暖护眼配色方案

代码结构

src/
├── browser.cpp/h         # 主浏览器 (pImpl模式)
├── main.cpp              # 程序入口点
├── http_client.cpp/h     # HTTP 客户端 (支持二进制和异步)
├── dom_tree.cpp/h        # DOM 树
├── html_parser.cpp/h     # HTML 解析
├── input_handler.cpp/h   # 输入处理
├── bookmark.cpp/h        # 书签管理
├── history.cpp/h         # 历史记录管理
├── render/
│   ├── terminal.cpp/h    # 终端抽象 (ncurses)
│   ├── renderer.cpp/h    # FrameBuffer + 差分渲染
│   ├── layout.cpp/h      # 布局引擎 + 文档渲染
│   ├── image.cpp/h       # 图片渲染器 (ASCII Art)
│   ├── colors.h          # 配色方案定义
│   └── decorations.h     # Unicode 装饰字符
└── utils/
    ├── unicode.cpp/h     # Unicode 处理
    └── stb_image.h       # 图片解码库

tests/
├── test_terminal.cpp     # Terminal 测试
├── test_renderer.cpp     # Renderer 测试
├── test_layout.cpp       # Layout + 图片占位符测试
├── test_http_async.cpp   # HTTP 异步测试
├── test_html_parse.cpp   # HTML 解析测试
├── test_bookmark.cpp     # 书签测试
└── test_history.cpp      # 历史记录测试

构建与运行

# 构建
cmake -B build -S . -DCMAKE_BUILD_TYPE=Debug
cmake --build build

# 运行
./build/tut                      # 显示帮助
./build/tut https://example.com  # 打开网页

# 测试
./build/test_terminal      # 终端测试
./build/test_renderer      # 渲染测试
./build/test_layout        # 布局+图片测试
./build/test_http_async    # HTTP异步测试
./build/test_html_parse    # HTML解析测试
./build/test_bookmark      # 书签测试

快捷键

功能
j/k 上下滚动
Ctrl+d/u 翻页
gg/G 顶部/底部
Tab/Shift+Tab 切换链接
Enter 跟随链接
h/l 后退/前进
/ 搜索
n/N 下一个/上一个匹配
r 刷新 (跳过缓存)
B 添加书签
D 删除书签
:o URL 打开URL
:bookmarks 查看书签
:history 查看历史
:q 退出
? 帮助
Esc 取消加载

下一步功能优先级

  1. 更多表单交互 - 文本输入编辑,下拉选择
  2. 图片缓存 - 避免重复下载相同图片
  3. 异步图片加载 - 图片也使用异步加载
  4. Cookie 支持 - 保存和发送 Cookie

恢复对话时说

"继续TUT 2.0开发"

Git 信息

# 恢复开发
git clone https://github.com/m1ngsama/TUT.git
cd TUT
cmake -B build -S . -DCMAKE_BUILD_TYPE=Debug
cmake --build build
./build/tut

更新时间: 2025-12-27