Match on keywords in the launcher

In the launcher match not only on the program name but also on the
keywords specified in the desktop file.
This commit is contained in:
Pedro Côrte-Real
2020-01-02 17:19:37 +00:00
parent 2ba19f9e64
commit 809af580a9
4 changed files with 40 additions and 15 deletions
Generated
+16 -4
View File
@@ -244,6 +244,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 = "multimap"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "nix" name = "nix"
version = "0.13.1" version = "0.13.1"
@@ -451,8 +459,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "rust-ini" name = "rust-ini"
version = "0.13.0" version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://github.com/pedrocr/rust-ini.git?branch=no_eol_comments#70d2b56842d244d37a83c895dd345c122a0df218"
dependencies = [
"multimap 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "rusttype" name = "rusttype"
@@ -724,7 +735,7 @@ dependencies = [
"nix 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "nix 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
"os_pipe 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", "os_pipe 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rcalc_lib 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", "rcalc_lib 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)",
"rust-ini 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", "rust-ini 0.14.0 (git+https://github.com/pedrocr/rust-ini.git?branch=no_eol_comments)",
"rusttype 0.7.7 (registry+https://github.com/rust-lang/crates.io-index)", "rusttype 0.7.7 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -789,6 +800,7 @@ dependencies = [
"checksum linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ae91b68aebc4ddb91978b11a1b02ddd8602a05ec19002801c5666000e05e0f83" "checksum linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ae91b68aebc4ddb91978b11a1b02ddd8602a05ec19002801c5666000e05e0f83"
"checksum maplit 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" "checksum maplit 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d"
"checksum memmap 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6585fd95e7bb50d6cc31e20d4cf9afb4e2ba16c5846fc76793f11218da9c475b" "checksum memmap 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6585fd95e7bb50d6cc31e20d4cf9afb4e2ba16c5846fc76793f11218da9c475b"
"checksum multimap 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1838fe05e64c53b9a62579020e4a12ec5947af5d703c56962d0e3b7b923bf3ba"
"checksum nix 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4dbdc256eaac2e3bd236d93ad999d3479ef775c863dbda3068c4006a92eec51b" "checksum nix 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4dbdc256eaac2e3bd236d93ad999d3479ef775c863dbda3068c4006a92eec51b"
"checksum nix 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6c722bee1037d430d0f8e687bbdbf222f27cc6e4e68d5caf630857bb2b6dbdce" "checksum nix 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6c722bee1037d430d0f8e687bbdbf222f27cc6e4e68d5caf630857bb2b6dbdce"
"checksum nix 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3b2e0b4f3320ed72aaedb9a5ac838690a8047c7b275da22711fddff4f8a14229" "checksum nix 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3b2e0b4f3320ed72aaedb9a5ac838690a8047c7b275da22711fddff4f8a14229"
@@ -812,7 +824,7 @@ dependencies = [
"checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" "checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe"
"checksum rcalc_lib 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2497fc2d7578e75282922918d96de8d4790714312900d95b6d5f577168f2656e" "checksum rcalc_lib 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2497fc2d7578e75282922918d96de8d4790714312900d95b6d5f577168f2656e"
"checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" "checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84"
"checksum rust-ini 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3e52c148ef37f8c375d49d5a73aa70713125b7f19095948a923f80afdeb22ec2" "checksum rust-ini 0.14.0 (git+https://github.com/pedrocr/rust-ini.git?branch=no_eol_comments)" = "<none>"
"checksum rusttype 0.7.7 (registry+https://github.com/rust-lang/crates.io-index)" = "654103d61a05074b268a107cf6581ce120f0fc0115f2610ed9dfea363bb81139" "checksum rusttype 0.7.7 (registry+https://github.com/rust-lang/crates.io-index)" = "654103d61a05074b268a107cf6581ce120f0fc0115f2610ed9dfea363bb81139"
"checksum ryu 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c92464b447c0ee8c4fb3824ecc8383b81717b9f1e74ba2e72540aef7b9f82997" "checksum ryu 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c92464b447c0ee8c4fb3824ecc8383b81717b9f1e74ba2e72540aef7b9f82997"
"checksum same-file 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "585e8ddcedc187886a30fa705c47985c3fa88d06624095856b36ca0b82ff4421" "checksum same-file 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "585e8ddcedc187886a30fa705c47985c3fa88d06624095856b36ca0b82ff4421"
+1 -1
View File
@@ -31,7 +31,7 @@ dbus = "0.6"
fuzzy-matcher = "0.2" fuzzy-matcher = "0.2"
lazy_static = "1.4" lazy_static = "1.4"
rcalc_lib = { version = "0.9" } rcalc_lib = { version = "0.9" }
rust-ini = "0.13" rust-ini = { version = "0.14", git = "https://github.com/pedrocr/rust-ini.git", branch = "no_eol_comments"}
shlex = "0.1" shlex = "0.1"
timerfd = "1.0.0" timerfd = "1.0.0"
+4
View File
@@ -16,6 +16,7 @@ pub struct Desktop {
pub exec: Option<String>, pub exec: Option<String>,
pub url: Option<String>, pub url: Option<String>,
pub term: bool, pub term: bool,
pub keywords: Vec<String>,
} }
impl Desktop { impl Desktop {
@@ -36,6 +37,9 @@ impl Desktop {
hidden: desktop.get("Hidden").unwrap_or(&"".to_string()) == "true", hidden: desktop.get("Hidden").unwrap_or(&"".to_string()) == "true",
exec: desktop.get("Exec").map(|x| x.to_string()), exec: desktop.get("Exec").map(|x| x.to_string()),
url: desktop.get("URL").map(|x| x.to_string()), url: desktop.get("URL").map(|x| x.to_string()),
keywords: desktop.get("Keywords").map(|x|
x.split(";").map(|y| y.trim().to_string()).filter(|z| z != "").collect()
).unwrap_or(vec![]),
}), }),
None => Err(Box::new(io_error::new( None => Err(Box::new(io_error::new(
ErrorKind::NotFound, ErrorKind::NotFound,
+19 -10
View File
@@ -80,7 +80,8 @@ impl Launcher {
}; };
let size = if idx == self.offset && self.input.len() > 0 { let size = if idx == self.offset && self.input.len() > 0 {
let (_, indices) = let (_, indices) =
fuzzy_indices(&m.name.to_lowercase(), &self.input.to_lowercase()).unwrap(); fuzzy_indices(&m.name.to_lowercase(), &self.input.to_lowercase())
.unwrap_or((0, vec![]));
let mut colors = Vec::with_capacity(m.name.len()); let mut colors = Vec::with_capacity(m.name.len());
for pos in 0..m.name.len() { for pos in 0..m.name.len() {
if indices.contains(&pos) { if indices.contains(&pos) {
@@ -227,15 +228,23 @@ impl Widget for Launcher {
} }
Some('!') => (), Some('!') => (),
_ => { _ => {
let mut m = self let mut m = vec![];
.options
.iter() for desktop in self.options.iter() {
.map(|x| { let d = desktop.clone();
( m.push((
fuzzy_match(&x.name.to_lowercase(), &self.input.to_lowercase()), fuzzy_match(&desktop.name.to_lowercase(), &self.input.to_lowercase()),
x, d.clone(),
) ));
}) for keyword in desktop.keywords.iter() {
m.push((
fuzzy_match(&keyword.to_lowercase(), &self.input.to_lowercase()),
d.clone(),
));
}
}
let mut m = m.iter()
.filter(|(x, _)| x.is_some()) .filter(|(x, _)| x.is_some())
.map(|(x, y)| (x.unwrap(), y.clone())) .map(|(x, y)| (x.unwrap(), y.clone()))
.collect::<Vec<(i64, Desktop)>>(); .collect::<Vec<(i64, Desktop)>>();