85 releases
0.5.42 | Nov 11, 2024 |
---|---|
0.5.33 | Oct 13, 2024 |
0.4.6 | Jul 25, 2024 |
0.3.31 | Mar 30, 2024 |
#175 in Text processing
1,237 downloads per month
Used in 6 crates
210KB
5.5K
SLoC
Minimo
Description
Minimo is a minimalistic terminal printing library for Rust, designed to simplify the task of creating colorful and formatted terminal output. It offers a range of features including colorized text output, styled text (bold, italic, underline), and utility functions for enhanced terminal interactions.
Features
- Colorized text output with simple macros.
- Text styling (bold, italic, underline).
- Utility functions for terminal UI elements like dividers and positioned text.
- Vibrant text with random colorization for characters.
- Support for terminal header creation with customizable styles.
Installation
Add minimo
to your Rust project's Cargo.toml
file:
[dependencies]
minimo = "0.1.0"
Usage
Here's a quick example to get you started with minimo
:
use minimo::{gray, header, in_bold, in_cyan, in_gray, in_italic, in_magenta, in_underline, in_yellow, show, showln, success, vibrant, yellow, Printable};
fn main() {
// Displaying a header
header!(success, "Minimo", "VERSION 0.1.0", "A minimalistic terminal printing library for Rust");
// Using showln! macro for colorful text segments
showln!(gray, "You can use ", magenta, "show!", gray, " or ", yellow, "showln!", gray, " macros");
showln!(gray, "to print text segments in different colors.\n (Make sure each segment starts with a color)");
// Using show! and showln! macros with Printable trait
"You can also use ".show();
"show! ".print(in_magenta);
"and ".print(in_gray);
"showln! ".println(in_cyan);
"macros to print random text segments with formatting.".showln();
// Additional demonstrations
"This is a line in gray.".println(in_gray);
"This line is in yellow.".println(in_yellow);
// Demonstrating text styling
"Bold and colorful text: ".show();
"Bold".print(in_bold);
", ".show();
"Italic".print(in_italic);
", and ".show();
"Underlined".println(in_underline);
// Showing usage of vibrant function for colorful characters
"Vibrant text example: ".print(vibrant);
"Colorful characters!".println(minimo::vibrant);
// Showing divider and reset line
minimo::divider();
"Divider above".showln();
minimo::reset_line();
"Reset line used".showln();
}
Additional Examples
use std::sync::Arc;
use minimo::*;
use minimo::ask::*;
use minimo::{gray, magenta, yellow, cyan, purple, red, purple_bold, white_dim, pink, white};
fn main() {
println!("{}", "This is a test".style(cyan));
// Using showln! macro for colorful text segments
showln!(
gray,
"You can use ",
magenta,
"show!",
gray,
" or ",
yellow,
"showln!",
gray,
" macros"
);
showln!(gray, "to print text segments in different colors.\n (Make sure each segment starts with a color)");
// Using show! and showln! macros with Printable trait
"You can also use ".show(white_dim);
"show! ".show(pink);
"and ".show(purple_bold);
"showln! ".show(cyan);
"macros to print random text segments with formatting.".showln(white_dim);
divider();
// Additional demonstrations
let s = (purple +"we can " + red + "mix " + yellow+ "colors " + yellow + "like " + "this") ;
s.showln();
(red + "or " + yellow + "like " + "this" + purple_bold).showln();
("or even " + cyan + "like this").showln();
( "or even " + red + "like this"+ cyan).showln();
// Showing divider and reset line
minimo::divider();
"Divider above".style(red).showln();
minimo::reset_line();
"Reset line used".show(red);
let s = StyledText::new("This is a styled text", red);
s.showln();
"This is also a styled text".style(red).showln();
divider();
divider!();
divider!("hello");
divider!("-", "hello");
divider!("-", "hello", "-");
divider!("hello", "-");
divider!("-", "hello", "-", "world");
let c = "This is a styled text".style(red);
c.showln();
paragraph!(purple_bold, "title", white,"This is a paragraph with a title and long text to see if the content will automatically be wrapped and displayed accordingly");
// Ask for input
let name = text("What is your name?").unwrap();
// Create a list of choices
let choices = vec![
choice!("First choice", "This is the first choice", || println!("First choice selected")),
choice!("Second choice", "This is the second choice", || println!("Second choice selected")),
choice!("Third choice", "This is the third choice", || println!("Third choice selected")),
];
// Ask for selection
let selected = selection!("Select an option", &choices);
showln!(gray, "You selected: ", yellow, selected.get_title());
selected.run();
}
Detailed API Documentation
Functions
print_positioned
Prints the provided text at the specified position.
pub fn print_positioned(x: i16, y: i16, text: impl Into<String>)
reset_line
Resets the cursor to the beginning of the current line.
pub fn reset_line()
move_up
Moves the cursor up by n
lines.
pub fn move_up(n: i16)
move_down
Moves the cursor down by n
lines.
pub fn move_down(n: i16)
move_right
Moves the cursor right by n
columns.
pub fn move_right(n: i16)
move_left
Moves the cursor left by n
columns.
pub fn move_left(n: i16)
clear_line
Clears the current line.
pub fn clear_line()
clear_screen
Clears the entire screen.
pub fn clear_screen()
enable_raw_mode
Enables raw mode for custom input handling.
pub fn enable_raw_mode() -> std::io::Result<()>
disable_raw_mode
Disables raw mode.
pub fn disable_raw_mode() -> std::io::Result<()>
Macros
divider!
Prints a divider with optional text alignment and styles.
#[macro_export]
macro_rules! divider {
() => { /* implementation */ };
($($arg:tt)*) => { /* implementation */ };
}
paragraph!
Prints a paragraph with a title and text, automatically wrapping the text to fit the width.
#[macro_export]
macro_rules! paragraph {
($title_style:ident, $title:expr, $text_style:ident, $text:expr) => { /* implementation */ };
}
tree!
Prints a tree representation of a JSON object.
#[macro_export]
macro_rules! tree {
($val:expr) => { /* implementation */ };
}
async_choice!
Creates an asynchronous choice for a menu.
#[macro_export]
macro_rules! async_choice {
($name:expr, $description:expr, $action:expr, $matches_if:expr) => { /* implementation */ };
($name:expr, $description:expr, $action:expr) => { /* implementation */ };
($name:expr, $action:expr) => { /* implementation */ };
}
selection!
Displays a menu and returns the selected choice.
#[macro_export]
macro_rules! selection {
($message:expr, $choices:expr) => { /* implementation */ };
($choices:expr) => { /* implementation */ };
}
Traits
Printable
A trait that supports calling print
, write
, render
, and style
on any type.
pub trait Printable {
fn print<F>(&self, func: F) where F: Fn(&str) -> String;
fn println<F>(&self, func: F) where F: Fn(&str) -> String;
fn print_positioned<F>(&self, x: i32, y: i32, func: F) where F: Fn(&str) -> String;
}
Renderable
A trait for rendering styled text.
pub trait Renderable<'a> {
fn render<'b>(&'b self, style: &'a CStyle<'a>) -> StyledText<'b> where 'a: 'b;
fn style<'b>(&'b self, style: &'a CStyle<'a>) -> StyledText<'b> where 'a: 'b;
fn show<'b>(&'b self, style: &'a CStyle<'
a>) where 'a: 'b;
fn showln<'b>(&'b self, style: &'a CStyle<'a>) where 'a: 'b;
fn write<'b>(&'b self, style: &'a CStyle<'a>, writer: &mut dyn Write) -> std::io::Result<()>
where 'a: 'b;
fn write_line<'b>(&'b self, style: &'a CStyle<'a>, writer: &mut dyn Write) -> std::io::Result<()>
where 'a: 'b;
}
Pickable
A trait for items that can be picked from a list.
pub trait Pickable {
fn get_title(&self) -> String;
fn get_description(&self) -> String;
}
Minimo provides a comprehensive set of tools for creating rich, interactive command-line interfaces in Rust. Whether you need simple text styling or complex interactive menus, Minimo has you covered.
Dependencies
~2–13MB
~171K SLoC