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

Function draw

crates/openshell-tui/src/ui/sandbox_draft.rs:17–169  ·  view source on GitHub ↗

Draw the network rules panel (list view with highlight bar).

(frame: &mut Frame<'_>, app: &mut App, area: Rect)

Source from the content-addressed store, hash-verified

15
16/// Draw the network rules panel (list view with highlight bar).
17pub fn draw(frame: &mut Frame<'_>, app: &mut App, area: Rect) {
18 let t = &app.theme;
19 let pending_count = app
20 .draft_chunks
21 .iter()
22 .filter(|c| c.status == "pending")
23 .count();
24
25 let title = if pending_count > 0 {
26 Line::from(vec![
27 Span::styled(" Network Rules ", t.heading),
28 Span::styled(format!(" {pending_count} pending "), t.badge),
29 Span::raw(" "),
30 ])
31 } else {
32 Line::from(Span::styled(" Network Rules ", t.heading))
33 };
34
35 let mut block = Block::default()
36 .title(title)
37 .borders(Borders::ALL)
38 .border_style(t.border_focused)
39 .padding(Padding::horizontal(1));
40
41 if app.sandbox_policy_is_global {
42 block = block.title_bottom(
43 Line::from(Span::styled(
44 " Cannot approve rules while global policy is active ",
45 t.status_warn,
46 ))
47 .left_aligned(),
48 );
49 }
50
51 if app.draft_chunks.is_empty() {
52 let msg = Paragraph::new(
53 "No network rules yet. Denied connections will \
54 generate rules automatically.",
55 )
56 .block(block)
57 .style(t.muted);
58 frame.render_widget(msg, area);
59 return;
60 }
61
62 // Calculate visible area inside the block (borders + padding).
63 let inner_height = area.height.saturating_sub(2) as usize;
64 app.draft_viewport_height = inner_height;
65
66 // Clamp cursor to visible range.
67 let total = app.draft_chunks.len();
68 let visible_count = total.saturating_sub(app.draft_scroll).min(inner_height);
69 if visible_count > 0 {
70 app.draft_selected = app.draft_selected.min(visible_count - 1);
71 }
72
73 let cursor_pos = app.draft_selected;
74

Callers

nothing calls this directly

Calls 6

approval_annotationFunction · 0.85
lenMethod · 0.80
pushMethod · 0.80
is_emptyMethod · 0.45
as_strMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected