summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Tay <sam.chong.tay@gmail.com>2020-06-16 12:58:22 -0700
committerSam Tay <sam.chong.tay@gmail.com>2020-06-16 12:58:22 -0700
commit00635360e52f8f9834be71a1e1e21f24ddb3529f (patch)
tree42825e3b1334c029f1845fcf45c5ee805d2e551b
parent00990e57824bd12bd3f7fc69aa51652b33fdb60a (diff)
Clean up TODO comments
-rw-r--r--TODO.md4
-rw-r--r--src/tui/app.rs41
-rw-r--r--src/tui/views.rs23
3 files changed, 19 insertions, 49 deletions
diff --git a/TODO.md b/TODO.md
index bd5924d..e322e7c 100644
--- a/TODO.md
+++ b/TODO.md
@@ -9,14 +9,14 @@ changing [soon](https://meta.stackexchange.com/q/348746).
### v0.2.0
#### Cursive interface for viewing questions and answers
-2. Handle focus with h,l
5. Init with smaller layout if terminal size smaller?
3. maybe cli `--auto-resize` option
3. make the default colors.toml file have a banging RGB > Hex > Defaults fallback
6. Small text at bottom with '?' to bring up key mapping dialog
7. Clean up! remove dupe between ListView and MdView by making a common trait
8. Possibly make `--arrow_keys_focus` option to toggle the arrow key consumption
-9. Maybe **ESC** cycles layout in the opposite direction?
+9. Maybe **ESC** cycles layout in the opposite direction? And stops at
+ BothColumns?
#### other
1. Use [par_iter](https://github.com/rayon-rs/rayon) for text preprocess & parsing?
diff --git a/src/tui/app.rs b/src/tui/app.rs
index 7280cac..f40021d 100644
--- a/src/tui/app.rs
+++ b/src/tui/app.rs
@@ -16,37 +16,6 @@ use crate::config;
use crate::error::Result;
use crate::stackexchange::{Answer, Question};
-// -----------------------------------------
-// |question title list|answer preview list| 1/3
-// -----------------------------------------
-// |question body |answer body | 2/3
-// -----------------------------------------
-// TODO <shift+HJKL> moves layout boundaries
-// TODO <hjkl> to move focus? at least for lists..
-// TODO <space> to cycle layout
-// TODO <?> to bring up key mappings
-// TODO query initial term size to choose initial layout
-
-// TODO Circular Focus handles layout & focus & stuff
-// TODO these might be "layers" ?
-
-// TODO make my own views for lists, md, etc, and use cursive::inner_getters!
-// (or at least type synonyms)
-// and abstract out the common builder funcs
-
-//pub struct App<'a> {
-//pub stackexchange: StackExchange,
-///// the questions matching the current query
-//pub question_list: StatefulList<Question>,
-///// the answers to a single question (i.e. the answer list currently shown)
-//pub answer_list: StatefulList<Answer>,
-//pub questions: Vec<Question>,
-//pub layout: Layout,
-//pub focus: Focus,
-//pub mode: Mode,
-//pub ratio: (u32, u32),
-//}
-
// TODO maybe a struct like Tui::new(stackexchange) creates App::new and impls tui.run()?
// TODO take async questions
// TODO take the entire SE struct for future questions
@@ -54,10 +23,6 @@ pub fn run(qs: Vec<Question>) -> Result<()> {
let mut siv = cursive::default();
siv.load_theme_file(config::theme_file_name()?).unwrap(); // TODO dont unwrap
- //app state
- //put this in siv.set_user_data? hmm
- //TODO maybe this isn't necessary until multithreading
-
let question_map: HashMap<u32, Question> = qs.clone().into_iter().map(|q| (q.id, q)).collect();
let question_map = Arc::new(question_map);
let answer_map: HashMap<u32, Answer> = qs
@@ -77,7 +42,6 @@ pub fn run(qs: Vec<Question>) -> Result<()> {
move |s, qid| question_selected_callback(question_map.clone(), s, qid),
);
- // TODO init with qs[0].answers ?
let answer_list_view = ListView::new(Name::AnswerList, move |s, aid| {
let a = answer_map.get(aid).unwrap();
s.call_on_name(NAME_ANSWER_VIEW, |v: &mut MdView| v.set_content(&a.body));
@@ -104,7 +68,6 @@ pub fn run(qs: Vec<Question>) -> Result<()> {
Ok(())
}
-// TODO need to get size of question list view, as this will change depending on layout
fn question_selected_callback(
question_map: Arc<HashMap<u32, Question>>,
mut s: &mut Cursive,
@@ -116,13 +79,13 @@ fn question_selected_callback(
s.call_on_name(NAME_QUESTION_VIEW, |v: &mut MdView| {
v.set_content(&q.body);
})
- .expect("TODO: make sure this is callable: setting question body on view");
+ .expect("Panic: setting question view content failed");
// Update answer list view
let cb = s
.call_on_name(NAME_ANSWER_LIST, |v: &mut ListView| {
v.reset_with_all(q.answers.iter().map(|a| (preview_answer(x, a), a.id)))
})
- .expect("TODO why would this ever fail");
+ .expect("Panic: setting answer list content failed");
cb(&mut s)
}
diff --git a/src/tui/views.rs b/src/tui/views.rs
index b49d5ac..b0d0224 100644
--- a/src/tui/views.rs
+++ b/src/tui/views.rs
@@ -165,7 +165,9 @@ impl ListView {
where
F: FnOnce(&mut SelectView<u32>) -> R,
{
- self.view.call_on_name(&self.inner_name, cb).expect("TODO")
+ self.view
+ .call_on_name(&self.inner_name, cb)
+ .expect("Panic: Call on select_view failed")
}
pub fn set_take_focus(&mut self, take: bool) {
@@ -354,7 +356,7 @@ impl LayoutView {
view,
layout_invalidated: true,
size_invalidated: true,
- layout: Layout::BothColumns, // TODO choose this based on initial width?
+ layout: Layout::BothColumns,
})
.with_name(NAME_FULL_LAYOUT)
}
@@ -372,7 +374,6 @@ impl LayoutView {
}
}
- // TODO wtf is going on here
fn resize(&mut self, size: Vec2) {
let LayoutViewSizing {
width,
@@ -466,10 +467,10 @@ impl LayoutView {
let f: Rc<dyn Fn(&mut ListView)> = Rc::new(move |v| f(v));
self.view
.call_on_name(NAME_QUESTION_LIST, &*f)
- .expect("TODO: call on question list failed");
+ .expect("Panic: call on question list failed");
self.view
.call_on_name(NAME_ANSWER_LIST, &*f)
- .expect("TODO: call on answer list failed");
+ .expect("Panic: call on answer list failed");
}
fn call_on_md_views<F>(&mut self, f: F) -> ()
@@ -479,10 +480,10 @@ impl LayoutView {
let f: Rc<dyn Fn(&mut MdView)> = Rc::new(move |v| f(v));
self.view
.call_on_name(NAME_QUESTION_VIEW, &*f)
- .expect("TODO: call on question view failed");
+ .expect("Panic: call on question view failed");
self.view
.call_on_name(NAME_ANSWER_VIEW, &*f)
- .expect("TODO: call on answer view failed");
+ .expect("Panic: call on answer view failed");
}
fn get_focused_index(&self) -> Vec2 {
@@ -519,7 +520,6 @@ impl<T: View> ViewWrapper for VimBindingsView<T> {
cursive::wrap_impl!(self.view: T);
fn wrap_on_event(&mut self, event: Event) -> EventResult {
- // TODO add more
match event {
Event::Char('g') => {
if let Some(Event::Char('g')) = self.last_event {
@@ -528,6 +528,13 @@ impl<T: View> ViewWrapper for VimBindingsView<T> {
}
self.last_event = Some(Event::Char('g'));
}
+ Event::Char('Z') => {
+ if let Some(Event::Char('Z')) = self.last_event {
+ self.last_event = None;
+ return EventResult::with_cb(|s| s.quit());
+ }
+ self.last_event = Some(Event::Char('Z'));
+ }
_ => self.last_event = None,
}
match event {