Skip to main content

opendev_tui/app/
enums.rs

1//! Operation mode and autonomy level enums.
2
3/// Operation mode — mirrors `OperationMode` from the Python side.
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum OperationMode {
6    Normal,
7    Plan,
8}
9
10impl std::fmt::Display for OperationMode {
11    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
12        match self {
13            Self::Normal => write!(f, "Normal"),
14            Self::Plan => write!(f, "Plan"),
15        }
16    }
17}
18
19impl OperationMode {
20    /// Parse from string (case-insensitive).
21    pub fn from_str_loose(s: &str) -> Option<Self> {
22        match s.to_lowercase().as_str() {
23            "normal" => Some(Self::Normal),
24            "plan" => Some(Self::Plan),
25            _ => None,
26        }
27    }
28}
29
30/// Autonomy level — mirrors Python `StatusBar.autonomy`.
31#[derive(Debug, Clone, Copy, PartialEq, Eq)]
32pub enum AutonomyLevel {
33    Manual,
34    SemiAuto,
35    Auto,
36}
37
38impl std::fmt::Display for AutonomyLevel {
39    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
40        match self {
41            Self::Manual => write!(f, "Manual"),
42            Self::SemiAuto => write!(f, "Semi-Auto"),
43            Self::Auto => write!(f, "Auto"),
44        }
45    }
46}
47
48impl AutonomyLevel {
49    /// Parse from string (case-insensitive).
50    pub fn from_str_loose(s: &str) -> Option<Self> {
51        match s.to_lowercase().as_str() {
52            "manual" => Some(Self::Manual),
53            "semi-auto" | "semiauto" | "semi" => Some(Self::SemiAuto),
54            "auto" | "full" => Some(Self::Auto),
55            _ => None,
56        }
57    }
58}
59
60/// Reasoning effort level for native provider thinking.
61#[derive(Debug, Clone, Copy, PartialEq, Eq)]
62pub enum ReasoningLevel {
63    Off,
64    Low,
65    Medium,
66    High,
67}
68
69impl std::fmt::Display for ReasoningLevel {
70    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
71        match self {
72            Self::Off => write!(f, "Off"),
73            Self::Low => write!(f, "Low"),
74            Self::Medium => write!(f, "Medium"),
75            Self::High => write!(f, "High"),
76        }
77    }
78}
79
80impl ReasoningLevel {
81    /// Parse from config string (case-insensitive).
82    pub fn from_str_loose(s: &str) -> Self {
83        match s.to_lowercase().as_str() {
84            "off" | "none" => Self::Off,
85            "low" => Self::Low,
86            "high" => Self::High,
87            _ => Self::Medium,
88        }
89    }
90
91    /// Convert to the config string used by LlmCallConfig.
92    pub fn to_config_string(&self) -> Option<String> {
93        match self {
94            Self::Off => None,
95            Self::Low => Some("low".to_string()),
96            Self::Medium => Some("medium".to_string()),
97            Self::High => Some("high".to_string()),
98        }
99    }
100
101    /// Cycle to the next level: Off → Low → Medium → High → Off.
102    pub fn next(self) -> Self {
103        match self {
104            Self::Off => Self::Low,
105            Self::Low => Self::Medium,
106            Self::Medium => Self::High,
107            Self::High => Self::Off,
108        }
109    }
110}
111
112#[cfg(test)]
113#[path = "enums_tests.rs"]
114mod tests;