/rust/registry/src/index.crates.io-1949cf8c6b5b557f/papergrid-0.17.0/src/grid/peekable.rs
Line | Count | Source |
1 | | //! The module contains a [`PeekableGrid`] structure. |
2 | | |
3 | | use core::borrow::Borrow; |
4 | | use std::{ |
5 | | borrow::Cow, |
6 | | cmp, |
7 | | fmt::{self, Write}, |
8 | | }; |
9 | | |
10 | | use crate::{ |
11 | | ansi::{ANSIBuf, ANSIFmt}, |
12 | | colors::Colors, |
13 | | config::{ |
14 | | spanned::SpannedConfig, AlignmentHorizontal, AlignmentVertical, Formatting, Indent, Offset, |
15 | | Position, Sides, |
16 | | }, |
17 | | dimension::Dimension, |
18 | | records::{ExactRecords, PeekableRecords, Records}, |
19 | | util::string::get_line_width, |
20 | | }; |
21 | | |
22 | | // TODO: Do we actually need PeekableRecords? |
23 | | // Maybe Cloned iterator will be faster? |
24 | | // Even better &referenced Records |
25 | | |
26 | | /// Grid provides a set of methods for building a text-based table. |
27 | | #[derive(Debug, Clone)] |
28 | | pub struct PeekableGrid<R, G, D, C> { |
29 | | records: R, |
30 | | config: G, |
31 | | dimension: D, |
32 | | colors: C, |
33 | | } |
34 | | |
35 | | impl<R, G, D, C> PeekableGrid<R, G, D, C> { |
36 | | /// The new method creates a grid instance with default styles. |
37 | 0 | pub fn new(records: R, config: G, dimension: D, colors: C) -> Self { |
38 | 0 | PeekableGrid { |
39 | 0 | records, |
40 | 0 | config, |
41 | 0 | dimension, |
42 | 0 | colors, |
43 | 0 | } |
44 | 0 | } Unexecuted instantiation: <papergrid::grid::peekable::PeekableGrid<&papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &papergrid::config::spanned::SpannedConfig, &&papergrid::dimension::peekable::PeekableGridDimension, papergrid::colors::nocolors::NoColors>>::new Unexecuted instantiation: <papergrid::grid::peekable::PeekableGrid<&papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &papergrid::config::spanned::SpannedConfig, &&papergrid::dimension::peekable::PeekableGridDimension, &tabled::grid::config::colored_config::ColorMap>>::new Unexecuted instantiation: <papergrid::grid::peekable::PeekableGrid<&papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &papergrid::config::spanned::SpannedConfig, &&tabled::grid::dimension::complete_dimension::CompleteDimension, papergrid::colors::nocolors::NoColors>>::new Unexecuted instantiation: <papergrid::grid::peekable::PeekableGrid<&papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &papergrid::config::spanned::SpannedConfig, &&tabled::grid::dimension::complete_dimension::CompleteDimension, &tabled::grid::config::colored_config::ColorMap>>::new Unexecuted instantiation: <papergrid::grid::peekable::PeekableGrid<_, _, _, _>>::new |
45 | | } |
46 | | |
47 | | impl<R, G, D, C> PeekableGrid<R, G, D, C> { |
48 | | /// Builds a table. |
49 | 0 | pub fn build<F>(&self, mut f: F) -> fmt::Result |
50 | 0 | where |
51 | 0 | R: Records + PeekableRecords + ExactRecords, |
52 | 0 | D: Dimension, |
53 | 0 | C: Colors, |
54 | 0 | G: Borrow<SpannedConfig>, |
55 | 0 | F: Write, |
56 | | { |
57 | 0 | if self.records.count_columns() == 0 || self.records.hint_count_rows() == Some(0) { |
58 | 0 | return Ok(()); |
59 | 0 | } |
60 | | |
61 | 0 | let ctx = PrintCtx { |
62 | 0 | cfg: self.config.borrow(), |
63 | 0 | colors: &self.colors, |
64 | 0 | dims: &self.dimension, |
65 | 0 | records: &self.records, |
66 | 0 | }; |
67 | | |
68 | 0 | print_grid(&mut f, ctx) |
69 | 0 | } Unexecuted instantiation: <papergrid::grid::peekable::PeekableGrid<&papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &papergrid::config::spanned::SpannedConfig, &&papergrid::dimension::peekable::PeekableGridDimension, papergrid::colors::nocolors::NoColors>>::build::<&mut core::fmt::Formatter> Unexecuted instantiation: <papergrid::grid::peekable::PeekableGrid<&papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &papergrid::config::spanned::SpannedConfig, &&papergrid::dimension::peekable::PeekableGridDimension, &tabled::grid::config::colored_config::ColorMap>>::build::<&mut core::fmt::Formatter> Unexecuted instantiation: <papergrid::grid::peekable::PeekableGrid<&papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &papergrid::config::spanned::SpannedConfig, &&tabled::grid::dimension::complete_dimension::CompleteDimension, papergrid::colors::nocolors::NoColors>>::build::<&mut core::fmt::Formatter> Unexecuted instantiation: <papergrid::grid::peekable::PeekableGrid<&papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &papergrid::config::spanned::SpannedConfig, &&tabled::grid::dimension::complete_dimension::CompleteDimension, &tabled::grid::config::colored_config::ColorMap>>::build::<&mut core::fmt::Formatter> Unexecuted instantiation: <papergrid::grid::peekable::PeekableGrid<_, _, _, _>>::build::<_> |
70 | | } |
71 | | |
72 | | impl<R, G, D, C> fmt::Display for PeekableGrid<R, G, D, C> |
73 | | where |
74 | | R: Records + PeekableRecords + ExactRecords, |
75 | | D: Dimension, |
76 | | C: Colors, |
77 | | G: Borrow<SpannedConfig>, |
78 | | { |
79 | 0 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
80 | 0 | self.build(f) |
81 | 0 | } |
82 | | } |
83 | | |
84 | | #[derive(Debug, Copy, Clone)] |
85 | | struct PrintCtx<'a, R, D, C> { |
86 | | records: &'a R, |
87 | | cfg: &'a SpannedConfig, |
88 | | dims: &'a D, |
89 | | colors: &'a C, |
90 | | } |
91 | | |
92 | 0 | fn print_grid<F, R, D, C>(f: &mut F, ctx: PrintCtx<'_, R, D, C>) -> fmt::Result |
93 | 0 | where |
94 | 0 | F: Write, |
95 | 0 | R: Records + PeekableRecords + ExactRecords, |
96 | 0 | D: Dimension, |
97 | 0 | C: Colors, |
98 | | { |
99 | 0 | let has_spans = ctx.cfg.has_column_spans() || ctx.cfg.has_row_spans(); |
100 | 0 | if has_spans { |
101 | 0 | return grid_spanned::build_grid(f, ctx); |
102 | 0 | } |
103 | | |
104 | 0 | let is_basic = !ctx.cfg.has_border_colors() |
105 | 0 | && !ctx.cfg.has_padding_color() |
106 | 0 | && !ctx.cfg.has_justification() |
107 | 0 | && !ctx.cfg.has_offset_chars() |
108 | 0 | && !has_margin(ctx.cfg) |
109 | 0 | && ctx.colors.is_empty(); |
110 | | |
111 | 0 | if is_basic { |
112 | 0 | grid_basic::build_grid(f, ctx) |
113 | | } else { |
114 | 0 | grid_not_spanned::build_grid(f, ctx) |
115 | | } |
116 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::print_grid::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&papergrid::dimension::peekable::PeekableGridDimension, papergrid::colors::nocolors::NoColors> Unexecuted instantiation: papergrid::grid::peekable::print_grid::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&papergrid::dimension::peekable::PeekableGridDimension, &tabled::grid::config::colored_config::ColorMap> Unexecuted instantiation: papergrid::grid::peekable::print_grid::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&tabled::grid::dimension::complete_dimension::CompleteDimension, papergrid::colors::nocolors::NoColors> Unexecuted instantiation: papergrid::grid::peekable::print_grid::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&tabled::grid::dimension::complete_dimension::CompleteDimension, &tabled::grid::config::colored_config::ColorMap> Unexecuted instantiation: papergrid::grid::peekable::print_grid::<_, _, _, _> |
117 | | |
118 | 0 | fn has_margin(cfg: &SpannedConfig) -> bool { |
119 | 0 | let margin = cfg.get_margin(); |
120 | 0 | margin.left.size > 0 || margin.right.size > 0 || margin.top.size > 0 || margin.bottom.size > 0 |
121 | 0 | } |
122 | | |
123 | | mod grid_basic { |
124 | | use super::*; |
125 | | |
126 | | struct TextCfg { |
127 | | alignment: AlignmentHorizontal, |
128 | | formatting: Formatting, |
129 | | justification: char, |
130 | | } |
131 | | |
132 | | #[derive(Debug, Clone, Copy)] |
133 | | struct Shape { |
134 | | count_rows: usize, |
135 | | count_columns: usize, |
136 | | } |
137 | | |
138 | | struct HIndent { |
139 | | left: usize, |
140 | | right: usize, |
141 | | } |
142 | | |
143 | 0 | pub(super) fn build_grid<F, R, D, C>(f: &mut F, ctx: PrintCtx<'_, R, D, C>) -> fmt::Result |
144 | 0 | where |
145 | 0 | F: Write, |
146 | 0 | R: Records + PeekableRecords + ExactRecords, |
147 | 0 | D: Dimension, |
148 | | { |
149 | 0 | let shape = Shape { |
150 | 0 | count_rows: ctx.records.count_rows(), |
151 | 0 | count_columns: ctx.records.count_columns(), |
152 | 0 | }; |
153 | | |
154 | 0 | let mut new_line = false; |
155 | | |
156 | 0 | for row in 0..shape.count_rows { |
157 | 0 | let height = ctx.dims.get_height(row); |
158 | | |
159 | 0 | let has_horizontal = ctx.cfg.has_horizontal(row, shape.count_rows); |
160 | | |
161 | 0 | if new_line && (has_horizontal || height > 0) { |
162 | 0 | f.write_char('\n')?; |
163 | 0 | new_line = false; |
164 | 0 | } |
165 | | |
166 | 0 | if has_horizontal { |
167 | 0 | print_split_line(f, ctx.cfg, ctx.dims, row, shape)?; |
168 | | |
169 | 0 | if height > 0 { |
170 | 0 | f.write_char('\n')?; |
171 | 0 | } else { |
172 | 0 | new_line = true; |
173 | 0 | } |
174 | 0 | } |
175 | | |
176 | 0 | if height > 0 { |
177 | 0 | print_grid_line(f, &ctx, shape, height, row, 0)?; |
178 | | |
179 | 0 | for i in 1..height { |
180 | 0 | f.write_char('\n')?; |
181 | | |
182 | 0 | print_grid_line(f, &ctx, shape, height, row, i)?; |
183 | | } |
184 | | |
185 | 0 | new_line = true; |
186 | 0 | } |
187 | | } |
188 | | |
189 | 0 | if ctx.cfg.has_horizontal(shape.count_rows, shape.count_rows) { |
190 | 0 | f.write_char('\n')?; |
191 | 0 | print_split_line(f, ctx.cfg, ctx.dims, shape.count_rows, shape)?; |
192 | 0 | } |
193 | | |
194 | 0 | Ok(()) |
195 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_basic::build_grid::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&papergrid::dimension::peekable::PeekableGridDimension, papergrid::colors::nocolors::NoColors> Unexecuted instantiation: papergrid::grid::peekable::grid_basic::build_grid::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&papergrid::dimension::peekable::PeekableGridDimension, &tabled::grid::config::colored_config::ColorMap> Unexecuted instantiation: papergrid::grid::peekable::grid_basic::build_grid::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&tabled::grid::dimension::complete_dimension::CompleteDimension, papergrid::colors::nocolors::NoColors> Unexecuted instantiation: papergrid::grid::peekable::grid_basic::build_grid::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&tabled::grid::dimension::complete_dimension::CompleteDimension, &tabled::grid::config::colored_config::ColorMap> Unexecuted instantiation: papergrid::grid::peekable::grid_basic::build_grid::<_, _, _, _> |
196 | | |
197 | 0 | fn print_grid_line<F, R, D, C>( |
198 | 0 | f: &mut F, |
199 | 0 | ctx: &PrintCtx<'_, R, D, C>, |
200 | 0 | shape: Shape, |
201 | 0 | height: usize, |
202 | 0 | row: usize, |
203 | 0 | line: usize, |
204 | 0 | ) -> fmt::Result |
205 | 0 | where |
206 | 0 | F: Write, |
207 | 0 | R: Records + PeekableRecords + ExactRecords, |
208 | 0 | D: Dimension, |
209 | | { |
210 | 0 | for col in 0..shape.count_columns { |
211 | 0 | let pos = (row, col).into(); |
212 | 0 | print_vertical_char(f, ctx.cfg, pos, shape.count_columns)?; |
213 | 0 | print_cell_line(f, ctx, height, pos, line)?; |
214 | | } |
215 | | |
216 | 0 | let pos = (row, shape.count_columns).into(); |
217 | 0 | print_vertical_char(f, ctx.cfg, pos, shape.count_columns)?; |
218 | | |
219 | 0 | Ok(()) |
220 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_basic::print_grid_line::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&papergrid::dimension::peekable::PeekableGridDimension, papergrid::colors::nocolors::NoColors> Unexecuted instantiation: papergrid::grid::peekable::grid_basic::print_grid_line::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&papergrid::dimension::peekable::PeekableGridDimension, &tabled::grid::config::colored_config::ColorMap> Unexecuted instantiation: papergrid::grid::peekable::grid_basic::print_grid_line::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&tabled::grid::dimension::complete_dimension::CompleteDimension, papergrid::colors::nocolors::NoColors> Unexecuted instantiation: papergrid::grid::peekable::grid_basic::print_grid_line::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&tabled::grid::dimension::complete_dimension::CompleteDimension, &tabled::grid::config::colored_config::ColorMap> Unexecuted instantiation: papergrid::grid::peekable::grid_basic::print_grid_line::<_, _, _, _> |
221 | | |
222 | 0 | fn print_split_line<F, D>( |
223 | 0 | f: &mut F, |
224 | 0 | cfg: &SpannedConfig, |
225 | 0 | dimension: &D, |
226 | 0 | row: usize, |
227 | 0 | shape: Shape, |
228 | 0 | ) -> fmt::Result |
229 | 0 | where |
230 | 0 | F: Write, |
231 | 0 | D: Dimension, |
232 | | { |
233 | 0 | print_vertical_intersection(f, cfg, (row, 0).into(), shape)?; |
234 | | |
235 | 0 | for col in 0..shape.count_columns { |
236 | 0 | let width = dimension.get_width(col); |
237 | | |
238 | | // general case |
239 | 0 | if width > 0 { |
240 | 0 | let pos = (row, col).into(); |
241 | 0 | let main = cfg.get_horizontal(pos, shape.count_rows); |
242 | 0 | match main { |
243 | 0 | Some(c) => repeat_char(f, c, width)?, |
244 | 0 | None => repeat_char(f, ' ', width)?, |
245 | | } |
246 | 0 | } |
247 | | |
248 | 0 | let pos = (row, col + 1).into(); |
249 | 0 | print_vertical_intersection(f, cfg, pos, shape)?; |
250 | | } |
251 | | |
252 | 0 | Ok(()) |
253 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_basic::print_split_line::<&mut core::fmt::Formatter, &&papergrid::dimension::peekable::PeekableGridDimension> Unexecuted instantiation: papergrid::grid::peekable::grid_basic::print_split_line::<&mut core::fmt::Formatter, &&tabled::grid::dimension::complete_dimension::CompleteDimension> Unexecuted instantiation: papergrid::grid::peekable::grid_basic::print_split_line::<_, _> |
254 | | |
255 | 0 | fn print_vertical_intersection<F>( |
256 | 0 | f: &mut F, |
257 | 0 | cfg: &SpannedConfig, |
258 | 0 | pos: Position, |
259 | 0 | shape: Shape, |
260 | 0 | ) -> fmt::Result |
261 | 0 | where |
262 | 0 | F: fmt::Write, |
263 | | { |
264 | 0 | let intersection = cfg.get_intersection(pos, (shape.count_rows, shape.count_columns)); |
265 | 0 | let intersection = match intersection { |
266 | 0 | Some(c) => c, |
267 | 0 | None => return Ok(()), |
268 | | }; |
269 | | |
270 | | // We need to make sure that we need to print it. |
271 | | // Specifically for cases where we have a limited amount of verticals. |
272 | | // |
273 | | // todo: Yes... this check very likely degrages performance a bit, |
274 | | // Surely we need to rethink it. |
275 | 0 | if !cfg.has_vertical(pos.col, shape.count_columns) { |
276 | 0 | return Ok(()); |
277 | 0 | } |
278 | | |
279 | 0 | f.write_char(intersection)?; |
280 | | |
281 | 0 | Ok(()) |
282 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_basic::print_vertical_intersection::<&mut core::fmt::Formatter> Unexecuted instantiation: papergrid::grid::peekable::grid_basic::print_vertical_intersection::<_> |
283 | | |
284 | 0 | fn print_vertical_char<F>( |
285 | 0 | f: &mut F, |
286 | 0 | cfg: &SpannedConfig, |
287 | 0 | pos: Position, |
288 | 0 | count_columns: usize, |
289 | 0 | ) -> fmt::Result |
290 | 0 | where |
291 | 0 | F: Write, |
292 | | { |
293 | 0 | let symbol = match cfg.get_vertical(pos, count_columns) { |
294 | 0 | Some(c) => c, |
295 | 0 | None => return Ok(()), |
296 | | }; |
297 | | |
298 | 0 | f.write_char(symbol)?; |
299 | | |
300 | 0 | Ok(()) |
301 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_basic::print_vertical_char::<&mut core::fmt::Formatter> Unexecuted instantiation: papergrid::grid::peekable::grid_basic::print_vertical_char::<_> |
302 | | |
303 | 0 | fn print_cell_line<F, R, D, C>( |
304 | 0 | f: &mut F, |
305 | 0 | ctx: &PrintCtx<'_, R, D, C>, |
306 | 0 | height: usize, |
307 | 0 | pos: Position, |
308 | 0 | line: usize, |
309 | 0 | ) -> fmt::Result |
310 | 0 | where |
311 | 0 | F: Write, |
312 | 0 | R: Records + PeekableRecords + ExactRecords, |
313 | 0 | D: Dimension, |
314 | | { |
315 | 0 | let width = ctx.dims.get_width(pos.col); |
316 | | |
317 | 0 | let pad = ctx.cfg.get_padding(pos); |
318 | 0 | let valignment = *ctx.cfg.get_alignment_vertical(pos); |
319 | 0 | let text_cfg = TextCfg { |
320 | 0 | alignment: *ctx.cfg.get_alignment_horizontal(pos), |
321 | 0 | formatting: ctx.cfg.get_formatting(pos), |
322 | 0 | justification: ctx.cfg.get_justification(pos), |
323 | 0 | }; |
324 | | |
325 | 0 | let mut cell_height = ctx.records.count_lines(pos); |
326 | 0 | if text_cfg.formatting.vertical_trim { |
327 | 0 | cell_height -= count_empty_lines_at_start(ctx.records, pos) |
328 | 0 | + count_empty_lines_at_end(ctx.records, pos); |
329 | 0 | } |
330 | | |
331 | 0 | if cell_height > height { |
332 | 0 | // it may happen if the height estimation decide so |
333 | 0 | cell_height = height; |
334 | 0 | } |
335 | | |
336 | 0 | let indent = top_indent(pad, valignment, cell_height, height); |
337 | 0 | if indent > line { |
338 | 0 | return repeat_char(f, pad.top.fill, width); |
339 | 0 | } |
340 | | |
341 | 0 | let mut index = line - indent; |
342 | 0 | let cell_has_this_line = cell_height > index; |
343 | 0 | if !cell_has_this_line { |
344 | | // happens when other cells have bigger height |
345 | 0 | return repeat_char(f, pad.bottom.fill, width); |
346 | 0 | } |
347 | | |
348 | 0 | if text_cfg.formatting.vertical_trim { |
349 | 0 | let empty_lines = count_empty_lines_at_start(ctx.records, pos); |
350 | 0 | index += empty_lines; |
351 | | |
352 | 0 | if index > ctx.records.count_lines(pos) { |
353 | 0 | return repeat_char(f, pad.top.fill, width); |
354 | 0 | } |
355 | 0 | } |
356 | | |
357 | 0 | let width = width - pad.left.size - pad.right.size; |
358 | | |
359 | 0 | repeat_char(f, pad.left.fill, pad.left.size)?; |
360 | 0 | print_line(f, ctx.records, pos, index, width, text_cfg)?; |
361 | 0 | repeat_char(f, pad.right.fill, pad.right.size)?; |
362 | | |
363 | 0 | Ok(()) |
364 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_basic::print_cell_line::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&papergrid::dimension::peekable::PeekableGridDimension, papergrid::colors::nocolors::NoColors> Unexecuted instantiation: papergrid::grid::peekable::grid_basic::print_cell_line::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&papergrid::dimension::peekable::PeekableGridDimension, &tabled::grid::config::colored_config::ColorMap> Unexecuted instantiation: papergrid::grid::peekable::grid_basic::print_cell_line::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&tabled::grid::dimension::complete_dimension::CompleteDimension, papergrid::colors::nocolors::NoColors> Unexecuted instantiation: papergrid::grid::peekable::grid_basic::print_cell_line::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&tabled::grid::dimension::complete_dimension::CompleteDimension, &tabled::grid::config::colored_config::ColorMap> Unexecuted instantiation: papergrid::grid::peekable::grid_basic::print_cell_line::<_, _, _, _> |
365 | | |
366 | 0 | fn print_line<F, R>( |
367 | 0 | f: &mut F, |
368 | 0 | records: &R, |
369 | 0 | pos: Position, |
370 | 0 | index: usize, |
371 | 0 | available: usize, |
372 | 0 | cfg: TextCfg, |
373 | 0 | ) -> fmt::Result |
374 | 0 | where |
375 | 0 | F: Write, |
376 | 0 | R: Records + PeekableRecords, |
377 | | { |
378 | 0 | let line = records.get_line(pos, index); |
379 | 0 | let (line, line_width) = if cfg.formatting.horizontal_trim { |
380 | 0 | let line = string_trim(line); |
381 | 0 | let width = get_line_width(&line); |
382 | 0 | (line, width) |
383 | | } else { |
384 | 0 | let width = records.get_line_width(pos, index); |
385 | 0 | (Cow::Borrowed(line), width) |
386 | | }; |
387 | | |
388 | 0 | if cfg.formatting.allow_lines_alignment { |
389 | 0 | let indent = calculate_indent(cfg.alignment, line_width, available); |
390 | 0 | return print_text_padded(f, &line, cfg.justification, indent); |
391 | 0 | } |
392 | | |
393 | 0 | let cell_width = if cfg.formatting.horizontal_trim { |
394 | 0 | (0..records.count_lines(pos)) |
395 | 0 | .map(|i| records.get_line(pos, i)) Unexecuted instantiation: papergrid::grid::peekable::grid_basic::print_line::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>>::{closure#0}Unexecuted instantiation: papergrid::grid::peekable::grid_basic::print_line::<_, _>::{closure#0} |
396 | 0 | .map(|line| get_line_width(line.trim())) Unexecuted instantiation: papergrid::grid::peekable::grid_basic::print_line::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>>::{closure#1}Unexecuted instantiation: papergrid::grid::peekable::grid_basic::print_line::<_, _>::{closure#1} |
397 | 0 | .max() |
398 | 0 | .unwrap_or_default() |
399 | | } else { |
400 | 0 | records.get_width(pos) |
401 | | }; |
402 | | |
403 | 0 | let indent = calculate_indent(cfg.alignment, cell_width, available); |
404 | 0 | print_text_padded(f, &line, cfg.justification, indent)?; |
405 | | |
406 | 0 | let rest_width = cell_width - line_width; |
407 | 0 | repeat_char(f, cfg.justification, rest_width)?; |
408 | | |
409 | 0 | Ok(()) |
410 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_basic::print_line::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>> Unexecuted instantiation: papergrid::grid::peekable::grid_basic::print_line::<_, _> |
411 | | |
412 | 0 | fn print_text_padded<F>(f: &mut F, text: &str, space: char, indent: HIndent) -> fmt::Result |
413 | 0 | where |
414 | 0 | F: Write, |
415 | | { |
416 | 0 | repeat_char(f, space, indent.left)?; |
417 | 0 | f.write_str(text)?; |
418 | 0 | repeat_char(f, space, indent.right)?; |
419 | | |
420 | 0 | Ok(()) |
421 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_basic::print_text_padded::<&mut core::fmt::Formatter> Unexecuted instantiation: papergrid::grid::peekable::grid_basic::print_text_padded::<_> |
422 | | |
423 | 0 | fn top_indent( |
424 | 0 | pad: &Sides<Indent>, |
425 | 0 | alignment: AlignmentVertical, |
426 | 0 | height: usize, |
427 | 0 | available: usize, |
428 | 0 | ) -> usize { |
429 | 0 | let available = available - pad.top.size; |
430 | 0 | let indent = indent_from_top(alignment, available, height); |
431 | | |
432 | 0 | indent + pad.top.size |
433 | 0 | } |
434 | | |
435 | 0 | fn indent_from_top(alignment: AlignmentVertical, available: usize, real: usize) -> usize { |
436 | 0 | match alignment { |
437 | 0 | AlignmentVertical::Top => 0, |
438 | 0 | AlignmentVertical::Bottom => available - real, |
439 | 0 | AlignmentVertical::Center => (available - real) / 2, |
440 | | } |
441 | 0 | } |
442 | | |
443 | 0 | fn calculate_indent(alignment: AlignmentHorizontal, width: usize, available: usize) -> HIndent { |
444 | 0 | let diff = available - width; |
445 | | |
446 | 0 | let (left, right) = match alignment { |
447 | 0 | AlignmentHorizontal::Left => (0, diff), |
448 | 0 | AlignmentHorizontal::Right => (diff, 0), |
449 | | AlignmentHorizontal::Center => { |
450 | 0 | let left = diff / 2; |
451 | 0 | let rest = diff - left; |
452 | 0 | (left, rest) |
453 | | } |
454 | | }; |
455 | | |
456 | 0 | HIndent { left, right } |
457 | 0 | } |
458 | | |
459 | 0 | fn repeat_char<F>(f: &mut F, c: char, n: usize) -> fmt::Result |
460 | 0 | where |
461 | 0 | F: Write, |
462 | | { |
463 | 0 | for _ in 0..n { |
464 | 0 | f.write_char(c)?; |
465 | | } |
466 | | |
467 | 0 | Ok(()) |
468 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_basic::repeat_char::<&mut core::fmt::Formatter> Unexecuted instantiation: papergrid::grid::peekable::grid_basic::repeat_char::<_> |
469 | | |
470 | 0 | fn count_empty_lines_at_end<R>(records: &R, pos: Position) -> usize |
471 | 0 | where |
472 | 0 | R: Records + PeekableRecords, |
473 | | { |
474 | 0 | (0..records.count_lines(pos)) |
475 | 0 | .map(|i| records.get_line(pos, i)) Unexecuted instantiation: papergrid::grid::peekable::grid_basic::count_empty_lines_at_end::<&papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>>::{closure#0}Unexecuted instantiation: papergrid::grid::peekable::grid_basic::count_empty_lines_at_end::<_>::{closure#0} |
476 | 0 | .rev() |
477 | 0 | .take_while(|l| l.trim().is_empty()) Unexecuted instantiation: papergrid::grid::peekable::grid_basic::count_empty_lines_at_end::<&papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>>::{closure#1}Unexecuted instantiation: papergrid::grid::peekable::grid_basic::count_empty_lines_at_end::<_>::{closure#1} |
478 | 0 | .count() |
479 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_basic::count_empty_lines_at_end::<&papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>> Unexecuted instantiation: papergrid::grid::peekable::grid_basic::count_empty_lines_at_end::<_> |
480 | | |
481 | 0 | fn count_empty_lines_at_start<R>(records: &R, pos: Position) -> usize |
482 | 0 | where |
483 | 0 | R: Records + PeekableRecords, |
484 | | { |
485 | 0 | (0..records.count_lines(pos)) |
486 | 0 | .map(|i| records.get_line(pos, i)) Unexecuted instantiation: papergrid::grid::peekable::grid_basic::count_empty_lines_at_start::<&papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>>::{closure#0}Unexecuted instantiation: papergrid::grid::peekable::grid_basic::count_empty_lines_at_start::<_>::{closure#0} |
487 | 0 | .take_while(|s| s.trim().is_empty()) Unexecuted instantiation: papergrid::grid::peekable::grid_basic::count_empty_lines_at_start::<&papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>>::{closure#1}Unexecuted instantiation: papergrid::grid::peekable::grid_basic::count_empty_lines_at_start::<_>::{closure#1} |
488 | 0 | .count() |
489 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_basic::count_empty_lines_at_start::<&papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>> Unexecuted instantiation: papergrid::grid::peekable::grid_basic::count_empty_lines_at_start::<_> |
490 | | |
491 | | /// Trims a string. |
492 | 0 | fn string_trim(text: &str) -> Cow<'_, str> { |
493 | | #[cfg(feature = "ansi")] |
494 | | { |
495 | | ansi_str::AnsiStr::ansi_trim(text) |
496 | | } |
497 | | |
498 | | #[cfg(not(feature = "ansi"))] |
499 | | { |
500 | 0 | text.trim().into() |
501 | | } |
502 | 0 | } |
503 | | } |
504 | | |
505 | | mod grid_not_spanned { |
506 | | use super::*; |
507 | | |
508 | | struct TextCfg<C, C1> { |
509 | | alignment: AlignmentHorizontal, |
510 | | formatting: Formatting, |
511 | | color: Option<C>, |
512 | | justification: Colored<char, C1>, |
513 | | } |
514 | | |
515 | | struct Colored<T, C> { |
516 | | data: T, |
517 | | color: Option<C>, |
518 | | } |
519 | | |
520 | | impl<T, C> Colored<T, C> { |
521 | 0 | fn new(data: T, color: Option<C>) -> Self { |
522 | 0 | Self { data, color } |
523 | 0 | } Unexecuted instantiation: <papergrid::grid::peekable::grid_not_spanned::Colored<&str, &papergrid::ansi::ansi_buf::ANSIBuf>>::new Unexecuted instantiation: <papergrid::grid::peekable::grid_not_spanned::Colored<&str, &papergrid::colors::nocolors::NoColor>>::new Unexecuted instantiation: <papergrid::grid::peekable::grid_not_spanned::Colored<char, &papergrid::ansi::ansi_buf::ANSIBuf>>::new Unexecuted instantiation: <papergrid::grid::peekable::grid_not_spanned::Colored<_, _>>::new |
524 | | } |
525 | | |
526 | | #[derive(Debug, Clone, Copy)] |
527 | | struct Shape { |
528 | | count_rows: usize, |
529 | | count_columns: usize, |
530 | | } |
531 | | |
532 | | struct HIndent { |
533 | | left: usize, |
534 | | right: usize, |
535 | | } |
536 | | |
537 | 0 | pub(super) fn build_grid<F, R, D, C>(f: &mut F, ctx: PrintCtx<'_, R, D, C>) -> fmt::Result |
538 | 0 | where |
539 | 0 | F: Write, |
540 | 0 | R: Records + PeekableRecords + ExactRecords, |
541 | 0 | D: Dimension, |
542 | 0 | C: Colors, |
543 | | { |
544 | 0 | let shape = Shape { |
545 | 0 | count_rows: ctx.records.count_rows(), |
546 | 0 | count_columns: ctx.records.count_columns(), |
547 | 0 | }; |
548 | | |
549 | 0 | let total_width = total_width(ctx.cfg, ctx.dims, shape.count_columns); |
550 | | |
551 | 0 | let margin = ctx.cfg.get_margin(); |
552 | 0 | let total_width_with_margin = total_width + margin.left.size + margin.right.size; |
553 | | |
554 | 0 | let total_height = total_height(ctx.cfg, ctx.dims, shape.count_rows); |
555 | | |
556 | 0 | if margin.top.size > 0 { |
557 | 0 | print_margin_top(f, ctx.cfg, total_width_with_margin)?; |
558 | 0 | f.write_char('\n')?; |
559 | 0 | } |
560 | | |
561 | 0 | let mut table_line = 0; |
562 | 0 | let mut prev_empty_horizontal = false; |
563 | 0 | for row in 0..shape.count_rows { |
564 | 0 | let height = ctx.dims.get_height(row); |
565 | | |
566 | 0 | if ctx.cfg.has_horizontal(row, shape.count_rows) { |
567 | 0 | if prev_empty_horizontal { |
568 | 0 | f.write_char('\n')?; |
569 | 0 | } |
570 | | |
571 | 0 | print_margin_left(f, ctx.cfg, table_line, total_height)?; |
572 | 0 | print_split_line(f, ctx.cfg, ctx.dims, row, shape)?; |
573 | 0 | print_margin_right(f, ctx.cfg, table_line, total_height)?; |
574 | | |
575 | 0 | if height > 0 { |
576 | 0 | f.write_char('\n')?; |
577 | 0 | prev_empty_horizontal = false; |
578 | 0 | } else { |
579 | 0 | prev_empty_horizontal = true; |
580 | 0 | } |
581 | | |
582 | 0 | table_line += 1; |
583 | 0 | } else if height > 0 && prev_empty_horizontal { |
584 | 0 | f.write_char('\n')?; |
585 | 0 | prev_empty_horizontal = false; |
586 | 0 | } |
587 | | |
588 | 0 | for i in 0..height { |
589 | 0 | print_margin_left(f, ctx.cfg, table_line, total_height)?; |
590 | | |
591 | 0 | for col in 0..shape.count_columns { |
592 | 0 | let pos = (row, col).into(); |
593 | 0 | print_vertical_char(f, ctx.cfg, pos, i, height, shape.count_columns)?; |
594 | 0 | print_cell_line(f, &ctx, height, pos, i)?; |
595 | | |
596 | 0 | let is_last_column = col + 1 == shape.count_columns; |
597 | 0 | if is_last_column { |
598 | 0 | let pos = (row, col + 1).into(); |
599 | 0 | print_vertical_char(f, ctx.cfg, pos, i, height, shape.count_columns)?; |
600 | 0 | } |
601 | | } |
602 | | |
603 | 0 | print_margin_right(f, ctx.cfg, table_line, total_height)?; |
604 | | |
605 | 0 | let is_last_line = i + 1 == height; |
606 | 0 | let is_last_row = row + 1 == shape.count_rows; |
607 | 0 | if !(is_last_line && is_last_row) { |
608 | 0 | f.write_char('\n')?; |
609 | 0 | } |
610 | | |
611 | 0 | table_line += 1; |
612 | | } |
613 | | } |
614 | | |
615 | 0 | if ctx.cfg.has_horizontal(shape.count_rows, shape.count_rows) { |
616 | 0 | f.write_char('\n')?; |
617 | 0 | print_margin_left(f, ctx.cfg, table_line, total_height)?; |
618 | 0 | print_split_line(f, ctx.cfg, ctx.dims, shape.count_rows, shape)?; |
619 | 0 | print_margin_right(f, ctx.cfg, table_line, total_height)?; |
620 | 0 | } |
621 | | |
622 | 0 | if margin.bottom.size > 0 { |
623 | 0 | f.write_char('\n')?; |
624 | 0 | print_margin_bottom(f, ctx.cfg, total_width_with_margin)?; |
625 | 0 | } |
626 | | |
627 | 0 | Ok(()) |
628 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::build_grid::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&papergrid::dimension::peekable::PeekableGridDimension, papergrid::colors::nocolors::NoColors> Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::build_grid::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&papergrid::dimension::peekable::PeekableGridDimension, &tabled::grid::config::colored_config::ColorMap> Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::build_grid::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&tabled::grid::dimension::complete_dimension::CompleteDimension, papergrid::colors::nocolors::NoColors> Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::build_grid::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&tabled::grid::dimension::complete_dimension::CompleteDimension, &tabled::grid::config::colored_config::ColorMap> Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::build_grid::<_, _, _, _> |
629 | | |
630 | 0 | fn print_split_line<F, D>( |
631 | 0 | f: &mut F, |
632 | 0 | cfg: &SpannedConfig, |
633 | 0 | dimension: &D, |
634 | 0 | row: usize, |
635 | 0 | shape: Shape, |
636 | 0 | ) -> fmt::Result |
637 | 0 | where |
638 | 0 | F: Write, |
639 | 0 | D: Dimension, |
640 | | { |
641 | 0 | let mut used_color = None; |
642 | 0 | print_vertical_intersection(f, cfg, (row, 0).into(), shape, &mut used_color)?; |
643 | | |
644 | 0 | for col in 0..shape.count_columns { |
645 | 0 | let width = dimension.get_width(col); |
646 | | |
647 | | // general case |
648 | 0 | if width > 0 { |
649 | 0 | let pos = (row, col).into(); |
650 | 0 | let main = cfg.get_horizontal(pos, shape.count_rows); |
651 | 0 | match main { |
652 | 0 | Some(c) => { |
653 | 0 | let clr = cfg.get_horizontal_color(pos, shape.count_rows); |
654 | 0 | prepare_coloring(f, clr, &mut used_color)?; |
655 | 0 | print_horizontal_border(f, cfg, pos, width, c, &used_color)?; |
656 | | } |
657 | 0 | None => repeat_char(f, ' ', width)?, |
658 | | } |
659 | 0 | } |
660 | | |
661 | 0 | let pos = (row, col + 1).into(); |
662 | 0 | print_vertical_intersection(f, cfg, pos, shape, &mut used_color)?; |
663 | | } |
664 | | |
665 | 0 | if let Some(clr) = used_color.take() { |
666 | 0 | clr.fmt_ansi_suffix(f)?; |
667 | 0 | } |
668 | | |
669 | 0 | Ok(()) |
670 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_split_line::<&mut core::fmt::Formatter, &&papergrid::dimension::peekable::PeekableGridDimension> Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_split_line::<&mut core::fmt::Formatter, &&tabled::grid::dimension::complete_dimension::CompleteDimension> Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_split_line::<_, _> |
671 | | |
672 | 0 | fn print_vertical_intersection<'a, F>( |
673 | 0 | f: &mut F, |
674 | 0 | cfg: &'a SpannedConfig, |
675 | 0 | pos: Position, |
676 | 0 | shape: Shape, |
677 | 0 | used_color: &mut Option<&'a ANSIBuf>, |
678 | 0 | ) -> fmt::Result |
679 | 0 | where |
680 | 0 | F: fmt::Write, |
681 | | { |
682 | 0 | let intersection = match cfg.get_intersection(pos, (shape.count_rows, shape.count_columns)) |
683 | | { |
684 | 0 | Some(c) => c, |
685 | 0 | None => return Ok(()), |
686 | | }; |
687 | | |
688 | | // We need to make sure that we need to print it. |
689 | | // Specifically for cases where we have a limited amount of verticals. |
690 | | // |
691 | | // todo: Yes... this check very likely degrages performance a bit, |
692 | | // Surely we need to rethink it. |
693 | 0 | if !cfg.has_vertical(pos.col, shape.count_columns) { |
694 | 0 | return Ok(()); |
695 | 0 | } |
696 | | |
697 | 0 | let color = cfg.get_intersection_color(pos, (shape.count_rows, shape.count_columns)); |
698 | 0 | prepare_coloring(f, color, used_color)?; |
699 | 0 | f.write_char(intersection)?; |
700 | | |
701 | 0 | Ok(()) |
702 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_vertical_intersection::<&mut core::fmt::Formatter> Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_vertical_intersection::<_> |
703 | | |
704 | 0 | fn prepare_coloring<'a, F>( |
705 | 0 | f: &mut F, |
706 | 0 | clr: Option<&'a ANSIBuf>, |
707 | 0 | used_color: &mut Option<&'a ANSIBuf>, |
708 | 0 | ) -> fmt::Result |
709 | 0 | where |
710 | 0 | F: Write, |
711 | | { |
712 | 0 | match clr { |
713 | 0 | Some(clr) => match used_color.as_mut() { |
714 | 0 | Some(used_clr) => { |
715 | 0 | if **used_clr != *clr { |
716 | 0 | used_clr.fmt_ansi_suffix(f)?; |
717 | 0 | clr.fmt_ansi_prefix(f)?; |
718 | 0 | *used_clr = clr; |
719 | 0 | } |
720 | | } |
721 | | None => { |
722 | 0 | clr.fmt_ansi_prefix(f)?; |
723 | 0 | *used_color = Some(clr); |
724 | | } |
725 | | }, |
726 | | None => { |
727 | 0 | if let Some(clr) = used_color.take() { |
728 | 0 | clr.fmt_ansi_suffix(f)? |
729 | 0 | } |
730 | | } |
731 | | } |
732 | | |
733 | 0 | Ok(()) |
734 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::prepare_coloring::<&mut core::fmt::Formatter> Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::prepare_coloring::<_> |
735 | | |
736 | 0 | fn print_vertical_char<F>( |
737 | 0 | f: &mut F, |
738 | 0 | cfg: &SpannedConfig, |
739 | 0 | pos: Position, |
740 | 0 | line: usize, |
741 | 0 | count_lines: usize, |
742 | 0 | count_columns: usize, |
743 | 0 | ) -> fmt::Result |
744 | 0 | where |
745 | 0 | F: Write, |
746 | | { |
747 | 0 | let symbol = match cfg.get_vertical(pos, count_columns) { |
748 | 0 | Some(c) => c, |
749 | 0 | None => return Ok(()), |
750 | | }; |
751 | | |
752 | 0 | let symbol = cfg |
753 | 0 | .lookup_vertical_char(pos, line, count_lines) |
754 | 0 | .unwrap_or(symbol); |
755 | | |
756 | 0 | let color = cfg |
757 | 0 | .get_vertical_color(pos, count_columns) |
758 | 0 | .or_else(|| cfg.lookup_vertical_color(pos, line, count_lines)); Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_vertical_char::<&mut core::fmt::Formatter>::{closure#0}Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_vertical_char::<_>::{closure#0} |
759 | | |
760 | 0 | match color { |
761 | 0 | Some(clr) => { |
762 | 0 | clr.fmt_ansi_prefix(f)?; |
763 | 0 | f.write_char(symbol)?; |
764 | 0 | clr.fmt_ansi_suffix(f)?; |
765 | | } |
766 | 0 | None => f.write_char(symbol)?, |
767 | | } |
768 | | |
769 | 0 | Ok(()) |
770 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_vertical_char::<&mut core::fmt::Formatter> Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_vertical_char::<_> |
771 | | |
772 | 0 | fn print_horizontal_border<F>( |
773 | 0 | f: &mut F, |
774 | 0 | cfg: &SpannedConfig, |
775 | 0 | pos: Position, |
776 | 0 | width: usize, |
777 | 0 | c: char, |
778 | 0 | used_color: &Option<&ANSIBuf>, |
779 | 0 | ) -> fmt::Result |
780 | 0 | where |
781 | 0 | F: Write, |
782 | | { |
783 | 0 | if !cfg.is_overridden_horizontal(pos) { |
784 | 0 | return repeat_char(f, c, width); |
785 | 0 | } |
786 | | |
787 | 0 | for i in 0..width { |
788 | 0 | let c = cfg.lookup_horizontal_char(pos, i, width).unwrap_or(c); |
789 | 0 | match cfg.lookup_horizontal_color(pos, i, width) { |
790 | 0 | Some(color) => match used_color { |
791 | 0 | Some(clr) => { |
792 | 0 | clr.fmt_ansi_suffix(f)?; |
793 | 0 | color.fmt_ansi_prefix(f)?; |
794 | 0 | f.write_char(c)?; |
795 | 0 | color.fmt_ansi_suffix(f)?; |
796 | 0 | clr.fmt_ansi_prefix(f)?; |
797 | | } |
798 | | None => { |
799 | 0 | color.fmt_ansi_prefix(f)?; |
800 | 0 | f.write_char(c)?; |
801 | 0 | color.fmt_ansi_suffix(f)?; |
802 | | } |
803 | | }, |
804 | 0 | _ => f.write_char(c)?, |
805 | | } |
806 | | } |
807 | | |
808 | 0 | Ok(()) |
809 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_horizontal_border::<&mut core::fmt::Formatter> Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_horizontal_border::<_> |
810 | | |
811 | 0 | fn print_cell_line<F, R, D, C>( |
812 | 0 | f: &mut F, |
813 | 0 | ctx: &PrintCtx<'_, R, D, C>, |
814 | 0 | height: usize, |
815 | 0 | pos: Position, |
816 | 0 | line: usize, |
817 | 0 | ) -> fmt::Result |
818 | 0 | where |
819 | 0 | F: Write, |
820 | 0 | R: Records + PeekableRecords + ExactRecords, |
821 | 0 | C: Colors, |
822 | 0 | D: Dimension, |
823 | | { |
824 | 0 | let width = ctx.dims.get_width(pos.col); |
825 | | |
826 | 0 | let formatting = ctx.cfg.get_formatting(pos); |
827 | 0 | let text_cfg = TextCfg { |
828 | 0 | alignment: *ctx.cfg.get_alignment_horizontal(pos), |
829 | 0 | color: ctx.colors.get_color(pos), |
830 | 0 | justification: Colored::new( |
831 | 0 | ctx.cfg.get_justification(pos), |
832 | 0 | ctx.cfg.get_justification_color(pos), |
833 | 0 | ), |
834 | 0 | formatting, |
835 | 0 | }; |
836 | | |
837 | 0 | let pad = ctx.cfg.get_padding(pos); |
838 | 0 | let pad_color = ctx.cfg.get_padding_color(pos); |
839 | 0 | let valignment = *ctx.cfg.get_alignment_vertical(pos); |
840 | | |
841 | 0 | let mut cell_height = ctx.records.count_lines(pos); |
842 | 0 | if formatting.vertical_trim { |
843 | 0 | cell_height -= count_empty_lines_at_start(ctx.records, pos) |
844 | 0 | + count_empty_lines_at_end(ctx.records, pos); |
845 | 0 | } |
846 | | |
847 | 0 | if cell_height > height { |
848 | 0 | // it may happen if the height estimation decide so |
849 | 0 | cell_height = height; |
850 | 0 | } |
851 | | |
852 | 0 | let indent = top_indent(pad, valignment, cell_height, height); |
853 | 0 | if indent > line { |
854 | 0 | return print_indent(f, pad.top.fill, width, pad_color.top.as_ref()); |
855 | 0 | } |
856 | | |
857 | 0 | let mut index = line - indent; |
858 | 0 | let cell_has_this_line = cell_height > index; |
859 | 0 | if !cell_has_this_line { |
860 | | // happens when other cells have bigger height |
861 | 0 | return print_indent(f, pad.bottom.fill, width, pad_color.bottom.as_ref()); |
862 | 0 | } |
863 | | |
864 | 0 | if formatting.vertical_trim { |
865 | 0 | let empty_lines = count_empty_lines_at_start(ctx.records, pos); |
866 | 0 | index += empty_lines; |
867 | | |
868 | 0 | if index > ctx.records.count_lines(pos) { |
869 | 0 | return print_indent(f, pad.top.fill, width, pad_color.top.as_ref()); |
870 | 0 | } |
871 | 0 | } |
872 | | |
873 | 0 | let width = width - pad.left.size - pad.right.size; |
874 | | |
875 | 0 | print_indent(f, pad.left.fill, pad.left.size, pad_color.left.as_ref())?; |
876 | 0 | print_line(f, ctx.records, pos, index, width, text_cfg)?; |
877 | 0 | print_indent(f, pad.right.fill, pad.right.size, pad_color.right.as_ref())?; |
878 | | |
879 | 0 | Ok(()) |
880 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_cell_line::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&papergrid::dimension::peekable::PeekableGridDimension, papergrid::colors::nocolors::NoColors> Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_cell_line::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&papergrid::dimension::peekable::PeekableGridDimension, &tabled::grid::config::colored_config::ColorMap> Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_cell_line::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&tabled::grid::dimension::complete_dimension::CompleteDimension, papergrid::colors::nocolors::NoColors> Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_cell_line::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&tabled::grid::dimension::complete_dimension::CompleteDimension, &tabled::grid::config::colored_config::ColorMap> Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_cell_line::<_, _, _, _> |
881 | | |
882 | 0 | fn print_line<F, R, C>( |
883 | 0 | f: &mut F, |
884 | 0 | records: &R, |
885 | 0 | pos: Position, |
886 | 0 | index: usize, |
887 | 0 | available: usize, |
888 | 0 | cfg: TextCfg<C, &'_ ANSIBuf>, |
889 | 0 | ) -> fmt::Result |
890 | 0 | where |
891 | 0 | F: Write, |
892 | 0 | R: Records + PeekableRecords, |
893 | 0 | C: ANSIFmt, |
894 | | { |
895 | 0 | let line = records.get_line(pos, index); |
896 | 0 | let (line, line_width) = if cfg.formatting.horizontal_trim { |
897 | 0 | let line = string_trim(line); |
898 | 0 | let width = get_line_width(&line); |
899 | 0 | (line, width) |
900 | | } else { |
901 | 0 | let width = records.get_line_width(pos, index); |
902 | 0 | (Cow::Borrowed(line), width) |
903 | | }; |
904 | | |
905 | 0 | if cfg.formatting.allow_lines_alignment { |
906 | 0 | let indent = calculate_indent(cfg.alignment, line_width, available); |
907 | 0 | let text = Colored::new(line.as_ref(), cfg.color); |
908 | 0 | return print_text_padded(f, &text, &cfg.justification, indent); |
909 | 0 | } |
910 | | |
911 | 0 | let cell_width = if cfg.formatting.horizontal_trim { |
912 | 0 | (0..records.count_lines(pos)) |
913 | 0 | .map(|i| records.get_line(pos, i)) Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_line::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &papergrid::ansi::ansi_buf::ANSIBuf>::{closure#0}Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_line::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &papergrid::colors::nocolors::NoColor>::{closure#0}Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_line::<_, _, _>::{closure#0} |
914 | 0 | .map(|line| get_line_width(line.trim())) Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_line::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &papergrid::ansi::ansi_buf::ANSIBuf>::{closure#1}Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_line::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &papergrid::colors::nocolors::NoColor>::{closure#1}Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_line::<_, _, _>::{closure#1} |
915 | 0 | .max() |
916 | 0 | .unwrap_or_default() |
917 | | } else { |
918 | 0 | records.get_width(pos) |
919 | | }; |
920 | | |
921 | 0 | let indent = calculate_indent(cfg.alignment, cell_width, available); |
922 | 0 | let text = Colored::new(line.as_ref(), cfg.color); |
923 | 0 | print_text_padded(f, &text, &cfg.justification, indent)?; |
924 | | |
925 | 0 | let rest_width = cell_width - line_width; |
926 | 0 | print_indent2(f, &cfg.justification, rest_width)?; |
927 | | |
928 | 0 | Ok(()) |
929 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_line::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &papergrid::ansi::ansi_buf::ANSIBuf> Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_line::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &papergrid::colors::nocolors::NoColor> Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_line::<_, _, _> |
930 | | |
931 | 0 | fn print_text_padded<F, C, C1>( |
932 | 0 | f: &mut F, |
933 | 0 | text: &Colored<&str, C>, |
934 | 0 | justification: &Colored<char, C1>, |
935 | 0 | indent: HIndent, |
936 | 0 | ) -> fmt::Result |
937 | 0 | where |
938 | 0 | F: Write, |
939 | 0 | C: ANSIFmt, |
940 | 0 | C1: ANSIFmt, |
941 | | { |
942 | 0 | print_indent2(f, justification, indent.left)?; |
943 | 0 | print_text2(f, text)?; |
944 | 0 | print_indent2(f, justification, indent.right)?; |
945 | | |
946 | 0 | Ok(()) |
947 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_text_padded::<&mut core::fmt::Formatter, &papergrid::ansi::ansi_buf::ANSIBuf, &papergrid::ansi::ansi_buf::ANSIBuf> Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_text_padded::<&mut core::fmt::Formatter, &papergrid::colors::nocolors::NoColor, &papergrid::ansi::ansi_buf::ANSIBuf> Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_text_padded::<_, _, _> |
948 | | |
949 | 0 | fn print_text2<F, C>(f: &mut F, text: &Colored<&str, C>) -> fmt::Result |
950 | 0 | where |
951 | 0 | F: Write, |
952 | 0 | C: ANSIFmt, |
953 | | { |
954 | 0 | match &text.color { |
955 | 0 | Some(color) => { |
956 | 0 | color.fmt_ansi_prefix(f)?; |
957 | 0 | f.write_str(text.data)?; |
958 | 0 | color.fmt_ansi_suffix(f) |
959 | | } |
960 | 0 | None => f.write_str(text.data), |
961 | | } |
962 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_text2::<&mut core::fmt::Formatter, &papergrid::ansi::ansi_buf::ANSIBuf> Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_text2::<&mut core::fmt::Formatter, &papergrid::colors::nocolors::NoColor> Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_text2::<_, _> |
963 | | |
964 | 0 | fn top_indent( |
965 | 0 | pad: &Sides<Indent>, |
966 | 0 | alignment: AlignmentVertical, |
967 | 0 | height: usize, |
968 | 0 | available: usize, |
969 | 0 | ) -> usize { |
970 | 0 | let available = available - pad.top.size; |
971 | 0 | let indent = indent_from_top(alignment, available, height); |
972 | | |
973 | 0 | indent + pad.top.size |
974 | 0 | } |
975 | | |
976 | 0 | fn indent_from_top(alignment: AlignmentVertical, available: usize, real: usize) -> usize { |
977 | 0 | match alignment { |
978 | 0 | AlignmentVertical::Top => 0, |
979 | 0 | AlignmentVertical::Bottom => available - real, |
980 | 0 | AlignmentVertical::Center => (available - real) / 2, |
981 | | } |
982 | 0 | } |
983 | | |
984 | 0 | fn calculate_indent(alignment: AlignmentHorizontal, width: usize, available: usize) -> HIndent { |
985 | 0 | let diff = available - width; |
986 | | |
987 | 0 | let (left, right) = match alignment { |
988 | 0 | AlignmentHorizontal::Left => (0, diff), |
989 | 0 | AlignmentHorizontal::Right => (diff, 0), |
990 | | AlignmentHorizontal::Center => { |
991 | 0 | let left = diff / 2; |
992 | 0 | let rest = diff - left; |
993 | 0 | (left, rest) |
994 | | } |
995 | | }; |
996 | | |
997 | 0 | HIndent { left, right } |
998 | 0 | } |
999 | | |
1000 | 0 | fn repeat_char<F>(f: &mut F, c: char, n: usize) -> fmt::Result |
1001 | 0 | where |
1002 | 0 | F: Write, |
1003 | | { |
1004 | 0 | for _ in 0..n { |
1005 | 0 | f.write_char(c)?; |
1006 | | } |
1007 | | |
1008 | 0 | Ok(()) |
1009 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::repeat_char::<&mut core::fmt::Formatter> Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::repeat_char::<_> |
1010 | | |
1011 | 0 | fn count_empty_lines_at_end<R>(records: &R, pos: Position) -> usize |
1012 | 0 | where |
1013 | 0 | R: Records + PeekableRecords, |
1014 | | { |
1015 | 0 | (0..records.count_lines(pos)) |
1016 | 0 | .map(|i| records.get_line(pos, i)) Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::count_empty_lines_at_end::<&papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>>::{closure#0}Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::count_empty_lines_at_end::<_>::{closure#0} |
1017 | 0 | .rev() |
1018 | 0 | .take_while(|l| l.trim().is_empty()) Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::count_empty_lines_at_end::<&papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>>::{closure#1}Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::count_empty_lines_at_end::<_>::{closure#1} |
1019 | 0 | .count() |
1020 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::count_empty_lines_at_end::<&papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>> Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::count_empty_lines_at_end::<_> |
1021 | | |
1022 | 0 | fn count_empty_lines_at_start<R>(records: &R, pos: Position) -> usize |
1023 | 0 | where |
1024 | 0 | R: Records + PeekableRecords, |
1025 | | { |
1026 | 0 | (0..records.count_lines(pos)) |
1027 | 0 | .map(|i| records.get_line(pos, i)) Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::count_empty_lines_at_start::<&papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>>::{closure#0}Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::count_empty_lines_at_start::<_>::{closure#0} |
1028 | 0 | .take_while(|s| s.trim().is_empty()) Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::count_empty_lines_at_start::<&papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>>::{closure#1}Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::count_empty_lines_at_start::<_>::{closure#1} |
1029 | 0 | .count() |
1030 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::count_empty_lines_at_start::<&papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>> Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::count_empty_lines_at_start::<_> |
1031 | | |
1032 | 0 | fn total_width<D>(cfg: &SpannedConfig, dimension: &D, count_columns: usize) -> usize |
1033 | 0 | where |
1034 | 0 | D: Dimension, |
1035 | | { |
1036 | 0 | (0..count_columns) |
1037 | 0 | .map(|i| dimension.get_width(i)) Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::total_width::<&&papergrid::dimension::peekable::PeekableGridDimension>::{closure#0}Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::total_width::<&&tabled::grid::dimension::complete_dimension::CompleteDimension>::{closure#0}Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::total_width::<_>::{closure#0} |
1038 | 0 | .sum::<usize>() |
1039 | 0 | + cfg.count_vertical(count_columns) |
1040 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::total_width::<&&papergrid::dimension::peekable::PeekableGridDimension> Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::total_width::<&&tabled::grid::dimension::complete_dimension::CompleteDimension> Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::total_width::<_> |
1041 | | |
1042 | 0 | fn total_height<D>(cfg: &SpannedConfig, dimension: &D, count_rows: usize) -> usize |
1043 | 0 | where |
1044 | 0 | D: Dimension, |
1045 | | { |
1046 | 0 | (0..count_rows) |
1047 | 0 | .map(|i| dimension.get_height(i)) Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::total_height::<&&papergrid::dimension::peekable::PeekableGridDimension>::{closure#0}Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::total_height::<&&tabled::grid::dimension::complete_dimension::CompleteDimension>::{closure#0}Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::total_height::<_>::{closure#0} |
1048 | 0 | .sum::<usize>() |
1049 | 0 | + cfg.count_horizontal(count_rows) |
1050 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::total_height::<&&papergrid::dimension::peekable::PeekableGridDimension> Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::total_height::<&&tabled::grid::dimension::complete_dimension::CompleteDimension> Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::total_height::<_> |
1051 | | |
1052 | 0 | fn print_margin_top<F>(f: &mut F, cfg: &SpannedConfig, width: usize) -> fmt::Result |
1053 | 0 | where |
1054 | 0 | F: Write, |
1055 | | { |
1056 | 0 | let indent = cfg.get_margin().top; |
1057 | 0 | let offset = cfg.get_margin_offset().top; |
1058 | 0 | let color = cfg.get_margin_color(); |
1059 | 0 | let color = color.top; |
1060 | 0 | print_indent_lines(f, indent, offset, color, width) |
1061 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_margin_top::<&mut core::fmt::Formatter> Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_margin_top::<_> |
1062 | | |
1063 | 0 | fn print_margin_bottom<F>(f: &mut F, cfg: &SpannedConfig, width: usize) -> fmt::Result |
1064 | 0 | where |
1065 | 0 | F: Write, |
1066 | | { |
1067 | 0 | let indent = cfg.get_margin().bottom; |
1068 | 0 | let offset = cfg.get_margin_offset().bottom; |
1069 | 0 | let color = cfg.get_margin_color(); |
1070 | 0 | let color = color.bottom; |
1071 | 0 | print_indent_lines(f, indent, offset, color, width) |
1072 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_margin_bottom::<&mut core::fmt::Formatter> Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_margin_bottom::<_> |
1073 | | |
1074 | 0 | fn print_margin_left<F>( |
1075 | 0 | f: &mut F, |
1076 | 0 | cfg: &SpannedConfig, |
1077 | 0 | line: usize, |
1078 | 0 | height: usize, |
1079 | 0 | ) -> fmt::Result |
1080 | 0 | where |
1081 | 0 | F: Write, |
1082 | | { |
1083 | 0 | let indent = cfg.get_margin().left; |
1084 | 0 | let offset = cfg.get_margin_offset().left; |
1085 | 0 | let color = cfg.get_margin_color(); |
1086 | 0 | let color = color.left; |
1087 | 0 | print_margin_vertical(f, indent, offset, color, line, height) |
1088 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_margin_left::<&mut core::fmt::Formatter> Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_margin_left::<_> |
1089 | | |
1090 | 0 | fn print_margin_right<F>( |
1091 | 0 | f: &mut F, |
1092 | 0 | cfg: &SpannedConfig, |
1093 | 0 | line: usize, |
1094 | 0 | height: usize, |
1095 | 0 | ) -> fmt::Result |
1096 | 0 | where |
1097 | 0 | F: Write, |
1098 | | { |
1099 | 0 | let indent = cfg.get_margin().right; |
1100 | 0 | let offset = cfg.get_margin_offset().right; |
1101 | 0 | let color = cfg.get_margin_color(); |
1102 | 0 | let color = color.right; |
1103 | 0 | print_margin_vertical(f, indent, offset, color, line, height) |
1104 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_margin_right::<&mut core::fmt::Formatter> Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_margin_right::<_> |
1105 | | |
1106 | 0 | fn print_margin_vertical<F>( |
1107 | 0 | f: &mut F, |
1108 | 0 | indent: Indent, |
1109 | 0 | offset: Offset, |
1110 | 0 | color: Option<&ANSIBuf>, |
1111 | 0 | line: usize, |
1112 | 0 | height: usize, |
1113 | 0 | ) -> fmt::Result |
1114 | 0 | where |
1115 | 0 | F: Write, |
1116 | | { |
1117 | 0 | if indent.size == 0 { |
1118 | 0 | return Ok(()); |
1119 | 0 | } |
1120 | | |
1121 | 0 | match offset { |
1122 | 0 | Offset::Start(offset) => { |
1123 | 0 | let offset = cmp::min(offset, height); |
1124 | 0 | if line >= offset { |
1125 | 0 | print_indent(f, indent.fill, indent.size, color)?; |
1126 | | } else { |
1127 | 0 | repeat_char(f, ' ', indent.size)?; |
1128 | | } |
1129 | | } |
1130 | 0 | Offset::End(offset) => { |
1131 | 0 | let offset = cmp::min(offset, height); |
1132 | 0 | let pos = height - offset; |
1133 | | |
1134 | 0 | if line >= pos { |
1135 | 0 | repeat_char(f, ' ', indent.size)?; |
1136 | | } else { |
1137 | 0 | print_indent(f, indent.fill, indent.size, color)?; |
1138 | | } |
1139 | | } |
1140 | | } |
1141 | | |
1142 | 0 | Ok(()) |
1143 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_margin_vertical::<&mut core::fmt::Formatter> Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_margin_vertical::<_> |
1144 | | |
1145 | 0 | fn print_indent_lines<F>( |
1146 | 0 | f: &mut F, |
1147 | 0 | indent: Indent, |
1148 | 0 | offset: Offset, |
1149 | 0 | color: Option<&ANSIBuf>, |
1150 | 0 | width: usize, |
1151 | 0 | ) -> fmt::Result |
1152 | 0 | where |
1153 | 0 | F: Write, |
1154 | | { |
1155 | 0 | if indent.size == 0 { |
1156 | 0 | return Ok(()); |
1157 | 0 | } |
1158 | | |
1159 | 0 | let (start_offset, end_offset) = match offset { |
1160 | 0 | Offset::Start(start) => (start, 0), |
1161 | 0 | Offset::End(end) => (0, end), |
1162 | | }; |
1163 | | |
1164 | 0 | let start_offset = std::cmp::min(start_offset, width); |
1165 | 0 | let end_offset = std::cmp::min(end_offset, width); |
1166 | 0 | let indent_size = width - start_offset - end_offset; |
1167 | | |
1168 | 0 | for i in 0..indent.size { |
1169 | 0 | if start_offset > 0 { |
1170 | 0 | repeat_char(f, ' ', start_offset)?; |
1171 | 0 | } |
1172 | | |
1173 | 0 | if indent_size > 0 { |
1174 | 0 | print_indent(f, indent.fill, indent_size, color)?; |
1175 | 0 | } |
1176 | | |
1177 | 0 | if end_offset > 0 { |
1178 | 0 | repeat_char(f, ' ', end_offset)?; |
1179 | 0 | } |
1180 | | |
1181 | 0 | if i + 1 != indent.size { |
1182 | 0 | f.write_char('\n')?; |
1183 | 0 | } |
1184 | | } |
1185 | | |
1186 | 0 | Ok(()) |
1187 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_indent_lines::<&mut core::fmt::Formatter> Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_indent_lines::<_> |
1188 | | |
1189 | 0 | fn print_indent<F, C>(f: &mut F, c: char, n: usize, color: Option<C>) -> fmt::Result |
1190 | 0 | where |
1191 | 0 | F: Write, |
1192 | 0 | C: ANSIFmt, |
1193 | | { |
1194 | 0 | if n == 0 { |
1195 | 0 | return Ok(()); |
1196 | 0 | } |
1197 | | |
1198 | 0 | match color { |
1199 | 0 | Some(color) => { |
1200 | 0 | color.fmt_ansi_prefix(f)?; |
1201 | 0 | repeat_char(f, c, n)?; |
1202 | 0 | color.fmt_ansi_suffix(f) |
1203 | | } |
1204 | 0 | None => repeat_char(f, c, n), |
1205 | | } |
1206 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_indent::<&mut core::fmt::Formatter, &papergrid::ansi::ansi_buf::ANSIBuf> Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_indent::<_, _> |
1207 | | |
1208 | 0 | fn print_indent2<F, C>(f: &mut F, c: &Colored<char, C>, n: usize) -> fmt::Result |
1209 | 0 | where |
1210 | 0 | F: Write, |
1211 | 0 | C: ANSIFmt, |
1212 | | { |
1213 | 0 | if n == 0 { |
1214 | 0 | return Ok(()); |
1215 | 0 | } |
1216 | | |
1217 | 0 | match &c.color { |
1218 | 0 | Some(color) => { |
1219 | 0 | color.fmt_ansi_prefix(f)?; |
1220 | 0 | repeat_char(f, c.data, n)?; |
1221 | 0 | color.fmt_ansi_suffix(f) |
1222 | | } |
1223 | 0 | None => repeat_char(f, c.data, n), |
1224 | | } |
1225 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_indent2::<&mut core::fmt::Formatter, &papergrid::ansi::ansi_buf::ANSIBuf> Unexecuted instantiation: papergrid::grid::peekable::grid_not_spanned::print_indent2::<_, _> |
1226 | | |
1227 | | /// Trims a string. |
1228 | 0 | fn string_trim(text: &str) -> Cow<'_, str> { |
1229 | | #[cfg(feature = "ansi")] |
1230 | | { |
1231 | | ansi_str::AnsiStr::ansi_trim(text) |
1232 | | } |
1233 | | |
1234 | | #[cfg(not(feature = "ansi"))] |
1235 | | { |
1236 | 0 | text.trim().into() |
1237 | | } |
1238 | 0 | } |
1239 | | } |
1240 | | |
1241 | | mod grid_spanned { |
1242 | | use super::*; |
1243 | | |
1244 | | struct TextCfg<C, C1> { |
1245 | | alignment: AlignmentHorizontal, |
1246 | | formatting: Formatting, |
1247 | | color: Option<C>, |
1248 | | justification: Colored<char, C1>, |
1249 | | } |
1250 | | |
1251 | | struct Colored<T, C> { |
1252 | | data: T, |
1253 | | color: Option<C>, |
1254 | | } |
1255 | | |
1256 | | impl<T, C> Colored<T, C> { |
1257 | 0 | fn new(data: T, color: Option<C>) -> Self { |
1258 | 0 | Self { data, color } |
1259 | 0 | } Unexecuted instantiation: <papergrid::grid::peekable::grid_spanned::Colored<&str, &papergrid::ansi::ansi_buf::ANSIBuf>>::new Unexecuted instantiation: <papergrid::grid::peekable::grid_spanned::Colored<&str, &papergrid::colors::nocolors::NoColor>>::new Unexecuted instantiation: <papergrid::grid::peekable::grid_spanned::Colored<&str, &&papergrid::ansi::ansi_buf::ANSIBuf>>::new Unexecuted instantiation: <papergrid::grid::peekable::grid_spanned::Colored<&str, &&papergrid::colors::nocolors::NoColor>>::new Unexecuted instantiation: <papergrid::grid::peekable::grid_spanned::Colored<char, &papergrid::ansi::ansi_buf::ANSIBuf>>::new Unexecuted instantiation: <papergrid::grid::peekable::grid_spanned::Colored<_, _>>::new |
1260 | | } |
1261 | | |
1262 | | #[derive(Debug, Copy, Clone)] |
1263 | | struct Shape { |
1264 | | count_rows: usize, |
1265 | | count_columns: usize, |
1266 | | } |
1267 | | |
1268 | | struct HIndent { |
1269 | | left: usize, |
1270 | | right: usize, |
1271 | | } |
1272 | | |
1273 | 0 | pub(super) fn build_grid<F, R, D, C>(f: &mut F, ctx: PrintCtx<'_, R, D, C>) -> fmt::Result |
1274 | 0 | where |
1275 | 0 | F: Write, |
1276 | 0 | R: Records + PeekableRecords + ExactRecords, |
1277 | 0 | D: Dimension, |
1278 | 0 | C: Colors, |
1279 | | { |
1280 | 0 | let shape = Shape { |
1281 | 0 | count_rows: ctx.records.count_rows(), |
1282 | 0 | count_columns: ctx.records.count_columns(), |
1283 | 0 | }; |
1284 | | |
1285 | 0 | let total_width = total_width(ctx.cfg, ctx.dims, shape.count_columns); |
1286 | | |
1287 | 0 | let margin = ctx.cfg.get_margin(); |
1288 | 0 | let total_width_with_margin = total_width + margin.left.size + margin.right.size; |
1289 | | |
1290 | 0 | let total_height = total_height(ctx.cfg, ctx.dims, shape.count_rows); |
1291 | | |
1292 | 0 | if margin.top.size > 0 { |
1293 | 0 | print_margin_top(f, ctx.cfg, total_width_with_margin)?; |
1294 | 0 | f.write_char('\n')?; |
1295 | 0 | } |
1296 | | |
1297 | 0 | let mut table_line = 0; |
1298 | 0 | let mut prev_empty_horizontal = false; |
1299 | 0 | for row in 0..shape.count_rows { |
1300 | 0 | let count_lines = ctx.dims.get_height(row); |
1301 | | |
1302 | 0 | if ctx.cfg.has_horizontal(row, shape.count_rows) { |
1303 | 0 | if prev_empty_horizontal { |
1304 | 0 | f.write_char('\n')?; |
1305 | 0 | } |
1306 | | |
1307 | 0 | print_margin_left(f, ctx.cfg, table_line, total_height)?; |
1308 | 0 | print_split_line_spanned(f, &ctx, row, shape)?; |
1309 | 0 | print_margin_right(f, ctx.cfg, table_line, total_height)?; |
1310 | | |
1311 | 0 | if count_lines > 0 { |
1312 | 0 | f.write_char('\n')?; |
1313 | 0 | prev_empty_horizontal = false; |
1314 | 0 | } else { |
1315 | 0 | prev_empty_horizontal = true; |
1316 | 0 | } |
1317 | | |
1318 | 0 | table_line += 1; |
1319 | 0 | } else if count_lines > 0 && prev_empty_horizontal { |
1320 | 0 | f.write_char('\n')?; |
1321 | 0 | prev_empty_horizontal = false; |
1322 | 0 | } |
1323 | | |
1324 | 0 | for i in 0..count_lines { |
1325 | 0 | print_margin_left(f, ctx.cfg, table_line, total_height)?; |
1326 | | |
1327 | 0 | for col in 0..shape.count_columns { |
1328 | 0 | let pos = (row, col).into(); |
1329 | | |
1330 | 0 | if ctx.cfg.is_cell_covered_by_both_spans(pos) { |
1331 | 0 | continue; |
1332 | 0 | } |
1333 | | |
1334 | 0 | if ctx.cfg.is_cell_covered_by_column_span(pos) { |
1335 | 0 | let is_last_column = col + 1 == shape.count_columns; |
1336 | 0 | if is_last_column { |
1337 | 0 | let pos = (row, col + 1).into(); |
1338 | 0 | let count_columns = shape.count_columns; |
1339 | 0 | print_vertical_char(f, ctx.cfg, pos, i, count_lines, count_columns)?; |
1340 | 0 | } |
1341 | | |
1342 | 0 | continue; |
1343 | 0 | } |
1344 | | |
1345 | 0 | print_vertical_char(f, ctx.cfg, pos, i, count_lines, shape.count_columns)?; |
1346 | | |
1347 | 0 | if ctx.cfg.is_cell_covered_by_row_span(pos) { |
1348 | | // means it's part of other a spanned cell |
1349 | | // so. we just need to use line from other cell. |
1350 | 0 | let original_row = closest_visible_row(ctx.cfg, pos).unwrap(); |
1351 | | |
1352 | | // considering that the content will be printed instead horizontal lines so we can skip some lines. |
1353 | 0 | let mut skip_lines = (original_row..row) |
1354 | 0 | .map(|i| ctx.dims.get_height(i)) Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::build_grid::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&papergrid::dimension::peekable::PeekableGridDimension, papergrid::colors::nocolors::NoColors>::{closure#0}Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::build_grid::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&papergrid::dimension::peekable::PeekableGridDimension, &tabled::grid::config::colored_config::ColorMap>::{closure#0}Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::build_grid::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&tabled::grid::dimension::complete_dimension::CompleteDimension, papergrid::colors::nocolors::NoColors>::{closure#0}Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::build_grid::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&tabled::grid::dimension::complete_dimension::CompleteDimension, &tabled::grid::config::colored_config::ColorMap>::{closure#0}Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::build_grid::<_, _, _, _>::{closure#0} |
1355 | 0 | .sum::<usize>(); |
1356 | | |
1357 | 0 | skip_lines += (original_row + 1..=row) |
1358 | 0 | .map(|row| ctx.cfg.has_horizontal(row, shape.count_rows) as usize) Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::build_grid::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&papergrid::dimension::peekable::PeekableGridDimension, papergrid::colors::nocolors::NoColors>::{closure#1}Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::build_grid::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&papergrid::dimension::peekable::PeekableGridDimension, &tabled::grid::config::colored_config::ColorMap>::{closure#1}Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::build_grid::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&tabled::grid::dimension::complete_dimension::CompleteDimension, papergrid::colors::nocolors::NoColors>::{closure#1}Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::build_grid::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&tabled::grid::dimension::complete_dimension::CompleteDimension, &tabled::grid::config::colored_config::ColorMap>::{closure#1}Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::build_grid::<_, _, _, _>::{closure#1} |
1359 | 0 | .sum::<usize>(); |
1360 | | |
1361 | 0 | let line = i + skip_lines; |
1362 | 0 | let pos = (original_row, col).into(); |
1363 | | |
1364 | 0 | let width = get_cell_width(ctx.cfg, ctx.dims, pos, shape.count_columns); |
1365 | 0 | let height = get_cell_height(ctx.cfg, ctx.dims, pos, shape.count_rows); |
1366 | | |
1367 | 0 | print_cell_line(f, &ctx, width, height, pos, line)?; |
1368 | | } else { |
1369 | 0 | let width = get_cell_width(ctx.cfg, ctx.dims, pos, shape.count_columns); |
1370 | 0 | let height = get_cell_height(ctx.cfg, ctx.dims, pos, shape.count_rows); |
1371 | 0 | print_cell_line(f, &ctx, width, height, pos, i)?; |
1372 | | } |
1373 | | |
1374 | 0 | let is_last_column = col + 1 == shape.count_columns; |
1375 | 0 | if is_last_column { |
1376 | 0 | let pos = (row, col + 1).into(); |
1377 | 0 | print_vertical_char(f, ctx.cfg, pos, i, count_lines, shape.count_columns)?; |
1378 | 0 | } |
1379 | | } |
1380 | | |
1381 | 0 | print_margin_right(f, ctx.cfg, table_line, total_height)?; |
1382 | | |
1383 | 0 | let is_last_line = i + 1 == count_lines; |
1384 | 0 | let is_last_row = row + 1 == shape.count_rows; |
1385 | 0 | if !(is_last_line && is_last_row) { |
1386 | 0 | f.write_char('\n')?; |
1387 | 0 | } |
1388 | | |
1389 | 0 | table_line += 1; |
1390 | | } |
1391 | | } |
1392 | | |
1393 | 0 | if ctx.cfg.has_horizontal(shape.count_rows, shape.count_rows) { |
1394 | 0 | f.write_char('\n')?; |
1395 | 0 | print_margin_left(f, ctx.cfg, table_line, total_height)?; |
1396 | 0 | print_split_line(f, ctx.cfg, ctx.dims, shape.count_rows, shape)?; |
1397 | 0 | print_margin_right(f, ctx.cfg, table_line, total_height)?; |
1398 | 0 | } |
1399 | | |
1400 | 0 | if margin.bottom.size > 0 { |
1401 | 0 | f.write_char('\n')?; |
1402 | 0 | print_margin_bottom(f, ctx.cfg, total_width_with_margin)?; |
1403 | 0 | } |
1404 | | |
1405 | 0 | Ok(()) |
1406 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::build_grid::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&papergrid::dimension::peekable::PeekableGridDimension, papergrid::colors::nocolors::NoColors> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::build_grid::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&papergrid::dimension::peekable::PeekableGridDimension, &tabled::grid::config::colored_config::ColorMap> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::build_grid::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&tabled::grid::dimension::complete_dimension::CompleteDimension, papergrid::colors::nocolors::NoColors> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::build_grid::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&tabled::grid::dimension::complete_dimension::CompleteDimension, &tabled::grid::config::colored_config::ColorMap> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::build_grid::<_, _, _, _> |
1407 | | |
1408 | 0 | fn print_split_line_spanned<F, R, D, C>( |
1409 | 0 | f: &mut F, |
1410 | 0 | ctx: &PrintCtx<'_, R, D, C>, |
1411 | 0 | row: usize, |
1412 | 0 | shape: Shape, |
1413 | 0 | ) -> fmt::Result |
1414 | 0 | where |
1415 | 0 | F: Write, |
1416 | 0 | R: Records + ExactRecords + PeekableRecords, |
1417 | 0 | D: Dimension, |
1418 | 0 | C: Colors, |
1419 | | { |
1420 | 0 | let mut used_color = None; |
1421 | | |
1422 | 0 | let pos = (row, 0).into(); |
1423 | 0 | print_vertical_intersection(f, ctx.cfg, pos, shape, &mut used_color)?; |
1424 | | |
1425 | 0 | for col in 0..shape.count_columns { |
1426 | 0 | let pos = (row, col).into(); |
1427 | 0 | if ctx.cfg.is_cell_covered_by_both_spans(pos) { |
1428 | 0 | continue; |
1429 | 0 | } |
1430 | | |
1431 | 0 | if ctx.cfg.is_cell_covered_by_row_span(pos) { |
1432 | | // means it's part of other a spanned cell |
1433 | | // so. we just need to use line from other cell. |
1434 | | |
1435 | 0 | prepare_coloring(f, None, &mut used_color)?; |
1436 | | |
1437 | 0 | let original_row = closest_visible_row(ctx.cfg, pos).unwrap(); |
1438 | | |
1439 | | // considering that the content will be printed instead horizontal lines so we can skip some lines. |
1440 | 0 | let mut skip_lines = (original_row..row) |
1441 | 0 | .map(|i| ctx.dims.get_height(i)) Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_split_line_spanned::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&papergrid::dimension::peekable::PeekableGridDimension, papergrid::colors::nocolors::NoColors>::{closure#0}Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_split_line_spanned::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&papergrid::dimension::peekable::PeekableGridDimension, &tabled::grid::config::colored_config::ColorMap>::{closure#0}Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_split_line_spanned::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&tabled::grid::dimension::complete_dimension::CompleteDimension, papergrid::colors::nocolors::NoColors>::{closure#0}Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_split_line_spanned::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&tabled::grid::dimension::complete_dimension::CompleteDimension, &tabled::grid::config::colored_config::ColorMap>::{closure#0}Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_split_line_spanned::<_, _, _, _>::{closure#0} |
1442 | 0 | .sum::<usize>(); |
1443 | | |
1444 | | // skip horizontal lines |
1445 | 0 | if row > 0 { |
1446 | 0 | skip_lines += (original_row..row - 1) |
1447 | 0 | .map(|row| ctx.cfg.has_horizontal(row + 1, shape.count_rows) as usize) Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_split_line_spanned::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&papergrid::dimension::peekable::PeekableGridDimension, papergrid::colors::nocolors::NoColors>::{closure#1}Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_split_line_spanned::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&papergrid::dimension::peekable::PeekableGridDimension, &tabled::grid::config::colored_config::ColorMap>::{closure#1}Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_split_line_spanned::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&tabled::grid::dimension::complete_dimension::CompleteDimension, papergrid::colors::nocolors::NoColors>::{closure#1}Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_split_line_spanned::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&tabled::grid::dimension::complete_dimension::CompleteDimension, &tabled::grid::config::colored_config::ColorMap>::{closure#1}Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_split_line_spanned::<_, _, _, _>::{closure#1} |
1448 | 0 | .sum::<usize>(); |
1449 | 0 | } |
1450 | | |
1451 | 0 | let pos = (original_row, col).into(); |
1452 | 0 | let height = get_cell_height(ctx.cfg, ctx.dims, pos, shape.count_rows); |
1453 | 0 | let width = get_cell_width(ctx.cfg, ctx.dims, pos, shape.count_columns); |
1454 | 0 | let line = skip_lines; |
1455 | | |
1456 | 0 | print_cell_line(f, ctx, width, height, pos, line)?; |
1457 | | |
1458 | | // We need to use a correct right split char. |
1459 | 0 | let mut col = col; |
1460 | 0 | if let Some(span) = ctx.cfg.get_column_span(pos) { |
1461 | 0 | col += span - 1; |
1462 | 0 | } |
1463 | | |
1464 | 0 | let pos = (row, col + 1).into(); |
1465 | 0 | print_vertical_intersection(f, ctx.cfg, pos, shape, &mut used_color)?; |
1466 | | |
1467 | 0 | continue; |
1468 | 0 | } |
1469 | | |
1470 | 0 | let width = ctx.dims.get_width(col); |
1471 | 0 | if width > 0 { |
1472 | | // general case |
1473 | 0 | let main = ctx.cfg.get_horizontal(pos, shape.count_rows); |
1474 | 0 | match main { |
1475 | 0 | Some(c) => { |
1476 | 0 | let clr = ctx.cfg.get_horizontal_color(pos, shape.count_rows); |
1477 | 0 | prepare_coloring(f, clr, &mut used_color)?; |
1478 | 0 | print_horizontal_border(f, ctx.cfg, pos, width, c, &used_color)?; |
1479 | | } |
1480 | 0 | None => repeat_char(f, ' ', width)?, |
1481 | | } |
1482 | 0 | } |
1483 | | |
1484 | 0 | let pos = (row, col + 1).into(); |
1485 | 0 | print_vertical_intersection(f, ctx.cfg, pos, shape, &mut used_color)?; |
1486 | | } |
1487 | | |
1488 | 0 | if let Some(clr) = used_color { |
1489 | 0 | clr.fmt_ansi_suffix(f)?; |
1490 | 0 | } |
1491 | | |
1492 | 0 | Ok(()) |
1493 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_split_line_spanned::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&papergrid::dimension::peekable::PeekableGridDimension, papergrid::colors::nocolors::NoColors> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_split_line_spanned::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&papergrid::dimension::peekable::PeekableGridDimension, &tabled::grid::config::colored_config::ColorMap> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_split_line_spanned::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&tabled::grid::dimension::complete_dimension::CompleteDimension, papergrid::colors::nocolors::NoColors> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_split_line_spanned::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&tabled::grid::dimension::complete_dimension::CompleteDimension, &tabled::grid::config::colored_config::ColorMap> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_split_line_spanned::<_, _, _, _> |
1494 | | |
1495 | 0 | fn print_vertical_char<F>( |
1496 | 0 | f: &mut F, |
1497 | 0 | cfg: &SpannedConfig, |
1498 | 0 | pos: Position, |
1499 | 0 | line: usize, |
1500 | 0 | count_lines: usize, |
1501 | 0 | count_columns: usize, |
1502 | 0 | ) -> fmt::Result |
1503 | 0 | where |
1504 | 0 | F: Write, |
1505 | | { |
1506 | 0 | let symbol = match cfg.get_vertical(pos, count_columns) { |
1507 | 0 | Some(c) => c, |
1508 | 0 | None => return Ok(()), |
1509 | | }; |
1510 | | |
1511 | 0 | let symbol = cfg |
1512 | 0 | .lookup_vertical_char(pos, line, count_lines) |
1513 | 0 | .unwrap_or(symbol); |
1514 | | |
1515 | 0 | let color = cfg |
1516 | 0 | .get_vertical_color(pos, count_columns) |
1517 | 0 | .or_else(|| cfg.lookup_vertical_color(pos, line, count_lines)); Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_vertical_char::<&mut core::fmt::Formatter>::{closure#0}Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_vertical_char::<_>::{closure#0} |
1518 | | |
1519 | 0 | match color { |
1520 | 0 | Some(clr) => { |
1521 | 0 | clr.fmt_ansi_prefix(f)?; |
1522 | 0 | f.write_char(symbol)?; |
1523 | 0 | clr.fmt_ansi_suffix(f)?; |
1524 | | } |
1525 | 0 | None => f.write_char(symbol)?, |
1526 | | } |
1527 | | |
1528 | 0 | Ok(()) |
1529 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_vertical_char::<&mut core::fmt::Formatter> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_vertical_char::<_> |
1530 | | |
1531 | 0 | fn print_vertical_intersection<'a, F>( |
1532 | 0 | f: &mut F, |
1533 | 0 | cfg: &'a SpannedConfig, |
1534 | 0 | pos: Position, |
1535 | 0 | shape: Shape, |
1536 | 0 | used_color: &mut Option<&'a ANSIBuf>, |
1537 | 0 | ) -> fmt::Result |
1538 | 0 | where |
1539 | 0 | F: fmt::Write, |
1540 | | { |
1541 | 0 | let intersection = match cfg.get_intersection(pos, (shape.count_rows, shape.count_columns)) |
1542 | | { |
1543 | 0 | Some(c) => c, |
1544 | 0 | None => return Ok(()), |
1545 | | }; |
1546 | | |
1547 | | // We need to make sure that we need to print it. |
1548 | | // Specifically for cases where we have a limited amount of verticals. |
1549 | | // |
1550 | | // todo: Yes... this check very likely degrages performance a bit, |
1551 | | // Surely we need to rethink it. |
1552 | 0 | if !cfg.has_vertical(pos.col, shape.count_columns) { |
1553 | 0 | return Ok(()); |
1554 | 0 | } |
1555 | | |
1556 | 0 | let color = cfg.get_intersection_color(pos, (shape.count_rows, shape.count_columns)); |
1557 | 0 | prepare_coloring(f, color, used_color)?; |
1558 | 0 | f.write_char(intersection)?; |
1559 | | |
1560 | 0 | Ok(()) |
1561 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_vertical_intersection::<&mut core::fmt::Formatter> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_vertical_intersection::<_> |
1562 | | |
1563 | 0 | fn prepare_coloring<'a, F>( |
1564 | 0 | f: &mut F, |
1565 | 0 | clr: Option<&'a ANSIBuf>, |
1566 | 0 | used_color: &mut Option<&'a ANSIBuf>, |
1567 | 0 | ) -> fmt::Result |
1568 | 0 | where |
1569 | 0 | F: Write, |
1570 | | { |
1571 | 0 | match clr { |
1572 | 0 | Some(clr) => match used_color.as_mut() { |
1573 | 0 | Some(used_clr) => { |
1574 | 0 | if **used_clr != *clr { |
1575 | 0 | used_clr.fmt_ansi_suffix(f)?; |
1576 | 0 | clr.fmt_ansi_prefix(f)?; |
1577 | 0 | *used_clr = clr; |
1578 | 0 | } |
1579 | | } |
1580 | | None => { |
1581 | 0 | clr.fmt_ansi_prefix(f)?; |
1582 | 0 | *used_color = Some(clr); |
1583 | | } |
1584 | | }, |
1585 | | None => { |
1586 | 0 | if let Some(clr) = used_color.take() { |
1587 | 0 | clr.fmt_ansi_suffix(f)? |
1588 | 0 | } |
1589 | | } |
1590 | | } |
1591 | | |
1592 | 0 | Ok(()) |
1593 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::prepare_coloring::<&mut core::fmt::Formatter> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::prepare_coloring::<_> |
1594 | | |
1595 | 0 | fn print_split_line<F, D>( |
1596 | 0 | f: &mut F, |
1597 | 0 | cfg: &SpannedConfig, |
1598 | 0 | dimension: &D, |
1599 | 0 | row: usize, |
1600 | 0 | shape: Shape, |
1601 | 0 | ) -> fmt::Result |
1602 | 0 | where |
1603 | 0 | F: Write, |
1604 | 0 | D: Dimension, |
1605 | | { |
1606 | 0 | let mut used_color = None; |
1607 | 0 | print_vertical_intersection(f, cfg, (row, 0).into(), shape, &mut used_color)?; |
1608 | | |
1609 | 0 | for col in 0..shape.count_columns { |
1610 | 0 | let width = dimension.get_width(col); |
1611 | | |
1612 | | // general case |
1613 | 0 | if width > 0 { |
1614 | 0 | let pos = (row, col).into(); |
1615 | 0 | let main = cfg.get_horizontal(pos, shape.count_rows); |
1616 | 0 | match main { |
1617 | 0 | Some(c) => { |
1618 | 0 | let clr = cfg.get_horizontal_color(pos, shape.count_rows); |
1619 | 0 | prepare_coloring(f, clr, &mut used_color)?; |
1620 | 0 | print_horizontal_border(f, cfg, pos, width, c, &used_color)?; |
1621 | | } |
1622 | 0 | None => repeat_char(f, ' ', width)?, |
1623 | | } |
1624 | 0 | } |
1625 | | |
1626 | 0 | let pos = (row, col + 1).into(); |
1627 | 0 | print_vertical_intersection(f, cfg, pos, shape, &mut used_color)?; |
1628 | | } |
1629 | | |
1630 | 0 | if let Some(clr) = used_color.take() { |
1631 | 0 | clr.fmt_ansi_suffix(f)?; |
1632 | 0 | } |
1633 | | |
1634 | 0 | Ok(()) |
1635 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_split_line::<&mut core::fmt::Formatter, &&papergrid::dimension::peekable::PeekableGridDimension> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_split_line::<&mut core::fmt::Formatter, &&tabled::grid::dimension::complete_dimension::CompleteDimension> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_split_line::<_, _> |
1636 | | |
1637 | 0 | fn print_horizontal_border<F>( |
1638 | 0 | f: &mut F, |
1639 | 0 | cfg: &SpannedConfig, |
1640 | 0 | pos: Position, |
1641 | 0 | width: usize, |
1642 | 0 | c: char, |
1643 | 0 | used_color: &Option<&ANSIBuf>, |
1644 | 0 | ) -> fmt::Result |
1645 | 0 | where |
1646 | 0 | F: Write, |
1647 | | { |
1648 | 0 | if !cfg.is_overridden_horizontal(pos) { |
1649 | 0 | return repeat_char(f, c, width); |
1650 | 0 | } |
1651 | | |
1652 | 0 | for i in 0..width { |
1653 | 0 | let c = cfg.lookup_horizontal_char(pos, i, width).unwrap_or(c); |
1654 | 0 | match cfg.lookup_horizontal_color(pos, i, width) { |
1655 | 0 | Some(color) => match used_color { |
1656 | 0 | Some(clr) => { |
1657 | 0 | clr.fmt_ansi_suffix(f)?; |
1658 | 0 | color.fmt_ansi_prefix(f)?; |
1659 | 0 | f.write_char(c)?; |
1660 | 0 | color.fmt_ansi_suffix(f)?; |
1661 | 0 | clr.fmt_ansi_prefix(f)?; |
1662 | | } |
1663 | | None => { |
1664 | 0 | color.fmt_ansi_prefix(f)?; |
1665 | 0 | f.write_char(c)?; |
1666 | 0 | color.fmt_ansi_suffix(f)?; |
1667 | | } |
1668 | | }, |
1669 | 0 | _ => f.write_char(c)?, |
1670 | | } |
1671 | | } |
1672 | | |
1673 | 0 | Ok(()) |
1674 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_horizontal_border::<&mut core::fmt::Formatter> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_horizontal_border::<_> |
1675 | | |
1676 | 0 | fn print_cell_line<F, R, D, C>( |
1677 | 0 | f: &mut F, |
1678 | 0 | ctx: &PrintCtx<'_, R, D, C>, |
1679 | 0 | width: usize, |
1680 | 0 | height: usize, |
1681 | 0 | pos: Position, |
1682 | 0 | line: usize, |
1683 | 0 | ) -> fmt::Result |
1684 | 0 | where |
1685 | 0 | F: Write, |
1686 | 0 | R: Records + PeekableRecords + ExactRecords, |
1687 | 0 | C: Colors, |
1688 | | { |
1689 | 0 | let mut cell_height = ctx.records.count_lines(pos); |
1690 | 0 | let formatting = ctx.cfg.get_formatting(pos); |
1691 | 0 | if formatting.vertical_trim { |
1692 | 0 | cell_height -= count_empty_lines_at_start(ctx.records, pos) |
1693 | 0 | + count_empty_lines_at_end(ctx.records, pos); |
1694 | 0 | } |
1695 | | |
1696 | 0 | if cell_height > height { |
1697 | 0 | // it may happen if the height estimation decide so |
1698 | 0 | cell_height = height; |
1699 | 0 | } |
1700 | | |
1701 | 0 | let pad = ctx.cfg.get_padding(pos); |
1702 | 0 | let pad_color = ctx.cfg.get_padding_color(pos); |
1703 | 0 | let alignment = ctx.cfg.get_alignment_vertical(pos); |
1704 | 0 | let indent = top_indent(pad, *alignment, cell_height, height); |
1705 | 0 | if indent > line { |
1706 | 0 | return print_indent(f, pad.top.fill, width, pad_color.top.as_ref()); |
1707 | 0 | } |
1708 | | |
1709 | 0 | let mut index = line - indent; |
1710 | 0 | let cell_has_this_line = cell_height > index; |
1711 | 0 | if !cell_has_this_line { |
1712 | | // happens when other cells have bigger height |
1713 | 0 | return print_indent(f, pad.bottom.fill, width, pad_color.bottom.as_ref()); |
1714 | 0 | } |
1715 | | |
1716 | 0 | if formatting.vertical_trim { |
1717 | 0 | let empty_lines = count_empty_lines_at_start(ctx.records, pos); |
1718 | 0 | index += empty_lines; |
1719 | | |
1720 | 0 | if index > ctx.records.count_lines(pos) { |
1721 | 0 | return print_indent(f, pad.top.fill, width, pad_color.top.as_ref()); |
1722 | 0 | } |
1723 | 0 | } |
1724 | | |
1725 | 0 | print_indent(f, pad.left.fill, pad.left.size, pad_color.left.as_ref())?; |
1726 | | |
1727 | 0 | let width = width - pad.left.size - pad.right.size; |
1728 | | |
1729 | 0 | let line_cfg = TextCfg { |
1730 | 0 | alignment: *ctx.cfg.get_alignment_horizontal(pos), |
1731 | 0 | color: ctx.colors.get_color(pos), |
1732 | 0 | justification: Colored::new( |
1733 | 0 | ctx.cfg.get_justification(pos), |
1734 | 0 | ctx.cfg.get_justification_color(pos), |
1735 | 0 | ), |
1736 | 0 | formatting, |
1737 | 0 | }; |
1738 | | |
1739 | 0 | print_line(f, ctx.records, pos, index, width, line_cfg)?; |
1740 | | |
1741 | 0 | print_indent(f, pad.right.fill, pad.right.size, pad_color.right.as_ref())?; |
1742 | | |
1743 | 0 | Ok(()) |
1744 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_cell_line::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&papergrid::dimension::peekable::PeekableGridDimension, papergrid::colors::nocolors::NoColors> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_cell_line::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&papergrid::dimension::peekable::PeekableGridDimension, &tabled::grid::config::colored_config::ColorMap> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_cell_line::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&tabled::grid::dimension::complete_dimension::CompleteDimension, papergrid::colors::nocolors::NoColors> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_cell_line::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &&tabled::grid::dimension::complete_dimension::CompleteDimension, &tabled::grid::config::colored_config::ColorMap> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_cell_line::<_, _, _, _> |
1745 | | |
1746 | 0 | fn print_line<F, R, C, C1>( |
1747 | 0 | f: &mut F, |
1748 | 0 | records: &R, |
1749 | 0 | pos: Position, |
1750 | 0 | index: usize, |
1751 | 0 | available: usize, |
1752 | 0 | text_cfg: TextCfg<C, C1>, |
1753 | 0 | ) -> fmt::Result |
1754 | 0 | where |
1755 | 0 | F: Write, |
1756 | 0 | R: Records + PeekableRecords, |
1757 | 0 | C: ANSIFmt, |
1758 | 0 | C1: ANSIFmt, |
1759 | | { |
1760 | 0 | let line = records.get_line(pos, index); |
1761 | 0 | let (line, line_width) = if text_cfg.formatting.horizontal_trim { |
1762 | 0 | let line = string_trim(line); |
1763 | 0 | let width = get_line_width(&line); |
1764 | 0 | (line, width) |
1765 | | } else { |
1766 | 0 | let width = records.get_line_width(pos, index); |
1767 | 0 | (Cow::Borrowed(line), width) |
1768 | | }; |
1769 | | |
1770 | 0 | if text_cfg.formatting.allow_lines_alignment { |
1771 | 0 | let indent = calculate_indent(text_cfg.alignment, line_width, available); |
1772 | 0 | let text = Colored::new(line.as_ref(), text_cfg.color); |
1773 | 0 | return print_text_with_pad(f, &text, &text_cfg.justification, indent); |
1774 | 0 | } |
1775 | | |
1776 | 0 | let cell_width = if text_cfg.formatting.horizontal_trim { |
1777 | 0 | (0..records.count_lines(pos)) |
1778 | 0 | .map(|i| records.get_line(pos, i)) Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_line::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &papergrid::ansi::ansi_buf::ANSIBuf, &papergrid::ansi::ansi_buf::ANSIBuf>::{closure#0}Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_line::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &papergrid::colors::nocolors::NoColor, &papergrid::ansi::ansi_buf::ANSIBuf>::{closure#0}Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_line::<_, _, _, _>::{closure#0} |
1779 | 0 | .map(|line| get_line_width(line.trim())) Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_line::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &papergrid::ansi::ansi_buf::ANSIBuf, &papergrid::ansi::ansi_buf::ANSIBuf>::{closure#1}Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_line::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &papergrid::colors::nocolors::NoColor, &papergrid::ansi::ansi_buf::ANSIBuf>::{closure#1}Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_line::<_, _, _, _>::{closure#1} |
1780 | 0 | .max() |
1781 | 0 | .unwrap_or_default() |
1782 | | } else { |
1783 | 0 | records.get_width(pos) |
1784 | | }; |
1785 | | |
1786 | 0 | let indent = calculate_indent(text_cfg.alignment, cell_width, available); |
1787 | 0 | let text = Colored::new(line.as_ref(), text_cfg.color.as_ref()); |
1788 | 0 | print_text_with_pad(f, &text, &text_cfg.justification, indent)?; |
1789 | | |
1790 | 0 | let rest_width = cell_width - line_width; |
1791 | 0 | print_indent( |
1792 | 0 | f, |
1793 | 0 | text_cfg.justification.data, |
1794 | 0 | rest_width, |
1795 | 0 | text_cfg.justification.color.as_ref(), |
1796 | 0 | )?; |
1797 | | |
1798 | 0 | Ok(()) |
1799 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_line::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &papergrid::ansi::ansi_buf::ANSIBuf, &papergrid::ansi::ansi_buf::ANSIBuf> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_line::<&mut core::fmt::Formatter, &papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>, &papergrid::colors::nocolors::NoColor, &papergrid::ansi::ansi_buf::ANSIBuf> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_line::<_, _, _, _> |
1800 | | |
1801 | 0 | fn print_text_with_pad<F, C, C1>( |
1802 | 0 | f: &mut F, |
1803 | 0 | text: &Colored<&str, C>, |
1804 | 0 | space: &Colored<char, C1>, |
1805 | 0 | indent: HIndent, |
1806 | 0 | ) -> fmt::Result |
1807 | 0 | where |
1808 | 0 | F: Write, |
1809 | 0 | C: ANSIFmt, |
1810 | 0 | C1: ANSIFmt, |
1811 | | { |
1812 | 0 | print_indent(f, space.data, indent.left, space.color.as_ref())?; |
1813 | 0 | print_text(f, text.data, text.color.as_ref())?; |
1814 | 0 | print_indent(f, space.data, indent.right, space.color.as_ref())?; |
1815 | 0 | Ok(()) |
1816 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_text_with_pad::<&mut core::fmt::Formatter, &papergrid::ansi::ansi_buf::ANSIBuf, &papergrid::ansi::ansi_buf::ANSIBuf> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_text_with_pad::<&mut core::fmt::Formatter, &papergrid::colors::nocolors::NoColor, &papergrid::ansi::ansi_buf::ANSIBuf> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_text_with_pad::<&mut core::fmt::Formatter, &&papergrid::ansi::ansi_buf::ANSIBuf, &papergrid::ansi::ansi_buf::ANSIBuf> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_text_with_pad::<&mut core::fmt::Formatter, &&papergrid::colors::nocolors::NoColor, &papergrid::ansi::ansi_buf::ANSIBuf> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_text_with_pad::<_, _, _> |
1817 | | |
1818 | 0 | fn print_text<F, C>(f: &mut F, text: &str, clr: Option<C>) -> fmt::Result |
1819 | 0 | where |
1820 | 0 | F: Write, |
1821 | 0 | C: ANSIFmt, |
1822 | | { |
1823 | 0 | match clr { |
1824 | 0 | Some(color) => { |
1825 | 0 | color.fmt_ansi_prefix(f)?; |
1826 | 0 | f.write_str(text)?; |
1827 | 0 | color.fmt_ansi_suffix(f) |
1828 | | } |
1829 | 0 | None => f.write_str(text), |
1830 | | } |
1831 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_text::<&mut core::fmt::Formatter, &&papergrid::ansi::ansi_buf::ANSIBuf> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_text::<&mut core::fmt::Formatter, &&papergrid::colors::nocolors::NoColor> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_text::<&mut core::fmt::Formatter, &&&papergrid::ansi::ansi_buf::ANSIBuf> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_text::<&mut core::fmt::Formatter, &&&papergrid::colors::nocolors::NoColor> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_text::<_, _> |
1832 | | |
1833 | 0 | fn top_indent( |
1834 | 0 | pad: &Sides<Indent>, |
1835 | 0 | alignment: AlignmentVertical, |
1836 | 0 | cell_height: usize, |
1837 | 0 | available: usize, |
1838 | 0 | ) -> usize { |
1839 | 0 | let height = available - pad.top.size; |
1840 | 0 | let indent = indent_from_top(alignment, height, cell_height); |
1841 | | |
1842 | 0 | indent + pad.top.size |
1843 | 0 | } |
1844 | | |
1845 | 0 | fn indent_from_top(alignment: AlignmentVertical, available: usize, real: usize) -> usize { |
1846 | 0 | match alignment { |
1847 | 0 | AlignmentVertical::Top => 0, |
1848 | 0 | AlignmentVertical::Bottom => available - real, |
1849 | 0 | AlignmentVertical::Center => (available - real) / 2, |
1850 | | } |
1851 | 0 | } |
1852 | | |
1853 | 0 | fn calculate_indent(alignment: AlignmentHorizontal, width: usize, available: usize) -> HIndent { |
1854 | 0 | let diff = available - width; |
1855 | | |
1856 | 0 | let (left, right) = match alignment { |
1857 | 0 | AlignmentHorizontal::Left => (0, diff), |
1858 | 0 | AlignmentHorizontal::Right => (diff, 0), |
1859 | | AlignmentHorizontal::Center => { |
1860 | 0 | let left = diff / 2; |
1861 | 0 | let rest = diff - left; |
1862 | 0 | (left, rest) |
1863 | | } |
1864 | | }; |
1865 | | |
1866 | 0 | HIndent { left, right } |
1867 | 0 | } |
1868 | | |
1869 | 0 | fn repeat_char<F>(f: &mut F, c: char, n: usize) -> fmt::Result |
1870 | 0 | where |
1871 | 0 | F: Write, |
1872 | | { |
1873 | 0 | for _ in 0..n { |
1874 | 0 | f.write_char(c)?; |
1875 | | } |
1876 | | |
1877 | 0 | Ok(()) |
1878 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::repeat_char::<&mut core::fmt::Formatter> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::repeat_char::<_> |
1879 | | |
1880 | 0 | fn count_empty_lines_at_end<R>(records: &R, pos: Position) -> usize |
1881 | 0 | where |
1882 | 0 | R: Records + PeekableRecords, |
1883 | | { |
1884 | 0 | (0..records.count_lines(pos)) |
1885 | 0 | .map(|i| records.get_line(pos, i)) Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::count_empty_lines_at_end::<&papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>>::{closure#0}Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::count_empty_lines_at_end::<_>::{closure#0} |
1886 | 0 | .rev() |
1887 | 0 | .take_while(|l| l.trim().is_empty()) Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::count_empty_lines_at_end::<&papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>>::{closure#1}Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::count_empty_lines_at_end::<_>::{closure#1} |
1888 | 0 | .count() |
1889 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::count_empty_lines_at_end::<&papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::count_empty_lines_at_end::<_> |
1890 | | |
1891 | 0 | fn count_empty_lines_at_start<R>(records: &R, pos: Position) -> usize |
1892 | 0 | where |
1893 | 0 | R: Records + PeekableRecords, |
1894 | | { |
1895 | 0 | (0..records.count_lines(pos)) |
1896 | 0 | .map(|i| records.get_line(pos, i)) Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::count_empty_lines_at_start::<&papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>>::{closure#0}Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::count_empty_lines_at_start::<_>::{closure#0} |
1897 | 0 | .take_while(|s| s.trim().is_empty()) Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::count_empty_lines_at_start::<&papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>>::{closure#1}Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::count_empty_lines_at_start::<_>::{closure#1} |
1898 | 0 | .count() |
1899 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::count_empty_lines_at_start::<&papergrid::records::vec_records::VecRecords<papergrid::records::vec_records::text::Text<alloc::string::String>>> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::count_empty_lines_at_start::<_> |
1900 | | |
1901 | 0 | fn total_width<D>(cfg: &SpannedConfig, dimension: &D, count_columns: usize) -> usize |
1902 | 0 | where |
1903 | 0 | D: Dimension, |
1904 | | { |
1905 | 0 | (0..count_columns) |
1906 | 0 | .map(|i| dimension.get_width(i)) Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::total_width::<&&papergrid::dimension::peekable::PeekableGridDimension>::{closure#0}Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::total_width::<&&tabled::grid::dimension::complete_dimension::CompleteDimension>::{closure#0}Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::total_width::<_>::{closure#0} |
1907 | 0 | .sum::<usize>() |
1908 | 0 | + cfg.count_vertical(count_columns) |
1909 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::total_width::<&&papergrid::dimension::peekable::PeekableGridDimension> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::total_width::<&&tabled::grid::dimension::complete_dimension::CompleteDimension> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::total_width::<_> |
1910 | | |
1911 | 0 | fn total_height<D>(cfg: &SpannedConfig, dimension: &D, count_rows: usize) -> usize |
1912 | 0 | where |
1913 | 0 | D: Dimension, |
1914 | | { |
1915 | 0 | (0..count_rows) |
1916 | 0 | .map(|i| dimension.get_height(i)) Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::total_height::<&&papergrid::dimension::peekable::PeekableGridDimension>::{closure#0}Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::total_height::<&&tabled::grid::dimension::complete_dimension::CompleteDimension>::{closure#0}Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::total_height::<_>::{closure#0} |
1917 | 0 | .sum::<usize>() |
1918 | 0 | + cfg.count_horizontal(count_rows) |
1919 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::total_height::<&&papergrid::dimension::peekable::PeekableGridDimension> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::total_height::<&&tabled::grid::dimension::complete_dimension::CompleteDimension> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::total_height::<_> |
1920 | | |
1921 | 0 | fn print_margin_top<F>(f: &mut F, cfg: &SpannedConfig, width: usize) -> fmt::Result |
1922 | 0 | where |
1923 | 0 | F: Write, |
1924 | | { |
1925 | 0 | let indent = cfg.get_margin().top; |
1926 | 0 | let offset = cfg.get_margin_offset().top; |
1927 | 0 | let color = cfg.get_margin_color(); |
1928 | 0 | let color = color.top; |
1929 | 0 | print_indent_lines(f, &indent, &offset, color, width) |
1930 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_margin_top::<&mut core::fmt::Formatter> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_margin_top::<_> |
1931 | | |
1932 | 0 | fn print_margin_bottom<F>(f: &mut F, cfg: &SpannedConfig, width: usize) -> fmt::Result |
1933 | 0 | where |
1934 | 0 | F: Write, |
1935 | | { |
1936 | 0 | let indent = cfg.get_margin().bottom; |
1937 | 0 | let offset = cfg.get_margin_offset().bottom; |
1938 | 0 | let color = cfg.get_margin_color(); |
1939 | 0 | let color = color.bottom; |
1940 | 0 | print_indent_lines(f, &indent, &offset, color, width) |
1941 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_margin_bottom::<&mut core::fmt::Formatter> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_margin_bottom::<_> |
1942 | | |
1943 | 0 | fn print_margin_left<F>( |
1944 | 0 | f: &mut F, |
1945 | 0 | cfg: &SpannedConfig, |
1946 | 0 | line: usize, |
1947 | 0 | height: usize, |
1948 | 0 | ) -> fmt::Result |
1949 | 0 | where |
1950 | 0 | F: Write, |
1951 | | { |
1952 | 0 | let indent = cfg.get_margin().left; |
1953 | 0 | let offset = cfg.get_margin_offset().left; |
1954 | 0 | let color = cfg.get_margin_color(); |
1955 | 0 | let color = color.left; |
1956 | 0 | print_margin_vertical(f, indent, offset, color, line, height) |
1957 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_margin_left::<&mut core::fmt::Formatter> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_margin_left::<_> |
1958 | | |
1959 | 0 | fn print_margin_right<F>( |
1960 | 0 | f: &mut F, |
1961 | 0 | cfg: &SpannedConfig, |
1962 | 0 | line: usize, |
1963 | 0 | height: usize, |
1964 | 0 | ) -> fmt::Result |
1965 | 0 | where |
1966 | 0 | F: Write, |
1967 | | { |
1968 | 0 | let indent = cfg.get_margin().right; |
1969 | 0 | let offset = cfg.get_margin_offset().right; |
1970 | 0 | let color = cfg.get_margin_color(); |
1971 | 0 | let color = color.right; |
1972 | 0 | print_margin_vertical(f, indent, offset, color, line, height) |
1973 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_margin_right::<&mut core::fmt::Formatter> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_margin_right::<_> |
1974 | | |
1975 | 0 | fn print_margin_vertical<F>( |
1976 | 0 | f: &mut F, |
1977 | 0 | indent: Indent, |
1978 | 0 | offset: Offset, |
1979 | 0 | color: Option<&ANSIBuf>, |
1980 | 0 | line: usize, |
1981 | 0 | height: usize, |
1982 | 0 | ) -> fmt::Result |
1983 | 0 | where |
1984 | 0 | F: Write, |
1985 | | { |
1986 | 0 | if indent.size == 0 { |
1987 | 0 | return Ok(()); |
1988 | 0 | } |
1989 | | |
1990 | 0 | match offset { |
1991 | 0 | Offset::Start(offset) => { |
1992 | 0 | let offset = cmp::min(offset, height); |
1993 | 0 | if line >= offset { |
1994 | 0 | print_indent(f, indent.fill, indent.size, color)?; |
1995 | | } else { |
1996 | 0 | repeat_char(f, ' ', indent.size)?; |
1997 | | } |
1998 | | } |
1999 | 0 | Offset::End(offset) => { |
2000 | 0 | let offset = cmp::min(offset, height); |
2001 | 0 | let pos = height - offset; |
2002 | | |
2003 | 0 | if line >= pos { |
2004 | 0 | repeat_char(f, ' ', indent.size)?; |
2005 | | } else { |
2006 | 0 | print_indent(f, indent.fill, indent.size, color)?; |
2007 | | } |
2008 | | } |
2009 | | } |
2010 | | |
2011 | 0 | Ok(()) |
2012 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_margin_vertical::<&mut core::fmt::Formatter> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_margin_vertical::<_> |
2013 | | |
2014 | 0 | fn print_indent_lines<F>( |
2015 | 0 | f: &mut F, |
2016 | 0 | indent: &Indent, |
2017 | 0 | offset: &Offset, |
2018 | 0 | color: Option<&ANSIBuf>, |
2019 | 0 | width: usize, |
2020 | 0 | ) -> fmt::Result |
2021 | 0 | where |
2022 | 0 | F: Write, |
2023 | | { |
2024 | 0 | if indent.size == 0 { |
2025 | 0 | return Ok(()); |
2026 | 0 | } |
2027 | | |
2028 | 0 | let (start_offset, end_offset) = match offset { |
2029 | 0 | Offset::Start(start) => (*start, 0), |
2030 | 0 | Offset::End(end) => (0, *end), |
2031 | | }; |
2032 | | |
2033 | 0 | let start_offset = std::cmp::min(start_offset, width); |
2034 | 0 | let end_offset = std::cmp::min(end_offset, width); |
2035 | 0 | let indent_size = width - start_offset - end_offset; |
2036 | | |
2037 | 0 | for i in 0..indent.size { |
2038 | 0 | if start_offset > 0 { |
2039 | 0 | repeat_char(f, ' ', start_offset)?; |
2040 | 0 | } |
2041 | | |
2042 | 0 | if indent_size > 0 { |
2043 | 0 | print_indent(f, indent.fill, indent_size, color)?; |
2044 | 0 | } |
2045 | | |
2046 | 0 | if end_offset > 0 { |
2047 | 0 | repeat_char(f, ' ', end_offset)?; |
2048 | 0 | } |
2049 | | |
2050 | 0 | if i + 1 != indent.size { |
2051 | 0 | f.write_char('\n')?; |
2052 | 0 | } |
2053 | | } |
2054 | | |
2055 | 0 | Ok(()) |
2056 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_indent_lines::<&mut core::fmt::Formatter> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_indent_lines::<_> |
2057 | | |
2058 | 0 | fn print_indent<F, C>(f: &mut F, c: char, n: usize, color: Option<C>) -> fmt::Result |
2059 | 0 | where |
2060 | 0 | F: Write, |
2061 | 0 | C: ANSIFmt, |
2062 | | { |
2063 | 0 | if n == 0 { |
2064 | 0 | return Ok(()); |
2065 | 0 | } |
2066 | | |
2067 | 0 | match color { |
2068 | 0 | Some(color) => { |
2069 | 0 | color.fmt_ansi_prefix(f)?; |
2070 | 0 | repeat_char(f, c, n)?; |
2071 | 0 | color.fmt_ansi_suffix(f) |
2072 | | } |
2073 | 0 | None => repeat_char(f, c, n), |
2074 | | } |
2075 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_indent::<&mut core::fmt::Formatter, &papergrid::ansi::ansi_buf::ANSIBuf> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_indent::<&mut core::fmt::Formatter, &&papergrid::ansi::ansi_buf::ANSIBuf> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::print_indent::<_, _> |
2076 | | |
2077 | 0 | fn get_cell_width<D>(cfg: &SpannedConfig, dims: &D, pos: Position, max: usize) -> usize |
2078 | 0 | where |
2079 | 0 | D: Dimension, |
2080 | | { |
2081 | 0 | match cfg.get_column_span(pos) { |
2082 | 0 | Some(span) => { |
2083 | 0 | let start = pos.col; |
2084 | 0 | let end = start + span; |
2085 | 0 | range_width(dims, start, end) + count_verticals_range(cfg, start, end, max) |
2086 | | } |
2087 | 0 | None => dims.get_width(pos.col), |
2088 | | } |
2089 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::get_cell_width::<&&papergrid::dimension::peekable::PeekableGridDimension> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::get_cell_width::<&&tabled::grid::dimension::complete_dimension::CompleteDimension> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::get_cell_width::<_> |
2090 | | |
2091 | 0 | fn range_width<D>(dims: &D, start: usize, end: usize) -> usize |
2092 | 0 | where |
2093 | 0 | D: Dimension, |
2094 | | { |
2095 | 0 | (start..end).map(|col| dims.get_width(col)).sum::<usize>() Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::range_width::<&&papergrid::dimension::peekable::PeekableGridDimension>::{closure#0}Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::range_width::<&&tabled::grid::dimension::complete_dimension::CompleteDimension>::{closure#0}Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::range_width::<_>::{closure#0} |
2096 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::range_width::<&&papergrid::dimension::peekable::PeekableGridDimension> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::range_width::<&&tabled::grid::dimension::complete_dimension::CompleteDimension> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::range_width::<_> |
2097 | | |
2098 | 0 | fn count_verticals_range(cfg: &SpannedConfig, start: usize, end: usize, max: usize) -> usize { |
2099 | 0 | (start + 1..end) |
2100 | 0 | .map(|i| cfg.has_vertical(i, max) as usize) |
2101 | 0 | .sum() |
2102 | 0 | } |
2103 | | |
2104 | 0 | fn get_cell_height<D>(cfg: &SpannedConfig, dims: &D, pos: Position, max: usize) -> usize |
2105 | 0 | where |
2106 | 0 | D: Dimension, |
2107 | | { |
2108 | 0 | match cfg.get_row_span(pos) { |
2109 | 0 | Some(span) => { |
2110 | 0 | let start = pos.row; |
2111 | 0 | let end = pos.row + span; |
2112 | 0 | range_height(dims, start, end) + count_horizontals_range(cfg, start, end, max) |
2113 | | } |
2114 | 0 | None => dims.get_height(pos.row), |
2115 | | } |
2116 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::get_cell_height::<&&papergrid::dimension::peekable::PeekableGridDimension> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::get_cell_height::<&&tabled::grid::dimension::complete_dimension::CompleteDimension> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::get_cell_height::<_> |
2117 | | |
2118 | 0 | fn range_height<D>(dims: &D, start: usize, end: usize) -> usize |
2119 | 0 | where |
2120 | 0 | D: Dimension, |
2121 | | { |
2122 | 0 | (start..end).map(|col| dims.get_height(col)).sum::<usize>() Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::range_height::<&&papergrid::dimension::peekable::PeekableGridDimension>::{closure#0}Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::range_height::<&&tabled::grid::dimension::complete_dimension::CompleteDimension>::{closure#0}Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::range_height::<_>::{closure#0} |
2123 | 0 | } Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::range_height::<&&papergrid::dimension::peekable::PeekableGridDimension> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::range_height::<&&tabled::grid::dimension::complete_dimension::CompleteDimension> Unexecuted instantiation: papergrid::grid::peekable::grid_spanned::range_height::<_> |
2124 | | |
2125 | 0 | fn count_horizontals_range(cfg: &SpannedConfig, start: usize, end: usize, max: usize) -> usize { |
2126 | 0 | (start + 1..end) |
2127 | 0 | .map(|i| cfg.has_horizontal(i, max) as usize) |
2128 | 0 | .sum() |
2129 | 0 | } |
2130 | | |
2131 | 0 | fn closest_visible_row(cfg: &SpannedConfig, mut pos: Position) -> Option<usize> { |
2132 | | loop { |
2133 | 0 | if cfg.is_cell_visible(pos) { |
2134 | 0 | return Some(pos.row); |
2135 | 0 | } |
2136 | | |
2137 | 0 | if pos.row == 0 { |
2138 | 0 | return None; |
2139 | 0 | } |
2140 | | |
2141 | 0 | pos -= (1, 0); |
2142 | | } |
2143 | 0 | } |
2144 | | |
2145 | | /// Trims a string. |
2146 | 0 | fn string_trim(text: &str) -> Cow<'_, str> { |
2147 | | #[cfg(feature = "ansi")] |
2148 | | { |
2149 | | ansi_str::AnsiStr::ansi_trim(text) |
2150 | | } |
2151 | | |
2152 | | #[cfg(not(feature = "ansi"))] |
2153 | | { |
2154 | 0 | text.trim().into() |
2155 | | } |
2156 | 0 | } |
2157 | | } |