1 | //! A module which contains [`ANSIFmt`] trait and its implementation [`ANSIStr`] |
2 | #[cfg_attr (feature = "std" , doc = "and [`ANSIBuf`]." )] |
3 | #[cfg (feature = "std" )] |
4 | mod ansi_buf; |
5 | mod ansi_str; |
6 | |
7 | #[cfg (feature = "std" )] |
8 | pub use ansi_buf::ANSIBuf; |
9 | |
10 | pub use self::ansi_str::ANSIStr; |
11 | |
12 | use core::fmt::{self, Write}; |
13 | |
14 | /// A trait which prints an ANSI prefix and suffix. |
15 | pub trait ANSIFmt { |
16 | /// Print ANSI prefix. |
17 | fn fmt_ansi_prefix<W: Write>(&self, f: &mut W) -> fmt::Result; |
18 | |
19 | /// Print ANSI suffix. |
20 | fn fmt_ansi_suffix<W: Write>(&self, f: &mut W) -> fmt::Result { |
21 | f.write_str(" \u{1b}[0m" ) |
22 | } |
23 | } |
24 | |
25 | impl<C> ANSIFmt for &C |
26 | where |
27 | C: ANSIFmt, |
28 | { |
29 | fn fmt_ansi_prefix<W: Write>(&self, f: &mut W) -> fmt::Result { |
30 | C::fmt_ansi_prefix(self, f) |
31 | } |
32 | |
33 | fn fmt_ansi_suffix<W: Write>(&self, f: &mut W) -> fmt::Result { |
34 | C::fmt_ansi_suffix(self, f) |
35 | } |
36 | } |
37 | |