claude_code_status_line/
types.rs

1use crate::colors::SectionColors;
2use crate::utils::visible_len;
3use serde::{Deserialize, Serialize};
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 new(content: String, priority: u16, colors: SectionColors) -> Self {
25        let width = visible_len(&content);
26        Section {
27            kind: SectionKind::Generic,
28            content,
29            priority,
30            colors,
31            width,
32        }
33    }
34
35    pub fn new_quota_compact(
36        label: &str,
37        content: String,
38        priority: u16,
39        colors: SectionColors,
40    ) -> Self {
41        let width = visible_len(&content);
42        Section {
43            kind: SectionKind::QuotaCompact(label.to_string()),
44            content,
45            priority,
46            colors,
47            width,
48        }
49    }
50
51    pub fn new_quota_detailed(
52        label: &str,
53        content: String,
54        priority: u16,
55        colors: SectionColors,
56    ) -> Self {
57        let width = visible_len(&content);
58        Section {
59            kind: SectionKind::QuotaDetailed(label.to_string()),
60            content,
61            priority,
62            colors,
63            width,
64        }
65    }
66
67    pub fn new_context_compact(content: String, priority: u16, colors: SectionColors) -> Self {
68        let width = visible_len(&content);
69        Section {
70            kind: SectionKind::ContextCompact,
71            content,
72            priority,
73            colors,
74            width,
75        }
76    }
77
78    pub fn new_context_detailed(content: String, priority: u16, colors: SectionColors) -> Self {
79        let width = visible_len(&content);
80        Section {
81            kind: SectionKind::ContextDetailed,
82            content,
83            priority,
84            colors,
85            width,
86        }
87    }
88}
89
90/// Context usage information (used for display formatting)
91pub struct ContextUsageInfo {
92    pub percentage: f64,
93    pub current_usage_tokens: u64,
94    pub context_window_size: u64,
95    pub is_exact: bool, // true if from direct percentage, false if calculated
96}
97
98#[derive(Debug, Deserialize)]
99pub struct ClaudeInput {
100    pub workspace: Option<Workspace>,
101    pub model: Option<Model>,
102    pub context_window: Option<ContextWindow>,
103    pub cost: Option<Cost>,
104    pub output_style: Option<OutputStyle>,
105}
106
107#[derive(Debug, Deserialize)]
108pub struct Workspace {
109    pub current_dir: Option<String>,
110}
111
112#[derive(Debug, Deserialize)]
113pub struct Model {
114    pub display_name: Option<String>,
115}
116
117#[derive(Debug, Deserialize)]
118pub struct OutputStyle {
119    pub name: Option<String>,
120}
121
122#[derive(Debug, Deserialize)]
123pub struct ContextWindow {
124    pub context_window_size: Option<u64>,
125    pub current_usage: Option<CurrentUsage>,
126    pub used_percentage: Option<f64>,
127    pub remaining_percentage: Option<f64>,
128}
129
130#[derive(Debug, Deserialize)]
131pub struct CurrentUsage {
132    pub input_tokens: Option<u64>,
133    pub _output_tokens: Option<u64>,
134    pub cache_creation_input_tokens: Option<u64>,
135    pub cache_read_input_tokens: Option<u64>,
136}
137
138#[derive(Debug, Deserialize)]
139pub struct Cost {
140    pub total_cost_usd: Option<f64>,
141    pub total_duration_ms: Option<u64>,
142    pub total_api_duration_ms: Option<u64>,
143    pub total_lines_added: Option<u64>,
144    pub total_lines_removed: Option<u64>,
145}
146
147#[derive(Debug, Deserialize)]
148pub struct QuotaResponse {
149    pub five_hour: Option<QuotaLimit>,
150    pub seven_day: Option<QuotaLimit>,
151}
152
153#[derive(Debug, Deserialize)]
154pub struct QuotaLimit {
155    pub utilization: f64,
156    pub resets_at: Option<String>,
157}
158
159#[derive(Debug, Deserialize)]
160pub struct KeychainCredentials {
161    #[serde(rename = "claudeAiOauth")]
162    pub claude_ai_oauth: Option<OAuthCredentials>,
163}
164
165#[derive(Debug, Deserialize)]
166pub struct OAuthCredentials {
167    #[serde(rename = "accessToken")]
168    pub access_token: String,
169}
170
171// Quota data structure
172#[derive(Debug, Deserialize, Serialize, Clone)]
173pub struct QuotaData {
174    pub five_hour_pct: Option<f64>,
175    pub five_hour_resets_at: Option<String>,
176    pub seven_day_pct: Option<f64>,
177    pub seven_day_resets_at: Option<String>,
178}
179
180#[derive(Serialize, Deserialize)]
181pub struct CachedQuota {
182    pub timestamp: u64,
183    pub data: QuotaData,
184}
185
186#[derive(Debug, PartialEq)]
187pub struct GitInfo {
188    pub branch: String,
189    pub is_dirty: bool,
190    pub repo_name: Option<String>,
191    pub lines_added: usize,
192    pub lines_removed: usize,
193}