Repository: j0ru/kickoff (language: rust)

Issue:
add priority for list entries
Hi,

i think it'd be good to have some form of control over the searching algorithm in form of priority. F.e. i've created https://github.com/abenz1267/hyproff and it lists Hyprland windows. 

The "problem": if i have spotify open i'd like the spotify window entry to be in top, not the executable in $PATH.

Do you think this would make sense?

Regards


Discussion / hints:
Hey,
just to clarify your use case, are you using kickoff with both, the `--from-stdin` and `--from-path` option?
Would it be enough if you could define a bonus score for items that are read from a different source i.e. for `--from-stdin` or would you need a per entry priority?

More control over the search parameters is something I've wanted to build for a while, especially because there is quite an old issue regarding this #30 
Hi,

no, i'm just using `--from-stdin`.  I use https://github.com/abenz1267/hyproff to provide whatever i need, but the sorting isn't always optimal.

Sorting/prioritizing needs to be specified by the provider and factored in by kickoff when searching.

Regards
Okay, I think I understand now.

I'm a bit reluctant to change the format of the input because that could possibly break compatibility for people who included kickoff in their scripts, but I think a simpler approach would be to add a flag to respect the original ordering.

Cheers
yeah, that could work as well i guess. I just have to sort the source then.
Perfect, I'll probably have this implemented by the end of the week

Fix patch:
diff --git a/src/selection.rs b/src/selection.rs
index f5b5bd0..db9cd8a 100644
--- a/src/selection.rs
+++ b/src/selection.rs
@@ -139,22 +139,29 @@ impl ElementListBuilder {
         for file in files {
             let mut reader = BufReader::new(File::open(file)?);
             let mut buf = String::new();
+            let mut base_score = 0;
+
             while reader.read_line(&mut buf)? > 0 {
                 let kv_pair = match parse_line(&buf) {
                     None => continue,
                     Some(res) => res,
                 };
                 match kv_pair {
+                    ("%base_score", Some(value)) => {
+                        if let Ok(value) = value.parse::<usize>() {
+                            base_score = value
+                        }
+                    }
                     (key, Some(value)) => res.push(Element {
                         name: key.to_string(),
                         value: value.to_string(),
-                        base_score: 0,
+                        base_score,
                     }),
                     ("", None) => {} // Empty Line
                     (key, None) => res.push(Element {
                         name: key.to_string(),
                         value: key.to_string(),
-                        base_score: 0,
+                        base_score,
                     }),
                 }
 
@@ -199,6 +206,7 @@ impl ElementListBuilder {
         let reader = io::BufReader::new(stdin);
         let mut lines = reader.lines();
         let mut res = Vec::new();
+        let mut base_score = 0;
 
         while let Some(line) = lines.next_line().await? {
             let kv_pair = match parse_line(&line) {
@@ -206,16 +214,21 @@ impl ElementListBuilder {
                 Some(res) => res,
             };
             match kv_pair {
+                ("%base_score", Some(value)) => {
+                    if let Ok(value) = value.parse::<usize>() {
+                        base_score = value
+                    }
+                }
                 (key, Some(value)) => res.push(Element {
                     name: key.to_string(),
                     value: value.to_string(),
-                    base_score: 0,
+                    base_score,
                 }),
                 ("", None) => {} // Empty Line
                 (key, None) => res.push(Element {
                     name: key.to_string(),
                     value: key.to_string(),
-                    base_score: 0,
+                    base_score,
                 }),
             }
         }


Test patch: