AppCUI-rs

AppCUI-rs คือไลบรารี Rust ที่รวดเร็ว รองรับข้ามแพลตฟอร์ม สำหรับสร้างอินเทอร์เฟซผู้ใช้แบบข้อความ (TUI) สมัยใหม่ที่มีวิดเจ็ต ธีม และรองรับ Unicode อย่างเต็มรูปแบบ—เป็นทางเลือกแทน ncurses และเฟรมเวิร์ก UI บนเทอร์มินัลอื่น ๆ
✨ คุณสมบัติ
- [x] คอนโทรลหลากหลายแบบพร้อมใช้งาน (ปุ่ม, ป้ายกำกับ, กล่องข้อความ, กล่องเช็ค, ปุ่มวิทยุ, รายการ, มุมมองต้นไม้, คอมโบ, ตัวเลือกวันที่/เวลา, ตัวเลือกสี, แท็บ, แอคคอร์เดียน ฯลฯ) ดูรายการทั้งหมด ที่นี่
- [x] ระบบเลย์เอาต์ที่ทรงพลัง ให้คุณจัดตำแหน่งคอนโทรลด้วยค่าพิกัดแบบสัมบูรณ์ แบบสัมพันธ์ การ dock การจัดแนว anchor หรือ pivot (ดูเพิ่มเติม ที่นี่)
- [x] เมนูและทูลบาร์
- [x] รองรับหลายแพลตฟอร์ม (Windows ผ่าน API และ virtual terminal, Linux ผ่าน ncurses, macOS ผ่าน termios)
- [x] รองรับมัลติเธรดสำหรับงานพื้นหลัง
- [x] ตัวจับเวลา (timers)
- [x] รองรับเมาส์
- [x] รองรับคลิปบอร์ด
- [x] ธีมสี
- [x] รองรับอักขระ Unicode
- [x] ไดอะล็อกที่กำหนดไว้ล่วงหน้า (กล่องข้อความ, กล่องอินพุต, ตัวเลือกสี, กล่องเซฟ & เปิดไฟล์, ตัวนำทางโฟลเดอร์ ฯลฯ)
- [x] รองรับ True-color (24 บิตต่อพิกเซล) สำหรับเทอร์มินัลที่รองรับ
📸 ตัวอย่างภาพหน้าจอ

👉 ดู แกลเลอรี สำหรับตัวอย่างเดโมของคอนโทรลทั้งหมด!
🖥️ แบ็คเอนด์
AppCUI รองรับแบ็คเอนด์ที่หลากหลายขึ้นอยู่กับระบบปฏิบัติการ:
- Windows Console - อิงตาม Win32 low-level API ออกแบบมาสำหรับคอนโซล Windows แบบคลาสสิก
- Windows VT - อิงตาม ANSI sequences ออกแบบมาสำหรับ virtual terminal สมัยใหม่ของ Windows
- NCurses - อิงตาม NCurses API สำหรับสภาพแวดล้อม Linux
- Termios - อิงตาม ANSI sequences และ low-level APIs สำหรับ macOS
- Web Terminal - ออกแบบมาสำหรับการใช้งานบนเว็บ (อิงตาม WebGL)
- CrossTerm - อิงตาม crate crossterm
เปิดใช้งานผ่าน feature flag
🚀 เริ่มต้นอย่างรวดเร็ว
เพิ่มบรรทัดต่อไปนี้ลงในไฟล์ 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(()) }
หรือเวอร์ชันที่กระชับกว่าด้วยการใช้ 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::*;จากนั้นให้รันโปรเจคด้วยcargo runคุณจะเห็นหน้าต่างที่มีชื่อว่าTestและข้อความHello World !อยู่ตรงกลาง🧪 ตัวอย่าง
AppCUI-rs มาพร้อมกับชุดตัวอย่างเพื่อช่วยให้คุณเริ่มต้น คุณสามารถพบตัวอย่างเหล่านี้ได้ในโฟลเดอร์ examples รวมถึง:
- เกม เช่น Tic Tac Toe, Snake, Flappy Bird, Minesweeper, Ram it, PacMan, Chess, Connect Four, 2048, หรือ Tetris
- เครื่องมือ เช่น Calculator, CSV Viewer, Temperature Converter, หรือ Timer
- แอนิเมชัน เช่น Matrix, Fractals, หรือ Spiral
- คอนโทรล/วิดเจ็ต เช่น Button, CheckBox, ComboBox, DatePicker, ListView, TreeView และอีกมากมาย
- ไดอะล็อก เช่น Notification หรือ Input
🛠️ ตัวอย่างที่ซับซ้อนมากขึ้น
ตัวอย่างที่สร้างหน้าต่างพร้อมปุ่ม ซึ่งเมื่อกดปุ่มจะเพิ่มค่าตัวนับ
// 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 ---