From 6a911ece8fa3e1801e5d2c03dddfd11cdf324e53 Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sun, 21 Jul 2019 12:37:53 +0800 Subject: [PATCH] use rust_util --- Cargo.lock | 10 ++++++++++ Cargo.toml | 1 + src/main.rs | 5 ++--- src/util.rs | 24 ------------------------ 4 files changed, 13 insertions(+), 27 deletions(-) delete mode 100644 src/util.rs diff --git a/Cargo.lock b/Cargo.lock index 3c08d41..5222923 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -138,6 +138,7 @@ version = "0.1.0" dependencies = [ "argparse 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "json 0.11.14 (registry+https://github.com/rust-lang/crates.io-index)", + "rust_util 0.1.0 (git+https://github.com/jht5945/rust_util)", "term 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -207,6 +208,14 @@ dependencies = [ "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rust_util" +version = "0.1.0" +source = "git+https://github.com/jht5945/rust_util#8dd2f042609d8b3235f537cada75d891cf0d7b0c" +dependencies = [ + "term 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rustc-demangle" version = "0.1.15" @@ -300,6 +309,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" "checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" "checksum redox_users 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3fe5204c3a17e97dde73f285d49be585df59ed84b50a872baf416e73b62c3828" +"checksum rust_util 0.1.0 (git+https://github.com/jht5945/rust_util)" = "" "checksum rustc-demangle 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "a7f4dccf6f4891ebcc0c39f9b6eb1a83b9bf5d747cb439ec6fba4f3b977038af" "checksum scoped_threadpool 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "1d51f5df5af43ab3f1360b429fa5e0152ac5ce8c0bd6485cae490332e96846a8" "checksum syn 0.15.40 (registry+https://github.com/rust-lang/crates.io-index)" = "bc945221ccf4a7e8c31222b9d1fc77aefdd6638eb901a6ce457a3dc29d4c31e8" diff --git a/Cargo.toml b/Cargo.toml index 7ab042a..0a00cf9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,3 +8,4 @@ edition = "2018" argparse = "0.2.2" json = "0.11.14" term = "0.5.2" +rust_util = { git = "https://github.com/jht5945/rust_util" } diff --git a/src/main.rs b/src/main.rs index 59205b2..606dc37 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,7 @@ extern crate argparse; extern crate term; extern crate json; - -mod util; +extern crate rust_util; use std::{ fs::File, @@ -12,7 +11,7 @@ use std::{ } }; use argparse::{ArgumentParser, StoreTrue, Store}; -use util::*; +use rust_util::*; const VERSION: &str = "0.1"; diff --git a/src/util.rs b/src/util.rs deleted file mode 100644 index 4990ecd..0000000 --- a/src/util.rs +++ /dev/null @@ -1,24 +0,0 @@ -pub type XResult = Result>; - -#[allow(dead_code)] -pub enum MessageType { INFO, OK, WARN, ERROR, } - -pub fn print_message_ex(color: Option, h: &str, message: &str) { - let mut t = term::stdout().unwrap(); - match color { - Some(c) => t.fg(c).unwrap(), - None => (), - } - write!(t, "{}", h).unwrap(); - t.reset().unwrap(); - println!(" {}", message); -} - -pub fn print_message(mt: MessageType, message: &str) { - match mt { - MessageType::OK => print_message_ex(Some(term::color::GREEN), "[OK ]", message), - MessageType::WARN => print_message_ex(Some(term::color::YELLOW), "[WARN ]", message), - MessageType::ERROR => print_message_ex(Some(term::color::RED), "[ERROR]", message), - MessageType::INFO => print_message_ex(None, "[INFO]", message), - } -}