mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-12-27 00:00:03 +03:00
Compare commits
No commits in common. "75a38fa38b65c075f34233f4745eb6d1d7405a39" and "ea52c99560119070cb2c82c65dd92017240c5071" have entirely different histories.
75a38fa38b
...
ea52c99560
|
@ -331,7 +331,7 @@ impl AppState {
|
|||
})
|
||||
}
|
||||
|
||||
/// Official exercises: Dump the solution file from the binary and return its path.
|
||||
/// Official exercises: Dump the solution file form the binary and return its path.
|
||||
/// Third-party exercises: Check if a solution file exists and return its path in that case.
|
||||
pub fn current_solution_path(&self) -> Result<Option<String>> {
|
||||
if cfg!(debug_assertions) {
|
||||
|
|
|
@ -44,6 +44,7 @@ pub struct ListState<'a> {
|
|||
term_width: u16,
|
||||
term_height: u16,
|
||||
separator_line: Vec<u8>,
|
||||
narrow_term: bool,
|
||||
show_footer: bool,
|
||||
}
|
||||
|
||||
|
@ -77,6 +78,7 @@ impl<'a> ListState<'a> {
|
|||
term_width: 0,
|
||||
term_height: 0,
|
||||
separator_line: Vec::new(),
|
||||
narrow_term: false,
|
||||
show_footer: true,
|
||||
};
|
||||
|
||||
|
@ -94,9 +96,13 @@ impl<'a> ListState<'a> {
|
|||
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;
|
||||
// 2 separators, 1 progress bar, 2 footer message lines.
|
||||
let footer_height = 5;
|
||||
// 2 separator, 1 progress bar, 1-2 footer message.
|
||||
let footer_height = 4 + u16::from(self.narrow_term);
|
||||
self.show_footer = height > header_height + footer_height;
|
||||
|
||||
if self.show_footer {
|
||||
|
@ -221,10 +227,14 @@ impl<'a> ListState<'a> {
|
|||
// Help footer message
|
||||
if self.scroll_state.selected().is_some() {
|
||||
writer.write_str("↓/j ↑/k home/g end/G | <c>ontinue at | <r>eset exercise")?;
|
||||
next_ln(stdout)?;
|
||||
writer = MaxLenWriter::new(stdout, self.term_width as usize);
|
||||
if self.narrow_term {
|
||||
next_ln(stdout)?;
|
||||
writer = MaxLenWriter::new(stdout, self.term_width as usize);
|
||||
|
||||
writer.write_ascii(b"<s>earch | filter ")?;
|
||||
writer.write_ascii(b"filter ")?;
|
||||
} else {
|
||||
writer.write_ascii(b" | filter ")?;
|
||||
}
|
||||
} else {
|
||||
// Nothing selected (and nothing shown), so only display filter and quit.
|
||||
writer.write_ascii(b"filter ")?;
|
||||
|
@ -253,14 +263,17 @@ impl<'a> ListState<'a> {
|
|||
}
|
||||
|
||||
writer.write_ascii(b" | <q>uit list")?;
|
||||
next_ln(stdout)?;
|
||||
} else {
|
||||
writer.stdout.queue(SetForegroundColor(Color::Magenta))?;
|
||||
writer.write_str(&self.message)?;
|
||||
stdout.queue(ResetColor)?;
|
||||
next_ln(stdout)?;
|
||||
}
|
||||
|
||||
next_ln(stdout)?;
|
||||
if self.narrow_term {
|
||||
next_ln(stdout)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stdout.queue(EndSynchronizedUpdate)?.flush()
|
||||
|
|
Loading…
Reference in a new issue