diff --git a/src/cmd.rs b/src/cmd.rs index ee7f3bc5..f6c86876 100644 --- a/src/cmd.rs +++ b/src/cmd.rs @@ -725,6 +725,7 @@ impl Default for Commands { .command("e/frames", "Edit frames as view", |p| { p.then(paths()).map(|(_, paths)| Command::EditFrames(paths)) }) + .command("h", "Display help", |p| p.value(Command::Mode(Mode::Help))) .command("help", "Display help", |p| { p.value(Command::Mode(Mode::Help)) }) diff --git a/src/draw.rs b/src/draw.rs index b1fd96ef..8af23262 100644 --- a/src/draw.rs +++ b/src/draw.rs @@ -800,14 +800,7 @@ pub fn draw_help(session: &Session, text: &mut TextBatch, shape: &mut shape2d::B TextAlign::Left, ); - let (normal_kbs, visual_kbs): ( - Vec<(&String, &session::KeyBinding)>, - Vec<(&String, &session::KeyBinding)>, - ) = session - .key_bindings - .iter() - .filter_map(|kb| kb.display.as_ref().map(|d| (d, kb))) - .partition(|(_, kb)| kb.modes.contains(&Mode::Normal)); + let (normal_kbs, visual_kbs) = session.key_bindings.get_key_bindings(); let mut line = (0..(session.height as usize - self::LINE_HEIGHT as usize * 4)) .rev() diff --git a/src/lib.rs b/src/lib.rs index 022e9fed..88a24f38 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -49,6 +49,56 @@ mod gfx; #[macro_use] pub mod util; +// manual prints a quick reference given default Session parameters +pub fn manual() -> std::io::Result { + use std::io; + + let mut manual: String = String::new(); + + let proj_dirs = dirs::ProjectDirs::from("io", "cloudhead", "rx") + .ok_or_else(|| io::Error::new(io::ErrorKind::NotFound, "config directory not found"))?; + let base_dirs = dirs::BaseDirs::new() + .ok_or_else(|| io::Error::new(io::ErrorKind::NotFound, "home directory not found"))?; + let cwd = std::env::current_dir()?; + let options = Options { + headless: true, + ..Default::default() + }; + + let session = Session::new(1, 1, cwd, ResourceManager::new(), proj_dirs, base_dirs) + .with_blank( + FileStatus::NoFile, + Session::DEFAULT_VIEW_W, + Session::DEFAULT_VIEW_H, + ) + .init(options.source.clone())?; + + &manual.push_str(&format!("rx v{}: quick reference\n", crate::VERSION)); + + let session_kbs = session.key_bindings; + let (normal_kbs, visual_kbs) = session_kbs.get_key_bindings(); + + // colour the header? Windows versions before Linux subshell update doesn't support ANSI + &manual.push_str("\nNORMAL MODE\n\n"); + for (display, kb) in normal_kbs.iter() { + &manual.push_str(&format!("{:<36} {}\n", display, kb.command)); + } + + &manual.push_str("\nVISUAL MODE\n\n"); + for (display, kb) in visual_kbs.iter() { + &manual.push_str(&format!("{:<36} {}\n", display, kb.command)); + } + + &manual.push_str("\nCOMMAND MODE\n\n"); + for (key, def, _) in cmd::Commands::default().iter() { + &manual.push_str(&format!(":{:<36} {}\n", key, def)); + } + + manual.push_str(session::SETTINGS); + + Ok(manual) +} + use cmd::Value; use event::Event; use execution::{DigestMode, Execution, ExecutionMode, GifMode}; diff --git a/src/main.rs b/src/main.rs index 6cb7509c..88a112ed 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,6 +19,7 @@ OPTIONS -v Verbose mode -u