/*
* This file is part of espanso.
*
* Copyright (C) 2019-2021 Federico Terzi
*
* espanso is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* espanso is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with espanso. If not, see .
*/
use anyhow::Result;
use std::{collections::BTreeMap, convert::TryInto, path::Path};
use thiserror::Error;
mod yaml;
#[derive(Debug, Clone, PartialEq, Default)]
pub(crate) struct ParsedConfig {
pub label: Option,
pub backend: Option,
pub enable: Option,
pub clipboard_threshold: Option,
pub auto_restart: Option,
pub preserve_clipboard: Option,
pub toggle_key: Option,
pub paste_shortcut: Option,
pub disable_x11_fast_inject: Option,
pub word_separators: Option>,
pub backspace_limit: Option,
pub apply_patch: Option,
pub search_trigger: Option,
pub search_shortcut: Option,
pub undo_backspace: Option,
pub show_notifications: Option,
pub show_icon: Option,
pub secure_input_notification: Option,
pub post_form_delay: Option,
pub post_search_delay: Option,
pub win32_exclude_orphan_events: Option,
pub win32_keyboard_layout_cache_interval: Option,
pub x11_use_xclip_backend: Option,
pub pre_paste_delay: Option,
pub restore_clipboard_delay: Option,
pub paste_shortcut_event_delay: Option,
pub inject_delay: Option,
pub key_delay: Option,
pub keyboard_layout: Option>,
pub evdev_modifier_delay: Option,
// Includes
pub includes: Option>,
pub excludes: Option>,
pub extra_includes: Option>,
pub extra_excludes: Option>,
pub use_standard_includes: Option,
// Filters
pub filter_title: Option,
pub filter_class: Option,
pub filter_exec: Option,
pub filter_os: Option,
}
impl ParsedConfig {
pub fn load(path: &Path) -> Result {
let content = std::fs::read_to_string(path)?;
match yaml::YAMLConfig::parse_from_str(&content) {
Ok(config) => Ok(config.try_into()?),
Err(err) => Err(ParsedConfigError::LoadFailed(err).into()),
}
}
}
#[derive(Error, Debug)]
pub enum ParsedConfigError {
#[error("can't load config `{0}`")]
LoadFailed(#[from] anyhow::Error),
}