1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
//! A simple, fast library for styling text with ANSI escape codes.
//!
//! # Features
//!
//! - Simple, intuitive API
//! - Fast, no allocations
//! - No dependencies
//! - `#![no_std]` out of the box
//! - Hyperlink support
//!
//! # Basic Usage
//!
//! Import the [`Styleable`](crate::Styleable) trait for an easy way to create
//! styled values. Then use the methods from [`Styled`](crate::Styled) to style the value.
//!
//! ```
//! use stylic::Styleable;
//!
//! println!("{}", "Hello, World!".styled().green().italic());
//! ```
//!
//! You can also create a style and apply it later. [`Style`](struct@crate::Style) has the same
//! styling options as [`Styled`](crate::Styled). Styling methods (on both types) are `const`,
//! so you can create constant styles.
//!
//! ```
//! use stylic::{Style, Styleable};
//!
//! const EMPHASIS: Style = Style::new().bold().italic();
//! println!("To be or not to be, {} is the question.", "that".styled_with(EMPHASIS));
//! ```
//!
//! # Styling
//!
//! Both [`Style`](struct@crate::Style) and [`Styled`](crate::Styled) have methods for setting
//! the foreground color, background color, underline color, and attributes of the text
//! (such as bold, italic, etc).
//!
//! Available attributes are:
//!
//! - `bold`
//! - `dim`
//! - `italic`
//! - `underlined`
//! - `blink`
//! - `inverted`
//! - `hidden`
//! - `strikethrough`
//!
//! Available colors include basic ANSI colors, the extended 256-color palette, and RGB colors.
//!
//! The ANSI colors are:
//!
//! - `black`
//! - `red`
//! - `green`
//! - `yellow`
//! - `blue`
//! - `magenta`
//! - `cyan`
//! - `white`
//!
//! Plus bright variants.
//!
//! There are methods for setting the foreground color, background color and underline color
//! to basic ANSI colors:
//!
//! ```rust
//! use stylic::Styleable;
//!
//! println!("{}", "Hello, World!".styled().black().on_blue());
//! ```
//!
//! There are also [`fg`](fn@crate::Style::fg), [`bg`](fn@crate::Style::bg)
//! and [`underline_colored`](fn@crate::Style::underline_colored) methods that take a `Color`,
//! allowing the use of colors from the extended 256-color palette and RGB colors:
//!
//! ```
//! use stylic::{Styleable, BasicColor, Color};
//!
//! // Setting the foreground color to red.
//! println!("{}", "Hello, World!".styled().fg(Color::Basic(BasicColor::Red)));
//! println!("{}", "Hello, World!".styled().fg(BasicColor::Red.into()));
//!
//! // Setting the background color to a color from the 256-color palette.
//! println!("{}", "Hello, World!".styled().bg(Color::Extended(58)));
//! println!("{}", "Hello, World!".styled().bg(58.into()));
//!
//! // Setting the underline color to a RGB color.
//! println!("{}", "Hello, World!".styled().underline_colored(Color::Rgb(255, 0, 255)));
//! println!("{}", "Hello, World!".styled().underline_colored((255, 0, 255).into()));
//! ```
//!
//! You can also create attributes separately and apply them later:
//!
//! ```
//! use stylic::{Styleable, Attributes};
//!
//! let my_attrs = Attributes::ITALIC | Attributes::STRIKETHROUGH;
//! println!("My homework was {}", "redacted".styled().attributes(my_attrs));
//! ```
//!
//! Attributes have methods for performing bitwise operations in a `const` environment:
//!
//! ```
//! use stylic::{Styleable, Attributes};
//!
//! const MY_ATTRS: Attributes = Attributes::ITALIC.or(Attributes::BLINK);
//! println!("Did you hear about the {}?", "thing".styled().attributes(MY_ATTRS));
//! ```
//!
//! # Hyperlinks
//!
//! You can add a hyperlink to a styled value using the [`Styled::link`](fn@crate::Styled::link) method:
//!
//! ```
//! use stylic::Styleable;
//!
//! println!("{}", "Example!".styled().link("https://example.com"));
//! ```
// These are used for `cargo-rdme`.
use builder_methods;
pub use ;
/// A trait for making types styleable with ANSI colors and attributes.
///
/// This trait is implemented for all ([`Sized`](core::marker::Sized)) types and allows easily creating
/// a [`Styled`](crate::Styled) value from any type using the `.styled()` or `.styled_with(style)` method.
/// Type parameter for [`Styled`](crate::Styled) value with no associated link.
;
/// Type parameter for [`Styled`](crate::Styled) value with an associated link.
;
/// A styled value.
///
/// Has builder methods for building a style. See crate level docs for examples
/// of these.
///
/// Supports hyperlinks via the [`link`](`crate::Styled::link`) method.
///
/// This type can be created using [`Styleable::styled`](crate::Styleable::styled)
/// or [`Styleable::styled_with`](crate::Styleable::styled_with).