Added checkboxes & radio buttons; Updated uninstall script

This commit is contained in:
Uber Veng
2026-05-22 19:04:52 +07:00
parent ab4ad186e6
commit 6a79fb2c54
8 changed files with 296 additions and 56 deletions

View File

@@ -1,4 +1,4 @@
pub mod structured;
pub use structured::{StructuredCommand, MessageLevel};
pub use structured::{StructuredCommand, MessageLevel, FormField, FormFieldType};
// Здесь могут быть функции для download, http и т.д.

View File

@@ -31,15 +31,34 @@ pub enum StructuredCommand {
percent: u8,
message: Option<String>,
},
/// A list of checkboxes and radio buttons.
/// Response: space-separated IDs of all checked/selected fields.
Form {
prompt: String,
fields: Vec<FormField>,
},
/// Run an interactive program that needs the real terminal.
/// The client suspends ratatui, inherits stdin/stdout/stderr, waits for
/// the process to exit, then restores the TUI.
/// The script receives the exit code as the response.
Exec {
shell: String,
},
}
#[derive(Debug, Clone, PartialEq)]
pub enum FormFieldType {
Checkbox,
Radio,
}
#[derive(Debug, Clone)]
pub struct FormField {
pub id: String,
pub label: String,
pub field_type: FormFieldType,
pub default: bool,
/// Radio buttons with the same group are mutually exclusive.
pub group: Option<String>,
}
#[derive(Debug)]
pub struct MenuOption {
pub id: String,
@@ -203,6 +222,25 @@ fn parse_command(json_str: &str, cmd_tx: UnboundedSender<StructuredCommand>) ->
let message = v["message"].as_str().map(String::from);
StructuredCommand::Progress { percent, message }
}
"form" => {
let prompt = v["prompt"].as_str().unwrap_or("").to_string();
let fields = v["fields"].as_array()
.map(|arr| {
arr.iter().filter_map(|f| {
let id = f["id"].as_str()?.to_string();
let label = f["label"].as_str()?.to_string();
let field_type = match f["field_type"].as_str().unwrap_or("checkbox") {
"radio" => FormFieldType::Radio,
_ => FormFieldType::Checkbox,
};
let default = f["default"].as_bool().unwrap_or(false);
let group = f["group"].as_str().map(String::from);
Some(FormField { id, label, field_type, default, group })
}).collect()
})
.unwrap_or_default();
StructuredCommand::Form { prompt, fields }
}
"exec" => {
let shell = v["shell"].as_str().unwrap_or("").to_string();
StructuredCommand::Exec { shell }