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
/// Very simple and naive colour changing for your terminal, but that's exactly what you need sometimes.
///
/// All colour-related things are used by `Display`ing them.
///
/// # Examples
///
/// ```
/// # use trivial_colours::{BgColour, Reset};
/// print!("{}", Reset);
///
/// println!("{}BgColour::Black", BgColour::Black);
/// println!("{}BgColour::Red", BgColour::Red);
/// println!("{}BgColour::Green", BgColour::Green);
/// println!("{}BgColour::Yellow", BgColour::Yellow);
/// println!("{}BgColour::Blue", BgColour::Blue);
/// println!("{}BgColour::Magenta", BgColour::Magenta);
/// println!("{}BgColour::Cyan", BgColour::Cyan);
/// println!("{}BgColour::White", BgColour::White);
///
/// println!("{}This text has default colours", Reset);
/// ```


#[cfg(all(target_os = "windows", feature = "use_winapi"))]
#[macro_use]
extern crate lazy_static;
#[cfg(all(target_os = "windows", feature = "use_winapi"))]
extern crate kernel32;
#[cfg(all(target_os = "windows", feature = "use_winapi"))]
extern crate winapi;

#[cfg(all(target_os = "windows", feature = "use_winapi"))]
mod windows_winapi;
#[cfg(all(target_os = "windows", not(feature = "use_winapi")))]
mod dummy;
#[cfg(not(target_os = "windows"))]
mod not_windows;

#[cfg(all(target_os = "windows", feature = "use_winapi"))]
pub use self::windows_winapi::*;
#[cfg(all(target_os = "windows", not(feature = "use_winapi")))]
pub use self::dummy::*;
#[cfg(not(target_os = "windows"))]
pub use self::not_windows::*;


/// The supported foreground colours.
///
/// Use them with `Display` to engage setting colour.
///
/// You can use this with `{:.0}` which will *not* change the colour.
///
/// Note: take *extreme* care, as each and every call to `Display::fmt()` on this enum might change the *terminal*'s foreground
/// colour on some platforms.
///
/// # Examples
///
/// ```
/// # use trivial_colours::{Colour, Reset};
/// # print!("{}", Reset);
/// println!("{}C{}M{}Y{}K", Colour::Cyan, Colour::Magenta, Colour::Yellow, Colour::Black);
/// # print!("{}", Reset);
/// ```
#[repr(usize)]
#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd, Debug)]
pub enum Colour {
    Black,
    Red,
    Green,
    Yellow,
    Blue,
    Magenta,
    Cyan,
    White,
}

/// The supported background colours.
///
/// Use them with `Display` to engage setting colour.
///
/// You can use this with `{:.0}` which will *not* change the colour.
///
/// Note: take *extreme* care, as each and every call to `Display::fmt()` on this enum might change the *terminal*'s background
/// colour on some platforms.
///
/// # Examples
///
/// ```
/// # use trivial_colours::{BgColour, Reset};
/// # print!("{}", Reset);
/// println!("{}C{}M{}Y{}K", BgColour::Cyan, BgColour::Magenta, BgColour::Yellow, BgColour::Black);
/// # print!("{}", Reset);
/// ```
#[repr(usize)]
#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd, Debug)]
pub enum BgColour {
    Black,
    Red,
    Green,
    Yellow,
    Blue,
    Magenta,
    Cyan,
    White,
}

/// The attribute resetter.
///
/// Use this with `Display` to reset the attributes.
///
/// You can use this with `{:.0}` which will *not* reset the colour.
///
/// Note: you *need* to `Display::fmt()` on this at least once before using it to reset changes.
///
/// Note: take *extreme* care, as each and every call to `Display::fmt()` on this enum might reset the *terminal*'s colours on
/// some platforms.
///
/// # Examples
///
/// ```
/// # use trivial_colours::{Colour, Reset};
/// // Set defaults
/// print!("{}", Reset);
///
/// println!("{}Colourful", Colour::Magenta);
/// println!("{}Not Colourful", Reset);
/// ```
#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd, Debug)]
pub struct Reset;