Skip to content

Commit

Permalink
move example in README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
tertsdiepraam committed Nov 7, 2023
1 parent a96ad3d commit 3faf4d6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
45 changes: 22 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,28 @@ uutils_term_grid = "0.3"

The Minimum Supported Rust Version is 1.70.

This library arranges textual data in a grid format suitable for fixed-width
fonts, using an algorithm to minimise the amount of space needed. For example:
## Creating a grid

To add data to a grid, first create a new [`Grid`] value with a list of strings
and a set of options.

There are three options that must be specified in the [`GridOptions`] value that
dictate how the grid is formatted:

- [`filling`][filling]: what to put in between two columns — either a number of
spaces, or a text string;
- [`direction`][direction]: specifies whether the cells should go along rows, or
columns:
- [`Direction::LeftToRight`][LeftToRight] starts them in the top left and
moves _rightwards_, going to the start of a new row after reaching the final
column;
- [`Direction::TopToBottom`][TopToBottom] starts them in the top left and
moves _downwards_, going to the top of a new column after reaching the final
row.
- [`width`][width]: the width to fill the grid into. Usually, this should be the
width of the terminal.

In practice, creating a grid can be done as follows:

```rust
use term_grid::{Grid, GridOptions, Direction, Filling};
Expand Down Expand Up @@ -69,27 +89,6 @@ five six seven eight
nine ten eleven twelve
```

## Creating a grid

To add data to a grid, first create a new [`Grid`] value with a list of strings
and a set of options.

There are three options that must be specified in the [`GridOptions`] value that
dictate how the grid is formatted:

- [`filling`][filling]: what to put in between two columns — either a number of
spaces, or a text string;
- [`direction`][direction]: specifies whether the cells should go along rows, or
columns:
- [`Direction::LeftToRight`][LeftToRight] starts them in the top left and
moves _rightwards_, going to the start of a new row after reaching the final
column;
- [`Direction::TopToBottom`][TopToBottom] starts them in the top left and
moves _downwards_, going to the top of a new column after reaching the final
row.
- [`width`][width]: the width to fill the grid into. Usually, this should be the
width of the terminal.

[filling]: struct.GridOptions.html#structfield.filling
[direction]: struct.GridOptions.html#structfield.direction
[width]: struct.GridOptions.html#structfield.width
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ pub struct Grid<T: AsRef<str>> {
dimensions: Dimensions,

Check warning on line 93 in src/lib.rs

View check run for this annotation

Codecov / codecov/patch

src/lib.rs#L93

Added line #L93 was not covered by tests
}

// Public methods
impl<T: AsRef<str>> Grid<T> {
/// Creates a new grid view with the given cells and options
pub fn new(cells: Vec<T>, options: GridOptions) -> Self {
Expand Down

0 comments on commit 3faf4d6

Please sign in to comment.