| 1 | use superrust-analyzer cargo comfy-table 7.2.2 utils/arrangement/::DisplayInfosrust-analyzer cargo comfy-table 7.2.2 utils/arrangement/DisplayInfos#; |
| 2 | use craterust-analyzer cargo comfy-table 7.2.2 crate/::{ |
| 3 | Cellrust-analyzer cargo comfy-table 7.2.2 cell/Cell#, Columnrust-analyzer cargo comfy-table 7.2.2 column/Column#, Tablerust-analyzer cargo comfy-table 7.2.2 table/Table#, |
| 4 | utilsrust-analyzer cargo comfy-table 7.2.2 utils/::formattingrust-analyzer cargo comfy-table 7.2.2 utils/formatting/::bordersrust-analyzer cargo comfy-table 7.2.2 utils/formatting/borders/::{ |
| 5 | should_draw_left_borderrust-analyzer cargo comfy-table 7.2.2 utils/formatting/borders/should_draw_left_border()., should_draw_right_borderrust-analyzer cargo comfy-table 7.2.2 utils/formatting/borders/should_draw_right_border()., should_draw_vertical_linesrust-analyzer cargo comfy-table 7.2.2 utils/formatting/borders/should_draw_vertical_lines()., |
| 6 | }, |
| 7 | }; |
| 8 | |
| 9 | /// The ColumnDisplayInfo works with a fixed value for content width. |
| 10 | /// However, if a column is supposed to get a absolute width, we have to make sure that |
| 11 | /// the padding on top of the content width doesn't get larger than the specified absolute width. |
| 12 | /// |
| 13 | /// For this reason, we take the targeted width, subtract the column's padding and make sure that |
| 14 | /// the content width is always a minimum of 1 |
| 15 | pub fn absolute_width_with_paddingrust-analyzer cargo comfy-table 7.2.2 utils/arrangement/helper/absolute_width_with_padding().(column: &Columnrust-analyzer cargo comfy-table 7.2.2 column/Column#, width: u16) -> u16 { |
| 16 | let mut content_width = width |
| 17 | .saturating_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u16]saturating_sub().(column.paddingrust-analyzer cargo comfy-table 7.2.2 column/Column#padding..0) |
| 18 | .saturating_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u16]saturating_sub().(column.paddingrust-analyzer cargo comfy-table 7.2.2 column/Column#padding..1); |
| 19 | if content_width rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq().0 { |
| 20 | content_width = 1; |
| 21 | } |
| 22 | |
| 23 | content_width |
| 24 | } |
| 25 | |
| 26 | /// Return the amount of visible columns |
| 27 | pub fn count_visible_columnsrust-analyzer cargo comfy-table 7.2.2 utils/arrangement/helper/count_visible_columns().(columns: &[Columnrust-analyzer cargo comfy-table 7.2.2 column/Column#]) -> usize { |
| 28 | columns.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|column| !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().column.is_hiddenrust-analyzer cargo comfy-table 7.2.2 column/impl#[Column]is_hidden().()).countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter/impl#[`Filter<I, P>`][Iterator]count().() |
| 29 | } |
| 30 | |
| 31 | /// Return the amount of visible columns that haven't been checked yet. |
| 32 | /// |
| 33 | /// - `column_count` is the total amount of columns that are visible, calculated with |
| 34 | /// [count_visible_columns]. |
| 35 | /// - `infos` are all columns that have already been fixed in size or are hidden. |
| 36 | pub fn count_remaining_columnsrust-analyzer cargo comfy-table 7.2.2 utils/arrangement/helper/count_remaining_columns().(column_count: usize, infos: &DisplayInfosrust-analyzer cargo comfy-table 7.2.2 utils/arrangement/DisplayInfos#) -> usize { |
| 37 | column_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().infos.iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]iter().().filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|(_, info)| !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().info.is_hiddenrust-analyzer cargo comfy-table 7.2.2 utils/ColumnDisplayInfo#is_hidden.).countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter/impl#[`Filter<I, P>`][Iterator]count().() |
| 38 | } |
| 39 | |
| 40 | /// Return the amount of border columns, that will be visible in the final table output. |
| 41 | pub fn count_border_columnsrust-analyzer cargo comfy-table 7.2.2 utils/arrangement/helper/count_border_columns().(table: &Tablerust-analyzer cargo comfy-table 7.2.2 table/Table#, visible_columns: usize) -> usize { |
| 42 | let mut lines = 0; |
| 43 | // Remove space occupied by borders from remaining_width |
| 44 | if should_draw_left_borderrust-analyzer cargo comfy-table 7.2.2 utils/formatting/borders/should_draw_left_border().(table) { |
| 45 | lines rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 46 | } |
| 47 | if should_draw_right_borderrust-analyzer cargo comfy-table 7.2.2 utils/formatting/borders/should_draw_right_border().(table) { |
| 48 | lines rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 49 | } |
| 50 | if should_draw_vertical_linesrust-analyzer cargo comfy-table 7.2.2 utils/formatting/borders/should_draw_vertical_lines().(table) { |
| 51 | lines rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().visible_columns.saturating_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]saturating_sub().(1); |
| 52 | } |
| 53 | |
| 54 | lines |
| 55 | } |
| 56 | |
| 57 | /// Get the delimiter for a Cell. |
| 58 | /// Priority is in decreasing order: Cell -> Column -> Table. |
| 59 | pub fn delimiterrust-analyzer cargo comfy-table 7.2.2 utils/arrangement/helper/delimiter().(table: &Tablerust-analyzer cargo comfy-table 7.2.2 table/Table#, column: &Columnrust-analyzer cargo comfy-table 7.2.2 column/Column#, cell: &Cellrust-analyzer cargo comfy-table 7.2.2 cell/Cell#) -> char { |
| 60 | // Determine, which delimiter should be used |
| 61 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(delimiter) = cell.delimiterrust-analyzer cargo comfy-table 7.2.2 cell/Cell#delimiter. { |
| 62 | delimiter |
| 63 | } else if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(delimiter) = column.delimiterrust-analyzer cargo comfy-table 7.2.2 column/Column#delimiter. { |
| 64 | delimiter |
| 65 | } else if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(delimiter) = table.delimiterrust-analyzer cargo comfy-table 7.2.2 table/Table#delimiter. { |
| 66 | delimiter |
| 67 | } else { |
| 68 | ' ' |
| 69 | } |
| 70 | } |