Repository: zellij-org/zellij
File: zellij-server/src/pty.rs (Rust)

Code before:
            task_handles: HashMap::new(),
        }
    }
    pub fn spawn_terminal(&mut self, terminal_action: Option<TerminalAction>) -> RawFd {
        let (pid_primary, pid_secondary): (RawFd, Pid) = self
            .bus
            .os_input
            .as_mut()
            .unwrap()
            .spawn_terminal(terminal_action);
        let task_handle = stream_terminal_bytes(
            pid_primary,
            self.bus.senders.clone(),
            self.bus.os_input.as_ref().unwrap().clone(),
            self.debug_to_file,
        );
        self.task_handles.insert(pid_primary, task_handle);
        self.id_to_child_pid.insert(pid_primary, pid_secondary);
        pid_primary
    }
    pub fn spawn_terminals_for_layout(
        &mut self,
        layout: Layout,
        default_shell: Option<TerminalAction>,
    ) {
        let total_runnables = layout.total_runnables();
        let mut new_pane_pids = vec![];
        for runnable in total_runnables {
            match runnable {
                Some(Run::Command(command)) => {
                    let cmd = TerminalAction::RunCommand(command);
                    let (pid_primary, pid_secondary): (RawFd, Pid) = self
                        .bus
                        .os_input
                        .as_mut()
                        .unwrap()
                        .spawn_terminal(Some(cmd));
                    self.id_to_child_pid.insert(pid_primary, pid_secondary);
                    new_pane_pids.push(pid_primary);
                }
                None => {
                    let (pid_primary, pid_secondary): (RawFd, Pid) = self
                        .bus
                        .os_input
                        .as_mut()
                        .unwrap()
                        .spawn_terminal(default_shell.clone());
                    self.id_to_child_pid.insert(pid_primary, pid_secondary);
                    new_pane_pids.push(pid_primary);
                }
                // Investigate moving plugin loading to here.

Review comment (refactor):
I think calling this method "total_runnables" is a little confusing. "total" implies we're talking about an amount, and here we're getting back a run instruction... maybe we can call it `extract_run_instructions` and then in the loop call the singular version `run_instruction`? What do you think?

Code after:
            task_handles: HashMap::new(),
        }
    }
    pub fn spawn_terminal(&mut self, terminal_action: Option<TerminalAction>) -> RawFd {
        let (pid_primary, pid_secondary): (RawFd, Pid) = self
            .bus
            .os_input
            .as_mut()
            .unwrap()
            .spawn_terminal(terminal_action);
        let task_handle = stream_terminal_bytes(
            pid_primary,
            self.bus.senders.clone(),
            self.bus.os_input.as_ref().unwrap().clone(),
            self.debug_to_file,
        );
        self.task_handles.insert(pid_primary, task_handle);
        self.id_to_child_pid.insert(pid_primary, pid_secondary);
        pid_primary
    }
    pub fn spawn_terminals_for_layout(
        &mut self,
        layout: Layout,
        default_shell: Option<TerminalAction>,
    ) {
        let extracted_run_instructions = layout.extract_run_instructions();
        let mut new_pane_pids = vec![];
        for run_instruction in extracted_run_instructions {
            match run_instruction {
                Some(Run::Command(command)) => {
                    let cmd = TerminalAction::RunCommand(command);
                    let (pid_primary, pid_secondary): (RawFd, Pid) = self
                        .bus
                        .os_input
                        .as_mut()
                        .unwrap()
                        .spawn_terminal(Some(cmd));
                    self.id_to_child_pid.insert(pid_primary, pid_secondary);
                    new_pane_pids.push(pid_primary);
                }
                None => {
                    let (pid_primary, pid_secondary): (RawFd, Pid) = self
                        .bus
                        .os_input
                        .as_mut()
                        .unwrap()
                        .spawn_terminal(default_shell.clone());
                    self.id_to_child_pid.insert(pid_primary, pid_secondary);
                    new_pane_pids.push(pid_primary);
                }
                // Investigate moving plugin loading to here.