added optional confirm message
This commit is contained in:
27
src/app.rs
27
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<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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user