AppCUI-rs

AppCUI-rs เป็นไลบรารี Rust ที่รวดเร็วและรองรับหลายแพลตฟอร์ม สำหรับสร้างส่วนติดต่อผู้ใช้แบบข้อความ (TUI) ที่ทันสมัย พร้อมวิดเจ็ตหลากหลาย ธีม และรองรับ Unicode อย่างเต็มรูปแบบ เป็นทางเลือกแทน ncurses และเฟรมเวิร์ก UI เทอร์มินัลอื่นๆ
✨ ฟีเจอร์
- [x] ควบคุมหลายแบบพร้อมใช้งาน (ปุ่ม, ป้าย, กล่องข้อความ, เช็คบ็อกซ์, เรดิโอบัตตัน, ลิสต์วิว, ทรีวิว, คอมโบบ็อกซ์, ตัวเลือกวันที่/เวลา, ตัวเลือกสี, แท็บ, accordeons ฯลฯ) รายการควบคุมทั้งหมดดูได้ที่ นี่
- [x] ระบบจัดวางที่ทรงพลัง ให้คุณจัดตำแหน่งควบคุมด้วยพิกัดแบบสัมบูรณ์, สัมพัทธ์, docking, alignment, anchors หรือ pivot positioning (ดูเพิ่มเติม ที่นี่)
- [x] เมนูและทูลบาร์
- [x] รองรับหลายแพลตฟอร์ม (Windows ผ่าน API และ virtual terminal, Linux ผ่าน ncurses, MacOS ผ่าน termios)
- [x] รองรับมัลติเธรดสำหรับงานเบื้องหลัง
- [x] ตั้งเวลา
- [x] รองรับเมาส์
- [x] รองรับคลิปบอร์ด
- [x] ธีมสี
- [x] รองรับอักขระ Unicode
- [x] กล่องโต้ตอบที่กำหนดไว้ล่วงหน้า (message box, input box, color picker, save & open dialogs, folder navigator ฯลฯ)
- [x] รองรับ true colors (24 บิตต่อพิกเซล) สำหรับเทอร์มินัลที่รองรับ
📸 ภาพหน้าจอ

👉 ดู Gallery เพื่อชมเดโมของทุกควบคุม!
🖥️ แบ็คเอนด์
AppCUI รองรับแบ็คเอนด์หลายแบบตามระบบปฏิบัติการที่ใช้งาน
- Windows Console - พื้นฐานบน Win32 low level API ออกแบบสำหรับคอนโซลวินโดว์แบบคลาสสิก
- Windows VT - พื้นฐานบน ANSI sequances ออกแบบสำหรับเทอร์มินัลเสมือนวินโดว์ยุคใหม่
- NCurses - พื้นฐานบน NCurses API สำหรับสภาพแวดล้อมลินุกซ์
- Termios - พื้นฐานบน ANSI sequances และ low level APIs สำหรับ MAC OSX
- Web Terminal - ออกแบบสำหรับการใช้งานบนเว็บ (พื้นฐานบน webgl)
- CrossTerm - พื้นฐานบน crossterm
crate แต่เปิดใช้งานผ่าน 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, Chees, 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 wil start the window loop and messaage 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-02-09 ---