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