Closed zwieberl closed 4 years ago
Looks good at first glance, I'm excited to try it out. If I don't get to it tonight I will for sure get to it tomorrow.
Thanks for the PR!
Oooo that is slick, great job!
I think I know how to include the format_simple
, the text manipulation is weird in tui
hence why I had to fork it. I think if this section was a flat_map
and returned the split and wrapped in tui::Text
segments from format_simple
it would work. I can merge this and mess with it in a few hours or if you want to take a shot at it just let me know.
Update: I came up with this but it still has some major problems, text wraps funny, re-calling best_match
is probably terible, it should probably give up if it encounters a best_match
of None, anyways heres waht I had
let text_fmt = |name: &str, style: Style| -> Vec<Text> {
if let Some(search) = self.filter_string.as_ref() {
let highlight = format_simple(
&best_match(&search, name).unwrap_or(sublime_fuzzy::Match::new()),
&search,
"^^^",
"^^^",
)
.split("^^^")
.map(|s| s.to_string())
.collect::<Vec<String>>();
let in_match = false;
highlight
.into_iter()
.map(|seg| {
if in_match {
Text::styled(seg, style.bg(Color::Black))
} else {
Text::styled(seg, style)
}
})
.collect()
} else {
vec![Text::styled(name.to_owned(), style)]
}
};
// Render items
let items = self
.names
.items
.iter()
.unique_by(|(_, id)| id)
.enumerate()
.flat_map(|(i, (name, _id))| {
if i == selected {
let style = Style::default()
.bg(highlight_style.bg)
.fg(highlight_style.fg)
.modifier(highlight_style.modifier);
text_fmt(&format!("{} {}", highlight_symbol, name), style)
} else {
let style = Style::default().fg(Color::Blue);
text_fmt(&format!(" {}", name), style)
}
})
.skip(offset as usize);
What do you think about merging without the highlight? If your ready I'm ready to merge, I will run cargo fmt
after I merge unless you want to, I don't mind either way I figure your PR so you might as well use the style your comfortable with.
Hi, sorry for the radio silence. Yes, merging sounds good to me. I don't really have time at the moment to work on the highlighting. But I will do the cargo fmt
quickly. Its your repo, so the PR should be accordingly ;-) (Actually, I just always forget to run it..)
I also have a commit for cargo clippy, but that should be its own PR. Will open, once this one is merged.
Functionality is basically done. One could use
format_simple
to highlight which letters have been matched. Didn't do this yet (not sure how yet), but left it imported for the moment. In case you are wondering about the compiler-warning because of unused.