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

Code before:
                match runnable {
                    // A plugin pane
                    Run::Plugin(Some(plugin)) => {
                        let (pid_tx, pid_rx) = channel();
                        self.senders
                            .send_to_plugin(PluginInstruction::Load(pid_tx, plugin.clone()))
                            .unwrap();
                        let pid = pid_rx.recv().unwrap();
                        let new_plugin = PluginPane::new(
                            pid,
                            *position_and_size,
                            self.senders.to_plugin.as_ref().unwrap().clone(),
                        );
                        self.panes.insert(PaneId::Plugin(pid), Box::new(new_plugin));
                        // Send an initial mode update to the newly loaded plugin only!
                        self.senders
                            .send_to_plugin(PluginInstruction::Update(
                                Some(pid),
                                Event::ModeUpdate(self.mode_info.clone()),
                            ))
                            .unwrap();
                    }
                    // A command pane
                    Run::Command(command) => {
                        let cmd = TerminalAction::RunCommand(command.clone());
                        self.senders
                            .send_to_pty(PtyInstruction::SpawnTerminal(Some(cmd)))
                            .unwrap();

                        // I would expect something like this to work,
                        // but I must still be overlooking something.
                        //let (_, pid) = self.os_api.spawn_terminal(Some(cmd));
                        //let new_terminal = TerminalPane::new(pid.into(), *position_and_size, self.colors);
                        //self.os_api.set_terminal_size_using_fd(
                        //new_terminal.pid,
                        //new_terminal.columns() as u16,
                        //new_terminal.rows() as u16,
                        //);
                        //self.panes
                        //.insert(PaneId::Terminal(pid.into()), Box::new(new_terminal));
                    }
                    Run::Plugin(None) => {}
                }
            } else {
                // there are still panes left to fill, use the pids we received in this method
                let pid = new_pids.next().unwrap(); // if this crashes it means we got less pids than there are panes in this layout
                let new_terminal = TerminalPane::new(*pid, *position_and_size, self.colors);
                self.os_api.set_terminal_size_using_fd(
                    new_terminal.pid,
                    new_terminal.columns() as u16,
                    new_terminal.rows() as u16,

Review comment (suggestion):
This is for current testing and most likely not the way to go.
If I understand correctly we need the `pid`, which the `ScreenInstruction` doesn't
provide to us.

Code after:
                let (pid_tx, pid_rx) = channel();
                self.senders
                    .send_to_plugin(PluginInstruction::Load(pid_tx, plugin.clone()))
                    .unwrap();
                let pid = pid_rx.recv().unwrap();
                let new_plugin = PluginPane::new(
                    pid,
                    *position_and_size,
                    self.senders.to_plugin.as_ref().unwrap().clone(),
                );
                self.panes.insert(PaneId::Plugin(pid), Box::new(new_plugin));
                // Send an initial mode update to the newly loaded plugin only!
                self.senders
                    .send_to_plugin(PluginInstruction::Update(
                        Some(pid),
                        Event::ModeUpdate(self.mode_info.clone()),
                    ))
                    .unwrap();
            } else {
                // there are still panes left to fill, use the pids we received in this method
                let pid = new_pids.next().unwrap(); // if this crashes it means we got less pids than there are panes in this layout
                let new_terminal = TerminalPane::new(*pid, *position_and_size, self.colors);
                self.os_api.set_terminal_size_using_fd(
                    new_terminal.pid,
                    new_terminal.columns() as u16,
                    new_terminal.rows() as u16,
                );
                self.panes
                    .insert(PaneId::Terminal(*pid), Box::new(new_terminal));
            }
        }
        for unused_pid in new_pids {
            // this is a bit of a hack and happens because we don't have any central location that
            // can query the screen as to how many panes it needs to create a layout
            // fixing this will require a bit of an architecture change
            self.senders
                .send_to_pty(PtyInstruction::ClosePane(PaneId::Terminal(*unused_pid)))
                .unwrap();
        }
        self.active_terminal = self.panes.iter().map(|(id, _)| id.to_owned()).next();
        self.render();
    }
    pub fn new_pane(&mut self, pid: PaneId) {
        self.close_down_to_max_terminals();
        if self.fullscreen_is_active {
            self.toggle_active_pane_fullscreen();
        }
        if !self.has_panes() {
            if let PaneId::Terminal(term_pid) = pid {
                let new_terminal = TerminalPane::new(term_pid, self.full_screen_ws, self.colors);
                self.os_api.set_terminal_size_using_fd(