mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-12-24 22:50:26 +00:00
list: Highlight search match in exercise names
Some checks failed
Rustlings Tests / clippy (push) Has been cancelled
Rustlings Tests / fmt (push) Has been cancelled
Rustlings Tests / test (macOS-latest) (push) Has been cancelled
Rustlings Tests / test (ubuntu-latest) (push) Has been cancelled
Rustlings Tests / test (windows-latest) (push) Has been cancelled
Rustlings Tests / dev-check (push) Has been cancelled
Web / Build and deploy site and docs (push) Has been cancelled
Some checks failed
Rustlings Tests / clippy (push) Has been cancelled
Rustlings Tests / fmt (push) Has been cancelled
Rustlings Tests / test (macOS-latest) (push) Has been cancelled
Rustlings Tests / test (ubuntu-latest) (push) Has been cancelled
Rustlings Tests / test (windows-latest) (push) Has been cancelled
Rustlings Tests / dev-check (push) Has been cancelled
Web / Build and deploy site and docs (push) Has been cancelled
This commit is contained in:
parent
7e2f56f41a
commit
930a0ea73b
1 changed files with 24 additions and 2 deletions
|
@ -105,6 +105,28 @@ impl<'a> ListState<'a> {
|
|||
);
|
||||
}
|
||||
|
||||
fn draw_exericse_name(&self, writer: &mut MaxLenWriter, exercise: &Exercise) -> io::Result<()> {
|
||||
if !self.search_query.is_empty() {
|
||||
if let Some((pre_highlight, highlight, post_highlight)) = exercise
|
||||
.name
|
||||
.find(&self.search_query)
|
||||
.and_then(|ind| exercise.name.split_at_checked(ind))
|
||||
.and_then(|(pre_highlight, rest)| {
|
||||
rest.split_at_checked(self.search_query.len())
|
||||
.map(|x| (pre_highlight, x.0, x.1))
|
||||
})
|
||||
{
|
||||
writer.write_str(pre_highlight)?;
|
||||
writer.stdout.queue(SetForegroundColor(Color::Magenta))?;
|
||||
writer.write_str(highlight)?;
|
||||
writer.stdout.queue(ResetColor)?;
|
||||
return writer.write_str(post_highlight);
|
||||
}
|
||||
}
|
||||
|
||||
writer.write_str(exercise.name)
|
||||
}
|
||||
|
||||
fn draw_rows(
|
||||
&self,
|
||||
stdout: &mut StdoutLock,
|
||||
|
@ -147,10 +169,10 @@ impl<'a> ListState<'a> {
|
|||
writer.stdout.queue(SetForegroundColor(Color::Yellow))?;
|
||||
writer.write_ascii(b"PENDING ")?;
|
||||
}
|
||||
|
||||
writer.stdout.queue(SetForegroundColor(Color::Reset))?;
|
||||
|
||||
writer.write_str(exercise.name)?;
|
||||
self.draw_exericse_name(&mut writer, exercise)?;
|
||||
|
||||
writer.write_ascii(&self.name_col_padding[exercise.name.len()..])?;
|
||||
|
||||
// The list links aren't shown correctly in VS Code on Windows.
|
||||
|
|
Loading…
Reference in a new issue