summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSam Tay <sam.chong.tay@gmail.com>2020-06-25 19:48:16 -0700
committerSam Tay <sam.chong.tay@gmail.com>2020-06-26 10:19:06 -0700
commit408660cb5d9a900921200d9cc43943e912f815e6 (patch)
tree4346ceec5f98b9b384033c2dbf6dceffc322775b /src
parentcea8ac496f97a36790bdbe3bbb3a87bf9c91a7f4 (diff)
Fix various small bugs
Diffstat (limited to 'src')
-rw-r--r--src/error.rs2
-rw-r--r--src/main.rs12
-rw-r--r--src/stackexchange/scraper.rs29
-rw-r--r--src/stackexchange/search.rs7
4 files changed, 25 insertions, 25 deletions
diff --git a/src/error.rs b/src/error.rs
index 53ba23c..ec76943 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -28,7 +28,7 @@ pub enum Error {
ScrapingError(String),
#[error("Couldn't find a suitable project directory; is your OS supported?")]
ProjectDir,
- #[error("Sorry, couldn't find any answers for your query")]
+ #[error("Sorry, couldn't find any answers to your question")]
NoResults,
}
diff --git a/src/main.rs b/src/main.rs
index a2d3b08..7ce78a1 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -6,23 +6,23 @@ mod term;
mod tui;
mod utils;
-use crate::stackexchange::Question;
-use crate::tui::markdown::Markdown;
use crossterm::style::Color;
-use error::{Error, Result};
use lazy_static::lazy_static;
use minimad::mad_inline;
-use stackexchange::{LocalStorage, Search};
-use term::mk_print_error;
use termimad::{CompoundStyle, MadSkin};
use tokio::runtime::Runtime;
use tokio::task;
+use error::{Error, Result};
+use stackexchange::{LocalStorage, Question, Search};
+use term::mk_print_error;
+use tui::markdown::Markdown;
+
fn main() -> Result<()> {
// Markdown styles (outside of TUI)
let mut skin = MadSkin::default();
skin.inline_code = CompoundStyle::with_fg(Color::Cyan);
- skin.code_block.set_fg(Color::Cyan);
+ skin.code_block.compound_style = CompoundStyle::with_fg(Color::Cyan);
let mut print_error = mk_print_error(&skin);
// Tokio runtime
diff --git a/src/stackexchange/scraper.rs b/src/stackexchange/scraper.rs
index 7c9047f..cdeef3c 100644
--- a/src/stackexchange/scraper.rs
+++ b/src/stackexchange/scraper.rs
@@ -147,25 +147,18 @@ fn parse_with_selector(
.attr("href")
.ok_or_else(|| Error::ScrapingError("Anchor with no href".to_string()))
.map(|href| percent_decode_str(href).decode_utf8_lossy().into_owned())?;
- sites
- .iter()
- .find_map(|(site_code, site_url)| {
- let id = question_url_to_id(site_url, &url)?;
- ordering.insert(id.to_owned(), count);
- match question_ids.entry(site_code.to_owned()) {
- Entry::Occupied(mut o) => o.get_mut().push(id),
- Entry::Vacant(o) => {
- o.insert(vec![id]);
- }
+ sites.iter().find_map(|(site_code, site_url)| {
+ let id = question_url_to_id(site_url, &url)?;
+ ordering.insert(id.to_owned(), count);
+ match question_ids.entry(site_code.to_owned()) {
+ Entry::Occupied(mut o) => o.get_mut().push(id),
+ Entry::Vacant(o) => {
+ o.insert(vec![id]);
}
- count += 1;
- Some(())
- })
- .ok_or_else(|| {
- Error::ScrapingError(
- "Search engine returned results outside of SE network".to_string(),
- )
- })?;
+ }
+ count += 1;
+ Some(())
+ });
if count >= limit as usize {
break;
}
diff --git a/src/stackexchange/search.rs b/src/stackexchange/search.rs
index 6cd4854..1357c80 100644
--- a/src/stackexchange/search.rs
+++ b/src/stackexchange/search.rs
@@ -86,6 +86,13 @@ impl Search {
SearchEngine::Google => self.search_by_scraper(Google).await,
SearchEngine::StackExchange => self.parallel_search_advanced().await,
}
+ .and_then(|qs| {
+ if qs.is_empty() {
+ Err(Error::NoResults)
+ } else {
+ Ok(qs)
+ }
+ })
}
/// Search query at duckduckgo and then fetch the resulting questions from SE.