From 8fc5f68c23d158e1d15b9d9a5c0580d823f261b2 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 3 Jan 2016 20:10:03 +0100 Subject: [PATCH 1/4] Remove dep: rustty --- Cargo.lock | 26 -------------------------- Cargo.toml | 1 - 2 files changed, 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0c0933b7..336021f3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12,7 +12,6 @@ dependencies = [ "open 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "prettytable-rs 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", - "rustty 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "term 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", @@ -114,11 +113,6 @@ dependencies = [ "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "lazy_static" -version = "0.1.15" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "libc" version = "0.1.10" @@ -145,15 +139,6 @@ dependencies = [ "libc 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "nix" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bitflags 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "nom" version = "0.3.11" @@ -212,17 +197,6 @@ name = "rustc-serialize" version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "rustty" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "lazy_static 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "nix 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "term 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "serde" version = "0.6.1" diff --git a/Cargo.toml b/Cargo.toml index 04479644..30c0b1b5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,6 @@ serde = "0.6.1" serde_json = "0.6.0" clap = { version = "1.4.5", features = ["yaml"] } -rustty = "0.1.9" term = "0.2.12" term_grid = "0.1.2" prettytable-rs = "0.4.0" From a5cbac534edaa1653e013cfc5cf95948089311ac Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 3 Jan 2016 20:11:15 +0100 Subject: [PATCH 2/4] Remove dep: term --- Cargo.lock | 1 - Cargo.toml | 1 - 2 files changed, 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 336021f3..a6fa1a2a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14,7 +14,6 @@ dependencies = [ "regex 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "term 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", "term_grid 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "url 0.2.37 (registry+https://github.com/rust-lang/crates.io-index)", "uuid 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 30c0b1b5..259fae6a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,6 @@ serde = "0.6.1" serde_json = "0.6.0" clap = { version = "1.4.5", features = ["yaml"] } -term = "0.2.12" term_grid = "0.1.2" prettytable-rs = "0.4.0" open = "1.1.0" From e1407c75a3be4e97ad40138828b86df9a8f76d16 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 3 Jan 2016 20:12:08 +0100 Subject: [PATCH 3/4] Add dep: ansi_term --- Cargo.lock | 6 ++++++ Cargo.toml | 1 + src/main.rs | 1 + 3 files changed, 8 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index a6fa1a2a..105498e3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,7 @@ name = "imag" version = "0.1.0" dependencies = [ + "ansi_term 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)", "clap 1.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "config 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -41,6 +42,11 @@ name = "ansi_term" version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "ansi_term" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "bitflags" version = "0.3.2" diff --git a/Cargo.toml b/Cargo.toml index 259fae6a..9a513a53 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,4 +27,5 @@ prettytable-rs = "0.4.0" open = "1.1.0" itertools = "0.4.5" hoedown = "3.0.3" +ansi_term = "0.7.1" diff --git a/src/main.rs b/src/main.rs index a91072b6..6449cea6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,6 +11,7 @@ extern crate url; extern crate config; extern crate open; extern crate itertools; +extern crate ansi_term; pub use cli::CliConfig; pub use configuration::Configuration; From d775750362e59164f7795b1783557d14336251c2 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 3 Jan 2016 20:28:42 +0100 Subject: [PATCH 4/4] Color some info!() output --- src/main.rs | 4 +++- src/module/bm/mod.rs | 26 ++++++++++++++++---------- src/module/notes/mod.rs | 25 +++++++++++++++++-------- src/ui/file.rs | 8 ++++++-- 4 files changed, 42 insertions(+), 21 deletions(-) diff --git a/src/main.rs b/src/main.rs index 6449cea6..3348a680 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,6 +31,8 @@ pub use module::bm::BM; pub use module::notes::Notes; fn main() { + use ansi_term::Colour::Yellow; + let yaml = load_yaml!("../etc/cli.yml"); let app = App::from_yaml(yaml); let config = CliConfig::new(app); @@ -53,5 +55,5 @@ fn main() { _ => false, }; - info!("Module execution ended with {}", res); + info!("{}", Yellow.paint(format!("Module execution ended with {}", res))); } diff --git a/src/module/bm/mod.rs b/src/module/bm/mod.rs index 251645f0..ba08f7d8 100644 --- a/src/module/bm/mod.rs +++ b/src/module/bm/mod.rs @@ -38,6 +38,7 @@ impl<'a> BM<'a> { * Subcommand: add */ fn command_add(&self, matches: &ArgMatches) -> bool { + use ansi_term::Colour::{Green, Yellow, Red}; use std::process::exit; use self::header::build_header; @@ -69,7 +70,7 @@ impl<'a> BM<'a> { .store() .load(self, &parser, &fileid) .map(|file| { - info!("Created file in memory: {}", fileid); + info!("{}", Yellow.paint(format!("Created file in memory: {}", fileid))); self.rt .store() .persist(&parser, file) @@ -77,9 +78,9 @@ impl<'a> BM<'a> { .unwrap_or(false); if result { - info!("Adding worked"); + info!("{}", Red.paint("Adding worked")); } else { - info!("Adding failed"); + info!("{}", Green.paint("Adding failed")); } result @@ -156,6 +157,7 @@ impl<'a> BM<'a> { * Subcommand: open */ fn command_open(&self, matches: &ArgMatches) -> bool { + use ansi_term::Colour::{Green, Yellow, Red}; use open; let parser = Parser::new(JsonHeaderParser::new(None)); @@ -175,10 +177,10 @@ impl<'a> BM<'a> { let f = file.deref().borrow(); get_url_from_header(f.header()).map(|url| { if open::that(&url[..]).is_ok() { - info!("open({})", url); + info!("{}", Green.paint(format!("open({})", url))); true } else { - info!("could not open({})", url); + info!("{}", Red.paint(format!("could not open({})", url))); false } }) @@ -194,8 +196,8 @@ impl<'a> BM<'a> { }); let (succ, fail) = result; - info!("open() succeeded for {} files", succ); - info!("open() failed for {} files", fail); + info!("{}", Green.paint(format!("open() succeeded for {} files", succ))); + info!("{}", Red.paint(format!( "open() failed for {} files", fail))); return fail == 0; } @@ -203,6 +205,8 @@ impl<'a> BM<'a> { * Subcommand: remove */ fn command_remove(&self, matches: &ArgMatches) -> bool { + use ansi_term::Colour::{Green, Yellow, Red}; + let parser = Parser::new(JsonHeaderParser::new(None)); let filter = { @@ -233,8 +237,8 @@ impl<'a> BM<'a> { let (worked, failed) = result; - info!("Removing succeeded for {} files", worked); - info!("Removing failed for {} files", failed); + info!("{}", Green.paint(format!("Removing succeeded for {} files", worked))); + info!("{}", Red.paint(format!( "Removing failed for {} files", failed))); return failed == 0; } @@ -291,6 +295,8 @@ impl<'a> BM<'a> { impl<'a> Module<'a> for BM<'a> { fn exec(&self, matches: &ArgMatches) -> bool { + use ansi_term::Colour::{Green, Yellow, Red}; + match matches.subcommand_name() { Some("add") => { self.command_add(matches.subcommand_matches("add").unwrap()) @@ -321,7 +327,7 @@ impl<'a> Module<'a> for BM<'a> { }, Some(_) | None => { - info!("No command given, doing nothing"); + info!("{}", Red.bold().paint("No command given, doing nothing")); false }, } diff --git a/src/module/notes/mod.rs b/src/module/notes/mod.rs index 739e3ba3..7662f851 100644 --- a/src/module/notes/mod.rs +++ b/src/module/notes/mod.rs @@ -34,6 +34,7 @@ impl<'a> Notes<'a> { fn command_add(&self, matches: &ArgMatches) -> bool { use std::process::exit; + use ansi_term::Colour::Yellow; use self::header::build_header; use ui::external::editor::let_user_provide_content; @@ -57,13 +58,14 @@ impl<'a> Notes<'a> { .store() .load(self, &parser, &fileid) .and_then(|file| { - info!("Created file in memory: {}", fileid); + info!("{}", Yellow.paint(format!("Created file in memory: {}", fileid))); Some(self.rt.store().persist(&parser, file)) }) .unwrap_or(false) } fn command_edit(&self, matches: &ArgMatches) -> bool { + use ansi_term::Colour::{Red, Green}; use ui::external::editor::edit_content; let parser = Parser::new(JsonHeaderParser::new(None)); @@ -116,13 +118,14 @@ impl<'a> Notes<'a> { let (worked, failed) = result; - info!("Editing succeeded for {} files", worked); - info!("Editing failed for {} files", failed); + info!("{}", Green.paint(format!("Editing succeeded for {} files", worked))); + info!("{}", Red.paint(format!( "Editing failed for {} files", failed))); return failed == 0; } fn command_list(&self, matches: &ArgMatches) -> bool { + use ansi_term::Colour::{Red, Green}; use ui::file::{FilePrinter, TablePrinter}; use self::header::get_name_from_header; use self::header::get_tags_from_header; @@ -162,6 +165,7 @@ impl<'a> Notes<'a> { } fn command_links(&self, matches: &ArgMatches) -> bool { + use ansi_term::Colour::{Red, Green}; use module::helpers::content::markdown::MarkdownParser; use ui::file::{FilePrinter, TablePrinter}; use util::is_url; @@ -260,13 +264,15 @@ impl<'a> Notes<'a> { debug!("Not printing table as there wouldn't be any entries in it"); } - info!("Listing links succeeded for {} files", worked); - info!("Listing links failed for {} files", failed); + info!("{}", Green.paint(format!("Listing links succeeded for {} files", worked))); + info!("{}", Red.paint( format!("Listing links failed for {} files", failed))); return failed == 0; } fn command_remove(&self, matches: &ArgMatches) -> bool { + use ansi_term::Colour::{Red, Green}; + let parser = Parser::new(JsonHeaderParser::new(None)); let filter = { @@ -297,8 +303,9 @@ impl<'a> Notes<'a> { let (worked, failed) = result; - info!("Removing succeeded for {} files", worked); - info!("Removing failed for {} files", failed); + + info!("{}", Green.paint(format!("Removing succeeded for {} files", worked))); + info!("{}", Red.paint( format!("Removing failed for {} files", failed))); return failed == 0; } @@ -343,6 +350,8 @@ impl<'a> Notes<'a> { impl<'a> Module<'a> for Notes<'a> { fn exec(&self, matches: &ArgMatches) -> bool { + use ansi_term::Colour::Red; + match matches.subcommand_name() { Some("add") => { self.command_add(matches.subcommand_matches("add").unwrap()) @@ -377,7 +386,7 @@ impl<'a> Module<'a> for Notes<'a> { }, Some(_) | None => { - info!("No command given, doing nothing"); + info!("{}", Red.bold().paint("No command given, doing nothing")); false }, } diff --git a/src/ui/file.rs b/src/ui/file.rs index 3feb8eab..ce1cd27e 100644 --- a/src/ui/file.rs +++ b/src/ui/file.rs @@ -92,25 +92,29 @@ impl FilePrinter for SimplePrinter { } fn print_file(&self, f: Rc>) { + use ansi_term::Colour::Cyan; + if self.debug { debug!("{:?}", f); } else if self.verbose { info!("{}", &*f.deref().borrow()); } else { - info!("[File]: {}", f.deref().borrow().id()); + info!("{}: {}", Cyan.paint("[File]"), f.deref().borrow().id()); } } fn print_file_custom(&self, file: Rc>, f: &F) where F: Fn(Rc>) -> Vec { + use ansi_term::Colour::Cyan; + let s = f(file).join(" "); if self.debug { debug!("{:?}", s); } else if self.verbose { info!("{}", s); } else { - info!("[File]: {}", s); + info!("{}: {}", Cyan.paint("[File]"), s); } }