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
//! Definition of shell behavior traits and defaults.
use crate::{Shell, error, extensions};
/// Trait for static shell extensions. Collects all associated types needed to
/// instantiate a shell into a single containing struct.
pub trait ShellExtensions: Clone + Default + Send + Sync + 'static {
/// Type of the error behavior implementation.
type ErrorFormatter: ErrorFormatter;
}
/// Shell extensions implementation constructed from component types.
#[derive(Clone, Default)]
pub struct ShellExtensionsImpl<EF: ErrorFormatter = DefaultErrorFormatter> {
_marker: std::marker::PhantomData<EF>,
}
impl<EF: ErrorFormatter> ShellExtensions for ShellExtensionsImpl<EF> {
type ErrorFormatter = EF;
}
/// Default shell extensions implementation.
/// This is a type alias for the most common shell configuration.
pub type DefaultShellExtensions = ShellExtensionsImpl<DefaultErrorFormatter>;
/// Trait for defining shell error behaviors.
pub trait ErrorFormatter: Clone + Default + Send + Sync + 'static {
/// Format the given error for display within the context of the provided shell.
///
/// # Arguments
///
/// * `error` - The error to format
/// * `shell` - The shell context in which the error occurred.
fn format_error(
&self,
error: &error::Error,
shell: &Shell<impl extensions::ShellExtensions>,
) -> String {
let _ = shell;
std::format!("error: {error:#}\n")
}
}
/// Default shell error behavior implementation.
#[derive(Clone, Default)]
pub struct DefaultErrorFormatter;
impl ErrorFormatter for DefaultErrorFormatter {}
/// Trait for placeholder behavior (stub for future extension).
pub trait PlaceholderBehavior: Clone + Default + Send + Sync + 'static {}
/// Default placeholder implementation.
#[derive(Clone, Default)]
pub struct DefaultPlaceholder;
impl PlaceholderBehavior for DefaultPlaceholder {}