termint/
lib.rs

1//! # termint
2//!
3//! [![Crates.io Version](https://img.shields.io/crates/v/termint?logo=rust)](https://crates.io/crates/termint)
4//! [![docs.rs](https://img.shields.io/docsrs/termint?logo=rust)](https://docs.rs/termint/latest/termint/)
5//! [![Crates.io Total Downloads](https://img.shields.io/crates/d/termint)](https://crates.io/crates/termint)
6//!
7//! Rust library for colored printing and Terminal User Interfaces
8//!
9//! ## Table of Contents
10//! - [How to get it](#how-to-get-it)
11//!     - [With cargo](#with-cargo)
12//!     - [In Cargo.toml](#in-cargotoml)
13//!     - [Features](#features)
14//! - [Examples](#examples)
15//!     - [Printing colored text](#printing-colored-text)
16//!     - [Terminal User Interface (TUI)](#terminal-user-interface-tui)
17//! - [Usage](#usage)
18//! - [Links](#links)
19//!
20//! ## How to get it
21//!
22//! This crate is available on [crates.io](https://crates.io/crates/termint).
23//!
24//! ### With cargo
25//! ```terminal
26//! cargo add termint
27//! ```
28//!
29//! ### In Cargo.toml
30//! ```toml
31//! [dependencies]
32//! termint = "0.6.0"
33//! ```
34//!
35//! ### Features
36//!
37//! - `serde`: Enables serialization and deserialization of some structs.
38//! - `all`: Enables all features.
39//!
40//! ## Examples
41//!
42//! ### Printing colored text
43//!
44//! Printing colored text is really easy, you can do it by using any `Text`
45//! widget. Here is an example of using `Span` widget:
46//!
47//! ```rust
48//! # use termint::{
49//! #     enums::{Modifier, Color},
50//! #     widgets::ToSpan
51//! # };
52//! println!("{}", "Cyan text".fg(Color::Cyan));
53//! println!("{}", "Cyan text on white".fg(Color::Cyan).bg(Color::White));
54//! println!("{}", "Bold red text".fg(Color::Red).modifier(Modifier::BOLD));
55//! println!("{}", "Text with RGB value".fg(Color::Rgb(0, 249, 210)));
56//! ```
57//! ![image](https://github.com/Martan03/termint/assets/46300167/c906a565-69b5-4664-9db0-ad89ff457cbb)
58//!
59//! You can also use re-exported `termal` crate to print colored text:
60//! ```rust
61//! # use termint::termal::printcln;
62//! printcln!("{'yellow italic}Yellow Italic text{'reset}");
63//! printcln!("{'y i}{}{'_}", "Yellow Italic text");
64//! printcln!("{'#dd0 i}{}{'_}", "Custom Yellow Italic text");
65//! ```
66//!
67//! ### Terminal User Interface (TUI)
68//!
69//! The main purpose of this crate is to create Terminal User Interfaces (TUIs).
70//! Example below shows minimal example of creating a TUI using `Block` widget
71//! and rendering it using `Term`. You can find more examples in the `examples`
72//! directory of this repository.
73//!
74//! ```rust
75//! # use termint::{
76//! #     term::Term,
77//! #     enums::{Color, Border, BorderType},
78//! #     geometry::{Constraint, Rect},
79//! #     widgets::{Block, ToSpan, Widget}
80//! # };
81//! # fn example() -> Result<(), &'static str> {
82//! // Creates main block and sets its properties
83//! let mut main = Block::horizontal()
84//!     .title("Termint")
85//!     .border_type(BorderType::Double);
86//!
87//! // Creates block1 and adds span as its child
88//! let mut block1 = Block::vertical().title("Sub block");
89//! let span1 = "I like it!".fg(Color::Green).bg(Color::Yellow);
90//! block1.push(span1, Constraint::Percent(100));
91//! // Adds block1 as child of main block
92//! main.push(block1, Constraint::Min(0));
93//!
94//! // Creates block2 and adds span as its child
95//! let mut block2 = Block::vertical().title("Another");
96//! let span2 = "This is really cool, right?".fg(Color::Blue);
97//! block2.push(span2, Constraint::Percent(100));
98//! // Adds block2 as child of main block
99//! main.push(block2, Constraint::Fill(1));
100//!
101//! // Renders the main block which renders all the children using Buffer
102//! let mut term = Term::new();
103//! term.render(main)?;
104//! # Ok(())
105//! # }
106//! ```
107//! ![image](https://github.com/Martan03/termint/assets/46300167/cdd0850b-1952-4c4b-8dec-b49c30d59f6d)
108//!
109//! ### TUI examples
110//!
111//! ![image](https://github.com/user-attachments/assets/1e81fad9-dc56-4715-b49b-fbe9153f1b42)
112//!
113//! ![image](https://github.com/user-attachments/assets/660a3794-723a-494f-b28b-83377d5ebe49)
114//!
115//! ![image](https://github.com/user-attachments/assets/5c239669-1182-4962-8449-b76107fd574f)
116//!
117//! ## Usage
118//!
119//! Code blocks above are just examples of the usage. To see more about functions,
120//! Widgets and more, please visit the
121//! [documentation](https://docs.rs/termint/latest/termint/).
122//!
123//! You can also check the `examples` directory of this repository for more
124//! examples of how to use this crate for creating TUIs.
125//!
126//! ## Projects
127//!
128//! Here is a list of some projects using termint:
129//!
130//! - [2048](https://github.com/Martan03/2048)
131//! - [futoshiki](https://github.com/Martan03/futoshiki)
132//! - [loopover](https://github.com/Martan03/loopover)
133//! - [minesweeper](https://github.com/Martan03/minesweeper)
134//! - [rsTimer](https://github.com/Martan03/rsTimer)
135//! - [tictactoe](https://github.com/Martan03/tictactoe)
136//!
137//! ## Links
138//!
139//! - **Author:** [Martan03](https://github.com/Martan03)
140//! - **GitHub repository:** [termint](https://github.com/Martan03/termint)
141//! - **Package**: [crates.io](https://crates.io/crates/termint)
142//! - **Documentation**: [docs.rs](https://docs.rs/termint/latest/termint/)
143//! - **Author website:** [martan03.github.io](https://martan03.github.io)
144
145pub mod buffer;
146/// Contains enums for foreground, background and more
147pub mod enums;
148/// Contains structs for geometry, such as Coords
149pub mod geometry;
150/// Contains useful macros
151pub mod macros;
152pub mod style;
153/// Contains Term struct
154pub mod term;
155pub mod text;
156/// Contains widgets (Layout, Block, Span)
157pub mod widgets;
158
159pub use termal;