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
//! Configuration for printing styled output to the console.
//!
//! This struct controls how messages are formatted:
//! - `prefix`: text shown before each message (e.g., a label)
//! - `prefix_color`: color applied to the prefix and log level tag
//! - `text_color`: color applied to the message body
//! - `log_level`: optional tag (e.g., INFO, WARN) displayed before the message
//! - `indent_level`: number of spaces to indent each line
//! - `max_chars_per_line`: maximum width before wrapping occurs
//!
//! # Full Example
//!
//! ```rust
//! use prettui::io::output::{OutputConfig, write_output};
//! use prettui::color::Color;
//!
//! fn main() -> std::io::Result<()> {
//! // Example 1: simple message with default config
//! let mut cfg1 = OutputConfig::default();
//! write_output(&cfg1, "Hello, world! This is a long message that will wrap around at the default width of 80 characters to demonstrate text wrapping functionality.")?;
//!
//! // Example 2: with prefix and indent
//! let mut cfg2 = OutputConfig::default();
//! cfg2.prefix = String::from("[App] ");
//! cfg2.prefix_color = Color::Blue;
//! cfg2.indent_level = 4;
//! write_output(&cfg2, "Indented message with a prefix.")?;
//!
//! // Example 3: with log level tag and custom text color
//! let mut cfg3 = OutputConfig::default();
//! cfg3.log_level = Some(String::from("INFO"));
//! cfg3.text_color = Color::Green;
//! cfg3.prefix = String::from("[Server] ");
//! cfg3.prefix_color = Color::Magenta;
//! write_output(&cfg3, "Server started on port 8080.")?;
//!
//! Ok(())
//! }
//! ```
use crateColor;
use cratewrap_text;
use ;
use ;
/// Writes a styled and optionally wrapped message to stdout.
///
/// This function:
/// 1. Wraps the message at `cfg.max_chars_per_line` using `wrap_text`.
/// 2. Iterates over each line and applies:
/// - indentation (if `cfg.indent_level > 0`).
/// - prefix (if non-empty), styled with `cfg.prefix_color`.
/// - log level tag (if `cfg.log_level` is `Some`), styled with `cfg.prefix_color`.
/// - message text, styled with `cfg.text_color`.
/// 3. Prints a newline after each line and flushes stdout at the end.
///
/// # Errors
/// Returns an `io::Error` if writing to stdout fails.