2021-03-09 15:06:50 +00:00
|
|
|
/*
|
|
|
|
* 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 <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2021-03-07 14:53:02 +00:00
|
|
|
use anyhow::Result;
|
2021-08-09 20:53:32 +00:00
|
|
|
use std::{collections::BTreeMap, convert::TryInto, path::Path};
|
2021-03-09 15:06:50 +00:00
|
|
|
use thiserror::Error;
|
2021-03-07 14:53:02 +00:00
|
|
|
|
|
|
|
mod yaml;
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, PartialEq, Default)]
|
|
|
|
pub(crate) struct ParsedConfig {
|
|
|
|
pub label: Option<String>,
|
|
|
|
|
2021-03-24 19:51:15 +00:00
|
|
|
pub backend: Option<String>,
|
2021-08-21 07:21:59 +00:00
|
|
|
pub enable: Option<bool>,
|
2021-05-05 19:19:32 +00:00
|
|
|
pub clipboard_threshold: Option<usize>,
|
2021-06-03 19:00:38 +00:00
|
|
|
pub auto_restart: Option<bool>,
|
2021-06-05 09:36:55 +00:00
|
|
|
pub preserve_clipboard: Option<bool>,
|
2021-06-05 10:18:52 +00:00
|
|
|
pub toggle_key: Option<String>,
|
|
|
|
pub paste_shortcut: Option<String>,
|
|
|
|
pub disable_x11_fast_inject: Option<bool>,
|
2021-06-10 19:14:12 +00:00
|
|
|
pub word_separators: Option<Vec<String>>,
|
2021-06-10 19:27:05 +00:00
|
|
|
pub backspace_limit: Option<usize>,
|
2021-07-31 15:17:24 +00:00
|
|
|
pub apply_patch: Option<bool>,
|
2021-08-13 18:34:15 +00:00
|
|
|
pub search_trigger: Option<String>,
|
2021-08-13 19:17:01 +00:00
|
|
|
pub search_shortcut: Option<String>,
|
2021-08-15 09:01:36 +00:00
|
|
|
pub undo_backspace: Option<bool>,
|
2021-08-20 16:45:22 +00:00
|
|
|
pub show_notifications: Option<bool>,
|
|
|
|
pub show_icon: Option<bool>,
|
|
|
|
pub secure_input_notification: Option<bool>,
|
2022-03-05 19:27:49 +00:00
|
|
|
pub post_form_delay: Option<usize>,
|
|
|
|
pub post_search_delay: Option<usize>,
|
2021-08-22 19:46:26 +00:00
|
|
|
pub win32_exclude_orphan_events: Option<bool>,
|
2021-10-25 19:31:11 +00:00
|
|
|
pub win32_keyboard_layout_cache_interval: Option<i64>,
|
2021-11-21 18:39:35 +00:00
|
|
|
pub x11_use_xclip_backend: Option<bool>,
|
2021-03-24 19:51:15 +00:00
|
|
|
|
2021-05-08 12:57:18 +00:00
|
|
|
pub pre_paste_delay: Option<usize>,
|
2021-06-05 09:36:55 +00:00
|
|
|
pub restore_clipboard_delay: Option<usize>,
|
2021-06-05 10:18:52 +00:00
|
|
|
pub paste_shortcut_event_delay: Option<usize>,
|
2021-06-07 19:15:39 +00:00
|
|
|
pub inject_delay: Option<usize>,
|
|
|
|
pub key_delay: Option<usize>,
|
2021-08-09 20:53:32 +00:00
|
|
|
pub keyboard_layout: Option<BTreeMap<String, String>>,
|
2021-09-06 21:11:47 +00:00
|
|
|
pub evdev_modifier_delay: Option<usize>,
|
2021-05-23 13:45:58 +00:00
|
|
|
|
2021-03-07 14:53:02 +00:00
|
|
|
// Includes
|
|
|
|
pub includes: Option<Vec<String>>,
|
|
|
|
pub excludes: Option<Vec<String>>,
|
|
|
|
pub extra_includes: Option<Vec<String>>,
|
|
|
|
pub extra_excludes: Option<Vec<String>>,
|
|
|
|
pub use_standard_includes: Option<bool>,
|
|
|
|
|
|
|
|
// Filters
|
|
|
|
pub filter_title: Option<String>,
|
|
|
|
pub filter_class: Option<String>,
|
|
|
|
pub filter_exec: Option<String>,
|
|
|
|
pub filter_os: Option<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ParsedConfig {
|
|
|
|
pub fn load(path: &Path) -> Result<Self> {
|
|
|
|
let content = std::fs::read_to_string(path)?;
|
|
|
|
match yaml::YAMLConfig::parse_from_str(&content) {
|
2021-03-09 15:06:50 +00:00
|
|
|
Ok(config) => Ok(config.try_into()?),
|
|
|
|
Err(err) => Err(ParsedConfigError::LoadFailed(err).into()),
|
2021-03-07 14:53:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Error, Debug)]
|
|
|
|
pub enum ParsedConfigError {
|
|
|
|
#[error("can't load config `{0}`")]
|
|
|
|
LoadFailed(#[from] anyhow::Error),
|
2021-10-06 16:37:15 +00:00
|
|
|
}
|