diff --git a/src/app.rs b/src/app.rs index 42926c8..4e0c87f 100644 --- a/src/app.rs +++ b/src/app.rs @@ -434,9 +434,9 @@ impl TTApp { vertical: 0, horizontal: 0, })); - let maximum_column_width = area.width; - let (contexts, headers) = self.get_all_contexts(); + + let maximum_column_width = area.width; let widths = self.calculate_widths(&contexts, &headers, maximum_column_width); let selected = self.context_table_state.selected().unwrap_or_default(); @@ -566,7 +566,7 @@ impl TTApp { for row in tasks.iter() { for (i, cell) in row.iter().enumerate() { - widths[i] = std::cmp::max(cell.len() + 2, widths[i]); + widths[i] = std::cmp::max(cell.len(), widths[i]); } } @@ -577,9 +577,15 @@ impl TTApp { break } } + for (i, header) in headers.iter().enumerate() { + if header == "ID" { + // always give ID a couple of extra for indicator + widths[i] += self.config.uda_selection_indicator.as_str().graphemes(true).count(); + } + } // now start trimming - while (widths.iter().sum::() as u16) >= maximum_column_width - 5 { + while (widths.iter().sum::() as u16) >= maximum_column_width - (headers.len()) as u16 { let index = widths.iter().position(|i| i == widths.iter().max().unwrap()).unwrap(); if widths[index] == 1 { break @@ -617,9 +623,7 @@ impl TTApp { for (i, header) in headers.iter().enumerate() { if header == "Description" || header == "Definition" { - if widths[i] > headers.iter().len() { - self.task_report_table.description_width = widths[i] - 1; - } + self.task_report_table.description_width = widths[i] - 1; break } } diff --git a/src/table.rs b/src/table.rs index 22c755d..02cdd55 100644 --- a/src/table.rs +++ b/src/table.rs @@ -15,6 +15,8 @@ use tui::{ widgets::{Block, StatefulWidget, Widget}, }; use unicode_width::UnicodeWidthStr; +use unicode_segmentation::Graphemes; +use unicode_segmentation::UnicodeSegmentation; #[derive(Debug, Clone)] pub struct TableState { @@ -272,10 +274,18 @@ where let mut x = table_area.left(); // Draw header + let mut header_index = usize::MAX; + let mut index = 0; if y < table_area.bottom() { for (w, t) in solved_widths.iter().zip(self.header.by_ref()) { - buf.set_stringn(x, y, format!("{}", t), *w as usize, self.header_style); + if t.to_string() == "ID" { + buf.set_stringn(x, y, format!("{symbol:>width$}", symbol=t, width=*w as usize), *w as usize, self.header_style); + header_index = index; + } else { + buf.set_stringn(x, y, format!("{}", t), *w as usize, self.header_style); + } x += *w + self.column_spacing; + index += 1; } } y += 1 + self.header_gap; @@ -323,7 +333,11 @@ where *w as usize, style, ); - format!("{}{}", symbol, elt) + if c == header_index { + format!("{symbol}{elt:>width$}", symbol = symbol, elt = elt, width = *w as usize - symbol.to_string().graphemes(true).count()) + } else { + format!("{symbol}{elt:width$}", elt = elt, width = *w as usize) + } else { + format!("{elt: