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
//! Macros for ergonomic status messages printed to stdout/stderr
//!
//! # `status_ok!`: Successful status messages
//!
//! ```
//! # #[macro_use] extern crate abscissa;
//! # fn main() {
//! // Print a Cargo-like justified status to STDOUT
//! status_ok!("Loaded", "app loaded successfully");
//! # }
//! ```
//!
//! # `status_err!`: Error messages
//!
//! ```
//! # #[macro_use] extern crate abscissa;
//! # fn main() {
//! // Print an error message
//! status_err!("something bad happened");
//! # }
//! ```
//!
//! # `status_attr_ok!`: Successful attributes
//!
//! ```
//! # #[macro_use] extern crate abscissa;
//! # fn main() {
//! // Print an indented attribute to STDOUT
//! status_attr_ok!("good", "yep");
//! # }
//! ```
//!
//! # `status_attr_error!`: Error attributes
//!
//! ```
//! # #[macro_use] extern crate abscissa;
//! # fn main() {
//! // Print an error attribute to STDERR
//! status_attr_err!("error", "yep");
//! # }
//! ```

/// Print a justified status message (in the given color if colors are enabled)
#[macro_export]
macro_rules! status {
    ($stream:expr, $color:expr, $status:expr, $msg:expr) => {
        $crate::status($stream, $color, $status, $msg, true);
    };
    ($stream:expr, $color:expr, $status:expr, $fmt:expr, $($arg:tt)+) => {
        status!($stream, $color, $status, format!($fmt, $($arg)+));
    };
}

/// Print an unjustified status message (in the given color if colors are enabled)
#[macro_export]
macro_rules! status_nojust {
    ($stream:expr, $color:expr, $status:expr, $msg:expr) => {
        $crate::status($stream, $color, $status, $msg, false);
    };
    ($stream:expr, $color:expr, $status:expr, $fmt:expr, $($arg:tt)+) => {
        status!($stream, $color, $status, format!($fmt, $($arg)+));
    };
}

/// Print a success status message (in green if colors are enabled)
///
/// ```
/// # #[macro_use] extern crate abscissa;
/// # fn main() {
/// // Print a Cargo-like justified status to STDOUT
/// status_ok!("Loaded", "app loaded successfully");
/// # }
/// ```
#[macro_export]
macro_rules! status_ok {
    ($status:expr, $msg:expr) => {
        status!($crate::Stream::Stdout, $crate::shell::color::GREEN, $status, $msg);
    };
    ($status:expr, $fmt:expr, $($arg:tt)+) => {
        status_ok!($status, format!($fmt, $($arg)+));
    };
}

/// Print an informational status message (in cyan if colors are enabled)
///
/// ```
/// # #[macro_use] extern crate abscissa;
/// # fn main() {
/// // Print a Cargo-like justified status to STDOUT
/// status_info!("Info", "you may care to know about");
/// # }
/// ```
#[macro_export]
macro_rules! status_info {
    ($status:expr, $msg:expr) => {
        status!($crate::Stream::Stdout, $crate::shell::color::BRIGHT_CYAN, $status, $msg);
    };
    ($status:expr, $fmt:expr, $($arg:tt)+) => {
        status_info!($status, format!($fmt, $($arg)+));
    };
}

/// Print a warning status message (in yellow if colors are enabled)
///
/// ```
/// # #[macro_use] extern crate abscissa;
/// # fn main() {
/// // Print a Cargo-like justified status to STDOUT
/// status_warn!("heads up, there's something you should know");
/// # }
/// ```
#[macro_export]
macro_rules! status_warn {
    ($msg:expr) => {
        status_nojust!($crate::Stream::Stdout, $crate::shell::color::YELLOW, "warning:", $msg);
    };
    ($fmt:expr, $($arg:tt)+) => {
        status_warn!(format!($fmt, $($arg)+));
    };
}

/// Print an error message (in red if colors are enabled)
///
/// ```
/// # #[macro_use] extern crate abscissa;
/// # fn main() {
/// // Print an error message
/// status_err!("something bad happened");
/// # }
/// ```
#[macro_export]
macro_rules! status_err {
    ($msg:expr) => {
        status_nojust!($crate::Stream::Stderr, $crate::shell::color::RED, "error:", $msg);
    };
    ($fmt:expr, $($arg:tt)+) => {
        status_err!(format!($fmt, $($arg)+));
    };
}

/// Print a tab-delimited status (with the given color if enabled)
#[macro_export]
macro_rules! status_attr {
    ($stream:expr, $color:expr, $attr:expr, $msg:expr) => {
        // TODO: this is kind of hax... use a better format string?
        let attr_delimited = if $attr.len() >= 7 {
            format!("{}:", $attr)
        } else {
            format!("{}:\t", $attr)
        };

        status_nojust!(
            $stream,
            $color,
            attr_delimited,
            $msg
        );
    };
    ($stream:expr, $color:expr, $attr: expr, $fmt:expr, $($arg:tt)+) => {
        status_attr!($stream, $attr, format!($fmt, $($arg)+));
    }
}

/// Print a tab-delimited status attribute (in green if colors are enabled)
///
/// ```
/// # #[macro_use] extern crate abscissa;
/// # fn main() {
/// // Print an indented attribute to STDOUT
/// status_attr_ok!("good", "yep");
/// # }
/// ```
#[macro_export]
macro_rules! status_attr_ok {
    ($attr:expr, $msg:expr) => {
        status_attr!($crate::Stream::Stdout, $crate::shell::color::GREEN, $attr, $msg);
    };
    ($attr: expr, $fmt:expr, $($arg:tt)+) => {
        status_attr_ok!($attr, format!($fmt, $($arg)+));
    }
}

/// Print a tab-delimited status attribute (in red if colors are enabled)
///
/// ```
/// # #[macro_use] extern crate abscissa;
/// # fn main() {
/// // Print an error attribute to STDERR
/// status_attr_err!("error", "yep");
/// # }
/// ```
#[macro_export]
macro_rules! status_attr_err {
    ($attr:expr, $msg:expr) => {
        status_attr!($crate::Stream::Stderr, $crate::shell::color::RED, $attr, $msg);
    };
    ($attr: expr, $fmt:expr, $($arg:tt)+) => {
        status_attr_err!($attr, format!($fmt, $($arg)+));
    }
}