feat(config): introduce image matches options

This commit is contained in:
Federico Terzi 2021-05-01 19:41:04 +02:00
parent 7b9e01c1db
commit 7a8e39fdad
3 changed files with 22 additions and 5 deletions

View File

@ -17,7 +17,7 @@
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
*/
use crate::{counter::next_id, matches::{Match, Params, TextFormat, UpperCasingStyle, Value, Variable, group::{path::resolve_imports, MatchGroup}}};
use crate::{counter::next_id, matches::{ImageEffect, Match, Params, TextFormat, UpperCasingStyle, Value, Variable, group::{path::resolve_imports, MatchGroup}}};
use anyhow::Result;
use log::{error, warn};
use parse::YAMLMatchGroup;
@ -198,6 +198,10 @@ impl TryFrom<YAMLMatch> for Match {
vars,
format: TextFormat::Plain,
})
} else if let Some(image_path) = yaml_match.image_path { // TODO: test image case
MatchEffect::Image(ImageEffect {
path: image_path,
})
} else {
MatchEffect::None
};

View File

@ -17,11 +17,11 @@
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
*/
use std::{collections::HashMap, path::Path};
use std::{path::Path};
use anyhow::Result;
use serde::{Deserialize, Serialize};
use serde_yaml::{Mapping, Value};
use serde_yaml::{Mapping};
use crate::util::is_yaml_empty;
@ -68,7 +68,7 @@ pub struct YAMLMatch {
pub replace: Option<String>,
#[serde(default)]
pub image_path: Option<String>, // TODO: map
pub image_path: Option<String>,
#[serde(default)]
pub form: Option<String>,

View File

@ -94,7 +94,7 @@ pub enum UpperCasingStyle {
pub enum MatchEffect {
None,
Text(TextEffect),
// TODO: image
Image(ImageEffect),
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@ -121,6 +121,19 @@ impl Default for TextEffect {
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ImageEffect {
pub path: String,
}
impl Default for ImageEffect {
fn default() -> Self {
Self {
path: String::new(),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Variable {
pub id: StructId,