diff --git a/src/running_command.rs b/src/running_command.rs index c2e391023..e3d3acda3 100644 --- a/src/running_command.rs +++ b/src/running_command.rs @@ -135,12 +135,12 @@ impl RunningCommand { let mut script = String::new(); for command in commands { match command { - Command::Raw(prompt) => script.push_str(&format!("{}\\\n", prompt)), + Command::Raw(prompt) => script.push_str(&format!("{}\\\n", prompt)), // Merge commands Command::LocalFile(file) => { if let Some(parent) = file.parent() { script.push_str(&format!("cd {}\n", parent.display())); } - script.push_str(&format!("{} {}\n", "bash", file.display())); + script.push_str(&format!("{} {}\n", "sh", file.display())); // Get the file path for sourcing common-script } Command::None => panic!("Command::None was treated as a command"), } @@ -166,7 +166,7 @@ impl RunningCommand { child.wait().unwrap() }); - let mut reader = pair.master.try_clone_reader().unwrap(); // This is a reader, this is where we + let mut reader = pair.master.try_clone_reader().unwrap(); // A buffer, shared between the thread that reads the command output, and the main tread. // The main thread only reads the contents diff --git a/src/state.rs b/src/state.rs index d4129c3ac..324d94b1f 100644 --- a/src/state.rs +++ b/src/state.rs @@ -33,7 +33,8 @@ pub struct AppState { /// widget selection: ListState, filter: Filter, - selected_commands: Vec, // Add this field to store selected commands + multi_select: bool, // This keeps track of Multi select toggle + selected_commands: Vec, // This field is to store selected commands } pub enum Focus { @@ -61,6 +62,7 @@ impl AppState { visit_stack: vec![root_id], selection: ListState::default().with_selected(Some(0)), filter: Filter::new(), + multi_select: false, selected_commands: Vec::new(), // Initialize with an empty vector }; state.update_items(); @@ -122,8 +124,8 @@ impl AppState { |ListEntry { node, has_children, .. }| { - let is_selected = self.selected_commands.contains(&node.command); - let indicator = if is_selected { "*" } else { "" }; + let is_selected = self.selected_commands.contains(&node.command); // Add * if multi-selection is enabled + let indicator = if is_selected { "*" } else { "" }; if *has_children { Line::from(format!( "{} {} {}", @@ -154,7 +156,12 @@ impl AppState { .block( Block::default() .borders(Borders::ALL) - .title(format!("Linux Toolbox - {}", env!("BUILD_DATE"))), + .title(format!( + "Linux Toolbox - {} {}", + env!("BUILD_DATE"), + if self.multi_select { "[Multi-Select]" } else { "" } + ) + ), ) .scroll_padding(1); frame.render_stateful_widget(list, chunks[1], &mut self.selection); @@ -198,7 +205,6 @@ impl AppState { Focus::List if key.kind != KeyEventKind::Release => match key.code { KeyCode::Char('j') | KeyCode::Down => self.selection.select_next(), KeyCode::Char('k') | KeyCode::Up => self.selection.select_previous(), - KeyCode::Char(' ') => self.toggle_selection(), // Add space key to toggle selection KeyCode::Char('p') => self.enable_preview(), KeyCode::Enter | KeyCode::Char('l') | KeyCode::Right => self.handle_enter(), KeyCode::Char('h') | KeyCode::Left => { @@ -212,6 +218,9 @@ impl AppState { KeyCode::Tab => self.focus = Focus::TabList, KeyCode::Char('t') => self.theme.next(), KeyCode::Char('T') => self.theme.prev(), + KeyCode::Char('v') => self.toggle_multi_select(), + KeyCode::Char(' ') if self.multi_select => self.toggle_selection(), // Add space key to toggle selection + _ => {} }, _ => {} @@ -219,6 +228,13 @@ impl AppState { true } + fn toggle_multi_select(&mut self) { + self.multi_select = !self.multi_select; + if !self.multi_select { + self.selected_commands.clear(); + } + } + fn toggle_selection(&mut self) { if let Some(command) = self.get_selected_command(false) { if self.selected_commands.contains(&command) {