Crate quick_io

Source
Expand description

A simple crate to facilitate input and output within programs, with a set of macros. Example:

use quick_io::*;

clear!();
addstr!("Input something: ");

println!("You typed: {}.", getstr!());

getstr!();

down!(10);
right!(20);
addstr!("Went down 10 characters and right 20 characters");

getstr!();

addstr!(0, 10, "Moved to 0, 10 within addstr!");

getstr!();

mv!(0, 20);
addstr!("Moved to 0, 20 with mv!");

getstr!();

down!(20);
addln!("Press enter to clear this line.");

getstr!();

line_up!(2);
clear_line!();
line_down!(2);

println!("Press enter to clear the entire screen.");

getstr!();

clear!();

Copypaste this into a main.rs for a demonstration of the crate (rust playground doesn’t support input for some reason?) Note: Since this uses ANSI escape codes for clear!(), mv!(), etc. it may not work on some terminals/systems.

Macros§

addstr
Adds a string at the cursor location, or at a specified location. Flushes buffer as well (normally stdout is only flushed on newlines.)
clear
Clears the entire screen.
clear_line
Clears the line the cursor is on. Does not move it to the beginning of the line.
down
Moves the cusor down the specified amount of characters. If no arguments are given, defaults to 1.
getstr
Gets a string from stdin. Output trimmed.
left
Moves the cusor left the specified amount of characters. If no arguments are given, defaults to 1.
line_down
Moves the cursor down a specified amount of lines, and positions it at the start of that line. If no arguments are given, defaults to 1.
line_up
Moves the cursor up a specified amount of lines, and positions it at the start of that line. If no arguments are given, defaults to 1.
mv
Moves the cursor to the specified location. Moves to top left corner (0, 0) if no arguments are provided. If argument specified is out of bounds, it clamps it to be in bounds. I have no idea what happens if you provide a number outside of the u16 limits.
right
Moves the cusor right the specified amount of characters. If no arguments are given, defaults to 1.
up
Moves the cusor up the specified amount of characters. If no arguments are given, defaults to 1.