summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Tay <sam.chong.tay@gmail.com>2020-06-21 22:02:30 -0700
committerSam Tay <sam.chong.tay@gmail.com>2020-06-21 22:02:30 -0700
commitfdc4092d0276259c47a14cf2cc52c933fec633e4 (patch)
tree3c7583dae22640d446d088ec9a13a4faaeee4780
parent01ffac500ab19d54548f0f69bf40c59f0ecb02b1 (diff)
Fix resizing issue
Turns out this is an issue running ncurses after crossterm
-rw-r--r--Cargo.lock1
-rw-r--r--Cargo.toml14
-rw-r--r--README.md57
-rw-r--r--TODO.md23
-rw-r--r--src/tui/views.rs29
-rw-r--r--src/utils.rs2
6 files changed, 74 insertions, 52 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 1b4ea90..3d8f148 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -323,6 +323,7 @@ dependencies = [
"ahash",
"cfg-if",
"crossbeam-channel",
+ "crossterm",
"cursive_core",
"enumset",
"lazy_static",
diff --git a/Cargo.toml b/Cargo.toml
index b9126e9..25d5708 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -27,4 +27,16 @@ crossterm = { version = "0.17", features = ["event-stream"] }
pulldown-cmark = { version = "0.7", default-features = false }
phf = { version = "0.8", features = ["macros"] }
unicode-width = "0.1.5"
-cursive = { version = "0.15", features = ["toml"] }
+
+[dependencies.cursive]
+version = "0.15"
+default-features = false
+features = ["toml"]
+
+[features]
+default = ["cursive/termion-backend"]
+windows = ["cursive/crossterm-backend"]
+termion-backend = ["cursive/termion-backend"]
+ncurses-backend = ["cursive/ncurses-backend"]
+pancurses-backend = ["cursive/pancurses-backend"]
+crossterm-backend = ["cursive/crossterm-backend"]
diff --git a/README.md b/README.md
index a383197..7b773c3 100644
--- a/README.md
+++ b/README.md
@@ -2,6 +2,46 @@
**Note:** under development, not ready for prime time.
+# documentation
+
+### api keys
+According to the [StackExchange
+docs](https://api.stackexchange.com/docs/throttle), most users should be fine
+without generating a personal API key (10k requests per IP per day). If you do
+run into throttling issues, get a key
+[here](https://stackapps.com/apps/oauth/register) and tell `so` to use it:
+```
+so --set-api-key <KEY>
+```
+
+### multi-site searching
+As stated in the docs linked above,
+
+> If a single IP is making more than 30 requests a second, new requests will be dropped.
+
+So, don't go crazy with the multi-site search, since it is all done in parallel.
+In particular, if you specify more than 30 sites, SE will likely ban you for a short time.
+
+### selecting a backend
+Crossterm's level of support is awesome, but it comes at a price. On my machine,
+the app kind of flashes between draws quite a bit. If you are on Mac, Linux, or
+Redox, your best bet is to compile with default features which uses the
+termion backend. If you are on windows, use crossterm, but know it will be
+slightly jumpy.
+
+If the crossterm folks figure out a fix for [allowing ncurses to receive resize events](),
+and you have ncurses installed on your system, then you should use the
+ncurses backend, or the pancurses backend if you are on Windows. Just know that
+currently if you choose this option, you won't be able to resize the terminal
+window while the TUI is open.
+
+default = ["cursive/termion-backend"]
+ncurses-backend = ["cursive/ncurses-backend"]
+pancurses-backend = ["cursive/pancurses-backend"]
+crossterm-backend = ["cursive/crossterm-backend"]
+
+# notes to self
+
### async considerations
Implemented async with tokio in ec92f93, but unclear if this is necessary. For
< 10 simultaneous network requests, it might be better and simpler to just use
@@ -25,23 +65,6 @@ export RUST_BACKTRACE=full
cargo run -- how do I exit Vim > test.txt 2>&1
```
-### api keys
-According to the [StackExchange
-docs](https://api.stackexchange.com/docs/throttle), most users should be fine
-without generating a personal API key (10k requests per IP per day). If you do
-run into throttling issues, get a key
-[here](https://stackapps.com/apps/oauth/register) and tell `so` to use it:
-```
-so --set-api-key <KEY>
-```
-
-### multi-site searching
-As stated in the docs linked above,
-
-> If a single IP is making more than 30 requests a second, new requests will be dropped.
-
-So, don't go crazy with the multi-site search, since it is all done in parallel.
-In particular, if you specify more than 30 sites, SE will likely ban you for a short time.
diff --git a/TODO.md b/TODO.md
index f3724e3..056472f 100644
--- a/TODO.md
+++ b/TODO.md
@@ -1,7 +1,5 @@
# TODO
-[ ] Fix resizing. Something in `wait_for_char` screws up the future cursive app...
-
### v0.3.0
1. Duckduck go search ftw, e.g.
```
@@ -9,16 +7,6 @@
```
etc.
-#### Tech debt and low hanging fruit
-1. Use [`par_iter`](https://github.com/rayon-rs/rayon) for text preprocess &
- parsing. In particular the `tui::markdown::preprocess` function should just
- get called on all markdown as soon as its received from stack exchange; this
- is prime for parallelization.
-2. Also, we could `par_iter` the initial q&a data to SpannedStrings from the
- start, so that it's not done on the fly...
-3. The rest of the questions should really start being fetched while waiting for
- the user to press [Enter]... maybe start with just simple threads?
-
### Endless future improvements for the TUI
1. Init with smaller layout depending on initial screen size.
2. Maybe cli `--auto-resize` option.
@@ -45,13 +33,10 @@ etc.
6. Google stuff [scraping with reqwest](https://rust-lang-nursery.github.io/rust-cookbook/web/scraping.html))
#### distribution
-7. App Distribution
- [cross-platform binaries via travis](https://github.com/rustwasm/wasm-pack/blob/51e6351c28fbd40745719e6d4a7bf26dadd30c85/.travis.yml#L74-L91)
- also see lobster script in this [repo](https://git.sr.ht/~wezm/lobsters).
-9. Great tui-rs [example app](https://github.com/SoptikHa2/desed/blob/master/src/ui/tui.rs)
-11. general CI & deploy [info](https://rust-cli.github.io/book/tutorial/packaging.html)
-12. window binaries deployed via [github actions](https://github.com/rust-av/av-metrics)
-13. oh game over [dawg](https://github.com/japaric/trust)
+1. oh game over [dawg](https://github.com/japaric/trust)
+2. also, use [feature flags]() to select backend. Only use crossterm on Windows
+ since it is rather jumpy...
+
#### ideas
5. Add sort option, e.g. relevance|votes|date
diff --git a/src/tui/views.rs b/src/tui/views.rs
index e4c8649..c131455 100644
--- a/src/tui/views.rs
+++ b/src/tui/views.rs
@@ -287,6 +287,7 @@ pub struct LayoutView {
layout: Layout,
layout_invalidated: bool,
size_invalidated: bool,
+ last_size: Option<Vec2>,
}
struct LayoutViewSizing {
@@ -305,31 +306,30 @@ impl ViewWrapper for LayoutView {
cursive::wrap_impl!(self.view: PaddedView<LinearLayout>);
fn wrap_on_event(&mut self, event: Event) -> EventResult {
- match event {
- Event::WindowResize => {
- println!("window resized");
- self.size_invalidated = true;
- }
- Event::Char(' ') => {
- self.cycle_layout();
- self.layout_invalidated = true;
- return EventResult::Consumed(None);
- }
- _ => (),
+ if let Event::Char(' ') = event {
+ self.cycle_layout();
+ self.layout_invalidated = true;
+ return EventResult::Consumed(None);
}
self.view.on_event(event)
}
fn wrap_required_size(&mut self, req: Vec2) -> Vec2 {
+ if self.last_size != Some(req) {
+ self.size_invalidated = true;
+ self.last_size = Some(req);
+ }
req
}
fn wrap_layout(&mut self, size: Vec2) {
- self.resize(size);
- self.relayout();
- self.layout_invalidated = false;
+ if self.layout_invalidated || self.size_invalidated {
+ self.resize(size);
+ self.relayout();
+ }
self.size_invalidated = false;
+ self.layout_invalidated = false;
self.view.layout(size);
}
@@ -354,6 +354,7 @@ impl LayoutView {
view,
layout_invalidated: true,
size_invalidated: true,
+ last_size: None,
layout: Layout::BothColumns,
})
.with_name(NAME_FULL_LAYOUT)
diff --git a/src/utils.rs b/src/utils.rs
index 560f186..e7a8830 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -26,8 +26,8 @@ pub fn create_file(filename: &PathBuf) -> Result<File> {
}
pub fn wait_for_char(c: char) -> Result<bool> {
- terminal::enable_raw_mode()?;
let mut pressed = false;
+ terminal::enable_raw_mode()?;
loop {
match read()? {
Event::Key(KeyEvent {