1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// cleansh-workspace/cleansh/src/ui/output_format.rs
//! Module for consistent command-line output formatting in Cleansh.
//!
//! This module provides utility functions for printing various types of messages
//! to standard output or standard error, applying theme-based styling (colors)
//! when the terminal supports it. It centralizes text styling logic to ensure
//! a consistent user interface experience across the application.
use crate;
use OwoColorize;
use ;
// Removed: use is_terminal::IsTerminal; // Not needed in this module now as we pass `enable_colors` directly
/// Helper to get a styled string based on the theme.
///
/// This function applies ANSI color codes to a given `text` based on the
/// specified `ThemeEntry` and `theme_map`. If `enable_colors` is `false`
/// or if no specific style/color is found for the given `ThemeEntry`,
/// the original text is returned without any color codes.
///
/// It returns an owned `String` that implements `Display`.
/// Made `pub(crate)` for use by other UI modules within the crate.
///
/// # Arguments
///
/// * `text` - The string slice to apply styling to.
/// * `entry` - The `ThemeEntry` indicating which style to use from the `theme_map`
/// (e.g., `ThemeEntry::Info`, `ThemeEntry::Error`).
/// * `theme_map` - A `HashMap` containing the defined `ThemeStyle`s for various `ThemeEntry`s.
/// * `enable_colors` - A boolean indicating whether ANSI colors should actually be applied.
/// If `false`, the original text is returned without color codes,
/// regardless of theme configuration.
///
/// # Returns
///
/// A `String` with ANSI color codes applied if `enable_colors` is true and a matching
/// theme color is found. If no specific color is found but colors are enabled,
/// it falls back to white. Otherwise (if colors are not enabled), the original `text`
/// is returned as a `String` without color codes.
pub
/// Prints a general message to the given writer, with an optional theme entry for styling.
///
/// If `theme_entry` is `None`, it defaults to `ThemeEntry::Info`.
/// The message is automatically followed by a newline character.
/// Colors are applied only if `enable_colors` is true.
///
/// # Type Parameters
///
/// * `W`: A type that implements `std::io::Write`.
///
/// # Arguments
///
/// * `writer` - The output writer (e.g., `&mut io::stdout()` or `&mut io::stderr()`).
/// * `message` - The string slice containing the message to print.
/// * `theme_map` - A `HashMap` containing the defined `ThemeStyle`s for styling.
/// * `theme_entry` - An `Option<ThemeEntry>` specifying the desired style. If `None`, `ThemeEntry::Info` is used.
/// * `enable_colors` - A boolean indicating whether ANSI colors should be applied.
///
/// # Returns
///
/// An `io::Result<()>` indicating success or an I/O error during writing.
/// Prints an informational message to the given writer, styled by the theme.
///
/// This function uses `ThemeEntry::Info` for styling. The message is automatically
/// followed by a newline character. Colors are applied only if `enable_colors` is true.
///
/// # Type Parameters
///
/// * `W`: A type that implements `std::io::Write`.
///
/// # Arguments
///
/// * `writer` - The output writer (e.g., `&mut io::stderr()`).
/// * `message` - The string slice containing the informational message.
/// * `theme_map` - A `HashMap` containing the defined `ThemeStyle`s for styling.
/// * `enable_colors` - A boolean indicating whether ANSI colors should be applied.
///
/// # Returns
///
/// An `io::Result<()>` indicating success or an I/O error during writing.
/// Prints an error message to the given writer, styled by the theme.
///
/// This function prefixes the message with "ERROR: " and uses `ThemeEntry::Error` for styling.
/// The message is automatically followed by a newline character. Colors are applied only
/// if `enable_colors` is true.
///
/// # Type Parameters
///
/// * `W`: A type that implements `std::io::Write`.
///
/// # Arguments
///
/// * `writer` - The output writer (e.g., `&mut io::stderr()`).
/// * `message` - The string slice containing the error message.
/// * `theme_map` - A `HashMap` containing the defined `ThemeStyle`s for styling.
/// * `enable_colors` - A boolean indicating whether ANSI colors should be applied.
///
/// # Returns
///
/// An `io::Result<()>` indicating success or an I/O error during writing.
/// Prints a warning message to the given writer, styled by the theme.
///
/// This function prefixes the message with "WARNING: " and uses `ThemeEntry::Warn` for styling.
/// The message is automatically followed by a newline character. Colors are applied only
/// if `enable_colors` is true.
///
/// # Type Parameters
///
/// * `W`: A type that implements `std::io::Write`.
///
/// # Arguments
///
/// * `writer` - The output writer (e.g., `&mut io::stderr()`).
/// * `message` - The string slice containing the warning message.
/// * `theme_map` - A `HashMap` containing the defined `ThemeStyle`s for styling.
/// * `enable_colors` - A boolean indicating whether ANSI colors should be applied.
///
/// # Returns
///
/// An `io::Result<()>` indicating success or an I/O error during writing.