Merge pull request #94 from federico-terzi/dev

Version 0.3.1
This commit is contained in:
Federico Terzi 2019-10-19 23:46:49 +02:00 committed by GitHub
commit 31fb10efb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 110 additions and 21 deletions

57
Cargo.lock generated
View File

@ -172,6 +172,17 @@ dependencies = [
"vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", "vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "clicolors-control"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "cloudabi" name = "cloudabi"
version = "0.0.3" version = "0.0.3"
@ -188,6 +199,21 @@ dependencies = [
"cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)", "cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "console"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"clicolors-control 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"encode_unicode 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"termios 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-width 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "constant_time_eq" name = "constant_time_eq"
version = "0.1.4" version = "0.1.4"
@ -280,6 +306,16 @@ dependencies = [
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "dialoguer"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"console 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "dirs" name = "dirs"
version = "2.0.2" version = "2.0.2"
@ -310,6 +346,11 @@ name = "either"
version = "1.5.3" version = "1.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "encode_unicode"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "encoding_rs" name = "encoding_rs"
version = "0.8.20" version = "0.8.20"
@ -329,12 +370,13 @@ dependencies = [
[[package]] [[package]]
name = "espanso" name = "espanso"
version = "0.3.0" version = "0.3.1"
dependencies = [ dependencies = [
"backtrace 0.3.37 (registry+https://github.com/rust-lang/crates.io-index)", "backtrace 0.3.37 (registry+https://github.com/rust-lang/crates.io-index)",
"chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
"clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cmake 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", "cmake 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
"dialoguer 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"fs2 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "fs2 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
"git2 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", "git2 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1383,6 +1425,14 @@ dependencies = [
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "termios"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "textwrap" name = "textwrap"
version = "0.11.0" version = "0.11.0"
@ -1753,8 +1803,10 @@ dependencies = [
"checksum cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33" "checksum cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33"
"checksum chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e8493056968583b0193c1bb04d6f7684586f3726992d6c573261941a895dbd68" "checksum chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e8493056968583b0193c1bb04d6f7684586f3726992d6c573261941a895dbd68"
"checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" "checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9"
"checksum clicolors-control 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "90082ee5dcdd64dc4e9e0d37fbf3ee325419e39c0092191e0393df65518f741e"
"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
"checksum cmake 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "81fb25b677f8bf1eb325017cb6bb8452f87969db0fedb4f757b297bee78a7c62" "checksum cmake 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "81fb25b677f8bf1eb325017cb6bb8452f87969db0fedb4f757b297bee78a7c62"
"checksum console 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "62828f51cfa18f8c31d3d55a43c6ce6af3f87f754cba9fbba7ff38089b9f5612"
"checksum constant_time_eq 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "995a44c877f9212528ccc74b21a232f66ad69001e40ede5bcee2ac9ef2657120" "checksum constant_time_eq 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "995a44c877f9212528ccc74b21a232f66ad69001e40ede5bcee2ac9ef2657120"
"checksum cookie 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "888604f00b3db336d2af898ec3c1d5d0ddf5e6d462220f2ededc33a87ac4bbd5" "checksum cookie 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "888604f00b3db336d2af898ec3c1d5d0ddf5e6d462220f2ededc33a87ac4bbd5"
"checksum cookie_store 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "46750b3f362965f197996c4448e4a0935e791bf7d6631bfce9ee0af3d24c919c" "checksum cookie_store 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "46750b3f362965f197996c4448e4a0935e791bf7d6631bfce9ee0af3d24c919c"
@ -1765,10 +1817,12 @@ dependencies = [
"checksum crossbeam-epoch 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "fedcd6772e37f3da2a9af9bf12ebe046c0dfe657992377b4df982a2b54cd37a9" "checksum crossbeam-epoch 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "fedcd6772e37f3da2a9af9bf12ebe046c0dfe657992377b4df982a2b54cd37a9"
"checksum crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7c979cd6cfe72335896575c6b5688da489e420d36a27a0b9eb0c73db574b4a4b" "checksum crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7c979cd6cfe72335896575c6b5688da489e420d36a27a0b9eb0c73db574b4a4b"
"checksum crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "04973fa96e96579258a5091af6003abde64af786b860f18622b82e026cca60e6" "checksum crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "04973fa96e96579258a5091af6003abde64af786b860f18622b82e026cca60e6"
"checksum dialoguer 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "116f66c4e7b19af0d52857aa4ff710cc3b4781d9c16616e31540bc55ec57ba8c"
"checksum dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "13aea89a5c93364a98e9b37b2fa237effbb694d5cfe01c5b70941f7eb087d5e3" "checksum dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "13aea89a5c93364a98e9b37b2fa237effbb694d5cfe01c5b70941f7eb087d5e3"
"checksum dirs-sys 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "afa0b23de8fd801745c471deffa6e12d248f962c9fd4b4c33787b055599bde7b" "checksum dirs-sys 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "afa0b23de8fd801745c471deffa6e12d248f962c9fd4b4c33787b055599bde7b"
"checksum dtoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "ea57b42383d091c85abcc2706240b94ab2a8fa1fc81c10ff23c4de06e2a90b5e" "checksum dtoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "ea57b42383d091c85abcc2706240b94ab2a8fa1fc81c10ff23c4de06e2a90b5e"
"checksum either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" "checksum either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3"
"checksum encode_unicode 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f"
"checksum encoding_rs 0.8.20 (registry+https://github.com/rust-lang/crates.io-index)" = "87240518927716f79692c2ed85bfe6e98196d18c6401ec75355760233a7e12e9" "checksum encoding_rs 0.8.20 (registry+https://github.com/rust-lang/crates.io-index)" = "87240518927716f79692c2ed85bfe6e98196d18c6401ec75355760233a7e12e9"
"checksum error-chain 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3ab49e9dcb602294bc42f9a7dfc9bc6e936fca4418ea300dbfb84fe16de0b7d9" "checksum error-chain 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3ab49e9dcb602294bc42f9a7dfc9bc6e936fca4418ea300dbfb84fe16de0b7d9"
"checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2" "checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2"
@ -1886,6 +1940,7 @@ dependencies = [
"checksum synstructure 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "02353edf96d6e4dc81aea2d8490a7e9db177bf8acb0e951c24940bf866cb313f" "checksum synstructure 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "02353edf96d6e4dc81aea2d8490a7e9db177bf8acb0e951c24940bf866cb313f"
"checksum tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" "checksum tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9"
"checksum term 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c0863a3345e70f61d613eab32ee046ccd1bcc5f9105fe402c61fcd0c13eeb8b5" "checksum term 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c0863a3345e70f61d613eab32ee046ccd1bcc5f9105fe402c61fcd0c13eeb8b5"
"checksum termios 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "72b620c5ea021d75a735c943269bb07d30c9b77d6ac6b236bc8b5c496ef05625"
"checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" "checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" "checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b"
"checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" "checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f"

View File

@ -1,6 +1,6 @@
[package] [package]
name = "espanso" name = "espanso"
version = "0.3.0" version = "0.3.1"
authors = ["Federico Terzi <federicoterzi96@gmail.com>"] authors = ["Federico Terzi <federicoterzi96@gmail.com>"]
license = "GPL-3.0" license = "GPL-3.0"
description = "Cross-platform Text Expander written in Rust" description = "Cross-platform Text Expander written in Rust"
@ -29,6 +29,7 @@ walkdir = "2.2.9"
reqwest = "0.9.20" reqwest = "0.9.20"
git2 = {version = "0.10.1", features = ["https"]} git2 = {version = "0.10.1", features = ["https"]}
tempfile = "3.1.0" tempfile = "3.1.0"
dialoguer = "0.4.0"
[target.'cfg(unix)'.dependencies] [target.'cfg(unix)'.dependencies]
libc = "0.2.62" libc = "0.2.62"

View File

@ -2,6 +2,7 @@
> A cross-platform Text Expander written in Rust > A cross-platform Text Expander written in Rust
![GitHub release (latest by date)](https://img.shields.io/github/v/release/federico-terzi/espanso)
![Language](https://img.shields.io/badge/language-rust-orange) ![Language](https://img.shields.io/badge/language-rust-orange)
![Platforms](https://img.shields.io/badge/platforms-Windows%2C%20macOS%20and%20Linux-blue) ![Platforms](https://img.shields.io/badge/platforms-Windows%2C%20macOS%20and%20Linux-blue)
![License](https://img.shields.io/github/license/federico-terzi/espanso) ![License](https://img.shields.io/github/license/federico-terzi/espanso)

View File

@ -440,6 +440,12 @@ int32_t is_current_window_terminal() {
return 1; return 1;
}else if (strstr(class_buffer, "URxvt") != NULL) { // Manjaro terminal }else if (strstr(class_buffer, "URxvt") != NULL) { // Manjaro terminal
return 1; return 1;
}else if (strstr(class_buffer, "XTerm") != NULL) { // XTerm and UXTerm
return 1;
}else if (strstr(class_buffer, "Termite") != NULL) { // Termite
return 1;
}else if (strstr(class_buffer, "konsole") != NULL) { // KDE Konsole
return 1;
} }
} }

View File

@ -30,6 +30,7 @@ use std::sync::mpsc::Sender;
use crate::event::Event; use crate::event::Event;
use std::path::PathBuf; use std::path::PathBuf;
use std::fs::create_dir_all; use std::fs::create_dir_all;
use std::sync::Once;
pub trait Context { pub trait Context {
fn eventloop(&self); fn eventloop(&self);
@ -55,6 +56,8 @@ pub fn new(send_channel: Sender<Event>) -> Box<dyn Context> {
// espanso directories // espanso directories
static WARING_INIT : Once = Once::new();
pub fn get_data_dir() -> PathBuf { pub fn get_data_dir() -> PathBuf {
let data_dir = dirs::data_local_dir().expect("Can't obtain data_local_dir(), terminating."); let data_dir = dirs::data_local_dir().expect("Can't obtain data_local_dir(), terminating.");
let espanso_dir = data_dir.join("espanso"); let espanso_dir = data_dir.join("espanso");
@ -79,13 +82,24 @@ pub fn get_config_dir() -> PathBuf {
let home_dir = dirs::home_dir().expect("Can't obtain the user home directory, terminating."); let home_dir = dirs::home_dir().expect("Can't obtain the user home directory, terminating.");
let legacy_espanso_dir = home_dir.join(".espanso"); let legacy_espanso_dir = home_dir.join(".espanso");
if legacy_espanso_dir.exists() { if legacy_espanso_dir.exists() {
// Avoid printing the warning multiple times with std::sync::Once
WARING_INIT.call_once(|| {
eprintln!("WARNING: using legacy espanso config location in $HOME/.espanso is DEPRECATED"); eprintln!("WARNING: using legacy espanso config location in $HOME/.espanso is DEPRECATED");
eprintln!("Starting from espanso v0.3.0, espanso config location is changed."); eprintln!("Starting from espanso v0.3.0, espanso config location is changed.");
eprintln!("Please check out the documentation to find out more: https://espanso.org/docs/configuration/"); eprintln!("Please check out the documentation to find out more: https://espanso.org/docs/configuration/");
eprintln!()
});
return legacy_espanso_dir; return legacy_espanso_dir;
} }
// Check for $HOME/.config/espanso location
let home_config_dir = home_dir.join(".config");
let config_espanso_dir = home_config_dir.join("espanso");
if config_espanso_dir.exists() {
return config_espanso_dir;
}
// New config location, from version v0.3.0 // New config location, from version v0.3.0
// Refer to issue #73 for more information: https://github.com/federico-terzi/espanso/issues/73 // Refer to issue #73 for more information: https://github.com/federico-terzi/espanso/issues/73
let config_dir = dirs::config_dir().expect("Can't obtain config_dir(), terminating."); let config_dir = dirs::config_dir().expect("Can't obtain config_dir(), terminating.");

View File

@ -400,17 +400,15 @@ fn start_daemon(config_set: ConfigSet) {
// Make sure espanso is currently registered in systemd // Make sure espanso is currently registered in systemd
let res = Command::new("systemctl") let res = Command::new("systemctl")
.args(&["--user", "is-enabled", "espanso.service"]) .args(&["--user", "is-enabled", "espanso.service"])
.status(); .output();
if !res.unwrap().success() { if !res.unwrap().status.success() {
use std::io::{self, BufRead}; use dialoguer::Confirmation;
eprintln!("espanso must be registered to systemd (user level) first."); if Confirmation::new()
eprint!("Do you want to proceed? [Y/n]: "); .with_text("espanso must be registered to systemd (user level) first. Do you want to proceed?")
.default(true)
.show_default(true)
.interact().expect("Unable to read user answer") {
let mut line = String::new();
let stdin = io::stdin();
stdin.lock().read_line(&mut line).unwrap();
let answer = line.trim().to_lowercase();
if answer != "n" {
register_main(config_set); register_main(config_set);
}else{ }else{
eprintln!("Please register espanso to systemd with this command:"); eprintln!("Please register espanso to systemd with this command:");
@ -779,7 +777,7 @@ fn list_package_main(_config_set: ConfigSet, matches: &ArgMatches) {
fn path_main(_config_set: ConfigSet) { fn path_main(_config_set: ConfigSet) {
println!("Config: {}", crate::context::get_config_dir().to_string_lossy()); println!("Config: {}", crate::context::get_config_dir().to_string_lossy());
println!("Packages: {}", crate::context::get_package_dir().to_string_lossy()); println!("Packages: {}", crate::context::get_package_dir().to_string_lossy());
println!("Data: {}", crate::context::get_config_dir().to_string_lossy()); println!("Data: {}", crate::context::get_data_dir().to_string_lossy());
} }

View File

@ -118,12 +118,26 @@ pub fn register(config_set: ConfigSet) {
if let Ok(res) = res { if let Ok(res) = res {
let output = String::from_utf8_lossy(res.stdout.as_slice()); let output = String::from_utf8_lossy(res.stdout.as_slice());
let output = output.trim(); let output = output.trim();
if res.status.success() && output == "enabled" { if res.status.success() {
if output == "enabled" {
eprintln!("espanso service is already registered to systemd"); eprintln!("espanso service is already registered to systemd");
eprintln!("If you want to register it again, please uninstall it first with:"); eprintln!("If you want to register it again, please uninstall it first with:");
eprintln!(" espanso unregister"); eprintln!(" espanso unregister");
std::process::exit(5); std::process::exit(5);
} }
}else{
if output == "disabled" {
use dialoguer::Confirmation;
if !Confirmation::new()
.with_text("espanso is already registered but currently disabled. Do you want to override it?")
.default(false)
.show_default(true)
.interact().expect("Unable to read user answer") {
std::process::exit(6);
}
}
}
} }
// User level systemd services should be placed in this directory: // User level systemd services should be placed in this directory: