Web Analytics

AppCUI-rs

⭐ 358 stars Traditional Chinese by gdt050579

🌐 語言

AppCUI-rs

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


Windows 建置狀態
Linux 建置狀態
MacOS 建置狀態
程式碼覆蓋率
授權
Crates.io
Docs.rs
Gallery

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 Console - 基於 Win32 低階 API,設計用於傳統 Windows 主控台
  • Windows VT - 基於 ANSI 序列,設計用於現代 Windows 虛擬終端機
  • NCurses - 基於 NCurses API,適用於 Linux 環境
  • Termios - 基於 ANSI 序列及 MAC OSX 低階 API
  • Web Terminal - 為 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(()) }

或使用 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