Web Analytics

AppCUI-rs

⭐ 376 stars Traditional Chinese by gdt050579

🌐 語言

AppCUI-rs

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


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

AppCUI-rs 是一個快速、跨平台的 Rust 函式庫,用於構建現代文字基礎的使用者介面(TUI),擁有豐富的元件、主題與完整的 Unicode 支援——是 ncurses 及其他終端介面框架的替代方案。

✨ 功能特色

  • [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 - 基於 Linux 環境下的 NCurses API
  • Termios - 基於 ANSI 序列及 macOS 的低階 API
  • Web Terminal - 為網頁實現所設計(基於 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