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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
32
src/menu.rs
32
src/menu.rs
@@ -32,6 +32,8 @@ pub enum Action {
|
||||
interaction: InteractionMode,
|
||||
#[serde(default)]
|
||||
confirm: bool,
|
||||
#[serde(default)]
|
||||
confirm_message: Option<String>,
|
||||
},
|
||||
Download {
|
||||
url: String,
|
||||
@@ -39,6 +41,8 @@ pub enum Action {
|
||||
target_dir: Option<String>,
|
||||
#[serde(default)]
|
||||
confirm: bool,
|
||||
#[serde(default)]
|
||||
confirm_message: Option<String>,
|
||||
},
|
||||
DownloadAndRun {
|
||||
url: String,
|
||||
@@ -48,14 +52,18 @@ pub enum Action {
|
||||
keep_file: bool,
|
||||
#[serde(default)]
|
||||
confirm: bool,
|
||||
#[serde(default)]
|
||||
confirm_message: Option<String>,
|
||||
},
|
||||
HttpRequest {
|
||||
method: HttpMethod,
|
||||
url: String,
|
||||
headers: std::collections::HashMap<String, String>,
|
||||
headers: HashMap<String, String>,
|
||||
body: Option<String>,
|
||||
#[serde(default)]
|
||||
confirm: bool,
|
||||
#[serde(default)]
|
||||
confirm_message: Option<String>,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -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<String> {
|
||||
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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
20
src/ui.rs
20
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)
|
||||
|
||||
Reference in New Issue
Block a user