-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature renderable filter #48
Draft
markzporter
wants to merge
8
commits into
autobib:master
Choose a base branch
from
markzporter:feature-renderable_filter
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a49bab5
add options for all control chars
f6430e7
add "EOL" for better visibility of line behaviour
6289cc6
formatting
ba97566
update .toml with example
f888848
move from vect to range into iterator lazy eval for ascii chars based…
e9d2407
formatting
5601ea1
Merge branch 'master' into feature-renderable_filter
markzporter b2e5b0c
update with better hex formatting
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
//! # Demonstration of configuration options, some of which are un-renderable, demonstrating the filtering ability | ||
//! | ||
//! This blocking example demonstrates some of the configuration options available to the picker. | ||
use std::io::Result; | ||
|
||
use nucleo_picker::{nucleo::Config, render::StrRenderer, PickerOptions}; | ||
|
||
|
||
fn list_control_characters() -> Vec<char> { | ||
(0x00..=0x1F).map(|i| char::from_u32(i).unwrap()).collect() | ||
} | ||
fn main() -> Result<()> { | ||
let mut picker = PickerOptions::default() | ||
// set the configuration to match 'path-like' objects | ||
.config(Config::DEFAULT.match_paths()) | ||
// set the default query string to `/var` | ||
.query("/var") | ||
.picker(StrRenderer); | ||
|
||
|
||
|
||
|
||
let control_chars = list_control_characters(); | ||
|
||
|
||
// populate the matcher | ||
let injector = picker.injector(); | ||
for ctrl in control_chars { | ||
let hex_ctrl = format!("{:X}", ctrl as u32); // Convert the char to a u32 and format as hex | ||
let option = format!("hex is {} control {} |",hex_ctrl, ctrl); | ||
injector.push(option); | ||
} | ||
|
||
// open interactive prompt | ||
match picker.pick()? { | ||
Some(opt) => { | ||
println!("You selected: '{opt}'"); | ||
} | ||
None => { | ||
println!("Nothing selected!"); | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't have to return a
Vec
here, you can returnimpl Iterator<Item = char>
to the same effect:and the code should still compile. The reason is that for looks in rust are actually based on
Iterator
s: the thing you are looping over is anything that implements theIntoIterator
trait. The lazy version is better since it saves on an allocation.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
impl ...
return type says "I am returning a concrete type, but I am just not telling you exactly what it is"; it's not actually a dynamic object. The compiler will replace yourimpl ...
block with the actual type of the thing that you return.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even better, you can directly construct a
Range<char>
:and just use that instead (since
Range<char>
implementsIntoIterator<Item = char>
).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right so the idea being that we are only storing one char in memory at a time OK makes sense. Will make this change thanks!