agent-air-tui 0.7.0

TUI frontend for agent-air - ratatui-based terminal interface
Documentation
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
// Theme system for the TUI
//
// Centralizes all colors, modifiers, and styles for consistent theming.
// Supports runtime theme switching via RwLock.

use std::sync::RwLock;

use ratatui::style::{Color, Modifier, Style};

/// Global theme instance with runtime switching support
static THEME: RwLock<Option<Theme>> = RwLock::new(None);

/// Current theme name
static THEME_NAME: RwLock<Option<String>> = RwLock::new(None);

/// Initialize the global theme (call once at startup)
pub fn init_theme(name: &str, theme: Theme) {
    if let Ok(mut guard) = THEME.write() {
        *guard = Some(theme);
    }
    if let Ok(mut guard) = THEME_NAME.write() {
        *guard = Some(name.to_string());
    }
}

/// Set a new theme at runtime
pub fn set_theme(name: &str, theme: Theme) {
    if let Ok(mut guard) = THEME.write() {
        *guard = Some(theme);
    }
    if let Ok(mut guard) = THEME_NAME.write() {
        *guard = Some(name.to_string());
    }
}

/// Get the current theme name
pub fn current_theme_name() -> String {
    THEME_NAME
        .read()
        .ok()
        .and_then(|guard| guard.clone())
        .unwrap_or_else(|| "default".to_string())
}

/// Get the current theme (cloned for safe access)
pub fn theme() -> Theme {
    THEME
        .read()
        .ok()
        .and_then(|guard| guard.clone())
        .unwrap_or_default()
}

/// Complete theme definition for the TUI.
///
/// Contains styles for all UI elements including chat messages, markdown formatting,
/// tool execution, input areas, popups, and interactive panels.
#[derive(Clone)]
pub struct Theme {
    // Base
    /// Background style for the entire UI.
    pub background: Style,
    /// Default text style.
    pub text: Style,

    // Borders & Chrome
    pub border: Style,
    pub border_focused: Style,

    // Chat Title Bar
    pub title_separator: Style,
    pub title_indicator_connected: Style,
    pub title_indicator_disconnected: Style,
    pub title_text: Style,

    // Message Roles
    pub user_prefix: Style,
    pub system_prefix: Style,
    pub assistant_prefix: Style,
    pub timestamp: Style,

    // Streaming
    pub cursor: Style,

    // Markdown - Inline
    pub bold: Modifier,
    pub italic: Modifier,
    pub strikethrough: Modifier,
    pub inline_code: Style,
    pub link_text: Style,
    pub link_url: Style,

    // Markdown - Headings
    pub heading_1: Style,
    pub heading_2: Style,
    pub heading_3: Style,
    pub heading_4: Style,

    // Markdown - Code Blocks
    pub code_block: Style,

    // Tables
    pub table_header: Style,
    pub table_cell: Style,
    pub table_border: Style,

    // Tool Execution
    pub tool_header: Style,
    pub tool_executing: Style,
    pub tool_completed: Style,
    pub tool_failed: Style,

    // Input Area
    pub input_border: Style,
    pub input_text: Style,
    pub prompt: Style,

    // Throbber/Progress
    pub throbber_label: Style,
    pub throbber_spinner: Style,

    // Status Bar
    pub status_help: Style,
    pub status_model: Style,

    // Slash Command Popup
    pub popup_border: Style,
    pub popup_header: Style,
    pub popup_item: Style,
    pub popup_item_selected: Style,
    pub popup_item_desc: Style,
    pub popup_item_desc_selected: Style,
    pub popup_selected_bg: Style,
    pub popup_empty: Style,

    // UI Panel styles (permission panel, question panel)
    pub help_text: Style,
    pub muted_text: Style,
    pub focused_text: Style,
    pub focus_indicator: Style,
    pub selected: Style,
    pub unselected: Style,
    pub button_confirm: Style,
    pub button_confirm_focused: Style,
    pub button_cancel: Style,
    pub button_cancel_focused: Style,
    pub warning: Style,
    pub category: Style,
    pub resource: Style,
}

