TermX là terminal emulator native cho macOS, viết bằng Swift và AppKit. Mục tiêu của dự án là tạo terminal nhẹ, khởi động nhanh, render mượt và hòa hợp với trải nghiệm macOS.
- Native macOS app, không phụ thuộc framework đa nền tảng.
- Khởi động nhanh, độ trễ input thấp.
- Hỗ trợ shell mặc định của người dùng như
zshhoặcbash. - Hỗ trợ PTY, ANSI escape codes, scrollback và tab workflow.
- Tối ưu CPU, RAM và năng lượng.
| Thành phần | Công nghệ |
|---|---|
| Language | Swift 5.9+ |
| UI | AppKit |
| Terminal backend | forkpty qua C bridge |
| Build project | XcodeGen |
| Native C bridge | CMake / C |
| Target | macOS 13.0+ |
TermX/
├── Sources/
│ ├── App/ App lifecycle, window, tab
│ ├── Core/ PTY, shell session, terminal buffer
│ ├── Terminal/ Rendering, ANSI handling, input mapping
│ ├── UI/ AppKit wrappers
│ └── Utils/ Shared utilities
├── Resources/ Info.plist, entitlements, assets
├── libvtutil/ C bridge for PTY operations
├── docs/ Developer documentation
├── plans/ Implementation plans
├── project.yml XcodeGen config
└── CMakeLists.txt C bridge build config
- macOS 13.0+
- Xcode 15+
- XcodeGen 2.40+
Cài XcodeGen nếu chưa có:
brew install xcodegenGenerate Xcode project:
make generateBuild app:
make buildBuild rồi mở app:
make devBuild rồi chạy binary trực tiếp để xem log trong terminal:
make runMở app đã build sẵn, không build lại:
make openRestart app đã build sẵn, không build lại:
make rerunDọn build output:
make cleanNếu không muốn dùng make, có thể chạy trực tiếp:
xcodegen generate --spec project.yml
xcodebuild \
-project TermX.xcodeproj \
-scheme TermX \
-configuration Debug \
-derivedDataPath .derived-data \
build
open .derived-data/Build/Products/Debug/TermX.appĐã có foundation ban đầu:
- XcodeGen project config.
- AppKit app lifecycle.
- Main window và native tab controller.
- PTY bridge qua
forkpty. - Shell session đọc/ghi dữ liệu thật.
- NSTextView terminal view tối thiểu.
- Keyboard mapping cơ bản cho arrow keys, Home/End, Page Up/Down, F1-F4.
Giới hạn hiện tại:
- ANSI escape sequences hiện được strip để hiển thị text sạch, chưa preserve màu/style.
- Scrollback buffer hiện là implementation đơn giản, cần nâng cấp sang ring buffer đúng nghĩa.
- Chưa có test suite tự động.
- Implement ANSI parser giữ style spans: color, bold, underline, true color.
- Thay scrollback bằng circular/ring buffer O(1).
- Dirty-region rendering để tránh redraw toàn màn hình.
- Resize/reflow theo PTY size.
- Preferences UI cho font size, theme và shell path.
- Ưu tiên độ đúng của terminal core.
- Không block main thread bằng parsing hoặc I/O.
- Hot path phải tránh O(n²) và object allocation không cần thiết.
- Dùng
struct/enumcho dữ liệu terminal khi có thể. - Chỉ dùng
classkhi cần identity, lifecycle hoặc AppKit subclassing.