Repository: lapce/lapce
File: lapce-ui/src/status.rs (Rust)

Code before:
        );
        ctx.fill(
            rect,
            data.config
                .get_color_unchecked(LapceTheme::STATUS_BACKGROUND),
        );

        let mut left = 0.0;

        if data.config.lapce.modal {
            let (mode, color) = {
                let mode =
                    if data.focus_area == FocusArea::Panel(PanelKind::Terminal) {
                        data.terminal
                            .terminals
                            .get(&data.terminal.active_term_id)
                            .unwrap()
                            .mode
                    } else {
                        data.main_split
                            .active_editor()
                            .map(|e| e.cursor.get_mode())
                            .unwrap_or(Mode::Normal)
                    };
                match mode {
                    Mode::Normal => (
                        "Normal",
                        data.config
                            .get_color_unchecked(LapceTheme::STATUS_MODAL_NORMAL)
                            .clone(),
                    ),
                    Mode::Insert => (
                        "Insert",
                        data.config
                            .get_color_unchecked(LapceTheme::STATUS_MODAL_INSERT)
                            .clone(),
                    ),
                    Mode::Visual => (
                        "Visual",
                        data.config
                            .get_color_unchecked(LapceTheme::STATUS_MODAL_VISUAL)
                            .clone(),
                    ),
                    Mode::Terminal => (
                        "Terminal",
                        data.config
                            .get_color_unchecked(LapceTheme::STATUS_MODAL_TERMINAL)
                            .clone(),
                    ),
                }
            };

Review comment (suggestion):
I think this could be condensed slightly if you return a `(name, style_name)` pair and transform that into `(name, color)` in the next statement.

Code after:
        );
        ctx.fill(
            rect,
            data.config
                .get_color_unchecked(LapceTheme::STATUS_BACKGROUND),
        );

        let mut left = 0.0;

        if data.config.lapce.modal {
            let (mode, color) = {
                let mode =
                    if data.focus_area == FocusArea::Panel(PanelKind::Terminal) {
                        data.terminal
                            .terminals
                            .get(&data.terminal.active_term_id)
                            .unwrap()
                            .mode
                    } else {
                        data.main_split
                            .active_editor()
                            .map(|e| e.cursor.get_mode())
                            .unwrap_or(Mode::Normal)
                    };
                match mode {
                    Mode::Normal => (
                        "Normal", LapceTheme::STATUS_MODAL_NORMAL,
                    ),
                    Mode::Insert => (
                        "Insert", LapceTheme::STATUS_MODAL_INSERT,
                    ),
                    Mode::Visual => (
                        "Visual", LapceTheme::STATUS_MODAL_VISUAL,
                    ),
                    Mode::Terminal => (
                        "Terminal", LapceTheme::STATUS_MODAL_TERMINAL,
                    ),
                }
            };

            let text_layout = ctx
                .text()
                .new_text_layout(mode)
                .font(FontFamily::SYSTEM_UI, 13.0)
                .text_color(
                    data.config
                        .get_color_unchecked(LapceTheme::EDITOR_BACKGROUND)
                        .clone(),
                )
                .build()
                .unwrap();