You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To add data to a grid, first create a new `Grid` value, and then add cells to them with the `add` method.
62
-
63
-
There are two options that must be specified in the `GridOptions` value that dictate how the grid is formatted:
64
-
65
-
-`filling`: what to put in between two columns - either a number of spaces, or a text string;
66
-
-`direction`, which specifies whether the cells should go along rows, or columns:
67
-
-`Direction::LeftToRight` starts them in the top left and moves *rightwards*, going to the start of a new row after reaching the final column;
68
-
-`Direction::TopToBottom` starts them in the top left and moves *downwards*, going to the top of a new column after reaching the final row.
69
-
70
-
71
-
## Displaying a grid
72
-
73
-
When display a grid, you can either specify the number of columns in advance, or try to find the maximum number of columns that can fit in an area of a given width.
74
-
75
-
Splitting a series of cells into columns - or, in other words, starting a new row every *n* cells - is achieved with the `fit_into_columns` method on a `Grid` value.
76
-
It takes as its argument the number of columns.
77
-
78
-
Trying to fit as much data onto one screen as possible is the main use case for specifying a maximum width instead.
79
-
This is achieved with the `fit_into_width` method.
80
-
It takes the maximum allowed width, including separators, as its argument.
81
-
However, it returns an *optional*`Display` value, depending on whether any of the cells actually had a width greater than the maximum width!
82
-
If this is the case, your best bet is to just output the cells with one per line.
83
-
84
-
85
-
## Cells and data
98
+
## Width of grid cells
86
99
87
-
Grids do not take `String`s or `&str`s - they take `Cells`.
100
+
This library calculates the width of strings as displayed in the terminal using
101
+
the [`textwrap`][textwrap] library (with the [`display_width`][display_width] function).
102
+
This takes into account the width of characters and ignores ANSI codes.
88
103
89
-
A **Cell**is a struct containing an individual cell’s contents, as a string, and its pre-computed length, which gets used when calculating a grid’s final dimensions.
90
-
Usually, you want the *Unicode width* of the string to be used for this, so you can turn a `String` into a `Cell` with the `.into()` method.
104
+
The width calculation is currently not configurable. If you have a use-case for
105
+
which this calculation is wrong, please open an issue.
91
106
92
-
However, you may also want to supply your own width: when you already know the width in advance, or when you want to change the measurement, such as skipping over terminal control characters.
93
-
For cases like these, the fields on the `Cell` values are public, meaning you can construct your own instances as necessary.
0 commit comments