summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorSam Tay <sam.chong.tay@gmail.com>2020-06-07 18:01:22 -0700
committerSam Tay <sam.chong.tay@gmail.com>2020-06-07 18:01:22 -0700
commit556612119a77d8235904819a2f17a8ed82ca304c (patch)
treee59ee68b900af1744e4d5ba48830df080e9b1052 /src/main.rs
parent1942882d2825b205cec89c8cb5990d637ebdf838 (diff)
Start using termimad
Getting feet wet by scrapping manual crossterm calls and just letting termimad do the heavy lifting via markdown
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs30
1 files changed, 21 insertions, 9 deletions
diff --git a/src/main.rs b/src/main.rs
index 0f390df..9c75662 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -6,10 +6,14 @@ mod stackexchange;
mod term;
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 std::io::stderr;
-use term::ColoredOutput;
+use term::{prefix_err, ColoredOutput};
+use termimad::MadSkin;
fn main() {
(|| {
@@ -17,6 +21,10 @@ fn main() {
let config = opts.config;
let site = &config.site;
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);
if opts.update_sites {
ls.update_sites()?;
@@ -27,6 +35,7 @@ fn main() {
match sites.iter().map(|s| s.api_site_parameter.len()).max() {
Some(max_w) => {
for s in sites {
+ // TODO print as table!
println!("{:>w$}: {}", s.api_site_parameter, s.site_url, w = max_w);
}
}
@@ -43,14 +52,17 @@ fn main() {
match ls.validate_site(site) {
Ok(true) => (),
Ok(false) => {
- stderr()
- .queue_error(&format!("{} is not a valid StackExchange site.\n\n", site)[..])
- .queue_notice("If you think this is in error, try running\n\n")
- .queue_code("so --update-sites\n\n")
- .queue_notice_inline("to update the cached site listing. You can also run ")
- .queue_code_inline("so --list-sites")
- .queue_notice_inline(" to list all available sites.")
- .unsafe_flush();
+ print_error!(skin, "$0 is not a valid StackExchange site.\n\n", site)?;
+ // TODO what about using text wrapping feature?
+ print_notice!(
+ skin,
+ "If you think this is incorrect, try running\n\
+ ```\n\
+ so --update-sites\n\
+ ```\n\
+ to update the cached site listing. You can also run `so --list-sites` \
+ to list all available sites.",
+ )?;
return Ok(());
}
Err(Error {