| Crates.io | minimo |
| lib.rs | minimo |
| version | 0.5.42 |
| created_at | 2024-01-19 16:02:02.089214+00 |
| updated_at | 2024-11-11 14:38:15.66528+00 |
| description | terminal ui library combining alot of things from here and there and making it slightly easier to play with |
| homepage | |
| repository | https://github.com/incredimo/minimo |
| max_upload_size | |
| id | 1105464 |
| size | 233,221 |
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.
Add minimo to your Rust project's Cargo.toml file:
[dependencies]
minimo = "0.1.0"
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();
}
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();
}
print_positionedPrints the provided text at the specified position.
pub fn print_positioned(x: i16, y: i16, text: impl Into<String>)
reset_lineResets the cursor to the beginning of the current line.
pub fn reset_line()
move_upMoves the cursor up by n lines.
pub fn move_up(n: i16)
move_downMoves the cursor down by n lines.
pub fn move_down(n: i16)
move_rightMoves the cursor right by n columns.
pub fn move_right(n: i16)
move_leftMoves the cursor left by n columns.
pub fn move_left(n: i16)
clear_lineClears the current line.
pub fn clear_line()
clear_screenClears the entire screen.
pub fn clear_screen()
enable_raw_modeEnables raw mode for custom input handling.
pub fn enable_raw_mode() -> std::io::Result<()>
disable_raw_modeDisables raw mode.
pub fn disable_raw_mode() -> std::io::Result<()>
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 */ };
}
PrintableA 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;
}
RenderableA 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;
}
PickableA 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.