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

Function draw_text_field

crates/openshell-tui/src/ui/mod.rs:585–634  ·  view source on GitHub ↗
(
    frame: &mut Frame<'_>,
    label: &str,
    value: &str,
    placeholder: &str,
    focused: bool,
    area: Rect,
    theme: &Theme,
    cursor: &str,
    show_gap: bool,
)

Source from the content-addressed store, hash-verified

583/// `show_gap` appends an extra blank row below the input line.
584#[allow(clippy::too_many_arguments)]
585fn draw_text_field(
586 frame: &mut Frame<'_>,
587 label: &str,
588 value: &str,
589 placeholder: &str,
590 focused: bool,
591 area: Rect,
592 theme: &Theme,
593 cursor: &str,
594 show_gap: bool,
595) {
596 let t = theme;
597 let chunks = if show_gap {
598 Layout::default()
599 .direction(Direction::Vertical)
600 .constraints([
601 Constraint::Length(1), // label
602 Constraint::Length(1), // input
603 Constraint::Length(1), // gap
604 ])
605 .split(area)
606 } else {
607 Layout::default()
608 .direction(Direction::Vertical)
609 .constraints([
610 Constraint::Length(1), // label
611 Constraint::Length(1), // input
612 ])
613 .split(area)
614 };
615
616 let label_style = if focused { t.accent_bold } else { t.text };
617 let mut label_spans = vec![Span::styled(format!("{label}:"), label_style)];
618 if !placeholder.is_empty() {
619 label_spans.push(Span::styled(format!(" {placeholder}"), t.muted));
620 }
621 frame.render_widget(Paragraph::new(Line::from(label_spans)), chunks[0]);
622
623 let display = if value.is_empty() && !focused {
624 Line::from(Span::styled(" -", t.muted))
625 } else if focused {
626 Line::from(vec![
627 Span::styled(format!(" {value}"), t.accent),
628 Span::styled(cursor, t.accent),
629 ])
630 } else {
631 Line::from(Span::styled(format!(" {value}"), t.text))
632 };
633 frame.render_widget(Paragraph::new(display), chunks[1]);
634}
635
636/// Render a bordered confirmation popup centred on `area`.
637///

Callers 2

draw_formFunction · 0.85
draw_enter_keyFunction · 0.85

Calls 2

pushMethod · 0.80
is_emptyMethod · 0.45

Tested by

no test coverage detected