MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / draw

Function draw

crates/openshell-tui/src/ui/sandbox_logs.rs:13–121  ·  view source on GitHub ↗
(frame: &mut Frame<'_>, app: &mut App, area: Rect)

Source from the content-addressed store, hash-verified

11use super::centered_rect;
12
13pub fn draw(frame: &mut Frame<'_>, app: &mut App, area: Rect) {
14 let t = &app.theme;
15 let name = app
16 .sandbox_names
17 .get(app.sandbox_selected)
18 .map_or("-", String::as_str);
19
20 let filter_label = app.log_source_filter.label();
21
22 let block = Block::default()
23 .title(Span::styled(format!(" Logs: {name} "), t.heading))
24 .borders(Borders::ALL)
25 .border_style(t.border_focused)
26 .padding(Padding::horizontal(1));
27
28 // Calculate visible area inside the block (borders + padding).
29 let inner_height = area.height.saturating_sub(2) as usize;
30 // Inner width = total width - 2 (borders) - 2 (horizontal padding).
31 let inner_width = area.width.saturating_sub(4) as usize;
32 // Store viewport height so autoscroll calculations can use it.
33 app.log_viewport_height = inner_height;
34
35 // Clamp cursor to visible range before borrowing filtered log lines.
36 {
37 let filtered_len = app.filtered_log_lines().len();
38 let visible_count = filtered_len
39 .saturating_sub(app.sandbox_log_scroll)
40 .min(inner_height);
41 if visible_count > 0 {
42 app.log_cursor = app.log_cursor.min(visible_count - 1);
43 }
44 }
45
46 // Snapshot the cursor position (already clamped above).
47 let cursor_pos = app.log_cursor;
48
49 let filtered: Vec<&LogLine> = app.filtered_log_lines();
50
51 if filtered.is_empty() && app.sandbox_log_lines.is_empty() {
52 // Still loading.
53 let lines = vec![Line::from(Span::styled("Loading...", t.muted))];
54 let block = block.title_bottom(Line::from(Span::styled(
55 format!(" filter: {filter_label} "),
56 t.muted,
57 )));
58 frame.render_widget(Paragraph::new(lines).block(block), area);
59 return;
60 }
61
62 // Compute visual selection range (if active).
63 let selection_range = app.log_selection_anchor.map(|anchor| {
64 let cursor_abs = app.sandbox_log_scroll + cursor_pos;
65 (anchor.min(cursor_abs), anchor.max(cursor_abs))
66 });
67
68 let lines: Vec<Line<'_>> = filtered
69 .iter()
70 .skip(app.sandbox_log_scroll)

Callers

nothing calls this directly

Calls 6

render_log_lineFunction · 0.85
lenMethod · 0.80
filtered_log_linesMethod · 0.80
getMethod · 0.45
labelMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected