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-04-09 19:29:23 +00:00
|
|
|
use enum_as_inner::EnumAsInner;
|
|
|
|
use ordered_float::OrderedFloat;
|
2021-04-29 20:35:05 +00:00
|
|
|
use std::collections::BTreeMap;
|
2021-02-24 20:57:23 +00:00
|
|
|
|
2021-04-29 20:35:05 +00:00
|
|
|
use crate::counter::StructId;
|
2021-03-04 21:02:44 +00:00
|
|
|
|
2021-03-23 20:57:03 +00:00
|
|
|
pub(crate) mod group;
|
2021-03-08 20:46:27 +00:00
|
|
|
pub mod store;
|
2021-02-24 20:57:23 +00:00
|
|
|
|
2021-04-04 20:01:59 +00:00
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
2021-02-24 20:57:23 +00:00
|
|
|
pub struct Match {
|
2021-04-04 20:01:59 +00:00
|
|
|
pub id: StructId,
|
2021-02-24 20:57:23 +00:00
|
|
|
|
2021-04-04 20:01:59 +00:00
|
|
|
pub cause: MatchCause,
|
|
|
|
pub effect: MatchEffect,
|
2021-03-04 21:02:44 +00:00
|
|
|
|
2021-04-04 20:01:59 +00:00
|
|
|
// Metadata
|
|
|
|
pub label: Option<String>,
|
2021-02-24 20:57:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Match {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
cause: MatchCause::None,
|
|
|
|
effect: MatchEffect::None,
|
|
|
|
label: None,
|
2021-04-04 20:01:59 +00:00
|
|
|
id: 0,
|
2021-02-24 20:57:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Causes
|
|
|
|
|
2021-04-19 20:03:29 +00:00
|
|
|
#[derive(Debug, Clone, Eq, Hash, PartialEq, EnumAsInner)]
|
2021-02-24 20:57:23 +00:00
|
|
|
pub enum MatchCause {
|
|
|
|
None,
|
|
|
|
Trigger(TriggerCause),
|
|
|
|
// TODO: regex
|
|
|
|
// TODO: shortcut
|
|
|
|
}
|
|
|
|
|
2021-04-04 20:01:59 +00:00
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
2021-02-24 20:57:23 +00:00
|
|
|
pub struct TriggerCause {
|
|
|
|
pub triggers: Vec<String>,
|
|
|
|
|
|
|
|
pub left_word: bool,
|
|
|
|
pub right_word: bool,
|
|
|
|
|
|
|
|
pub propagate_case: bool,
|
2021-04-19 20:03:29 +00:00
|
|
|
pub uppercase_style: UpperCasingStyle,
|
2021-02-24 20:57:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for TriggerCause {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
triggers: Vec::new(),
|
|
|
|
left_word: false,
|
|
|
|
right_word: false,
|
|
|
|
propagate_case: false,
|
2021-04-19 20:03:29 +00:00
|
|
|
uppercase_style: UpperCasingStyle::Uppercase,
|
2021-02-24 20:57:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-19 20:03:29 +00:00
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
|
|
pub enum UpperCasingStyle {
|
|
|
|
Uppercase,
|
|
|
|
Capitalize,
|
|
|
|
CapitalizeWords,
|
|
|
|
}
|
|
|
|
|
2021-02-24 20:57:23 +00:00
|
|
|
// Effects
|
|
|
|
|
2021-04-19 20:03:29 +00:00
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash, EnumAsInner)]
|
2021-02-24 20:57:23 +00:00
|
|
|
pub enum MatchEffect {
|
|
|
|
None,
|
|
|
|
Text(TextEffect),
|
2021-05-01 17:41:04 +00:00
|
|
|
Image(ImageEffect),
|
2021-02-24 20:57:23 +00:00
|
|
|
}
|
|
|
|
|
2021-04-04 20:01:59 +00:00
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
2021-02-24 20:57:23 +00:00
|
|
|
pub struct TextEffect {
|
|
|
|
pub replace: String,
|
|
|
|
pub vars: Vec<Variable>,
|
2021-04-29 20:35:05 +00:00
|
|
|
pub format: TextFormat,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
|
|
pub enum TextFormat {
|
|
|
|
Plain,
|
|
|
|
Markdown,
|
|
|
|
Html,
|
2021-02-24 20:57:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for TextEffect {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
replace: String::new(),
|
|
|
|
vars: Vec::new(),
|
2021-04-29 20:35:05 +00:00
|
|
|
format: TextFormat::Plain,
|
2021-02-24 20:57:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-01 17:41:04 +00:00
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
|
|
pub struct ImageEffect {
|
|
|
|
pub path: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for ImageEffect {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
path: String::new(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-04 20:01:59 +00:00
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
2021-02-24 20:57:23 +00:00
|
|
|
pub struct Variable {
|
2021-04-04 20:01:59 +00:00
|
|
|
pub id: StructId,
|
2021-02-24 20:57:23 +00:00
|
|
|
pub name: String,
|
|
|
|
pub var_type: String,
|
2021-04-09 19:29:23 +00:00
|
|
|
pub params: Params,
|
2021-03-04 21:02:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Variable {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
2021-04-04 20:01:59 +00:00
|
|
|
id: 0,
|
2021-03-04 21:02:44 +00:00
|
|
|
name: String::new(),
|
|
|
|
var_type: String::new(),
|
2021-04-09 19:29:23 +00:00
|
|
|
params: Params::new(),
|
2021-03-04 21:02:44 +00:00
|
|
|
}
|
|
|
|
}
|
2021-02-24 20:57:23 +00:00
|
|
|
}
|
2021-04-09 19:29:23 +00:00
|
|
|
|
|
|
|
pub type Params = BTreeMap<String, Value>;
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash, EnumAsInner)]
|
|
|
|
pub enum Value {
|
|
|
|
Null,
|
|
|
|
Bool(bool),
|
|
|
|
Number(Number),
|
|
|
|
String(String),
|
|
|
|
Array(Vec<Value>),
|
|
|
|
Object(Params),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Eq, Hash, PartialEq)]
|
|
|
|
pub enum Number {
|
|
|
|
Integer(i64),
|
|
|
|
Float(OrderedFloat<f64>),
|
2021-04-29 20:35:05 +00:00
|
|
|
}
|