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, // content_tokens + buffer (matches current_usage naming)
94    pub context_window_size: u64,  // total window size (same name as JSON)
95}
96
97#[derive(Debug, Deserialize)]
98pub struct ClaudeInput {
99    pub workspace: Option<Workspace>,
100    pub model: Option<Model>,
101    pub context_window: Option<ContextWindow>,
102    pub cost: Option<Cost>,
103    pub output_style: Option<OutputStyle>,
104}
105
106#[derive(Debug, Deserialize)]
107pub struct Workspace {
108    pub current_dir: Option<String>,
109}
110
111#[derive(Debug, Deserialize)]
112pub struct Model {
113    pub display_name: Option<String>,
114}
115
116#[derive(Debug, Deserialize)]
117pub struct OutputStyle {
118    pub name: Option<String>,
119}
120
121#[derive(Debug, Deserialize)]
122pub struct ContextWindow {
123    pub context_window_size: Option<u64>,
124    pub current_usage: Option<CurrentUsage>,
125}
126
127#[derive(Debug, Deserialize)]
128pub struct CurrentUsage {
129    pub input_tokens: Option<u64>,
130    pub _output_tokens: Option<u64>,
131    pub cache_creation_input_tokens: Option<u64>,
132    pub cache_read_input_tokens: Option<u64>,
133}
134
135#[derive(Debug, Deserialize)]
136pub struct Cost {
137    pub total_cost_usd: Option<f64>,
138    pub total_duration_ms: Option<u64>,
139    pub total_api_duration_ms: Option<u64>,
140    pub total_lines_added: Option<u64>,
141    pub total_lines_removed: Option<u64>,
142}
143
144#[derive(Debug, Deserialize)]
145pub struct QuotaResponse {
146    pub five_hour: Option<QuotaLimit>,
147    pub seven_day: Option<QuotaLimit>,
148}
149
150#[derive(Debug, Deserialize)]
151pub struct QuotaLimit {
152    pub utilization: f64,
153    pub resets_at: Option<String>,
154}
155
156#[derive(Debug, Deserialize)]
157pub struct KeychainCredentials {
158    #[serde(rename = "claudeAiOauth")]
159    pub claude_ai_oauth: Option<OAuthCredentials>,
160}
161
162#[derive(Debug, Deserialize)]
163pub struct OAuthCredentials {
164    #[serde(rename = "accessToken")]
165    pub access_token: String,
166}
167
168// Quota data structure
169#[derive(Debug, Deserialize, Serialize, Clone)]
170pub struct QuotaData {
171    pub five_hour_pct: Option<f64>,
172    pub five_hour_resets_at: Option<String>,
173    pub seven_day_pct: Option<f64>,
174    pub seven_day_resets_at: Option<String>,
175}
176
177#[derive(Serialize, Deserialize)]
178pub struct CachedQuota {
179    pub timestamp: u64,
180    pub data: QuotaData,
181}
182
183#[derive(Debug, PartialEq)]
184pub struct GitInfo {
185    pub branch: String,
186    pub is_dirty: bool,
187    pub repo_name: Option<String>,
188    pub lines_added: usize,
189    pub lines_removed: usize,
190}