From 3cdc964777bbc3a77aa10b7336ccd1eba07c163d Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Sat, 31 Jul 2021 22:05:30 +0200 Subject: [PATCH] feat(config): add config pretty dump --- Cargo.lock | 16 +++++++++ espanso-config/Cargo.toml | 1 + espanso-config/src/config/mod.rs | 57 ++++++++++++++++++++++++++++---- 3 files changed, 68 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f190e6b..9a1a388 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -579,6 +579,7 @@ dependencies = [ "dunce", "enum-as-inner", "glob", + "indoc", "lazy_static", "log", "mockall", @@ -976,6 +977,15 @@ dependencies = [ "syn 1.0.67", ] +[[package]] +name = "indoc" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5a75aeaaef0ce18b58056d306c27b07436fbb34b8816c53094b76dd81803136" +dependencies = [ + "unindent", +] + [[package]] name = "inotify" version = "0.7.1" @@ -2156,6 +2166,12 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" +[[package]] +name = "unindent" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f14ee04d9415b52b3aeab06258a3f07093182b88ba0f9b8d203f211a7a7d41c7" + [[package]] name = "utf-8" version = "0.7.6" diff --git a/espanso-config/Cargo.toml b/espanso-config/Cargo.toml index a4e8dbd..b00cc9c 100644 --- a/espanso-config/Cargo.toml +++ b/espanso-config/Cargo.toml @@ -17,6 +17,7 @@ dunce = "1.0.1" walkdir = "2.3.1" enum-as-inner = "0.3.3" ordered-float = "2.0" +indoc = "1.0.3" [dev-dependencies] tempdir = "0.3.7" diff --git a/espanso-config/src/config/mod.rs b/espanso-config/src/config/mod.rs index 6304f4a..88be928 100644 --- a/espanso-config/src/config/mod.rs +++ b/espanso-config/src/config/mod.rs @@ -18,16 +18,17 @@ */ use anyhow::Result; -use std::{collections::HashSet, path::Path}; +use indoc::formatdoc; use std::sync::Arc; +use std::{collections::HashSet, path::Path}; use thiserror::Error; +pub(crate) mod default; mod parse; mod path; mod resolve; -mod util; -pub(crate) mod default; pub(crate) mod store; +mod util; #[cfg(test)] use mockall::{automock, predicate::*}; @@ -42,10 +43,10 @@ pub trait Config: Send + Sync { // Number of chars after which a match is injected with the clipboard // backend instead of the default one. This is done for efficiency - // reasons, as injecting a long match through separate events becomes + // reasons, as injecting a long match through separate events becomes // slow for long strings. fn clipboard_threshold(&self) -> usize; - + // Delay (in ms) that espanso should wait to trigger the paste shortcut // after copying the content in the clipboard. This is needed because // if we trigger a "paste" shortcut before the content is actually @@ -107,6 +108,51 @@ pub trait Config: Send + Sync { fn apply_patch(&self) -> bool; fn is_match<'a>(&self, app: &AppProperties<'a>) -> bool; + + fn pretty_dump(&self) -> String { + formatdoc! {" + [espanso config: {:?}] + + backend: {:?} + paste_shortcut: {:?} + inject_delay: {:?} + key_delay: {:?} + apply_patch: {:?} + word_separators: {:?} + + preserve_clipboard: {:?} + clipboard_threshold: {:?} + disable_x11_fast_inject: {} + pre_paste_delay: {} + paste_shortcut_event_delay: {} + toggle_key: {:?} + auto_restart: {:?} + restore_clipboard_delay: {:?} + backspace_limit: {} + + match_paths: {:#?} + ", + self.label(), + self.backend(), + self.paste_shortcut(), + self.inject_delay(), + self.key_delay(), + self.apply_patch(), + self.word_separators(), + + self.preserve_clipboard(), + self.clipboard_threshold(), + self.disable_x11_fast_inject(), + self.pre_paste_delay(), + self.paste_shortcut_event_delay(), + self.toggle_key(), + self.auto_restart(), + self.restore_clipboard_delay(), + self.backspace_limit(), + + self.match_paths(), + } + } } pub trait ConfigStore: Send { @@ -130,7 +176,6 @@ pub enum Backend { Auto, } - #[derive(Debug, Copy, Clone)] pub enum ToggleKey { Ctrl,