impl Theme {
    // Accessor methods for compatibility with code that used the old trait

    // Markdown styles
    pub fn bold(&self) -> Modifier {
        self.bold
    }
    pub fn italic(&self) -> Modifier {
        self.italic
    }
    pub fn strikethrough(&self) -> Modifier {
        self.strikethrough
    }
    pub fn inline_code(&self) -> Style {
        self.inline_code
    }
    pub fn link_text(&self) -> Style {
        self.link_text
    }
    pub fn link_url(&self) -> Style {
        self.link_url
    }
    pub fn heading_1(&self) -> Style {
        self.heading_1
    }
    pub fn heading_2(&self) -> Style {
        self.heading_2
    }
    pub fn heading_3(&self) -> Style {
        self.heading_3
    }
    pub fn heading_4(&self) -> Style {
        self.heading_4
    }
    pub fn code_block(&self) -> Style {
        self.code_block
    }
    pub fn assistant_prefix(&self) -> Style {
        self.assistant_prefix
    }

    // Table styles
    pub fn table_header(&self) -> Style {
        self.table_header
    }
    pub fn table_cell(&self) -> Style {
        self.table_cell
    }
    pub fn table_border(&self) -> Style {
        self.table_border
    }

    // Border styles
    pub fn border(&self) -> Style {
        self.border
    }
    pub fn border_focused(&self) -> Style {
        self.border_focused
    }

    // Popup styles
    pub fn popup_border(&self) -> Style {
        self.popup_border
    }
    pub fn popup_header(&self) -> Style {
        self.popup_header
    }
    pub fn popup_item(&self) -> Style {
        self.popup_item
    }
    pub fn popup_item_selected(&self) -> Style {
        self.popup_item_selected
    }
    pub fn popup_item_desc(&self) -> Style {
        self.popup_item_desc
    }
    pub fn popup_item_desc_selected(&self) -> Style {
        self.popup_item_desc_selected
    }
    pub fn popup_selected_bg(&self) -> Style {
        self.popup_selected_bg
    }
    pub fn popup_empty(&self) -> Style {
        self.popup_empty
    }

    // Status styles
    pub fn status_help(&self) -> Style {
        self.status_help
    }
    pub fn background(&self) -> Style {
        self.background
    }
    pub fn text(&self) -> Style {
        self.text
    }
    pub fn cursor(&self) -> Style {
        self.cursor
    }

    // UI Panel styles
    pub fn help_text(&self) -> Style {
        self.help_text
    }
    pub fn muted_text(&self) -> Style {
        self.muted_text
    }
    pub fn focused_text(&self) -> Style {
        self.focused_text
    }
    pub fn focus_indicator(&self) -> Style {
        self.focus_indicator
    }
    pub fn selected(&self) -> Style {
        self.selected
    }
    pub fn unselected(&self) -> Style {
        self.unselected
    }
    pub fn button_confirm(&self) -> Style {
        self.button_confirm
    }
    pub fn button_confirm_focused(&self) -> Style {
        self.button_confirm_focused
    }
    pub fn button_cancel(&self) -> Style {
        self.button_cancel
    }
    pub fn button_cancel_focused(&self) -> Style {
        self.button_cancel_focused
    }
    pub fn warning(&self) -> Style {
        self.warning
    }
    pub fn category(&self) -> Style {
        self.category
    }
    pub fn resource(&self) -> Style {
        self.resource
    }
}

