Skip to content

Commit b0b5c39

Browse files
committed
new: add italic, strike, and blink to fyi_ansi
remove: ">" and "~" `ansi` modifiers misc: support trailing commas for `ansi` and shortcut macros
1 parent 3653a48 commit b0b5c39

File tree

5 files changed

+185
-168
lines changed

5 files changed

+185
-168
lines changed

fyi_ansi/README.md

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
[![license](https://img.shields.io/badge/license-wtfpl-ff1493?style=flat-square)](https://en.wikipedia.org/wiki/WTFPL)
99

1010
This crate exports two simple compile-time ANSI formatting macros — `csi` and
11-
`ansi` — as well as shortcut helpers for `bold`, `dim`, and `underline`.
11+
`ansi` — as well as shortcut helpers for `blink`, `bold`, `dim`,
12+
`italic`, `strike`, and `underline`.
1213

1314
## Examples
1415

@@ -25,20 +26,22 @@ assert_eq!(
2526
);
2627
```
2728

28-
The `dim`, `bold`, and `underline` macros are only shortcuts, but can
29-
help declutter your code when there's only the one style being toggled.
29+
The `bold`, `dim`, etc., macros are only shortcuts, but can help declutter
30+
your code when there's only the one style being toggled.
3031

3132
```rust
32-
use fyi_ansi::{bold, dim, underline};
33+
use fyi_ansi::{blink, bold, dim, italic, strike, underline};
3334

3435
// Same as with `ansi`, they terminate with a blanket reset by default.
35-
assert_eq!(bold!("I'm bold!"), "\x1b[1mI'm bold!\x1b[0m");
36-
assert_eq!(dim!("I'm dim!"), "\x1b[2mI'm dim!\x1b[0m");
37-
assert_eq!(underline!("I'm underlined!"), "\x1b[4mI'm underlined!\x1b[0m");
38-
39-
// And same as `ansi`, the ">" modifier will make them terminate more
40-
// selectively instead.
41-
assert_eq!(bold!(> "I'm bold!"), "\x1b[1mI'm bold!\x1b[21m");
42-
assert_eq!(dim!(> "I'm dim!"), "\x1b[2mI'm dim!\x1b[22m");
43-
assert_eq!(underline!(> "I'm underlined!"), "\x1b[4mI'm underlined!\x1b[24m");
36+
assert_eq!(bold!("I'm bold!"), "\x1b[1mI'm bold!\x1b[0m");
37+
assert_eq!(dim!("I'm dim!"), "\x1b[2mI'm dim!\x1b[0m");
38+
assert_eq!(italic!("I'm italic!"), "\x1b[3mI'm italic!\x1b[0m");
39+
assert_eq!(underline!("I'm underlined!"), "\x1b[4mI'm underlined!\x1b[0m");
40+
assert_eq!(blink!("I'm annoying!"), "\x1b[5mI'm annoying!\x1b[0m");
41+
assert_eq!(strike!("I'm struck!"), "\x1b[9mI'm struck!\x1b[0m");
4442
```
43+
44+
## Stability
45+
46+
This library is currently under development and subject to breaking changes
47+
between dot releases, though the basic API is pretty well set.

fyi_ansi/build.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,18 @@ fn macro_codes() -> BTreeMap<Cow<'static, str>, Cow<'static, str>> {
7373
// Reset bold, dim, underline.
7474
out.insert(Cow::Borrowed("!bold"), Cow::Borrowed("21"));
7575
out.insert(Cow::Borrowed("!dim"), Cow::Borrowed("22"));
76+
out.insert(Cow::Borrowed("!italic"), Cow::Borrowed("23"));
7677
out.insert(Cow::Borrowed("!underline"), Cow::Borrowed("24"));
78+
out.insert(Cow::Borrowed("!blink"), Cow::Borrowed("25"));
79+
out.insert(Cow::Borrowed("!strike"), Cow::Borrowed("29"));
7780

7881
// Enable bold, dim, underline.
7982
out.insert(Cow::Borrowed("bold"), Cow::Borrowed("1"));
8083
out.insert(Cow::Borrowed("dim"), Cow::Borrowed("2"));
84+
out.insert(Cow::Borrowed("italic"), Cow::Borrowed("3"));
8185
out.insert(Cow::Borrowed("underline"), Cow::Borrowed("4"));
86+
out.insert(Cow::Borrowed("blink"), Cow::Borrowed("5"));
87+
out.insert(Cow::Borrowed("strike"), Cow::Borrowed("9"));
8288

8389
// Now the colors!
8490
for (k, v) in (u8::MIN..=u8::MAX).zip(COLORS.iter().map(|(v, _)| v)) {

0 commit comments

Comments
 (0)