AppCUI-rs

AppCUI-rs 是一个快速、跨平台的 Rust 库,用于构建现代化、基于文本的用户界面(TUI),具有丰富的控件、主题和完整的 Unicode 支持——是 ncurses 和其他终端 UI 框架的替代方案。
✨ 功能
- [x] 多种开箱即用控件(按钮、标签、文本框、复选框、单选按钮、列表视图、树视图、组合框、日期/时间选择器、颜色选择器、标签页、折叠面板等)。完整控件列表见这里
- [x] 强大的布局系统,可使用绝对坐标、相对坐标、停靠、对齐、锚点或枢轴定位控件(详见这里)
- [x] 菜单和工具栏
- [x] 多平台支持(Windows 通过 API 和虚拟终端,Linux 通过 ncurses,macOS 通过 termios)
- [x] 多线程支持,允许后台任务
- [x] 定时器
- [x] 鼠标支持
- [x] 剪贴板支持
- [x] 颜色主题
- [x] 支持 Unicode 字符
- [x] 预定义对话框(消息框、输入框、颜色选择器、保存与打开对话框、文件夹导航器等)
- [x] 对支持的终端提供真彩色支持(每像素 24 位)。
📸 截图

👉 前往图库查看所有控件的完整演示!
🖥️ 后端
AppCUI 根据操作系统支持不同的后端:
- Windows 控制台 - 基于 Win32 低级 API,专为经典 Windows 控制台设计
- Windows VT - 基于 ANSI 序列,专为现代 Windows 虚拟终端设计
- NCurses - 基于 Linux 环境的 NCurses API
- Termios - 基于 ANSI 序列和 macOS 的低级 API
- Web 终端 - 专为 Web 实现设计(基于 WebGL)
- CrossTerm - 基于 crossterm
crate,通过功能标志启用
🚀 快速开始
将以下内容添加到你的 Cargo.toml:
toml
[dependencies]
appcui = "*"
然后创建一个新的 Rust 项目并添加以下代码:
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(()) }
或者使用过程宏的更简洁版本: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::*;然后使用cargo run运行项目。你应该会看到一个标题为Test的窗口,并且中间显示着Hello World !的文字。🧪 示例
AppCUI-rs 自带了一组示例帮助你快速上手。你可以在 examples 文件夹中找到它们,包括:
- 游戏,如 井字棋、贪吃蛇、Flappy Bird、扫雷、Ram it、吃豆人、国际象棋、四子棋、2048 或 俄罗斯方块
- 工具,如 计算器、CSV 查看器、温度转换器、或 计时器
- 动画,如 黑客帝国、分形、或 螺旋
- 控件/小部件,如 按钮、复选框、下拉框、日期选择器、列表视图、树视图 等等。
- 对话框,如 通知 或 输入
🛠️ 更复杂的示例
此示例创建了一个带有按钮的窗口,按下按钮时计数器会增加。
// 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(()) } ``
🛣️ 路线图
- [x] 基本组件集以及对 Windows、Linux 和 macOS 的支持
- [x] 支持 WebGL
- [ ] 支持 OpenGL / SDL / Vulkan
- [ ] TextArea 代码高亮支持
🤝 贡献指南
欢迎贡献代码、提出问题和功能请求! 请查阅 CONTRIBUTING.md 以开始参与。
欢迎在 GitHub Discussions 中参与讨论。
--- Tranlated By Open Ai Tx | Last indexed: 2026-06-13 ---