impl Default for Theme {
    fn default() -> Self {
        Self {
            // Base
            background: Style::default(),
            text: Style::default(),

            // Borders & Chrome
            border: Style::default().fg(Color::DarkGray),
            border_focused: Style::default().fg(Color::Cyan),

            // Chat Title Bar
            title_separator: Style::default().fg(Color::DarkGray),
            title_indicator_connected: Style::default().fg(Color::Green),
            title_indicator_disconnected: Style::default().fg(Color::Red),
            title_text: Style::default(),

            // Message Roles
            user_prefix: Style::default().fg(Color::Blue),
            system_prefix: Style::default().fg(Color::Yellow),
            assistant_prefix: Style::default().fg(Color::Magenta),
            timestamp: Style::default().fg(Color::DarkGray),

            // Streaming
            cursor: Style::default().fg(Color::Green),

            // Markdown - Inline (modifiers only, preserve existing fg color)
            bold: Modifier::BOLD,
            italic: Modifier::ITALIC,
            strikethrough: Modifier::CROSSED_OUT,
            inline_code: Style::default().fg(Color::Yellow),
            link_text: Style::default().fg(Color::Cyan),
            link_url: Style::default().fg(Color::DarkGray),

            // Markdown - Headings
            heading_1: Style::default()
                .fg(Color::Cyan)
                .add_modifier(Modifier::BOLD),
            heading_2: Style::default()
                .fg(Color::Green)
                .add_modifier(Modifier::BOLD),
            heading_3: Style::default()
                .fg(Color::Yellow)
                .add_modifier(Modifier::BOLD),
            heading_4: Style::default()
                .fg(Color::White)
                .add_modifier(Modifier::BOLD),

            // Markdown - Code Blocks
            code_block: Style::default().fg(Color::Rgb(180, 180, 180)),

            // Tables
            table_header: Style::default()
                .fg(Color::Cyan)
                .add_modifier(Modifier::BOLD),
            table_cell: Style::default().fg(Color::White),
            table_border: Style::default().fg(Color::DarkGray),

            // Tool Execution
            tool_header: Style::default().fg(Color::Cyan),
            tool_executing: Style::default()
                .fg(Color::Gray)
                .add_modifier(Modifier::ITALIC),
            tool_completed: Style::default().fg(Color::Green),
            tool_failed: Style::default().fg(Color::Red),

            // Input Area
            input_border: Style::default().fg(Color::DarkGray),
            input_text: Style::default(),
            prompt: Style::default(),

            // Throbber/Progress
            throbber_label: Style::default().fg(Color::DarkGray),
            throbber_spinner: Style::default().fg(Color::Cyan),

            // Status Bar
            status_help: Style::default().fg(Color::DarkGray),
            status_model: Style::default().fg(Color::DarkGray),

            // Slash Command Popup
            popup_border: Style::default().fg(Color::DarkGray),
            popup_header: Style::default().fg(Color::DarkGray),
            popup_item: Style::default().fg(Color::White),
            popup_item_selected: Style::default()
                .fg(Color::Cyan)
                .add_modifier(Modifier::BOLD),
            popup_item_desc: Style::default().fg(Color::DarkGray),
            popup_item_desc_selected: Style::default().fg(Color::Gray),
            popup_selected_bg: Style::default().bg(Color::DarkGray),
            popup_empty: Style::default()
                .fg(Color::DarkGray)
                .add_modifier(Modifier::ITALIC),

            // UI Panel styles
            help_text: Style::default().fg(Color::DarkGray),
            muted_text: Style::default().fg(Color::Gray),
            focused_text: Style::default()
                .fg(Color::Cyan)
                .add_modifier(Modifier::BOLD),
            focus_indicator: Style::default().fg(Color::Yellow),
            selected: Style::default().fg(Color::Green),
            unselected: Style::default().fg(Color::Gray),
            button_confirm: Style::default().fg(Color::Rgb(60, 120, 60)),
            button_confirm_focused: Style::default()
                .fg(Color::LightGreen)
                .add_modifier(Modifier::BOLD),
            button_cancel: Style::default().fg(Color::Rgb(140, 70, 70)),
            button_cancel_focused: Style::default()
                .fg(Color::LightRed)
                .add_modifier(Modifier::BOLD),
            warning: Style::default().fg(Color::Yellow),
            category: Style::default().fg(Color::Magenta),
            resource: Style::default().fg(Color::Cyan),
        }
    }
}