1 //! Macros used on ouch.
3 /// Macro that prints \[INFO\] messages, wraps [`println`].
5 /// There are essentially two different versions of the `info!()` macro:
6 /// - `info!(accessible, ...)` should only be used for short, important
7 /// information which is expected to be useful for e.g. blind users whose
8 /// text-to-speach systems read out every output line, which is why we
9 /// should reduce nonessential output to a minimum when running in
11 /// - `info!(inaccessible, ...)` can be used more carelessly / for less
12 /// important information. A seeing user can easily skim through more lines
13 /// of output, so e.g. reporting every single processed file can be helpful,
14 /// while it would generate long and hard to navigate text for blind people
15 /// who have to have each line of output read to them aloud, whithout to
16 /// ability to skip some lines deemed not important like a seeing person would.
18 /// By default `info` outputs to Stdout, if you want to specify the output you can use
19 /// `@display_handle` modifier
23 // Accessible (short/important) info message.
24 // Show info message even in ACCESSIBLE mode
25 (accessible, $($arg:tt)*) => {
26 info!(@::std::io::stdout(), accessible, $($arg)*);
28 (@$display_handle: expr, accessible, $($arg:tt)*) => {
29 let display_handle = &mut $display_handle;
30 // if in ACCESSIBLE mode, suppress the "[INFO]" and just print the message
31 if !(*$crate::cli::ACCESSIBLE.get().unwrap()) {
32 $crate::macros::_info_helper(display_handle);
34 writeln!(display_handle, $($arg)*).unwrap();
36 // Inccessible (long/no important) info message.
37 // Print info message if ACCESSIBLE is not turned on
38 (inaccessible, $($arg:tt)*) => {
39 info!(@::std::io::stdout(), inaccessible, $($arg)*);
41 (@$display_handle: expr, inaccessible, $($arg:tt)*) => {
42 if (!$crate::cli::ACCESSIBLE.get().unwrap())
44 let display_handle = &mut $display_handle;
45 $crate::macros::_info_helper(display_handle);
46 writeln!(display_handle, $($arg)*).unwrap();
51 /// Helper to display "\[INFO\]", colored yellow
52 pub fn _info_helper(handle: &mut impl std::io::Write) {
53 use crate::utils::colors::{RESET, YELLOW};
55 write!(handle, "{}[INFO]{} ", *YELLOW, *RESET).unwrap();
58 /// Macro that prints \[WARNING\] messages, wraps [`println`].
60 macro_rules! warning {
62 $crate::macros::_warning_helper();
67 /// Helper to display "\[WARNING\]", colored orange
68 pub fn _warning_helper() {
69 use crate::utils::colors::{ORANGE, RESET};
71 if !crate::cli::ACCESSIBLE.get().unwrap() {
72 print!("{}Warning:{} ", *ORANGE, *RESET);
74 print!("{}[WARNING]{} ", *ORANGE, *RESET);