1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
use crate::app::App;
use crate::ui::utils::truncate_str;
use crate::ui::ColorScheme;
use ratatui::{
backend::Backend,
layout::{Alignment, Rect},
style::{Color, Modifier, Style},
text::{Line, Span, Text},
widgets::{Block, BorderType, Borders, List, ListItem, Padding, Paragraph},
Frame,
};
pub(super) fn render_feed_items<B: Backend>(
f: &mut Frame<B>,
app: &App,
area: Rect,
colors: &ColorScheme,
) {
if let Some(feed) = app.current_feed() {
let feed_icon = colors.get_icon_feed();
let title = format!(" {} {} ", feed_icon, feed.title);
if feed.items.is_empty() {
// Empty feed visualization
let mut text = Text::default();
let empty_icon = if colors.border_normal == BorderType::Double {
"◇" // Dark: hollow diamond
} else {
"📭" // Light: mailbox
};
text.lines.push(Line::from(""));
text.lines.push(Line::from(Span::styled(
format!(" {} ", empty_icon),
Style::default().fg(colors.secondary),
)));
text.lines.push(Line::from(""));
text.lines.push(Line::from(Span::styled(
"No items in this feed",
Style::default()
.fg(colors.text)
.add_modifier(Modifier::BOLD),
)));
text.lines.push(Line::from(""));
text.lines.push(Line::from(Span::styled(
"This feed might be empty or need refreshing",
Style::default().fg(colors.muted),
)));
text.lines.push(Line::from(""));
text.lines.push(Line::from(Span::styled(
"Press 'r' to refresh feeds",
Style::default().fg(colors.highlight),
)));
let paragraph = Paragraph::new(text).alignment(Alignment::Center).block(
Block::default()
.title(title)
.title_alignment(Alignment::Center)
.borders(Borders::ALL)
.border_type(colors.border_normal)
.border_style(Style::default().fg(colors.border))
.style(Style::default().bg(colors.surface))
.padding(Padding::new(2, 2, 2, 2)),
);
f.render_widget(paragraph, area);
return;
}
// Enhanced feed items with theme-specific styling
let arrow = colors.get_arrow_right();
let success_icon = colors.get_icon_success();
let items: Vec<ListItem> = feed
.items
.iter()
.enumerate()
.map(|(idx, item)| {
let date_str = item.formatted_date.as_deref().unwrap_or("");
let author = item.author.as_deref().unwrap_or("");
let is_selected = app.selected_item == Some(idx);
let is_read = app
.selected_feed
.is_some_and(|feed_idx| app.is_item_read(feed_idx, idx));
let is_starred = app
.selected_feed
.is_some_and(|feed_idx| app.is_item_starred(feed_idx, idx));
// Use cached plain_text to avoid HTML parsing per frame
let snippet = if let Some(plain_text) = &item.plain_text {
// Remove excess whitespace for cleaner display
let clean_text = plain_text
.replace('\n', " ")
.replace(" ", " ")
.trim()
.to_string();
truncate_str(&clean_text, 100)
} else {
"".to_string()
};
// Create compact but readable item layout with theme-specific indicators
let mut lines = vec![
// Title with read indicator
Line::from(vec![
Span::styled(
if is_selected {
format!("{} ", arrow)
} else {
" ".to_string()
},
Style::default().fg(colors.highlight),
),
Span::styled(
&item.title,
Style::default()
.fg(if is_selected {
colors.text
} else if is_read {
colors.text_secondary
} else {
colors.text
})
.add_modifier(if is_selected {
Modifier::BOLD
} else {
Modifier::empty()
}),
),
Span::styled(
if is_starred { " \u{2605}" } else { "" },
Style::default().fg(Color::Rgb(255, 215, 0)),
),
Span::styled(
if is_read {
format!(" {}", success_icon)
} else {
"".to_string()
},
Style::default().fg(colors.success),
),
]),
];
// Add content preview with subtle styling
if !snippet.is_empty() {
lines.push(Line::from(vec![
Span::styled(" ", Style::default()),
Span::styled(
snippet,
Style::default().fg(if is_selected {
colors.text_secondary
} else {
colors.muted
}),
),
]));
}
// Add metadata on one line
let mut metadata_parts = Vec::new();
metadata_parts.push(Span::styled(" ", Style::default()));
if !author.is_empty() {
metadata_parts.push(Span::styled(author, Style::default().fg(colors.muted)));
if !date_str.is_empty() {
metadata_parts.push(Span::styled(" · ", Style::default().fg(colors.muted)));
}
}
if !date_str.is_empty() {
metadata_parts.push(Span::styled(date_str, Style::default().fg(colors.muted)));
}
if !metadata_parts.is_empty() {
lines.push(Line::from(metadata_parts));
}
// Add spacing between items
lines.push(Line::from(""));
ListItem::new(lines).style(Style::default().fg(colors.text).bg(if is_selected {
colors.selected_bg
} else {
colors.background
}))
})
.collect();
let items_list = List::new(items)
.block(
Block::default()
.title(title)
.title_alignment(Alignment::Center)
.borders(Borders::ALL)
.border_type(colors.border_normal)
.border_style(Style::default().fg(colors.border))
.style(Style::default().bg(colors.surface))
.padding(Padding::new(2, 1, 1, 1)),
)
.highlight_style(
Style::default()
.bg(colors.selected_bg)
.fg(colors.highlight)
.add_modifier(Modifier::BOLD),
)
.highlight_symbol("");
let mut state = ratatui::widgets::ListState::default();
state.select(app.selected_item);
f.render_stateful_widget(items_list, area, &mut state);
}
}