diff options
| author | Aram Drevekenin <aram@poor.dev> | 2026-02-17 15:43:28 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-02-17 15:43:28 +0100 |
| commit | 4e66a0beff5e41bda1dbde521fa1d2858c46fe7b (patch) | |
| tree | 380bee5eeac56bea2ebf341cccbe69615585e394 /default-plugins/sequence/src/state/execution.rs | |
| parent | Fix startup message and cache file creation (#4705) (diff) | |
| download | sl0ppij-4e66a0beff5e41bda1dbde521fa1d2858c46fe7b.tar.gz sl0ppij-4e66a0beff5e41bda1dbde521fa1d2858c46fe7b.tar.xz sl0ppij-4e66a0beff5e41bda1dbde521fa1d2858c46fe7b.zip | |
Revamp the sequence plugin (#4713)
* initial pipe interface
* initial open_x_pane_in_new_tab plugin api implementation
* fix: send CommandPaneExited for command panes opened as initial_terminals in new tabs from plugins
* open panes in place of specific pane id plugin commands - initial implementation
* sequence and plugin api ux
* focus self when starting
* combine ui and pipe paths
* highlight selected pane
* initial sequence removal of editing capabilities
* fix: translate plugin paths in api
* properly trim commands when loaded from pipe or pasted text
* minor ux fixes
* get ctrl c to work properly
* behavior fixes
* more ui fixes
* fix tests
* close tab and end sequence properly
* default to AND
* zellij sequence alias
* add alias
* consolidate paths
* rustfmt
* fix ui padding
* add pr
* fix: reset scrolling when resetting terminal state
Diffstat (limited to 'default-plugins/sequence/src/state/execution.rs')
| -rw-r--r-- | default-plugins/sequence/src/state/execution.rs | 185 |
1 files changed, 3 insertions, 182 deletions
diff --git a/default-plugins/sequence/src/state/execution.rs b/default-plugins/sequence/src/state/execution.rs index fb194f61..42d4112a 100644 --- a/default-plugins/sequence/src/state/execution.rs +++ b/default-plugins/sequence/src/state/execution.rs @@ -1,16 +1,13 @@ use crate::path_formatting::format_cwd; -use crate::state::{ChainType, CommandEntry, CommandStatus}; -use std::collections::BTreeMap; +use crate::state::{CommandEntry, CommandStatus}; use std::path::PathBuf; -use std::time::Duration; use zellij_tile::prelude::*; pub struct Execution { pub all_commands: Vec<CommandEntry>, pub current_running_command_index: usize, pub is_running: bool, - pub sequence_id: u64, - pub primary_pane_id_before_sequence: Option<PaneId>, + pub displayed_pane_id: Option<PaneId>, } impl Execution { @@ -19,8 +16,7 @@ impl Execution { all_commands: vec![CommandEntry::default()], current_running_command_index: 0, is_running: false, - sequence_id: 0, - primary_pane_id_before_sequence: None, + displayed_pane_id: None, } } @@ -82,181 +78,6 @@ impl Execution { copy_to_clipboard(text_to_copy); } } - - pub fn update_pane_id_for_command(&mut self, pane_id: PaneId, command_text: &str) { - for command in self.all_commands.iter_mut() { - if let CommandStatus::Pending | CommandStatus::Running(None) = command.get_status() { - let cmd_text = command.get_text(); - if cmd_text == command_text { - command.set_status(CommandStatus::Running(Some(pane_id))); - break; - } - } - } - } - - pub fn update_exited_command_statuses(&mut self, pane_manifest: &PaneManifest) -> bool { - let mut updated = false; - for command in self.all_commands.iter_mut() { - let status = command.get_status(); - let pane_id_opt = match &status { - CommandStatus::Running(pid) => *pid, - CommandStatus::Exited(_, pid) => *pid, - CommandStatus::Interrupted(pid) => *pid, - _ => None, - }; - - if let Some(pane_id) = pane_id_opt { - let mut pane_found = false; - for (_tab_index, panes) in &pane_manifest.panes { - for pane_info in panes { - let pane_matches = match pane_id { - PaneId::Terminal(id) => !pane_info.is_plugin && pane_info.id == id, - PaneId::Plugin(id) => pane_info.is_plugin && pane_info.id == id, - }; - - if pane_matches { - pane_found = true; - if pane_info.exited { - command.set_status(CommandStatus::Exited( - pane_info.exit_status, - Some(pane_id), - )); - updated = true; - } - break; - } - } - if pane_found { - break; - } - } - - if !pane_found && command.start_time.elapsed() > Duration::from_millis(400) { - match command.get_status() { - CommandStatus::Running(_) => { - eprintln!( - "Pane {:?} was closed while running, setting pane_id to None", - pane_id - ); - command.set_status(CommandStatus::Running(None)); - updated = true; - }, - CommandStatus::Exited(exit_code, _) => { - eprintln!( - "Pane {:?} was closed after exiting, setting pane_id to None", - pane_id - ); - command.set_status(CommandStatus::Exited(exit_code, None)); - updated = true; - }, - CommandStatus::Interrupted(_) => { - eprintln!("Pane {:?} was closed after being interrupted, setting pane_id to None", pane_id); - command.set_status(CommandStatus::Interrupted(None)); - updated = true; - }, - _ => {}, - } - } - } - } - updated - } - - pub fn update_sequence_stopped_state(&mut self) -> bool { - let mut needs_rerender = false; - if self.is_running { - let current_idx = self.current_running_command_index; - if let Some(command) = self.all_commands.get_mut(current_idx) { - if let CommandStatus::Exited(exit_code, _) = command.get_status() { - let should_stop; - if current_idx >= self.all_commands.len().saturating_sub(1) { - should_stop = true; - } else { - if let Some(chain_type) = &self - .all_commands - .get(current_idx) - .map(|c| c.get_chain_type()) - { - match chain_type { - ChainType::And => { - should_stop = exit_code.unwrap_or(0) != 0; - }, - ChainType::Or => { - should_stop = exit_code.unwrap_or(0) == 0; - }, - ChainType::Then => { - should_stop = false; - }, - ChainType::None => { - should_stop = true; - }, - } - } else { - should_stop = true; - } - }; - if should_stop { - self.is_running = false; - } - } - } - needs_rerender = true; - } - needs_rerender - } - - pub fn execute_command_sequence( - &mut self, - shell: &Option<PathBuf>, - global_cwd: &Option<PathBuf>, - primary_pane_id: Option<PaneId>, - ) { - use zellij_tile::prelude::actions::{Action, RunCommandAction}; - - self.all_commands.retain(|c| !c.is_empty()); - - let Some(first_active_sequence_command) = self.get_first_command() else { - return; - }; - - let shell = shell.clone().unwrap_or_else(|| PathBuf::from("/bin/bash")); - - let first_command = first_active_sequence_command.get_text(); - let first_chain_type = first_active_sequence_command.get_chain_type(); - let command_cwd = first_active_sequence_command - .get_cwd() - .or_else(|| global_cwd.clone()); - - let command = RunCommandAction { - command: shell.clone(), - args: vec!["-ic".to_string(), first_command.trim().to_string()], - cwd: command_cwd, - hold_on_close: true, - ..Default::default() - }; - - let placement = NewPanePlacement::InPlace { - pane_id_to_replace: primary_pane_id, - close_replaced_pane: false, - borderless: Some(false), - }; - - let action = Action::NewBlockingPane { - placement, - command: Some(command), - pane_name: Some(first_command.trim().to_string()), - unblock_condition: first_chain_type.to_unblock_condition(), - near_current_pane: true, - }; - - self.sequence_id += 1; - - let mut context = BTreeMap::new(); - context.insert("sequence_id".to_string(), self.sequence_id.to_string()); - run_action(action, context); - self.set_command_status(0, CommandStatus::Running(None)); - } } impl Default for Execution { |
