Skip to content

Commit 4f106eb

Browse files
committed
refactor: change package termion to package colored
1 parent ae3908c commit 4f106eb

File tree

3 files changed

+136
-49
lines changed

3 files changed

+136
-49
lines changed

Cargo.lock

Lines changed: 127 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ authors = ["Tzu-Yin Hong <lili668668@gmail.com>"]
55
edition = "2018"
66

77
[dependencies]
8-
termion = "*"
8+
colored = "1.8.0"
99
serde = { version = "1.0", features = ["derive"] }
1010
serde_json = "1.0"

src/main.rs

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::fs::File;
22
use std::io;
33

4+
use colored::*;
45
use serde::{Deserialize, Serialize};
5-
use termion::{color, style};
66

77
#[derive(Debug, Serialize, Deserialize)]
88
struct Subject {
@@ -18,45 +18,25 @@ fn main() {
1818
let length = subjects.len();
1919
for (count, subject) in subjects.iter().enumerate() {
2020
loop {
21-
println!(
22-
"{}{}{}/{} 問題:{}{}",
23-
color::Fg(color::Cyan),
24-
style::Bold,
25-
count + 1,
26-
length,
27-
subject.question,
28-
style::Reset
29-
);
21+
let question = format!("{}/{} 問題:{}", count + 1, length, subject.question);
22+
println!("{}", question.cyan().bold());
3023

3124
let mut guess = String::new();
32-
println!(
33-
"{}請輸入答案:{}",
34-
color::Fg(color::LightBlack),
35-
style::Reset
36-
);
25+
println!("{}", "請輸入答案:".bright_black());
3726

3827
io::stdin().read_line(&mut guess).expect("請輸入一些文字");
3928

4029
if guess.trim().to_lowercase() == subject.answer {
41-
println!(
42-
"{}答對了,你好棒 owo\n{}",
43-
color::Fg(color::Yellow),
44-
style::Reset
45-
);
30+
println!("{}", "答對了,你好棒 owo\n".yellow());
4631
break;
4732
} else {
48-
println!(
49-
"{}叭叭,答錯了 OAO\n{}",
50-
color::Fg(color::LightRed),
51-
style::Reset
52-
);
33+
println!("{}", "叭叭,答錯了 OAO\n".bright_red());
5334
}
5435
}
5536
}
5637

5738
println!(
58-
"{}你全部都答對了耶,可以領個小禮物 OwO{}",
59-
color::Fg(color::LightYellow),
60-
style::Reset
39+
"{}",
40+
"你全部都答對了耶,歡迎拍下過關畫面,到南休息區「Code Dojo 技術傳道場」Mozilla 攤位領個小禮物 OwO".bright_yellow()
6141
);
6242
}

0 commit comments

Comments
 (0)