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

Code before:
        let hide_cursor = "\u{1b}[?25l";
        stdout
            .write_all(&hide_cursor.as_bytes())
            .expect("cannot write to stdout");
        if self.should_clear_display_before_rendering {
            let clear_display = "\u{1b}[2J";
            stdout
                .write_all(&clear_display.as_bytes())
                .expect("cannot write to stdout");
            self.should_clear_display_before_rendering = false;
        }
        for (kind, pane) in self.panes.iter_mut() {
            if !self.panes_to_hide.contains(&pane.pid()) {
                match self.active_terminal.unwrap() == pane.pid() {
                    true => {
                        boundaries.add_rect(pane.as_ref(), self.mode_info.mode, Some(colors::GREEN))
                    }
                    false => boundaries.add_rect(pane.as_ref(), self.mode_info.mode, None),
                }
                if let Some(vte_output) = pane.render() {
                    let vte_output = if let PaneId::Terminal(_) = kind {
                        vte_output
                    } else {
                        adjust_to_size(&vte_output, pane.rows(), pane.columns())
                    };
                    // FIXME: Use Termion for cursor and style clearing?
                    write!(
                        stdout,
                        "\u{1b}[{};{}H\u{1b}[m{}",
                        pane.y() + 1,
                        pane.x() + 1,
                        vte_output
                    )
                    .expect("cannot write to stdout");
                }
            }
        }

        // TODO: only render (and calculate) boundaries if there was a resize
        let vte_output = boundaries.vte_output();
        stdout
            .write_all(&vte_output.as_bytes())
            .expect("cannot write to stdout");

        match self.get_active_terminal_cursor_position() {
            Some((cursor_position_x, cursor_position_y)) => {
                let show_cursor = "\u{1b}[?25h";
                let goto_cursor_position = format!(
                    "\u{1b}[{};{}H\u{1b}[m",
                    cursor_position_y + 1,
                    cursor_position_x + 1

Review comment (suggestion):
Nice. I would have gone with something on the state of `Tab` that bypasses the `should_render` of each pane, but the more I think about it, the more I like this solution.

Code after:
                    return;
                } else {
                    let active_terminal = self.panes.get_mut(&active_pane_id).unwrap();
                    active_terminal.override_size_and_position(
                        self.full_screen_ws.x,
                        self.full_screen_ws.y,
                        &self.full_screen_ws,
                    );
                }
            }
            let active_terminal = self.panes.get(&active_pane_id).unwrap();
            if let PaneId::Terminal(active_pid) = active_pane_id {
                self.os_api.set_terminal_size_using_fd(
                    active_pid,
                    active_terminal.columns() as u16,
                    active_terminal.rows() as u16,
                );
            }
            self.render();
            self.toggle_fullscreen_is_active();
        }
    }
    pub fn toggle_fullscreen_is_active(&mut self) {
        self.fullscreen_is_active = !self.fullscreen_is_active;
    }
    pub fn set_force_render(&mut self) {
        for pane in self.panes.values_mut() {
            pane.set_should_render(true);
        }
    }
    pub fn is_sync_panes_active(&self) -> bool {
        self.synchronize_is_active
    }
    pub fn toggle_sync_panes_is_active(&mut self) {
        self.synchronize_is_active = !self.synchronize_is_active;
    }
    pub fn panes_contain_widechar(&self) -> bool {
        self.panes.iter().any(|(_, p)| p.contains_widechar())
    }
    pub fn render(&mut self) {
        if self.active_terminal.is_none() {
            // we might not have an active terminal if we closed the last pane
            // in that case, we should not render as the app is exiting
            return;
        }
        // if any pane contain widechar, all pane in the same row will messup. We should render them every time
        // FIXME: remove this when we can handle widechars correctly
        if self.panes_contain_widechar() {
            self.set_force_render()
        }
        let mut stdout = self.os_api.get_stdout_writer();