π¦ Feather-Tui
A Rust rewrite of the terminal UI library I originally wrote in C for my school management project.
β οΈ This is my first-ever Rust project β οΈ
Feather-Tui is a simple terminal UI library designed to provide building blocks for text-based user interfaces. It started life as a small C library in my school management system project, aiming to offer an easy-to-use UI framework for terminal applications. Now, Iβm rewriting it in Rust to learn the language and (hopefully) improve both performance and maintainability.
π Progress
- π§ Feather-Tui is still under development.
- β Some parts are complete, while others are only partially done.
- β¨ These parts may get refined or improved in the future.
- π For now, theyβre good enough to work with.
π Changelog
- Fix
TextFlags::ALIGN_BOTTOMnot working.
π¦ Crates
https://crates.io/crates/feather-tui
π Usage
1οΈβ£ Render Your First Terminal UI
Let's render a simple UI in the terminal.
use feather_tui as tui;
let mut container = new
// 2. Add a header component with the title "Hello, World"
.with_header
// 3. Add text component with the following properties:
// - Content: "Simple UI"
// - Background: Magenta
// - Position: Bottom-aligned
.with_text;
// Rendering setup and display
// --------------------------
// 1. Create a renderer with dimensions 40x20 characters
let mut renderer = new;
// 2. Prepare terminal for TUI rendering
ready;
// 3. Clear the renderer's buffer before drawing new content
renderer.clear;
// 4. Render the container to the internal buffer (not yet visible)
renderer.render;
// 5. Draw the buffered content to the terminal (makes it visible)
renderer.draw;
// 6. Keep the UI visible for 5 seconds
sleep;
// 7. Restore terminal to original state
unready;
}
You can achieve the same result more concisely like this.
use feather_tui as tui;
2οΈβ£ Terminal UI With Selectable Options
This section will be imrpove later
Now let's crate a terminal UI with selectable options.
use feather_tui as tui;
// Define trigger functions for handling keyboard input
// This macro creates a function that checks if 'w' key was pressed (for moving up)
trg_new_trigger_func!;
// Create trigger function for moving down with 's' key
trg_new_trigger_func!;
// Create trigger function for selection with 'e' key
trg_new_trigger_func!;
// Create trigger function for quitting with 'q' key
trg_new_trigger_func!;
// Define callback function that executes when a menu option is selected
cbk_new_callback_func!;
// Helper function to read keyboard input
ποΈ Dependencies
bitflags crossterm