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

Function draw_enter_key

crates/openshell-tui/src/ui/create_provider.rs:192–414  ·  view source on GitHub ↗
(
    frame: &mut Frame<'_>,
    form: &crate::app::CreateProviderForm,
    area: Rect,
    theme: &crate::theme::Theme,
)

Source from the content-addressed store, hash-verified

190// ---------------------------------------------------------------------------
191
192fn draw_enter_key(
193 frame: &mut Frame<'_>,
194 form: &crate::app::CreateProviderForm,
195 area: Rect,
196 theme: &crate::theme::Theme,
197) {
198 let t = theme;
199 let modal_width = 64u16.min(area.width.saturating_sub(4));
200
201 let has_warning = form.warning.is_some();
202 let warning_rows: u16 = if has_warning { 2 } else { 0 }; // warning + spacer
203
204 #[allow(clippy::cast_possible_truncation)]
205 let content_height = if form.is_generic {
206 // type(1) + name(2) + spacer(1) + env_name(2) + value(2) + spacer(1) + submit(1) + status(1) + hint(1)
207 warning_rows + 12
208 } else {
209 let num_creds = form.credentials.len().clamp(1, 8) as u16;
210 // type(1) + name(2) + spacer(1) + creds + spacer(1) + submit(1) + status(1) + hint(1)
211 warning_rows + 1 + 2 + 1 + num_creds + 1 + 1 + 1 + 1
212 };
213 let modal_height = (content_height + 4).min(area.height.saturating_sub(2));
214 let popup_area = centered_rect(modal_width, modal_height, area);
215
216 frame.render_widget(Clear, popup_area);
217
218 let block = Block::default()
219 .title(Span::styled(" Create Provider ", t.heading))
220 .borders(Borders::ALL)
221 .border_style(t.accent)
222 .padding(Padding::new(2, 2, 1, 1));
223
224 let inner = block.inner(popup_area);
225 frame.render_widget(block, popup_area);
226
227 // Build dynamic constraints.
228 let mut constraints: Vec<Constraint> = Vec::new();
229 if has_warning {
230 constraints.push(Constraint::Length(1)); // warning text
231 constraints.push(Constraint::Length(1)); // spacer
232 }
233 constraints.push(Constraint::Length(1)); // type label
234 constraints.push(Constraint::Length(2)); // name field
235 constraints.push(Constraint::Length(1)); // spacer
236 if form.is_generic {
237 constraints.push(Constraint::Length(2)); // env var name
238 constraints.push(Constraint::Length(2)); // value
239 } else {
240 #[allow(clippy::cast_possible_truncation)]
241 let num_creds = form.credentials.len().clamp(1, 8) as u16;
242 constraints.push(Constraint::Length(num_creds)); // credential rows
243 }
244 constraints.push(Constraint::Length(1)); // spacer
245 constraints.push(Constraint::Length(1)); // submit
246 constraints.push(Constraint::Length(1)); // status
247 constraints.push(Constraint::Length(1)); // hint
248 constraints.push(Constraint::Min(0));
249

Callers 1

drawFunction · 0.85

Calls 7

centered_rectFunction · 0.85
draw_text_fieldFunction · 0.85
draw_secret_fieldFunction · 0.85
mask_input_valueFunction · 0.85
lenMethod · 0.80
pushMethod · 0.80
is_emptyMethod · 0.45

Tested by

no test coverage detected