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

Code before:
    ) = channel();
    let (send_pty_instructions, receive_pty_instructions): (
        Sender<PtyInstruction>,
        Receiver<PtyInstruction>,
    ) = channel();
    let (send_app_instructions, receive_app_instructions): (
        SyncSender<AppInstruction>,
        Receiver<AppInstruction>,
    ) = sync_channel(0);
    let mut screen = Screen::new(
        receive_screen_instructions,
        send_pty_instructions.clone(),
        send_app_instructions.clone(),
        &full_screen_ws,
        os_input.clone(),
        opts.max_panes,
    );
    let mut pty_bus = PtyBus::new(
        receive_pty_instructions,
        send_screen_instructions.clone(),
        os_input.clone(),
        opts.debug,
    );
    let maybe_layout = opts.layout.map(Layout::new);

    let send_app_instructions_clone = send_app_instructions.clone();

    #[cfg(not(test))]
    std::panic::set_hook(Box::new(move |info| {
        let backtrace = Backtrace::new();
        let thread = thread::current();
        let thread = thread.name().unwrap_or("unnamed");

        let msg = match info.payload().downcast_ref::<&'static str>() {
            Some(s) => *s,
            None => match info.payload().downcast_ref::<String>() {
                Some(s) => &**s,
                None => "Box<Any>",
            },
        };

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

Review comment (refactor):
Can we move this into the `set_hook` block in a similar way to which we do in the other threads? Just for consistency.

Something like:
```rust
std::panic::set_hook({
    let send_app_instructions = send_app_instructions.clone();
    Box::new(move |info| {
    ...
    });
});
```

Code after:
        Receiver<PtyInstruction>,
    ) = channel();
    let (send_app_instructions, receive_app_instructions): (
        SyncSender<AppInstruction>,
        Receiver<AppInstruction>,
    ) = sync_channel(0);
    let mut screen = Screen::new(
        receive_screen_instructions,
        send_pty_instructions.clone(),
        send_app_instructions.clone(),
        &full_screen_ws,
        os_input.clone(),
        opts.max_panes,
    );
    let mut pty_bus = PtyBus::new(
        receive_pty_instructions,
        send_screen_instructions.clone(),
        os_input.clone(),
        opts.debug,
    );
    let maybe_layout = opts.layout.map(Layout::new);

    #[cfg(not(test))]
    std::panic::set_hook({
        use crate::errors::handle_panic;
        let send_app_instructions = send_app_instructions.clone();
        Box::new(move |info| {
            handle_panic(info, &send_app_instructions);
        })
    });

    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);