simple_colors/macros/
bg.rs

1#[macro_export]
2/// Adds a background to text. See also the different bg_{color} methods to be able to display
3/// text with a background and text color (e.g. [`bg_blue!`])
4///
5/// # Example
6/// ```rust
7/// # use simple_colors::{green, bg, printlnc};
8/// # fn main() {
9/// printlnc!(bg!(green!("This text has a green background")))
10/// # }
11/// ```
12macro_rules! bg {
13    ( $str: tt ) => ({
14        use simple_colors::custom::Style as be_jonaseveraert_colors_custom_style;
15        &format!("\x1b[7m{}\x1b[0m", $str)
16    });
17    // Allows to call other style macros inside of this macro
18    ( $other: expr) => ({
19        use simple_colors::custom::Style as be_jonaseveraert_colors_custom_style;
20        &format!("\x1b[7m{}\x1b[0m", $other)
21    })
22}
23
24#[macro_export]
25/// Adds a background to text
26///
27/// # Example
28/// ```rust
29/// # use simple_colors::{green, bg_black, bold, printlnc};
30/// # fn main() {
31/// printlnc!(bg_black!(green!(bold!("This text has a black background and bold, green text"))))
32/// # }
33/// ```
34macro_rules! bg_black {
35    ( $str: tt ) => ({
36        use simple_colors::custom::Style as be_jonaseveraert_colors_custom_style;
37        &format!("\x1b[40m{}\x1b[0m", $str)
38    });
39    // Allows to call other style macros inside of this macro
40    ( $other: expr) => ({
41        use simple_colors::custom::Style as be_jonaseveraert_colors_custom_style;
42        &format!("\x1b[40m{}\x1b[0m", $other)
43    })
44}
45
46#[macro_export]
47macro_rules! bg_red {
48    ( $str: tt ) => ({
49        use simple_colors::custom::Style as be_jonaseveraert_colors_custom_style;
50        &format!("\x1b[41m{}\x1b[0m", $str)
51    });
52    // Allows to call other style macros inside of this macro
53    ( $other: expr) => ({
54        use simple_colors::custom::Style as be_jonaseveraert_colors_custom_style;
55        &format!("\x1b[41m{}\x1b[0m", $other)
56    })
57}
58
59#[macro_export]
60macro_rules! bg_green {
61    ( $str: tt ) => ({
62        use simple_colors::custom::Style as be_jonaseveraert_colors_custom_style;
63        &format!("\x1b[42m{}\x1b[0m", $str)
64    });
65    // Allows to call other style macros inside of this macro
66    ( $other: expr) => ({
67        use simple_colors::custom::Style as be_jonaseveraert_colors_custom_style;
68        &format!("\x1b[42m{}\x1b[0m", $other)
69    })
70}
71
72#[macro_export]
73macro_rules! bg_yellow {
74    ( $str: tt ) => ({
75        use simple_colors::custom::Style as be_jonaseveraert_colors_custom_style;
76        &format!("\x1b[43m{}\x1b[0m", $str)
77    });
78    // Allows to call other style macros inside of this macro
79    ( $other: expr) => ({
80        use simple_colors::custom::Style as be_jonaseveraert_colors_custom_style;
81        &format!("\x1b[43m{}\x1b[0m", $other)
82    })
83}
84
85#[macro_export]
86/// ![bg_blue](https://raw.githubusercontent.com/jomy10/simple_colors/master/assets/gif/bg_blue.gif)
87macro_rules! bg_blue {
88    ( $str: tt ) => ({
89        use simple_colors::custom::Style as be_jonaseveraert_colors_custom_style;
90        &format!("\x1b[44m{}\x1b[0m", $str)
91    });
92    // Allows to call other style macros inside of this macro
93    ( $other: expr) => ({
94        use simple_colors::custom::Style as be_jonaseveraert_colors_custom_style;
95        &format!("\x1b[44m{}\x1b[0m", $other)
96    })
97}
98
99#[macro_export]
100macro_rules! bg_magenta {
101    ( $str: tt ) => ({
102        use simple_colors::custom::Style as be_jonaseveraert_colors_custom_style;
103        &format!("\x1b[45m{}\x1b[0m", $str)
104    });
105    // Allows to call other style macros inside of this macro
106    ( $other: expr) => ({
107        use simple_colors::custom::Style as be_jonaseveraert_colors_custom_style;
108        &format!("\x1b[45m{}\x1b[0m", $other)
109    })
110}
111
112#[macro_export]
113macro_rules! bg_cyan {
114    ( $str: tt ) => ({
115        use simple_colors::custom::Style as be_jonaseveraert_colors_custom_style;
116        &format!("\x1b[46m{}\x1b[0m", $str)
117    });
118    // Allows to call other style macros inside of this macro
119    ( $other: expr) => ({
120        use simple_colors::custom::Style as be_jonaseveraert_colors_custom_style;
121        &format!("\x1b[46m{}\x1b[0m", $other)
122    })
123}
124
125#[macro_export]
126macro_rules! bg_light_gray {
127    ( $str: tt ) => ({
128        use simple_colors::custom::Style as be_jonaseveraert_colors_custom_style;
129        &format!("\x1b[47m{}\x1b[0m", $str)
130    });
131    // Allows to call other style macros inside of this macro
132    ( $other: expr) => ({
133        use simple_colors::custom::Style as be_jonaseveraert_colors_custom_style;
134        &format!("\x1b[47m{}\x1b[0m", $other)
135    })
136}
137
138#[macro_export]
139macro_rules! bg_dark_gray {
140    ( $str: tt ) => ({
141        use simple_colors::custom::Style as be_jonaseveraert_colors_custom_style;
142        &format!("\x1b[100m{}\x1b[0m", $str)
143    });
144    // Allows to call other style macros inside of this macro
145    ( $other: expr) => ({
146        use simple_colors::custom::Style as be_jonaseveraert_colors_custom_style;
147        &format!("\x1b[100m{}\x1b[0m", $other)
148    })
149}
150
151#[macro_export]
152macro_rules! bg_light_red {
153    ( $str: tt ) => ({
154        use simple_colors::custom::Style as be_jonaseveraert_colors_custom_style;
155        &format!("\x1b[101m{}\x1b[0m", $str)
156    });
157    // Allows to call other style macros inside of this macro
158    ( $other: expr) => ({
159        use simple_colors::custom::Style as be_jonaseveraert_colors_custom_style;
160        &format!("\x1b[101m{}\x1b[0m", $other)
161    })
162}
163
164#[macro_export]
165macro_rules! bg_light_green {
166    ( $str: tt ) => ({
167        use simple_colors::custom::Style as be_jonaseveraert_colors_custom_style;
168        &format!("\x1b[102m{}\x1b[0m", $str)
169    });
170    // Allows to call other style macros inside of this macro
171    ( $other: expr) => ({
172        use simple_colors::custom::Style as be_jonaseveraert_colors_custom_style;
173        &format!("\x1b[102m{}\x1b[0m", $other)
174    })
175}
176
177#[macro_export]
178macro_rules! bg_light_yellow {
179    ( $str: tt ) => ({
180        use simple_colors::custom::Style as be_jonaseveraert_colors_custom_style;
181        &format!("\x1b[103m{}\x1b[0m", $str)
182    });
183    // Allows to call other style macros inside of this macro
184    ( $other: expr) => ({
185        use simple_colors::custom::Style as be_jonaseveraert_colors_custom_style;
186        &format!("\x1b[103m{}\x1b[0m", $other)
187    })
188}
189
190#[macro_export]
191macro_rules! bg_light_blue {
192    ( $str: tt ) => ({
193        use simple_colors::custom::Style as be_jonaseveraert_colors_custom_style;
194        &format!("\x1b[104m{}\x1b[0m", $str)
195    });
196    // Allows to call other style macros inside of this macro
197    ( $other: expr) => ({
198        use simple_colors::custom::Style as be_jonaseveraert_colors_custom_style;
199        &format!("\x1b[104m{}\x1b[0m", $other)
200    })
201}
202
203#[macro_export]
204macro_rules! bg_light_magenta {
205    ( $str: tt ) => ({
206        use simple_colors::custom::Style as be_jonaseveraert_colors_custom_style;
207        &format!("\x1b[105m{}\x1b[0m", $str)
208    });
209    // Allows to call other style macros inside of this macro
210    ( $other: expr) => ({
211        use simple_colors::custom::Style as be_jonaseveraert_colors_custom_style;
212        &format!("\x1b[105m{}\x1b[0m", $other)
213    })
214}
215
216#[macro_export]
217macro_rules! bg_light_cyan {
218    ( $str: tt ) => ({
219        use simple_colors::custom::Style as be_jonaseveraert_colors_custom_style;
220        &format!("\x1b[106m{}\x1b[0m", $str)
221    });
222    // Allows to call other style macros inside of this macro
223    ( $other: expr) => ({
224        use simple_colors::custom::Style as be_jonaseveraert_colors_custom_style;
225        &format!("\x1b[106m{}\x1b[0m", $other)
226    })
227}
228
229#[macro_export]
230macro_rules! bg_white {
231    ( $str: tt ) => ({
232        use simple_colors::custom::Style as be_jonaseveraert_colors_custom_style;
233        &format!("\x1b[107m{}\x1b[0m", $str)
234    });
235    // Allows to call other style macros inside of this macro
236    ( $other: expr) => ({
237        use simple_colors::custom::Style as be_jonaseveraert_colors_custom_style;
238        &format!("\x1b[107m{}\x1b[0m", $other)
239    })
240}