diff --git a/.gitignore b/.gitignore index ea8c4bf..b5c2428 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /target +*txt diff --git a/src/app.rs b/src/app.rs index a38318f..7945dd6 100644 --- a/src/app.rs +++ b/src/app.rs @@ -35,7 +35,11 @@ pub struct App { } pub enum Popup { - Confirming { action: Action, item_title: String }, + Confirming { + action: Action, + item_title: String, + confirm_message: Option, + }, ExecutingBashTerminal { child: tokio::process::Child }, ExecutingStructured { reply_tx: tokio::sync::mpsc::UnboundedSender, @@ -153,7 +157,8 @@ impl App { // Если есть popup, передаём ему if let Some(popup) = &mut self.popup { match popup { - Popup::Confirming { action, item_title } => { + Popup::Confirming { action, item_title: _, confirm_message: _ } => { + // confirm_message можно не использовать здесь, но нужно изменить паттерн match key.code { KeyCode::Char('y') | KeyCode::Char('Y') => { let action = action.clone(); @@ -264,11 +269,12 @@ impl App { } } MenuItemKind::Action { action } => { - // Если требуется подтверждение if action.confirm() { + let confirm_message = action.confirm_message(); // забираем до перемещения self.popup = Some(Popup::Confirming { - action, + action, // перемещаем item_title: item.title, + confirm_message, }); } else { self.run_action(action).await?; @@ -284,6 +290,7 @@ impl App { script, interaction, confirm: _, + confirm_message: _, } => match interaction { InteractionMode::Terminal => { // Запуск в PTY (упрощённо) @@ -298,6 +305,7 @@ impl App { filename: _, target_dir: _, confirm: _, + confirm_message: _, } => { // Заглушка self.popup = Some(Popup::Message { @@ -363,14 +371,3 @@ impl App { Ok(()) } } - -impl Action { - fn confirm(&self) -> bool { - match self { - Action::Bash { confirm, .. } => *confirm, - Action::Download { confirm, .. } => *confirm, - Action::DownloadAndRun { confirm, .. } => *confirm, - Action::HttpRequest { confirm, .. } => *confirm, - } - } -} diff --git a/src/menu.rs b/src/menu.rs index 84bb073..e6b5a83 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -32,6 +32,8 @@ pub enum Action { interaction: InteractionMode, #[serde(default)] confirm: bool, + #[serde(default)] + confirm_message: Option, }, Download { url: String, @@ -39,6 +41,8 @@ pub enum Action { target_dir: Option, #[serde(default)] confirm: bool, + #[serde(default)] + confirm_message: Option, }, DownloadAndRun { url: String, @@ -48,14 +52,18 @@ pub enum Action { keep_file: bool, #[serde(default)] confirm: bool, + #[serde(default)] + confirm_message: Option, }, HttpRequest { method: HttpMethod, url: String, - headers: std::collections::HashMap, + headers: HashMap, body: Option, #[serde(default)] confirm: bool, + #[serde(default)] + confirm_message: Option, }, } @@ -78,3 +86,25 @@ pub enum HttpMethod { Put, Delete, } + +impl Action { + // Уже существующий метод confirm + pub fn confirm(&self) -> bool { + match self { + Action::Bash { confirm, .. } => *confirm, + Action::Download { confirm, .. } => *confirm, + Action::DownloadAndRun { confirm, .. } => *confirm, + Action::HttpRequest { confirm, .. } => *confirm, + } + } + + // Добавляем новый метод + pub fn confirm_message(&self) -> Option { + match self { + Action::Bash { confirm_message, .. } => confirm_message.clone(), + Action::Download { confirm_message, .. } => confirm_message.clone(), + Action::DownloadAndRun { confirm_message, .. } => confirm_message.clone(), + Action::HttpRequest { confirm_message, .. } => confirm_message.clone(), + } + } +} diff --git a/src/ui.rs b/src/ui.rs index 7ae8169..b15b8cf 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -70,13 +70,21 @@ fn render_popup(f: &mut Frame, popup: &mut Popup) { f.render_widget(Clear, popup_area); match popup { - Popup::Confirming { action: _, item_title } => { + Popup::Confirming { action: _, item_title, confirm_message } => { let block = Block::default().borders(Borders::ALL).title("Подтверждение"); - let text = vec![ - Line::from(format!("Запустить '{}'?", item_title)), - Line::from(""), - Line::from("Нажмите Y для подтверждения, N для отмены"), - ]; + let text = if let Some(msg) = confirm_message { + vec![ + Line::from(msg.as_str()), + Line::from(""), + Line::from("Нажмите Y для подтверждения, N для отмены"), + ] + } else { + vec![ + Line::from(format!("Запустить '{}'?", item_title)), + Line::from(""), + Line::from("Нажмите Y для подтверждения, N для отмены"), + ] + }; let paragraph = Paragraph::new(text) .block(block) .alignment(Alignment::Center)