Skip to content

Commit

Permalink
使用termcolor取代colored
Browse files Browse the repository at this point in the history
  • Loading branch information
upsuper committed Jun 1, 2019
1 parent fbbaf1e commit 7da51bf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion coverage-check/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors = ["Xidorn Quan <me@upsuper.org>"]
edition = "2018"

[dependencies]
colored = "1.8.0"
termcolor = "1.0.4"

[dependencies.pinyin]
path = ".."
Expand Down
12 changes: 7 additions & 5 deletions coverage-check/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use colored::{Color, Colorize};
use pinyin::ToPinyin;
use std::collections::HashSet;
use std::io::{self, stdin, BufRead};
use std::io::{self, BufRead, Write};
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};

const CHARS: &[&[char]] = &[
&['a', 'ā', 'á', 'ǎ', 'à'],
Expand All @@ -14,7 +14,7 @@ const CHARS: &[&[char]] = &[

fn main() -> io::Result<()> {
let mut chars = HashSet::new();
let stdin = stdin();
let stdin = io::stdin();
for line in stdin.lock().lines() {
let line = line?;
for opt_pinyin in line.as_str().to_pinyin() {
Expand All @@ -23,16 +23,18 @@ fn main() -> io::Result<()> {
}
}
}
let mut stdout = StandardStream::stdout(ColorChoice::Auto);
for line in CHARS.iter() {
for ch in line.iter() {
let color = if chars.contains(ch) {
Color::Green
} else {
Color::Red
};
print!("{}\t", ch.to_string().color(color).bold());
stdout.set_color(ColorSpec::new().set_fg(Some(color)).set_bold(true))?;
write!(&mut stdout, "{}\t", ch)?;
}
println!();
writeln!(&mut stdout)?;
}
Ok(())
}

0 comments on commit 7da51bf

Please sign in to comment.