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
use std::fmt;


/// Some properties not necessarily releated to foreground and background colors and are in this enum.
pub enum Styles {
	/// Sometimes you want to turn off all properties and switching to default for every property is quite unreadable.
	/// By using this, you can turn off all ansi customizations.
	/// # Example
	/// ```
	/// # use colory::{ForegroundColor as fg, BackgroundColor as bg, Off};
	/// #
	/// # fn main() {
	/// // Instead of doing this
	/// println!("{}{}This is green text with a blue background.{}{} This is plain text.", bg::Blue, fg::Green, bg::Normal, fg::Normal);
	/// // You can do
	/// println!("{}{}This is green text with a blue background.{} This is plain text.", bg::Blue, fg::Green, Off);
	/// # }
	/// ```
	Off,
	Bold,
	Dim,
	Italic,
	Underline,
	SlowBlink,
	FaskBlink,
	Reverse,
	Conseal,
	Strike,
	DefaultFont,
	DoublyUnderline,
	BoldOrDimOff,
	ItalicOff,
	UnderlineOff,
	BlinkOff,
	ReverseOff,
	Reveal,
	StrikeOff,
}

impl fmt::Display for Styles {
	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
	  let code = match self {
        Styles::Off=> 0,
		Styles::Bold => 1,
		Styles::Dim => 2,
		Styles::Italic => 3,
		Styles::Underline => 4,
		Styles::SlowBlink => 5,
		Styles::FaskBlink => 6,
		Styles::Reverse => 7,
		Styles::Conseal => 8,
		Styles::Strike => 9,
		Styles::DefaultFont => 10,
		Styles::DoublyUnderline => 21,
		Styles::BoldOrDimOff => 22,
		Styles::ItalicOff => 23,
		Styles::UnderlineOff => 24,
		Styles::BlinkOff => 25,
		Styles::ReverseOff => 27,
		Styles::Reveal => 28,
		Styles::StrikeOff => 29,
	  };
	  write!(f, "\x1b[{}m", code)
	}
  }