Added checkboxes & radio buttons; Updated uninstall script
This commit is contained in:
55
src/ui.rs
55
src/ui.rs
@@ -132,6 +132,8 @@ fn render_popup(f: &mut Frame, popup: &mut Popup) {
|
||||
current_command,
|
||||
input_buffer,
|
||||
menu_selected_index,
|
||||
form_cursor,
|
||||
form_values,
|
||||
log_scroll_pos,
|
||||
log_follow_bottom,
|
||||
finished,
|
||||
@@ -140,6 +142,9 @@ fn render_popup(f: &mut Frame, popup: &mut Popup) {
|
||||
Some(executor::StructuredCommand::Menu { options, .. }) => {
|
||||
(options.len() as u16 + 2).min(14)
|
||||
}
|
||||
Some(executor::StructuredCommand::Form { fields, .. }) => {
|
||||
(fields.len() as u16 + 2).min(16)
|
||||
}
|
||||
Some(_) => 5,
|
||||
None => 0,
|
||||
};
|
||||
@@ -229,7 +234,12 @@ fn render_popup(f: &mut Frame, popup: &mut Popup) {
|
||||
// ── Interactive command area ─────────────────────────────────────
|
||||
if cmd_height > 0 {
|
||||
if let Some(cmd) = current_command {
|
||||
render_command(f, cmd, input_buffer, *menu_selected_index, chunks[1]);
|
||||
render_command(
|
||||
f, cmd, input_buffer,
|
||||
*menu_selected_index,
|
||||
*form_cursor, form_values,
|
||||
chunks[1],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -364,6 +374,8 @@ fn render_command(
|
||||
cmd: &executor::StructuredCommand,
|
||||
input_buffer: &str,
|
||||
menu_selected_index: usize,
|
||||
form_cursor: usize,
|
||||
form_values: &[bool],
|
||||
area: Rect,
|
||||
) {
|
||||
match cmd {
|
||||
@@ -492,6 +504,47 @@ fn render_command(
|
||||
f.render_widget(paragraph, area);
|
||||
}
|
||||
|
||||
executor::StructuredCommand::Form { prompt, fields } => {
|
||||
let items: Vec<ListItem> = fields.iter().enumerate().map(|(i, field)| {
|
||||
let checked = form_values.get(i).copied().unwrap_or(false);
|
||||
let icon = match field.field_type {
|
||||
executor::FormFieldType::Checkbox => {
|
||||
if checked { "[✓]" } else { "[ ]" }
|
||||
}
|
||||
executor::FormFieldType::Radio => {
|
||||
if checked { "(●)" } else { "( )" }
|
||||
}
|
||||
};
|
||||
let is_cursor = i == form_cursor;
|
||||
let prefix = if is_cursor { "▶ " } else { " " };
|
||||
let style = if is_cursor {
|
||||
Style::default().bg(Color::Blue).add_modifier(Modifier::BOLD)
|
||||
} else {
|
||||
Style::default()
|
||||
};
|
||||
ListItem::new(Line::from(vec![
|
||||
Span::raw(format!("{}{} {}", prefix, icon, field.label)),
|
||||
])).style(style)
|
||||
}).collect();
|
||||
|
||||
let mut state = ListState::default();
|
||||
state.select(Some(form_cursor));
|
||||
|
||||
let list = List::new(items).block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.title(format!(" {} ", prompt))
|
||||
.title_bottom(
|
||||
Line::from(Span::styled(
|
||||
" Space — переключить Enter/l — применить Esc — отмена ",
|
||||
Style::default().fg(Color::DarkGray),
|
||||
)).alignment(Alignment::Right),
|
||||
)
|
||||
.border_style(Style::default().fg(Color::Cyan)),
|
||||
);
|
||||
f.render_stateful_widget(list, area, &mut state);
|
||||
}
|
||||
|
||||
// Exec is handled by the main loop before rendering; this arm is
|
||||
// never reached in practice but satisfies the exhaustiveness check.
|
||||
executor::StructuredCommand::Exec { shell } => {
|
||||
|
||||
Reference in New Issue
Block a user