From: Harishankar Date: Sat, 30 May 2020 10:24:01 +0000 (+0530) Subject: Changed coloured output to use colored instead of ansi_term X-Git-Tag: 0.1-a~5 X-Git-Url: https://harishankar.org/repos/?a=commitdiff_plain;h=a550442ff655e75c85edc1d0d591c34a1cc4380c;p=evpf.git Changed coloured output to use colored instead of ansi_term Changed the package from ansi_term to colored to display colour in terminal --- diff --git a/Cargo.lock b/Cargo.lock index 9a08007..95687ca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10,11 +10,24 @@ dependencies = [ ] [[package]] -name = "ansi_term" -version = "0.12.1" +name = "atty" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + +[[package]] +name = "colored" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4ffc801dacf156c5854b9df4f425a626539c3a6ef7893cc0c5084a23f0b6c59" +dependencies = [ + "atty", + "lazy_static", "winapi", ] @@ -22,16 +35,31 @@ dependencies = [ name = "evpf" version = "0.1.0" dependencies = [ - "ansi_term", + "colored", "regex", ] +[[package]] +name = "hermit-abi" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91780f809e750b0a89f5544be56617ff6b1227ee485bcb06ebe10cdf89bd3b71" +dependencies = [ + "libc", +] + [[package]] name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +[[package]] +name = "libc" +version = "0.2.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9457b06509d27052635f90d6466700c65095fdf75409b3fbdd903e988b886f49" + [[package]] name = "memchr" version = "2.3.3" diff --git a/Cargo.toml b/Cargo.toml index c4e36c3..bac1457 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,4 +8,4 @@ edition = "2018" [dependencies] regex="1" -ansi_term="0.12" +colored="1.9.3" diff --git a/src/main.rs b/src/main.rs index 2154ba5..98532ff 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,7 @@ use std::io; use std::io::Write; use regex::Regex; -use ansi_term::Colour; -use ansi_term::Style; +use colored::*; use std::env; const ILLEGAL_EXP : &'static str = "Illegal Expression"; @@ -159,12 +158,12 @@ fn main() { if res.is_ok () { let restxt = format! ("{}: {}", RESULT, res.unwrap()); - println! ("{}", Colour::Green.paint (restxt)); + println! ("{}", restxt.green ()); } else { // print the error in purple let errtxt = format! ("{}: {}", ERROR, res.unwrap_err()); - eprintln! ("{}", Colour::Purple.paint (errtxt)); + eprintln! ("{}", errtxt.purple ()); } } else { @@ -178,7 +177,7 @@ fn main() { // loop until a blank line is received loop { expr.clear (); - print!("{}", Style::new().bold().paint("evpf>")); + print!("{}", "evpf>".bold() ); io::stdout().flush ().expect (ERR_FLUSHING); // read a line of text io::stdin().read_line (&mut expr).expect (ERR_READING_LINE); @@ -191,7 +190,7 @@ fn main() { } else if expr == "?" || expr == "h" || expr == "H" { // display help text for text in HELP_TEXT.iter() { - println! ("{}", Colour::Cyan.paint(*text)); + println! ("{}", text.cyan() ); } continue; @@ -207,13 +206,13 @@ fn main() { if res.is_ok () { let restxt = format! ("{}: {}", RESULT, res.unwrap()); - println! ("{}", Colour::Green.paint (restxt)); + println! ("{}", restxt.green ()); } else { // print the error in purple let errtxt = format! ("{}: {}", ERROR, res.unwrap_err()); - eprintln! ("{}", Colour::Purple.paint (errtxt)); - eprintln! ("{}", Colour::Purple.paint (ERROR_HELP)); + eprintln! ("{}", errtxt.purple()); + eprintln! ("{}", ERROR_HELP.purple()); } } }