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:
parent
b6ef2b4508
commit
c3a7c62214
1 changed files with 12 additions and 1 deletions
13
src/lib.rs
13
src/lib.rs
|
|
@ -266,10 +266,21 @@ pub fn main(config: &Config, terminal: &mut Terminal<CrosstermBackend<Stdout>>)
|
|||
.style(Style::default().fg(Color::Yellow));
|
||||
frame.render_widget(p, layout[0]);
|
||||
} else {
|
||||
let max_from = emails.iter()
|
||||
.map(|e| e.from.chars().count())
|
||||
.max()
|
||||
.unwrap_or(20)
|
||||
.min(40);
|
||||
let items: Vec<ListItem> = emails
|
||||
.iter()
|
||||
.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();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue