davatorium / rofi

Rofi: A window switcher, application launcher and dmenu replacement
https://davatorium.github.io/rofi/
Other
13.27k stars 613 forks source link

Icons specified with new metadata syntax fail to display consistently #860

Closed Celti closed 6 years ago

Celti commented 6 years ago

Version

$ rofi -v
Version: 1.5.1-58-git-114b2cf2-dirty (makepkg)

Configuration

Gist of rofi -help output. To note a deliberate oddity, the -modi configuration listed there is empty, as I set them from the command-line for different launch use-cases as desired.

Launch Command

rofi -show file -modi file:rofi-file rofi-file is the code here — vaguely based on the rofi-file-browser.sh example, but written in Rust and attempting to support the new icon syntax from a99cfa5.

Steps to reproduce

What behaviour you see

What behaviour you expect to see

DaveDavenport commented 6 years ago

Drun mode icons work correctly for you?

DaveDavenport commented 6 years ago

Your rofi-file does not build for me, what am I doing wrong:

cargo build
warning: unused manifest key: package.edition
    Updating registry `https://github.com/rust-lang/crates.io-index`
 Downloading fnv v1.0.6                                                         
 Downloading lazy_static v1.1.0                                                 
 Downloading dirs v1.0.4                                                        
 Downloading itertools v0.7.8                                                   
 Downloading walkdir v2.2.5                                                     
 Downloading tree_magic v0.2.0                                                  
 Downloading version_check v0.1.5                                               
 Downloading either v1.5.0                                                      
 Downloading same-file v1.0.3                                                   
 Downloading petgraph v0.4.13                                                   
 Downloading lazy_static v0.2.11                                                
 Downloading nom v2.2.1                                                         
 Downloading fixedbitset v0.1.9                                                 
 Downloading ordermap v0.3.5                                                    
 Downloading libc v0.2.43                                                       
   Compiling fixedbitset v0.1.9                                                 
   Compiling libc v0.2.43
   Compiling lazy_static v0.2.11
   Compiling fnv v1.0.6
   Compiling same-file v1.0.3
   Compiling version_check v0.1.5
   Compiling ordermap v0.3.5
   Compiling either v1.5.0
   Compiling nom v2.2.1
   Compiling walkdir v2.2.5
   Compiling lazy_static v1.1.0
   Compiling dirs v1.0.4
   Compiling itertools v0.7.8
   Compiling petgraph v0.4.13
   Compiling tree_magic v0.2.0
   Compiling rofi-file v0.1.0 (file:///home/d/Programming/Others/rofi-file)
error[E0432]: unresolved import `fnv`
 --> src/main.rs:1:5
  |
1 | use fnv::FnvHashMap;
  |     ^^^ Maybe a missing `extern crate fnv;`?

error[E0432]: unresolved import `itertools`
 --> src/main.rs:2:5
  |
2 | use itertools::Itertools;
  |     ^^^^^^^^^ Maybe a missing `extern crate itertools;`?

error[E0432]: unresolved import `lazy_static`
 --> src/main.rs:3:5
  |
3 | use lazy_static::lazy_static;
  |     ^^^^^^^^^^^ Maybe a missing `extern crate lazy_static;`?

error[E0432]: unresolved import `walkdir`
  --> src/main.rs:11:5
   |
11 | use walkdir::{DirEntry, WalkDir};
   |     ^^^^^^^ Maybe a missing `extern crate walkdir;`?

error: cannot find macro `lazy_static!` in this scope
  --> src/main.rs:13:1
   |
13 | lazy_static! {
   | ^^^^^^^^^^^

error[E0433]: failed to resolve. Use of undeclared type or module `tree_magic`
  --> src/main.rs:54:20
   |
54 |         let mime = tree_magic::from_filepath(entry.path());
   |                    ^^^^^^^^^^ Use of undeclared type or module `tree_magic`

error[E0433]: failed to resolve. Use of undeclared type or module `dirs`
  --> src/main.rs:74:21
   |
74 |     let cache_dir = dirs::cache_dir().expect("cache dir").join("rofi");
   |                     ^^^^ Use of undeclared type or module `dirs`

error[E0433]: failed to resolve. Use of undeclared type or module `dirs`
  --> src/main.rs:84:13
   |
84 |             dirs::home_dir().expect("cache_dir")
   |             ^^^^ Use of undeclared type or module `dirs`

error[E0425]: cannot find value `ICONS` in this scope
  --> src/main.rs:32:5
   |
32 |     ICONS.get(mime).or_else(|| GENERIC.get(mime)).map(Cow::from)
   |     ^^^^^ not found in this scope

error[E0425]: cannot find value `GENERIC` in this scope
  --> src/main.rs:32:32
   |
32 |     ICONS.get(mime).or_else(|| GENERIC.get(mime)).map(Cow::from)
   |                                ^^^^^^^ not found in this scope

error[E0425]: cannot find function `read_to_string` in module `std::fs`
  --> src/main.rs:78:42
   |
78 |     let lastdir = PathBuf::from(std::fs::read_to_string(&lastdir_path).unwrap_or_default());
   |                                          ^^^^^^^^^^^^^^ did you mean `read_string`?

error: aborting due to 11 previous errors

error: Could not compile `rofi-file`.
DaveDavenport commented 6 years ago

After some serious rust frustration, got it to build, but get:

thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', libcore/option.rs:345:21
note: Run with `RUST_BACKTRACE=1` for a backtrace.

Patch to build (on latest rustc/cargo):

diff --git a/Cargo.toml b/Cargo.toml
index 08f1010..f0e24c1 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -2,7 +2,6 @@
 name = "rofi-file"
 version = "0.1.0"
 authors = ["Celti Burroughs <celti@celti.name>"]
-edition = "2018"

 [dependencies]
 dirs = "1"
diff --git a/src/main.rs b/src/main.rs
index a0a65d9..2b50ebf 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,6 +1,14 @@
+extern crate fnv;
+extern crate itertools;
+#[macro_use]
+extern crate lazy_static;
+extern crate walkdir;
+extern crate tree_magic;
+extern crate dirs;
+
 use fnv::FnvHashMap;
 use itertools::Itertools;
-use lazy_static::lazy_static;
+//use lazy_static::lazy_static;
 use std::cmp::Ordering;
 use std::fs::File;
 use std::io::{BufRead, BufReader, Result as IoResult};
Celti commented 6 years ago

Re: the rustc errors; you have my apologies, I should have specified I was using the latest nightly and the 2018 edition. I didn't do any error-handling beyond panics and backtraces, but I suspect that it's failing because it's unable to find any one of magic, icons, or generic-icons in /usr/share/mime/ — it's very FDO-specific.

Yes, drun modi icons show up appropriately, this only happens with a custom script. More specifically, in drun mode, when I scroll/browse through the list, the next screen full of icons will not render instantly — there is a short but perceptible delay. With a custom script, that second(+) rendering needs to be manually triggered by filtering, as described above.

DaveDavenport commented 6 years ago

Its weird, the code path for both (drun,script) for icons in rofi is pretty identical.

Can you generate me a txt with the input generated by your program? so I can try to reproduce.

Celti commented 6 years ago

Ah, I should've thought of that, sorry. Here's two, one for a relatively small $HOME and one for a fairly large directory of PDFs. The first one will only show the (mis)behaviour when I navigate to it, not on first load; the second will show it when I navigate to it, and also when I scroll through the available entries.

DaveDavenport commented 6 years ago

Should be fixed, can you test.

Celti commented 6 years ago

Works flawlessly. Thank you!

DaveDavenport commented 6 years ago

Thx for the lists, it made me spot the issue instantly :D

colonelpanic8 commented 5 years ago

@DaveDavenport Sorry to hijack this thread, but I can't seem to get this feature to work.

Is there some flag that needs to be enabled to get it to work? I tried using the sample inputs provided by @Celti, but they did not seem to register.

DaveDavenport commented 5 years ago

@IvanMalison please follow the guidelines. It is explicitly asks not to hijack threads!