altui-core 0.2.0

A library to build rich terminal user interfaces or dashboards
Documentation
//! [altui-cure](https://altlinux.space/writers/altui/src/branch/devel/altui-core) is a library used to build rich
//! terminal users interfaces and dashboards.
//!
//! ![](https://raw.githubusercontent.com/fdehau/tui-rs/master/assets/demo.gif)
//!
//! # Get started
//!
//! ## Adding `altui-core` as a dependency
//!
//! Add `altui-core` to your `Cargo.toml`:
//!
//! ```toml
//! [dependencies]
//! altui_core = "0.1"
//! crossterm = "0.29"
//! ```
//!
//! By default, `altui-core` uses the **Crossterm backend**, which works on most
//! platforms (Linux, macOS, Windows) and requires no additional configuration.
//!
//! ### Using a different backend
//!
//! If you want to use another backend (for example, `termion`), disable default
//! features and enable the corresponding backend feature:
//!
//! ```toml
//! [dependencies]
//! termion = "4"
//! altui_core = { version = "0.1", default-features = false, features = ["termion"] }
//! ```
//!
//! The same approach applies to all other available backends.
//!
//! ---
//!
//! ## Creating a terminal (recommended way)
//!
//! The easiest and safest way to initialize a terminal is via [`AltuiInit`].
//! It takes care of:
//!
//! - enabling raw mode
//! - entering the alternate screen
//! - optional mouse support
//! - restoring the terminal on panic
//!
//! ```rust,ignore
//! use std::io;
//! use altui_core::AltuiInit;
//!
//! fn main() -> io::Result<()> {
//!     let mut ui = AltuiInit::new(true)?   // enable mouse support
//!         .set_panic_hook();               // restore terminal on panic
//!
//!     ui.run(|terminal| {
//!         terminal.draw(|f| {
//!             let size = f.size();
//!             // draw UI here
//!         }).expect("Fail to draw to the terminal");
//!         Ok(())
//!     })
//! }
//! ```
//!
//! ### Mouse support
//!
//! Mouse input is optional and can be disabled:
//!
//! ```rust,no-run
//! use altui_core::AltuiInit;
//!
//! let mut ui = AltuiInit::new(false);
//! ```
//!
//! ---
//!
//! ## Manual terminal initialization (advanced)
//!
//! If you need full control over terminal initialization, you may construct
//! a [`Terminal`] and backend manually.
//!
//! ```rust
//! use std::io;
//! use altui_core::{backend::CrosstermBackend, Terminal};
//!
//! fn main() -> io::Result<()> {
//!     let stdout = io::stdout();
//!     let backend = CrosstermBackend::new(stdout);
//!     let mut terminal = Terminal::new(backend)?;
//!     Ok(())
//! }
//! ```
//!
//! ⚠️ When using this approach, you are responsible for:
//!
//! - enabling and disabling raw mode
//! - entering and leaving the alternate screen
//! - restoring cursor visibility on exit or panic
//!
//! ### See also
//!
//! - [`AltuiInit`]
//! - [`Terminal`]
//! - [`backend::Backend`]
//!
//! ---
//!
//! ## Building a User Interface (UI)
//!
//! User interfaces in `altui-core` are composed of widgets implementing the
//! [`Widget`] trait.
//!
//! Widgets use a builder-style API and are rendered via
//! [`Frame::render_widget`].
//!
//! ```rust,ignore
//! use altui_core::{
//!     widgets::{Block, Borders},
//! };
//!
//! terminal.draw(|f| {
//!     let size = f.size();
//!     let mut block = Block::default()
//!         .title("Block")
//!         .borders(Borders::ALL);
//!     f.render_widget(&mut block, size);
//! })?;
//! ```
//!
//! ---
//!
//! ## Layout
//!
//! Layout management is handled by [`Layout`], which allows building responsive
//! terminal UIs by splitting available space into regions.
//!
//! The example below creates a **centered block** that occupies **80% of the
//! terminal width and 80% of the terminal height**. The remaining space is
//! evenly distributed around the block, keeping it centered both vertically
//! and horizontally.
//!
//! This pattern is useful for dialogs, popups, and other UI elements that should
//! stay visually centered regardless of terminal size.
//!
//! ```rust
//! use altui_core::{
//!     layout::{Constraint, Layout, Flex},
//!     widgets::{Block, Borders},
//! };
//!
//! fn ui<B: altui_core::backend::Backend>(f: &mut altui_core::Frame<B>) {
//!     let chunks = Layout::vertical([Constraint::Percentage(80)])
//!     .flex(Flex::Center)
//!     .cross_size(Constraint::Percentage(80))
//!     .cross_flex(Flex::Center)
//!     .margin(1)
//!     .split(f.size());
//!
//!     let mut block = Block::default()
//!         .title("Header")
//!         .borders(Borders::ALL);
//!     f.render_widget(&mut block, chunks[0]);
//! }
//! ```
//!
//! Layouts can be nested to create complex, adaptive terminal interfaces.
//! Unused layout regions may be left empty to create spacing.

pub mod backend;
pub mod buffer;
#[cfg(feature = "crossterm")]
mod init;
pub mod layout;
pub mod style;
pub mod symbols;
pub mod terminal;
pub mod text;
pub mod widgets;

#[cfg(feature = "crossterm")]
pub use self::init::AltuiInit;
pub use self::terminal::{Frame, Terminal, TerminalOptions, Viewport};