pub struct AlignOptions {
pub align: Alignment,
pub split: String,
pub pad: char,
}Expand description
Configuration options for text alignment operations.
This struct allows you to customize how text alignment is performed, including the alignment direction, line separator, and padding character.
§Examples
use ansi_align::{AlignOptions, Alignment, ansi_align_with_options};
// Basic usage with default settings
let opts = AlignOptions::new(Alignment::Center);
// Customized options
let opts = AlignOptions::new(Alignment::Right)
.with_split("|")
.with_pad('.');
let text = "short|longer text";
let result = ansi_align_with_options(text, &opts);Fields§
§align: AlignmentThe alignment type (left, center, right)
split: StringThe string to split lines on (default: “\n”)
pad: charThe padding character to use (default: “ “)
Implementations§
Source§impl AlignOptions
impl AlignOptions
Sourcepub fn new(align: Alignment) -> Self
pub fn new(align: Alignment) -> Self
Creates new alignment options with the specified alignment direction.
Uses default values for split string ("\n") and padding character (' ').
§Arguments
align- The alignment direction to use
§Examples
use ansi_align::{AlignOptions, Alignment};
let opts = AlignOptions::new(Alignment::Center);Examples found in repository?
66fn main() -> Result<(), Box<dyn std::error::Error>> {
67 let cli = Cli::parse();
68
69 if cli.demo {
70 show_demo();
71 return Ok(());
72 }
73
74 let input_text = get_input_text(&cli)?;
75
76 if input_text.trim().is_empty() {
77 if !cli.quiet {
78 eprintln!("{}", "⚠️ No input text provided".yellow());
79 }
80 return Ok(());
81 }
82
83 let split_str = cli.split.replace("\\n", "\n").replace("\\t", "\t");
84
85 let alignment = cli.align.into();
86 let options = AlignOptions::new(alignment)
87 .with_split(split_str)
88 .with_pad(cli.pad);
89
90 let aligned_text = ansi_align_with_options(&input_text, &options);
91
92 if cli.border {
93 print_with_border(&aligned_text, &cli);
94 } else {
95 println!("{}", aligned_text);
96 }
97
98 Ok(())
99}
100
101fn get_input_text(cli: &Cli) -> Result<String, Box<dyn std::error::Error>> {
102 if let Some(file_path) = &cli.file {
103 // Read from file
104 Ok(fs::read_to_string(file_path)?)
105 } else if let Some(text) = &cli.text {
106 if text == "-" {
107 // Read from stdin
108 let mut buffer = String::new();
109 io::stdin().read_to_string(&mut buffer)?;
110 Ok(buffer)
111 } else {
112 // Process escape sequences in command line text
113 Ok(text.replace("\\n", "\n").replace("\\t", "\t"))
114 }
115 } else {
116 // Read from stdin if no text provided
117 let mut buffer = String::new();
118 io::stdin().read_to_string(&mut buffer)?;
119 Ok(buffer)
120 }
121}
122
123fn print_with_border(text: &str, cli: &Cli) {
124 let lines: Vec<&str> = text.split('\n').collect();
125 let max_width = lines
126 .iter()
127 .map(|line| string_width::string_width(line))
128 .max()
129 .unwrap_or(0);
130
131 let border_width = max_width + 2; // 1 space padding on each side
132
133 if !cli.quiet {
134 // Top border
135 println!(
136 "{}{}{}",
137 "┌".cyan().bold(),
138 "─".repeat(border_width).cyan(),
139 "┐".cyan().bold()
140 );
141 }
142
143 // Content with side borders - text is already aligned
144 for line in lines {
145 if !cli.quiet {
146 print!("{}", "│ ".cyan().bold());
147 }
148 print!("{}", line);
149 if !cli.quiet {
150 print!("{}", " │".cyan().bold());
151 }
152 println!();
153 }
154
155 if !cli.quiet {
156 // Bottom border
157 println!(
158 "{}{}{}",
159 "└".cyan().bold(),
160 "─".repeat(border_width).cyan(),
161 "┘".cyan().bold()
162 );
163 }
164}
165
166fn show_demo() {
167 println!(
168 "{}",
169 "🎨 ansi-align Demo - Beautiful Text Alignment"
170 .bold()
171 .magenta()
172 );
173 println!();
174
175 // Demo 1: Basic alignment
176 println!("{}", "📝 Basic Alignment:".bold().blue());
177 let basic_text = "Hello\nWorld\nRust";
178
179 println!("\n{}", "Left:".green());
180 println!(
181 "{}",
182 ansi_align_with_options(basic_text, &AlignOptions::new(Alignment::Left))
183 );
184
185 println!("\n{}", "Center:".green());
186 println!(
187 "{}",
188 ansi_align_with_options(basic_text, &AlignOptions::new(Alignment::Center))
189 );
190
191 println!("\n{}", "Right:".green());
192 println!(
193 "{}",
194 ansi_align_with_options(basic_text, &AlignOptions::new(Alignment::Right))
195 );
196
197 println!("\n{}", "─".repeat(50).dimmed());
198
199 // Demo 2: ANSI colors
200 println!("\n{}", "🌈 ANSI Color Support:".bold().blue());
201 let colored_text = format!(
202 "{}\n{}\n{}",
203 "Red Text".red().bold(),
204 "Green Text".green().italic(),
205 "Blue Text".blue().underline()
206 );
207
208 println!("\n{}", "Center aligned with colors:".green());
209 println!(
210 "{}",
211 ansi_align_with_options(&colored_text, &AlignOptions::new(Alignment::Center))
212 );
213
214 println!("\n{}", "─".repeat(50).dimmed());
215
216 // Demo 3: Unicode support
217 println!("\n{}", "🌏 Unicode Support:".bold().blue());
218 let unicode_text = "古\n古古古\nHello 世界";
219
220 println!("\n{}", "Right aligned Unicode:".green());
221 println!(
222 "{}",
223 ansi_align_with_options(unicode_text, &AlignOptions::new(Alignment::Right))
224 );
225
226 println!("\n{}", "─".repeat(50).dimmed());
227
228 // Demo 4: Custom options
229 println!("\n{}", "⚙️ Custom Options:".bold().blue());
230 let custom_text = "Name|Age|Location";
231 let options = AlignOptions::new(Alignment::Center)
232 .with_split("|")
233 .with_pad('.');
234
235 println!("\n{}", "Custom separator '|' and padding '.':".green());
236 println!("{}", ansi_align_with_options(custom_text, &options));
237
238 println!("\n{}", "─".repeat(50).dimmed());
239
240 // Demo 5: Menu example
241 println!("\n{}", "📋 Menu Example:".bold().blue());
242 let menu = format!(
243 "{}\n{}\n{}\n{}",
244 "🏠 Home".cyan(),
245 "📋 About Us".yellow(),
246 "📞 Contact".green(),
247 "⚙️ Settings".magenta()
248 );
249
250 println!("\n{}", "Center aligned menu:".green());
251 println!(
252 "{}",
253 ansi_align_with_options(&menu, &AlignOptions::new(Alignment::Center))
254 );
255
256 println!(
257 "\n{}",
258 "✨ Try it yourself with different options!".bold().green()
259 );
260 println!("{}", "Examples:".dimmed());
261 println!(
262 "{}",
263 " cargo run --example cli_tool -- \"Hello\\nWorld\" --align center".dimmed()
264 );
265 println!(
266 "{}",
267 " echo \"Line 1\\nLonger Line 2\" | cargo run --example cli_tool -- - --border".dimmed()
268 );
269 println!(
270 "{}",
271 " cargo run --example cli_tool -- --file README.md --align right --pad '.'".dimmed()
272 );
273}More examples
3fn main() {
4 println!("=== Basic Alignment Examples ===\n");
5
6 // Simple text alignment
7 let text = "Hello\nWorld\nRust";
8
9 println!("Original text:");
10 println!("{}\n", text);
11
12 println!("Left aligned:");
13 println!("{}\n", left(text));
14
15 println!("Center aligned:");
16 println!("{}\n", center(text));
17
18 println!("Right aligned:");
19 println!("{}\n", right(text));
20
21 println!("=== ANSI Color Examples ===\n");
22
23 // Text with ANSI colors
24 let colored_text = "\x1b[31mRed\x1b[0m\n\x1b[32mGreen Text\x1b[0m\n\x1b[34mBlue\x1b[0m";
25
26 println!("Colored text (center aligned):");
27 println!("{}\n", center(colored_text));
28
29 println!("=== Unicode Examples ===\n");
30
31 // Unicode text with wide characters
32 let unicode_text = "古\n古古古\nHello 世界";
33
34 println!("Unicode text (right aligned):");
35 println!("{}\n", right(unicode_text));
36
37 println!("=== Custom Options Examples ===\n");
38
39 // Custom separator and padding
40 let pipe_separated = "Name|Age|Location";
41 let options = AlignOptions::new(Alignment::Center)
42 .with_split("|")
43 .with_pad('.');
44
45 println!("Custom separator and padding:");
46 println!("{}\n", ansi_align_with_options(pipe_separated, &options));
47
48 // Menu-like alignment
49 let menu = "🏠 Home\n📋 About Us\n📞 Contact\n⚙️ Settings";
50
51 println!("Menu (center aligned):");
52 println!("{}\n", center(menu));
53}Sourcepub fn with_split<S: Into<String>>(self, split: S) -> Self
pub fn with_split<S: Into<String>>(self, split: S) -> Self
Sets the string used to split lines using the builder pattern.
By default, lines are split on "\n", but you can specify any string
as a line separator.
§Arguments
split- The string to use as a line separator
§Examples
use ansi_align::{AlignOptions, Alignment};
let opts = AlignOptions::new(Alignment::Center)
.with_split("|")
.with_split("<->"); // Multi-character separators work tooExamples found in repository?
66fn main() -> Result<(), Box<dyn std::error::Error>> {
67 let cli = Cli::parse();
68
69 if cli.demo {
70 show_demo();
71 return Ok(());
72 }
73
74 let input_text = get_input_text(&cli)?;
75
76 if input_text.trim().is_empty() {
77 if !cli.quiet {
78 eprintln!("{}", "⚠️ No input text provided".yellow());
79 }
80 return Ok(());
81 }
82
83 let split_str = cli.split.replace("\\n", "\n").replace("\\t", "\t");
84
85 let alignment = cli.align.into();
86 let options = AlignOptions::new(alignment)
87 .with_split(split_str)
88 .with_pad(cli.pad);
89
90 let aligned_text = ansi_align_with_options(&input_text, &options);
91
92 if cli.border {
93 print_with_border(&aligned_text, &cli);
94 } else {
95 println!("{}", aligned_text);
96 }
97
98 Ok(())
99}
100
101fn get_input_text(cli: &Cli) -> Result<String, Box<dyn std::error::Error>> {
102 if let Some(file_path) = &cli.file {
103 // Read from file
104 Ok(fs::read_to_string(file_path)?)
105 } else if let Some(text) = &cli.text {
106 if text == "-" {
107 // Read from stdin
108 let mut buffer = String::new();
109 io::stdin().read_to_string(&mut buffer)?;
110 Ok(buffer)
111 } else {
112 // Process escape sequences in command line text
113 Ok(text.replace("\\n", "\n").replace("\\t", "\t"))
114 }
115 } else {
116 // Read from stdin if no text provided
117 let mut buffer = String::new();
118 io::stdin().read_to_string(&mut buffer)?;
119 Ok(buffer)
120 }
121}
122
123fn print_with_border(text: &str, cli: &Cli) {
124 let lines: Vec<&str> = text.split('\n').collect();
125 let max_width = lines
126 .iter()
127 .map(|line| string_width::string_width(line))
128 .max()
129 .unwrap_or(0);
130
131 let border_width = max_width + 2; // 1 space padding on each side
132
133 if !cli.quiet {
134 // Top border
135 println!(
136 "{}{}{}",
137 "┌".cyan().bold(),
138 "─".repeat(border_width).cyan(),
139 "┐".cyan().bold()
140 );
141 }
142
143 // Content with side borders - text is already aligned
144 for line in lines {
145 if !cli.quiet {
146 print!("{}", "│ ".cyan().bold());
147 }
148 print!("{}", line);
149 if !cli.quiet {
150 print!("{}", " │".cyan().bold());
151 }
152 println!();
153 }
154
155 if !cli.quiet {
156 // Bottom border
157 println!(
158 "{}{}{}",
159 "└".cyan().bold(),
160 "─".repeat(border_width).cyan(),
161 "┘".cyan().bold()
162 );
163 }
164}
165
166fn show_demo() {
167 println!(
168 "{}",
169 "🎨 ansi-align Demo - Beautiful Text Alignment"
170 .bold()
171 .magenta()
172 );
173 println!();
174
175 // Demo 1: Basic alignment
176 println!("{}", "📝 Basic Alignment:".bold().blue());
177 let basic_text = "Hello\nWorld\nRust";
178
179 println!("\n{}", "Left:".green());
180 println!(
181 "{}",
182 ansi_align_with_options(basic_text, &AlignOptions::new(Alignment::Left))
183 );
184
185 println!("\n{}", "Center:".green());
186 println!(
187 "{}",
188 ansi_align_with_options(basic_text, &AlignOptions::new(Alignment::Center))
189 );
190
191 println!("\n{}", "Right:".green());
192 println!(
193 "{}",
194 ansi_align_with_options(basic_text, &AlignOptions::new(Alignment::Right))
195 );
196
197 println!("\n{}", "─".repeat(50).dimmed());
198
199 // Demo 2: ANSI colors
200 println!("\n{}", "🌈 ANSI Color Support:".bold().blue());
201 let colored_text = format!(
202 "{}\n{}\n{}",
203 "Red Text".red().bold(),
204 "Green Text".green().italic(),
205 "Blue Text".blue().underline()
206 );
207
208 println!("\n{}", "Center aligned with colors:".green());
209 println!(
210 "{}",
211 ansi_align_with_options(&colored_text, &AlignOptions::new(Alignment::Center))
212 );
213
214 println!("\n{}", "─".repeat(50).dimmed());
215
216 // Demo 3: Unicode support
217 println!("\n{}", "🌏 Unicode Support:".bold().blue());
218 let unicode_text = "古\n古古古\nHello 世界";
219
220 println!("\n{}", "Right aligned Unicode:".green());
221 println!(
222 "{}",
223 ansi_align_with_options(unicode_text, &AlignOptions::new(Alignment::Right))
224 );
225
226 println!("\n{}", "─".repeat(50).dimmed());
227
228 // Demo 4: Custom options
229 println!("\n{}", "⚙️ Custom Options:".bold().blue());
230 let custom_text = "Name|Age|Location";
231 let options = AlignOptions::new(Alignment::Center)
232 .with_split("|")
233 .with_pad('.');
234
235 println!("\n{}", "Custom separator '|' and padding '.':".green());
236 println!("{}", ansi_align_with_options(custom_text, &options));
237
238 println!("\n{}", "─".repeat(50).dimmed());
239
240 // Demo 5: Menu example
241 println!("\n{}", "📋 Menu Example:".bold().blue());
242 let menu = format!(
243 "{}\n{}\n{}\n{}",
244 "🏠 Home".cyan(),
245 "📋 About Us".yellow(),
246 "📞 Contact".green(),
247 "⚙️ Settings".magenta()
248 );
249
250 println!("\n{}", "Center aligned menu:".green());
251 println!(
252 "{}",
253 ansi_align_with_options(&menu, &AlignOptions::new(Alignment::Center))
254 );
255
256 println!(
257 "\n{}",
258 "✨ Try it yourself with different options!".bold().green()
259 );
260 println!("{}", "Examples:".dimmed());
261 println!(
262 "{}",
263 " cargo run --example cli_tool -- \"Hello\\nWorld\" --align center".dimmed()
264 );
265 println!(
266 "{}",
267 " echo \"Line 1\\nLonger Line 2\" | cargo run --example cli_tool -- - --border".dimmed()
268 );
269 println!(
270 "{}",
271 " cargo run --example cli_tool -- --file README.md --align right --pad '.'".dimmed()
272 );
273}More examples
3fn main() {
4 println!("=== Basic Alignment Examples ===\n");
5
6 // Simple text alignment
7 let text = "Hello\nWorld\nRust";
8
9 println!("Original text:");
10 println!("{}\n", text);
11
12 println!("Left aligned:");
13 println!("{}\n", left(text));
14
15 println!("Center aligned:");
16 println!("{}\n", center(text));
17
18 println!("Right aligned:");
19 println!("{}\n", right(text));
20
21 println!("=== ANSI Color Examples ===\n");
22
23 // Text with ANSI colors
24 let colored_text = "\x1b[31mRed\x1b[0m\n\x1b[32mGreen Text\x1b[0m\n\x1b[34mBlue\x1b[0m";
25
26 println!("Colored text (center aligned):");
27 println!("{}\n", center(colored_text));
28
29 println!("=== Unicode Examples ===\n");
30
31 // Unicode text with wide characters
32 let unicode_text = "古\n古古古\nHello 世界";
33
34 println!("Unicode text (right aligned):");
35 println!("{}\n", right(unicode_text));
36
37 println!("=== Custom Options Examples ===\n");
38
39 // Custom separator and padding
40 let pipe_separated = "Name|Age|Location";
41 let options = AlignOptions::new(Alignment::Center)
42 .with_split("|")
43 .with_pad('.');
44
45 println!("Custom separator and padding:");
46 println!("{}\n", ansi_align_with_options(pipe_separated, &options));
47
48 // Menu-like alignment
49 let menu = "🏠 Home\n📋 About Us\n📞 Contact\n⚙️ Settings";
50
51 println!("Menu (center aligned):");
52 println!("{}\n", center(menu));
53}Sourcepub const fn with_pad(self, pad: char) -> Self
pub const fn with_pad(self, pad: char) -> Self
Sets the character used for padding using the builder pattern.
By default, spaces (' ') are used for padding, but you can specify
any character.
§Arguments
pad- The character to use for padding
§Examples
use ansi_align::{AlignOptions, Alignment};
let opts = AlignOptions::new(Alignment::Right)
.with_pad('.');Examples found in repository?
66fn main() -> Result<(), Box<dyn std::error::Error>> {
67 let cli = Cli::parse();
68
69 if cli.demo {
70 show_demo();
71 return Ok(());
72 }
73
74 let input_text = get_input_text(&cli)?;
75
76 if input_text.trim().is_empty() {
77 if !cli.quiet {
78 eprintln!("{}", "⚠️ No input text provided".yellow());
79 }
80 return Ok(());
81 }
82
83 let split_str = cli.split.replace("\\n", "\n").replace("\\t", "\t");
84
85 let alignment = cli.align.into();
86 let options = AlignOptions::new(alignment)
87 .with_split(split_str)
88 .with_pad(cli.pad);
89
90 let aligned_text = ansi_align_with_options(&input_text, &options);
91
92 if cli.border {
93 print_with_border(&aligned_text, &cli);
94 } else {
95 println!("{}", aligned_text);
96 }
97
98 Ok(())
99}
100
101fn get_input_text(cli: &Cli) -> Result<String, Box<dyn std::error::Error>> {
102 if let Some(file_path) = &cli.file {
103 // Read from file
104 Ok(fs::read_to_string(file_path)?)
105 } else if let Some(text) = &cli.text {
106 if text == "-" {
107 // Read from stdin
108 let mut buffer = String::new();
109 io::stdin().read_to_string(&mut buffer)?;
110 Ok(buffer)
111 } else {
112 // Process escape sequences in command line text
113 Ok(text.replace("\\n", "\n").replace("\\t", "\t"))
114 }
115 } else {
116 // Read from stdin if no text provided
117 let mut buffer = String::new();
118 io::stdin().read_to_string(&mut buffer)?;
119 Ok(buffer)
120 }
121}
122
123fn print_with_border(text: &str, cli: &Cli) {
124 let lines: Vec<&str> = text.split('\n').collect();
125 let max_width = lines
126 .iter()
127 .map(|line| string_width::string_width(line))
128 .max()
129 .unwrap_or(0);
130
131 let border_width = max_width + 2; // 1 space padding on each side
132
133 if !cli.quiet {
134 // Top border
135 println!(
136 "{}{}{}",
137 "┌".cyan().bold(),
138 "─".repeat(border_width).cyan(),
139 "┐".cyan().bold()
140 );
141 }
142
143 // Content with side borders - text is already aligned
144 for line in lines {
145 if !cli.quiet {
146 print!("{}", "│ ".cyan().bold());
147 }
148 print!("{}", line);
149 if !cli.quiet {
150 print!("{}", " │".cyan().bold());
151 }
152 println!();
153 }
154
155 if !cli.quiet {
156 // Bottom border
157 println!(
158 "{}{}{}",
159 "└".cyan().bold(),
160 "─".repeat(border_width).cyan(),
161 "┘".cyan().bold()
162 );
163 }
164}
165
166fn show_demo() {
167 println!(
168 "{}",
169 "🎨 ansi-align Demo - Beautiful Text Alignment"
170 .bold()
171 .magenta()
172 );
173 println!();
174
175 // Demo 1: Basic alignment
176 println!("{}", "📝 Basic Alignment:".bold().blue());
177 let basic_text = "Hello\nWorld\nRust";
178
179 println!("\n{}", "Left:".green());
180 println!(
181 "{}",
182 ansi_align_with_options(basic_text, &AlignOptions::new(Alignment::Left))
183 );
184
185 println!("\n{}", "Center:".green());
186 println!(
187 "{}",
188 ansi_align_with_options(basic_text, &AlignOptions::new(Alignment::Center))
189 );
190
191 println!("\n{}", "Right:".green());
192 println!(
193 "{}",
194 ansi_align_with_options(basic_text, &AlignOptions::new(Alignment::Right))
195 );
196
197 println!("\n{}", "─".repeat(50).dimmed());
198
199 // Demo 2: ANSI colors
200 println!("\n{}", "🌈 ANSI Color Support:".bold().blue());
201 let colored_text = format!(
202 "{}\n{}\n{}",
203 "Red Text".red().bold(),
204 "Green Text".green().italic(),
205 "Blue Text".blue().underline()
206 );
207
208 println!("\n{}", "Center aligned with colors:".green());
209 println!(
210 "{}",
211 ansi_align_with_options(&colored_text, &AlignOptions::new(Alignment::Center))
212 );
213
214 println!("\n{}", "─".repeat(50).dimmed());
215
216 // Demo 3: Unicode support
217 println!("\n{}", "🌏 Unicode Support:".bold().blue());
218 let unicode_text = "古\n古古古\nHello 世界";
219
220 println!("\n{}", "Right aligned Unicode:".green());
221 println!(
222 "{}",
223 ansi_align_with_options(unicode_text, &AlignOptions::new(Alignment::Right))
224 );
225
226 println!("\n{}", "─".repeat(50).dimmed());
227
228 // Demo 4: Custom options
229 println!("\n{}", "⚙️ Custom Options:".bold().blue());
230 let custom_text = "Name|Age|Location";
231 let options = AlignOptions::new(Alignment::Center)
232 .with_split("|")
233 .with_pad('.');
234
235 println!("\n{}", "Custom separator '|' and padding '.':".green());
236 println!("{}", ansi_align_with_options(custom_text, &options));
237
238 println!("\n{}", "─".repeat(50).dimmed());
239
240 // Demo 5: Menu example
241 println!("\n{}", "📋 Menu Example:".bold().blue());
242 let menu = format!(
243 "{}\n{}\n{}\n{}",
244 "🏠 Home".cyan(),
245 "📋 About Us".yellow(),
246 "📞 Contact".green(),
247 "⚙️ Settings".magenta()
248 );
249
250 println!("\n{}", "Center aligned menu:".green());
251 println!(
252 "{}",
253 ansi_align_with_options(&menu, &AlignOptions::new(Alignment::Center))
254 );
255
256 println!(
257 "\n{}",
258 "✨ Try it yourself with different options!".bold().green()
259 );
260 println!("{}", "Examples:".dimmed());
261 println!(
262 "{}",
263 " cargo run --example cli_tool -- \"Hello\\nWorld\" --align center".dimmed()
264 );
265 println!(
266 "{}",
267 " echo \"Line 1\\nLonger Line 2\" | cargo run --example cli_tool -- - --border".dimmed()
268 );
269 println!(
270 "{}",
271 " cargo run --example cli_tool -- --file README.md --align right --pad '.'".dimmed()
272 );
273}More examples
3fn main() {
4 println!("=== Basic Alignment Examples ===\n");
5
6 // Simple text alignment
7 let text = "Hello\nWorld\nRust";
8
9 println!("Original text:");
10 println!("{}\n", text);
11
12 println!("Left aligned:");
13 println!("{}\n", left(text));
14
15 println!("Center aligned:");
16 println!("{}\n", center(text));
17
18 println!("Right aligned:");
19 println!("{}\n", right(text));
20
21 println!("=== ANSI Color Examples ===\n");
22
23 // Text with ANSI colors
24 let colored_text = "\x1b[31mRed\x1b[0m\n\x1b[32mGreen Text\x1b[0m\n\x1b[34mBlue\x1b[0m";
25
26 println!("Colored text (center aligned):");
27 println!("{}\n", center(colored_text));
28
29 println!("=== Unicode Examples ===\n");
30
31 // Unicode text with wide characters
32 let unicode_text = "古\n古古古\nHello 世界";
33
34 println!("Unicode text (right aligned):");
35 println!("{}\n", right(unicode_text));
36
37 println!("=== Custom Options Examples ===\n");
38
39 // Custom separator and padding
40 let pipe_separated = "Name|Age|Location";
41 let options = AlignOptions::new(Alignment::Center)
42 .with_split("|")
43 .with_pad('.');
44
45 println!("Custom separator and padding:");
46 println!("{}\n", ansi_align_with_options(pipe_separated, &options));
47
48 // Menu-like alignment
49 let menu = "🏠 Home\n📋 About Us\n📞 Contact\n⚙️ Settings";
50
51 println!("Menu (center aligned):");
52 println!("{}\n", center(menu));
53}Trait Implementations§
Source§impl Clone for AlignOptions
impl Clone for AlignOptions
Source§fn clone(&self) -> AlignOptions
fn clone(&self) -> AlignOptions
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more