|
@@ -54,8 +54,8 @@ impl<AE: ActionEnum> ActionPrompt<AE> {
|
|
let key_string = key.to_string();
|
|
let key_string = key.to_string();
|
|
let Some((before,after)) = label.split_once(&key_string) else { continue };
|
|
let Some((before,after)) = label.split_once(&key_string) else { continue };
|
|
|
|
|
|
- if line.len() > 0 {
|
|
|
|
- line.push_str("/");
|
|
|
|
|
|
+ if !line.is_empty() {
|
|
|
|
+ line.push('/');
|
|
}
|
|
}
|
|
|
|
|
|
line += format!("{reset}{before}{underline}{red}{key_string}{reset}{after}").as_str();
|
|
line += format!("{reset}{before}{underline}{red}{key_string}{reset}{after}").as_str();
|
|
@@ -67,14 +67,14 @@ impl<AE: ActionEnum> ActionPrompt<AE> {
|
|
|
|
|
|
line += format!(" {green}?{reset} ").as_str();
|
|
line += format!(" {green}?{reset} ").as_str();
|
|
|
|
|
|
- stdout.write(line.as_bytes())?;
|
|
|
|
|
|
+ stdout.write_all(line.as_bytes())?;
|
|
stdout.flush()?;
|
|
stdout.flush()?;
|
|
|
|
|
|
Ok(())
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
|
|
fn wait_for_answer(self, cancellable: bool) -> Result<Option<AE>, AskError> {
|
|
fn wait_for_answer(self, cancellable: bool) -> Result<Option<AE>, AskError> {
|
|
- let _rawlock = std::io::stdout().into_raw_mode()?;
|
|
|
|
|
|
+ let stdoutlock = std::io::stdout().into_raw_mode()?;
|
|
|
|
|
|
let stdin = std::io::stdin();
|
|
let stdin = std::io::stdin();
|
|
|
|
|
|
@@ -105,7 +105,7 @@ impl<AE: ActionEnum> ActionPrompt<AE> {
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
- drop(_rawlock);
|
|
|
|
|
|
+ drop(stdoutlock);
|
|
|
|
|
|
let reset = termion::style::Reset;
|
|
let reset = termion::style::Reset;
|
|
let underline = termion::style::Underline;
|
|
let underline = termion::style::Underline;
|
|
@@ -160,7 +160,7 @@ impl<'l, T: std::fmt::Display> SelectPrompt<'l, T> {
|
|
self.items.sort_by_cached_key(|v| v.0.clone());
|
|
self.items.sort_by_cached_key(|v| v.0.clone());
|
|
}
|
|
}
|
|
|
|
|
|
- for _ in 0..self.height { writeln!(stdout, "")? };
|
|
|
|
|
|
+ for _ in 0..self.height { writeln!(stdout)? };
|
|
|
|
|
|
write!(stdout, "{}{}",
|
|
write!(stdout, "{}{}",
|
|
termion::cursor::Up(self.height as u16),
|
|
termion::cursor::Up(self.height as u16),
|
|
@@ -193,7 +193,7 @@ impl<'l, T: std::fmt::Display> SelectPrompt<'l, T> {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- fn append_column(remaining_width: usize, rows: &mut Vec<String>, col: &mut Vec<&str>) -> Option<usize> {
|
|
|
|
|
|
+ fn append_column(remaining_width: usize, rows: &mut [String], col: &mut Vec<&str>) -> Option<usize> {
|
|
if col.is_empty() || remaining_width == 0 {
|
|
if col.is_empty() || remaining_width == 0 {
|
|
return None
|
|
return None
|
|
}
|
|
}
|
|
@@ -202,7 +202,7 @@ impl<'l, T: std::fmt::Display> SelectPrompt<'l, T> {
|
|
let widths = col.iter().map(|v| v.graphemes(true).count()).collect::<Vec<_>>();
|
|
let widths = col.iter().map(|v| v.graphemes(true).count()).collect::<Vec<_>>();
|
|
let max_width = *widths.iter().max().unwrap() + 2;
|
|
let max_width = *widths.iter().max().unwrap() + 2;
|
|
|
|
|
|
- let Some(newrem) = remaining_width.checked_sub(max_width) else { return None };
|
|
|
|
|
|
+ let newrem = remaining_width.checked_sub(max_width)?;
|
|
|
|
|
|
for (row, (col, width)) in rows.iter_mut().zip(col.drain(..).zip(widths.into_iter())) {
|
|
for (row, (col, width)) in rows.iter_mut().zip(col.drain(..).zip(widths.into_iter())) {
|
|
row.push_str(col);
|
|
row.push_str(col);
|
|
@@ -262,11 +262,10 @@ impl<'l, T: std::fmt::Display> SelectPrompt<'l, T> {
|
|
}
|
|
}
|
|
|
|
|
|
fn input_loop(&mut self, stdout: &mut std::io::Stdout, cancellable: bool) -> Result<Option<T>, AskError> {
|
|
fn input_loop(&mut self, stdout: &mut std::io::Stdout, cancellable: bool) -> Result<Option<T>, AskError> {
|
|
- let mut keys = std::io::stdin().keys();
|
|
|
|
let mut raw = stdout.into_raw_mode()?;
|
|
let mut raw = stdout.into_raw_mode()?;
|
|
self.refilter();
|
|
self.refilter();
|
|
self.repaint(&mut raw)?;
|
|
self.repaint(&mut raw)?;
|
|
- while let Some(key) = keys.next() {
|
|
|
|
|
|
+ for key in std::io::stdin().keys() {
|
|
let key = key?;
|
|
let key = key?;
|
|
|
|
|
|
match key {
|
|
match key {
|