summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Tay <sam.chong.tay@gmail.com>2020-06-28 18:04:54 -0700
committerSam Tay <sam.chong.tay@gmail.com>2020-06-28 18:07:46 -0700
commit8b5c16b8a09f8f778036ebd2a0329243ad0edd77 (patch)
treecbf98631d88143c205c14c278fbb01b8d6c82b96
parentf23602053eb04b31a715f3cc6acb471acced11c1 (diff)
Add a key-bindings help popup
-rw-r--r--TODO.md9
-rw-r--r--roadmap.md4
-rw-r--r--src/tui/app.rs44
-rw-r--r--src/tui/views.rs1
4 files changed, 48 insertions, 10 deletions
diff --git a/TODO.md b/TODO.md
index 076d028..d3433d4 100644
--- a/TODO.md
+++ b/TODO.md
@@ -4,13 +4,10 @@
2. Move to github actions ASAP, travis & appveyor are a PITA. See resources below.
4. Refactor layout handling (see TODO on `tui::views::LayoutView::relayout`)
5. Release on AUR & Homebrew
-6. Benchmark markdown parsing: see what I'm gaining by borrowing and querying
- entity hash set. If building my own spannedstring source from md output
- doesn't affect performance, do it! This would rule out a large class of
- indexing panics coming from cursive.
### bugs
-1. why does `so -e stackexchange -s stackoverflow how do i exit vim` result in
+1. Shift+TAB should move focus backwards
+2. why does `so -e stackexchange -s stackoverflow how do i exit vim` result in
different results than `so -e stackexchange -s stackoverflow "how do i exit vim"`?
### feature ideas
@@ -19,8 +16,6 @@
- Maybe allow slimmer builds without TUI that only offer --lucky.
#### Endless improvements for the TUI
-1. Add Shift+TAB to cycle focus backwards (just add CirculularFocus wrapper)
-3. **Priority** Small text at bottom with '?' to bring up key mapping dialog
1. Init with smaller layout depending on initial screen size.
2. Maybe cli `--auto-resize` option that changes layouts at breakpoints.
5. Maybe **[ESC]** cycles layout in the opposite direction? And stops at
diff --git a/roadmap.md b/roadmap.md
index 05cc9b8..ef75cf6 100644
--- a/roadmap.md
+++ b/roadmap.md
@@ -30,7 +30,9 @@
- [x] use trust to distrubute app binaries
- [ ] look up how to add logging `debug!` macros; will help troubleshooting blocked requests
- [ ] handle backoff responses from SE
- - [ ] allow new queries from TUI, e.g. hit `/` for a prompt
+ - [ ] allow new queries from TUI, e.g. hit `/` for a prompt. This could
+ also bring up an advanced search form that allows mutliselect of sites, select
+ search engine, etc.
- [ ] or `/` searches current q/a
- [ ] clean up dingleberries in error.rs and term.rs ; only keep what's actually ergonomic
- [ ] per platform package mgmt
diff --git a/src/tui/app.rs b/src/tui/app.rs
index 06ac090..023955f 100644
--- a/src/tui/app.rs
+++ b/src/tui/app.rs
@@ -1,7 +1,9 @@
use cursive::event::Event;
use cursive::theme::{BaseColor, Color, Effect, Style};
+use cursive::traits::{Nameable, Scrollable};
use cursive::utils::markup::StyledString;
use cursive::utils::span::SpannedString;
+use cursive::views::{Dialog, TextView};
use cursive::Cursive;
use cursive::XY;
use std::collections::HashMap;
@@ -17,6 +19,8 @@ use crate::config;
use crate::error::Result;
use crate::stackexchange::{Answer, Question};
+pub const NAME_HELP_VIEW: &str = "help_view";
+
pub fn run(qs: Vec<Question<Markdown>>) -> Result<()> {
let mut siv = cursive::default();
siv.load_theme_file(config::theme_file_name()?).unwrap(); // TODO dont unwrap
@@ -61,8 +65,16 @@ pub fn run(qs: Vec<Question<Markdown>>) -> Result<()> {
if let Some(cb) = cb {
cb(&mut siv)
}
- cursive::logger::init();
- siv.add_global_callback('?', cursive::Cursive::toggle_debug_console);
+
+ // Help / View keymappings
+ siv.add_global_callback('?', |s| {
+ if let Some(pos) = s.screen_mut().find_layer_from_name(NAME_HELP_VIEW) {
+ s.screen_mut().remove_layer(pos);
+ } else {
+ s.add_layer(help());
+ }
+ });
+ // Reload theme
siv.add_global_callback(Event::CtrlChar('r'), |s| {
s.load_theme_file(config::theme_file_name().unwrap())
.unwrap()
@@ -127,5 +139,33 @@ fn pretty_score(score: i32) -> StyledString {
)
}
+// This would be a good usecase for brining in termimad tables
+// TODO dont parse this at runtime, just hardcode it
+pub fn help() -> Dialog {
+ let bindings = r###"
+## Panes
+**Tab**: Focus next pane
+**Space**: Cycle layout (4 Pane, 2 Pane, FullScreen)
+
+## Scroll
+**h,j,k,l**: ←,↓,↑,→
+**Ctrl<b>, Ctrl<u>**: ↑ x 10
+**Ctrl<f>, Ctrl<d>**: ↓ x 10
+**gg**: Scroll To Top
+**G**: Scroll To Bottom
+
+## Misc
+**ZZ, Ctrl<c>**: Exit
+**?**: Toggle this help menu
+"###;
+ Dialog::around(
+ TextView::new(markdown::parse(bindings))
+ .scrollable()
+ .with_name(NAME_HELP_VIEW),
+ )
+ .dismiss_button("Close")
+ .title("Help")
+}
+
// TODO see cursive/examples/src/bin/select_test.rs for how to test the interface!
// maybe see if we can conditionally run when --nocapture is passed?
diff --git a/src/tui/views.rs b/src/tui/views.rs
index 2e2fc4d..3dc12a8 100644
--- a/src/tui/views.rs
+++ b/src/tui/views.rs
@@ -20,6 +20,7 @@ pub const NAME_QUESTION_VIEW: &str = "question_view";
pub const NAME_ANSWER_VIEW: &str = "answer_view";
pub const NAME_FULL_LAYOUT: &str = "full_layout";
+// TODO this seems pointless; probably should be removed
pub enum Name {
QuestionList,
AnswerList,