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
/*!
# FYI Msg
[](https://docs.rs/fyi_msg/)
<br>
[](https://crates.io/crates/fyi_msg)
[](https://github.com/Blobfolio/fyi/actions)
[](https://deps.rs/repo/github/blobfolio/fyi)<br>
[](https://en.wikipedia.org/wiki/WTFPL)
This crate contains the objects providing the heart of the [FYI command line application](https://github.com/blobfolio/fyi), namely [`Msg`], a simple struct for status-like messages that can be easily printed to `STDOUT` or `STDERR`.
## Examples
```
use fyi_msg::{Msg, MsgKind};
// One way.
Msg::new(MsgKind::Success, "You did it!")
.with_newline(true)
.print();
// Another equivalent way.
Msg::success("You did it!").print();
```
For more usage examples, check out the `examples/msg` demo, which covers just about every common use case.
## Macros
| Macro | Equivalent |
| ----- | ---------- |
| `confirm!(…)` | `Msg::new(MsgKind::Confirm, "Some question…").prompt()` |
## Optional Features
| Feature | Description |
| ------- | ----------- |
| `fitted` | Enables [`Msg::fitted`] for obtaining a slice trimmed to a specific display width. |
| `progress` | Enables [`Progless`], a thread-safe CLI progress bar displayer.
| `timestamps` | Enables timestamp-related methods and flags like [`Msg::with_timestamp`]. |
*/
#![deny(unsafe_code)]
#![warn(
clippy::filetype_is_file,
clippy::integer_division,
clippy::needless_borrow,
clippy::nursery,
clippy::pedantic,
clippy::perf,
clippy::suboptimal_flops,
clippy::unneeded_field_pattern,
macro_use_extern_crate,
missing_copy_implementations,
missing_debug_implementations,
missing_docs,
non_ascii_idents,
trivial_casts,
trivial_numeric_casts,
unreachable_pub,
unused_crate_dependencies,
unused_extern_crates,
unused_import_braces,
)]
#![allow(
clippy::module_name_repetitions,
clippy::redundant_pub_crate,
)]
#![cfg_attr(feature = "docsrs", feature(doc_cfg))]
mod msg;
#[cfg(feature = "fitted")] mod fitted;
#[cfg(feature = "progress")] mod progress;
#[doc(hidden)]
pub use msg::{
buffer::BUFFER2,
buffer::BUFFER3,
buffer::BUFFER4,
buffer::BUFFER5,
buffer::BUFFER6,
buffer::BUFFER7,
buffer::BUFFER8,
buffer::BUFFER9,
buffer::BUFFER10,
buffer::MsgBuffer,
};
pub use msg::{
FLAG_INDENT,
FLAG_NEWLINE,
kind::MsgKind,
Msg,
};
#[cfg(feature = "fitted")]
#[cfg_attr(feature = "docsrs", doc(cfg(feature = "fitted")))]
pub use fitted::{
length_width,
width,
};
#[cfg(feature = "progress")]
#[cfg_attr(feature = "docsrs", doc(cfg(feature = "progress")))]
pub use progress::{
ba::BeforeAfter,
Progless,
error::ProglessError,
};
#[cfg(feature = "timestamps")]
#[cfg_attr(feature = "docsrs", doc(cfg(feature = "timestamps")))]
pub use msg::FLAG_TIMESTAMP;
#[macro_use]
mod macros {
#[macro_export(local_inner_macros)]
/// # Confirm.
///
/// This is a convenience macro for generating a confirmation message,
/// handling the prompting, and returning the response `bool`.
///
/// ## Example
///
/// ```no_run
/// use fyi_msg::{confirm, Msg, MsgKind};
///
/// // The manual way:
/// if Msg::new(MsgKind::Confirm, "Do you like chickens?").prompt() {
/// println!("That's great! They like you too!");
/// }
///
/// // The macro way:
/// if confirm!("Do you like chickens?") {
/// println!("That's great! They like you too!");
/// }
///
/// // Indendation can be set with the macro too by appending a second
/// // argument:
/// if confirm!("Do you like chickens?", 1) {
/// println!(" That's great! They like you too!");
/// }
/// ```
macro_rules! confirm {
($text:expr) => (
$crate::Msg::new($crate::MsgKind::Confirm, $text).prompt()
);
($text:expr, $indent:expr) => (
$crate::Msg::new($crate::MsgKind::Confirm, $text)
.with_indent($indent)
.prompt()
);
}
}