@@ -9,44 +9,6 @@ use crate::util::errors::CargoResult;
99use crate :: util:: hostname;
1010use crate :: util:: style:: * ;
1111
12- pub enum TtyWidth {
13- NoTty ,
14- Known ( usize ) ,
15- Guess ( usize ) ,
16- }
17-
18- impl TtyWidth {
19- /// Returns the width of the terminal to use for diagnostics (which is
20- /// relayed to rustc via `--diagnostic-width`).
21- pub fn diagnostic_terminal_width ( & self ) -> Option < usize > {
22- // ALLOWED: For testing cargo itself only.
23- #[ allow( clippy:: disallowed_methods) ]
24- if let Ok ( width) = std:: env:: var ( "__CARGO_TEST_TTY_WIDTH_DO_NOT_USE_THIS" ) {
25- return Some ( width. parse ( ) . unwrap ( ) ) ;
26- }
27- match * self {
28- TtyWidth :: NoTty | TtyWidth :: Guess ( _) => None ,
29- TtyWidth :: Known ( width) => Some ( width) ,
30- }
31- }
32-
33- /// Returns the width used by progress bars for the tty.
34- pub fn progress_max_width ( & self ) -> Option < usize > {
35- match * self {
36- TtyWidth :: NoTty => None ,
37- TtyWidth :: Known ( width) | TtyWidth :: Guess ( width) => Some ( width) ,
38- }
39- }
40- }
41-
42- /// The requested verbosity of output.
43- #[ derive( Debug , Clone , Copy , PartialEq ) ]
44- pub enum Verbosity {
45- Verbose ,
46- Normal ,
47- Quiet ,
48- }
49-
5012/// An abstraction around console output that remembers preferences for output
5113/// verbosity and color.
5214pub struct Shell {
@@ -77,31 +39,6 @@ impl fmt::Debug for Shell {
7739 }
7840}
7941
80- /// A `Write`able object, either with or without color support
81- enum ShellOut {
82- /// A plain write object without color support
83- Write ( AutoStream < Box < dyn Write > > ) ,
84- /// Color-enabled stdio, with information on whether color should be used
85- Stream {
86- stdout : AutoStream < std:: io:: Stdout > ,
87- stderr : AutoStream < std:: io:: Stderr > ,
88- stderr_tty : bool ,
89- color_choice : ColorChoice ,
90- hyperlinks : bool ,
91- } ,
92- }
93-
94- /// Whether messages should use color output
95- #[ derive( Debug , PartialEq , Clone , Copy ) ]
96- pub enum ColorChoice {
97- /// Force color output
98- Always ,
99- /// Force disable color output
100- Never ,
101- /// Intelligently guess whether to use color output
102- CargoAuto ,
103- }
104-
10542impl Shell {
10643 /// Creates a new shell (color choice and verbosity), defaulting to 'auto' color and verbose
10744 /// output.
@@ -444,6 +381,20 @@ impl Default for Shell {
444381 }
445382}
446383
384+ /// A `Write`able object, either with or without color support
385+ enum ShellOut {
386+ /// A plain write object without color support
387+ Write ( AutoStream < Box < dyn Write > > ) ,
388+ /// Color-enabled stdio, with information on whether color should be used
389+ Stream {
390+ stdout : AutoStream < std:: io:: Stdout > ,
391+ stderr : AutoStream < std:: io:: Stderr > ,
392+ stderr_tty : bool ,
393+ color_choice : ColorChoice ,
394+ hyperlinks : bool ,
395+ } ,
396+ }
397+
447398impl ShellOut {
448399 /// Prints out a message with a status. The status comes first, and is bold plus the given
449400 /// color. The status can be justified, in which case the max width that will right align is
@@ -488,6 +439,55 @@ impl ShellOut {
488439 }
489440}
490441
442+ pub enum TtyWidth {
443+ NoTty ,
444+ Known ( usize ) ,
445+ Guess ( usize ) ,
446+ }
447+
448+ impl TtyWidth {
449+ /// Returns the width of the terminal to use for diagnostics (which is
450+ /// relayed to rustc via `--diagnostic-width`).
451+ pub fn diagnostic_terminal_width ( & self ) -> Option < usize > {
452+ // ALLOWED: For testing cargo itself only.
453+ #[ allow( clippy:: disallowed_methods) ]
454+ if let Ok ( width) = std:: env:: var ( "__CARGO_TEST_TTY_WIDTH_DO_NOT_USE_THIS" ) {
455+ return Some ( width. parse ( ) . unwrap ( ) ) ;
456+ }
457+ match * self {
458+ TtyWidth :: NoTty | TtyWidth :: Guess ( _) => None ,
459+ TtyWidth :: Known ( width) => Some ( width) ,
460+ }
461+ }
462+
463+ /// Returns the width used by progress bars for the tty.
464+ pub fn progress_max_width ( & self ) -> Option < usize > {
465+ match * self {
466+ TtyWidth :: NoTty => None ,
467+ TtyWidth :: Known ( width) | TtyWidth :: Guess ( width) => Some ( width) ,
468+ }
469+ }
470+ }
471+
472+ /// The requested verbosity of output.
473+ #[ derive( Debug , Clone , Copy , PartialEq ) ]
474+ pub enum Verbosity {
475+ Verbose ,
476+ Normal ,
477+ Quiet ,
478+ }
479+
480+ /// Whether messages should use color output
481+ #[ derive( Debug , PartialEq , Clone , Copy ) ]
482+ pub enum ColorChoice {
483+ /// Force color output
484+ Always ,
485+ /// Force disable color output
486+ Never ,
487+ /// Intelligently guess whether to use color output
488+ CargoAuto ,
489+ }
490+
491491impl ColorChoice {
492492 /// Converts our color choice to anstream's version.
493493 fn to_anstream_color_choice ( self ) -> anstream:: ColorChoice {
0 commit comments