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
//! Snapshot view rendering for the AI Inspector panel.
//!
//! Contains the controls row, environment strip, and the four view-mode
//! renderers: Cards, Timeline, Tree, and ListDetail.
use egui::{Color32, Frame, Label, RichText};
use crate::ai_inspector::panel_helpers::{format_duration, truncate_chars, truncate_output};
use crate::ai_inspector::snapshot::{CommandEntry, SnapshotData};
use crate::ui_constants::{AI_PANEL_CARD_ROUNDING, AI_PANEL_INNER_MARGIN};
use super::AIInspectorPanel;
use super::types::{CARD_BG, CARD_BORDER, EXIT_FAILURE, EXIT_SUCCESS, SCOPE_OPTIONS, ViewMode};
impl AIInspectorPanel {
/// Render the controls row (scope, view mode, live/paused, refresh).
pub(super) fn render_controls(&mut self, ui: &mut egui::Ui) {
ui.horizontal(|ui| {
// Scope dropdown
let current_scope_label = SCOPE_OPTIONS
.iter()
.find(|opt| opt.scope == self.scope)
.map_or("Visible", |opt| opt.label);
egui::ComboBox::from_id_salt("ai_inspector_scope")
.selected_text(current_scope_label)
.width(90.0)
.show_ui(ui, |ui| {
for opt in SCOPE_OPTIONS {
if ui
.selectable_label(self.scope == opt.scope, opt.label)
.clicked()
{
self.scope = opt.scope.clone();
self.needs_refresh = true;
}
}
});
// View mode dropdown
egui::ComboBox::from_id_salt("ai_inspector_view_mode")
.selected_text(self.view_mode.label())
.width(80.0)
.show_ui(ui, |ui| {
for mode in ViewMode::all() {
if ui
.selectable_label(self.view_mode == *mode, mode.label())
.clicked()
{
self.view_mode = *mode;
}
}
});
});
ui.horizontal(|ui| {
// Live/Paused toggle
let live_label = if self.live_update {
RichText::new("* Live").color(EXIT_SUCCESS).small()
} else {
RichText::new("o Paused")
.color(Color32::from_gray(140))
.small()
};
if ui
.button(live_label)
.on_hover_text(if self.live_update {
"Click to pause auto-refresh"
} else {
"Click to enable auto-refresh"
})
.clicked()
{
self.live_update = !self.live_update;
}
// Refresh button
if ui
.button(RichText::new("~ Refresh").small())
.on_hover_text("Refresh snapshot now")
.clicked()
{
self.needs_refresh = true;
}
});
}
/// Render the environment info strip.
pub(super) fn render_environment(&self, ui: &mut egui::Ui, snapshot: &SnapshotData) {
let env = &snapshot.environment;
let dim_color = Color32::from_gray(120);
let val_color = Color32::from_gray(190);
ui.horizontal_wrapped(|ui| {
// user@host
if let Some(ref user) = env.username {
ui.label(RichText::new(user).color(val_color).small());
if env.hostname.is_some() {
ui.label(RichText::new("@").color(dim_color).small());
}
}
if let Some(ref host) = env.hostname {
ui.label(RichText::new(host).color(val_color).small());
}
// Separator
if env.username.is_some() || env.hostname.is_some() {
ui.label(RichText::new("|").color(dim_color).small());
}
// CWD
if let Some(ref cwd) = env.cwd {
ui.label(RichText::new(cwd).color(val_color).small());
}
});
ui.horizontal(|ui| {
// Shell
if let Some(ref shell) = env.shell {
ui.label(RichText::new("Shell:").color(dim_color).small());
ui.label(RichText::new(shell).color(val_color).small());
ui.label(RichText::new("|").color(dim_color).small());
}
// Command count
let cmd_count = snapshot.commands.len();
ui.label(RichText::new("Commands:").color(dim_color).small());
ui.label(
RichText::new(cmd_count.to_string())
.color(val_color)
.small(),
);
});
}
/// Render cards view: each command in a framed card.
pub(super) fn render_cards(ui: &mut egui::Ui, commands: &[CommandEntry]) {
for (i, cmd) in commands.iter().enumerate() {
let card_frame = Frame::new()
.fill(CARD_BG)
.stroke(CARD_BORDER)
.corner_radius(AI_PANEL_CARD_ROUNDING)
.inner_margin(AI_PANEL_INNER_MARGIN);
card_frame.show(ui, |ui| {
ui.set_min_width(ui.available_width());
// Command text (wrap to prevent panel overflow)
ui.add(
Label::new(
RichText::new(&cmd.command)
.color(Color32::from_gray(230))
.monospace(),
)
.wrap(),
);
ui.add_space(4.0);
// Exit code badge + duration
ui.horizontal(|ui| {
if let Some(code) = cmd.exit_code {
let (color, text) = if code == 0 {
(EXIT_SUCCESS, format!("OK {code}"))
} else {
(EXIT_FAILURE, format!("FAIL {code}"))
};
ui.label(RichText::new(text).color(color).small().strong());
}
// Duration
let duration_str = format_duration(cmd.duration_ms);
ui.label(
RichText::new(duration_str)
.color(Color32::from_gray(120))
.small(),
);
});
// CWD if present
if let Some(ref cwd) = cmd.cwd {
ui.label(
RichText::new(cwd)
.color(Color32::from_gray(90))
.small()
.italics(),
);
}
// Collapsible output
if let Some(ref output) = cmd.output
&& !output.is_empty()
{
egui::CollapsingHeader::new(
RichText::new("Output")
.color(Color32::from_gray(140))
.small(),
)
.id_salt(format!("card_output_{i}"))
.show(ui, |ui| {
let truncated = truncate_output(output, 20);
ui.add(
Label::new(
RichText::new(truncated)
.color(Color32::from_gray(160))
.monospace()
.small(),
)
.wrap(),
);
});
}
});
ui.add_space(4.0);
}
}
/// Render timeline view: flat list with icons and durations.
pub(super) fn render_timeline(ui: &mut egui::Ui, commands: &[CommandEntry]) {
// Reserve space for icon (~15px), duration label (~60px), and spacing
let avail = ui.available_width();
let max_cmd_chars = ((avail - 90.0) / 7.5).max(10.0) as usize;
for (i, cmd) in commands.iter().enumerate() {
ui.horizontal(|ui| {
// Status icon
let icon = match cmd.exit_code {
Some(0) => RichText::new("*").color(EXIT_SUCCESS),
Some(_) => RichText::new("*").color(EXIT_FAILURE),
None => RichText::new("o").color(Color32::from_gray(100)),
};
ui.label(icon);
// Command text (truncated to fit, char-boundary-safe)
let cmd_display = if cmd.command.len() > max_cmd_chars {
format!("{}...", truncate_chars(&cmd.command, max_cmd_chars))
} else {
cmd.command.clone()
};
ui.label(
RichText::new(cmd_display)
.color(Color32::from_gray(210))
.monospace(),
);
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
ui.label(
RichText::new(format_duration(cmd.duration_ms))
.color(Color32::from_gray(100))
.small(),
);
});
});
// Separator between entries
if i < commands.len() - 1 {
ui.separator();
}
}
}
/// Render tree view: collapsing headers per command with detail children.
pub(super) fn render_tree(ui: &mut egui::Ui, commands: &[CommandEntry]) {
// Truncate to fit within panel - account for collapsing header icon (~20px)
// and monospace char width (~7-8px). Use available width dynamically.
let avail = ui.available_width();
let max_chars = ((avail - 20.0) / 7.5).max(10.0) as usize;
for (i, cmd) in commands.iter().enumerate() {
let header_text = if cmd.command.len() > max_chars {
format!("{}...", truncate_chars(&cmd.command, max_chars))
} else {
cmd.command.clone()
};
egui::CollapsingHeader::new(
RichText::new(header_text)
.color(Color32::from_gray(210))
.monospace(),
)
.id_salt(format!("tree_cmd_{i}"))
.show(ui, |ui| {
// Exit code
if let Some(code) = cmd.exit_code {
let (color, label) = if code == 0 {
(EXIT_SUCCESS, "Success")
} else {
(EXIT_FAILURE, "Failed")
};
ui.horizontal(|ui| {
ui.label(
RichText::new("Exit:")
.color(Color32::from_gray(120))
.small(),
);
ui.label(
RichText::new(format!("{code} ({label})"))
.color(color)
.small(),
);
});
}
// Duration
ui.horizontal(|ui| {
ui.label(
RichText::new("Duration:")
.color(Color32::from_gray(120))
.small(),
);
ui.label(
RichText::new(format_duration(cmd.duration_ms))
.color(Color32::from_gray(180))
.small(),
);
});
// CWD
if let Some(ref cwd) = cmd.cwd {
ui.horizontal(|ui| {
ui.label(RichText::new("CWD:").color(Color32::from_gray(120)).small());
ui.label(RichText::new(cwd).color(Color32::from_gray(180)).small());
});
}
// Output
if let Some(ref output) = cmd.output
&& !output.is_empty()
{
ui.add_space(2.0);
ui.label(
RichText::new("Output:")
.color(Color32::from_gray(120))
.small(),
);
let truncated = truncate_output(output, 20);
ui.add(
Label::new(
RichText::new(truncated)
.color(Color32::from_gray(160))
.monospace()
.small(),
)
.wrap(),
);
}
});
}
}
/// Render list detail view: simple list with icon and command text.
pub(super) fn render_list_detail(ui: &mut egui::Ui, commands: &[CommandEntry]) {
// Truncate command to fit in horizontal layout
let avail = ui.available_width();
let max_cmd_chars = ((avail - 50.0) / 7.5).max(10.0) as usize;
for cmd in commands {
ui.horizontal(|ui| {
// Status icon
let icon = match cmd.exit_code {
Some(0) => RichText::new("OK").color(EXIT_SUCCESS),
Some(_) => RichText::new("FAIL").color(EXIT_FAILURE),
None => RichText::new("-").color(Color32::from_gray(100)),
};
ui.label(icon);
// Command text (truncated to fit, char-boundary-safe)
let cmd_display = if cmd.command.len() > max_cmd_chars {
format!("{}...", truncate_chars(&cmd.command, max_cmd_chars))
} else {
cmd.command.clone()
};
ui.label(
RichText::new(cmd_display)
.color(Color32::from_gray(210))
.monospace(),
);
});
}
}
}