aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBrooks J Rady <b.j.rady@gmail.com>2021-01-11 21:35:49 +0000
committerBrooks J Rady <b.j.rady@gmail.com>2021-01-11 21:35:49 +0000
commit94c231bf2c2ab51e329cd8e384213f1f0598db15 (patch)
treea105c0875db15dd109e04a44e3765615bf55f2d2 /src
parentKeypress Debug Version (diff)
downloadsl0ppij-94c231bf2c2ab51e329cd8e384213f1f0598db15.tar.gz
sl0ppij-94c231bf2c2ab51e329cd8e384213f1f0598db15.tar.xz
sl0ppij-94c231bf2c2ab51e329cd8e384213f1f0598db15.zip
Functional help bar
Diffstat (limited to 'src')
-rw-r--r--src/main.rs42
1 files changed, 37 insertions, 5 deletions
diff --git a/src/main.rs b/src/main.rs
index b820a18d..7557b066 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -2,7 +2,10 @@ use colored::*;
use mosaic_tile::*;
#[derive(Default)]
-struct State(usize, String);
+struct State {
+ lines: Vec<String>,
+ page: usize,
+}
register_tile!(State);
@@ -12,12 +15,41 @@ impl MosaicTile for State {
}
fn draw(&mut self, _rows: usize, cols: usize) {
- let line = format!("{}: {}", self.0, self.1);
- println!("{:cols$}", line.reversed(), cols = cols);
+ let mut width = 0;
+ let more_msg = ", <?> More";
+ self.lines = vec![String::new()];
+ for item in get_help() {
+ if width + item.len() > cols - more_msg.len() {
+ self.lines.last_mut().unwrap().push_str(more_msg);
+ width = item.len();
+ self.lines.push(item);
+ } else {
+ let line = self.lines.last_mut().unwrap();
+ if !line.is_empty() {
+ line.push_str(", ");
+ }
+ line.push_str(&item);
+ width += item.len() + 2;
+ }
+ }
+ let line = format!(
+ "{}{}",
+ self.lines[self.page],
+ if self.page > 0 && self.lines.len() == self.page + 1 {
+ ", <?> Back"
+ } else {
+ ""
+ }
+ );
+ println!("{}", line.italic());
}
fn handle_global_key(&mut self, key: Key) {
- self.0 += 1;
- self.1 = format!("{:?}", key);
+ if self.lines.len() > 1 {
+ if let Key::Char('?') = key {
+ self.page += 1;
+ self.page %= self.lines.len();
+ }
+ }
}
}