mirror of
https://github.com/notohh/rustlings.git
synced 2024-12-17 22:58:08 -05:00
Add search to the help footer
This commit is contained in:
parent
ac62a3713c
commit
75a38fa38b
1 changed files with 7 additions and 20 deletions
|
@ -44,7 +44,6 @@ pub struct ListState<'a> {
|
||||||
term_width: u16,
|
term_width: u16,
|
||||||
term_height: u16,
|
term_height: u16,
|
||||||
separator_line: Vec<u8>,
|
separator_line: Vec<u8>,
|
||||||
narrow_term: bool,
|
|
||||||
show_footer: bool,
|
show_footer: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +77,6 @@ impl<'a> ListState<'a> {
|
||||||
term_width: 0,
|
term_width: 0,
|
||||||
term_height: 0,
|
term_height: 0,
|
||||||
separator_line: Vec::new(),
|
separator_line: Vec::new(),
|
||||||
narrow_term: false,
|
|
||||||
show_footer: true,
|
show_footer: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -96,13 +94,9 @@ impl<'a> ListState<'a> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let wide_help_footer_width = 95;
|
|
||||||
// The help footer is shorter when nothing is selected.
|
|
||||||
self.narrow_term = width < wide_help_footer_width && self.scroll_state.selected().is_some();
|
|
||||||
|
|
||||||
let header_height = 1;
|
let header_height = 1;
|
||||||
// 2 separator, 1 progress bar, 1-2 footer message.
|
// 2 separators, 1 progress bar, 2 footer message lines.
|
||||||
let footer_height = 4 + u16::from(self.narrow_term);
|
let footer_height = 5;
|
||||||
self.show_footer = height > header_height + footer_height;
|
self.show_footer = height > header_height + footer_height;
|
||||||
|
|
||||||
if self.show_footer {
|
if self.show_footer {
|
||||||
|
@ -227,14 +221,10 @@ impl<'a> ListState<'a> {
|
||||||
// Help footer message
|
// Help footer message
|
||||||
if self.scroll_state.selected().is_some() {
|
if self.scroll_state.selected().is_some() {
|
||||||
writer.write_str("↓/j ↑/k home/g end/G | <c>ontinue at | <r>eset exercise")?;
|
writer.write_str("↓/j ↑/k home/g end/G | <c>ontinue at | <r>eset exercise")?;
|
||||||
if self.narrow_term {
|
next_ln(stdout)?;
|
||||||
next_ln(stdout)?;
|
writer = MaxLenWriter::new(stdout, self.term_width as usize);
|
||||||
writer = MaxLenWriter::new(stdout, self.term_width as usize);
|
|
||||||
|
|
||||||
writer.write_ascii(b"filter ")?;
|
writer.write_ascii(b"<s>earch | filter ")?;
|
||||||
} else {
|
|
||||||
writer.write_ascii(b" | filter ")?;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Nothing selected (and nothing shown), so only display filter and quit.
|
// Nothing selected (and nothing shown), so only display filter and quit.
|
||||||
writer.write_ascii(b"filter ")?;
|
writer.write_ascii(b"filter ")?;
|
||||||
|
@ -263,17 +253,14 @@ impl<'a> ListState<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
writer.write_ascii(b" | <q>uit list")?;
|
writer.write_ascii(b" | <q>uit list")?;
|
||||||
next_ln(stdout)?;
|
|
||||||
} else {
|
} else {
|
||||||
writer.stdout.queue(SetForegroundColor(Color::Magenta))?;
|
writer.stdout.queue(SetForegroundColor(Color::Magenta))?;
|
||||||
writer.write_str(&self.message)?;
|
writer.write_str(&self.message)?;
|
||||||
stdout.queue(ResetColor)?;
|
stdout.queue(ResetColor)?;
|
||||||
next_ln(stdout)?;
|
next_ln(stdout)?;
|
||||||
|
|
||||||
if self.narrow_term {
|
|
||||||
next_ln(stdout)?;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
next_ln(stdout)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
stdout.queue(EndSynchronizedUpdate)?.flush()
|
stdout.queue(EndSynchronizedUpdate)?.flush()
|
||||||
|
|
Loading…
Reference in a new issue