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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
//! User interface utilities and display helpers for SubX CLI.
//!
//! This module provides a comprehensive set of utilities for creating
//! consistent and user-friendly command-line interfaces. It handles
//! status messages, progress indicators, result displays, and AI usage
//! statistics with consistent styling and formatting.
//!
//! # Features
//!
//! - **Status Messages**: Success, error, and warning message formatting
//! - **Progress Indicators**: Configurable progress bars for long operations
//! - **Result Display**: Formatted tables and structured output
//! - **AI Statistics**: Usage tracking and cost information display
//! - **Consistent Styling**: Color-coded messages with Unicode symbols
//!
//! # Design Principles
//!
//! - **Accessibility**: Clear visual hierarchy with color and symbols
//! - **Configurability**: Respects user preferences for progress display
//! - **Consistency**: Unified styling across all CLI operations
//! - **Informativeness**: Rich context and actionable information
//!
//! # Examples
//!
//! ```rust
//! use subx_cli::cli::ui;
//!
//! // Display status messages
//! ui::print_success("Subtitle files processed successfully");
//! ui::print_warning("File format might be incompatible");
//! ui::print_error("Unable to read configuration file");
//!
//! // Create progress bar for batch operations
//! let progress = ui::create_progress_bar(100);
//! for i in 0..100 {
//! progress.inc(1);
//! // ... processing ...
//! }
//! progress.finish_with_message("Processing completed");
//! ```
// src/cli/ui.rs
use crate;
use crate;
use crateMatchOperation;
use *;
use ;
/// Display a success message with consistent formatting.
///
/// Prints a success message with a green checkmark symbol and styled text.
/// Used throughout the application to indicate successful completion of
/// operations such as file processing, configuration updates, or command execution.
///
/// # Format
/// ```text
/// ✓ [message]
/// ```
///
/// # Examples
///
/// ```rust
/// use subx_cli::cli::ui::print_success;
///
/// print_success("Successfully processed 15 subtitle files");
/// print_success("Configuration saved to ~/.config/subx/config.toml");
/// print_success("AI matching completed with 98% confidence");
/// ```
///
/// # Output Examples
/// ```text
/// ✓ Successfully processed 15 subtitle files
/// ✓ Configuration saved to ~/.config/subx/config.toml
/// ✓ AI matching completed with 98% confidence
/// ```
/// Display an error message with consistent formatting.
///
/// Prints an error message to stderr with a red X symbol and styled text.
/// Used for reporting errors, failures, and critical issues that prevent
/// operation completion. Messages are sent to stderr to separate them
/// from normal program output.
///
/// # Format
/// ```text
/// ✗ [message]
/// ```
///
/// # Examples
///
/// ```rust
/// use subx_cli::cli::ui::print_error;
///
/// print_error("Failed to load configuration file");
/// print_error("AI API request timed out after 30 seconds");
/// print_error("Invalid subtitle format detected");
/// ```
///
/// # Output Examples
/// ```text
/// ✗ Failed to load configuration file
/// ✗ AI API request timed out after 30 seconds
/// ✗ Invalid subtitle format detected
/// ```
/// Display a warning message with consistent formatting.
///
/// Prints a warning message with a yellow warning symbol and styled text.
/// Used for non-critical issues, deprecation notices, or situations that
/// may require user attention but don't prevent operation completion.
///
/// # Format
/// ```text
/// ⚠ [message]
/// ```
///
/// # Examples
///
/// ```rust
/// use subx_cli::cli::ui::print_warning;
///
/// print_warning("Legacy subtitle format detected, consider upgrading");
/// print_warning("AI confidence below 80%, manual review recommended");
/// print_warning("Configuration file not found, using defaults");
/// ```
///
/// # Output Examples
/// ```text
/// ⚠ Legacy subtitle format detected, consider upgrading
/// ⚠ AI confidence below 80%, manual review recommended
/// ⚠ Configuration file not found, using defaults
/// ```
/// Create a progress bar with consistent styling and configuration.
///
/// Creates a progress bar with customized styling that respects user
/// configuration preferences. The progress bar can be hidden based on
/// the `enable_progress_bar` configuration setting, allowing users to
/// disable progress indicators if desired.
///
/// # Configuration Integration
///
/// The progress bar visibility is controlled by the configuration setting:
/// ```toml
/// [general]
/// enable_progress_bar = true # Show progress bars
/// # or
/// enable_progress_bar = false # Hide progress bars
/// ```
///
/// # Progress Bar Features
///
/// - **Animated spinner**: Indicates ongoing activity
/// - **Elapsed time**: Shows time since operation started
/// - **Progress bar**: Visual representation of completion percentage
/// - **ETA estimation**: Estimated time to completion
/// - **Current/total counts**: Numeric progress indicator
///
/// # Template Format
/// ```text
/// ⠋ [00:01:23] [████████████████████████████████████████] 75/100 (00:00:17)
/// ```
///
/// # Arguments
///
/// * `total` - The total number of items to be processed
///
/// # Returns
///
/// A configured `ProgressBar` instance ready for use
///
/// # Examples
///
/// ```rust
/// use subx_cli::cli::ui::create_progress_bar;
///
/// // Create progress bar for 100 items
/// let progress = create_progress_bar(100);
///
/// for i in 0..100 {
/// // ... process item ...
/// progress.inc(1);
///
/// if i % 10 == 0 {
/// progress.set_message(format!("Processing item {}", i));
/// }
/// }
///
/// progress.finish_with_message("✓ All items processed successfully");
/// ```
///
/// # Error Handling
///
/// If configuration loading fails, the progress bar will default to visible.
/// This ensures that progress indication is available even when configuration
/// is problematic.
/// Resolve the progress-bar draw target for the active output mode.
///
/// Per the `progress-reporting` spec, every `indicatif::ProgressBar`
/// constructed by SubX SHALL obtain its `ProgressDrawTarget` from this
/// helper so JSON mode force-hides progress frames regardless of
/// `general.enable_progress_bar`.
/// Display comprehensive AI API usage statistics and cost information.
///
/// Presents detailed information about AI API calls including token usage,
/// model information, and cost implications. This helps users understand
/// their AI service consumption and manage usage costs effectively.
///
/// # Information Displayed
///
/// - **Model Name**: The specific AI model used for processing
/// - **Token Breakdown**: Detailed token usage by category
/// - Prompt tokens: Input text sent to the AI
/// - Completion tokens: AI-generated response text
/// - Total tokens: Sum of prompt and completion tokens
/// - **Cost Implications**: Helps users understand billing impact
///
/// # Format Example
/// ```text
/// 🤖 AI API Call Details:
/// Model: gpt-4-turbo-preview
/// Prompt tokens: 1,247
/// Completion tokens: 892
/// Total tokens: 2,139
/// ```
///
/// # Arguments
///
/// * `usage` - AI usage statistics containing token counts and model information
///
/// # Examples
///
/// ```rust
/// use subx_cli::cli::ui::display_ai_usage;
/// use subx_cli::services::ai::AiUsageStats;
///
/// let usage = AiUsageStats {
/// model: "gpt-4-turbo-preview".to_string(),
/// prompt_tokens: 1247,
/// completion_tokens: 892,
/// total_tokens: 2139,
/// };
///
/// display_ai_usage(&usage);
/// ```
///
/// # Use Cases
///
/// - **Cost monitoring**: Track API usage for billing awareness
/// - **Performance analysis**: Understand token efficiency
/// - **Debugging**: Verify expected model usage
/// - **Optimization**: Identify opportunities to reduce token consumption
/// Display file matching results with support for dry-run preview mode.