oxur_cli/common/output.rs
1//! Colored terminal output utilities
2//!
3//! Provides consistent, colored output helpers for success, error, info,
4//! and warning messages across all Oxur CLI tools.
5
6use colored::*;
7
8/// Print a success message with a green checkmark
9///
10/// # Examples
11///
12/// ```no_run
13/// use oxur_cli::common::output::success;
14///
15/// success("Operation completed successfully");
16/// // Output: ✓ Operation completed successfully (in green)
17/// ```
18pub fn success(msg: &str) {
19 println!("{} {}", "✓".green().bold(), msg);
20}
21
22/// Print an error message with a red "Error:" prefix
23///
24/// # Examples
25///
26/// ```no_run
27/// use oxur_cli::common::output::error;
28///
29/// error("Failed to open file");
30/// // Output: Error: Failed to open file (in red, to stderr)
31/// ```
32pub fn error(msg: &str) {
33 eprintln!("{} {}", "Error:".red().bold(), msg);
34}
35
36/// Print an error message with context
37///
38/// # Examples
39///
40/// ```no_run
41/// use oxur_cli::common::output::error_with_context;
42///
43/// error_with_context("Failed to parse file", "Check the file format");
44/// // Output:
45/// // Error: Failed to parse file (in red)
46/// // → Check the file format (in yellow)
47/// ```
48pub fn error_with_context(msg: &str, context: &str) {
49 eprintln!("{} {}", "Error:".red().bold(), msg);
50 eprintln!("{} {}", "→".yellow(), context);
51}
52
53/// Print an info message with a cyan arrow
54///
55/// # Examples
56///
57/// ```no_run
58/// use oxur_cli::common::output::info;
59///
60/// info("Processing 5 files...");
61/// // Output: → Processing 5 files... (in cyan)
62/// ```
63pub fn info(msg: &str) {
64 println!("{} {}", "→".cyan(), msg);
65}
66
67/// Print a warning message with a yellow prefix
68///
69/// # Examples
70///
71/// ```no_run
72/// use oxur_cli::common::output::warning;
73///
74/// warning("File already exists, skipping");
75/// // Output: Warning: File already exists, skipping (in yellow)
76/// ```
77pub fn warning(msg: &str) {
78 println!("{} {}", "Warning:".yellow().bold(), msg);
79}
80
81/// Print a numbered step in a process
82///
83/// # Examples
84///
85/// ```no_run
86/// use oxur_cli::common::output::step;
87///
88/// step(1, "Parsing input");
89/// // Output: 1. Parsing input...
90/// ```
91pub fn step(num: usize, msg: &str) {
92 println!("{}. {}...", num, msg);
93}
94
95/// Print a step completion marker
96///
97/// # Examples
98///
99/// ```no_run
100/// use oxur_cli::common::output::{step, step_done};
101///
102/// step(1, "Parsing input");
103/// // ... do work ...
104/// step_done();
105/// // Output: ✓ Done (in green, indented)
106/// ```
107pub fn step_done() {
108 println!(" {} Done", "✓".green());
109}
110
111#[cfg(test)]
112mod tests {
113 use super::*;
114
115 // Note: These tests just verify the functions don't panic
116 // Testing actual colored output would require capturing stdout/stderr
117
118 #[test]
119 fn test_success() {
120 success("test message");
121 }
122
123 #[test]
124 fn test_error() {
125 error("test error");
126 }
127
128 #[test]
129 fn test_error_with_context() {
130 error_with_context("test error", "test context");
131 }
132
133 #[test]
134 fn test_info() {
135 info("test info");
136 }
137
138 #[test]
139 fn test_warning() {
140 warning("test warning");
141 }
142
143 #[test]
144 fn test_step() {
145 step(1, "test step");
146 }
147
148 #[test]
149 fn test_step_done() {
150 step_done();
151 }
152}