| 1 | use craterust-analyzer cargo anstyle 1.0.14 crate/::resetrust-analyzer cargo anstyle 1.0.14 reset/::RESETrust-analyzer cargo anstyle 1.0.14 reset/RESET.; |
| 2 | |
| 3 | /// ANSI Text styling |
| 4 | /// |
| 5 | /// You can print a `Style` to render the corresponding ANSI code. |
| 6 | /// Using the alternate flag `#` will render the ANSI reset code, if needed. |
| 7 | /// Together, this makes it convenient to render styles using inline format arguments. |
| 8 | /// |
| 9 | /// # Examples |
| 10 | /// |
| 11 | /// ```rust |
| 12 | /// let style = anstyle::Style::new().bold(); |
| 13 | /// |
| 14 | /// let value = 42; |
| 15 | /// println!("{style}{value}{style:#}"); |
| 16 | /// ``` |
| 17 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, 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:, PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd:, Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:)] |
| 18 | pub struct Stylerust-analyzer cargo anstyle 1.0.14 style/Style# { |
| 19 | fgrust-analyzer cargo anstyle 1.0.14 style/Style#fg.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<craterust-analyzer cargo anstyle 1.0.14 crate/::Colorrust-analyzer cargo anstyle 1.0.14 color/Color#>, |
| 20 | bgrust-analyzer cargo anstyle 1.0.14 style/Style#bg.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<craterust-analyzer cargo anstyle 1.0.14 crate/::Colorrust-analyzer cargo anstyle 1.0.14 color/Color#>, |
| 21 | underlinerust-analyzer cargo anstyle 1.0.14 style/Style#underline.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<craterust-analyzer cargo anstyle 1.0.14 crate/::Colorrust-analyzer cargo anstyle 1.0.14 color/Color#>, |
| 22 | effectsrust-analyzer cargo anstyle 1.0.14 style/Style#effects.: craterust-analyzer cargo anstyle 1.0.14 crate/::Effectsrust-analyzer cargo anstyle 1.0.14 effect/Effects#, |
| 23 | } |
| 24 | |
| 25 | /// # Core |
| 26 | impl Stylerust-analyzer cargo anstyle 1.0.14 style/Style# { |
| 27 | /// No effects enabled |
| 28 | /// |
| 29 | /// # Examples |
| 30 | /// |
| 31 | /// ```rust |
| 32 | /// let style = anstyle::Style::new(); |
| 33 | /// ``` |
| 34 | #[inline] |
| 35 | pub const fn newrust-analyzer cargo anstyle 1.0.14 style/impl#[Style]new().() -> Selfrust-analyzer cargo anstyle 1.0.14 style/impl#[Style] { |
| 36 | Selfrust-analyzer cargo anstyle 1.0.14 style/impl#[Style] { |
| 37 | fgrust-analyzer cargo anstyle 1.0.14 style/Style#fg.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 38 | bgrust-analyzer cargo anstyle 1.0.14 style/Style#bg.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 39 | underlinerust-analyzer cargo anstyle 1.0.14 style/Style#underline.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 40 | effectsrust-analyzer cargo anstyle 1.0.14 style/Style#effects.: craterust-analyzer cargo anstyle 1.0.14 crate/::Effectsrust-analyzer cargo anstyle 1.0.14 effect/Effects#::newrust-analyzer cargo anstyle 1.0.14 effect/impl#[Effects]new().(), |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | /// Set foreground color |
| 45 | /// |
| 46 | /// # Examples |
| 47 | /// |
| 48 | /// ```rust |
| 49 | /// let style = anstyle::Style::new().fg_color(Some(anstyle::AnsiColor::Red.into())); |
| 50 | /// ``` |
| 51 | #[must_use] |
| 52 | #[inline] |
| 53 | pub const fn fg_colorrust-analyzer cargo anstyle 1.0.14 style/impl#[Style]fg_color().(mut self, fg: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<craterust-analyzer cargo anstyle 1.0.14 crate/::Colorrust-analyzer cargo anstyle 1.0.14 color/Color#>) -> Selfrust-analyzer cargo anstyle 1.0.14 style/impl#[Style] { |
| 54 | self.fgrust-analyzer cargo anstyle 1.0.14 style/Style#fg. = fg; |
| 55 | self |
| 56 | } |
| 57 | |
| 58 | /// Set background color |
| 59 | /// |
| 60 | /// # Examples |
| 61 | /// |
| 62 | /// ```rust |
| 63 | /// let style = anstyle::Style::new().bg_color(Some(anstyle::AnsiColor::Red.into())); |
| 64 | /// ``` |
| 65 | #[must_use] |
| 66 | #[inline] |
| 67 | pub const fn bg_colorrust-analyzer cargo anstyle 1.0.14 style/impl#[Style]bg_color().(mut self, bg: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<craterust-analyzer cargo anstyle 1.0.14 crate/::Colorrust-analyzer cargo anstyle 1.0.14 color/Color#>) -> Selfrust-analyzer cargo anstyle 1.0.14 style/impl#[Style] { |
| 68 | self.bgrust-analyzer cargo anstyle 1.0.14 style/Style#bg. = bg; |
| 69 | self |
| 70 | } |
| 71 | |
| 72 | /// Set underline color |
| 73 | /// |
| 74 | /// # Examples |
| 75 | /// |
| 76 | /// ```rust |
| 77 | /// let style = anstyle::Style::new().underline_color(Some(anstyle::AnsiColor::Red.into())); |
| 78 | /// ``` |
| 79 | #[must_use] |
| 80 | #[inline] |
| 81 | pub const fn underline_colorrust-analyzer cargo anstyle 1.0.14 style/impl#[Style]underline_color().(mut self, underline: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<craterust-analyzer cargo anstyle 1.0.14 crate/::Colorrust-analyzer cargo anstyle 1.0.14 color/Color#>) -> Selfrust-analyzer cargo anstyle 1.0.14 style/impl#[Style] { |
| 82 | self.underlinerust-analyzer cargo anstyle 1.0.14 style/Style#underline. = underline; |
| 83 | self |
| 84 | } |
| 85 | |
| 86 | /// Set text effects |
| 87 | /// |
| 88 | /// # Examples |
| 89 | /// |
| 90 | /// ```rust |
| 91 | /// let style = anstyle::Style::new().effects(anstyle::Effects::BOLD | anstyle::Effects::UNDERLINE); |
| 92 | /// ``` |
| 93 | #[must_use] |
| 94 | #[inline] |
| 95 | pub const fn effectsrust-analyzer cargo anstyle 1.0.14 style/impl#[Style]effects().(mut self, effects: craterust-analyzer cargo anstyle 1.0.14 crate/::Effectsrust-analyzer cargo anstyle 1.0.14 effect/Effects#) -> Selfrust-analyzer cargo anstyle 1.0.14 style/impl#[Style] { |
| 96 | self.effectsrust-analyzer cargo anstyle 1.0.14 style/Style#effects. = effects; |
| 97 | self |
| 98 | } |
| 99 | |
| 100 | /// Render the ANSI code |
| 101 | /// |
| 102 | /// `Style` also implements `Display` directly, so calling this method is optional. |
| 103 | #[inline] |
| 104 | pub fn renderrust-analyzer cargo anstyle 1.0.14 style/impl#[Style]render().(self) -> impl corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# + Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy# { |
| 105 | StyleDisplayrust-analyzer cargo anstyle 1.0.14 style/StyleDisplay#(self) |
| 106 | } |
| 107 | |
| 108 | fn fmt_torust-analyzer cargo anstyle 1.0.14 style/impl#[Style]fmt_to().(&self, f: &mut corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 109 | use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# as _; |
| 110 | |
| 111 | self.effectsrust-analyzer cargo anstyle 1.0.14 style/Style#effects..renderrust-analyzer cargo anstyle 1.0.14 effect/impl#[Effects]render().().fmtrust-analyzer cargo anstyle 1.0.14 effect/impl#[EffectsDisplay][Display]fmt().(f)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 112 | |
| 113 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(fg) = self.fgrust-analyzer cargo anstyle 1.0.14 style/Style#fg. { |
| 114 | fg.render_fgrust-analyzer cargo anstyle 1.0.14 color/impl#[Color]render_fg().().fmtrust-analyzer cargo anstyle 1.0.14 color/impl#[DisplayBuffer][Display]fmt().(f)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 115 | } |
| 116 | |
| 117 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(bg) = self.bgrust-analyzer cargo anstyle 1.0.14 style/Style#bg. { |
| 118 | bg.render_bgrust-analyzer cargo anstyle 1.0.14 color/impl#[Color]render_bg().().fmtrust-analyzer cargo anstyle 1.0.14 color/impl#[DisplayBuffer][Display]fmt().(f)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 119 | } |
| 120 | |
| 121 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(underline) = self.underlinerust-analyzer cargo anstyle 1.0.14 style/Style#underline. { |
| 122 | underline.render_underlinerust-analyzer cargo anstyle 1.0.14 color/impl#[Color]render_underline().().fmtrust-analyzer cargo anstyle 1.0.14 color/impl#[DisplayBuffer][Display]fmt().(f)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 123 | } |
| 124 | |
| 125 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 126 | } |
| 127 | |
| 128 | /// Write the ANSI code |
| 129 | #[inline] |
| 130 | #[cfg(feature = "std")] |
| 131 | pub fn write_torust-analyzer cargo anstyle 1.0.14 style/impl#[Style]write_to().(self, write: &mut dyn stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> { |
| 132 | self.effectsrust-analyzer cargo anstyle 1.0.14 style/Style#effects..write_torust-analyzer cargo anstyle 1.0.14 effect/impl#[Effects]write_to().(write)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 133 | |
| 134 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(fg) = self.fgrust-analyzer cargo anstyle 1.0.14 style/Style#fg. { |
| 135 | fg.write_fg_torust-analyzer cargo anstyle 1.0.14 color/impl#[Color]write_fg_to().(write)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 136 | } |
| 137 | |
| 138 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(bg) = self.bgrust-analyzer cargo anstyle 1.0.14 style/Style#bg. { |
| 139 | bg.write_bg_torust-analyzer cargo anstyle 1.0.14 color/impl#[Color]write_bg_to().(write)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 140 | } |
| 141 | |
| 142 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(underline) = self.underlinerust-analyzer cargo anstyle 1.0.14 style/Style#underline. { |
| 143 | underline.write_underline_torust-analyzer cargo anstyle 1.0.14 color/impl#[Color]write_underline_to().(write)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 144 | } |
| 145 | |
| 146 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 147 | } |
| 148 | |
| 149 | /// Renders the relevant [`Reset`][crate::Reset] code |
| 150 | /// |
| 151 | /// Unlike [`Reset::render`][crate::Reset::render], this will elide the code if there is nothing to reset. |
| 152 | #[inline] |
| 153 | pub fn render_resetrust-analyzer cargo anstyle 1.0.14 style/impl#[Style]render_reset().(self) -> impl corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# + Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy# { |
| 154 | if self rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().Selfrust-analyzer cargo anstyle 1.0.14 style/impl#[Style]::newrust-analyzer cargo anstyle 1.0.14 style/impl#[Style]new().() { |
| 155 | RESETrust-analyzer cargo anstyle 1.0.14 reset/RESET. |
| 156 | } else { |
| 157 | "" |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | /// Write the relevant [`Reset`][crate::Reset] code |
| 162 | /// |
| 163 | /// Unlike [`Reset::render`][crate::Reset::render], this will elide the code if there is nothing to reset. |
| 164 | #[inline] |
| 165 | #[cfg(feature = "std")] |
| 166 | pub fn write_reset_torust-analyzer cargo anstyle 1.0.14 style/impl#[Style]write_reset_to().(self, write: &mut dyn stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> { |
| 167 | if self rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().Selfrust-analyzer cargo anstyle 1.0.14 style/impl#[Style]::newrust-analyzer cargo anstyle 1.0.14 style/impl#[Style]new().() { |
| 168 | write.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(RESETrust-analyzer cargo anstyle 1.0.14 reset/RESET..as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()) |
| 169 | } else { |
| 170 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 171 | } |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | /// # Convenience |
| 176 | impl Stylerust-analyzer cargo anstyle 1.0.14 style/Style# { |
| 177 | /// Apply `bold` effect |
| 178 | /// |
| 179 | /// # Examples |
| 180 | /// |
| 181 | /// ```rust |
| 182 | /// let style = anstyle::Style::new().bold(); |
| 183 | /// ``` |
| 184 | #[must_use] |
| 185 | #[inline] |
| 186 | pub const fn boldrust-analyzer cargo anstyle 1.0.14 style/impl#[Style]bold().(mut self) -> Selfrust-analyzer cargo anstyle 1.0.14 style/impl#[Style] { |
| 187 | self.effectsrust-analyzer cargo anstyle 1.0.14 style/Style#effects. = self.effectsrust-analyzer cargo anstyle 1.0.14 style/Style#effects..insertrust-analyzer cargo anstyle 1.0.14 effect/impl#[Effects]insert().(craterust-analyzer cargo anstyle 1.0.14 crate/::Effectsrust-analyzer cargo anstyle 1.0.14 effect/Effects#::BOLDrust-analyzer cargo anstyle 1.0.14 effect/impl#[Effects]BOLD.); |
| 188 | self |
| 189 | } |
| 190 | |
| 191 | /// Apply `dimmed` effect |
| 192 | /// |
| 193 | /// # Examples |
| 194 | /// |
| 195 | /// ```rust |
| 196 | /// let style = anstyle::Style::new().dimmed(); |
| 197 | /// ``` |
| 198 | #[must_use] |
| 199 | #[inline] |
| 200 | pub const fn dimmedrust-analyzer cargo anstyle 1.0.14 style/impl#[Style]dimmed().(mut self) -> Selfrust-analyzer cargo anstyle 1.0.14 style/impl#[Style] { |
| 201 | self.effectsrust-analyzer cargo anstyle 1.0.14 style/Style#effects. = self.effectsrust-analyzer cargo anstyle 1.0.14 style/Style#effects..insertrust-analyzer cargo anstyle 1.0.14 effect/impl#[Effects]insert().(craterust-analyzer cargo anstyle 1.0.14 crate/::Effectsrust-analyzer cargo anstyle 1.0.14 effect/Effects#::DIMMEDrust-analyzer cargo anstyle 1.0.14 effect/impl#[Effects]DIMMED.); |
| 202 | self |
| 203 | } |
| 204 | |
| 205 | /// Apply `italic` effect |
| 206 | /// |
| 207 | /// # Examples |
| 208 | /// |
| 209 | /// ```rust |
| 210 | /// let style = anstyle::Style::new().italic(); |
| 211 | /// ``` |
| 212 | #[must_use] |
| 213 | #[inline] |
| 214 | pub const fn italicrust-analyzer cargo anstyle 1.0.14 style/impl#[Style]italic().(mut self) -> Selfrust-analyzer cargo anstyle 1.0.14 style/impl#[Style] { |
| 215 | self.effectsrust-analyzer cargo anstyle 1.0.14 style/Style#effects. = self.effectsrust-analyzer cargo anstyle 1.0.14 style/Style#effects..insertrust-analyzer cargo anstyle 1.0.14 effect/impl#[Effects]insert().(craterust-analyzer cargo anstyle 1.0.14 crate/::Effectsrust-analyzer cargo anstyle 1.0.14 effect/Effects#::ITALICrust-analyzer cargo anstyle 1.0.14 effect/impl#[Effects]ITALIC.); |
| 216 | self |
| 217 | } |
| 218 | |
| 219 | /// Apply `underline` effect |
| 220 | /// |
| 221 | /// # Examples |
| 222 | /// |
| 223 | /// ```rust |
| 224 | /// let style = anstyle::Style::new().underline(); |
| 225 | /// ``` |
| 226 | #[must_use] |
| 227 | #[inline] |
| 228 | pub const fn underlinerust-analyzer cargo anstyle 1.0.14 style/impl#[Style]underline().(mut self) -> Selfrust-analyzer cargo anstyle 1.0.14 style/impl#[Style] { |
| 229 | self.effectsrust-analyzer cargo anstyle 1.0.14 style/Style#effects. = self.effectsrust-analyzer cargo anstyle 1.0.14 style/Style#effects..insertrust-analyzer cargo anstyle 1.0.14 effect/impl#[Effects]insert().(craterust-analyzer cargo anstyle 1.0.14 crate/::Effectsrust-analyzer cargo anstyle 1.0.14 effect/Effects#::UNDERLINErust-analyzer cargo anstyle 1.0.14 effect/impl#[Effects]UNDERLINE.); |
| 230 | self |
| 231 | } |
| 232 | |
| 233 | /// Apply `blink` effect |
| 234 | /// |
| 235 | /// # Examples |
| 236 | /// |
| 237 | /// ```rust |
| 238 | /// let style = anstyle::Style::new().blink(); |
| 239 | /// ``` |
| 240 | #[must_use] |
| 241 | #[inline] |
| 242 | pub const fn blinkrust-analyzer cargo anstyle 1.0.14 style/impl#[Style]blink().(mut self) -> Selfrust-analyzer cargo anstyle 1.0.14 style/impl#[Style] { |
| 243 | self.effectsrust-analyzer cargo anstyle 1.0.14 style/Style#effects. = self.effectsrust-analyzer cargo anstyle 1.0.14 style/Style#effects..insertrust-analyzer cargo anstyle 1.0.14 effect/impl#[Effects]insert().(craterust-analyzer cargo anstyle 1.0.14 crate/::Effectsrust-analyzer cargo anstyle 1.0.14 effect/Effects#::BLINKrust-analyzer cargo anstyle 1.0.14 effect/impl#[Effects]BLINK.); |
| 244 | self |
| 245 | } |
| 246 | |
| 247 | /// Apply `invert` effect |
| 248 | /// |
| 249 | /// # Examples |
| 250 | /// |
| 251 | /// ```rust |
| 252 | /// let style = anstyle::Style::new().invert(); |
| 253 | /// ``` |
| 254 | #[must_use] |
| 255 | #[inline] |
| 256 | pub const fn invertrust-analyzer cargo anstyle 1.0.14 style/impl#[Style]invert().(mut self) -> Selfrust-analyzer cargo anstyle 1.0.14 style/impl#[Style] { |
| 257 | self.effectsrust-analyzer cargo anstyle 1.0.14 style/Style#effects. = self.effectsrust-analyzer cargo anstyle 1.0.14 style/Style#effects..insertrust-analyzer cargo anstyle 1.0.14 effect/impl#[Effects]insert().(craterust-analyzer cargo anstyle 1.0.14 crate/::Effectsrust-analyzer cargo anstyle 1.0.14 effect/Effects#::INVERTrust-analyzer cargo anstyle 1.0.14 effect/impl#[Effects]INVERT.); |
| 258 | self |
| 259 | } |
| 260 | |
| 261 | /// Apply `hidden` effect |
| 262 | /// |
| 263 | /// # Examples |
| 264 | /// |
| 265 | /// ```rust |
| 266 | /// let style = anstyle::Style::new().hidden(); |
| 267 | /// ``` |
| 268 | #[must_use] |
| 269 | #[inline] |
| 270 | pub const fn hiddenrust-analyzer cargo anstyle 1.0.14 style/impl#[Style]hidden().(mut self) -> Selfrust-analyzer cargo anstyle 1.0.14 style/impl#[Style] { |
| 271 | self.effectsrust-analyzer cargo anstyle 1.0.14 style/Style#effects. = self.effectsrust-analyzer cargo anstyle 1.0.14 style/Style#effects..insertrust-analyzer cargo anstyle 1.0.14 effect/impl#[Effects]insert().(craterust-analyzer cargo anstyle 1.0.14 crate/::Effectsrust-analyzer cargo anstyle 1.0.14 effect/Effects#::HIDDENrust-analyzer cargo anstyle 1.0.14 effect/impl#[Effects]HIDDEN.); |
| 272 | self |
| 273 | } |
| 274 | |
| 275 | /// Apply `strikethrough` effect |
| 276 | /// |
| 277 | /// # Examples |
| 278 | /// |
| 279 | /// ```rust |
| 280 | /// let style = anstyle::Style::new().strikethrough(); |
| 281 | /// ``` |
| 282 | #[must_use] |
| 283 | #[inline] |
| 284 | pub const fn strikethroughrust-analyzer cargo anstyle 1.0.14 style/impl#[Style]strikethrough().(mut self) -> Selfrust-analyzer cargo anstyle 1.0.14 style/impl#[Style] { |
| 285 | self.effectsrust-analyzer cargo anstyle 1.0.14 style/Style#effects. = self.effectsrust-analyzer cargo anstyle 1.0.14 style/Style#effects..insertrust-analyzer cargo anstyle 1.0.14 effect/impl#[Effects]insert().(craterust-analyzer cargo anstyle 1.0.14 crate/::Effectsrust-analyzer cargo anstyle 1.0.14 effect/Effects#::STRIKETHROUGHrust-analyzer cargo anstyle 1.0.14 effect/impl#[Effects]STRIKETHROUGH.); |
| 286 | self |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | /// # Reflection |
| 291 | impl Stylerust-analyzer cargo anstyle 1.0.14 style/Style# { |
| 292 | /// Get the foreground color |
| 293 | #[inline] |
| 294 | pub const fn get_fg_colorrust-analyzer cargo anstyle 1.0.14 style/impl#[Style]get_fg_color().(self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<craterust-analyzer cargo anstyle 1.0.14 crate/::Colorrust-analyzer cargo anstyle 1.0.14 color/Color#> { |
| 295 | self.fgrust-analyzer cargo anstyle 1.0.14 style/Style#fg. |
| 296 | } |
| 297 | |
| 298 | /// Get the background color |
| 299 | #[inline] |
| 300 | #[allow(missing_docs)] |
| 301 | pub const fn get_bg_colorrust-analyzer cargo anstyle 1.0.14 style/impl#[Style]get_bg_color().(self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<craterust-analyzer cargo anstyle 1.0.14 crate/::Colorrust-analyzer cargo anstyle 1.0.14 color/Color#> { |
| 302 | self.bgrust-analyzer cargo anstyle 1.0.14 style/Style#bg. |
| 303 | } |
| 304 | |
| 305 | #[inline] |
| 306 | #[allow(missing_docs)] |
| 307 | pub const fn get_underline_colorrust-analyzer cargo anstyle 1.0.14 style/impl#[Style]get_underline_color().(self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<craterust-analyzer cargo anstyle 1.0.14 crate/::Colorrust-analyzer cargo anstyle 1.0.14 color/Color#> { |
| 308 | self.underlinerust-analyzer cargo anstyle 1.0.14 style/Style#underline. |
| 309 | } |
| 310 | |
| 311 | #[inline] |
| 312 | #[allow(missing_docs)] |
| 313 | pub const fn get_effectsrust-analyzer cargo anstyle 1.0.14 style/impl#[Style]get_effects().(self) -> craterust-analyzer cargo anstyle 1.0.14 crate/::Effectsrust-analyzer cargo anstyle 1.0.14 effect/Effects# { |
| 314 | self.effectsrust-analyzer cargo anstyle 1.0.14 style/Style#effects. |
| 315 | } |
| 316 | |
| 317 | /// Check if no styling is enabled |
| 318 | #[inline] |
| 319 | pub const fn is_plainrust-analyzer cargo anstyle 1.0.14 style/impl#[Style]is_plain().(self) -> bool { |
| 320 | self.fgrust-analyzer cargo anstyle 1.0.14 style/Style#fg..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() |
| 321 | && self.bgrust-analyzer cargo anstyle 1.0.14 style/Style#bg..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() |
| 322 | && self.underlinerust-analyzer cargo anstyle 1.0.14 style/Style#underline..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() |
| 323 | && self.effectsrust-analyzer cargo anstyle 1.0.14 style/Style#effects..is_plainrust-analyzer cargo anstyle 1.0.14 effect/impl#[Effects]is_plain().() |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | /// # Examples |
| 328 | /// |
| 329 | /// ```rust |
| 330 | /// let style: anstyle::Style = anstyle::Effects::BOLD.into(); |
| 331 | /// ``` |
| 332 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<craterust-analyzer cargo anstyle 1.0.14 crate/::Effectsrust-analyzer cargo anstyle 1.0.14 effect/Effects#> for Stylerust-analyzer cargo anstyle 1.0.14 style/Style# { |
| 333 | #[inline] |
| 334 | fn fromrust-analyzer cargo anstyle 1.0.14 style/impl#[Style][`From<crate::Effects>`]from().(effects: craterust-analyzer cargo anstyle 1.0.14 crate/::Effectsrust-analyzer cargo anstyle 1.0.14 effect/Effects#) -> Selfrust-analyzer cargo anstyle 1.0.14 style/impl#[Style][`From<crate::Effects>`] { |
| 335 | Selfrust-analyzer cargo anstyle 1.0.14 style/impl#[Style][`From<crate::Effects>`]::newrust-analyzer cargo anstyle 1.0.14 style/impl#[Style]new().().effectsrust-analyzer cargo anstyle 1.0.14 style/impl#[Style]effects().(effects) |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | /// # Examples |
| 340 | /// |
| 341 | /// ```rust |
| 342 | /// let style = anstyle::Style::new() | anstyle::Effects::BOLD.into(); |
| 343 | /// ``` |
| 344 | impl corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::BitOrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/BitOr#<craterust-analyzer cargo anstyle 1.0.14 crate/::Effectsrust-analyzer cargo anstyle 1.0.14 effect/Effects#> for Stylerust-analyzer cargo anstyle 1.0.14 style/Style# { |
| 345 | type Outputrust-analyzer cargo anstyle 1.0.14 style/impl#[Style][`BitOr<crate::Effects>`]Output# = Selfrust-analyzer cargo anstyle 1.0.14 style/impl#[Style][`BitOr<crate::Effects>`]; |
| 346 | |
| 347 | #[inline(always)] |
| 348 | fn bitorrust-analyzer cargo anstyle 1.0.14 style/impl#[Style][`BitOr<crate::Effects>`]bitor().(mut self, rhs: craterust-analyzer cargo anstyle 1.0.14 crate/::Effectsrust-analyzer cargo anstyle 1.0.14 effect/Effects#) -> Selfrust-analyzer cargo anstyle 1.0.14 style/impl#[Style][`BitOr<crate::Effects>`] { |
| 349 | self.effectsrust-analyzer cargo anstyle 1.0.14 style/Style#effects. rust-analyzer cargo anstyle 1.0.14 effect/impl#[Effects][`BitOrAssign<Self>`]bitor_assign().|=rust-analyzer cargo anstyle 1.0.14 effect/impl#[Effects][`BitOrAssign<Self>`]bitor_assign(). rust-analyzer cargo anstyle 1.0.14 effect/impl#[Effects][`BitOrAssign<Self>`]bitor_assign().rhs; |
| 350 | self |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | /// # Examples |
| 355 | /// |
| 356 | /// ```rust |
| 357 | /// let mut style = anstyle::Style::new(); |
| 358 | /// style |= anstyle::Effects::BOLD.into(); |
| 359 | /// ``` |
| 360 | impl corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::BitOrAssignrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/BitOrAssign#<craterust-analyzer cargo anstyle 1.0.14 crate/::Effectsrust-analyzer cargo anstyle 1.0.14 effect/Effects#> for Stylerust-analyzer cargo anstyle 1.0.14 style/Style# { |
| 361 | #[inline] |
| 362 | fn bitor_assignrust-analyzer cargo anstyle 1.0.14 style/impl#[Style][`BitOrAssign<crate::Effects>`]bitor_assign().(&mut self, other: craterust-analyzer cargo anstyle 1.0.14 crate/::Effectsrust-analyzer cargo anstyle 1.0.14 effect/Effects#) { |
| 363 | self.effectsrust-analyzer cargo anstyle 1.0.14 style/Style#effects. rust-analyzer cargo anstyle 1.0.14 effect/impl#[Effects][`BitOrAssign<Self>`]bitor_assign().|=rust-analyzer cargo anstyle 1.0.14 effect/impl#[Effects][`BitOrAssign<Self>`]bitor_assign(). rust-analyzer cargo anstyle 1.0.14 effect/impl#[Effects][`BitOrAssign<Self>`]bitor_assign().other; |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | /// # Examples |
| 368 | /// |
| 369 | /// ```rust |
| 370 | /// let style = anstyle::Style::new().bold().underline() - anstyle::Effects::BOLD.into(); |
| 371 | /// ``` |
| 372 | impl corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::Subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#<craterust-analyzer cargo anstyle 1.0.14 crate/::Effectsrust-analyzer cargo anstyle 1.0.14 effect/Effects#> for Stylerust-analyzer cargo anstyle 1.0.14 style/Style# { |
| 373 | type Outputrust-analyzer cargo anstyle 1.0.14 style/impl#[Style][`Sub<crate::Effects>`]Output# = Selfrust-analyzer cargo anstyle 1.0.14 style/impl#[Style][`Sub<crate::Effects>`]; |
| 374 | |
| 375 | #[inline] |
| 376 | fn subrust-analyzer cargo anstyle 1.0.14 style/impl#[Style][`Sub<crate::Effects>`]sub().(mut self, other: craterust-analyzer cargo anstyle 1.0.14 crate/::Effectsrust-analyzer cargo anstyle 1.0.14 effect/Effects#) -> Selfrust-analyzer cargo anstyle 1.0.14 style/impl#[Style][`Sub<crate::Effects>`] { |
| 377 | self.effectsrust-analyzer cargo anstyle 1.0.14 style/Style#effects. rust-analyzer cargo anstyle 1.0.14 effect/impl#[Effects][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo anstyle 1.0.14 effect/impl#[Effects][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo anstyle 1.0.14 effect/impl#[Effects][`SubAssign<Self>`]sub_assign().other; |
| 378 | self |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | /// # Examples |
| 383 | /// |
| 384 | /// ```rust |
| 385 | /// let mut style = anstyle::Style::new().bold().underline(); |
| 386 | /// style -= anstyle::Effects::BOLD.into(); |
| 387 | /// ``` |
| 388 | impl corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::SubAssignrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/SubAssign#<craterust-analyzer cargo anstyle 1.0.14 crate/::Effectsrust-analyzer cargo anstyle 1.0.14 effect/Effects#> for Stylerust-analyzer cargo anstyle 1.0.14 style/Style# { |
| 389 | #[inline] |
| 390 | fn sub_assignrust-analyzer cargo anstyle 1.0.14 style/impl#[Style][`SubAssign<crate::Effects>`]sub_assign().(&mut self, other: craterust-analyzer cargo anstyle 1.0.14 crate/::Effectsrust-analyzer cargo anstyle 1.0.14 effect/Effects#) { |
| 391 | self.effectsrust-analyzer cargo anstyle 1.0.14 style/Style#effects. rust-analyzer cargo anstyle 1.0.14 effect/impl#[Effects][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo anstyle 1.0.14 effect/impl#[Effects][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo anstyle 1.0.14 effect/impl#[Effects][`SubAssign<Self>`]sub_assign().other; |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | /// # Examples |
| 396 | /// |
| 397 | /// ```rust |
| 398 | /// let effects = anstyle::Effects::BOLD; |
| 399 | /// assert_eq!(anstyle::Style::new().effects(effects), effects); |
| 400 | /// assert_ne!(anstyle::Effects::UNDERLINE | effects, effects); |
| 401 | /// assert_ne!(anstyle::RgbColor(0, 0, 0).on_default() | effects, effects); |
| 402 | /// ``` |
| 403 | impl PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#<craterust-analyzer cargo anstyle 1.0.14 crate/::Effectsrust-analyzer cargo anstyle 1.0.14 effect/Effects#> for Stylerust-analyzer cargo anstyle 1.0.14 style/Style# { |
| 404 | #[inline] |
| 405 | fn eqrust-analyzer cargo anstyle 1.0.14 style/impl#[Style][`PartialEq<crate::Effects>`]eq().(&self, other: &craterust-analyzer cargo anstyle 1.0.14 crate/::Effectsrust-analyzer cargo anstyle 1.0.14 effect/Effects#) -> bool { |
| 406 | let other = Selfrust-analyzer cargo anstyle 1.0.14 style/impl#[Style][`PartialEq<crate::Effects>`]::fromrust-analyzer cargo anstyle 1.0.14 style/impl#[Style][`From<crate::Effects>`]from().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().other); |
| 407 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self rust-analyzer cargo anstyle 1.0.14 style/impl#[Style][`PartialEq<Self>`]eq().==rust-analyzer cargo anstyle 1.0.14 style/impl#[Style][`PartialEq<Self>`]eq(). rust-analyzer cargo anstyle 1.0.14 style/impl#[Style][`PartialEq<Self>`]eq().other |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | impl corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for Stylerust-analyzer cargo anstyle 1.0.14 style/Style# { |
| 412 | #[inline] |
| 413 | fn fmtrust-analyzer cargo anstyle 1.0.14 style/impl#[Style][Display]fmt().(&self, f: &mut corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 414 | if f.alternaterust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]alternate().() { |
| 415 | self.render_resetrust-analyzer cargo anstyle 1.0.14 style/impl#[Style]render_reset().().fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`&T`][Display]fmt().(f) |
| 416 | } else { |
| 417 | self.fmt_torust-analyzer cargo anstyle 1.0.14 style/impl#[Style]fmt_to().(f) |
| 418 | } |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 423 | struct StyleDisplayrust-analyzer cargo anstyle 1.0.14 style/StyleDisplay#(Stylerust-analyzer cargo anstyle 1.0.14 style/Style#); |
| 424 | |
| 425 | impl corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for StyleDisplayrust-analyzer cargo anstyle 1.0.14 style/StyleDisplay# { |
| 426 | fn fmtrust-analyzer cargo anstyle 1.0.14 style/impl#[StyleDisplay][Display]fmt().(&self, f: &mut corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 427 | self.0rust-analyzer cargo anstyle 1.0.14 style/StyleDisplay#0..fmt_torust-analyzer cargo anstyle 1.0.14 style/impl#[Style]fmt_to().(f) |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 432 | #[cfg(feature = "std")] |
| 433 | fn print_size_ofrust-analyzer cargo anstyle 1.0.14 style/print_size_of().() { |
| 434 | use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().; |
| 435 | dbgrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/dbg!!(size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<Stylerust-analyzer cargo anstyle 1.0.14 style/Style#>()); |
| 436 | dbgrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/dbg!!(size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<StyleDisplayrust-analyzer cargo anstyle 1.0.14 style/StyleDisplay#>()); |
| 437 | } |