Web Analytics

AppCUI-rs

⭐ 358 stars Thai by gdt050579

🌐 ภาษา

AppCUI-rs

`` ⯈ 𝗔𝗽𝗽𝗖𝗨𝗜-𝗿𝘀 🖳


Windows Build Status
Linux Build Status
MacOS Build Status
Code Coverage
License
Crates.io
Docs.rs
Gallery

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
สามารถอ่านข้อมูลเพิ่มเติมเกี่ยวกับ backend ที่รองรับได้ ที่นี่

🚀 เริ่มต้นใช้งานอย่างรวดเร็ว

เพิ่มบรรทัดต่อไปนี้ลงในไฟล์ 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(()) }

จากนั้นให้รันโปรเจกต์ด้วยคำสั่ง cargo run คุณจะเห็นหน้าต่างที่มีชื่อว่า Test และข้อความ Hello World ! อยู่ตรงกลาง

🧪 ตัวอย่าง

AppCUI-rs มาพร้อมกับชุดตัวอย่างเพื่อช่วยให้คุณเริ่มต้นใช้งาน คุณสามารถพบตัวอย่างเหล่านี้ได้ในโฟลเดอร์ examples ซึ่งรวมถึง:

🛠️ ตัวอย่างที่ซับซ้อนมากขึ้น

ตัวอย่างนี้จะสร้างหน้าต่างที่มีปุ่ม ซึ่งเมื่อกดปุ่มแล้วจะเพิ่มตัวนับเลข

rust use appcui::prelude::*;

// 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