bel7_cli/
output.rs

1// Copyright (C) 2025-2026 Michael S. Klishin and Contributors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Colored console output utilities.
16//!
17//! Provides consistent, colored output for CLI applications.
18
19use owo_colors::OwoColorize;
20use std::fmt::Display;
21
22/// Prints a success message with a green checkmark prefix.
23///
24/// # Example
25///
26/// ```
27/// use bel7_cli::print_success;
28///
29/// print_success("Operation completed");
30/// // Output: ✓ Operation completed (green checkmark)
31/// ```
32pub fn print_success(message: impl Display) {
33    println!("{} {}", "✓".green().bold(), message);
34}
35
36/// Prints an error message to stderr with a red X prefix.
37///
38/// # Example
39///
40/// ```
41/// use bel7_cli::print_error;
42///
43/// print_error("Something went wrong");
44/// // Output: ✗ Something went wrong (red X)
45/// ```
46pub fn print_error(message: impl Display) {
47    eprintln!("{} {}", "✗".red().bold(), message);
48}
49
50/// Prints a warning message with a yellow exclamation prefix.
51///
52/// # Example
53///
54/// ```
55/// use bel7_cli::print_warning;
56///
57/// print_warning("This might cause issues");
58/// // Output: ! This might cause issues (yellow !)
59/// ```
60pub fn print_warning(message: impl Display) {
61    println!("{} {}", "!".yellow().bold(), message);
62}
63
64/// Prints an info message with a blue arrow prefix.
65///
66/// # Example
67///
68/// ```
69/// use bel7_cli::print_info;
70///
71/// print_info("Processing files...");
72/// // Output: → Processing files... (blue arrow)
73/// ```
74pub fn print_info(message: impl Display) {
75    println!("{} {}", "→".blue().bold(), message);
76}
77
78/// Prints a dimmed/muted message.
79///
80/// Useful for secondary information or hints.
81pub fn print_dimmed(message: impl Display) {
82    println!("{}", message.to_string().dimmed());
83}
84
85/// Formats a value as success (green).
86pub fn format_success<T: Display>(value: T) -> String {
87    format!("{}", value.green())
88}
89
90/// Formats a value as error (red).
91pub fn format_error<T: Display>(value: T) -> String {
92    format!("{}", value.red())
93}
94
95/// Formats a value as warning (yellow).
96pub fn format_warning<T: Display>(value: T) -> String {
97    format!("{}", value.yellow())
98}
99
100/// Formats a value as info (blue).
101pub fn format_info<T: Display>(value: T) -> String {
102    format!("{}", value.blue())
103}
104
105/// Formats a value as dimmed/muted.
106pub fn format_dimmed<T: Display>(value: T) -> String {
107    format!("{}", value.dimmed())
108}
109
110/// Formats a value as bold.
111pub fn format_bold<T: Display>(value: T) -> String {
112    format!("{}", value.bold())
113}