AppCUI-rs

AppCUI-rs là thư viện Rust nhanh, đa nền tảng để xây dựng giao diện người dùng dạng văn bản (TUI) hiện đại với các widget phong phú, chủ đề, hỗ trợ Unicode đầy đủ—là giải pháp thay thế cho ncurses và các framework giao diện terminal khác.
✨ Tính năng
- [x] nhiều control có sẵn (nút bấm, nhãn, hộp văn bản, hộp kiểm, nút radio, danh sách, cây, combo box, chọn ngày/giờ, chọn màu, tab, accordion, v.v.). Danh sách đầy đủ control xem tại đây
- [x] hệ thống layout mạnh mẽ cho phép định vị control bằng tọa độ tuyệt đối, tương đối, docking, căn chỉnh, anchor hoặc pivot (xem chi tiết tại đây)
- [x] menu và thanh công cụ
- [x] hỗ trợ đa nền tảng (Windows qua API và virtual terminal, Linux qua ncurses, macOS qua termios)
- [x] hỗ trợ đa luồng cho tác vụ nền
- [x] bộ đếm thời gian
- [x] hỗ trợ chuột
- [x] hỗ trợ clipboard
- [x] chủ đề màu sắc
- [x] hỗ trợ ký tự Unicode
- [x] hộp thoại định sẵn (message box, input box, chọn màu, lưu & mở file, duyệt thư mục, v.v.)
- [x] hỗ trợ màu thực (24 bit/pixel) cho terminal hỗ trợ.
📸 Ảnh chụp màn hình

👉 Xem Thư viện hình ảnh để trải nghiệm demo đầy đủ các control!
🖥️ Backend
AppCUI hỗ trợ nhiều backend tùy theo hệ điều hành:
- Windows Console - dựa trên API cấp thấp Win32, được thiết kế cho console Windows cổ điển
- Windows VT - dựa trên các chuỗi ANSI, được thiết kế cho các terminal ảo Windows hiện đại
- NCurses - dựa trên API NCurses dành cho môi trường Linux
- Termios - dựa trên các chuỗi ANSI và API cấp thấp cho macOS
- Web Terminal - được thiết kế cho các triển khai web (dựa trên WebGL)
- CrossTerm - dựa trên crate crossterm
, được bật thông qua cờ tính năng
🚀 Bắt đầu nhanh
Thêm nội dung sau vào file Cargo.toml của bạn:
toml
[dependencies]
appcui = "*"
Sau đó tạo một dự án Rust mới và thêm đoạn mã sau:rust
use appcui::prelude::*;fn main() -> Result<(), appcui::system::Error> { let mut app = App::new().build()?; let mut win = Window::new( "Test", LayoutBuilder::new().alignment(Alignment::Center).width(30).height(9).build(), window::Flags::Sizeable, ); win.add(Label::new( "Hello World !", LayoutBuilder::new().alignment(Alignment::Center).width(13).height(1).build(), )); app.add_window(win); app.run(); Ok(()) }
Hoặc một phiên bản gọn hơn sử dụng proc-macros:
rs
use appcui::prelude::*;fn main() -> Result<(), appcui::system::Error> { let mut app = App::new().build()?; let mut win = window!("Test,a:c,w:30,h:9"); win.add(label!("'Hello World !',a:c,w:13,h:1")); app.add_window(win); app.run(); Ok(()) }
rust use appcui::prelude::*;Sau đó chạy dự án vớicargo run. Bạn sẽ thấy một cửa sổ với tiêu đềTestvà dòng chữHello World !ở giữa màn hình.🧪 Ví dụ
AppCUI-rs đi kèm với một bộ ví dụ để giúp bạn bắt đầu. Bạn có thể tìm thấy chúng trong thư mục examples, bao gồm:
- Trò chơi như Tic Tac Toe, Snake, Flappy Bird, Minesweeper, Ram it, PacMan, Chess, Connect Four, 2048, hoặc Tetris
- Tiện ích như Calculator, CSV Viewer, Temperature Converter, hoặc Timer
- Hoạt hình như Matrix, Fractals, hoặc Spiral
- Controls/Widgets như Button, CheckBox, ComboBox, DatePicker, ListView, TreeView và nhiều hơn nữa.
- Hộp thoại như Notification hoặc Input
🛠️ Ví dụ phức tạp hơn
Một ví dụ tạo ra một cửa sổ với một nút bấm, khi nhấn sẽ tăng một bộ đếm.
// Create a window that handles button events and has a counter #[Window(events = ButtonEvents)] struct CounterWindow { counter: i32 }
impl CounterWindow { fn new() -> Self { let mut w = Self { // set up the window title and position base: window!("'Counter window',a:c,w:30,h:5"), // initial counter is 1 counter: 1 }; // add a single button with the caption "1" (like the counter) w.add(button!("'1',d:b,w:20")); w } } impl ButtonEvents for CounterWindow { // When the button is pressed, this function will be called // with the handle of the button that was pressed // Since we only have one button, we don't need to store its handle // in the struct, as we will receive the handle via the on_pressed method fn on_pressed(&mut self, handle: Handle
fn main() -> Result<(), appcui::system::Error> { // create a new application let mut a = App::new().build()?; // add a new window (of type CounterWindow) to the application a.add_window(CounterWindow::new()); // Run AppCUI framework (this will start the window loop and message passing) a.run(); Ok(()) } ``
🛣️ Lộ trình phát triển
- [x] Bộ widget cơ bản và hỗ trợ cho Windows, Linux, và macOS
- [x] Hỗ trợ WebGL
- [ ] Hỗ trợ OpenGL / SDL / Vulkan
- [ ] Hỗ trợ TextArea cho tô sáng mã nguồn
🤝 Đóng góp
Chào mừng các đóng góp, báo lỗi, và yêu cầu tính năng mới! Hãy xem CONTRIBUTING.md để bắt đầu.
Tham gia thảo luận tại GitHub Discussions.
--- Tranlated By Open Ai Tx | Last indexed: 2026-06-13 ---