From eb79920efd704fdf1863785b6740a2eb060aad0c Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Sat, 7 Dec 2019 16:20:27 +0100 Subject: basic color support --- src/main.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index c8afd0f..e0d0e89 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,12 +6,14 @@ extern crate itertools; extern crate md5; extern crate reqwest; extern crate rusttype; +extern crate termcolor; extern crate xdg; #[macro_use] extern crate quick_error; use std::error::Error as StdError; use std::fmt; +use std::io::Write; mod api; mod bt; @@ -19,6 +21,7 @@ mod cache; mod render; use clap::{App, Arg, ArgMatches}; +use termcolor::{StandardStream, WriteColor, ColorSpec, Color, ColorChoice}; use api::{Api, Profession, Skill}; use bt::{BuildTemplate, ExtraData, Legend, TraitChoice, Traitline}; @@ -291,7 +294,13 @@ fn run() -> MainResult<()> { fn main() { let result = run(); if let Err(e) = result { - eprintln!("[Error] {}", e); + let mut error_color = ColorSpec::new(); + error_color.set_fg(Some(Color::Red)); + let mut stderr = StandardStream::stderr(ColorChoice::Auto); + stderr.set_color(&error_color); + write!(stderr, "[Error]"); + stderr.reset(); + writeln!(stderr, " {}", e); let mut source = e.source(); while let Some(s) = source { eprintln!(" caused by {}", s); -- cgit v1.2.3