@@ -38,6 +38,8 @@ use std::fmt::Display;
38
38
use std:: ops:: Range ;
39
39
use std:: { cmp, fmt} ;
40
40
41
+ use unicode_width:: UnicodeWidthStr ;
42
+
41
43
use crate :: renderer:: styled_buffer:: StyledBuffer ;
42
44
use crate :: renderer:: { stylesheet:: Stylesheet , Margin , Style , DEFAULT_TERM_WIDTH } ;
43
45
@@ -53,6 +55,7 @@ pub(crate) struct DisplayList<'a> {
53
55
pub ( crate ) body : Vec < DisplaySet < ' a > > ,
54
56
pub ( crate ) stylesheet : & ' a Stylesheet ,
55
57
pub ( crate ) anonymized_line_numbers : bool ,
58
+ pub ( crate ) cut_indicator : & ' static str ,
56
59
}
57
60
58
61
impl PartialEq for DisplayList < ' _ > {
@@ -119,13 +122,21 @@ impl<'a> DisplayList<'a> {
119
122
stylesheet : & ' a Stylesheet ,
120
123
anonymized_line_numbers : bool ,
121
124
term_width : usize ,
125
+ cut_indicator : & ' static str ,
122
126
) -> DisplayList < ' a > {
123
- let body = format_message ( message, term_width, anonymized_line_numbers, true ) ;
127
+ let body = format_message (
128
+ message,
129
+ term_width,
130
+ anonymized_line_numbers,
131
+ cut_indicator,
132
+ true ,
133
+ ) ;
124
134
125
135
Self {
126
136
body,
127
137
stylesheet,
128
138
anonymized_line_numbers,
139
+ cut_indicator,
129
140
}
130
141
}
131
142
@@ -143,6 +154,7 @@ impl<'a> DisplayList<'a> {
143
154
multiline_depth,
144
155
self . stylesheet ,
145
156
self . anonymized_line_numbers ,
157
+ self . cut_indicator ,
146
158
buffer,
147
159
) ?;
148
160
}
@@ -278,6 +290,7 @@ impl DisplaySet<'_> {
278
290
multiline_depth : usize ,
279
291
stylesheet : & Stylesheet ,
280
292
anonymized_line_numbers : bool ,
293
+ cut_indicator : & ' static str ,
281
294
buffer : & mut StyledBuffer ,
282
295
) -> fmt:: Result {
283
296
let line_offset = buffer. num_lines ( ) ;
@@ -350,10 +363,15 @@ impl DisplaySet<'_> {
350
363
buffer. puts ( line_offset, code_offset, & code, Style :: new ( ) ) ;
351
364
if self . margin . was_cut_left ( ) {
352
365
// We have stripped some code/whitespace from the beginning, make it clear.
353
- buffer. puts ( line_offset, code_offset, "..." , * lineno_color) ;
366
+ buffer. puts ( line_offset, code_offset, cut_indicator , * lineno_color) ;
354
367
}
355
368
if self . margin . was_cut_right ( line_len) {
356
- buffer. puts ( line_offset, code_offset + taken - 3 , "..." , * lineno_color) ;
369
+ buffer. puts (
370
+ line_offset,
371
+ code_offset + taken - cut_indicator. width ( ) ,
372
+ cut_indicator,
373
+ * lineno_color,
374
+ ) ;
357
375
}
358
376
359
377
let left: usize = text
@@ -725,7 +743,7 @@ impl DisplaySet<'_> {
725
743
Ok ( ( ) )
726
744
}
727
745
DisplayLine :: Fold { inline_marks } => {
728
- buffer. puts ( line_offset, 0 , "..." , * stylesheet. line_no ( ) ) ;
746
+ buffer. puts ( line_offset, 0 , cut_indicator , * stylesheet. line_no ( ) ) ;
729
747
if !inline_marks. is_empty ( ) || 0 < multiline_depth {
730
748
format_inline_marks (
731
749
line_offset,
@@ -987,12 +1005,13 @@ impl<'a> Iterator for CursorLines<'a> {
987
1005
}
988
1006
}
989
1007
990
- fn format_message (
991
- message : snippet:: Message < ' _ > ,
1008
+ fn format_message < ' m > (
1009
+ message : snippet:: Message < ' m > ,
992
1010
term_width : usize ,
993
1011
anonymized_line_numbers : bool ,
1012
+ cut_indicator : & ' static str ,
994
1013
primary : bool ,
995
- ) -> Vec < DisplaySet < ' _ > > {
1014
+ ) -> Vec < DisplaySet < ' m > > {
996
1015
let snippet:: Message {
997
1016
level,
998
1017
id,
@@ -1016,6 +1035,7 @@ fn format_message(
1016
1035
!footer. is_empty ( ) ,
1017
1036
term_width,
1018
1037
anonymized_line_numbers,
1038
+ cut_indicator,
1019
1039
) ) ;
1020
1040
}
1021
1041
@@ -1035,6 +1055,7 @@ fn format_message(
1035
1055
annotation,
1036
1056
term_width,
1037
1057
anonymized_line_numbers,
1058
+ cut_indicator,
1038
1059
false ,
1039
1060
) ) ;
1040
1061
}
@@ -1089,13 +1110,14 @@ fn format_label(
1089
1110
result
1090
1111
}
1091
1112
1092
- fn format_snippet (
1093
- snippet : snippet:: Snippet < ' _ > ,
1113
+ fn format_snippet < ' m > (
1114
+ snippet : snippet:: Snippet < ' m > ,
1094
1115
is_first : bool ,
1095
1116
has_footer : bool ,
1096
1117
term_width : usize ,
1097
1118
anonymized_line_numbers : bool ,
1098
- ) -> DisplaySet < ' _ > {
1119
+ cut_indicator : & ' static str ,
1120
+ ) -> DisplaySet < ' m > {
1099
1121
let main_range = snippet. annotations . first ( ) . map ( |x| x. range . start ) ;
1100
1122
let origin = snippet. origin ;
1101
1123
let need_empty_header = origin. is_some ( ) || is_first;
@@ -1105,6 +1127,7 @@ fn format_snippet(
1105
1127
has_footer,
1106
1128
term_width,
1107
1129
anonymized_line_numbers,
1130
+ cut_indicator,
1108
1131
) ;
1109
1132
let header = format_header ( origin, main_range, & body. display_lines , is_first) ;
1110
1133
@@ -1248,7 +1271,7 @@ fn fold_body(body: Vec<DisplayLine<'_>>) -> Vec<DisplayLine<'_>> {
1248
1271
match unhighlighed_lines. len ( ) {
1249
1272
0 => { }
1250
1273
n if n <= INNER_UNFOLD_SIZE => {
1251
- // Rather than render `...` , don't fold
1274
+ // Rather than render our cut indicator , don't fold
1252
1275
lines. append ( & mut unhighlighed_lines) ;
1253
1276
}
1254
1277
_ => {
@@ -1287,13 +1310,14 @@ fn fold_body(body: Vec<DisplayLine<'_>>) -> Vec<DisplayLine<'_>> {
1287
1310
lines
1288
1311
}
1289
1312
1290
- fn format_body (
1291
- snippet : snippet:: Snippet < ' _ > ,
1313
+ fn format_body < ' m > (
1314
+ snippet : snippet:: Snippet < ' m > ,
1292
1315
need_empty_header : bool ,
1293
1316
has_footer : bool ,
1294
1317
term_width : usize ,
1295
1318
anonymized_line_numbers : bool ,
1296
- ) -> DisplaySet < ' _ > {
1319
+ cut_indicator : & ' static str ,
1320
+ ) -> DisplaySet < ' m > {
1297
1321
let source_len = snippet. source . len ( ) ;
1298
1322
if let Some ( bigger) = snippet. annotations . iter ( ) . find_map ( |x| {
1299
1323
// Allow highlighting one past the last character in the source.
@@ -1626,7 +1650,7 @@ fn format_body(
1626
1650
current_line. to_string ( ) . len ( )
1627
1651
} ;
1628
1652
1629
- let width_offset = 3 + max_line_num_len;
1653
+ let width_offset = cut_indicator . len ( ) + max_line_num_len;
1630
1654
1631
1655
if span_left_margin == usize:: MAX {
1632
1656
span_left_margin = 0 ;
0 commit comments