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

Code before:
            .os_input
            .as_mut()
            .unwrap()
            .spawn_terminal(terminal_action, quit_cb, self.default_editor.clone())?;
        let terminal_bytes = task::spawn({
            let senders = self.bus.senders.clone();
            let os_input = self.bus.os_input.as_ref().unwrap().clone();
            let debug_to_file = self.debug_to_file;
            async move {
                TerminalBytes::new(pid_primary, senders, os_input, debug_to_file, terminal_id)
                    .listen()
                    .await;
            }
        });

        self.task_handles.insert(terminal_id, terminal_bytes);
        self.id_to_child_pid.insert(terminal_id, child_fd);
        Ok(terminal_id)
    }
    pub fn spawn_terminals_for_layout(
        &mut self,
        layout: PaneLayout,
        default_shell: Option<TerminalAction>,
        client_id: ClientId,
    ) -> Result<()> {
        let err_context = || format!("fail to spawn terminals layout for client {client_id}");
        let mut default_shell = default_shell.unwrap_or_else(|| self.get_default_terminal(None));
        self.fill_cwd(&mut default_shell, client_id);
        let extracted_run_instructions = layout.extract_run_instructions();
        let mut new_pane_pids: Vec<(u32, Option<RunCommand>, Result<RawFd, SpawnTerminalError>)> =
            vec![]; // (terminal_id,
                    // run_command
                    // file_descriptor)
        for run_instruction in extracted_run_instructions {
            let quit_cb = Box::new({
                let senders = self.bus.senders.clone();
                move |pane_id, _exit_status, _command| {
                    let _ = senders.send_to_screen(ScreenInstruction::ClosePane(pane_id, None));
                }
            });
            match run_instruction {
                Some(Run::Command(command)) => {
                    let hold_on_close = command.hold_on_close;
                    let quit_cb = Box::new({
                        let senders = self.bus.senders.clone();
                        move |pane_id, exit_status, command| {
                            if hold_on_close {
                                let _ = senders.send_to_screen(ScreenInstruction::HoldPane(
                                    pane_id,
                                    exit_status,
                                    command,

Review comment (bug):
Sorry, this is picky, but I think we should be consistent with the error phrasing

```suggestion
        let err_context = || format!("failed to spawn terminals for layout for client {client_id}");
```

Code after:
        });
        let (terminal_id, pid_primary, child_fd): (u32, RawFd, RawFd) = self
            .bus
            .os_input
            .as_mut()
            .unwrap()
            .spawn_terminal(terminal_action, quit_cb, self.default_editor.clone())?;
        let terminal_bytes = task::spawn({
            let err_context = || format!("failed to run async task for terminal {terminal_id}");
            let senders = self.bus.senders.clone();
            let os_input = self
                .bus
                .os_input
                .as_ref()
                .with_context(err_context)
                .fatal()
                .clone();
            let debug_to_file = self.debug_to_file;
            async move {
                TerminalBytes::new(pid_primary, senders, os_input, debug_to_file, terminal_id)
                    .listen()
                    .await;
            }
        });

        self.task_handles.insert(terminal_id, terminal_bytes);
        self.id_to_child_pid.insert(terminal_id, child_fd);
        Ok(terminal_id)
    }
    pub fn spawn_terminals_for_layout(
        &mut self,
        layout: PaneLayout,
        default_shell: Option<TerminalAction>,
        client_id: ClientId,
    ) -> Result<()> {
        let err_context = || format!("failed to spawn terminals for layout for client {client_id}");
        let mut default_shell = default_shell.unwrap_or_else(|| self.get_default_terminal(None));
        self.fill_cwd(&mut default_shell, client_id);
        let extracted_run_instructions = layout.extract_run_instructions();
        let mut new_pane_pids: Vec<(u32, Option<RunCommand>, Result<RawFd, SpawnTerminalError>)> =
            vec![]; // (terminal_id,
                    // run_command
                    // file_descriptor)
        for run_instruction in extracted_run_instructions {
            let quit_cb = Box::new({
                let senders = self.bus.senders.clone();
                move |pane_id, _exit_status, _command| {
                    let _ = senders.send_to_screen(ScreenInstruction::ClosePane(pane_id, None));
                }
            });
            match run_instruction {