Skip to main content

claude_code_status_line/
types.rs

1use crate::colors::SectionColors;
2use crate::utils::visible_len;
3use serde::Deserialize;
4
5#[derive(Clone, PartialEq, Debug)]
6pub enum SectionKind {
7    Generic,
8    QuotaCompact(String),
9    QuotaDetailed(String),
10    ContextCompact,
11    ContextDetailed,
12}
13
14#[derive(Clone)]
15pub struct Section {
16    pub kind: SectionKind,
17    pub content: String,
18    pub priority: u16,         // Lower number = higher priority (0 = always show)
19    pub colors: SectionColors, // Per-section colors
20    pub width: usize,          // Cached visible width (excluding padding/separators)
21}
22
23impl Section {
24    pub fn with_kind(
25        kind: SectionKind,
26        content: String,
27        priority: u16,
28        colors: SectionColors,
29    ) -> Self {
30        let width = visible_len(&content);
31        Section {
32            kind,
33            content,
34            priority,
35            colors,
36            width,
37        }
38    }
39
40    pub fn new(content: String, priority: u16, colors: SectionColors) -> Self {
41        Self::with_kind(SectionKind::Generic, content, priority, colors)
42    }
43
44    pub fn new_quota_compact(
45        label: &str,
46        content: String,
47        priority: u16,
48        colors: SectionColors,
49    ) -> Self {
50        Self::with_kind(
51            SectionKind::QuotaCompact(label.to_string()),
52            content,
53            priority,
54            colors,
55        )
56    }
57
58    pub fn new_quota_detailed(
59        label: &str,
60        content: String,
61        priority: u16,
62        colors: SectionColors,
63    ) -> Self {
64        Self::with_kind(
65            SectionKind::QuotaDetailed(label.to_string()),
66            content,
67            priority,
68            colors,
69        )
70    }
71
72    pub fn new_context_compact(content: String, priority: u16, colors: SectionColors) -> Self {
73        Self::with_kind(SectionKind::ContextCompact, content, priority, colors)
74    }
75
76    pub fn new_context_detailed(content: String, priority: u16, colors: SectionColors) -> Self {
77        Self::with_kind(SectionKind::ContextDetailed, content, priority, colors)
78    }
79}
80
81#[derive(Clone, Copy, Debug, PartialEq, Eq)]
82pub enum ContextAccuracy {
83    Exact,
84    Estimated,
85}
86
87/// Context usage information (used for display formatting)
88pub struct ContextUsageInfo {
89    pub percentage: f64,
90    pub current_usage_tokens: u64,
91    pub context_window_size: Option<u64>,
92    pub accuracy: ContextAccuracy,
93}
94
95#[derive(Debug, Deserialize, Clone)]
96pub struct ClaudeInput {
97    pub cwd: Option<String>,
98    pub workspace: Option<Workspace>,
99    pub model: Option<Model>,
100    pub context_window: Option<ContextWindow>,
101    pub cost: Option<Cost>,
102    pub output_style: Option<OutputStyle>,
103    pub worktree: Option<Worktree>,
104    pub rate_limits: Option<RateLimits>,
105    pub effort: Option<Effort>,
106    pub thinking: Option<Thinking>,
107    pub version: Option<String>,
108}
109
110#[derive(Debug, Deserialize, Clone)]
111pub struct RateLimits {
112    pub five_hour: Option<RateLimit>,
113    pub seven_day: Option<RateLimit>,
114}
115
116#[derive(Debug, Deserialize, Clone)]
117pub struct RateLimit {
118    pub used_percentage: Option<f64>,
119    pub resets_at: Option<u64>,
120}
121
122#[derive(Debug, Deserialize, Clone)]
123pub struct Effort {
124    pub level: Option<String>,
125}
126
127#[derive(Debug, Deserialize, Clone)]
128pub struct Thinking {
129    pub enabled: Option<bool>,
130}
131
132#[derive(Debug, Deserialize, Clone)]
133pub struct Workspace {
134    pub current_dir: Option<String>,
135    pub project_dir: Option<String>,
136    pub added_dirs: Option<Vec<String>>,
137}
138
139#[derive(Debug, Deserialize, Clone)]
140pub struct Model {
141    pub id: Option<String>,
142    pub display_name: Option<String>,
143}
144
145#[derive(Debug, Deserialize, Clone)]
146pub struct OutputStyle {
147    pub name: Option<String>,
148}
149
150#[derive(Debug, Deserialize, Clone)]
151pub struct ContextWindow {
152    pub context_window_size: Option<u64>,
153    pub total_input_tokens: Option<u64>,
154    pub total_output_tokens: Option<u64>,
155    pub current_usage: Option<CurrentUsage>,
156    pub used_percentage: Option<f64>,
157    pub remaining_percentage: Option<f64>,
158}
159
160#[derive(Debug, Deserialize, Clone)]
161pub struct CurrentUsage {
162    pub input_tokens: Option<u64>,
163    #[serde(alias = "_output_tokens")]
164    pub output_tokens: Option<u64>,
165    pub cache_creation_input_tokens: Option<u64>,
166    pub cache_read_input_tokens: Option<u64>,
167}
168
169#[derive(Debug, Deserialize, Clone)]
170pub struct Cost {
171    pub total_cost_usd: Option<f64>,
172    pub total_duration_ms: Option<u64>,
173    pub total_api_duration_ms: Option<u64>,
174    pub total_lines_added: Option<u64>,
175    pub total_lines_removed: Option<u64>,
176}
177
178#[derive(Debug, Deserialize, Clone)]
179pub struct Worktree {
180    pub name: Option<String>,
181    pub path: Option<String>,
182    pub branch: Option<String>,
183    pub original_cwd: Option<String>,
184    pub original_branch: Option<String>,
185}
186
187/// Quota usage derived from the payload's `rate_limits`.
188#[derive(Debug, Clone, PartialEq)]
189pub struct QuotaData {
190    pub five_hour_pct: Option<f64>,
191    pub five_hour_resets_at: Option<String>,
192    pub seven_day_pct: Option<f64>,
193    pub seven_day_resets_at: Option<String>,
194}
195
196#[derive(Debug, PartialEq)]
197pub struct GitInfo {
198    pub branch: String,
199    pub is_dirty: bool,
200    pub repo_name: Option<String>,
201    pub lines_added: usize,
202    pub lines_removed: usize,
203}