use super::*;
impl App {
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),
}
}
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}");
}
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();
}
}
}