MCPcopy Create free account
hub / github.com/GCWing/BitFun / render

Method render

src/apps/cli/src/ui/mcp_selector.rs:155–304  ·  view source on GitHub ↗

Render the MCP selector popup as an overlay

(&mut self, frame: &mut Frame, area: Rect, theme: &Theme)

Source from the content-addressed store, hash-verified

153
154 /// Render the MCP selector popup as an overlay
155 pub fn render(&mut self, frame: &mut Frame, area: Rect, theme: &Theme) {
156 if !self.visible {
157 self.last_area = None;
158 return;
159 }
160
161 let popup_width = area.width.saturating_sub(4).min(72);
162 // +5 for border(2) + title(1) + hint(1) + padding(1)
163 let popup_height = (self.items.len() as u16 + 5)
164 .min(area.height.saturating_sub(2))
165 .max(6);
166 if popup_height < 5 || popup_width < 30 {
167 self.last_area = None;
168 return;
169 }
170
171 let popup_x = area.x + (area.width.saturating_sub(popup_width)) / 2;
172 let popup_y = area.y + (area.height.saturating_sub(popup_height)) / 2;
173
174 let popup_area = Rect {
175 x: popup_x,
176 y: popup_y,
177 width: popup_width,
178 height: popup_height,
179 };
180 self.last_area = Some(popup_area);
181
182 let loading_id = self.loading_id.clone();
183 let confirm_delete_id = self.confirm_delete_id.clone();
184 let has_confirm_delete = confirm_delete_id.is_some();
185
186 let mut list_items: Vec<ListItem> = self
187 .items
188 .iter()
189 .map(|item| {
190 let is_loading = loading_id.as_ref().map_or(false, |id| id == &item.id);
191 let is_confirm_delete = confirm_delete_id
192 .as_ref()
193 .map_or(false, |id| id == &item.id);
194
195 // If this item is pending delete confirmation, show special style
196 if is_confirm_delete {
197 let line = Line::from(vec![
198 Span::styled(
199 "\u{2717} ",
200 theme.style(StyleKind::Error).add_modifier(Modifier::BOLD),
201 ),
202 Span::styled(
203 &item.name,
204 theme.style(StyleKind::Error).add_modifier(Modifier::BOLD),
205 ),
206 Span::styled(
207 " \u{2190} Press 'd' again to delete, any other key to cancel",
208 theme.style(StyleKind::Error),
209 ),
210 ]);
211 return ListItem::new(line);
212 }

Callers

nothing calls this directly

Calls 10

collectMethod · 0.80
iterMethod · 0.80
styleMethod · 0.80
titleMethod · 0.80
selection_foregroundMethod · 0.80
lenMethod · 0.45
cloneMethod · 0.45
as_strMethod · 0.45
is_emptyMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected