Trim and polish things a little

This commit is contained in:
Brooks J Rady 2021-01-12 04:53:39 +00:00
parent 145104abdf
commit c80c0a1fa7

View file

@ -15,13 +15,12 @@ impl MosaicTile for State {
} }
fn draw(&mut self, _rows: usize, cols: usize) { fn draw(&mut self, _rows: usize, cols: usize) {
let mut width = 0;
let more_msg = ", <?> More"; let more_msg = ", <?> More";
self.lines = vec![String::new()]; self.lines = vec![String::new()];
for item in get_help() { for item in get_help() {
let width = self.lines.last().unwrap().len();
if width + item.len() > cols - more_msg.len() { if width + item.len() > cols - more_msg.len() {
self.lines.last_mut().unwrap().push_str(more_msg); self.lines.last_mut().unwrap().push_str(more_msg);
width = item.len();
self.lines.push(item); self.lines.push(item);
} else { } else {
let line = self.lines.last_mut().unwrap(); let line = self.lines.last_mut().unwrap();
@ -29,9 +28,9 @@ impl MosaicTile for State {
line.push_str(", "); line.push_str(", ");
} }
line.push_str(&item); line.push_str(&item);
width += item.len() + 2;
} }
} }
self.page %= self.lines.len();
let line = format!( let line = format!(
"{}{}", "{}{}",
self.lines[self.page], self.lines[self.page],
@ -45,11 +44,8 @@ impl MosaicTile for State {
} }
fn handle_global_key(&mut self, key: Key) { fn handle_global_key(&mut self, key: Key) {
if self.lines.len() > 1 { if let Key::Char('?') = key {
if let Key::Char('?') = key { self.page += 1;
self.page += 1;
self.page %= self.lines.len();
}
} }
} }
} }