Skip to content

Commit ecbf2bc

Browse files
committed
Fix commit details
1 parent 4504d65 commit ecbf2bc

File tree

2 files changed

+50
-58
lines changed

2 files changed

+50
-58
lines changed

src/components/commit_details/details.rs

+47-55
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use tui::{
2121
backend::Backend,
2222
layout::{Constraint, Direction, Layout, Rect},
2323
style::{Modifier, Style},
24-
text::Span,
24+
text::{Span, Spans, Text},
2525
Frame,
2626
};
2727
enum Detail {
@@ -132,12 +132,7 @@ impl DetailsComponent {
132132
&self,
133133
width: usize,
134134
height: usize,
135-
) -> Vec<Span> {
136-
let newline = Span::styled::<String>(
137-
String::from("\n"),
138-
self.theme.text(true, false),
139-
);
140-
135+
) -> Vec<Spans> {
141136
let (wrapped_title, wrapped_message) =
142137
self.get_wrapped_lines(width);
143138

@@ -148,12 +143,11 @@ impl DetailsComponent {
148143
.skip(self.scroll_top.get())
149144
.take(height)
150145
.map(|(i, line)| {
151-
Span::styled(
146+
Spans::from(vec![Span::styled(
152147
line.clone(),
153148
self.get_theme_for_line(i < wrapped_title.len()),
154-
)
149+
)])
155150
})
156-
.intersperse(newline)
157151
.collect()
158152
}
159153

@@ -186,55 +180,57 @@ impl DetailsComponent {
186180
}
187181
}
188182

189-
fn get_text_info(&self) -> Vec<Span> {
190-
let new_line = Span::raw(Cow::from("\n"));
191-
183+
fn get_text_info(&self) -> Vec<Spans> {
192184
if let Some(ref data) = self.data {
193185
let mut res = vec![
194-
self.style_detail(&Detail::Author),
195-
Span::styled(
196-
Cow::from(format!(
197-
"{} <{}>",
198-
data.author.name, data.author.email
199-
)),
200-
self.theme.text(true, false),
201-
),
202-
new_line.clone(),
203-
self.style_detail(&Detail::Date),
204-
Span::styled(
205-
Cow::from(time_to_string(
206-
data.author.time,
207-
false,
208-
)),
209-
self.theme.text(true, false),
210-
),
211-
new_line.clone(),
212-
];
213-
214-
if let Some(ref committer) = data.committer {
215-
res.extend(vec![
216-
self.style_detail(&Detail::Commiter),
186+
Spans::from(vec![
187+
self.style_detail(&Detail::Author),
217188
Span::styled(
218189
Cow::from(format!(
219190
"{} <{}>",
220-
committer.name, committer.email
191+
data.author.name, data.author.email
221192
)),
222193
self.theme.text(true, false),
223194
),
224-
new_line.clone(),
195+
]),
196+
Spans::from(vec![
225197
self.style_detail(&Detail::Date),
226198
Span::styled(
227199
Cow::from(time_to_string(
228-
committer.time,
200+
data.author.time,
229201
false,
230202
)),
231203
self.theme.text(true, false),
232204
),
233-
new_line.clone(),
205+
]),
206+
];
207+
208+
if let Some(ref committer) = data.committer {
209+
res.extend(vec![
210+
Spans::from(vec![
211+
self.style_detail(&Detail::Commiter),
212+
Span::styled(
213+
Cow::from(format!(
214+
"{} <{}>",
215+
committer.name, committer.email
216+
)),
217+
self.theme.text(true, false),
218+
),
219+
]),
220+
Spans::from(vec![
221+
self.style_detail(&Detail::Date),
222+
Span::styled(
223+
Cow::from(time_to_string(
224+
committer.time,
225+
false,
226+
)),
227+
self.theme.text(true, false),
228+
),
229+
]),
234230
]);
235231
}
236232

237-
res.extend(vec![
233+
res.push(Spans::from(vec![
238234
Span::styled(
239235
Cow::from(strings::commit::details_sha(
240236
&self.key_config,
@@ -245,12 +241,13 @@ impl DetailsComponent {
245241
Cow::from(data.hash.clone()),
246242
self.theme.text(true, false),
247243
),
248-
new_line.clone(),
249-
]);
244+
]));
250245

251246
if !self.tags.is_empty() {
252-
res.push(self.style_detail(&Detail::Sha));
253-
res.extend(
247+
res.push(Spans::from(
248+
self.style_detail(&Detail::Sha),
249+
));
250+
res.push(Spans::from(
254251
self.tags
255252
.iter()
256253
.map(|tag| {
@@ -262,8 +259,9 @@ impl DetailsComponent {
262259
.intersperse(Span::styled(
263260
Cow::from(","),
264261
self.theme.text(true, false),
265-
)),
266-
);
262+
))
263+
.collect::<Vec<Span>>(),
264+
));
267265
}
268266

269267
res
@@ -323,10 +321,7 @@ impl DrawableComponent for DetailsComponent {
323321
&strings::commit::details_info_title(
324322
&self.key_config,
325323
),
326-
self.get_text_info()
327-
.iter()
328-
.map(Clone::clone)
329-
.collect::<Vec<Span>>(),
324+
Text::from(self.get_text_info()),
330325
&self.theme,
331326
false,
332327
),
@@ -352,10 +347,7 @@ impl DrawableComponent for DetailsComponent {
352347
&strings::commit::details_message_title(
353348
&self.key_config,
354349
),
355-
wrapped_lines
356-
.iter()
357-
.map(Clone::clone)
358-
.collect::<Vec<Span>>(),
350+
Text::from(wrapped_lines),
359351
&self.theme,
360352
self.focused,
361353
),

src/components/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use crate::ui::style::Theme;
4343
use tui::{
4444
backend::Backend,
4545
layout::{Alignment, Rect},
46-
text::{Span, Spans},
46+
text::{Span, Spans, Text},
4747
widgets::{Block, BorderType, Borders, Paragraph, Wrap},
4848
Frame,
4949
};
@@ -186,11 +186,11 @@ pub trait Component {
186186

187187
fn dialog_paragraph<'a>(
188188
title: &'a str,
189-
content: Vec<Span<'a>>,
189+
content: Text<'a>,
190190
theme: &Theme,
191191
focused: bool,
192192
) -> Paragraph<'a> {
193-
Paragraph::new(Spans::from(content))
193+
Paragraph::new(content)
194194
.block(
195195
Block::default()
196196
.title(Span::styled(title, theme.title(focused)))

0 commit comments

Comments
 (0)