@@ -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
}
@@ -270,6 +282,7 @@ impl DisplaySet<'_> {
270
282
}
271
283
272
284
// Adapted from https://github.com/rust-lang/rust/blob/d371d17496f2ce3a56da76aa083f4ef157572c20/compiler/rustc_errors/src/emitter.rs#L706-L1211
285
+ #[ allow( clippy:: too_many_arguments) ]
273
286
#[ inline]
274
287
fn format_line (
275
288
& self ,
@@ -278,6 +291,7 @@ impl DisplaySet<'_> {
278
291
multiline_depth : usize ,
279
292
stylesheet : & Stylesheet ,
280
293
anonymized_line_numbers : bool ,
294
+ cut_indicator : & ' static str ,
281
295
buffer : & mut StyledBuffer ,
282
296
) -> fmt:: Result {
283
297
let line_offset = buffer. num_lines ( ) ;
@@ -349,10 +363,15 @@ impl DisplaySet<'_> {
349
363
buffer. puts ( line_offset, code_offset, & code, Style :: new ( ) ) ;
350
364
if self . margin . was_cut_left ( ) {
351
365
// We have stripped some code/whitespace from the beginning, make it clear.
352
- buffer. puts ( line_offset, code_offset, "..." , * lineno_color) ;
366
+ buffer. puts ( line_offset, code_offset, cut_indicator , * lineno_color) ;
353
367
}
354
368
if was_cut_right {
355
- 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
+ ) ;
356
375
}
357
376
358
377
let left: usize = text
@@ -724,7 +743,7 @@ impl DisplaySet<'_> {
724
743
Ok ( ( ) )
725
744
}
726
745
DisplayLine :: Fold { inline_marks } => {
727
- buffer. puts ( line_offset, 0 , "..." , * stylesheet. line_no ( ) ) ;
746
+ buffer. puts ( line_offset, 0 , cut_indicator , * stylesheet. line_no ( ) ) ;
728
747
if !inline_marks. is_empty ( ) || 0 < multiline_depth {
729
748
format_inline_marks (
730
749
line_offset,
@@ -987,12 +1006,13 @@ impl<'a> Iterator for CursorLines<'a> {
987
1006
}
988
1007
}
989
1008
990
- fn format_message (
991
- message : snippet:: Message < ' _ > ,
1009
+ fn format_message < ' m > (
1010
+ message : snippet:: Message < ' m > ,
992
1011
term_width : usize ,
993
1012
anonymized_line_numbers : bool ,
1013
+ cut_indicator : & ' static str ,
994
1014
primary : bool ,
995
- ) -> Vec < DisplaySet < ' _ > > {
1015
+ ) -> Vec < DisplaySet < ' m > > {
996
1016
let snippet:: Message {
997
1017
level,
998
1018
id,
@@ -1016,6 +1036,7 @@ fn format_message(
1016
1036
!footer. is_empty ( ) ,
1017
1037
term_width,
1018
1038
anonymized_line_numbers,
1039
+ cut_indicator,
1019
1040
) ) ;
1020
1041
}
1021
1042
@@ -1035,6 +1056,7 @@ fn format_message(
1035
1056
annotation,
1036
1057
term_width,
1037
1058
anonymized_line_numbers,
1059
+ cut_indicator,
1038
1060
false ,
1039
1061
) ) ;
1040
1062
}
@@ -1089,13 +1111,14 @@ fn format_label(
1089
1111
result
1090
1112
}
1091
1113
1092
- fn format_snippet (
1093
- snippet : snippet:: Snippet < ' _ > ,
1114
+ fn format_snippet < ' m > (
1115
+ snippet : snippet:: Snippet < ' m > ,
1094
1116
is_first : bool ,
1095
1117
has_footer : bool ,
1096
1118
term_width : usize ,
1097
1119
anonymized_line_numbers : bool ,
1098
- ) -> DisplaySet < ' _ > {
1120
+ cut_indicator : & ' static str ,
1121
+ ) -> DisplaySet < ' m > {
1099
1122
let main_range = snippet. annotations . first ( ) . map ( |x| x. range . start ) ;
1100
1123
let origin = snippet. origin ;
1101
1124
let need_empty_header = origin. is_some ( ) || is_first;
@@ -1105,6 +1128,7 @@ fn format_snippet(
1105
1128
has_footer,
1106
1129
term_width,
1107
1130
anonymized_line_numbers,
1131
+ cut_indicator,
1108
1132
) ;
1109
1133
let header = format_header ( origin, main_range, & body. display_lines , is_first) ;
1110
1134
@@ -1241,7 +1265,7 @@ fn fold_body(body: Vec<DisplayLine<'_>>) -> Vec<DisplayLine<'_>> {
1241
1265
match unhighlighed_lines. len ( ) {
1242
1266
0 => { }
1243
1267
n if n <= INNER_UNFOLD_SIZE => {
1244
- // Rather than render `...` , don't fold
1268
+ // Rather than render our cut indicator , don't fold
1245
1269
lines. append ( & mut unhighlighed_lines) ;
1246
1270
}
1247
1271
_ => {
@@ -1280,13 +1304,14 @@ fn fold_body(body: Vec<DisplayLine<'_>>) -> Vec<DisplayLine<'_>> {
1280
1304
lines
1281
1305
}
1282
1306
1283
- fn format_body (
1284
- snippet : snippet:: Snippet < ' _ > ,
1307
+ fn format_body < ' m > (
1308
+ snippet : snippet:: Snippet < ' m > ,
1285
1309
need_empty_header : bool ,
1286
1310
has_footer : bool ,
1287
1311
term_width : usize ,
1288
1312
anonymized_line_numbers : bool ,
1289
- ) -> DisplaySet < ' _ > {
1313
+ cut_indicator : & ' static str ,
1314
+ ) -> DisplaySet < ' m > {
1290
1315
let source_len = snippet. source . len ( ) ;
1291
1316
if let Some ( bigger) = snippet. annotations . iter ( ) . find_map ( |x| {
1292
1317
// Allow highlighting one past the last character in the source.
@@ -1617,7 +1642,7 @@ fn format_body(
1617
1642
current_line. to_string ( ) . len ( )
1618
1643
} ;
1619
1644
1620
- let width_offset = 3 + max_line_num_len;
1645
+ let width_offset = cut_indicator . len ( ) + max_line_num_len;
1621
1646
1622
1647
if span_left_margin == usize:: MAX {
1623
1648
span_left_margin = 0 ;
0 commit comments