csh/lib.rs
1//! color-ssh (csh) - A Rust-based SSH client wrapper with syntax highlighting
2//!
3//! This library provides the core functionality for the color-ssh tool, which wraps
4//! SSH connections with syntax highlighting and enhanced logging capabilities.
5//!
6//! # Features
7//!
8//! - **Syntax Highlighting**: Apply ANSI color codes to SSH output based on regex patterns
9//! - **Configuration Management**: YAML-based configuration with hot-reloading
10//! - **Logging**: Comprehensive debug and session logging
11//! - **Process Management**: Robust SSH subprocess handling with proper error propagation
12//!
13//! # Modules
14//!
15//! - [`args`] - Command-line argument parsing
16//! - [`config`] - Configuration loading, watching, and management
17//! - [`highlighter`] - Syntax highlighting engine with regex pattern matching
18//! - [`log`] - Structured logging with multiple levels and targets
19//! - [`process`] - SSH subprocess spawning and I/O handling
20//!
21//! # Examples
22//!
23//! Basic usage as a library:
24//!
25//! ```no_run
26//! use csh::{args, config, process};
27//!
28//! fn main() -> csh::Result<std::process::ExitCode> {
29//! // Parse arguments
30//! let args = args::main_args();
31//!
32//! // Initialize config watcher
33//! let _watcher = config::config_watcher(None);
34//!
35//! // Run SSH process
36//! process::process_handler(args.ssh_args, args.is_non_interactive)
37//! }
38//! ```
39
40// Imports CSH specific modules
41pub mod args;
42pub mod config;
43pub mod highlighter;
44pub mod log;
45pub mod process;
46
47use std::io;
48
49/// Result type alias for color-ssh operations
50pub type Result<T> = std::result::Result<T, Error>;
51
52/// Top-level error type encompassing all module-specific errors
53#[derive(Debug)]
54pub enum Error {
55 /// I/O operation error
56 Io(io::Error),
57 /// Configuration loading or parsing error
58 Config(config::ConfigError),
59 /// Syntax highlighting error
60 Highlight(highlighter::HighlightError),
61 /// Logging operation error
62 Log(log::LogError),
63}
64
65impl std::fmt::Display for Error {
66 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
67 match self {
68 Error::Io(err) => write!(f, "IO error: {}", err),
69 Error::Config(err) => write!(f, "Configuration error: {}", err),
70 Error::Highlight(err) => write!(f, "Highlighting error: {}", err),
71 Error::Log(err) => write!(f, "Logging error: {}", err),
72 }
73 }
74}
75
76impl std::error::Error for Error {}
77
78// Implement From for each error type to enable easy error conversion
79
80impl From<io::Error> for Error {
81 fn from(err: io::Error) -> Self {
82 Error::Io(err)
83 }
84}
85
86impl From<config::ConfigError> for Error {
87 fn from(err: config::ConfigError) -> Self {
88 Error::Config(err)
89 }
90}
91
92impl From<highlighter::HighlightError> for Error {
93 fn from(err: highlighter::HighlightError) -> Self {
94 Error::Highlight(err)
95 }
96}
97
98impl From<log::LogError> for Error {
99 fn from(err: log::LogError) -> Self {
100 Error::Log(err)
101 }
102}