vtcode_core/utils/
mod.rs

1//! # Utility Functions and Helpers
2//!
3//! This module provides various utility functions and helpers used throughout VTCode,
4//! including configuration management, safety utilities, and common operations.
5//!
6//! ## Modules Overview
7//!
8//! ### Configuration Management (`dot_config`)
9//! - **User Preferences**: Theme settings, UI preferences, cache configuration
10//! - **Provider Configuration**: LLM provider settings and API keys
11//! - **Dotfile Management**: `.vtcode` directory and configuration files
12//!
13//! ### Safety Utilities (`safety`)
14//! - **Path Validation**: Workspace boundary checking
15//! - **Command Sanitization**: Safe command execution
16//! - **Input Validation**: User input sanitization
17//!
18//! ### ANSI and Colors (`ansi`, `colors`)
19//! - **Terminal Colors**: ANSI color codes and styling
20//! - **Color Management**: Theme support and color schemes
21//! - **Cross-platform**: Works on different terminal types
22//!
23//! ### Git Integration (`vtcodegitignore`)
24//! - **Gitignore Management**: Automatic `.vtcodegitignore` creation
25//! - **Pattern Matching**: File exclusion patterns
26//! - **Workspace Safety**: Prevents accidental file operations
27//!
28//! ## Basic Usage Examples
29//!
30//! ### Configuration Management
31//! ```rust,no_run
32//! use vtcode_core::utils::dot_config::{load_user_config, save_user_config, UserPreferences};
33//!
34//! #[tokio::main]
35//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
36//!     // Load user configuration
37//!     let config = load_user_config().await?;
38//!
39//!     // Modify preferences
40//!     let mut prefs = config.preferences;
41//!     prefs.theme = "dark".to_string();
42//!
43//!     // Save changes
44//!     save_user_config(&prefs).await?;
45//!
46//!     Ok(())
47//! }
48//! ```
49//!
50//! ### Path Safety
51//! ```rust,no_run
52//! use vtcode_core::utils::safety::validate_workspace_path;
53//! use std::path::PathBuf;
54//!
55//! let workspace = PathBuf::from("/home/user/project");
56//! let file_path = PathBuf::from("src/main.rs");
57//!
58//! // Validate path is within workspace
59//! match validate_workspace_path(&workspace, &file_path) {
60//!     Ok(valid_path) => println!("Safe path: {}", valid_path.display()),
61//!     Err(e) => eprintln!("Unsafe path: {}", e),
62//! }
63//! ```
64//!
65//! ### ANSI Colors
66//! ```rust,no_run
67//! use vtcode_core::utils::ansi::{colorize, Color};
68//!
69//! let message = "Hello, World!";
70//! let colored = colorize(message, Color::Green);
71//! println!("{}", colored); // Prints green text
72//!
73//! // Or use styling functions
74//! let bold_text = vtcode_core::utils::ansi::bold("Important message");
75//! let red_error = colorize("Error occurred", Color::Red);
76//! ```
77//!
78//! ### Git Integration
79//! ```rust,no_run
80//! use vtcode_core::utils::vtcodegitignore::initialize_vtcode_gitignore;
81//!
82//! #[tokio::main]
83//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
84//!     let workspace = std::env::current_dir()?;
85//!
86//!     // Initialize .vtcodegitignore
87//!     initialize_vtcode_gitignore(&workspace).await?;
88//!
89//!     println!("Git integration initialized");
90//!     Ok(())
91//! }
92//! ```
93
94pub mod ansi;
95pub mod colors;
96pub mod dot_config;
97pub mod safety;
98pub mod transcript;
99pub mod utils;
100pub mod vtcodegitignore;