1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
use UnicodeSegmentation;
use crateFrame;
/// Currently, an action is either printing a string or moving to a location.
/// The first value is the x location, the second is the y location.
/**
A handler is a structure that can convert actions into an output on an output device.
This simple trait is rather self-explanatory.
# Example
``` rust
# use grid_ui::grid;
# use grid_ui::out;
# use grid_ui::trim::Ignore;
# fn main() -> Result<(), ()>{
let mut grid = grid::Frame::new(0, 0, 10, 4).next_frame();
let mut process = grid.into_process(grid::DividerStrategy::Halfway);
process.add_to_section("Some stuff".to_string(), &mut Ignore, grid::Alignment::Plus);
let mut some_handler = out::OutToString;
let mut output_device = String::new();
process.print(&mut some_handler, &mut output_device)?;
assert_eq!(output_device, " \n \nSome stuff\n \n".to_string());
# Ok(())
# }
```
*/
/**
A handler that is "safe", ie doesn't return an error. All safe handlers are also handlers - you can use them as such.
# Example
``` rust
# use grid_ui::grid;
# use grid_ui::out;
# use grid_ui::trim::Ignore;
# fn main() -> Result<(), ()>{
let mut grid = grid::Frame::new(0, 0, 10, 4).next_frame();
let mut process = grid.into_process(grid::DividerStrategy::Halfway);
process.add_to_section("Some stuff".to_string(), &mut Ignore, grid::Alignment::Plus);
let mut some_handler = out::OutToString;
let mut output_device = String::new();
process.print_safe(&mut some_handler, &mut output_device); // no need for the ? operator
assert_eq!(output_device, " \n \nSome stuff\n \n".to_string());
# Ok(())
# }
```
*/
/**
A handler that outputs the text to a string, as lines. It does not pay attention to the location used.
This means that it won't panic at all, and will generally accept whatever text is thrown at it.
This makes it useful for debug purposes.
However, it doesn't do any formatting, and doesn't change behavior based on locations - only where you call it matters.
# Example
``` rust
# use grid_ui::grid;
# use grid_ui::out;
# use grid_ui::trim::Ignore;
# fn main() -> Result<(), ()>{
let mut grid = grid::Frame::new(0, 0, 10, 3).next_frame();
let mut process = grid.into_process(grid::DividerStrategy::Beginning);
process.add_to_section_lines(vec!["Some stuff".to_string(), "More stuff".to_string()].into_iter(), &mut Ignore, grid::Alignment::Plus);
let mut output: String = String::new();
process.print(&mut out::OutToString, &mut output)?;
assert_eq!("Some stuff\nMore stuff\n \n".to_string(), output);
# Ok(())
# }
```
The limitations of this method
``` rust
# use grid_ui::grid;
# use grid_ui::out::*;
# use grid_ui::trim::Ignore;
# fn main() -> Result<(), ()>{
let frame = grid::Frame::new(0, 0, 10, 1);
let mut left = frame.next_frame();
let mut right = left.split(&grid::SplitStrategy::new().max_x(5, grid::Alignment::Plus)).ok_or(())?;
let mut left_process = left.into_process(grid::DividerStrategy::Beginning);
let mut right_process = right.into_process(grid::DividerStrategy::Beginning);
right_process.add_to_section("stuff".to_string(), &mut Ignore, grid::Alignment::Plus);
left_process.add_to_section("Some".to_string(), &mut Ignore, grid::Alignment::Plus);
let mut output: String = String::new();
right_process.print(&mut OutToString, &mut output)?;
left_process.print(&mut OutToString, &mut output)?;
assert_eq!("stuff\nSome\n".to_string(), output);
# Ok(())
# }
```
*/
;
/**
A more complicated version of the structure OutToString. This modifies a string buffer
instead of pushing any text directly to a string. This allows the structure to actually
process multiple grids in any order, at the expense of time cost.
# Panics
This structure will cause a panic if it tries to print text that cannot fit in the assigned buffer.
This will not happen unless you either (A) use a structure that doesn't force text to fit
the frame/grid such as trim::Ignore, or (B) construct this structure with starting or ending
points different from the frame it's used in.
# Examples
Basic usage
``` rust
# use grid_ui::grid;
# use grid_ui::out::*;
# use grid_ui::trim::Ignore;
# fn main() -> Result<(), ()>{
let frame = grid::Frame::new(0, 0, 10, 1);
let mut output: StringBuffer = StringBuffer::from_frame(&frame);
let mut left = frame.next_frame();
let mut right = left.split(&grid::SplitStrategy::new().max_x(5, grid::Alignment::Plus)).ok_or(())?;
let mut left_process = left.into_process(grid::DividerStrategy::Beginning);
let mut right_process = right.into_process(grid::DividerStrategy::Beginning);
left_process.add_to_section("Some".to_string(), &mut Ignore, grid::Alignment::Plus);
right_process.add_to_section("stuff".to_string(), &mut Ignore, grid::Alignment::Plus);
left_process.print(&mut output, &mut ())?;
right_process.print(&mut output, &mut ())?;
assert_eq!(vec!["Some stuff".to_string()], output.lines());
# Ok(())
# }
```
Panicking with ignore
``` should_panic
# use grid_ui::grid;
# use grid_ui::out::*;
# use grid_ui::trim::Ignore;
# fn main() -> Result<(), ()>{
let frame = grid::Frame::new(0, 0, 10, 1);
let mut output: StringBuffer = StringBuffer::from_frame(&frame);
let mut grid = frame.next_frame();
let mut process = grid.into_process(grid::DividerStrategy::Beginning);
process.add_to_section("This string is too long.".to_string(), &mut Ignore, grid::Alignment::Plus);
process.print(&mut output, &mut ())?; // panics
# Ok(())
# }
```
Panicking with a grid mismatch
``` should_panic
# use grid_ui::grid;
# use grid_ui::out::*;
# use grid_ui::trim::Truncate;
# fn main() -> Result<(), ()>{
let frame = grid::Frame::new(0, 0, 10, 1);
let mut small_output: StringBuffer = StringBuffer::new(5, 0, 10, 1);
let mut grid = frame.next_frame();
let mut process = grid.into_process(grid::DividerStrategy::Beginning);
process.add_to_section("This string is trimmed to fit here, but not on the string buffer.".to_string(), &mut Truncate, grid::Alignment::Plus);
process.print(&mut small_output, &mut ())?; // panics
# Ok(())
# }
```
*/