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 /src/main.rs | |
parent | 1bf39e9128b67e234aa0306ee19b41342bd8c4e1 (diff) |
Print top answer in styled markdownv0.1.0
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 17 |
1 files changed, 7 insertions, 10 deletions
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(()) |