Web Analytics

AppCUI-rs

⭐ 376 stars Thai by gdt050579

🌐 ภาษา

AppCUI-rs

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


สถานะการ Build บน Windows
สถานะการ Build บน Linux
สถานะการ Build บน macOS
การครอบคลุมของโค้ด
ไลเซนส์
Crates.io
Docs.rs
Gallery

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