A native Rust library which enables you to incorporate a highly performant and Unicode-aware fuzzy picker directly in your own terminal application.
This library provides a TUI for the nucleo
crate with an interface similar to the fzf command-line tool.
- For implementation examples, jump to the fzf example or see the
examples
directory. - For documentation of interactive usage of the picker, see the
USAGE.md
file. - For a list of recent changes, see the
CHANGELOG.md
file.
Why use this library instead of a general-purpose fuzzy-finder such as fzf
or a lower level library such as nucleo
?
- Much tighter integration between your data source and your application.
Instead of reading from a SQLite database with
sqlite3
and then parsing raw text, read directly into in-memory data structures withrusqlite
and render the in-memory objects in the picker. - Skip the subprocess overhead and improve startup time.
Instead of starting up a subprocess to call
fzf
, have the picker integrated directly into your binary. - Distinguish items from their matcher representation.
Instead of writing your data structure to a string, passing it to
fzf
, and then parsing the resulting match string back into your data structure, directly obtain the original data structure when matching is complete. - Don't spend time debugging terminal rendering edge cases.
Out-of-the-box,
nucleo-picker
handles terminal rendering subtleties such as multiline rendering, double-width Unicode, automatic overflow scrollthrough, and grapheme-aware query input so you don't have to.
- Highly optimized matching.
- Robust rendering:
- Full Unicode handling with Unicode text segmentation and Unicode width.
- Match highlighting with automatic scroll-through.
- Correctly render multi-line or overflowed items.
- Responsive interface with batched keyboard input.
- Ergonomic API:
- Fully concurrent lock- and wait-free streaming of input items.
- Generic
Picker
for any typeT
which isSend + Sync + 'static
. - Customizable rendering of crate-local and foreign types with the
Render
trait.
Implement a heavily simplified fzf
clone in 25 lines of code.
Try it out with:
cargo build --release --example fzf
cat myfile.txt | ./target/release/examples/fzf
The code to create the binary:
use std::{
io::{self, BufRead},
process::exit,
thread::spawn,
};
use nucleo_picker::{render::StrRenderer, Picker};
fn main() -> io::Result<()> {
let mut picker = Picker::new(StrRenderer);
let injector = picker.injector();
spawn(move || {
for line in io::stdin().lock().lines() {
if let Ok(s) = line {
injector.push(s);
}
}
});
match picker.pick()? {
Some(it) => println!("{it}"),
None => exit(1),
}
Ok(())
}
This crate mainly exists as a result of the author's annoyance with pretty much every fuzzy picker TUI in the rust ecosystem.
- skim's
Arc<dyn SkimItem>
is inconvenient for a variety of reasons.skim
also has a large number of dependencies and is designed more as a binary than a library. - fuzzypicker is based on
skim
and inheritsskim
's problems. - nucleo-ui only has a blocking API and only supports matching on
String
. It also seems to be un-maintained. - fuzzy-select only has a blocking API.
- dialoguer
FuzzySelect
only has a blocking API and only supports matching onString
. The terminal handling also has a few strange bugs.
The feature set of this library is quite minimal (by design) but may be expanded in the future. There are a currently a few known problems which have not been addressed (see the issues page on GitHub for a list).