Screen Printer

Screen Printer is a Rust crate that will allow you to build and print arrays of data into a grid format.

The purpose of this crate is to make it easier to print rectangular blocks of text to the terminal. Including features like:

* If the grid changes in size or position it is reprinted in its entirety.

Examples

Using the dynamic print method to print a grid

The core part of this crate is the dynamic_print method for the Printer. This will take a rectangular grid of characters and print only the parts of the grid that have changed since the last print.

```rust,norun use screenprinter::printer::*;

const WIDTH: usize = 3; const HEIGHT: usize = 3;

fn main() { print!("\u{1b}[2J"); // Clear all text on the terminal // The default printing position is the bottom left of the terminal let mut printer = Printer::newwithprinting_position(PrintingPosition::default());

// Create the first grid to be printed. let grid1 = "abc\n123\nxyz".tostring(); // print the first grid. printer.dynamicprint(grid1).unwrap();

// Wait before printing the second grid. std::thread::sleep(std::time::Duration::from_millis(500));

// Create the second grid to be printed. let grid2 = "abc\n789\nxyz".tostring(); // Print the second grid. // This will only end up printing the difference between the two grids/ printer.dynamicprint(grid2).unwrap(); } ```

This will result in:

bash,no_run abc 123 xyz

Into

bash,no_run abc 789 < only line that was actually printed xyz

Printing Position

Another feature shown in the above example, the PrintingPosition.

This will print the grid in any of the 9 defined positions on the terminal. These are split by the X and Y axes:

What is a "rectangular grid"?

A grid is referring to a "grid" of characters, AKA a string with rows and columns. Each row of the "grid" would be sets of characters separated by newlines. Each column would be an individual character between the newlines.

A 3x2 "grid" would be something like: "xxx\nxxx" Each x on either side of the \n is like a column and the \n separates each row.

For a grid to "not be rectangular" would mean that a row has a differing amount of characters from every other, like so: "xx\nxxx"