(&self, object: &mut GitQLObject)
| 49 | |
| 50 | impl BaseOutputPrinter for TablePrinter { |
| 51 | fn print(&self, object: &mut GitQLObject) { |
| 52 | if object.is_empty() || object.groups[0].is_empty() { |
| 53 | return; |
| 54 | } |
| 55 | |
| 56 | let titles = &object.titles; |
| 57 | let group = object.groups.first().unwrap(); |
| 58 | let group_len = group.len(); |
| 59 | |
| 60 | // Setup table headers |
| 61 | let mut table_headers = vec![]; |
| 62 | for key in titles { |
| 63 | let mut table_cell = comfy_table::Cell::new(key); |
| 64 | if let Some(forground_color) = self.theme_config.header_forground_color { |
| 65 | table_cell = table_cell.fg(forground_color); |
| 66 | } |
| 67 | |
| 68 | if let Some(background_color) = self.theme_config.header_background_color { |
| 69 | table_cell = table_cell.bg(background_color); |
| 70 | } |
| 71 | |
| 72 | table_headers.push(table_cell); |
| 73 | } |
| 74 | |
| 75 | // Print all data without pagination |
| 76 | if !self.pagination || self.page_size >= group_len { |
| 77 | self.print_group_as_table(titles, table_headers, &group.rows); |
| 78 | return; |
| 79 | } |
| 80 | |
| 81 | // Setup the pagination mode |
| 82 | let number_of_pages = (group_len as f64 / self.page_size as f64).ceil() as usize; |
| 83 | let mut current_page = 1; |
| 84 | |
| 85 | loop { |
| 86 | let start_index = (current_page - 1) * self.page_size; |
| 87 | let end_index = (start_index + self.page_size).min(group_len); |
| 88 | |
| 89 | let current_page_groups = &group.rows[start_index..end_index]; |
| 90 | println!("Page {current_page}/{number_of_pages}"); |
| 91 | self.print_group_as_table(titles, table_headers.clone(), current_page_groups); |
| 92 | |
| 93 | let pagination_input = self.handle_pagination_input(current_page, number_of_pages); |
| 94 | match pagination_input { |
| 95 | PaginationInput::NextPage => current_page += 1, |
| 96 | PaginationInput::PreviousPage => current_page -= 1, |
| 97 | PaginationInput::Quit => break, |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | impl TablePrinter { |
nothing calls this directly
no test coverage detected