diff options
author | Sam Tay <sam.chong.tay@gmail.com> | 2020-06-08 00:00:51 -0700 |
---|---|---|
committer | Sam Tay <sam.chong.tay@gmail.com> | 2020-06-08 00:03:59 -0700 |
commit | 28b2629565149e381440c80f83732386eb99887c (patch) | |
tree | 5a6dbb9ecb5f41276da5a1eec2ef9c25756c5935 | |
parent | 1bf39e9128b67e234aa0306ee19b41342bd8c4e1 (diff) |
Print top answer in styled markdownv0.1.0
-rw-r--r-- | TODO.md | 28 | ||||
-rw-r--r-- | roadmap.md | 34 | ||||
-rw-r--r-- | src/main.rs | 17 |
3 files changed, 43 insertions, 36 deletions
@@ -1,9 +1,26 @@ # TODO -### initial release -3. Parse markdown (`pulldown_cmark`) -4. Maybe default --validate-sites off (parsing 30k file a big hit) -5. Print to stderr in [style](https://github.com/BurntSushi/termcolor) +### v0.1.1 +1. Touch up CLI and all that + +### v0.2.0 +3. Termimad interface for viewing questions and answers +1. Add `lucky: bool` to config, but +2. add --lucky and --no-lucky conflicting flags to cli +3. If --lucky, async get 1 result while getting limit results +4. Display with [space] to see more, any other key to exit. + +### v0.2.1 +1. Site can be multiple +2. do tokio async on SE api +3. add warning to README about throttling on excessive requests + +### v0.3.0 +1. Duckduck go search ftw, e.g. +``` +(site:stackoverflow.com OR site:unix.stackexchange.com) what is linux +``` +etc. ### resources for later 0. [Intro to async rust](http://jamesmcm.github.io/blog/2020/05/06/a-practical-introduction-to-async-programming-in-rust/) @@ -11,12 +28,11 @@ 2. Parallel calls against multiple sites [vid](https://www.youtube.com/watch?v=O-LagKc0MPA) 0. OR JUST THREADS [see here](https://rust-lang.github.io/async-book/01_getting_started/02_why_async.html) 3. [config mgmt](https://github.com/rust-cli/confy) or just use directories -4. Test if pre-made filter can be used for various api keys 5. Add sort option, e.g. relevance|votes|date 6. Google stuff [scraping with reqwest](https://rust-lang-nursery.github.io/rust-cookbook/web/scraping.html)) 8. Keep track of quota in a data file, inform user when getting close? 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) +10 nah look at [termimad example](https://github.com/Canop/whalespotter) @@ -1,33 +1,27 @@ # roadmap ### v0.1.0 -1. Set up CLI with options (assume --lucky) -2. Hit SO API -3. Markdown parser -4. End-to-end synchronous --lucky output +[x] Set up CLI with options (assume --lucky) +[x] Hit SO API +[x] Markdown parser +[x] End-to-end synchronous --lucky output ### v0.1.1 -1. Add xdga config +[x] Add xdga config +[ ] Finishing touches on cli opts like --set-api-key, etc. ### v0.2.0 -1. Add --no-lucky option -2. For --lucky, async parsing first q/a, then the rest -3. Tui-rs interface for viewing multiple results +[ ] Add --no-lucky option +[ ] For --lucky, async parsing first q/a, then the rest +[ ] Termimad interface for viewing multiple results ### v0.2.1 -1. Support multiple --site args & searches +[ ] Support multiple --site args & searches ### v0.3.0 -1. Add google scraper + helpful error messages +[ ] Add duckduckgo scraper ### at some point -1. cross-platform release binaries -2. per platform package mgmt - -## deps -1. clap -2. serde-json -2. pulldown-cmark (?) -3. crossterm -4. tui-rs -5. reqwest + scraper for google +[ ] cross-platform release binaries +[ ] per platform package mgmt +[ ] testing diff --git a/src/main.rs b/src/main.rs index 5e91580..cad09a7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,13 +4,12 @@ mod error; mod macros; mod stackexchange; -use config::Config; use crossterm::style::Color; use error::{Error, ErrorKind}; use lazy_static::lazy_static; use minimad::mad_inline; use stackexchange::{LocalStorage, StackExchange}; -use termimad::MadSkin; +use termimad::{CompoundStyle, MadSkin}; fn main() { (|| { @@ -20,8 +19,8 @@ fn main() { let mut ls = LocalStorage::new()?; // TODO style configuration let mut skin = MadSkin::default(); - skin.inline_code.set_fg(Color::Cyan); - skin.code_block.set_fg(Color::Cyan); + skin.inline_code = CompoundStyle::with_fg(Color::Cyan); + skin.code_block.set_fgbg(Color::Cyan, termimad::gray(20)); if opts.update_sites { ls.update_sites()?; @@ -74,12 +73,8 @@ fn main() { Err(e) => return Err(e), } - let se = StackExchange::new(Config { - api_key: Some(String::from("8o9g7WcfwnwbB*Qp4VsGsw((")), // TODO remove when releasing - ..config - }); - if let Some(q) = opts.query { + let se = StackExchange::new(config); let que = se.search(&q)?; let ans = que .first() @@ -92,7 +87,9 @@ fn main() { this shouldn't be possible!", ) })?; - println!("{}", ans.body); + // TODO eventually do this in the right place, e.g. abstract out md parser & do within threads + let md = ans.body.replace("<kbd>", "**[").replace("</kbd>", "]**"); + skin.print_text(&md); } Ok(()) |