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

Code before:
        };

        let backtrace = match info.location() {
            Some(location) => {
                format!(
                    "\nthread '{}' panicked at '{}': {}:{}\n{:?}",
                    thread,
                    msg,
                    location.file(),
                    location.line(),
                    backtrace
                )
            }
            None => {
                format!(
                    "\nthread '{}' panicked at '{}'\n{:?}",
                    thread, msg, backtrace
                )
            }
        };

        if send_app_instructions_clone
            .send(AppInstruction::Error(backtrace.clone()))
            .is_err()
        {
            get_os_input().unset_raw_mode(0);
            println!("{}", backtrace);
        }
    }));

    active_threads.push(
        thread::Builder::new()
            .name("pty".to_string())
            .spawn({
                let mut command_is_executing = command_is_executing.clone();
                move || {
                    if let Some(layout) = maybe_layout {
                        pty_bus.spawn_terminals_for_layout(layout);
                    } else {
                        pty_bus.spawn_terminal_vertically(None);
                    }

                    loop {
                        let event = pty_bus
                            .receive_pty_instructions
                            .recv()
                            .expect("failed to receive event on channel");
                        match event {
                            PtyInstruction::SpawnTerminal(file_to_open) => {
                                pty_bus.spawn_terminal(file_to_open);
                            }

Review comment (suggestion):
I'm not thrilled about this tbh. If I understand correctly, we can't pass os_input here because it doesn't implement `Sync`, just like we had with the app instructions sender, right?

The issue is that while right now calling this factory function doesn't change a lot, in the future we might want to add certain system startup operations there, and then calling it again here might cause issues.

Code after:
                    } else {
                        pty_bus.spawn_terminal_vertically(None);
                    }

                    loop {
                        let event = pty_bus
                            .receive_pty_instructions
                            .recv()
                            .expect("failed to receive event on channel");
                        match event {
                            PtyInstruction::SpawnTerminal(file_to_open) => {
                                pty_bus.spawn_terminal(file_to_open);
                            }
                            PtyInstruction::SpawnTerminalVertically(file_to_open) => {
                                pty_bus.spawn_terminal_vertically(file_to_open);
                            }
                            PtyInstruction::SpawnTerminalHorizontally(file_to_open) => {
                                pty_bus.spawn_terminal_horizontally(file_to_open);
                            }
                            PtyInstruction::ClosePane(id) => {
                                pty_bus.close_pane(id);
                                command_is_executing.done_closing_pane();
                            }
                            PtyInstruction::Quit => {
                                break;
                            }
                        }
                    }
                }
            })
            .unwrap(),
    );

    active_threads.push(
        thread::Builder::new()
            .name("screen".to_string())
            .spawn({
                let mut command_is_executing = command_is_executing.clone();
                move || loop {
                    let event = screen
                        .receiver
                        .recv()
                        .expect("failed to receive event on channel");
                    match event {
                        ScreenInstruction::Pty(pid, vte_event) => {
                            screen.handle_pty_event(pid, vte_event);
                        }
                        ScreenInstruction::Render => {
                            screen.render();
                        }
                        ScreenInstruction::NewPane(pid) => {