mirror of
https://github.com/jht5945/prettyjson.git
synced 2025-12-27 17:20:05 +08:00
use rust_util
This commit is contained in:
@@ -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";
|
||||
|
||||
|
||||
24
src/util.rs
24
src/util.rs
@@ -1,24 +0,0 @@
|
||||
pub type XResult<T> = Result<T, Box<dyn std::error::Error>>;
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub enum MessageType { INFO, OK, WARN, ERROR, }
|
||||
|
||||
pub fn print_message_ex(color: Option<term::color::Color>, 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),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user