Align sender and subject columns in inbox list

Compute the max sender width across the loaded emails (capped at 40
chars) and pad each sender field to that width. Long senders are
truncated with an ellipsis. Subject column now starts at a consistent
position regardless of sender name length.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Shautvast 2026-02-18 16:35:49 +01:00
parent b6ef2b4508
commit c3a7c62214

View file

@ -266,10 +266,21 @@ pub fn main(config: &Config, terminal: &mut Terminal<CrosstermBackend<Stdout>>)
.style(Style::default().fg(Color::Yellow)); .style(Style::default().fg(Color::Yellow));
frame.render_widget(p, layout[0]); frame.render_widget(p, layout[0]);
} else { } else {
let max_from = emails.iter()
.map(|e| e.from.chars().count())
.max()
.unwrap_or(20)
.min(40);
let items: Vec<ListItem> = emails let items: Vec<ListItem> = emails
.iter() .iter()
.map(|e| { .map(|e| {
ListItem::new(format!("{} | {} | {}", e.date, e.from, e.subject)) let from_len = e.from.chars().count();
let from = if from_len > max_from {
format!("{}", e.from.chars().take(max_from.saturating_sub(1)).collect::<String>())
} else {
format!("{:<width$}", e.from, width = max_from)
};
ListItem::new(format!("{} | {} | {}", e.date, from, e.subject))
}) })
.collect(); .collect();