#user-input #console #input-output #utilities #color

console-utilities

A Rust crate for handling console input and output utilities

10 releases (2 stable)

1.0.1 Jun 6, 2024
0.1.7 Jun 6, 2024

#727 in Text processing

MIT license

8KB
118 lines

Console Utilities

crates.io crates.io docs.rs

A Rust crate for handling console input and output utilities.

Usage

[dependencies]
console-utilities = "1"

Once you have the dependency you can import it in your project:

use console_utilities::{
    input::{
        input,
        input_rgb
    },
    output::{
        print_rgb,
        print_gradient
    }
};

Examples

User Input

use console_utilities::{
    input::{
        input,
        input_rgb,
        input_gradient
    },
    color::RGB
};

// Prompt for user input
let user_input: String = input("Enter your name: ");

// Prompt for user input (colored)
let colored_user_input: String = input_rgb("Enter your age: ", RGB::new(255, 0, 255));

// Prompt for user input (gradient)
let gradient_user_input: String = input_gradient("Enter your favourite color: ", RGB::new(255, 255, 255) /* start color */, RGB::new(2, 2, 2) /* end color */);

println!("Name: {}\n Age: {}\n Favourite Color: {}", user_input, colored_user_input, gradient_user_input);

Console Output

use console_utilities::output::{print_rgb, print_gradient};
use console_utilities::color::RGB;

// Print text in a specific color
print_rgb("This is colored text!", RGB::new(0, 255, 0));

// Print text with a gradient
print_gradient("Gradient Text", RGB::new(255, 0, 0), RGB::new(0, 0, 255));

Color Utilities

use console_utilities::color::{RGB, set_text_color, reset_text_color};

// Define a custom RGB variable
let color_variable: RGB = RGB::new(255, 0, 255);

// Set text color
set_text_color(RGB::new(255, 0, 0));

println!("This text is red!");
println!("This text is still red!");

// Reset text color
reset_text_color();

Cursor Utilties

use console_utilities::cursor::{Visibility, Move};

// Show and hide cursor
Visibility::show_cursor();
Visibility::hide_cursor();

// Move cursor
Move::cursor_up(2);
Move::cursor_down(2);
Move::cursor_left(2);
Move::cursor_right(2);

Console Utilties

use console_utilities::console::{flush_console, clear_line, clear_lines};

// Flush the console
flush_console();

// Clear the current line
clear_line();

// Clear multiple lines
clear_lines(3);

No runtime deps