@@ -30,6 +30,9 @@ pub struct GraphicalReportHandler {
30
30
pub ( crate ) context_lines : usize ,
31
31
pub ( crate ) tab_width : usize ,
32
32
pub ( crate ) with_cause_chain : bool ,
33
+ pub ( crate ) break_words : bool ,
34
+ pub ( crate ) word_separator : Option < textwrap:: WordSeparator > ,
35
+ pub ( crate ) word_splitter : Option < textwrap:: WordSplitter > ,
33
36
}
34
37
35
38
#[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
@@ -51,6 +54,9 @@ impl GraphicalReportHandler {
51
54
context_lines : 1 ,
52
55
tab_width : 4 ,
53
56
with_cause_chain : true ,
57
+ break_words : true ,
58
+ word_separator : None ,
59
+ word_splitter : None ,
54
60
}
55
61
}
56
62
@@ -64,6 +70,9 @@ impl GraphicalReportHandler {
64
70
context_lines : 1 ,
65
71
tab_width : 4 ,
66
72
with_cause_chain : true ,
73
+ break_words : true ,
74
+ word_separator : None ,
75
+ word_splitter : None ,
67
76
}
68
77
}
69
78
@@ -122,6 +131,24 @@ impl GraphicalReportHandler {
122
131
self
123
132
}
124
133
134
+ /// Enables or disables breaking of words during wrapping.
135
+ pub fn with_break_words ( mut self , break_words : bool ) -> Self {
136
+ self . break_words = break_words;
137
+ self
138
+ }
139
+
140
+ /// Sets the word separator to use when wrapping.
141
+ pub fn with_word_separator ( mut self , word_separator : textwrap:: WordSeparator ) -> Self {
142
+ self . word_separator = Some ( word_separator) ;
143
+ self
144
+ }
145
+
146
+ /// Sets the word splitter to usewhen wrapping.
147
+ pub fn with_word_splitter ( mut self , word_splitter : textwrap:: WordSplitter ) -> Self {
148
+ self . word_splitter = Some ( word_splitter) ;
149
+ self
150
+ }
151
+
125
152
/// Sets the 'global' footer for this handler.
126
153
pub fn with_footer ( mut self , footer : String ) -> Self {
127
154
self . footer = Some ( footer) ;
@@ -159,9 +186,17 @@ impl GraphicalReportHandler {
159
186
if let Some ( footer) = & self . footer {
160
187
writeln ! ( f) ?;
161
188
let width = self . termwidth . saturating_sub ( 4 ) ;
162
- let opts = textwrap:: Options :: new ( width)
189
+ let mut opts = textwrap:: Options :: new ( width)
163
190
. initial_indent ( " " )
164
- . subsequent_indent ( " " ) ;
191
+ . subsequent_indent ( " " )
192
+ . break_words ( self . break_words ) ;
193
+ if let Some ( word_separator) = self . word_separator {
194
+ opts = opts. word_separator ( word_separator) ;
195
+ }
196
+ if let Some ( word_splitter) = self . word_splitter . clone ( ) {
197
+ opts = opts. word_splitter ( word_splitter) ;
198
+ }
199
+
165
200
writeln ! ( f, "{}" , textwrap:: fill( footer, opts) ) ?;
166
201
}
167
202
Ok ( ( ) )
@@ -212,9 +247,16 @@ impl GraphicalReportHandler {
212
247
let initial_indent = format ! ( " {} " , severity_icon. style( severity_style) ) ;
213
248
let rest_indent = format ! ( " {} " , self . theme. characters. vbar. style( severity_style) ) ;
214
249
let width = self . termwidth . saturating_sub ( 2 ) ;
215
- let opts = textwrap:: Options :: new ( width)
250
+ let mut opts = textwrap:: Options :: new ( width)
216
251
. initial_indent ( & initial_indent)
217
- . subsequent_indent ( & rest_indent) ;
252
+ . subsequent_indent ( & rest_indent)
253
+ . break_words ( self . break_words ) ;
254
+ if let Some ( word_separator) = self . word_separator {
255
+ opts = opts. word_separator ( word_separator) ;
256
+ }
257
+ if let Some ( word_splitter) = self . word_splitter . clone ( ) {
258
+ opts = opts. word_splitter ( word_splitter) ;
259
+ }
218
260
219
261
writeln ! ( f, "{}" , textwrap:: fill( & diagnostic. to_string( ) , opts) ) ?;
220
262
@@ -251,9 +293,17 @@ impl GraphicalReportHandler {
251
293
)
252
294
. style ( severity_style)
253
295
. to_string ( ) ;
254
- let opts = textwrap:: Options :: new ( width)
296
+ let mut opts = textwrap:: Options :: new ( width)
255
297
. initial_indent ( & initial_indent)
256
- . subsequent_indent ( & rest_indent) ;
298
+ . subsequent_indent ( & rest_indent)
299
+ . break_words ( self . break_words ) ;
300
+ if let Some ( word_separator) = self . word_separator {
301
+ opts = opts. word_separator ( word_separator) ;
302
+ }
303
+ if let Some ( word_splitter) = self . word_splitter . clone ( ) {
304
+ opts = opts. word_splitter ( word_splitter) ;
305
+ }
306
+
257
307
match error {
258
308
ErrorKind :: Diagnostic ( diag) => {
259
309
let mut inner = String :: new ( ) ;
@@ -280,9 +330,17 @@ impl GraphicalReportHandler {
280
330
if let Some ( help) = diagnostic. help ( ) {
281
331
let width = self . termwidth . saturating_sub ( 4 ) ;
282
332
let initial_indent = " help: " . style ( self . theme . styles . help ) . to_string ( ) ;
283
- let opts = textwrap:: Options :: new ( width)
333
+ let mut opts = textwrap:: Options :: new ( width)
284
334
. initial_indent ( & initial_indent)
285
- . subsequent_indent ( " " ) ;
335
+ . subsequent_indent ( " " )
336
+ . break_words ( self . break_words ) ;
337
+ if let Some ( word_separator) = self . word_separator {
338
+ opts = opts. word_separator ( word_separator) ;
339
+ }
340
+ if let Some ( word_splitter) = self . word_splitter . clone ( ) {
341
+ opts = opts. word_splitter ( word_splitter) ;
342
+ }
343
+
286
344
writeln ! ( f, "{}" , textwrap:: fill( & help. to_string( ) , opts) ) ?;
287
345
}
288
346
Ok ( ( ) )
0 commit comments