bricks/cli/
pretty.rs

1use std::{fmt::Display, io::IsTerminal};
2
3use owo_colors::OwoColorize;
4
5pub fn error(err: impl Display) {
6    if std::io::stdout().is_terminal() {
7        println!("{} {}", "error".red().bold(), err);
8    } else {
9        println!("error {}", err)
10    }
11}
12
13pub fn warning(msg: impl Display) {
14    if std::io::stdout().is_terminal() {
15        println!("{} {}", "warning".yellow().bold(), msg);
16    } else {
17        println!("warning {}", msg);
18    }
19}
20
21pub fn info(msg: impl Display) {
22    if std::io::stdout().is_terminal() {
23        println!("{} {}", "info".blue().bold(), msg);
24    } else {
25        println!("info {}", msg);
26    }
27}
28
29pub fn msg(title: impl Display, msg: impl Display) {
30    if std::io::stdout().is_terminal() {
31        println!("{} {}", title.purple().bold(), msg);
32    } else {
33        println!("{} {}", title, msg);
34    }
35}