Skip to content

Commit 675d9bf

Browse files
authored
Merge pull request #3 from lxl66566/master
cargo feature: red
2 parents 032d2d3 + a390c21 commit 675d9bf

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

Cargo.lock

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ license = "MIT"
1313

1414
[features]
1515
test = []
16+
red = []

README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@ exit behaviour with a call to `panic!` in order to facilitate testing.
1313
[die-exit]: https://github.com/Xavientois/die
1414

1515
## Cargo.toml
16+
1617
```toml
1718
[dependencies]
18-
die-exit = "0.3"
19+
die-exit = "0.4"
1920

2021
[dev-dependencies.die-exit]
21-
version = "0.3"
22-
features = ["test"]
22+
version = "0.4"
23+
features = ["test", "red"]
2324
```
2425

25-
## Example usage:
26+
## Example usage
2627

2728
```rust
2829
use die_exit::*;
@@ -52,9 +53,10 @@ die!(2); // prints nothing, only exits with code 3
5253
die!(); // prints nothing, only exits with code 1
5354
```
5455

55-
## Example testing:
56+
## Example testing
5657

5758
Ensure that the `test` feature is turned on.
59+
5860
```rust
5961
#[cfg(test)]
6062
mod tests {
@@ -70,11 +72,13 @@ mod tests {
7072
```
7173

7274
## `cargo` Features
75+
7376
- **test**: Turn this on if you want to run tests where `die` might be used.
7477
This will change the behaviour of `die` and its variants to call `panic!()`
7578
instead of `process::exit()`.
79+
- **red**: Red and bold output.
7680

77-
# License
81+
## License
7882

7983
This project is licensed under the MIT license ([LICENSE-MIT](LICENSE-MIT)
80-
http://opensource.org/licenses/MIT)
84+
http://opensource.org/licenses/MIT)

src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ use std::process;
1010
/// const of 1
1111
pub const DEFAULT_EXIT_CODE: i32 = 1;
1212

13+
#[cfg(feature = "red")]
14+
macro_rules! eprintln {
15+
($($arg:tt)*) => {
16+
use std::io::Write;
17+
writeln!(&mut ::std::io::stderr(), "\u{001b}[91;49;1m{}\u{001b}[0m", format!($($arg)*)).expect("failed printing to stderr");
18+
};
19+
}
20+
1321
/// Prints a message to [`stderr`] and terminates the current process with the specified exit code
1422
/// or 1 if no exit code is specified, by calling [`eprintln`]!() on all arguments followed by
1523
/// [process::exit(exit_code)][exit]

0 commit comments

Comments
 (0)