Debian Codegraph @

src/lib.rs

raw symbols ◀ ▶ SCIP
2 Debian patches touch this file
1 //!Coloring terminal so simple, you already know how to do it !
2 //!
3 //! use colored::Colorize;
4 //!
5 //! "this is blue".blue();
6 //! "this is red".red();
7 //! "this is red on blue".red().on_blue();
8 //! "this is also red on blue".on_blue().red();
9 //! "you can use truecolor values too!".truecolor(0, 255, 136);
10 //! "background truecolor also works :)".on_truecolor(135, 28, 167);
11 //! "you can also make bold text".bold();
12 //! println!("{} {} {}", "or use".cyan(), "any".italic().yellow(), "string type".cyan());
13 //! "or change advice. This is red".yellow().blue().red();
14 //! "or clear things up. This is default color and style".red().bold().clear();
15 //! "purple and magenta are the same".purple().magenta();
16 //! "bright colors are also allowed".bright_blue().on_bright_white();
17 //! "you can specify color by string".color("blue").on_color("red");
18 //! "and so are normal and clear".normal().clear();
19 //! String::from("this also works!").green().bold();
20 //! format!("{:30}", "format works as expected. This will be padded".blue());
21 //! format!("{:.3}", "and this will be green but truncated to 3 chars".green());
22 //!
23 //!
24 //! See [the `Colorize` trait](./trait.Colorize.html) for all the methods.
25 //!
26 //! Note: The methods of [`Colorize`], when used on [`str`]'s, return
27 //! [`ColoredString`]'s. See [`ColoredString`] to learn more about them and
28 //! what you can do with them beyond continuing to use [`Colorize`] to further
29 //! modify them.
30 #![warn(missing_docs)]
31
32
33 mod colorrust-analyzer cargo colored 3.1.1 color/;
34 pub mod controlrust-analyzer cargo colored 3.1.1 control/;
35 mod errorrust-analyzer cargo colored 3.1.1 error/;
36 mod stylerust-analyzer cargo colored 3.1.1 style/;
37
38 pub use selfrust-analyzer cargo colored 3.1.1 crate/::customcolorsrust-analyzer cargo colored 3.1.1 customcolors/::CustomColorrust-analyzer cargo colored 3.1.1 customcolors/CustomColor#;
39
40 /// Custom colors support.
41 pub mod customcolorsrust-analyzer cargo colored 3.1.1 customcolors/;
42
43 pub use colorrust-analyzer cargo colored 3.1.1 color/::*;
44
45 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{
46 borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#,
47 errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#,
48 fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/,
49 opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::{Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#, DerefMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/DerefMut#},
50 };
51
52 pub use stylerust-analyzer cargo colored 3.1.1 style/::{Stylerust-analyzer cargo colored 3.1.1 style/Style#, Stylesrust-analyzer cargo colored 3.1.1 style/Styles#};
53
54 /// A string that may have color and/or style applied to it.
55 ///
56 /// Commonly created via calling the methods of [`Colorize`] on a &str.
57 /// All methods of [`Colorize`] either create a new `ColoredString` from
58 /// the type called on or modify a callee `ColoredString`. See
59 /// [`Colorize`] for more.
60 ///
61 /// The primary usage of `ColoredString`'s is as a way to take text,
62 /// apply colors and miscellaneous styling to it (such as bold or
63 /// underline), and then use it to create formatted strings that print
64 /// to the console with the special styling applied.
65 ///
66 /// ## Usage
67 ///
68 /// As stated, `ColoredString`'s, once created, can be printed to the
69 /// console with their colors and style or turned into a string
70 /// containing special console codes that has the same effect.
71 /// This is made easy via `ColoredString`'s implementations of
72 /// [`Display`](std::fmt::Display) and [`ToString`] for those purposes
73 /// respectively.
74 ///
75 /// Printing a `ColoredString` with its style is as easy as:
76 ///
77 /// ```
78 /// # use colored::*;
79 /// let cstring: ColoredString = "Bold and Red!".bold().red();
80 /// println!("{}", cstring);
81 /// ```
82 ///
83 /// ## Manipulating the coloring/style of a `ColoredString`
84 ///
85 /// Getting or changing the foreground color, background color, and or
86 /// style of a `ColoredString` is as easy as manually reading / modifying
87 /// the fields of `ColoredString`.
88 ///
89 /// ```
90 /// # use colored::*;
91 /// let mut red_text = "Red".red();
92 /// // Changing color using re-assignment and [`Colorize`]:
93 /// red_text = red_text.blue();
94 /// // Manipulating fields of `ColoredString` in-place:
95 /// red_text.fgcolor = Some(Color::Blue);
96 ///
97 /// let styled_text1 = "Bold".bold();
98 /// let styled_text2 = "Italic".italic();
99 /// let mut styled_text3 = ColoredString::from("Bold and Italic");
100 /// styled_text3.style = styled_text1.style | styled_text2.style;
101 /// ```
102 ///
103 /// ## Modifying the text of a `ColoredString`
104 ///
105 /// Modifying the text is as easy as modifying the `input` field of
106 /// `ColoredString`...
107 ///
108 /// ```
109 /// # use colored::*;
110 /// let mut colored_text = "Magenta".magenta();
111 /// colored_text = colored_text.blue();
112 /// colored_text.input = "Blue".to_string();
113 /// // Note: The above is inefficient and `colored_text.input.replace_range(.., "Blue")` would
114 /// // be more proper. This is just for example.
115 ///
116 /// assert_eq!(&*colored_text, "Blue");
117 /// ```
118 ///
119 /// Notice how this process preserves the coloring and style.
120 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)]
121 #[non_exhaustive]
122 pub struct ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
123 /// The plain text that will have color and style applied to it.
124 pub inputrust-analyzer cargo colored 3.1.1 ColoredString#input.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
125
126 /// The color of the text as it will be printed.
127 pub fgcolorrust-analyzer cargo colored 3.1.1 ColoredString#fgcolor.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Colorrust-analyzer cargo colored 3.1.1 color/Color#>,
128
129 /// The background color (if any). None means that the text will be printed
130 /// without a special background.
131 pub bgcolorrust-analyzer cargo colored 3.1.1 ColoredString#bgcolor.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Colorrust-analyzer cargo colored 3.1.1 color/Color#>,
132
133 /// Any special styling to be applied to the text (see Styles for a list of
134 /// available options).
135 pub stylerust-analyzer cargo colored 3.1.1 ColoredString#style.: stylerust-analyzer cargo colored 3.1.1 style/::Stylerust-analyzer cargo colored 3.1.1 style/Style#,
136 }
137
138 /// The trait that enables something to be given color.
139 ///
140 /// You can use `colored` effectively simply by importing this trait
141 /// and then using its methods on `String` and `&str`.
142 #[allow(missing_docs)]
143 pub trait Colorizerust-analyzer cargo colored 3.1.1 Colorize#: Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# {
144 // Font Colors
145 fn blackrust-analyzer cargo colored 3.1.1 Colorize#black().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
146 self.colorrust-analyzer cargo colored 3.1.1 Colorize#color().(Colorrust-analyzer cargo colored 3.1.1 color/Color#::Blackrust-analyzer cargo colored 3.1.1 color/Color#Black#)
147 }
148 fn redrust-analyzer cargo colored 3.1.1 Colorize#red().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
149 self.colorrust-analyzer cargo colored 3.1.1 Colorize#color().(Colorrust-analyzer cargo colored 3.1.1 color/Color#::Redrust-analyzer cargo colored 3.1.1 color/Color#Red#)
150 }
151 fn greenrust-analyzer cargo colored 3.1.1 Colorize#green().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
152 self.colorrust-analyzer cargo colored 3.1.1 Colorize#color().(Colorrust-analyzer cargo colored 3.1.1 color/Color#::Greenrust-analyzer cargo colored 3.1.1 color/Color#Green#)
153 }
154 fn yellowrust-analyzer cargo colored 3.1.1 Colorize#yellow().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
155 self.colorrust-analyzer cargo colored 3.1.1 Colorize#color().(Colorrust-analyzer cargo colored 3.1.1 color/Color#::Yellowrust-analyzer cargo colored 3.1.1 color/Color#Yellow#)
156 }
157 fn bluerust-analyzer cargo colored 3.1.1 Colorize#blue().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
158 self.colorrust-analyzer cargo colored 3.1.1 Colorize#color().(Colorrust-analyzer cargo colored 3.1.1 color/Color#::Bluerust-analyzer cargo colored 3.1.1 color/Color#Blue#)
159 }
160 fn magentarust-analyzer cargo colored 3.1.1 Colorize#magenta().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
161 self.colorrust-analyzer cargo colored 3.1.1 Colorize#color().(Colorrust-analyzer cargo colored 3.1.1 color/Color#::Magentarust-analyzer cargo colored 3.1.1 color/Color#Magenta#)
162 }
163 fn purplerust-analyzer cargo colored 3.1.1 Colorize#purple().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
164 self.colorrust-analyzer cargo colored 3.1.1 Colorize#color().(Colorrust-analyzer cargo colored 3.1.1 color/Color#::Magentarust-analyzer cargo colored 3.1.1 color/Color#Magenta#)
165 }
166 fn cyanrust-analyzer cargo colored 3.1.1 Colorize#cyan().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
167 self.colorrust-analyzer cargo colored 3.1.1 Colorize#color().(Colorrust-analyzer cargo colored 3.1.1 color/Color#::Cyanrust-analyzer cargo colored 3.1.1 color/Color#Cyan#)
168 }
169 fn whiterust-analyzer cargo colored 3.1.1 Colorize#white().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
170 self.colorrust-analyzer cargo colored 3.1.1 Colorize#color().(Colorrust-analyzer cargo colored 3.1.1 color/Color#::Whiterust-analyzer cargo colored 3.1.1 color/Color#White#)
171 }
172 fn bright_blackrust-analyzer cargo colored 3.1.1 Colorize#bright_black().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
173 self.colorrust-analyzer cargo colored 3.1.1 Colorize#color().(Colorrust-analyzer cargo colored 3.1.1 color/Color#::BrightBlackrust-analyzer cargo colored 3.1.1 color/Color#BrightBlack#)
174 }
175 fn bright_redrust-analyzer cargo colored 3.1.1 Colorize#bright_red().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
176 self.colorrust-analyzer cargo colored 3.1.1 Colorize#color().(Colorrust-analyzer cargo colored 3.1.1 color/Color#::BrightRedrust-analyzer cargo colored 3.1.1 color/Color#BrightRed#)
177 }
178 fn bright_greenrust-analyzer cargo colored 3.1.1 Colorize#bright_green().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
179 self.colorrust-analyzer cargo colored 3.1.1 Colorize#color().(Colorrust-analyzer cargo colored 3.1.1 color/Color#::BrightGreenrust-analyzer cargo colored 3.1.1 color/Color#BrightGreen#)
180 }
181 fn bright_yellowrust-analyzer cargo colored 3.1.1 Colorize#bright_yellow().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
182 self.colorrust-analyzer cargo colored 3.1.1 Colorize#color().(Colorrust-analyzer cargo colored 3.1.1 color/Color#::BrightYellowrust-analyzer cargo colored 3.1.1 color/Color#BrightYellow#)
183 }
184 fn bright_bluerust-analyzer cargo colored 3.1.1 Colorize#bright_blue().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
185 self.colorrust-analyzer cargo colored 3.1.1 Colorize#color().(Colorrust-analyzer cargo colored 3.1.1 color/Color#::BrightBluerust-analyzer cargo colored 3.1.1 color/Color#BrightBlue#)
186 }
187 fn bright_magentarust-analyzer cargo colored 3.1.1 Colorize#bright_magenta().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
188 self.colorrust-analyzer cargo colored 3.1.1 Colorize#color().(Colorrust-analyzer cargo colored 3.1.1 color/Color#::BrightMagentarust-analyzer cargo colored 3.1.1 color/Color#BrightMagenta#)
189 }
190 fn bright_purplerust-analyzer cargo colored 3.1.1 Colorize#bright_purple().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
191 self.colorrust-analyzer cargo colored 3.1.1 Colorize#color().(Colorrust-analyzer cargo colored 3.1.1 color/Color#::BrightMagentarust-analyzer cargo colored 3.1.1 color/Color#BrightMagenta#)
192 }
193 fn bright_cyanrust-analyzer cargo colored 3.1.1 Colorize#bright_cyan().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
194 self.colorrust-analyzer cargo colored 3.1.1 Colorize#color().(Colorrust-analyzer cargo colored 3.1.1 color/Color#::BrightCyanrust-analyzer cargo colored 3.1.1 color/Color#BrightCyan#)
195 }
196 fn bright_whiterust-analyzer cargo colored 3.1.1 Colorize#bright_white().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
197 self.colorrust-analyzer cargo colored 3.1.1 Colorize#color().(Colorrust-analyzer cargo colored 3.1.1 color/Color#::BrightWhiterust-analyzer cargo colored 3.1.1 color/Color#BrightWhite#)
198 }
199 fn truecolorrust-analyzer cargo colored 3.1.1 Colorize#truecolor().(self, r: u8, g: u8, b: u8) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
200 self.colorrust-analyzer cargo colored 3.1.1 Colorize#color().(Colorrust-analyzer cargo colored 3.1.1 color/Color#::TrueColorrust-analyzer cargo colored 3.1.1 color/Color#TrueColor# { rrust-analyzer cargo colored 3.1.1 color/Color#TrueColor#r., grust-analyzer cargo colored 3.1.1 color/Color#TrueColor#g., brust-analyzer cargo colored 3.1.1 color/Color#TrueColor#b. })
201 }
202 fn custom_colorrust-analyzer cargo colored 3.1.1 Colorize#custom_color().<C: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<CustomColorrust-analyzer cargo colored 3.1.1 customcolors/CustomColor#>>(self, color: C) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
203 let color = color.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().();
204
205 self.colorrust-analyzer cargo colored 3.1.1 Colorize#color().(Colorrust-analyzer cargo colored 3.1.1 color/Color#::TrueColorrust-analyzer cargo colored 3.1.1 color/Color#TrueColor# {
206 rrust-analyzer cargo colored 3.1.1 color/Color#TrueColor#r.: color.rrust-analyzer cargo colored 3.1.1 customcolors/CustomColor#r.,
207 grust-analyzer cargo colored 3.1.1 color/Color#TrueColor#g.: color.grust-analyzer cargo colored 3.1.1 customcolors/CustomColor#g.,
208 brust-analyzer cargo colored 3.1.1 color/Color#TrueColor#b.: color.brust-analyzer cargo colored 3.1.1 customcolors/CustomColor#b.,
209 })
210 }
211 fn ansi_colorrust-analyzer cargo colored 3.1.1 Colorize#ansi_color().<T: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<u8>>(self, color: T) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
212 self.colorrust-analyzer cargo colored 3.1.1 Colorize#color().(Colorrust-analyzer cargo colored 3.1.1 color/Color#::AnsiColorrust-analyzer cargo colored 3.1.1 color/Color#AnsiColor#(color.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().()))
213 }
214 fn colorrust-analyzer cargo colored 3.1.1 Colorize#color().<C: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Colorrust-analyzer cargo colored 3.1.1 color/Color#>>(self, color: C) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString#;
215
216 // Background Colors
217 fn on_blackrust-analyzer cargo colored 3.1.1 Colorize#on_black().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
218 self.on_colorrust-analyzer cargo colored 3.1.1 Colorize#on_color().(Colorrust-analyzer cargo colored 3.1.1 color/Color#::Blackrust-analyzer cargo colored 3.1.1 color/Color#Black#)
219 }
220 fn on_redrust-analyzer cargo colored 3.1.1 Colorize#on_red().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
221 self.on_colorrust-analyzer cargo colored 3.1.1 Colorize#on_color().(Colorrust-analyzer cargo colored 3.1.1 color/Color#::Redrust-analyzer cargo colored 3.1.1 color/Color#Red#)
222 }
223 fn on_greenrust-analyzer cargo colored 3.1.1 Colorize#on_green().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
224 self.on_colorrust-analyzer cargo colored 3.1.1 Colorize#on_color().(Colorrust-analyzer cargo colored 3.1.1 color/Color#::Greenrust-analyzer cargo colored 3.1.1 color/Color#Green#)
225 }
226 fn on_yellowrust-analyzer cargo colored 3.1.1 Colorize#on_yellow().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
227 self.on_colorrust-analyzer cargo colored 3.1.1 Colorize#on_color().(Colorrust-analyzer cargo colored 3.1.1 color/Color#::Yellowrust-analyzer cargo colored 3.1.1 color/Color#Yellow#)
228 }
229 fn on_bluerust-analyzer cargo colored 3.1.1 Colorize#on_blue().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
230 self.on_colorrust-analyzer cargo colored 3.1.1 Colorize#on_color().(Colorrust-analyzer cargo colored 3.1.1 color/Color#::Bluerust-analyzer cargo colored 3.1.1 color/Color#Blue#)
231 }
232 fn on_magentarust-analyzer cargo colored 3.1.1 Colorize#on_magenta().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
233 self.on_colorrust-analyzer cargo colored 3.1.1 Colorize#on_color().(Colorrust-analyzer cargo colored 3.1.1 color/Color#::Magentarust-analyzer cargo colored 3.1.1 color/Color#Magenta#)
234 }
235 fn on_purplerust-analyzer cargo colored 3.1.1 Colorize#on_purple().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
236 self.on_colorrust-analyzer cargo colored 3.1.1 Colorize#on_color().(Colorrust-analyzer cargo colored 3.1.1 color/Color#::Magentarust-analyzer cargo colored 3.1.1 color/Color#Magenta#)
237 }
238 fn on_cyanrust-analyzer cargo colored 3.1.1 Colorize#on_cyan().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
239 self.on_colorrust-analyzer cargo colored 3.1.1 Colorize#on_color().(Colorrust-analyzer cargo colored 3.1.1 color/Color#::Cyanrust-analyzer cargo colored 3.1.1 color/Color#Cyan#)
240 }
241 fn on_whiterust-analyzer cargo colored 3.1.1 Colorize#on_white().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
242 self.on_colorrust-analyzer cargo colored 3.1.1 Colorize#on_color().(Colorrust-analyzer cargo colored 3.1.1 color/Color#::Whiterust-analyzer cargo colored 3.1.1 color/Color#White#)
243 }
244 fn on_bright_blackrust-analyzer cargo colored 3.1.1 Colorize#on_bright_black().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
245 self.on_colorrust-analyzer cargo colored 3.1.1 Colorize#on_color().(Colorrust-analyzer cargo colored 3.1.1 color/Color#::BrightBlackrust-analyzer cargo colored 3.1.1 color/Color#BrightBlack#)
246 }
247 fn on_bright_redrust-analyzer cargo colored 3.1.1 Colorize#on_bright_red().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
248 self.on_colorrust-analyzer cargo colored 3.1.1 Colorize#on_color().(Colorrust-analyzer cargo colored 3.1.1 color/Color#::BrightRedrust-analyzer cargo colored 3.1.1 color/Color#BrightRed#)
249 }
250 fn on_bright_greenrust-analyzer cargo colored 3.1.1 Colorize#on_bright_green().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
251 self.on_colorrust-analyzer cargo colored 3.1.1 Colorize#on_color().(Colorrust-analyzer cargo colored 3.1.1 color/Color#::BrightGreenrust-analyzer cargo colored 3.1.1 color/Color#BrightGreen#)
252 }
253 fn on_bright_yellowrust-analyzer cargo colored 3.1.1 Colorize#on_bright_yellow().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
254 self.on_colorrust-analyzer cargo colored 3.1.1 Colorize#on_color().(Colorrust-analyzer cargo colored 3.1.1 color/Color#::BrightYellowrust-analyzer cargo colored 3.1.1 color/Color#BrightYellow#)
255 }
256 fn on_bright_bluerust-analyzer cargo colored 3.1.1 Colorize#on_bright_blue().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
257 self.on_colorrust-analyzer cargo colored 3.1.1 Colorize#on_color().(Colorrust-analyzer cargo colored 3.1.1 color/Color#::BrightBluerust-analyzer cargo colored 3.1.1 color/Color#BrightBlue#)
258 }
259 fn on_bright_magentarust-analyzer cargo colored 3.1.1 Colorize#on_bright_magenta().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
260 self.on_colorrust-analyzer cargo colored 3.1.1 Colorize#on_color().(Colorrust-analyzer cargo colored 3.1.1 color/Color#::BrightMagentarust-analyzer cargo colored 3.1.1 color/Color#BrightMagenta#)
261 }
262 fn on_bright_purplerust-analyzer cargo colored 3.1.1 Colorize#on_bright_purple().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
263 self.on_colorrust-analyzer cargo colored 3.1.1 Colorize#on_color().(Colorrust-analyzer cargo colored 3.1.1 color/Color#::BrightMagentarust-analyzer cargo colored 3.1.1 color/Color#BrightMagenta#)
264 }
265 fn on_bright_cyanrust-analyzer cargo colored 3.1.1 Colorize#on_bright_cyan().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
266 self.on_colorrust-analyzer cargo colored 3.1.1 Colorize#on_color().(Colorrust-analyzer cargo colored 3.1.1 color/Color#::BrightCyanrust-analyzer cargo colored 3.1.1 color/Color#BrightCyan#)
267 }
268 fn on_bright_whiterust-analyzer cargo colored 3.1.1 Colorize#on_bright_white().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
269 self.on_colorrust-analyzer cargo colored 3.1.1 Colorize#on_color().(Colorrust-analyzer cargo colored 3.1.1 color/Color#::BrightWhiterust-analyzer cargo colored 3.1.1 color/Color#BrightWhite#)
270 }
271 fn on_truecolorrust-analyzer cargo colored 3.1.1 Colorize#on_truecolor().(self, r: u8, g: u8, b: u8) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
272 self.on_colorrust-analyzer cargo colored 3.1.1 Colorize#on_color().(Colorrust-analyzer cargo colored 3.1.1 color/Color#::TrueColorrust-analyzer cargo colored 3.1.1 color/Color#TrueColor# { rrust-analyzer cargo colored 3.1.1 color/Color#TrueColor#r., grust-analyzer cargo colored 3.1.1 color/Color#TrueColor#g., brust-analyzer cargo colored 3.1.1 color/Color#TrueColor#b. })
273 }
274 fn on_custom_colorrust-analyzer cargo colored 3.1.1 Colorize#on_custom_color().<C: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<CustomColorrust-analyzer cargo colored 3.1.1 customcolors/CustomColor#>>(self, color: C) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
275 let color = color.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().();
276
277 self.on_colorrust-analyzer cargo colored 3.1.1 Colorize#on_color().(Colorrust-analyzer cargo colored 3.1.1 color/Color#::TrueColorrust-analyzer cargo colored 3.1.1 color/Color#TrueColor# {
278 rrust-analyzer cargo colored 3.1.1 color/Color#TrueColor#r.: color.rrust-analyzer cargo colored 3.1.1 customcolors/CustomColor#r.,
279 grust-analyzer cargo colored 3.1.1 color/Color#TrueColor#g.: color.grust-analyzer cargo colored 3.1.1 customcolors/CustomColor#g.,
280 brust-analyzer cargo colored 3.1.1 color/Color#TrueColor#b.: color.brust-analyzer cargo colored 3.1.1 customcolors/CustomColor#b.,
281 })
282 }
283 fn on_ansi_colorrust-analyzer cargo colored 3.1.1 Colorize#on_ansi_color().<T: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<u8>>(self, color: T) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
284 self.on_colorrust-analyzer cargo colored 3.1.1 Colorize#on_color().(Colorrust-analyzer cargo colored 3.1.1 color/Color#::AnsiColorrust-analyzer cargo colored 3.1.1 color/Color#AnsiColor#(color.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().()))
285 }
286 fn on_colorrust-analyzer cargo colored 3.1.1 Colorize#on_color().<C: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Colorrust-analyzer cargo colored 3.1.1 color/Color#>>(self, color: C) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString#;
287
288 // Styles
289 fn clearrust-analyzer cargo colored 3.1.1 Colorize#clear().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString#;
290 fn normalrust-analyzer cargo colored 3.1.1 Colorize#normal().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString#;
291 fn boldrust-analyzer cargo colored 3.1.1 Colorize#bold().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString#;
292 fn dimmedrust-analyzer cargo colored 3.1.1 Colorize#dimmed().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString#;
293 fn italicrust-analyzer cargo colored 3.1.1 Colorize#italic().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString#;
294 fn underlinerust-analyzer cargo colored 3.1.1 Colorize#underline().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString#;
295 fn blinkrust-analyzer cargo colored 3.1.1 Colorize#blink().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString#;
296 #[deprecated(since = "1.5.2", note = "Users should use reversed instead")]
297 fn reverserust-analyzer cargo colored 3.1.1 Colorize#reverse().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString#;
298 fn reversedrust-analyzer cargo colored 3.1.1 Colorize#reversed().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString#;
299 fn hiddenrust-analyzer cargo colored 3.1.1 Colorize#hidden().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString#;
300 fn strikethroughrust-analyzer cargo colored 3.1.1 Colorize#strikethrough().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString#;
301 }
302
303 impl ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
304 /// Get the current background color applied.
305 ///
306 /// ```rust
307 /// # use colored::*;
308 /// let cstr = "".blue();
309 /// assert_eq!(cstr.fgcolor(), Some(Color::Blue));
310 /// let cstr = cstr.clear();
311 /// assert_eq!(cstr.fgcolor(), None);
312 /// ```
313 #[deprecated(note = "Deprecated due to the exposing of the fgcolor struct field.")]
314 #[must_use]
315 pub fn fgcolorrust-analyzer cargo colored 3.1.1 impl#[ColoredString]fgcolor().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Colorrust-analyzer cargo colored 3.1.1 color/Color#> {
316 self.fgcolorrust-analyzer cargo colored 3.1.1 ColoredString#fgcolor..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().copiedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<&T>`]copied().()
317 }
318
319 /// Get the current background color applied.
320 ///
321 /// ```rust
322 /// # use colored::*;
323 /// let cstr = "".on_blue();
324 /// assert_eq!(cstr.bgcolor(), Some(Color::Blue));
325 /// let cstr = cstr.clear();
326 /// assert_eq!(cstr.bgcolor(), None);
327 /// ```
328 #[deprecated(note = "Deprecated due to the exposing of the bgcolor struct field.")]
329 #[must_use]
330 pub fn bgcolorrust-analyzer cargo colored 3.1.1 impl#[ColoredString]bgcolor().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Colorrust-analyzer cargo colored 3.1.1 color/Color#> {
331 self.bgcolorrust-analyzer cargo colored 3.1.1 ColoredString#bgcolor..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().copiedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<&T>`]copied().()
332 }
333
334 /// Get the current [`Style`] which can be check if it contains a [`Styles`].
335 ///
336 /// ```rust
337 /// # use colored::*;
338 /// let colored = "".bold().italic();
339 /// assert_eq!(colored.style().contains(Styles::Bold), true);
340 /// assert_eq!(colored.style().contains(Styles::Italic), true);
341 /// assert_eq!(colored.style().contains(Styles::Dimmed), false);
342 /// ```
343 #[deprecated(note = "Deprecated due to the exposing of the style struct field.")]
344 #[must_use]
345 pub fn stylerust-analyzer cargo colored 3.1.1 impl#[ColoredString]style().(&self) -> stylerust-analyzer cargo colored 3.1.1 style/::Stylerust-analyzer cargo colored 3.1.1 style/Style# {
346 self.stylerust-analyzer cargo colored 3.1.1 ColoredString#style.
347 }
348
349 /// Clears foreground coloring on this `ColoredString`, meaning that it
350 /// will be printed with the default terminal text color.
351 pub fn clear_fgcolorrust-analyzer cargo colored 3.1.1 impl#[ColoredString]clear_fgcolor().(&mut self) {
352 self.fgcolorrust-analyzer cargo colored 3.1.1 ColoredString#fgcolor. = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
353 }
354
355 /// Gets rid of this `ColoredString`'s background.
356 pub fn clear_bgcolorrust-analyzer cargo colored 3.1.1 impl#[ColoredString]clear_bgcolor().(&mut self) {
357 self.bgcolorrust-analyzer cargo colored 3.1.1 ColoredString#bgcolor. = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
358 }
359
360 /// Clears any special styling and sets it back to the default (plain,
361 /// maybe colored, text).
362 pub fn clear_stylerust-analyzer cargo colored 3.1.1 impl#[ColoredString]clear_style().(&mut self) {
363 self.stylerust-analyzer cargo colored 3.1.1 ColoredString#style. = Stylerust-analyzer cargo colored 3.1.1 style/Style#::defaultrust-analyzer cargo colored 3.1.1 style/impl#[Style][Default]default().();
364 }
365
366 /// Checks if the colored string has no color or styling.
367 ///
368 /// ```rust
369 /// # use colored::*;
370 /// let cstr = "".red();
371 /// assert_eq!(cstr.is_plain(), false);
372 /// let cstr = cstr.clear();
373 /// assert_eq!(cstr.is_plain(), true);
374 /// ```
375 #[must_use]
376 pub fn is_plainrust-analyzer cargo colored 3.1.1 impl#[ColoredString]is_plain().(&self) -> bool {
377 self.bgcolorrust-analyzer cargo colored 3.1.1 ColoredString#bgcolor..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() && self.fgcolorrust-analyzer cargo colored 3.1.1 ColoredString#fgcolor..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() && self.stylerust-analyzer cargo colored 3.1.1 ColoredString#style. rust-analyzer cargo colored 3.1.1 style/impl#[Style][`PartialEq<Self>`]eq().==rust-analyzer cargo colored 3.1.1 style/impl#[Style][`PartialEq<Self>`]eq(). rust-analyzer cargo colored 3.1.1 style/impl#[Style][`PartialEq<Self>`]eq().stylerust-analyzer cargo colored 3.1.1 style/::CLEARrust-analyzer cargo colored 3.1.1 style/CLEAR.
378 }
379
380 #[cfg(not(feature = "no-color"))]
381 fn has_colors() -> bool {
382 controlrust-analyzer cargo colored 3.1.1 control/::SHOULD_COLORIZErust-analyzer cargo colored 3.1.1 control/SHOULD_COLORIZE..should_colorize()
383 }
384
385 #[cfg(feature = "no-color")]
386 const fn has_colorsrust-analyzer cargo colored 3.1.1 impl#[ColoredString]has_colors().() -> bool {
387 false
388 }
389
390 fn compute_stylerust-analyzer cargo colored 3.1.1 impl#[ColoredString]compute_style().(&self) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
391 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().Selfrust-analyzer cargo colored 3.1.1 impl#[ColoredString]::has_colorsrust-analyzer cargo colored 3.1.1 impl#[ColoredString]has_colors().() || self.is_plainrust-analyzer cargo colored 3.1.1 impl#[ColoredString]is_plain().() {
392 return Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().();
393 }
394
395 let mut res = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`From<&str>`]from().("\x1B[");
396 let mut has_written = if self.stylerust-analyzer cargo colored 3.1.1 ColoredString#style. rust-analyzer cargo colored 3.1.1 style/impl#[Style][`PartialEq<Self>`]eq().==rust-analyzer cargo colored 3.1.1 style/impl#[Style][`PartialEq<Self>`]eq(). rust-analyzer cargo colored 3.1.1 style/impl#[Style][`PartialEq<Self>`]eq().stylerust-analyzer cargo colored 3.1.1 style/::CLEARrust-analyzer cargo colored 3.1.1 style/CLEAR. {
397 false
398 } else {
399 res.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(&self.stylerust-analyzer cargo colored 3.1.1 ColoredString#style..to_strrust-analyzer cargo colored 3.1.1 style/impl#[Style]to_str().());
400 true
401 };
402
403 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(bgcolor) = &self.bgcolorrust-analyzer cargo colored 3.1.1 ColoredString#bgcolor. {
404 if has_written {
405 res.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().(';');
406 }
407
408 res.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(&bgcolor.to_bg_strrust-analyzer cargo colored 3.1.1 color/impl#[Color]to_bg_str().());
409 has_written = true;
410 }
411
412 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(fgcolor) = &self.fgcolorrust-analyzer cargo colored 3.1.1 ColoredString#fgcolor. {
413 if has_written {
414 res.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().(';');
415 }
416
417 res.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(&fgcolor.to_fg_strrust-analyzer cargo colored 3.1.1 color/impl#[Color]to_fg_str().());
418 }
419
420 res.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('m');
421 res
422 }
423
424 fn escape_inner_reset_sequencesrust-analyzer cargo colored 3.1.1 impl#[ColoredString]escape_inner_reset_sequences().(&self) -> Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'_, str> {
425 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().Selfrust-analyzer cargo colored 3.1.1 impl#[ColoredString]::has_colorsrust-analyzer cargo colored 3.1.1 impl#[ColoredString]has_colors().() || self.is_plainrust-analyzer cargo colored 3.1.1 impl#[ColoredString]is_plain().() {
426 return self.inputrust-analyzer cargo colored 3.1.1 ColoredString#input..as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().();
427 }
428
429 // TODO: BoyScoutRule
430 let reset = "\x1B[0m";
431 let style = self.compute_stylerust-analyzer cargo colored 3.1.1 impl#[ColoredString]compute_style().();
432 let matches: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<usize> = self
433 .inputrust-analyzer cargo colored 3.1.1 ColoredString#input.
434 .match_indicesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]match_indices().(reset)
435 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(idx, _)| idx)
436 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
437 if matches.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() {
438 return self.inputrust-analyzer cargo colored 3.1.1 ColoredString#input..as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().();
439 }
440
441 let mut input = self.inputrust-analyzer cargo colored 3.1.1 ColoredString#input..clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().();
442 input.reserverust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]reserve().(matches.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().style.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]len().());
443
444 for (idx_in_matches, offset) in matches.into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() {
445 // shift the offset to the end of the reset sequence and take in account
446 // the number of matches we have escaped (which shift the index to insert)
447 let mut offset = offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().reset.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().idx_in_matches rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().style.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]len().();
448
449 for cchar in style.charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().() {
450 input.insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]insert().(offset, cchar);
451 offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
452 }
453 }
454
455 input.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()
456 }
457 }
458
459 impl Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref# for ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
460 type Targetrust-analyzer cargo colored 3.1.1 impl#[ColoredString][Deref]Target# = str;
461 fn derefrust-analyzer cargo colored 3.1.1 impl#[ColoredString][Deref]deref().(&self) -> &Selfrust-analyzer cargo colored 3.1.1 impl#[ColoredString][Deref]::Targetrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#Target# {
462 &self.inputrust-analyzer cargo colored 3.1.1 ColoredString#input.
463 }
464 }
465
466 impl DerefMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/DerefMut# for ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
467 fn deref_mutrust-analyzer cargo colored 3.1.1 impl#[ColoredString][DerefMut]deref_mut().(&mut self) -> &mut <Selfrust-analyzer cargo colored 3.1.1 impl#[ColoredString][DerefMut] as Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#>::Targetrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#Target# {
468 &mut self.inputrust-analyzer cargo colored 3.1.1 ColoredString#input.
469 }
470 }
471
472 impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> for ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
473 fn fromrust-analyzer cargo colored 3.1.1 impl#[ColoredString][`From<String>`]from().(s: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#) -> Selfrust-analyzer cargo colored 3.1.1 impl#[ColoredString][`From<String>`] {
474 Selfrust-analyzer cargo colored 3.1.1 impl#[ColoredString][`From<String>`] {
475 inputrust-analyzer cargo colored 3.1.1 ColoredString#input.: s,
476 ..Selfrust-analyzer cargo colored 3.1.1 impl#[ColoredString][`From<String>`]::defaultrust-analyzer cargo colored 3.1.1 impl#[ColoredString][Default]default().()
477 }
478 }
479 }
480
481 impl<'a> Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<&'a str> for ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
482 fn fromrust-analyzer cargo colored 3.1.1 impl#[ColoredString][`From<&'a str>`]from().(s: &'a str) -> Selfrust-analyzer cargo colored 3.1.1 impl#[ColoredString][`From<&'a str>`] {
483 Selfrust-analyzer cargo colored 3.1.1 impl#[ColoredString][`From<&'a str>`] {
484 inputrust-analyzer cargo colored 3.1.1 ColoredString#input.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`From<&str>`]from().(s),
485 ..Selfrust-analyzer cargo colored 3.1.1 impl#[ColoredString][`From<&'a str>`]::defaultrust-analyzer cargo colored 3.1.1 impl#[ColoredString][Default]default().()
486 }
487 }
488 }
489
490 impl Colorizerust-analyzer cargo colored 3.1.1 Colorize# for ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
491 fn colorrust-analyzer cargo colored 3.1.1 impl#[ColoredString][Colorize]color().<S: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Colorrust-analyzer cargo colored 3.1.1 color/Color#>>(mut self, color: S) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
492 self.fgcolorrust-analyzer cargo colored 3.1.1 ColoredString#fgcolor. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(color.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().());
493 self
494 }
495 fn on_colorrust-analyzer cargo colored 3.1.1 impl#[ColoredString][Colorize]on_color().<S: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Colorrust-analyzer cargo colored 3.1.1 color/Color#>>(mut self, color: S) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
496 self.bgcolorrust-analyzer cargo colored 3.1.1 ColoredString#bgcolor. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(color.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().());
497 self
498 }
499
500 fn clearrust-analyzer cargo colored 3.1.1 impl#[ColoredString][Colorize]clear().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
501 Selfrust-analyzer cargo colored 3.1.1 impl#[ColoredString][Colorize] {
502 inputrust-analyzer cargo colored 3.1.1 ColoredString#input.: self.inputrust-analyzer cargo colored 3.1.1 ColoredString#input.,
503 ..Selfrust-analyzer cargo colored 3.1.1 impl#[ColoredString][Colorize]::defaultrust-analyzer cargo colored 3.1.1 impl#[ColoredString][Default]default().()
504 }
505 }
506 fn normalrust-analyzer cargo colored 3.1.1 impl#[ColoredString][Colorize]normal().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
507 self.clearrust-analyzer cargo colored 3.1.1 impl#[ColoredString][Colorize]clear().()
508 }
509 fn boldrust-analyzer cargo colored 3.1.1 impl#[ColoredString][Colorize]bold().(mut self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
510 self.stylerust-analyzer cargo colored 3.1.1 ColoredString#style..addrust-analyzer cargo colored 3.1.1 style/impl#[Style]add().(stylerust-analyzer cargo colored 3.1.1 style/::Stylesrust-analyzer cargo colored 3.1.1 style/Styles#::Boldrust-analyzer cargo colored 3.1.1 style/Styles#Bold#);
511 self
512 }
513 fn dimmedrust-analyzer cargo colored 3.1.1 impl#[ColoredString][Colorize]dimmed().(mut self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
514 self.stylerust-analyzer cargo colored 3.1.1 ColoredString#style..addrust-analyzer cargo colored 3.1.1 style/impl#[Style]add().(stylerust-analyzer cargo colored 3.1.1 style/::Stylesrust-analyzer cargo colored 3.1.1 style/Styles#::Dimmedrust-analyzer cargo colored 3.1.1 style/Styles#Dimmed#);
515 self
516 }
517 fn italicrust-analyzer cargo colored 3.1.1 impl#[ColoredString][Colorize]italic().(mut self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
518 self.stylerust-analyzer cargo colored 3.1.1 ColoredString#style..addrust-analyzer cargo colored 3.1.1 style/impl#[Style]add().(stylerust-analyzer cargo colored 3.1.1 style/::Stylesrust-analyzer cargo colored 3.1.1 style/Styles#::Italicrust-analyzer cargo colored 3.1.1 style/Styles#Italic#);
519 self
520 }
521 fn underlinerust-analyzer cargo colored 3.1.1 impl#[ColoredString][Colorize]underline().(mut self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
522 self.stylerust-analyzer cargo colored 3.1.1 ColoredString#style..addrust-analyzer cargo colored 3.1.1 style/impl#[Style]add().(stylerust-analyzer cargo colored 3.1.1 style/::Stylesrust-analyzer cargo colored 3.1.1 style/Styles#::Underlinerust-analyzer cargo colored 3.1.1 style/Styles#Underline#);
523 self
524 }
525 fn blinkrust-analyzer cargo colored 3.1.1 impl#[ColoredString][Colorize]blink().(mut self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
526 self.stylerust-analyzer cargo colored 3.1.1 ColoredString#style..addrust-analyzer cargo colored 3.1.1 style/impl#[Style]add().(stylerust-analyzer cargo colored 3.1.1 style/::Stylesrust-analyzer cargo colored 3.1.1 style/Styles#::Blinkrust-analyzer cargo colored 3.1.1 style/Styles#Blink#);
527 self
528 }
529 fn reverserust-analyzer cargo colored 3.1.1 impl#[ColoredString][Colorize]reverse().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
530 self.reversedrust-analyzer cargo colored 3.1.1 impl#[ColoredString][Colorize]reversed().()
531 }
532 fn reversedrust-analyzer cargo colored 3.1.1 impl#[ColoredString][Colorize]reversed().(mut self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
533 self.stylerust-analyzer cargo colored 3.1.1 ColoredString#style..addrust-analyzer cargo colored 3.1.1 style/impl#[Style]add().(stylerust-analyzer cargo colored 3.1.1 style/::Stylesrust-analyzer cargo colored 3.1.1 style/Styles#::Reversedrust-analyzer cargo colored 3.1.1 style/Styles#Reversed#);
534 self
535 }
536 fn hiddenrust-analyzer cargo colored 3.1.1 impl#[ColoredString][Colorize]hidden().(mut self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
537 self.stylerust-analyzer cargo colored 3.1.1 ColoredString#style..addrust-analyzer cargo colored 3.1.1 style/impl#[Style]add().(stylerust-analyzer cargo colored 3.1.1 style/::Stylesrust-analyzer cargo colored 3.1.1 style/Styles#::Hiddenrust-analyzer cargo colored 3.1.1 style/Styles#Hidden#);
538 self
539 }
540 fn strikethroughrust-analyzer cargo colored 3.1.1 impl#[ColoredString][Colorize]strikethrough().(mut self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
541 self.stylerust-analyzer cargo colored 3.1.1 ColoredString#style..addrust-analyzer cargo colored 3.1.1 style/impl#[Style]add().(stylerust-analyzer cargo colored 3.1.1 style/::Stylesrust-analyzer cargo colored 3.1.1 style/Styles#::Strikethroughrust-analyzer cargo colored 3.1.1 style/Styles#Strikethrough#);
542 self
543 }
544 }
545
546 impl Colorizerust-analyzer cargo colored 3.1.1 Colorize# for &str {
547 fn colorrust-analyzer cargo colored 3.1.1 impl#[`&str`][Colorize]color().<S: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Colorrust-analyzer cargo colored 3.1.1 color/Color#>>(self, color: S) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
548 ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
549 fgcolorrust-analyzer cargo colored 3.1.1 ColoredString#fgcolor.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(color.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().()),
550 inputrust-analyzer cargo colored 3.1.1 ColoredString#input.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`From<&str>`]from().(self),
551 ..ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString#::defaultrust-analyzer cargo colored 3.1.1 impl#[ColoredString][Default]default().()
552 }
553 }
554
555 fn on_colorrust-analyzer cargo colored 3.1.1 impl#[`&str`][Colorize]on_color().<S: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Colorrust-analyzer cargo colored 3.1.1 color/Color#>>(self, color: S) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
556 ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
557 bgcolorrust-analyzer cargo colored 3.1.1 ColoredString#bgcolor.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(color.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().()),
558 inputrust-analyzer cargo colored 3.1.1 ColoredString#input.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`From<&str>`]from().(self),
559 ..ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString#::defaultrust-analyzer cargo colored 3.1.1 impl#[ColoredString][Default]default().()
560 }
561 }
562
563 fn clearrust-analyzer cargo colored 3.1.1 impl#[`&str`][Colorize]clear().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
564 ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
565 inputrust-analyzer cargo colored 3.1.1 ColoredString#input.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`From<&str>`]from().(self),
566 stylerust-analyzer cargo colored 3.1.1 ColoredString#style.: stylerust-analyzer cargo colored 3.1.1 style/::CLEARrust-analyzer cargo colored 3.1.1 style/CLEAR.,
567 ..ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString#::defaultrust-analyzer cargo colored 3.1.1 impl#[ColoredString][Default]default().()
568 }
569 }
570 fn normalrust-analyzer cargo colored 3.1.1 impl#[`&str`][Colorize]normal().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
571 self.clearrust-analyzer cargo colored 3.1.1 impl#[`&str`][Colorize]clear().()
572 }
573 fn boldrust-analyzer cargo colored 3.1.1 impl#[`&str`][Colorize]bold().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
574 ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString#::fromrust-analyzer cargo colored 3.1.1 impl#[ColoredString][`From<&'a str>`]from().(self).boldrust-analyzer cargo colored 3.1.1 impl#[ColoredString][Colorize]bold().()
575 }
576 fn dimmedrust-analyzer cargo colored 3.1.1 impl#[`&str`][Colorize]dimmed().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
577 ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString#::fromrust-analyzer cargo colored 3.1.1 impl#[ColoredString][`From<&'a str>`]from().(self).dimmedrust-analyzer cargo colored 3.1.1 impl#[ColoredString][Colorize]dimmed().()
578 }
579 fn italicrust-analyzer cargo colored 3.1.1 impl#[`&str`][Colorize]italic().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
580 ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString#::fromrust-analyzer cargo colored 3.1.1 impl#[ColoredString][`From<&'a str>`]from().(self).italicrust-analyzer cargo colored 3.1.1 impl#[ColoredString][Colorize]italic().()
581 }
582 fn underlinerust-analyzer cargo colored 3.1.1 impl#[`&str`][Colorize]underline().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
583 ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString#::fromrust-analyzer cargo colored 3.1.1 impl#[ColoredString][`From<&'a str>`]from().(self).underlinerust-analyzer cargo colored 3.1.1 impl#[ColoredString][Colorize]underline().()
584 }
585 fn blinkrust-analyzer cargo colored 3.1.1 impl#[`&str`][Colorize]blink().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
586 ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString#::fromrust-analyzer cargo colored 3.1.1 impl#[ColoredString][`From<&'a str>`]from().(self).blinkrust-analyzer cargo colored 3.1.1 impl#[ColoredString][Colorize]blink().()
587 }
588 fn reverserust-analyzer cargo colored 3.1.1 impl#[`&str`][Colorize]reverse().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
589 self.reversedrust-analyzer cargo colored 3.1.1 impl#[`&str`][Colorize]reversed().()
590 }
591 fn reversedrust-analyzer cargo colored 3.1.1 impl#[`&str`][Colorize]reversed().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
592 ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString#::fromrust-analyzer cargo colored 3.1.1 impl#[ColoredString][`From<&'a str>`]from().(self).reversedrust-analyzer cargo colored 3.1.1 impl#[ColoredString][Colorize]reversed().()
593 }
594 fn hiddenrust-analyzer cargo colored 3.1.1 impl#[`&str`][Colorize]hidden().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
595 ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString#::fromrust-analyzer cargo colored 3.1.1 impl#[ColoredString][`From<&'a str>`]from().(self).hiddenrust-analyzer cargo colored 3.1.1 impl#[ColoredString][Colorize]hidden().()
596 }
597 fn strikethroughrust-analyzer cargo colored 3.1.1 impl#[`&str`][Colorize]strikethrough().(self) -> ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
598 ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString#::fromrust-analyzer cargo colored 3.1.1 impl#[ColoredString][`From<&'a str>`]from().(self).strikethroughrust-analyzer cargo colored 3.1.1 impl#[ColoredString][Colorize]strikethrough().()
599 }
600 }
601
602 impl fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
603 fn fmtrust-analyzer cargo colored 3.1.1 impl#[ColoredString][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
604 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().Selfrust-analyzer cargo colored 3.1.1 impl#[ColoredString][Display]::has_colorsrust-analyzer cargo colored 3.1.1 impl#[ColoredString]has_colors().() || self.is_plainrust-analyzer cargo colored 3.1.1 impl#[ColoredString]is_plain().() {
605 return <Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# as fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#>::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Display]fmt().(&self.inputrust-analyzer cargo colored 3.1.1 ColoredString#input., f);
606 }
607
608 // XXX: see tests. Useful when nesting colored strings
609 let escaped_input = self.escape_inner_reset_sequencesrust-analyzer cargo colored 3.1.1 impl#[ColoredString]escape_inner_reset_sequences().();
610
611 f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().(&self.compute_stylerust-analyzer cargo colored 3.1.1 impl#[ColoredString]compute_style().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
612 escaped_input.fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, B>`][Display]fmt().(f)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
613 f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("\x1B[0m")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
614 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
615 }
616 }
617
618 impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString#> for Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#> {
619 fn fromrust-analyzer cargo colored 3.1.1 impl#[`Box<dyn Error + 'static>`][`From<ColoredString>`]from().(cs: ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString#) -> Selfrust-analyzer cargo colored 3.1.1 impl#[`Box<dyn Error + 'static>`][`From<ColoredString>`] {
620 Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/convert/impl#[`Box<dyn Error + 'a>`][`From<E>`]from().(errorrust-analyzer cargo colored 3.1.1 error/::ColoredStringErrorrust-analyzer cargo colored 3.1.1 error/ColoredStringError#(cs))
621 }
622 }
623
624 #[cfg(test)]
625 mod testsrust-analyzer cargo colored 3.1.1 tests/ {
626 use superrust-analyzer cargo colored 3.1.1 crate/::*;
627 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#, fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Write#};
•628 use craterust-analyzer cargo colored 3.1.1 crate/::controlrust-analyzer cargo colored 3.1.1 control/::set_overriderust-analyzer cargo colored 3.1.1 control/set_override().;
629
630 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
631 fn formattingrust-analyzer cargo colored 3.1.1 tests/formatting().() {
632 // respect the formatting. Escape sequence add some padding so >= 40
633 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{:40}", "".bluerust-analyzer cargo colored 3.1.1 Colorize#blue().()).lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]len().() >= 40);
634 // both should be truncated to 1 char before coloring
635 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
636 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{:1.1}", "toto".bluerust-analyzer cargo colored 3.1.1 Colorize#blue().()).lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]len().(),
637 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{:1.1}", "1".bluerust-analyzer cargo colored 3.1.1 Colorize#blue().()).lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]len().()
638 );
639 }
640
641 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
•642 #[ignore]
643 fn it_worksrust-analyzer cargo colored 3.1.1 tests/it_works().() -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#>> {
644 let mut buf = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().();
645 let toto = "toto";
646 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(&mut buf, "{}", toto.redrust-analyzer cargo colored 3.1.1 Colorize#red().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
647 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(&mut buf, "{}", Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`From<&str>`]from().(toto).redrust-analyzer cargo colored 3.1.1 Colorize#red().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
648 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(&mut buf, "{}", toto.bluerust-analyzer cargo colored 3.1.1 Colorize#blue().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
649
650 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(&mut buf, "blue style ****")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
651 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(&mut buf, "{}", toto.boldrust-analyzer cargo colored 3.1.1 impl#[`&str`][Colorize]bold().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
652 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(&mut buf, "{}", "yeah ! Red bold !".redrust-analyzer cargo colored 3.1.1 Colorize#red().().boldrust-analyzer cargo colored 3.1.1 impl#[ColoredString][Colorize]bold().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
653 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(&mut buf, "{}", "yeah ! Yellow bold !".boldrust-analyzer cargo colored 3.1.1 impl#[`&str`][Colorize]bold().().yellowrust-analyzer cargo colored 3.1.1 Colorize#yellow().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
654 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(&mut buf, "{}", toto.boldrust-analyzer cargo colored 3.1.1 impl#[`&str`][Colorize]bold().().bluerust-analyzer cargo colored 3.1.1 Colorize#blue().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
655 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(&mut buf, "{}", toto.bluerust-analyzer cargo colored 3.1.1 Colorize#blue().().boldrust-analyzer cargo colored 3.1.1 impl#[ColoredString][Colorize]bold().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
656 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(&mut buf, "{}", toto.bluerust-analyzer cargo colored 3.1.1 Colorize#blue().().boldrust-analyzer cargo colored 3.1.1 impl#[ColoredString][Colorize]bold().().underlinerust-analyzer cargo colored 3.1.1 impl#[ColoredString][Colorize]underline().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
657 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(&mut buf, "{}", toto.bluerust-analyzer cargo colored 3.1.1 Colorize#blue().().italicrust-analyzer cargo colored 3.1.1 impl#[ColoredString][Colorize]italic().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
658 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(&mut buf, "******")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
659 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(&mut buf, "test clearing")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
660 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(&mut buf, "{}", "red cleared".redrust-analyzer cargo colored 3.1.1 Colorize#red().().clearrust-analyzer cargo colored 3.1.1 impl#[ColoredString][Colorize]clear().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
661 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(&mut buf, "{}", "bold cyan cleared".boldrust-analyzer cargo colored 3.1.1 impl#[`&str`][Colorize]bold().().cyanrust-analyzer cargo colored 3.1.1 Colorize#cyan().().clearrust-analyzer cargo colored 3.1.1 impl#[ColoredString][Colorize]clear().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
662 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(&mut buf, "******")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
663 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(&mut buf, "Bg tests")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
664 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(&mut buf, "{}", toto.greenrust-analyzer cargo colored 3.1.1 Colorize#green().().on_bluerust-analyzer cargo colored 3.1.1 Colorize#on_blue().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
665 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(&mut buf, "{}", toto.on_magentarust-analyzer cargo colored 3.1.1 Colorize#on_magenta().().yellowrust-analyzer cargo colored 3.1.1 Colorize#yellow().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
666 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(&mut buf, "{}", toto.purplerust-analyzer cargo colored 3.1.1 Colorize#purple().().on_yellowrust-analyzer cargo colored 3.1.1 Colorize#on_yellow().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
667 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(&mut buf, "{}", toto.magentarust-analyzer cargo colored 3.1.1 Colorize#magenta().().on_whiterust-analyzer cargo colored 3.1.1 Colorize#on_white().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
668 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(&mut buf, "{}", toto.cyanrust-analyzer cargo colored 3.1.1 Colorize#cyan().().on_greenrust-analyzer cargo colored 3.1.1 Colorize#on_green().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
669 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(&mut buf, "{}", toto.blackrust-analyzer cargo colored 3.1.1 Colorize#black().().on_whiterust-analyzer cargo colored 3.1.1 Colorize#on_white().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
670 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(&mut buf, "******")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
671 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(&mut buf, "{}", toto.greenrust-analyzer cargo colored 3.1.1 Colorize#green().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
672 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(&mut buf, "{}", toto.yellowrust-analyzer cargo colored 3.1.1 Colorize#yellow().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
673 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(&mut buf, "{}", toto.purplerust-analyzer cargo colored 3.1.1 Colorize#purple().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
674 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(&mut buf, "{}", toto.magentarust-analyzer cargo colored 3.1.1 Colorize#magenta().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
675 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(&mut buf, "{}", toto.cyanrust-analyzer cargo colored 3.1.1 Colorize#cyan().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
676 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(&mut buf, "{}", toto.whiterust-analyzer cargo colored 3.1.1 Colorize#white().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
677 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(&mut buf, "{}", toto.whiterust-analyzer cargo colored 3.1.1 Colorize#white().().redrust-analyzer cargo colored 3.1.1 Colorize#red().().bluerust-analyzer cargo colored 3.1.1 Colorize#blue().().greenrust-analyzer cargo colored 3.1.1 Colorize#green().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
678 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(&mut buf, "{}", toto.truecolorrust-analyzer cargo colored 3.1.1 Colorize#truecolor().(255, 0, 0))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
679 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(&mut buf, "{}", toto.truecolorrust-analyzer cargo colored 3.1.1 Colorize#truecolor().(255, 255, 0))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
680 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(&mut buf, "{}", toto.on_truecolorrust-analyzer cargo colored 3.1.1 Colorize#on_truecolor().(0, 80, 80))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
681 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(&mut buf, "{}", toto.custom_colorrust-analyzer cargo colored 3.1.1 Colorize#custom_color().((255, 255, 0)))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
682 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(&mut buf, "{}", toto.on_custom_colorrust-analyzer cargo colored 3.1.1 Colorize#on_custom_color().((0, 80, 80)))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
683 #[cfg(feature = "no-color")]
684 instarust-analyzer cargo insta 1.46.1 crate/::assert_snapshotrust-analyzer cargo insta 1.46.1 macros/assert_snapshot!!("it_works_no_color", buf);
685 #[cfg(not(feature = "no-color"))]
686 instarust-analyzer cargo insta 1.46.1 crate/::assert_snapshotrust-analyzer cargo insta 1.46.1 macros/assert_snapshot!!("it_works", buf);
687 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
688 }
689
690 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
691 fn compute_style_empty_stringrust-analyzer cargo colored 3.1.1 tests/compute_style_empty_string().() {
692 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("", "".clearrust-analyzer cargo colored 3.1.1 impl#[`&str`][Colorize]clear().().compute_stylerust-analyzer cargo colored 3.1.1 impl#[ColoredString]compute_style().());
693 }
694
695 #[cfg_attr(feature = "no-color", ignore)]
696 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
697 fn compute_style_simple_fg_bluerust-analyzer cargo colored 3.1.1 tests/compute_style_simple_fg_blue().() {
698 let blue = "\x1B[34m";
699
•700 set_overriderust-analyzer cargo colored 3.1.1 control/set_override().(true);
701 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(blue, "".bluerust-analyzer cargo colored 3.1.1 Colorize#blue().().compute_stylerust-analyzer cargo colored 3.1.1 impl#[ColoredString]compute_style().());
702 }
703
704 #[cfg_attr(feature = "no-color", ignore)]
705 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
706 fn compute_style_simple_bg_bluerust-analyzer cargo colored 3.1.1 tests/compute_style_simple_bg_blue().() {
707 let on_blue = "\x1B[44m";
708
•709 set_overriderust-analyzer cargo colored 3.1.1 control/set_override().(true);
710 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(on_blue, "".on_bluerust-analyzer cargo colored 3.1.1 Colorize#on_blue().().compute_stylerust-analyzer cargo colored 3.1.1 impl#[ColoredString]compute_style().());
711 }
712
713 #[cfg_attr(feature = "no-color", ignore)]
714 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
715 fn compute_style_blue_on_bluerust-analyzer cargo colored 3.1.1 tests/compute_style_blue_on_blue().() {
716 let blue_on_blue = "\x1B[44;34m";
•717 set_overriderust-analyzer cargo colored 3.1.1 control/set_override().(true);
718 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(blue_on_blue, "".bluerust-analyzer cargo colored 3.1.1 Colorize#blue().().on_bluerust-analyzer cargo colored 3.1.1 Colorize#on_blue().().compute_stylerust-analyzer cargo colored 3.1.1 impl#[ColoredString]compute_style().());
719 }
720
721 #[cfg_attr(feature = "no-color", ignore)]
722 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
723 fn compute_style_simple_fg_bright_bluerust-analyzer cargo colored 3.1.1 tests/compute_style_simple_fg_bright_blue().() {
724 let blue = "\x1B[94m";
725
•726 set_overriderust-analyzer cargo colored 3.1.1 control/set_override().(true);
727 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(blue, "".bright_bluerust-analyzer cargo colored 3.1.1 Colorize#bright_blue().().compute_stylerust-analyzer cargo colored 3.1.1 impl#[ColoredString]compute_style().());
728 }
729
730 #[cfg_attr(feature = "no-color", ignore)]
731 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
732 fn compute_style_simple_bg_bright_bluerust-analyzer cargo colored 3.1.1 tests/compute_style_simple_bg_bright_blue().() {
733 let on_blue = "\x1B[104m";
734
•735 set_overriderust-analyzer cargo colored 3.1.1 control/set_override().(true);
736 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(on_blue, "".on_bright_bluerust-analyzer cargo colored 3.1.1 Colorize#on_bright_blue().().compute_stylerust-analyzer cargo colored 3.1.1 impl#[ColoredString]compute_style().());
737 }
738
739 #[cfg_attr(feature = "no-color", ignore)]
740 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
741 fn compute_style_bright_blue_on_bright_bluerust-analyzer cargo colored 3.1.1 tests/compute_style_bright_blue_on_bright_blue().() {
742 let blue_on_blue = "\x1B[104;94m";
743
•744 set_overriderust-analyzer cargo colored 3.1.1 control/set_override().(true);
745 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
746 blue_on_blue,
747 "".bright_bluerust-analyzer cargo colored 3.1.1 Colorize#bright_blue().().on_bright_bluerust-analyzer cargo colored 3.1.1 Colorize#on_bright_blue().().compute_stylerust-analyzer cargo colored 3.1.1 impl#[ColoredString]compute_style().()
748 );
749 }
750
751 #[cfg_attr(feature = "no-color", ignore)]
752 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
753 fn compute_style_simple_boldrust-analyzer cargo colored 3.1.1 tests/compute_style_simple_bold().() {
754 let bold = "\x1B[1m";
755
•756 set_overriderust-analyzer cargo colored 3.1.1 control/set_override().(true);
757 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(bold, "".boldrust-analyzer cargo colored 3.1.1 impl#[`&str`][Colorize]bold().().compute_stylerust-analyzer cargo colored 3.1.1 impl#[ColoredString]compute_style().());
758 }
759
760 #[cfg_attr(feature = "no-color", ignore)]
761 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
762 fn compute_style_blue_boldrust-analyzer cargo colored 3.1.1 tests/compute_style_blue_bold().() {
763 let blue_bold = "\x1B[1;34m";
•764 set_overriderust-analyzer cargo colored 3.1.1 control/set_override().(true);
765 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(blue_bold, "".bluerust-analyzer cargo colored 3.1.1 Colorize#blue().().boldrust-analyzer cargo colored 3.1.1 impl#[ColoredString][Colorize]bold().().compute_stylerust-analyzer cargo colored 3.1.1 impl#[ColoredString]compute_style().());
766 }
767
768 #[cfg_attr(feature = "no-color", ignore)]
769 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
770 fn compute_style_blue_bold_on_bluerust-analyzer cargo colored 3.1.1 tests/compute_style_blue_bold_on_blue().() {
771 let blue_bold_on_blue = "\x1B[1;44;34m";
772
•773 set_overriderust-analyzer cargo colored 3.1.1 control/set_override().(true);
774 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
775 blue_bold_on_blue,
776 "".bluerust-analyzer cargo colored 3.1.1 Colorize#blue().().boldrust-analyzer cargo colored 3.1.1 impl#[ColoredString][Colorize]bold().().on_bluerust-analyzer cargo colored 3.1.1 Colorize#on_blue().().compute_stylerust-analyzer cargo colored 3.1.1 impl#[ColoredString]compute_style().()
777 );
778 }
779
780 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
781 fn escape_reset_sequence_spec_should_do_nothing_on_empty_stringsrust-analyzer cargo colored 3.1.1 tests/escape_reset_sequence_spec_should_do_nothing_on_empty_strings().() {
782 let style = ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString#::defaultrust-analyzer cargo colored 3.1.1 impl#[ColoredString][Default]default().();
783 let expected = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().();
784
785 let output = style.escape_inner_reset_sequencesrust-analyzer cargo colored 3.1.1 impl#[ColoredString]escape_inner_reset_sequences().();
786
787 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, output);
788 }
789
790 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
791 fn escape_reset_sequence_spec_should_do_nothing_on_string_with_no_resetrust-analyzer cargo colored 3.1.1 tests/escape_reset_sequence_spec_should_do_nothing_on_string_with_no_reset().() {
792 let style = ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString# {
793 inputrust-analyzer cargo colored 3.1.1 ColoredString#input.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`From<&str>`]from().("hello world !"),
794 ..ColoredStringrust-analyzer cargo colored 3.1.1 ColoredString#::defaultrust-analyzer cargo colored 3.1.1 impl#[ColoredString][Default]default().()
795 };
796
797 let expected = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`From<&str>`]from().("hello world !");
798 let output = style.escape_inner_reset_sequencesrust-analyzer cargo colored 3.1.1 impl#[ColoredString]escape_inner_reset_sequences().();
799
800 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, output);
801 }
802
803 #[cfg_attr(feature = "no-color", ignore)]
804 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
805 fn escape_reset_sequence_spec_should_replace_inner_reset_sequence_with_current_stylerust-analyzer cargo colored 3.1.1 tests/escape_reset_sequence_spec_should_replace_inner_reset_sequence_with_current_style().() {
806 let input = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("start {} end", Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`From<&str>`]from().("hello world !").redrust-analyzer cargo colored 3.1.1 Colorize#red().());
807 let style = input.bluerust-analyzer cargo colored 3.1.1 Colorize#blue().();
808
•809 set_overriderust-analyzer cargo colored 3.1.1 control/set_override().(true);
810 let output = style.escape_inner_reset_sequencesrust-analyzer cargo colored 3.1.1 impl#[ColoredString]escape_inner_reset_sequences().();
811 let blue = "\x1B[34m";
812 let red = "\x1B[31m";
813 let reset = "\x1B[0m";
814 let expected = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("start {red}hello world !{reset}{blue} end");
815 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, output);
816 }
817
818 #[cfg_attr(feature = "no-color", ignore)]
819 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
820 fn escape_reset_sequence_spec_should_replace_multiple_inner_reset_sequences_with_current_stylerust-analyzer cargo colored 3.1.1 tests/escape_reset_sequence_spec_should_replace_multiple_inner_reset_sequences_with_current_style().()
821 {
822 let italic_str = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`From<&str>`]from().("yo").italicrust-analyzer cargo colored 3.1.1 impl#[`&str`][Colorize]italic().();
823 let input = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("start 1:{italic_str} 2:{italic_str} 3:{italic_str} end");
824 let style = input.bluerust-analyzer cargo colored 3.1.1 Colorize#blue().();
825
•826 set_overriderust-analyzer cargo colored 3.1.1 control/set_override().(true);
827 let output = style.escape_inner_reset_sequencesrust-analyzer cargo colored 3.1.1 impl#[ColoredString]escape_inner_reset_sequences().();
828 let blue = "\x1B[34m";
829 let italic = "\x1B[3m";
830 let reset = "\x1B[0m";
831 let expected = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
832 "start 1:{italic}yo{reset}{blue} 2:{italic}yo{reset}{blue} 3:{italic}yo{reset}{blue} end"
833 );
834
835 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("first: {expected}\nsecond: {output}");
836
837 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, output);
838 }
839
840 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
841 fn color_fnrust-analyzer cargo colored 3.1.1 tests/color_fn().() {
842 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("blue".bluerust-analyzer cargo colored 3.1.1 Colorize#blue().(), "blue".colorrust-analyzer cargo colored 3.1.1 impl#[`&str`][Colorize]color().("blue"));
843 }
844
845 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
846 fn on_color_fnrust-analyzer cargo colored 3.1.1 tests/on_color_fn().() {
847 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("blue".on_bluerust-analyzer cargo colored 3.1.1 Colorize#on_blue().(), "blue".on_colorrust-analyzer cargo colored 3.1.1 impl#[`&str`][Colorize]on_color().("blue"));
848 }
849
850 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
851 fn bright_color_fnrust-analyzer cargo colored 3.1.1 tests/bright_color_fn().() {
852 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("blue".bright_bluerust-analyzer cargo colored 3.1.1 Colorize#bright_blue().(), "blue".colorrust-analyzer cargo colored 3.1.1 impl#[`&str`][Colorize]color().("bright blue"));
853 }
854
855 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
856 fn on_bright_color_fnrust-analyzer cargo colored 3.1.1 tests/on_bright_color_fn().() {
857 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("blue".on_bright_bluerust-analyzer cargo colored 3.1.1 Colorize#on_bright_blue().(), "blue".on_colorrust-analyzer cargo colored 3.1.1 impl#[`&str`][Colorize]on_color().("bright blue"));
858 }
859
860 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
861 fn exposing_testsrust-analyzer cargo colored 3.1.1 tests/exposing_tests().() {
862 #![allow(deprecated)]
863
864 let cstring = "".redrust-analyzer cargo colored 3.1.1 Colorize#red().();
865 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cstring.fgcolorrust-analyzer cargo colored 3.1.1 impl#[ColoredString]fgcolor().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Colorrust-analyzer cargo colored 3.1.1 color/Color#::Redrust-analyzer cargo colored 3.1.1 color/Color#Red#));
866 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cstring.bgcolorrust-analyzer cargo colored 3.1.1 impl#[ColoredString]bgcolor().(), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
867
868 let cstring = cstring.clearrust-analyzer cargo colored 3.1.1 impl#[ColoredString][Colorize]clear().();
869 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cstring.fgcolorrust-analyzer cargo colored 3.1.1 impl#[ColoredString]fgcolor().(), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
870 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cstring.bgcolorrust-analyzer cargo colored 3.1.1 impl#[ColoredString]bgcolor().(), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
871
872 let cstring = cstring.bluerust-analyzer cargo colored 3.1.1 Colorize#blue().().on_bright_yellowrust-analyzer cargo colored 3.1.1 Colorize#on_bright_yellow().();
873 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cstring.fgcolorrust-analyzer cargo colored 3.1.1 impl#[ColoredString]fgcolor().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Colorrust-analyzer cargo colored 3.1.1 color/Color#::Bluerust-analyzer cargo colored 3.1.1 color/Color#Blue#));
874 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cstring.bgcolorrust-analyzer cargo colored 3.1.1 impl#[ColoredString]bgcolor().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Colorrust-analyzer cargo colored 3.1.1 color/Color#::BrightYellowrust-analyzer cargo colored 3.1.1 color/Color#BrightYellow#));
875
876 let cstring = cstring.boldrust-analyzer cargo colored 3.1.1 impl#[ColoredString][Colorize]bold().().italicrust-analyzer cargo colored 3.1.1 impl#[ColoredString][Colorize]italic().();
877 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cstring.fgcolorrust-analyzer cargo colored 3.1.1 impl#[ColoredString]fgcolor().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Colorrust-analyzer cargo colored 3.1.1 color/Color#::Bluerust-analyzer cargo colored 3.1.1 color/Color#Blue#));
878 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cstring.bgcolorrust-analyzer cargo colored 3.1.1 impl#[ColoredString]bgcolor().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Colorrust-analyzer cargo colored 3.1.1 color/Color#::BrightYellowrust-analyzer cargo colored 3.1.1 color/Color#BrightYellow#));
879 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(cstring.stylerust-analyzer cargo colored 3.1.1 impl#[ColoredString]style().().containsrust-analyzer cargo colored 3.1.1 style/impl#[Style]contains().(Stylesrust-analyzer cargo colored 3.1.1 style/Styles#::Boldrust-analyzer cargo colored 3.1.1 style/Styles#Bold#));
880 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(cstring.stylerust-analyzer cargo colored 3.1.1 impl#[ColoredString]style().().containsrust-analyzer cargo colored 3.1.1 style/impl#[Style]contains().(Stylesrust-analyzer cargo colored 3.1.1 style/Styles#::Italicrust-analyzer cargo colored 3.1.1 style/Styles#Italic#));
881 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().cstring.stylerust-analyzer cargo colored 3.1.1 impl#[ColoredString]style().().containsrust-analyzer cargo colored 3.1.1 style/impl#[Style]contains().(Stylesrust-analyzer cargo colored 3.1.1 style/Styles#::Dimmedrust-analyzer cargo colored 3.1.1 style/Styles#Dimmed#));
882 }
883 }