MCPcopy Create free account
hub / github.com/ankddev/envfetch / render

Function render

src/interactive/view.rs:8–152  ·  view source on GitHub ↗
(state: &AppState, f: &mut Frame)

Source from the content-addressed store, hash-verified

6use ratatui::widgets::{Block, BorderType, Borders, List, ListItem, ListState, Paragraph, Wrap};
7
8pub fn render(state: &AppState, f: &mut Frame) {
9 let size = f.area();
10 // Divide the screen: main area and footer.
11 let chunks = Layout::default()
12 .direction(Direction::Vertical)
13 .constraints([Constraint::Min(5), Constraint::Length(3)].as_ref())
14 .split(size);
15
16 match &state.mode {
17 Mode::List => {
18 let items: Vec<ListItem> = state
19 .entries
20 .iter()
21 .enumerate()
22 .map(|(i, (k, v))| {
23 let marker = if i == state.current_index { "> " } else { " " };
24 let key_field = format!("{:30}", k);
25 let content = format!("{}{} {}", marker, key_field, v);
26 let style = if i == state.current_index {
27 Style::default()
28 .fg(Color::Green)
29 .add_modifier(Modifier::BOLD)
30 } else {
31 Style::default().fg(Color::White)
32 };
33 ListItem::new(Line::from(Span::styled(content, style)))
34 })
35 .collect();
36
37 let list = List::new(items).block(
38 Block::default()
39 .borders(Borders::ALL)
40 .border_type(BorderType::Rounded)
41 .border_style(Style::default().fg(Color::Blue))
42 .title("Variables"),
43 );
44 let mut list_state = ListState::default();
45 list_state.select(Some(state.current_index));
46 f.render_stateful_widget(list, chunks[0], &mut list_state);
47 }
48 Mode::Add => {
49 let modal = Paragraph::new(vec![
50 Line::from(Span::styled(
51 "Add New Variable",
52 Style::default()
53 .fg(Color::Yellow)
54 .add_modifier(Modifier::BOLD),
55 )),
56 Line::from(format!("Key: {}", state.input_key)),
57 Line::from(format!("Value: {}", state.input_value)),
58 Line::from("Enter=confirm, Esc=cancel, Tab=switch field, ←/→ move cursor"),
59 ])
60 .block(
61 Block::default()
62 .borders(Borders::ALL)
63 .border_type(BorderType::Rounded)
64 .border_style(Style::default().fg(Color::Blue))
65 .title("Add"),

Callers 7

runMethod · 0.85
test_draw_list_modeFunction · 0.85
test_draw_add_modeFunction · 0.85
test_draw_edit_modeFunction · 0.85
test_draw_delete_modeFunction · 0.85
test_draw_messageFunction · 0.85
test_draw_scrollingFunction · 0.85

Calls 1

centered_rectFunction · 0.85

Tested by 6

test_draw_list_modeFunction · 0.68
test_draw_add_modeFunction · 0.68
test_draw_edit_modeFunction · 0.68
test_draw_delete_modeFunction · 0.68
test_draw_messageFunction · 0.68
test_draw_scrollingFunction · 0.68