@@ -265,17 +265,15 @@ impl MietteHandlerOpts {
265
265
let characters = match self . unicode {
266
266
Some ( true ) => ThemeCharacters :: unicode ( ) ,
267
267
Some ( false ) => ThemeCharacters :: ascii ( ) ,
268
- None if supports_unicode:: on ( supports_unicode:: Stream :: Stderr ) => {
269
- ThemeCharacters :: unicode ( )
270
- }
268
+ None if syscall:: supports_unicode ( ) => ThemeCharacters :: unicode ( ) ,
271
269
None => ThemeCharacters :: ascii ( ) ,
272
270
} ;
273
271
let styles = if self . color == Some ( false ) {
274
272
ThemeStyles :: none ( )
275
- } else if let Some ( color ) = supports_color :: on ( supports_color :: Stream :: Stderr ) {
273
+ } else if let Some ( color_has_16m ) = syscall :: supports_color_has_16m ( ) {
276
274
match self . rgb_colors {
277
275
RgbColors :: Always => ThemeStyles :: rgb ( ) ,
278
- RgbColors :: Preferred if color . has_16m => ThemeStyles :: rgb ( ) ,
276
+ RgbColors :: Preferred if color_has_16m => ThemeStyles :: rgb ( ) ,
279
277
_ => ThemeStyles :: ansi ( ) ,
280
278
}
281
279
} else if self . color == Some ( true ) {
@@ -291,9 +289,7 @@ impl MietteHandlerOpts {
291
289
#[ cfg( feature = "syntect-highlighter" ) ]
292
290
let highlighter = if self . color == Some ( false ) {
293
291
MietteHighlighter :: nocolor ( )
294
- } else if self . color == Some ( true )
295
- || supports_color:: on ( supports_color:: Stream :: Stderr ) . is_some ( )
296
- {
292
+ } else if self . color == Some ( true ) || syscall:: supports_color ( ) {
297
293
match self . highlighter {
298
294
Some ( highlighter) => highlighter,
299
295
None => match self . rgb_colors {
@@ -366,26 +362,13 @@ impl MietteHandlerOpts {
366
362
if let Some ( linkify) = self . linkify {
367
363
linkify
368
364
} else {
369
- supports_hyperlinks :: on ( supports_hyperlinks:: Stream :: Stderr )
365
+ syscall :: supports_hyperlinks ( )
370
366
}
371
367
}
372
368
373
- #[ cfg( not( miri) ) ]
374
- pub ( crate ) fn get_width ( & self ) -> usize {
375
- self . width . unwrap_or_else ( || {
376
- terminal_size:: terminal_size ( )
377
- . unwrap_or ( ( terminal_size:: Width ( 80 ) , terminal_size:: Height ( 0 ) ) )
378
- . 0
379
- . 0 as usize
380
- } )
381
- }
382
-
383
- #[ cfg( miri) ]
384
- // miri doesn't support a syscall (specifically ioctl)
385
- // performed by terminal_size, which causes test execution to fail
386
- // so when miri is running we'll just fallback to a constant
387
369
pub ( crate ) fn get_width ( & self ) -> usize {
388
- self . width . unwrap_or ( 80 )
370
+ self . width
371
+ . unwrap_or_else ( || syscall:: terminal_width ( ) . unwrap_or ( 80 ) )
389
372
}
390
373
}
391
374
@@ -430,3 +413,63 @@ impl ReportHandler for MietteHandler {
430
413
self . inner . debug ( diagnostic, f)
431
414
}
432
415
}
416
+
417
+ mod syscall {
418
+ use cfg_if:: cfg_if;
419
+
420
+ #[ inline]
421
+ pub ( super ) fn terminal_width ( ) -> Option < usize > {
422
+ cfg_if ! {
423
+ if #[ cfg( any( feature = "fancy-no-syscall" , miri) ) ] {
424
+ None
425
+ } else {
426
+ terminal_size:: terminal_size( ) . map( |size| size. 0 . 0 as usize )
427
+ }
428
+ }
429
+ }
430
+
431
+ #[ inline]
432
+ pub ( super ) fn supports_hyperlinks ( ) -> bool {
433
+ cfg_if ! {
434
+ if #[ cfg( feature = "fancy-no-syscall" ) ] {
435
+ false
436
+ } else {
437
+ supports_hyperlinks:: on( supports_hyperlinks:: Stream :: Stderr )
438
+ }
439
+ }
440
+ }
441
+
442
+ #[ cfg( feature = "syntect-highlighter" ) ]
443
+ #[ inline]
444
+ pub ( super ) fn supports_color ( ) -> bool {
445
+ cfg_if ! {
446
+ if #[ cfg( feature = "fancy-no-syscall" ) ] {
447
+ false
448
+ } else {
449
+ supports_color:: on( supports_color:: Stream :: Stderr ) . is_some( )
450
+ }
451
+ }
452
+ }
453
+
454
+ #[ inline]
455
+ pub ( super ) fn supports_color_has_16m ( ) -> Option < bool > {
456
+ cfg_if ! {
457
+ if #[ cfg( feature = "fancy-no-syscall" ) ] {
458
+ None
459
+ } else {
460
+ supports_color:: on( supports_color:: Stream :: Stderr ) . map( |color| color. has_16m)
461
+ }
462
+ }
463
+ }
464
+
465
+ #[ inline]
466
+ pub ( super ) fn supports_unicode ( ) -> bool {
467
+ cfg_if ! {
468
+ if #[ cfg( feature = "fancy-no-syscall" ) ] {
469
+ false
470
+ } else {
471
+ supports_unicode:: on( supports_unicode:: Stream :: Stderr )
472
+ }
473
+ }
474
+ }
475
+ }
0 commit comments