rustimal 0.8.0

A minimal, GPU-rendered terminal for Windows that runs Git Bash, with animated split panes and a glass look
//! Applying a changed config, from the file or from Settings.

use super::*;

impl App {
    /// Read the config file again and apply it. `announce` also reports success (an edit made
    /// elsewhere only speaks up when something is wrong).
    pub(super) fn reload_config(&mut self, announce: bool) {
        match Config::load_checked() {
            Ok(new) => {
                if new.to_table() == self.config.to_table() {
                    if announce {
                        self.toast("The config has not changed");
                    }
                    return;
                }
                self.apply_config(new);
                self.toast("Config reloaded");
            }
            Err(e) => self.toast(e),
        }
    }

    /// Switch to a new configuration while running. Most things take effect at once; a few
    /// (the glass window, the shell integration for open shells) need a restart.
    pub(super) fn apply_config(&mut self, new: Config) {
        let old = std::mem::replace(&mut self.config, new);
        let new = &self.config;
        self.palette = Palette::from_theme(&new.theme);
        let (keymap, problems) = Keymap::build(&new.keys);
        self.keymap = keymap;
        for problem in problems {
            log::warn!("{problem}");
        }
        // The hotkey thread can switch keys without a restart.
        if new.hotkey != old.hotkey {
            match (&self.hotkey, new.hotkey.trim().is_empty()) {
                (Some(h), true) => h.clear(),
                (Some(h), false) => {
                    if !h.change(&new.hotkey) {
                        log::warn!("can't read the hotkey '{}'", new.hotkey);
                    }
                }
                (None, false) => self.hotkey = Hotkey::start(&new.hotkey, self.proxy.clone()),
                (None, true) => {}
            }
        }
        if new.shell_integration != old.shell_integration || new.shell != old.shell {
            self.shell_env = new.shell_env();
        }
        let font_changed =
            new.font_family != old.font_family || new.font_size != old.font_size || new.line_height != old.line_height;
        let (family, size, line_height, scrollback) =
            (new.font_family.clone(), new.font_size, new.line_height, new.scrollback);
        if let Some(st) = self.state.as_mut() {
            if font_changed {
                st.font_pt = size.clamp(6.0, 40.0);
                let px = (st.font_pt * 96.0 / 72.0 * st.scale).round();
                st.glyphs = Glyphs::new(&family, px, line_height);
            }
            for pane in st.panes.iter().chain(st.closing.iter()) {
                pane.term.lock().set_options(alacritty_terminal::term::Config {
                    scrolling_history: scrollback,
                    ..Default::default()
                });
            }
        }
        self.relayout(true, true);
        if let Some(st) = self.state.as_ref() {
            st.window.request_redraw();
        }
    }
}