@@ -12,27 +12,16 @@ pub(crate) struct Color {
12
12
}
13
13
14
14
impl Color {
15
- fn restyle ( self , style : Style ) -> Self {
16
- Self { style, ..self }
17
- }
18
-
19
- fn redirect ( self , stream : impl IsTerminal ) -> Self {
20
- Self {
21
- is_terminal : stream. is_terminal ( ) ,
22
- ..self
23
- }
24
- }
25
-
26
- fn effective_style ( & self ) -> Style {
27
- if self . active ( ) {
28
- self . style
29
- } else {
30
- Style :: new ( )
15
+ pub ( crate ) fn active ( & self ) -> bool {
16
+ match self . use_color {
17
+ UseColor :: Always => true ,
18
+ UseColor :: Never => false ,
19
+ UseColor :: Auto => self . is_terminal ,
31
20
}
32
21
}
33
22
34
- pub ( crate ) fn auto ( ) -> Self {
35
- Self :: default ( )
23
+ pub ( crate ) fn alias ( self ) -> Self {
24
+ self . restyle ( Style :: new ( ) . fg ( Purple ) )
36
25
}
37
26
38
27
pub ( crate ) fn always ( ) -> Self {
@@ -42,25 +31,38 @@ impl Color {
42
31
}
43
32
}
44
33
45
- pub ( crate ) fn never ( ) -> Self {
46
- Self {
47
- use_color : UseColor :: Never ,
48
- ..Self :: default ( )
49
- }
34
+ pub ( crate ) fn annotation ( self ) -> Self {
35
+ self . restyle ( Style :: new ( ) . fg ( Purple ) )
50
36
}
51
37
52
- pub ( crate ) fn stderr ( self ) -> Self {
53
- self . redirect ( io :: stderr ( ) )
38
+ pub ( crate ) fn auto ( ) -> Self {
39
+ Self :: default ( )
54
40
}
55
41
56
- pub ( crate ) fn stdout ( self ) -> Self {
57
- self . redirect ( io:: stdout ( ) )
42
+ pub ( crate ) fn banner ( self ) -> Self {
43
+ self . restyle ( Style :: new ( ) . fg ( Cyan ) . bold ( ) )
44
+ }
45
+
46
+ pub ( crate ) fn command ( self , foreground : Option < ansi_term:: Color > ) -> Self {
47
+ self . restyle ( Style {
48
+ foreground,
49
+ is_bold : true ,
50
+ ..Style :: default ( )
51
+ } )
58
52
}
59
53
60
54
pub ( crate ) fn context ( self ) -> Self {
61
55
self . restyle ( Style :: new ( ) . fg ( Blue ) . bold ( ) )
62
56
}
63
57
58
+ pub ( crate ) fn diff_added ( self ) -> Self {
59
+ self . restyle ( Style :: new ( ) . fg ( Green ) )
60
+ }
61
+
62
+ pub ( crate ) fn diff_deleted ( self ) -> Self {
63
+ self . restyle ( Style :: new ( ) . fg ( Red ) )
64
+ }
65
+
64
66
pub ( crate ) fn doc ( self ) -> Self {
65
67
self . restyle ( Style :: new ( ) . fg ( Blue ) )
66
68
}
@@ -69,6 +71,14 @@ impl Color {
69
71
self . restyle ( Style :: new ( ) . fg ( Cyan ) )
70
72
}
71
73
74
+ fn effective_style ( & self ) -> Style {
75
+ if self . active ( ) {
76
+ self . style
77
+ } else {
78
+ Style :: new ( )
79
+ }
80
+ }
81
+
72
82
pub ( crate ) fn error ( self ) -> Self {
73
83
self . restyle ( Style :: new ( ) . fg ( Red ) . bold ( ) )
74
84
}
@@ -77,65 +87,59 @@ impl Color {
77
87
self . restyle ( Style :: new ( ) . fg ( Yellow ) . bold ( ) )
78
88
}
79
89
80
- pub ( crate ) fn warning ( self ) -> Self {
81
- self . restyle ( Style :: new ( ) . fg ( Yellow ) . bold ( ) )
90
+ pub ( crate ) fn message ( self ) -> Self {
91
+ self . restyle ( Style :: new ( ) . bold ( ) )
82
92
}
83
93
84
- pub ( crate ) fn banner ( self ) -> Self {
85
- self . restyle ( Style :: new ( ) . fg ( Cyan ) . bold ( ) )
94
+ pub ( crate ) fn never ( ) -> Self {
95
+ Self {
96
+ use_color : UseColor :: Never ,
97
+ ..Self :: default ( )
98
+ }
86
99
}
87
100
88
- pub ( crate ) fn command ( self , foreground : Option < ansi_term:: Color > ) -> Self {
89
- self . restyle ( Style {
90
- foreground,
91
- is_bold : true ,
92
- ..Style :: default ( )
93
- } )
101
+ pub ( crate ) fn paint < ' a > ( & self , text : & ' a str ) -> ANSIGenericString < ' a , str > {
102
+ self . effective_style ( ) . paint ( text)
94
103
}
95
104
96
105
pub ( crate ) fn parameter ( self ) -> Self {
97
106
self . restyle ( Style :: new ( ) . fg ( Cyan ) )
98
107
}
99
108
100
- pub ( crate ) fn message ( self ) -> Self {
101
- self . restyle ( Style :: new ( ) . bold ( ) )
102
- }
103
-
104
- pub ( crate ) fn annotation ( self ) -> Self {
105
- self . restyle ( Style :: new ( ) . fg ( Purple ) )
106
- }
107
-
108
- pub ( crate ) fn string ( self ) -> Self {
109
- self . restyle ( Style :: new ( ) . fg ( Green ) )
109
+ pub ( crate ) fn prefix ( & self ) -> Prefix {
110
+ self . effective_style ( ) . prefix ( )
110
111
}
111
112
112
- pub ( crate ) fn diff_added ( self ) -> Self {
113
- self . restyle ( Style :: new ( ) . fg ( Green ) )
113
+ fn redirect ( self , stream : impl IsTerminal ) -> Self {
114
+ Self {
115
+ is_terminal : stream. is_terminal ( ) ,
116
+ ..self
117
+ }
114
118
}
115
119
116
- pub ( crate ) fn diff_deleted ( self ) -> Self {
117
- self . restyle ( Style :: new ( ) . fg ( Red ) )
120
+ fn restyle ( self , style : Style ) -> Self {
121
+ Self { style , .. self }
118
122
}
119
123
120
- pub ( crate ) fn active ( & self ) -> bool {
121
- match self . use_color {
122
- UseColor :: Always => true ,
123
- UseColor :: Never => false ,
124
- UseColor :: Auto => self . is_terminal ,
125
- }
124
+ pub ( crate ) fn stderr ( self ) -> Self {
125
+ self . redirect ( io:: stderr ( ) )
126
126
}
127
127
128
- pub ( crate ) fn paint < ' a > ( & self , text : & ' a str ) -> ANSIGenericString < ' a , str > {
129
- self . effective_style ( ) . paint ( text )
128
+ pub ( crate ) fn stdout ( self ) -> Self {
129
+ self . redirect ( io :: stdout ( ) )
130
130
}
131
131
132
- pub ( crate ) fn prefix ( & self ) -> Prefix {
133
- self . effective_style ( ) . prefix ( )
132
+ pub ( crate ) fn string ( self ) -> Self {
133
+ self . restyle ( Style :: new ( ) . fg ( Green ) )
134
134
}
135
135
136
136
pub ( crate ) fn suffix ( & self ) -> Suffix {
137
137
self . effective_style ( ) . suffix ( )
138
138
}
139
+
140
+ pub ( crate ) fn warning ( self ) -> Self {
141
+ self . restyle ( Style :: new ( ) . fg ( Yellow ) . bold ( ) )
142
+ }
139
143
}
140
144
141
145
impl From < UseColor > for Color {
0 commit comments