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;
|
|
|
|
use std::{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-05-05 19:19:32 +00:00
|
|
|
pub clipboard_threshold: Option<usize>,
|
2021-03-24 19:51:15 +00:00
|
|
|
|
2021-05-08 12:57:18 +00:00
|
|
|
pub pre_paste_delay: Option<usize>,
|
|
|
|
|
2021-05-23 13:45:58 +00:00
|
|
|
pub toggle_key: Option<String>,
|
|
|
|
|
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-03-09 15:06:50 +00:00
|
|
|
}
|