@@ -21,7 +21,7 @@ use tui::{
21
21
backend:: Backend ,
22
22
layout:: { Constraint , Direction , Layout , Rect } ,
23
23
style:: { Modifier , Style } ,
24
- text:: Span ,
24
+ text:: { Span , Spans , Text } ,
25
25
Frame ,
26
26
} ;
27
27
enum Detail {
@@ -132,12 +132,7 @@ impl DetailsComponent {
132
132
& self ,
133
133
width : usize ,
134
134
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 > {
141
136
let ( wrapped_title, wrapped_message) =
142
137
self . get_wrapped_lines ( width) ;
143
138
@@ -148,12 +143,11 @@ impl DetailsComponent {
148
143
. skip ( self . scroll_top . get ( ) )
149
144
. take ( height)
150
145
. map ( |( i, line) | {
151
- Span :: styled (
146
+ Spans :: from ( vec ! [ Span :: styled(
152
147
line. clone( ) ,
153
148
self . get_theme_for_line( i < wrapped_title. len( ) ) ,
154
- )
149
+ ) ] )
155
150
} )
156
- . intersperse ( newline)
157
151
. collect ( )
158
152
}
159
153
@@ -186,55 +180,57 @@ impl DetailsComponent {
186
180
}
187
181
}
188
182
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 > {
192
184
if let Some ( ref data) = self . data {
193
185
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 ) ,
217
188
Span :: styled(
218
189
Cow :: from( format!(
219
190
"{} <{}>" ,
220
- committer . name, committer . email
191
+ data . author . name, data . author . email
221
192
) ) ,
222
193
self . theme. text( true , false ) ,
223
194
) ,
224
- new_line. clone( ) ,
195
+ ] ) ,
196
+ Spans :: from( vec![
225
197
self . style_detail( & Detail :: Date ) ,
226
198
Span :: styled(
227
199
Cow :: from( time_to_string(
228
- committer . time,
200
+ data . author . time,
229
201
false ,
230
202
) ) ,
231
203
self . theme. text( true , false ) ,
232
204
) ,
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
+ ] ) ,
234
230
] ) ;
235
231
}
236
232
237
- res. extend ( vec ! [
233
+ res. push ( Spans :: from ( vec ! [
238
234
Span :: styled(
239
235
Cow :: from( strings:: commit:: details_sha(
240
236
& self . key_config,
@@ -245,12 +241,13 @@ impl DetailsComponent {
245
241
Cow :: from( data. hash. clone( ) ) ,
246
242
self . theme. text( true , false ) ,
247
243
) ,
248
- new_line. clone( ) ,
249
- ] ) ;
244
+ ] ) ) ;
250
245
251
246
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 (
254
251
self . tags
255
252
. iter ( )
256
253
. map ( |tag| {
@@ -262,8 +259,9 @@ impl DetailsComponent {
262
259
. intersperse ( Span :: styled (
263
260
Cow :: from ( "," ) ,
264
261
self . theme . text ( true , false ) ,
265
- ) ) ,
266
- ) ;
262
+ ) )
263
+ . collect :: < Vec < Span > > ( ) ,
264
+ ) ) ;
267
265
}
268
266
269
267
res
@@ -323,10 +321,7 @@ impl DrawableComponent for DetailsComponent {
323
321
& strings:: commit:: details_info_title (
324
322
& self . key_config ,
325
323
) ,
326
- self . get_text_info ( )
327
- . iter ( )
328
- . map ( Clone :: clone)
329
- . collect :: < Vec < Span > > ( ) ,
324
+ Text :: from ( self . get_text_info ( ) ) ,
330
325
& self . theme ,
331
326
false ,
332
327
) ,
@@ -352,10 +347,7 @@ impl DrawableComponent for DetailsComponent {
352
347
& strings:: commit:: details_message_title (
353
348
& self . key_config ,
354
349
) ,
355
- wrapped_lines
356
- . iter ( )
357
- . map ( Clone :: clone)
358
- . collect :: < Vec < Span > > ( ) ,
350
+ Text :: from ( wrapped_lines) ,
359
351
& self . theme ,
360
352
self . focused ,
361
353
) ,
0 commit comments