added optional confirm message

This commit is contained in:
Uber Veng
2026-03-14 03:27:43 +07:00
parent f958e704f6
commit 533df4a476
4 changed files with 58 additions and 22 deletions

View File

@@ -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<String>,
},
ExecutingBashTerminal { child: tokio::process::Child },
ExecutingStructured {
reply_tx: tokio::sync::mpsc::UnboundedSender<String>,
@@ -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,
}
}
}